3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Create a page for displaying Contribute Pages
38 * Contribute Pages are pages that are used to display
39 * contributions of different types. Pages consist
40 * of many customizable sections which can be
43 * This page provides a top level browse view
44 * of all the contribution pages in the system.
47 class CRM_Contribute_Page_ContributionPage
extends CRM_Core_Page
{
50 * The action links that we need to display for the browse screen
54 private static $_actionLinks;
55 private static $_contributionLinks;
56 private static $_configureActionLinks;
57 private static $_onlineContributionLinks;
59 // @todo Unused private field can be safely removed.
60 private static $_links = NULL;
63 * @var CRM_Utils_Pager
65 protected $_pager = NULL;
70 protected $_sortByCharacter;
73 * Get the action links for this page.
77 function &actionLinks() {
78 // check if variable _actionsLinks is populated
79 if (!isset(self
::$_actionLinks)) {
80 // helper variable for nicer formatting
81 $deleteExtra = ts('Are you sure you want to delete this Contribution page?');
82 $copyExtra = ts('Are you sure you want to make a copy of this Contribution page?');
84 self
::$_actionLinks = array(
85 CRM_Core_Action
::COPY
=> array(
86 'name' => ts('Make a Copy'),
87 'url' => CRM_Utils_System
::currentPath(),
88 'qs' => 'action=copy&gid=%%id%%',
89 'title' => ts('Make a Copy of CiviCRM Contribution Page'),
90 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
92 CRM_Core_Action
::DISABLE
=> array(
93 'name' => ts('Disable'),
94 'title' => ts('Disable'),
95 'ref' => 'crm-enable-disable',
97 CRM_Core_Action
::ENABLE
=> array(
98 'name' => ts('Enable'),
99 'ref' => 'crm-enable-disable',
100 'title' => ts('Enable'),
102 CRM_Core_Action
::DELETE
=> array(
103 'name' => ts('Delete'),
104 'url' => CRM_Utils_System
::currentPath(),
105 'qs' => 'action=delete&reset=1&id=%%id%%',
106 'title' => ts('Delete Custom Field'),
107 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
111 return self
::$_actionLinks;
115 * Get the configure action links for this page.
119 public function &configureActionLinks() {
120 // check if variable _actionsLinks is populated
121 if (!isset(self
::$_configureActionLinks)) {
122 $urlString = 'civicrm/admin/contribute/';
123 $urlParams = 'reset=1&action=update&id=%%id%%';
125 self
::$_configureActionLinks = array(
126 CRM_Core_Action
::ADD
=> array(
127 'name' => ts('Title and Settings'),
128 'title' => ts('Title and Settings'),
129 'url' => $urlString . 'settings',
131 'uniqueName' => 'settings',
133 CRM_Core_Action
::UPDATE
=> array(
134 'name' => ts('Contribution Amounts'),
135 'title' => ts('Contribution Amounts'),
136 'url' => $urlString . 'amount',
138 'uniqueName' => 'amount',
140 CRM_Core_Action
::VIEW
=> array(
141 'name' => ts('Membership Settings'),
142 'title' => ts('Membership Settings'),
143 'url' => $urlString . 'membership',
145 'uniqueName' => 'membership',
147 CRM_Core_Action
::EXPORT
=> array(
148 'name' => ts('Thank-you and Receipting'),
149 'title' => ts('Thank-you and Receipting'),
150 'url' => $urlString . 'thankyou',
152 'uniqueName' => 'thankyou',
154 CRM_Core_Action
::BASIC
=> array(
155 'name' => ts('Tell a Friend'),
156 'title' => ts('Tell a Friend'),
157 'url' => $urlString . 'friend',
159 'uniqueName' => 'friend',
161 CRM_Core_Action
::PROFILE
=> array(
162 'name' => ts('Include Profiles'),
163 'title' => ts('Include Profiles'),
164 'url' => $urlString . 'custom',
166 'uniqueName' => 'custom',
168 CRM_Core_Action
::MAP
=> array(
169 'name' => ts('Contribution Widget'),
170 'title' => ts('Contribution Widget'),
171 'url' => $urlString . 'widget',
173 'uniqueName' => 'widget',
175 CRM_Core_Action
::FOLLOWUP
=> array(
176 'name' => ts('Premiums'),
177 'title' => ts('Premiums'),
178 'url' => $urlString . 'premium',
180 'uniqueName' => 'premium',
182 CRM_Core_Action
::ADVANCED
=> array(
183 'name' => ts('Personal Campaign Pages'),
184 'title' => ts('Personal Campaign Pages'),
185 'url' => $urlString . 'pcp',
187 'uniqueName' => 'pcp',
192 return self
::$_configureActionLinks;
196 * Get the online contribution links.
200 public function &onlineContributionLinks() {
201 if (!isset(self
::$_onlineContributionLinks)) {
202 $urlString = 'civicrm/contribute/transact';
203 $urlParams = 'reset=1&id=%%id%%';
204 self
::$_onlineContributionLinks = array(
205 CRM_Core_Action
::RENEW
=> array(
206 'name' => ts('Live Page'),
207 'title' => ts('Live Page'),
211 'uniqueName' => 'live_page',
213 CRM_Core_Action
::PREVIEW
=> array(
214 'name' => ts('Test-drive'),
215 'title' => ts('Test-drive'),
217 'qs' => $urlParams . '&action=preview',
218 'uniqueName' => 'test_drive',
223 return self
::$_onlineContributionLinks;
227 * Get the contributions links.
231 public function &contributionLinks() {
232 if (!isset(self
::$_contributionLinks)) {
233 //get contribution dates.
234 $dates = CRM_Contribute_BAO_Contribution
::getContributionDates();
235 $now = $dates['now'];
236 $yearDate = $dates['yearDate'];
237 $monthDate = $dates['monthDate'];
238 $yearNow = $yearDate +
10000;
240 $urlString = 'civicrm/contribute/search';
241 $urlParams = 'reset=1&pid=%%id%%&force=1&test=0';
243 self
::$_contributionLinks = array(
244 CRM_Core_Action
::DETACH
=> array(
245 'name' => ts('Current Month-To-Date'),
246 'title' => ts('Current Month-To-Date'),
248 'qs' => "{$urlParams}&start={$monthDate}&end={$now}",
249 'uniqueName' => 'current_month_to_date',
251 CRM_Core_Action
::REVERT
=> array(
252 'name' => ts('Fiscal Year-To-Date'),
253 'title' => ts('Fiscal Year-To-Date'),
255 'qs' => "{$urlParams}&start={$yearDate}&end={$yearNow}",
256 'uniqueName' => 'fiscal_year_to_date',
258 CRM_Core_Action
::BROWSE
=> array(
259 'name' => ts('Cumulative'),
260 'title' => ts('Cumulative'),
262 'qs' => "{$urlParams}&start=&end=$now",
263 'uniqueName' => 'cumulative',
268 return self
::$_contributionLinks;
274 * This method is called after the page is created. It checks for the
275 * type of action and executes that action.
276 * Finally it calls the parent's run method.
280 public function run() {
281 // get the requested action
282 $action = CRM_Utils_Request
::retrieve('action', 'String',
283 // default to 'browse'
284 $this, FALSE, 'browse'
287 // assign vars to templates
288 $this->assign('action', $action);
289 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
293 // set breadcrumb to append to 2nd layer pages
294 $breadCrumb = array(array('title' => ts('Manage Contribution Pages'),
295 'url' => CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
300 // what action to take ?
301 if ($action & CRM_Core_Action
::ADD
) {
302 $session = CRM_Core_Session
::singleton();
303 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
304 'action=browse&reset=1'
307 $controller = new CRM_Contribute_Controller_ContributionPage(NULL, $action);
308 CRM_Utils_System
::setTitle(ts('Manage Contribution Page'));
309 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
310 return $controller->run();
312 elseif ($action & CRM_Core_Action
::UPDATE
) {
313 $config = CRM_Core_Config
::singleton();
315 // assign vars to templates
316 $this->assign('id', $id);
317 $this->assign('title', CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'title'));
318 $this->assign('is_active', CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active'));
319 if (in_array('CiviMember', $config->enableComponents
)) {
320 $this->assign('CiviMember', TRUE);
323 elseif ($action & CRM_Core_Action
::COPY
) {
324 // @todo Unused local variable can be safely removed.
325 $session = CRM_Core_Session
::singleton();
326 CRM_Core_Session
::setStatus(ts('A copy of the contribution page has been created'), ts('Successfully Copied'), 'success');
329 elseif ($action & CRM_Core_Action
::DELETE
) {
330 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
332 $session = CRM_Core_Session
::singleton();
333 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
334 'reset=1&action=browse'
337 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
342 FROM civicrm_contribution_page ccp
343 JOIN civicrm_pcp cp ON ccp.id = cp.page_id
344 WHERE cp.page_id = {$id}
345 AND cp.page_type = 'contribute'
348 if ($pageTitle = CRM_Core_DAO
::singleValueQuery($query)) {
349 CRM_Core_Session
::setStatus(ts('The \'%1\' cannot be deleted! You must Delete all Personal Campaign Page(s) related with this contribution page prior to deleting the page.', array(1 => $pageTitle)), ts('Deletion Error'), 'error');
351 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
354 $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionPage_Delete',
355 'Delete Contribution Page',
356 CRM_Core_Action
::DELETE
358 $controller->set('id', $id);
359 $controller->process();
360 return $controller->run();
363 // finally browse the contribution pages
366 CRM_Utils_System
::setTitle(ts('Manage Contribution Pages'));
369 return parent
::run();
373 * This function is to make a copy of a contribution page, including
374 * all the fields in the page
378 public function copy() {
379 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive',
380 $this, TRUE, 0, 'GET'
383 CRM_Contribute_BAO_ContributionPage
::copy($gid);
385 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
389 * Browse all contribution pages
391 * @param mixed $action
395 public function browse($action = NULL) {
396 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
400 // @todo Unused local variable can be safely removed.
401 $createdId = CRM_Utils_Request
::retrieve('cid', 'Positive',
405 if ($this->_sortByCharacter
== 1 ||
408 $this->_sortByCharacter
= '';
409 $this->set('sortByCharacter', '');
416 $whereClause = $this->whereClause($params, FALSE);
417 $this->pagerAToZ($whereClause, $params);
420 $whereClause = $this->whereClause($params, TRUE);
421 $this->pager($whereClause, $params);
423 list($offset, $rowCount) = $this->_pager
->getOffsetAndRowCount();
425 //check for delete CRM-4418
426 $allowToDelete = CRM_Core_Permission
::check('delete in CiviContribute');
430 FROM civicrm_contribution_page
432 LIMIT $offset, $rowCount";
433 $contribPage = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage');
434 $contribPageIds = array();
435 while ($contribPage->fetch()) {
436 $contribPageIds[$contribPage->id
] = $contribPage->id
;
438 //get all section info.
439 $contriPageSectionInfo = CRM_Contribute_BAO_ContributionPage
::getSectionInfo($contribPageIds);
443 FROM civicrm_contribution_page
446 LIMIT $offset, $rowCount";
448 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage');
451 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
453 //get configure actions links.
454 $configureActionLinks = self
::configureActionLinks();
456 while ($dao->fetch()) {
457 $contribution[$dao->id
] = array();
458 CRM_Core_DAO
::storeValues($dao, $contribution[$dao->id
]);
460 // form all action links
461 $action = array_sum(array_keys($this->actionLinks()));
463 //add configure actions links.
464 $action +
= array_sum(array_keys($configureActionLinks));
466 //add online contribution links.
467 $action +
= array_sum(array_keys(self
::onlineContributionLinks()));
469 //add contribution search links.
470 $action +
= array_sum(array_keys(self
::contributionLinks()));
472 if ($dao->is_active
) {
473 $action -= (int)CRM_Core_Action
::ENABLE
;
476 $action -= (int)CRM_Core_Action
::DISABLE
;
480 if (!$allowToDelete) {
481 $action -= (int)CRM_Core_Action
::DELETE
;
484 //build the configure links.
485 $sectionsInfo = CRM_Utils_Array
::value($dao->id
, $contriPageSectionInfo, array());
486 $contribution[$dao->id
]['configureActionLinks'] = CRM_Core_Action
::formLink(self
::formatConfigureLinks($sectionsInfo),
488 array('id' => $dao->id
),
491 'contributionpage.configure.actions',
496 //build the contributions links.
497 $contribution[$dao->id
]['contributionLinks'] = CRM_Core_Action
::formLink(self
::contributionLinks(),
499 array('id' => $dao->id
),
502 'contributionpage.contributions.search',
507 //build the online contribution links.
508 $contribution[$dao->id
]['onlineContributionLinks'] = CRM_Core_Action
::formLink(self
::onlineContributionLinks(),
510 array('id' => $dao->id
),
513 'contributionpage.online.links',
518 //build the normal action links.
519 $contribution[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(),
521 array('id' => $dao->id
),
524 'contributionpage.action.links',
529 //show campaigns on selector.
530 $contribution[$dao->id
]['campaign'] = CRM_Utils_Array
::value($dao->campaign_id
, $allCampaigns);
533 if (isset($contribution)) {
534 $this->assign('rows', $contribution);
538 public function search() {
539 if (isset($this->_action
) &
540 (CRM_Core_Action
::ADD |
541 CRM_Core_Action
::UPDATE |
542 CRM_Core_Action
::DELETE
548 $form = new CRM_Core_Controller_Simple('CRM_Contribute_Form_SearchContribution',
549 ts('Search Contribution'),
552 $form->setEmbedded(TRUE);
553 $form->setParent($this);
559 * @param array $params
560 * @param bool $sortBy
564 public function whereClause(&$params, $sortBy = TRUE) {
565 // @todo Unused local variable can be safely removed.
566 $values = $clauses = array();
567 $title = $this->get('title');
568 $createdId = $this->get('cid');
571 $clauses[] = "(created_id = {$createdId})";
575 $clauses[] = "title LIKE %1";
576 if (strpos($title, '%') !== FALSE) {
577 $params[1] = array(trim($title), 'String', FALSE);
580 $params[1] = array(trim($title), 'String', TRUE);
584 $value = $this->get( 'financial_type_id' );
587 if (is_array($value)) {
588 foreach ($value as $k => $v) {
593 $type = implode(',', $val);
595 // @todo Variable 'type' might not have been defined.
596 $clauses[] = "financial_type_id IN ({$type})";
599 if ($sortBy && $this->_sortByCharacter
!== NULL) {
600 $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
603 // @todo Fatal typo: $campainIds vs $campaignIds.
604 $campainIds = $this->get('campaign_id');
605 if (!CRM_Utils_System
::isNull($campainIds)) {
606 if (!is_array($campainIds)) {
607 // @todo Undefined variable $campaignIds, due to fatal typo above.
608 $campaignIds = array($campaignIds);
610 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
613 if (empty($clauses)) {
614 // Let template know if user has run a search or not
615 $this->assign('isSearch', 0);
619 $this->assign('isSearch', 1);
622 return implode(' AND ', $clauses);
626 * @param $whereClause
627 * @param array $whereParams
629 public function pager($whereClause, $whereParams) {
631 $params['status'] = ts('Contribution %%StatusMessage%%');
632 $params['csvString'] = NULL;
633 $params['buttonTop'] = 'PagerTopButton';
634 $params['buttonBottom'] = 'PagerBottomButton';
635 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
636 if (!$params['rowCount']) {
637 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
642 FROM civicrm_contribution_page
645 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
647 $this->_pager
= new CRM_Utils_Pager($params);
648 $this->assign_by_ref('pager', $this->_pager
);
652 * @param $whereClause
653 * @param array $whereParams
655 public function pagerAtoZ($whereClause, $whereParams) {
658 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
659 FROM civicrm_contribution_page
661 ORDER BY LEFT(title, 1)
663 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
665 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
666 $this->assign('aToZ', $aToZBar);
670 * @param array $sectionsInfo
674 public function formatConfigureLinks($sectionsInfo) {
675 // build the formatted configure links.
676 $formattedConfLinks = self
::configureActionLinks();
677 foreach ($formattedConfLinks as $act => & $link) {
678 $sectionName = CRM_Utils_Array
::value('uniqueName', $link);
683 // @todo Unused local variable can be safely removed.
685 if (isset($link['class'])) {
686 $classes = $link['class'];
689 if (empty($sectionsInfo[$sectionName])) {
691 if (isset($link['class'])) {
692 $classes = $link['class'];
694 $link['class'] = array_merge($classes, array('disabled'));
698 return $formattedConfLinks;