3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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 private static $_links = NULL;
61 protected $_pager = NULL;
63 protected $_sortByCharacter;
66 * Get the action links for this page.
68 * @return array $_actionLinks
70 */ function &actionLinks() {
71 // check if variable _actionsLinks is populated
72 if (!isset(self
::$_actionLinks)) {
73 // helper variable for nicer formatting
74 $deleteExtra = ts('Are you sure you want to delete this Contribution page?');
75 $copyExtra = ts('Are you sure you want to make a copy of this Contribution page?');
77 self
::$_actionLinks = array(
78 CRM_Core_Action
::COPY
=> array(
79 'name' => ts('Make a Copy'),
80 'url' => CRM_Utils_System
::currentPath(),
81 'qs' => 'action=copy&gid=%%id%%',
82 'title' => ts('Make a Copy of CiviCRM Contribution Page'),
83 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
85 CRM_Core_Action
::DISABLE
=> array(
86 'name' => ts('Disable'),
87 'title' => ts('Disable'),
88 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Contribute_BAO_ContributionPage' . '\',\'' . 'enable-disable' . '\' );"',
89 'ref' => 'disable-action',
91 CRM_Core_Action
::ENABLE
=> array(
92 'name' => ts('Enable'),
93 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Contribute_BAO_ContributionPage' . '\',\'' . 'disable-enable' . '\' );"',
94 'ref' => 'enable-action',
95 'title' => ts('Enable'),
97 CRM_Core_Action
::DELETE
=> array(
98 'name' => ts('Delete'),
99 'url' => CRM_Utils_System
::currentPath(),
100 'qs' => 'action=delete&reset=1&id=%%id%%',
101 'title' => ts('Delete Custom Field'),
102 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
106 return self
::$_actionLinks;
110 * Get the configure action links for this page.
112 * @return array $_configureActionLinks
115 function &configureActionLinks() {
116 // check if variable _actionsLinks is populated
117 if (!isset(self
::$_configureActionLinks)) {
118 $urlString = 'civicrm/admin/contribute/';
119 $urlParams = 'reset=1&action=update&id=%%id%%';
121 self
::$_configureActionLinks = array(
122 CRM_Core_Action
::ADD
=> array(
123 'name' => ts('Title and Settings'),
124 'title' => ts('Title and Settings'),
125 'url' => $urlString . 'settings',
127 'uniqueName' => 'settings',
129 CRM_Core_Action
::UPDATE
=> array(
130 'name' => ts('Contribution Amounts'),
131 'title' => ts('Contribution Amounts'),
132 'url' => $urlString . 'amount',
134 'uniqueName' => 'amount',
136 CRM_Core_Action
::VIEW
=> array(
137 'name' => ts('Membership Settings'),
138 'title' => ts('Membership Settings'),
139 'url' => $urlString . 'membership',
141 'uniqueName' => 'membership',
143 CRM_Core_Action
::EXPORT
=> array(
144 'name' => ts('Thank-you and Receipting'),
145 'title' => ts('Thank-you and Receipting'),
146 'url' => $urlString . 'thankyou',
148 'uniqueName' => 'thankyou',
150 CRM_Core_Action
::BASIC
=> array(
151 'name' => ts('Tell a Friend'),
152 'title' => ts('Tell a Friend'),
153 'url' => $urlString . 'friend',
155 'uniqueName' => 'friend',
157 CRM_Core_Action
::PROFILE
=> array(
158 'name' => ts('Include Profiles'),
159 'title' => ts('Include Profiles'),
160 'url' => $urlString . 'custom',
162 'uniqueName' => 'custom',
164 CRM_Core_Action
::MAP
=> array(
165 'name' => ts('Contribution Widget'),
166 'title' => ts('Contribution Widget'),
167 'url' => $urlString . 'widget',
169 'uniqueName' => 'widget',
171 CRM_Core_Action
::FOLLOWUP
=> array(
172 'name' => ts('Premiums'),
173 'title' => ts('Premiums'),
174 'url' => $urlString . 'premium',
176 'uniqueName' => 'premium',
178 CRM_Core_Action
::ADVANCED
=> array(
179 'name' => ts('Personal Campaign Pages'),
180 'title' => ts('Personal Campaign Pages'),
181 'url' => $urlString . 'pcp',
183 'uniqueName' => 'pcp',
188 return self
::$_configureActionLinks;
192 * Get the online contribution links.
194 * @return array $_onlineContributionLinks.
197 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.
226 * @return array $_contributionLinks
229 function &contributionLinks() {
230 if (!isset(self
::$_contributionLinks)) {
231 //get contribution dates.
232 $dates = CRM_Contribute_BAO_Contribution
::getContributionDates();
234 'now', 'yearDate', 'monthDate') as $date) {
235 $
$date = $dates[$date];
237 $yearNow = $yearDate +
10000;
239 $urlString = 'civicrm/contribute/search';
240 $urlParams = 'reset=1&pid=%%id%%&force=1&test=0';
242 self
::$_contributionLinks = array(
243 CRM_Core_Action
::DETACH
=> array(
244 'name' => ts('Current Month-To-Date'),
245 'title' => ts('Current Month-To-Date'),
247 'qs' => "{$urlParams}&start={$monthDate}&end={$now}",
248 'uniqueName' => 'current_month_to_date',
250 CRM_Core_Action
::REVERT
=> array(
251 'name' => ts('Fiscal Year-To-Date'),
252 'title' => ts('Fiscal Year-To-Date'),
254 'qs' => "{$urlParams}&start={$yearDate}&end={$yearNow}",
255 'uniqueName' => 'fiscal_year_to_date',
257 CRM_Core_Action
::BROWSE
=> array(
258 'name' => ts('Cumulative'),
259 'title' => ts('Cumulative'),
261 'qs' => "{$urlParams}&start=&end=$now",
262 'uniqueName' => 'cumulative',
267 return self
::$_contributionLinks;
273 * This method is called after the page is created. It checks for the
274 * type of action and executes that action.
275 * Finally it calls the parent's run method.
282 // get the requested action
283 $action = CRM_Utils_Request
::retrieve('action', 'String',
284 // default to 'browse'
285 $this, FALSE, 'browse'
288 // assign vars to templates
289 $this->assign('action', $action);
290 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
294 // set breadcrumb to append to 2nd layer pages
295 $breadCrumb = array(array('title' => ts('Manage Contribution Pages'),
296 'url' => CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
301 // what action to take ?
302 if ($action & CRM_Core_Action
::ADD
) {
303 $session = CRM_Core_Session
::singleton();
304 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
305 'action=browse&reset=1'
308 $controller = new CRM_Contribute_Controller_ContributionPage(NULL, $action);
309 CRM_Utils_System
::setTitle(ts('Manage Contribution Page'));
310 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
311 return $controller->run();
313 elseif ($action & CRM_Core_Action
::UPDATE
) {
314 $config = CRM_Core_Config
::singleton();
316 // assign vars to templates
317 $this->assign('id', $id);
318 $this->assign('title', CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'title'));
319 $this->assign('is_active', CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active'));
320 if (in_array('CiviMember', $config->enableComponents
)) {
321 $this->assign('CiviMember', TRUE);
324 elseif ($action & CRM_Core_Action
::COPY
) {
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
380 $gid = CRM_Utils_Request
::retrieve('gid', 'Positive',
381 $this, TRUE, 0, 'GET'
384 CRM_Contribute_BAO_ContributionPage
::copy($gid);
386 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));
390 * Browse all contribution pages
396 function browse($action = NULL) {
397 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
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 -= CRM_Core_Action
::ENABLE
;
476 $action -= CRM_Core_Action
::DISABLE
;
480 if (!$allowToDelete) {
481 $action -= 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
),
493 //build the contributions links.
494 $contribution[$dao->id
]['contributionLinks'] = CRM_Core_Action
::formLink(self
::contributionLinks(),
496 array('id' => $dao->id
),
501 //build the online contribution links.
502 $contribution[$dao->id
]['onlineContributionLinks'] = CRM_Core_Action
::formLink(self
::onlineContributionLinks(),
504 array('id' => $dao->id
),
509 //build the normal action links.
510 $contribution[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(),
512 array('id' => $dao->id
),
517 //show campaigns on selector.
518 $contribution[$dao->id
]['campaign'] = CRM_Utils_Array
::value($dao->campaign_id
, $allCampaigns);
521 if (isset($contribution)) {
522 $this->assign('rows', $contribution);
527 if (isset($this->_action
) &
528 (CRM_Core_Action
::ADD |
529 CRM_Core_Action
::UPDATE |
530 CRM_Core_Action
::DELETE
536 $form = new CRM_Core_Controller_Simple('CRM_Contribute_Form_SearchContribution',
537 ts('Search Contribution'),
540 $form->setEmbedded(TRUE);
541 $form->setParent($this);
546 function whereClause(&$params, $sortBy = TRUE) {
547 $values = $clauses = array();
548 $title = $this->get('title');
549 $createdId = $this->get('cid');
552 $clauses[] = "(created_id = {$createdId})";
556 $clauses[] = "title LIKE %1";
557 if (strpos($title, '%') !== FALSE) {
558 $params[1] = array(trim($title), 'String', FALSE);
561 $params[1] = array(trim($title), 'String', TRUE);
565 $value = $this->get( 'financial_type_id' );
568 if (is_array($value)) {
569 foreach ($value as $k => $v) {
574 $type = implode(',', $val);
577 $clauses[] = "financial_type_id IN ({$type})";
581 $this->_sortByCharacter
!== NULL
583 $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO
::escapeWildCardString($this->_sortByCharacter
)) . "%'";
586 $campainIds = $this->get('campaign_id');
587 if (!CRM_Utils_System
::isNull($campainIds)) {
588 if (!is_array($campainIds)) {
589 $campaignIds = array($campaignIds);
591 $clauses[] = '( campaign_id IN ( ' . implode(' , ', array_values($campainIds)) . ' ) )';
594 if (empty($clauses)) {
595 // Let template know if user has run a search or not
596 $this->assign('isSearch', 0);
600 $this->assign('isSearch', 1);
603 return implode(' AND ', $clauses);
606 function pager($whereClause, $whereParams) {
608 $params['status'] = ts('Contribution %%StatusMessage%%');
609 $params['csvString'] = NULL;
610 $params['buttonTop'] = 'PagerTopButton';
611 $params['buttonBottom'] = 'PagerBottomButton';
612 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
613 if (!$params['rowCount']) {
614 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
619 FROM civicrm_contribution_page
622 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
624 $this->_pager
= new CRM_Utils_Pager($params);
625 $this->assign_by_ref('pager', $this->_pager
);
628 function pagerAtoZ($whereClause, $whereParams) {
631 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
632 FROM civicrm_contribution_page
634 ORDER BY LEFT(title, 1)
636 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
638 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
639 $this->assign('aToZ', $aToZBar);
642 function formatConfigureLinks($sectionsInfo) {
643 //build the formatted configure links.
644 $formattedConfLinks = self
::configureActionLinks();
645 foreach ($formattedConfLinks as $act => & $link) {
646 $sectionName = CRM_Utils_Array
::value('uniqueName', $link);
652 if (isset($link['class'])) {
653 $classes = $link['class'];
656 if (!CRM_Utils_Array
::value($sectionName, $sectionsInfo)) {
658 if (isset($link['class'])) {
659 $classes = $link['class'];
661 $link['class'] = array_merge($classes, array('disabled'));
665 return $formattedConfLinks;