3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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;
60 * @var CRM_Utils_Pager
62 protected $_pager = NULL;
67 protected $_sortByCharacter;
70 * Get the action links for this page.
74 public function &actionLinks() {
75 // check if variable _actionsLinks is populated
76 if (!isset(self
::$_actionLinks)) {
77 // helper variable for nicer formatting
78 $deleteExtra = ts('Are you sure you want to delete this Contribution page?');
79 $copyExtra = ts('Are you sure you want to make a copy of this Contribution page?');
81 self
::$_actionLinks = array(
82 CRM_Core_Action
::COPY
=> array(
83 'name' => ts('Make a Copy'),
84 'url' => CRM_Utils_System
::currentPath(),
85 'qs' => 'action=copy&gid=%%id%%',
86 'title' => ts('Make a Copy of CiviCRM Contribution Page'),
87 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
89 CRM_Core_Action
::DISABLE
=> array(
90 'name' => ts('Disable'),
91 'title' => ts('Disable'),
92 'ref' => 'crm-enable-disable',
94 CRM_Core_Action
::ENABLE
=> array(
95 'name' => ts('Enable'),
96 'ref' => 'crm-enable-disable',
97 'title' => ts('Enable'),
99 CRM_Core_Action
::DELETE
=> array(
100 'name' => ts('Delete'),
101 'url' => CRM_Utils_System
::currentPath(),
102 'qs' => 'action=delete&reset=1&id=%%id%%',
103 'title' => ts('Delete Custom Field'),
104 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
108 return self
::$_actionLinks;
112 * Get the configure action links for this page.
116 public function &configureActionLinks() {
117 // check if variable _actionsLinks is populated
118 if (!isset(self
::$_configureActionLinks)) {
119 $urlString = 'civicrm/admin/contribute/';
120 $urlParams = 'reset=1&action=update&id=%%id%%';
122 self
::$_configureActionLinks = array(
123 CRM_Core_Action
::ADD
=> array(
124 'name' => ts('Title and Settings'),
125 'title' => ts('Title and Settings'),
126 'url' => $urlString . 'settings',
128 'uniqueName' => 'settings',
130 CRM_Core_Action
::UPDATE
=> array(
131 'name' => ts('Contribution Amounts'),
132 'title' => ts('Contribution Amounts'),
133 'url' => $urlString . 'amount',
135 'uniqueName' => 'amount',
137 CRM_Core_Action
::VIEW
=> array(
138 'name' => ts('Membership Settings'),
139 'title' => ts('Membership Settings'),
140 'url' => $urlString . 'membership',
142 'uniqueName' => 'membership',
144 CRM_Core_Action
::EXPORT
=> array(
145 'name' => ts('Thank-you and Receipting'),
146 'title' => ts('Thank-you and Receipting'),
147 'url' => $urlString . 'thankyou',
149 'uniqueName' => 'thankyou',
151 CRM_Core_Action
::BASIC
=> array(
152 'name' => ts('Tell a Friend'),
153 'title' => ts('Tell a Friend'),
154 'url' => $urlString . 'friend',
156 'uniqueName' => 'friend',
158 CRM_Core_Action
::PROFILE
=> array(
159 'name' => ts('Include Profiles'),
160 'title' => ts('Include Profiles'),
161 'url' => $urlString . 'custom',
163 'uniqueName' => 'custom',
165 CRM_Core_Action
::MAP
=> array(
166 'name' => ts('Contribution Widget'),
167 'title' => ts('Contribution Widget'),
168 'url' => $urlString . 'widget',
170 'uniqueName' => 'widget',
172 CRM_Core_Action
::FOLLOWUP
=> array(
173 'name' => ts('Premiums'),
174 'title' => ts('Premiums'),
175 'url' => $urlString . 'premium',
177 'uniqueName' => 'premium',
179 CRM_Core_Action
::ADVANCED
=> array(
180 'name' => ts('Personal Campaign Pages'),
181 'title' => ts('Personal Campaign Pages'),
182 'url' => $urlString . 'pcp',
184 'uniqueName' => 'pcp',
189 return self
::$_configureActionLinks;
193 * Get the online contribution links.
197 public function &onlineContributionLinks() {
198 if (!isset(self
::$_onlineContributionLinks)) {
199 $urlString = 'civicrm/contribute/transact';
200 $urlParams = 'reset=1&id=%%id%%';
201 self
::$_onlineContributionLinks = array(
202 CRM_Core_Action
::RENEW
=> array(
203 'name' => ts('Live Page'),
204 'title' => ts('Live Page'),
208 'uniqueName' => 'live_page',
210 CRM_Core_Action
::PREVIEW
=> array(
211 'name' => ts('Test-drive'),
212 'title' => ts('Test-drive'),
214 'qs' => $urlParams . '&action=preview',
215 'uniqueName' => 'test_drive',
220 return self
::$_onlineContributionLinks;
224 * Get the contributions links.
228 public function &contributionLinks() {
229 if (!isset(self
::$_contributionLinks)) {
230 //get contribution dates.
231 $dates = CRM_Contribute_BAO_Contribution
::getContributionDates();
232 $now = $dates['now'];
233 $yearDate = $dates['yearDate'];
234 $monthDate = $dates['monthDate'];
235 $yearNow = $yearDate +
10000;
237 $urlString = 'civicrm/contribute/search';
238 $urlParams = 'reset=1&pid=%%id%%&force=1&test=0';
240 self
::$_contributionLinks = array(
241 CRM_Core_Action
::DETACH
=> array(
242 'name' => ts('Current Month-To-Date'),
243 'title' => ts('Current Month-To-Date'),
245 'qs' => "{$urlParams}&start={$monthDate}&end={$now}",
246 'uniqueName' => 'current_month_to_date',
248 CRM_Core_Action
::REVERT
=> array(
249 'name' => ts('Fiscal Year-To-Date'),
250 'title' => ts('Fiscal Year-To-Date'),
252 'qs' => "{$urlParams}&start={$yearDate}&end={$yearNow}",
253 'uniqueName' => 'fiscal_year_to_date',
255 CRM_Core_Action
::BROWSE
=> array(
256 'name' => ts('Cumulative'),
257 'title' => ts('Cumulative'),
259 'qs' => "{$urlParams}&start=&end=$now",
260 'uniqueName' => 'cumulative',
265 return self
::$_contributionLinks;
271 * This method is called after the page is created. It checks for the
272 * type of action and executes that action.
273 * Finally it calls the parent's run method.
277 public function run() {
278 // get the requested action
279 $action = CRM_Utils_Request
::retrieve('action', 'String',
280 // default to 'browse'
281 $this, FALSE, 'browse'
284 // assign vars to templates
285 $this->assign('action', $action);
286 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
290 // set breadcrumb to append to 2nd layer pages
293 'title' => ts('Manage Contribution Pages'),
294 '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 // But are there any side effects of CRM_Core_Session::singleton() that we
327 $session = CRM_Core_Session
::singleton();
328 CRM_Core_Session
::setStatus(ts('A copy of the contribution page has been created'), ts('Successfully Copied'), 'success');
331 elseif ($action & CRM_Core_Action
::DELETE
) {
332 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
334 $session = CRM_Core_Session
::singleton();
335 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
336 'reset=1&action=browse'
339 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
344 FROM civicrm_contribution_page ccp
345 JOIN civicrm_pcp cp ON ccp.id = cp.page_id
346 WHERE cp.page_id = {$id}
347 AND cp.page_type = 'contribute'
350 if ($pageTitle = CRM_Core_DAO
::singleValueQuery($query)) {
351 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');
353 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/contribute', 'reset=1'));
356 $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionPage_Delete',
357 'Delete Contribution Page',
358 CRM_Core_Action
::DELETE
360 $controller->set('id', $id);
361 $controller->process();
362 return $controller->run();
365 // finally browse the contribution pages
368 CRM_Utils_System
::setTitle(ts('Manage Contribution Pages'));
371 return parent
::run();
375 * make a copy of a contribution page, including
376 * all the fields in the page
380 public function copy() {
381 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive',
382 $this, TRUE, 0, 'GET'
385 CRM_Contribute_BAO_ContributionPage
::copy($gid);
387 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
391 * Browse all contribution pages.
393 * @param mixed $action
396 public function browse($action = NULL) {
397 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
401 // @todo Unused local variable can be safely removed.
402 // But are there any side effects of CRM_Utils_Request::retrieve() that we
404 $createdId = CRM_Utils_Request
::retrieve('cid', 'Positive',
408 if ($this->_sortByCharacter
== 'all' ||
411 $this->_sortByCharacter
= '';
412 $this->set('sortByCharacter', '');
419 $whereClause = $this->whereClause($params, FALSE);
420 $this->pagerAToZ($whereClause, $params);
423 $whereClause = $this->whereClause($params, TRUE);
424 $this->pager($whereClause, $params);
426 list($offset, $rowCount) = $this->_pager
->getOffsetAndRowCount();
428 //check for delete CRM-4418
429 $allowToDelete = CRM_Core_Permission
::check('delete in CiviContribute');
433 FROM civicrm_contribution_page
435 ORDER BY is_active desc, title asc
436 LIMIT $offset, $rowCount";
437 $contribPage = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage');
438 $contribPageIds = array();
439 while ($contribPage->fetch()) {
440 $contribPageIds[$contribPage->id
] = $contribPage->id
;
442 //get all section info.
443 $contriPageSectionInfo = CRM_Contribute_BAO_ContributionPage
::getSectionInfo($contribPageIds);
447 FROM civicrm_contribution_page
449 ORDER BY is_active desc, title asc
450 LIMIT $offset, $rowCount";
452 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage');
455 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
457 //get configure actions links.
458 $configureActionLinks = self
::configureActionLinks();
460 while ($dao->fetch()) {
461 $contribution[$dao->id
] = array();
462 CRM_Core_DAO
::storeValues($dao, $contribution[$dao->id
]);
464 // form all action links
465 $action = array_sum(array_keys($this->actionLinks()));
467 //add configure actions links.
468 $action +
= array_sum(array_keys($configureActionLinks));
470 //add online contribution links.
471 $action +
= array_sum(array_keys(self
::onlineContributionLinks()));
473 //add contribution search links.
474 $action +
= array_sum(array_keys(self
::contributionLinks()));
476 if ($dao->is_active
) {
477 $action -= (int) CRM_Core_Action
::ENABLE
;
480 $action -= (int) CRM_Core_Action
::DISABLE
;
484 if (!$allowToDelete) {
485 $action -= (int) CRM_Core_Action
::DELETE
;
488 //build the configure links.
489 $sectionsInfo = CRM_Utils_Array
::value($dao->id
, $contriPageSectionInfo, array());
490 $contribution[$dao->id
]['configureActionLinks'] = CRM_Core_Action
::formLink(self
::formatConfigureLinks($sectionsInfo),
492 array('id' => $dao->id
),
495 'contributionpage.configure.actions',
500 //build the contributions links.
501 $contribution[$dao->id
]['contributionLinks'] = CRM_Core_Action
::formLink(self
::contributionLinks(),
503 array('id' => $dao->id
),
506 'contributionpage.contributions.search',
511 //build the online contribution links.
512 $contribution[$dao->id
]['onlineContributionLinks'] = CRM_Core_Action
::formLink(self
::onlineContributionLinks(),
514 array('id' => $dao->id
),
517 'contributionpage.online.links',
522 //build the normal action links.
523 $contribution[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(),
525 array('id' => $dao->id
),
528 'contributionpage.action.links',
533 //show campaigns on selector.
534 $contribution[$dao->id
]['campaign'] = CRM_Utils_Array
::value($dao->campaign_id
, $allCampaigns);
537 if (isset($contribution)) {
538 $this->assign('rows', $contribution);
542 public function search() {
543 if (isset($this->_action
) & (CRM_Core_Action
::ADD |
544 CRM_Core_Action
::UPDATE |
545 CRM_Core_Action
::DELETE
551 $form = new CRM_Core_Controller_Simple('CRM_Contribute_Form_SearchContribution',
552 ts('Search Contribution'),
555 $form->setEmbedded(TRUE);
556 $form->setParent($this);
562 * @param array $params
563 * @param bool $sortBy
567 public function whereClause(&$params, $sortBy = TRUE) {
568 // @todo Unused local variable can be safely removed.
569 $values = $clauses = array();
570 $title = $this->get('title');
571 $createdId = $this->get('cid');
574 $clauses[] = "(created_id = {$createdId})";
578 $clauses[] = "title LIKE %1";
579 if (strpos($title, '%') !== FALSE) {
580 $params[1] = array(trim($title), 'String', FALSE);
583 $params[1] = array(trim($title), 'String', TRUE);
587 $value = $this->get('financial_type_id');
590 if (is_array($value)) {
591 foreach ($value as $k => $v) {
596 $type = implode(',', $val);
598 // @todo Variable 'type' might not have been defined.
599 $clauses[] = "financial_type_id IN ({$type})";
602 if ($sortBy && $this->_sortByCharacter
!== NULL) {
603 $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
606 $campaignIds = $this->getCampaignIds();
607 if (count($campaignIds) >= 1) {
608 $clauses[] = '( campaign_id IN ( ' . implode(' , ', $campaignIds) . ' ) )';
611 if (empty($clauses)) {
612 // Let template know if user has run a search or not
613 $this->assign('isSearch', 0);
617 $this->assign('isSearch', 1);
620 return implode(' AND ', $clauses);
624 * Gets the campaign ids from the session.
628 public function getCampaignIds() {
629 // The unfiltered value from the session cannot be trusted, it needs to be
630 // processed to get a clean array of positive integers.
632 foreach ((array) $this->get('campaign_id') as $id) {
633 if ((string) (int) $id === (string) $id && $id > 0) {
641 * @param $whereClause
642 * @param array $whereParams
644 public function pager($whereClause, $whereParams) {
646 $params['status'] = ts('Contribution %%StatusMessage%%');
647 $params['csvString'] = NULL;
648 $params['buttonTop'] = 'PagerTopButton';
649 $params['buttonBottom'] = 'PagerBottomButton';
650 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
651 if (!$params['rowCount']) {
652 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
657 FROM civicrm_contribution_page
660 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
662 $this->_pager
= new CRM_Utils_Pager($params);
663 $this->assign_by_ref('pager', $this->_pager
);
667 * @param $whereClause
668 * @param array $whereParams
670 public function pagerAtoZ($whereClause, $whereParams) {
673 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
674 FROM civicrm_contribution_page
676 ORDER BY LEFT(title, 1)
678 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
680 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
681 $this->assign('aToZ', $aToZBar);
685 * @param array $sectionsInfo
689 public function formatConfigureLinks($sectionsInfo) {
690 // build the formatted configure links.
691 $formattedConfLinks = self
::configureActionLinks();
692 foreach ($formattedConfLinks as $act => & $link) {
693 $sectionName = CRM_Utils_Array
::value('uniqueName', $link);
698 if (empty($sectionsInfo[$sectionName])) {
700 if (isset($link['class'])) {
701 $classes = $link['class'];
703 $link['class'] = array_merge($classes, array('disabled'));
707 return $formattedConfLinks;