Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * Create a page for displaying Contribute Pages | |
36 | * Contribute Pages are pages that are used to display | |
37 | * contributions of different types. Pages consist | |
38 | * of many customizable sections which can be | |
39 | * accessed. | |
40 | * | |
41 | * This page provides a top level browse view | |
42 | * of all the contribution pages in the system. | |
43 | * | |
44 | */ | |
45 | class CRM_Contribute_Page_ContributionPage extends CRM_Core_Page { | |
46 | ||
47 | /** | |
fe482240 | 48 | * The action links that we need to display for the browse screen. |
6a488035 TO |
49 | * |
50 | * @var array | |
51 | */ | |
52 | private static $_actionLinks; | |
53 | private static $_contributionLinks; | |
54 | private static $_configureActionLinks; | |
55 | private static $_onlineContributionLinks; | |
56 | ||
4bf0b605 AH |
57 | /** |
58 | * @var CRM_Utils_Pager | |
59 | */ | |
6a488035 TO |
60 | protected $_pager = NULL; |
61 | ||
4bf0b605 AH |
62 | /** |
63 | * @var string | |
64 | */ | |
6a488035 TO |
65 | protected $_sortByCharacter; |
66 | ||
67 | /** | |
68 | * Get the action links for this page. | |
69 | * | |
a3379cc1 AH |
70 | * @return array |
71 | */ | |
a130e045 | 72 | public function &actionLinks() { |
6a488035 TO |
73 | // check if variable _actionsLinks is populated |
74 | if (!isset(self::$_actionLinks)) { | |
75 | // helper variable for nicer formatting | |
76 | $deleteExtra = ts('Are you sure you want to delete this Contribution page?'); | |
77 | $copyExtra = ts('Are you sure you want to make a copy of this Contribution page?'); | |
78 | ||
79 | self::$_actionLinks = array( | |
80 | CRM_Core_Action::COPY => array( | |
81 | 'name' => ts('Make a Copy'), | |
82 | 'url' => CRM_Utils_System::currentPath(), | |
83 | 'qs' => 'action=copy&gid=%%id%%', | |
84 | 'title' => ts('Make a Copy of CiviCRM Contribution Page'), | |
85 | 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"', | |
86 | ), | |
87 | CRM_Core_Action::DISABLE => array( | |
88 | 'name' => ts('Disable'), | |
89 | 'title' => ts('Disable'), | |
4d17a233 | 90 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
91 | ), |
92 | CRM_Core_Action::ENABLE => array( | |
93 | 'name' => ts('Enable'), | |
4d17a233 | 94 | 'ref' => 'crm-enable-disable', |
6a488035 TO |
95 | 'title' => ts('Enable'), |
96 | ), | |
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 . '\');"', | |
103 | ), | |
104 | ); | |
105 | } | |
106 | return self::$_actionLinks; | |
107 | } | |
108 | ||
109 | /** | |
110 | * Get the configure action links for this page. | |
111 | * | |
a3379cc1 | 112 | * @return array |
6a488035 | 113 | */ |
00be9182 | 114 | public function &configureActionLinks() { |
6a488035 TO |
115 | // check if variable _actionsLinks is populated |
116 | if (!isset(self::$_configureActionLinks)) { | |
117 | $urlString = 'civicrm/admin/contribute/'; | |
118 | $urlParams = 'reset=1&action=update&id=%%id%%'; | |
119 | ||
120 | self::$_configureActionLinks = array( | |
121 | CRM_Core_Action::ADD => array( | |
122 | 'name' => ts('Title and Settings'), | |
123 | 'title' => ts('Title and Settings'), | |
124 | 'url' => $urlString . 'settings', | |
125 | 'qs' => $urlParams, | |
126 | 'uniqueName' => 'settings', | |
127 | ), | |
128 | CRM_Core_Action::UPDATE => array( | |
129 | 'name' => ts('Contribution Amounts'), | |
130 | 'title' => ts('Contribution Amounts'), | |
131 | 'url' => $urlString . 'amount', | |
132 | 'qs' => $urlParams, | |
133 | 'uniqueName' => 'amount', | |
134 | ), | |
135 | CRM_Core_Action::VIEW => array( | |
136 | 'name' => ts('Membership Settings'), | |
137 | 'title' => ts('Membership Settings'), | |
138 | 'url' => $urlString . 'membership', | |
139 | 'qs' => $urlParams, | |
140 | 'uniqueName' => 'membership', | |
141 | ), | |
142 | CRM_Core_Action::EXPORT => array( | |
143 | 'name' => ts('Thank-you and Receipting'), | |
144 | 'title' => ts('Thank-you and Receipting'), | |
145 | 'url' => $urlString . 'thankyou', | |
146 | 'qs' => $urlParams, | |
147 | 'uniqueName' => 'thankyou', | |
148 | ), | |
149 | CRM_Core_Action::BASIC => array( | |
150 | 'name' => ts('Tell a Friend'), | |
151 | 'title' => ts('Tell a Friend'), | |
152 | 'url' => $urlString . 'friend', | |
153 | 'qs' => $urlParams, | |
154 | 'uniqueName' => 'friend', | |
155 | ), | |
156 | CRM_Core_Action::PROFILE => array( | |
157 | 'name' => ts('Include Profiles'), | |
158 | 'title' => ts('Include Profiles'), | |
159 | 'url' => $urlString . 'custom', | |
160 | 'qs' => $urlParams, | |
161 | 'uniqueName' => 'custom', | |
162 | ), | |
163 | CRM_Core_Action::MAP => array( | |
164 | 'name' => ts('Contribution Widget'), | |
165 | 'title' => ts('Contribution Widget'), | |
166 | 'url' => $urlString . 'widget', | |
167 | 'qs' => $urlParams, | |
168 | 'uniqueName' => 'widget', | |
169 | ), | |
170 | CRM_Core_Action::FOLLOWUP => array( | |
171 | 'name' => ts('Premiums'), | |
172 | 'title' => ts('Premiums'), | |
173 | 'url' => $urlString . 'premium', | |
174 | 'qs' => $urlParams, | |
175 | 'uniqueName' => 'premium', | |
176 | ), | |
177 | CRM_Core_Action::ADVANCED => array( | |
178 | 'name' => ts('Personal Campaign Pages'), | |
179 | 'title' => ts('Personal Campaign Pages'), | |
180 | 'url' => $urlString . 'pcp', | |
181 | 'qs' => $urlParams, | |
182 | 'uniqueName' => 'pcp', | |
183 | ), | |
184 | ); | |
185 | } | |
186 | ||
187 | return self::$_configureActionLinks; | |
188 | } | |
189 | ||
190 | /** | |
191 | * Get the online contribution links. | |
192 | * | |
a3379cc1 | 193 | * @return array |
6a488035 | 194 | */ |
00be9182 | 195 | public function &onlineContributionLinks() { |
6a488035 TO |
196 | if (!isset(self::$_onlineContributionLinks)) { |
197 | $urlString = 'civicrm/contribute/transact'; | |
198 | $urlParams = 'reset=1&id=%%id%%'; | |
199 | self::$_onlineContributionLinks = array( | |
200 | CRM_Core_Action::RENEW => array( | |
201 | 'name' => ts('Live Page'), | |
202 | 'title' => ts('Live Page'), | |
203 | 'url' => $urlString, | |
204 | 'qs' => $urlParams, | |
205 | 'fe' => TRUE, | |
206 | 'uniqueName' => 'live_page', | |
207 | ), | |
208 | CRM_Core_Action::PREVIEW => array( | |
209 | 'name' => ts('Test-drive'), | |
210 | 'title' => ts('Test-drive'), | |
211 | 'url' => $urlString, | |
212 | 'qs' => $urlParams . '&action=preview', | |
213 | 'uniqueName' => 'test_drive', | |
214 | ), | |
215 | ); | |
216 | } | |
217 | ||
218 | return self::$_onlineContributionLinks; | |
219 | } | |
220 | ||
221 | /** | |
222 | * Get the contributions links. | |
223 | * | |
a3379cc1 | 224 | * @return array |
6a488035 | 225 | */ |
00be9182 | 226 | public function &contributionLinks() { |
6a488035 TO |
227 | if (!isset(self::$_contributionLinks)) { |
228 | //get contribution dates. | |
229 | $dates = CRM_Contribute_BAO_Contribution::getContributionDates(); | |
35959bc5 AH |
230 | $now = $dates['now']; |
231 | $yearDate = $dates['yearDate']; | |
232 | $monthDate = $dates['monthDate']; | |
6a488035 TO |
233 | $yearNow = $yearDate + 10000; |
234 | ||
235 | $urlString = 'civicrm/contribute/search'; | |
236 | $urlParams = 'reset=1&pid=%%id%%&force=1&test=0'; | |
237 | ||
238 | self::$_contributionLinks = array( | |
239 | CRM_Core_Action::DETACH => array( | |
240 | 'name' => ts('Current Month-To-Date'), | |
241 | 'title' => ts('Current Month-To-Date'), | |
242 | 'url' => $urlString, | |
243 | 'qs' => "{$urlParams}&start={$monthDate}&end={$now}", | |
244 | 'uniqueName' => 'current_month_to_date', | |
245 | ), | |
246 | CRM_Core_Action::REVERT => array( | |
247 | 'name' => ts('Fiscal Year-To-Date'), | |
248 | 'title' => ts('Fiscal Year-To-Date'), | |
249 | 'url' => $urlString, | |
250 | 'qs' => "{$urlParams}&start={$yearDate}&end={$yearNow}", | |
251 | 'uniqueName' => 'fiscal_year_to_date', | |
252 | ), | |
253 | CRM_Core_Action::BROWSE => array( | |
254 | 'name' => ts('Cumulative'), | |
255 | 'title' => ts('Cumulative'), | |
256 | 'url' => $urlString, | |
257 | 'qs' => "{$urlParams}&start=&end=$now", | |
258 | 'uniqueName' => 'cumulative', | |
259 | ), | |
260 | ); | |
261 | } | |
262 | ||
263 | return self::$_contributionLinks; | |
264 | } | |
265 | ||
266 | /** | |
267 | * Run the page. | |
268 | * | |
269 | * This method is called after the page is created. It checks for the | |
270 | * type of action and executes that action. | |
271 | * Finally it calls the parent's run method. | |
272 | * | |
4bf0b605 | 273 | * @return mixed |
6a488035 | 274 | */ |
00be9182 | 275 | public function run() { |
6a488035 TO |
276 | // get the requested action |
277 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
278 | // default to 'browse' | |
279 | $this, FALSE, 'browse' | |
280 | ); | |
281 | ||
282 | // assign vars to templates | |
283 | $this->assign('action', $action); | |
284 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
285 | $this, FALSE, 0 | |
286 | ); | |
287 | ||
288 | // set breadcrumb to append to 2nd layer pages | |
353ffa53 TO |
289 | $breadCrumb = array( |
290 | array( | |
291 | 'title' => ts('Manage Contribution Pages'), | |
6a488035 TO |
292 | 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), |
293 | 'reset=1' | |
294 | ), | |
a130e045 | 295 | ), |
353ffa53 | 296 | ); |
6a488035 TO |
297 | |
298 | // what action to take ? | |
299 | if ($action & CRM_Core_Action::ADD) { | |
300 | $session = CRM_Core_Session::singleton(); | |
301 | $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), | |
353ffa53 TO |
302 | 'action=browse&reset=1' |
303 | )); | |
6a488035 TO |
304 | |
305 | $controller = new CRM_Contribute_Controller_ContributionPage(NULL, $action); | |
306 | CRM_Utils_System::setTitle(ts('Manage Contribution Page')); | |
307 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
308 | return $controller->run(); | |
309 | } | |
310 | elseif ($action & CRM_Core_Action::UPDATE) { | |
311 | $config = CRM_Core_Config::singleton(); | |
312 | ||
313 | // assign vars to templates | |
314 | $this->assign('id', $id); | |
315 | $this->assign('title', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'title')); | |
316 | $this->assign('is_active', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active')); | |
317 | if (in_array('CiviMember', $config->enableComponents)) { | |
318 | $this->assign('CiviMember', TRUE); | |
319 | } | |
320 | } | |
321 | elseif ($action & CRM_Core_Action::COPY) { | |
d121646d | 322 | // @todo Unused local variable can be safely removed. |
aa344a47 AH |
323 | // But are there any side effects of CRM_Core_Session::singleton() that we |
324 | // need to preserve? | |
6a488035 TO |
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'); | |
327 | $this->copy(); | |
328 | } | |
329 | elseif ($action & CRM_Core_Action::DELETE) { | |
330 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
331 | ||
332 | $session = CRM_Core_Session::singleton(); | |
333 | $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), | |
353ffa53 TO |
334 | 'reset=1&action=browse' |
335 | )); | |
6a488035 TO |
336 | |
337 | $id = CRM_Utils_Request::retrieve('id', 'Positive', | |
338 | $this, FALSE, 0 | |
339 | ); | |
340 | $query = " | |
341 | SELECT ccp.title | |
665e5ec7 | 342 | FROM civicrm_contribution_page ccp |
6a488035 TO |
343 | JOIN civicrm_pcp cp ON ccp.id = cp.page_id |
344 | WHERE cp.page_id = {$id} | |
345 | AND cp.page_type = 'contribute' | |
346 | "; | |
347 | ||
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'); | |
350 | ||
351 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/contribute', 'reset=1')); | |
352 | } | |
353 | ||
354 | $controller = new CRM_Core_Controller_Simple('CRM_Contribute_Form_ContributionPage_Delete', | |
355 | 'Delete Contribution Page', | |
356 | CRM_Core_Action::DELETE | |
357 | ); | |
358 | $controller->set('id', $id); | |
359 | $controller->process(); | |
360 | return $controller->run(); | |
361 | } | |
362 | else { | |
363 | // finally browse the contribution pages | |
364 | $this->browse(); | |
365 | ||
366 | CRM_Utils_System::setTitle(ts('Manage Contribution Pages')); | |
367 | } | |
368 | ||
369 | return parent::run(); | |
370 | } | |
371 | ||
372 | /** | |
347e061b | 373 | * Make a copy of a contribution page, including all the fields in the page. |
6a488035 | 374 | */ |
00be9182 | 375 | public function copy() { |
6a488035 TO |
376 | $gid = CRM_Utils_Request::retrieve('gid', 'Positive', |
377 | $this, TRUE, 0, 'GET' | |
378 | ); | |
379 | ||
380 | CRM_Contribute_BAO_ContributionPage::copy($gid); | |
381 | ||
382 | CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1')); | |
383 | } | |
384 | ||
385 | /** | |
fe482240 | 386 | * Browse all contribution pages. |
6a488035 | 387 | * |
4bf0b605 AH |
388 | * @param mixed $action |
389 | * Unused parameter. | |
6a488035 | 390 | */ |
00be9182 | 391 | public function browse($action = NULL) { |
6a488035 TO |
392 | $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', |
393 | 'String', | |
394 | $this | |
395 | ); | |
d121646d | 396 | // @todo Unused local variable can be safely removed. |
aa344a47 AH |
397 | // But are there any side effects of CRM_Utils_Request::retrieve() that we |
398 | // need to preserve? | |
6a488035 TO |
399 | $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', |
400 | $this, FALSE, 0 | |
401 | ); | |
402 | ||
2a81202b | 403 | if ($this->_sortByCharacter == 'all' || |
6a488035 TO |
404 | !empty($_POST) |
405 | ) { | |
406 | $this->_sortByCharacter = ''; | |
407 | $this->set('sortByCharacter', ''); | |
408 | } | |
409 | ||
410 | $this->search(); | |
411 | ||
412 | $params = array(); | |
413 | ||
414 | $whereClause = $this->whereClause($params, FALSE); | |
415 | $this->pagerAToZ($whereClause, $params); | |
416 | ||
417 | $params = array(); | |
418 | $whereClause = $this->whereClause($params, TRUE); | |
419 | $this->pager($whereClause, $params); | |
420 | ||
421 | list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); | |
422 | ||
423 | //check for delete CRM-4418 | |
424 | $allowToDelete = CRM_Core_Permission::check('delete in CiviContribute'); | |
425 | ||
426 | $query = " | |
427 | SELECT id | |
428 | FROM civicrm_contribution_page | |
429 | WHERE $whereClause | |
2a81202b | 430 | ORDER BY is_active desc, title asc |
6a488035 TO |
431 | LIMIT $offset, $rowCount"; |
432 | $contribPage = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage'); | |
433 | $contribPageIds = array(); | |
434 | while ($contribPage->fetch()) { | |
435 | $contribPageIds[$contribPage->id] = $contribPage->id; | |
436 | } | |
437 | //get all section info. | |
438 | $contriPageSectionInfo = CRM_Contribute_BAO_ContributionPage::getSectionInfo($contribPageIds); | |
439 | ||
440 | $query = " | |
441 | SELECT * | |
442 | FROM civicrm_contribution_page | |
443 | WHERE $whereClause | |
2a81202b | 444 | ORDER BY is_active desc, title asc |
6a488035 TO |
445 | LIMIT $offset, $rowCount"; |
446 | ||
447 | $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_ContributionPage'); | |
448 | ||
449 | //get all campaigns. | |
450 | $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); | |
451 | ||
452 | //get configure actions links. | |
453 | $configureActionLinks = self::configureActionLinks(); | |
454 | ||
455 | while ($dao->fetch()) { | |
456 | $contribution[$dao->id] = array(); | |
457 | CRM_Core_DAO::storeValues($dao, $contribution[$dao->id]); | |
458 | ||
459 | // form all action links | |
460 | $action = array_sum(array_keys($this->actionLinks())); | |
461 | ||
462 | //add configure actions links. | |
463 | $action += array_sum(array_keys($configureActionLinks)); | |
464 | ||
465 | //add online contribution links. | |
466 | $action += array_sum(array_keys(self::onlineContributionLinks())); | |
467 | ||
468 | //add contribution search links. | |
469 | $action += array_sum(array_keys(self::contributionLinks())); | |
470 | ||
471 | if ($dao->is_active) { | |
874c9be7 | 472 | $action -= (int) CRM_Core_Action::ENABLE; |
6a488035 TO |
473 | } |
474 | else { | |
874c9be7 | 475 | $action -= (int) CRM_Core_Action::DISABLE; |
6a488035 TO |
476 | } |
477 | ||
478 | //CRM-4418 | |
479 | if (!$allowToDelete) { | |
874c9be7 | 480 | $action -= (int) CRM_Core_Action::DELETE; |
6a488035 TO |
481 | } |
482 | ||
483 | //build the configure links. | |
484 | $sectionsInfo = CRM_Utils_Array::value($dao->id, $contriPageSectionInfo, array()); | |
485 | $contribution[$dao->id]['configureActionLinks'] = CRM_Core_Action::formLink(self::formatConfigureLinks($sectionsInfo), | |
486 | $action, | |
487 | array('id' => $dao->id), | |
488 | ts('Configure'), | |
87dab4a4 AH |
489 | TRUE, |
490 | 'contributionpage.configure.actions', | |
491 | 'ContributionPage', | |
492 | $dao->id | |
6a488035 TO |
493 | ); |
494 | ||
495 | //build the contributions links. | |
496 | $contribution[$dao->id]['contributionLinks'] = CRM_Core_Action::formLink(self::contributionLinks(), | |
497 | $action, | |
498 | array('id' => $dao->id), | |
499 | ts('Contributions'), | |
87dab4a4 AH |
500 | TRUE, |
501 | 'contributionpage.contributions.search', | |
502 | 'ContributionPage', | |
503 | $dao->id | |
6a488035 TO |
504 | ); |
505 | ||
506 | //build the online contribution links. | |
507 | $contribution[$dao->id]['onlineContributionLinks'] = CRM_Core_Action::formLink(self::onlineContributionLinks(), | |
508 | $action, | |
509 | array('id' => $dao->id), | |
510 | ts('Links'), | |
87dab4a4 AH |
511 | TRUE, |
512 | 'contributionpage.online.links', | |
513 | 'ContributionPage', | |
514 | $dao->id | |
6a488035 TO |
515 | ); |
516 | ||
517 | //build the normal action links. | |
518 | $contribution[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), | |
519 | $action, | |
520 | array('id' => $dao->id), | |
521 | ts('more'), | |
87dab4a4 AH |
522 | TRUE, |
523 | 'contributionpage.action.links', | |
524 | 'ContributionPage', | |
525 | $dao->id | |
6a488035 TO |
526 | ); |
527 | ||
528 | //show campaigns on selector. | |
529 | $contribution[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns); | |
530 | } | |
531 | ||
532 | if (isset($contribution)) { | |
533 | $this->assign('rows', $contribution); | |
534 | } | |
535 | } | |
536 | ||
00be9182 | 537 | public function search() { |
874c9be7 | 538 | if (isset($this->_action) & (CRM_Core_Action::ADD | |
6a488035 TO |
539 | CRM_Core_Action::UPDATE | |
540 | CRM_Core_Action::DELETE | |
541 | ) | |
542 | ) { | |
543 | return; | |
544 | } | |
545 | ||
546 | $form = new CRM_Core_Controller_Simple('CRM_Contribute_Form_SearchContribution', | |
547 | ts('Search Contribution'), | |
548 | CRM_Core_Action::ADD | |
549 | ); | |
550 | $form->setEmbedded(TRUE); | |
551 | $form->setParent($this); | |
552 | $form->process(); | |
553 | $form->run(); | |
554 | } | |
555 | ||
186c9c17 | 556 | /** |
c490a46a | 557 | * @param array $params |
186c9c17 EM |
558 | * @param bool $sortBy |
559 | * | |
560 | * @return int|string | |
561 | */ | |
00be9182 | 562 | public function whereClause(&$params, $sortBy = TRUE) { |
d121646d | 563 | // @todo Unused local variable can be safely removed. |
353ffa53 TO |
564 | $values = $clauses = array(); |
565 | $title = $this->get('title'); | |
6a488035 TO |
566 | $createdId = $this->get('cid'); |
567 | ||
568 | if ($createdId) { | |
569 | $clauses[] = "(created_id = {$createdId})"; | |
570 | } | |
571 | ||
572 | if ($title) { | |
573 | $clauses[] = "title LIKE %1"; | |
574 | if (strpos($title, '%') !== FALSE) { | |
575 | $params[1] = array(trim($title), 'String', FALSE); | |
576 | } | |
577 | else { | |
578 | $params[1] = array(trim($title), 'String', TRUE); | |
579 | } | |
580 | } | |
581 | ||
481a74f4 | 582 | $value = $this->get('financial_type_id'); |
6a488035 TO |
583 | $val = array(); |
584 | if ($value) { | |
585 | if (is_array($value)) { | |
586 | foreach ($value as $k => $v) { | |
587 | if ($v) { | |
588 | $val[$k] = $k; | |
589 | } | |
590 | } | |
591 | $type = implode(',', $val); | |
592 | } | |
d121646d | 593 | // @todo Variable 'type' might not have been defined. |
8b647c3a | 594 | $clauses[] = "financial_type_id IN ({$type})"; |
6a488035 TO |
595 | } |
596 | ||
8b647c3a | 597 | if ($sortBy && $this->_sortByCharacter !== NULL) { |
6a488035 TO |
598 | $clauses[] = "title LIKE '" . strtolower(CRM_Core_DAO::escapeWildCardString($this->_sortByCharacter)) . "%'"; |
599 | } | |
600 | ||
a64ad157 | 601 | $campaignIds = $this->getCampaignIds(); |
42f91903 | 602 | if (count($campaignIds) >= 1) { |
a64ad157 AH |
603 | $clauses[] = '( campaign_id IN ( ' . implode(' , ', $campaignIds) . ' ) )'; |
604 | } | |
6a488035 TO |
605 | |
606 | if (empty($clauses)) { | |
607 | // Let template know if user has run a search or not | |
608 | $this->assign('isSearch', 0); | |
609 | return 1; | |
610 | } | |
611 | else { | |
612 | $this->assign('isSearch', 1); | |
613 | } | |
614 | ||
615 | return implode(' AND ', $clauses); | |
616 | } | |
617 | ||
a64ad157 AH |
618 | /** |
619 | * Gets the campaign ids from the session. | |
620 | * | |
621 | * @return int[] | |
622 | */ | |
13efab9d | 623 | public function getCampaignIds() { |
a64ad157 AH |
624 | // The unfiltered value from the session cannot be trusted, it needs to be |
625 | // processed to get a clean array of positive integers. | |
626 | $ids = array(); | |
874c9be7 TO |
627 | foreach ((array) $this->get('campaign_id') as $id) { |
628 | if ((string) (int) $id === (string) $id && $id > 0) { | |
a64ad157 AH |
629 | $ids[] = $id; |
630 | } | |
631 | } | |
632 | return $ids; | |
633 | } | |
634 | ||
186c9c17 EM |
635 | /** |
636 | * @param $whereClause | |
100fef9d | 637 | * @param array $whereParams |
186c9c17 | 638 | */ |
a130e045 | 639 | public function pager($whereClause, $whereParams) { |
6a488035 TO |
640 | |
641 | $params['status'] = ts('Contribution %%StatusMessage%%'); | |
642 | $params['csvString'] = NULL; | |
643 | $params['buttonTop'] = 'PagerTopButton'; | |
644 | $params['buttonBottom'] = 'PagerBottomButton'; | |
645 | $params['rowCount'] = $this->get(CRM_Utils_Pager::PAGE_ROWCOUNT); | |
646 | if (!$params['rowCount']) { | |
647 | $params['rowCount'] = CRM_Utils_Pager::ROWCOUNT; | |
648 | } | |
649 | ||
650 | $query = " | |
651 | SELECT count(id) | |
8b647c3a AH |
652 | FROM civicrm_contribution_page |
653 | WHERE $whereClause"; | |
6a488035 TO |
654 | |
655 | $params['total'] = CRM_Core_DAO::singleValueQuery($query, $whereParams); | |
656 | ||
657 | $this->_pager = new CRM_Utils_Pager($params); | |
658 | $this->assign_by_ref('pager', $this->_pager); | |
659 | } | |
660 | ||
186c9c17 EM |
661 | /** |
662 | * @param $whereClause | |
100fef9d | 663 | * @param array $whereParams |
186c9c17 | 664 | */ |
00be9182 | 665 | public function pagerAtoZ($whereClause, $whereParams) { |
6a488035 TO |
666 | |
667 | $query = " | |
8b647c3a AH |
668 | SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name |
669 | FROM civicrm_contribution_page | |
670 | WHERE $whereClause | |
671 | ORDER BY LEFT(title, 1) | |
6a488035 TO |
672 | "; |
673 | $dao = CRM_Core_DAO::executeQuery($query, $whereParams); | |
674 | ||
675 | $aToZBar = CRM_Utils_PagerAToZ::getAToZBar($dao, $this->_sortByCharacter, TRUE); | |
676 | $this->assign('aToZ', $aToZBar); | |
677 | } | |
678 | ||
186c9c17 | 679 | /** |
8b647c3a | 680 | * @param array $sectionsInfo |
186c9c17 EM |
681 | * |
682 | * @return array | |
683 | */ | |
00be9182 | 684 | public function formatConfigureLinks($sectionsInfo) { |
8b647c3a | 685 | // build the formatted configure links. |
6a488035 TO |
686 | $formattedConfLinks = self::configureActionLinks(); |
687 | foreach ($formattedConfLinks as $act => & $link) { | |
688 | $sectionName = CRM_Utils_Array::value('uniqueName', $link); | |
689 | if (!$sectionName) { | |
690 | continue; | |
691 | } | |
692 | ||
a7488080 | 693 | if (empty($sectionsInfo[$sectionName])) { |
6a488035 TO |
694 | $classes = array(); |
695 | if (isset($link['class'])) { | |
696 | $classes = $link['class']; | |
697 | } | |
698 | $link['class'] = array_merge($classes, array('disabled')); | |
699 | } | |
700 | } | |
701 | ||
702 | return $formattedConfLinks; | |
703 | } | |
96025800 | 704 | |
6a488035 | 705 | } |