Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | class CRM_Contribute_Page_Tab extends CRM_Core_Page { | |
36 | ||
37 | /** | |
38 | * The action links that we need to display for the browse screen | |
39 | * | |
40 | * @var array | |
41 | * @static | |
42 | */ | |
43 | static $_links = NULL; | |
44 | static $_honorLinks = NULL; | |
45 | static $_recurLinks = NULL; | |
46 | public $_permission = NULL; | |
47 | public $_contactId = NULL; | |
48 | public $_crid = NULL; | |
49 | ||
50 | /** | |
51 | * This method returns the links that are given for honor search row. | |
52 | * currently the links added for each row are | |
53 | * | |
54 | * - View | |
55 | * - Edit | |
56 | * | |
57 | * @return array | |
58 | * @access public | |
59 | * | |
60 | */ | |
61 | static function &honorLinks() { | |
62 | if (!(self::$_honorLinks)) { | |
63 | self::$_honorLinks = array( | |
64 | CRM_Core_Action::VIEW => array( | |
65 | 'name' => ts('View'), | |
66 | 'url' => 'civicrm/contact/view/contribution', | |
67 | 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&action=view&context=%%cxt%%&selectedChild=contribute', | |
68 | 'title' => ts('View Contribution'), | |
69 | ), | |
70 | CRM_Core_Action::UPDATE => array( | |
71 | 'name' => ts('Edit'), | |
72 | 'url' => 'civicrm/contact/view/contribution', | |
73 | 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&context=%%cxt%%&subType=%%contributionType%%', | |
74 | 'title' => ts('Edit Contribution'), | |
75 | ), | |
76 | CRM_Core_Action::DELETE => array( | |
77 | 'name' => ts('Delete'), | |
78 | 'url' => 'civicrm/contact/view/contribution', | |
79 | 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&context=%%cxt%%', | |
80 | 'title' => ts('Delete Contribution'), | |
81 | ), | |
82 | ); | |
83 | } | |
84 | return self::$_honorLinks; | |
85 | } | |
86 | //end of function | |
87 | ||
88 | /** | |
89 | * This method returns the links that are given for recur search row. | |
90 | * currently the links added for each row are: | |
91 | * - View | |
92 | * - Edit | |
93 | * - Cancel | |
94 | * | |
95 | * @return array | |
96 | * @access public | |
97 | * | |
98 | */ | |
99 | static function &recurLinks($recurID = FALSE, $context = 'contribution') { | |
100 | if (!(self::$_links)) { | |
101 | self::$_links = array( | |
102 | CRM_Core_Action::VIEW => array( | |
103 | 'name' => ts('View'), | |
104 | 'title' => ts('View Recurring Payment'), | |
105 | 'url' => 'civicrm/contact/view/contributionrecur', | |
106 | 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}", | |
107 | ), | |
108 | CRM_Core_Action::UPDATE => array( | |
109 | 'name' => ts('Edit'), | |
110 | 'title' => ts('Edit Recurring Payment'), | |
111 | 'url' => 'civicrm/contribute/updaterecur', | |
112 | 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}", | |
113 | ), | |
114 | CRM_Core_Action::DISABLE => array( | |
115 | 'name' => ts('Cancel'), | |
116 | 'title' => ts('Cancel'), | |
117 | 'extra' => 'onclick = "enableDisable( %%crid%%,\'' . 'CRM_Contribute_BAO_ContributionRecur' . '\',\'' . 'enable-disable' . '\' );"', | |
118 | 'ref' => 'disable-action', | |
119 | ), | |
120 | ); | |
121 | } | |
122 | ||
123 | if ($recurID) { | |
124 | $paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor::getProcessorForEntity($recurID, 'recur', 'obj'); | |
125 | if (is_object( $paymentProcessorObj) && $paymentProcessorObj->isSupported('cancelSubscription')) { | |
126 | unset(self::$_links[CRM_Core_Action::DISABLE]['extra'], self::$_links[CRM_Core_Action::DISABLE]['ref']); | |
127 | self::$_links[CRM_Core_Action::DISABLE]['url'] = "civicrm/contribute/unsubscribe"; | |
128 | self::$_links[CRM_Core_Action::DISABLE]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}"; | |
129 | } | |
130 | if (is_object( $paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) { | |
131 | self::$_links[CRM_Core_Action::RENEW] = array('name' => ts('Change Billing Details'), | |
132 | 'title' => ts('Change Billing Details'), | |
133 | 'url' => 'civicrm/contribute/updatebilling', | |
134 | 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}", | |
135 | ); | |
136 | } | |
137 | } | |
138 | ||
139 | return self::$_links; | |
140 | } | |
141 | // end function | |
142 | ||
143 | /** | |
144 | * This function is called when action is browse | |
145 | * | |
146 | * return null | |
147 | * @access public | |
148 | */ | |
149 | function browse() { | |
150 | ||
151 | // add annual contribution | |
152 | $annual = array(); | |
153 | list($annual['count'], | |
154 | $annual['amount'], | |
155 | $annual['avg'] | |
156 | ) = CRM_Contribute_BAO_Contribution::annual($this->_contactId); | |
157 | $this->assign('annual', $annual); | |
158 | ||
159 | $controller = new CRM_Core_Controller_Simple( | |
160 | 'CRM_Contribute_Form_Search', | |
161 | ts('Contributions'), | |
162 | $this->_action, | |
163 | FALSE, FALSE, TRUE | |
164 | ); | |
165 | $controller->setEmbedded(TRUE); | |
166 | $controller->reset(); | |
167 | $controller->set('cid', $this->_contactId); | |
168 | $controller->set('crid', $this->_crid); | |
169 | $controller->set('context', 'contribution'); | |
170 | $controller->process(); | |
171 | $controller->run(); | |
172 | ||
173 | // add recurring block | |
174 | $action = array_sum(array_keys($this->recurLinks())); | |
175 | $params = CRM_Contribute_BAO_ContributionRecur::getRecurContributions($this->_contactId); | |
176 | ||
177 | if (!empty($params)) { | |
178 | foreach ($params as $ids => $recur) { | |
179 | $action = array_sum(array_keys($this->recurLinks($ids))); | |
180 | // no action allowed if it's not active | |
181 | $params[$ids]['is_active'] = ($recur['contribution_status_id'] != 3); | |
182 | ||
183 | if ($params[$ids]['is_active']) { | |
184 | $details = CRM_Contribute_BAO_ContributionRecur::getSubscriptionDetails($params[$ids]['id'], 'recur'); | |
185 | $hideUpdate = $details->membership_id & $details->auto_renew; | |
186 | ||
187 | if ($hideUpdate) { | |
188 | $action -= CRM_Core_Action::UPDATE; | |
189 | } | |
190 | ||
191 | $params[$ids]['action'] = CRM_Core_Action::formLink(self::recurLinks($ids), $action, | |
192 | array( | |
193 | 'cid' => $this->_contactId, | |
194 | 'crid' => $ids, | |
195 | 'cxt' => 'contribution', | |
196 | ) | |
197 | ); | |
198 | } | |
199 | } | |
200 | // assign vars to templates | |
201 | $this->assign('action', $this->_action); | |
202 | $this->assign('recurRows', $params); | |
203 | $this->assign('recur', TRUE); | |
204 | } | |
205 | ||
206 | //add honor block | |
207 | // form all action links | |
208 | $action = array_sum(array_keys($this->honorLinks())); | |
209 | ||
210 | $params = array(); | |
211 | $params = CRM_Contribute_BAO_Contribution::getHonorContacts($this->_contactId); | |
212 | if (!empty($params)) { | |
213 | foreach ($params as $ids => $honorId) { | |
214 | $params[$ids]['action'] = CRM_Core_Action::formLink( | |
215 | self::honorLinks(), | |
216 | $action, | |
217 | array( | |
218 | 'cid' => $honorId['honorId'], | |
219 | 'id' => $ids, | |
220 | 'cxt' => 'contribution', | |
221 | 'contributionType' => $honorId['type_id'], | |
222 | 'honorId' => $this->_contactId, | |
223 | ) | |
224 | ); | |
225 | } | |
226 | ||
227 | // assign vars to templates | |
228 | $this->assign('action', $this->_action); | |
229 | $this->assign('honorRows', $params); | |
230 | $this->assign('honor', TRUE); | |
231 | } | |
232 | ||
233 | //enable/disable soft credit records for test contribution | |
234 | $isTest = 0; | |
235 | if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { | |
236 | $isTest = 1; | |
237 | } | |
238 | $this->assign('isTest', $isTest); | |
239 | ||
6dcc4d9d | 240 | $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, $isTest); |
6a488035 TO |
241 | |
242 | if (!empty($softCreditList)) { | |
243 | $softCreditTotals = array(); | |
244 | ||
245 | list($softCreditTotals['amount'], | |
246 | $softCreditTotals['avg'], | |
247 | $softCreditTotals['currency'] | |
6dcc4d9d | 248 | ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest); |
6a488035 TO |
249 | |
250 | $this->assign('softCredit', TRUE); | |
251 | $this->assign('softCreditRows', $softCreditList); | |
252 | $this->assign('softCreditTotals', $softCreditTotals); | |
253 | } | |
254 | ||
255 | if ($this->_contactId) { | |
256 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
257 | $this->assign('displayName', $displayName); | |
258 | } | |
259 | } | |
260 | ||
261 | /** | |
262 | * This function is called when action is view | |
263 | * | |
264 | * return null | |
265 | * @access public | |
266 | */ | |
267 | function view() { | |
268 | $controller = new CRM_Core_Controller_Simple( | |
269 | 'CRM_Contribute_Form_ContributionView', | |
270 | ts('View Contribution'), | |
271 | $this->_action | |
272 | ); | |
273 | $controller->setEmbedded(TRUE); | |
274 | $controller->set('id', $this->_id); | |
275 | $controller->set('cid', $this->_contactId); | |
276 | ||
277 | return $controller->run(); | |
278 | } | |
279 | ||
280 | /** | |
281 | * This function is called when action is update or new | |
282 | * | |
283 | * return null | |
284 | * @access public | |
285 | */ | |
286 | function edit() { | |
287 | // set https for offline cc transaction | |
288 | $mode = CRM_Utils_Request::retrieve('mode', 'String', $this); | |
289 | if ($mode == 'test' || $mode == 'live') { | |
290 | CRM_Utils_System::redirectToSSL(); | |
291 | } | |
292 | ||
293 | $controller = new CRM_Core_Controller_Simple( | |
294 | 'CRM_Contribute_Form_Contribution', | |
295 | 'Create Contribution', | |
296 | $this->_action | |
297 | ); | |
298 | $controller->setEmbedded(TRUE); | |
299 | $controller->set('id', $this->_id); | |
300 | $controller->set('cid', $this->_contactId); | |
301 | ||
302 | return $controller->run(); | |
303 | } | |
304 | ||
305 | function preProcess() { | |
306 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); | |
307 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); | |
308 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); | |
309 | ||
310 | if ($context == 'standalone') { | |
311 | $this->_action = CRM_Core_Action::ADD; | |
312 | } | |
313 | else { | |
314 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
315 | $this->assign('contactId', $this->_contactId); | |
316 | ||
317 | // check logged in url permission | |
318 | CRM_Contact_Page_View::checkUserPermission($this); | |
319 | ||
320 | // set page title | |
321 | CRM_Contact_Page_View::setTitle($this->_contactId); | |
322 | } | |
323 | $this->assign('action', $this->_action); | |
324 | ||
325 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit contributions')) { | |
326 | // demote to view since user does not have edit contrib rights | |
327 | $this->_permission = CRM_Core_Permission::VIEW; | |
328 | $this->assign('permission', 'view'); | |
329 | } | |
330 | } | |
331 | ||
332 | /** | |
333 | * This function is the main function that is called when the page | |
334 | * loads, it decides the which action has to be taken for the page. | |
335 | * | |
336 | * return null | |
337 | * @access public | |
338 | */ | |
339 | function run() { | |
340 | $this->preProcess(); | |
341 | ||
342 | // check if we can process credit card contribs | |
343 | CRM_Core_Payment::allowBackofficeCreditCard($this); | |
344 | ||
345 | $this->setContext(); | |
346 | ||
347 | if ($this->_action & CRM_Core_Action::VIEW) { | |
348 | $this->view(); | |
349 | } | |
350 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
351 | $this->edit(); | |
352 | } | |
353 | else { | |
354 | $this->browse(); | |
355 | } | |
356 | ||
357 | return parent::run(); | |
358 | } | |
359 | ||
360 | function setContext() { | |
361 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); | |
362 | $context = CRM_Utils_Request::retrieve('context', 'String', | |
363 | $this, FALSE, 'search' | |
364 | ); | |
365 | $compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this); | |
366 | ||
367 | //swap the context. | |
368 | if ($context == 'search' && $compContext) { | |
369 | $context = $compContext; | |
370 | } | |
371 | else { | |
372 | $compContext = NULL; | |
373 | } | |
374 | ||
375 | // make sure we dont get tricked with a bad key | |
376 | // so check format | |
377 | if (!CRM_Core_Key::valid($qfKey)) { | |
378 | $qfKey = NULL; | |
379 | } | |
380 | ||
381 | $session = CRM_Core_Session::singleton(); | |
382 | ||
383 | switch ($context) { | |
384 | case 'user': | |
385 | $url = CRM_Utils_System::url('civicrm/user', 'reset=1'); | |
386 | break; | |
387 | ||
388 | case 'dashboard': | |
389 | $url = CRM_Utils_System::url('civicrm/contribute', | |
390 | 'reset=1' | |
391 | ); | |
392 | break; | |
393 | ||
394 | case 'pledgeDashboard': | |
395 | $url = CRM_Utils_System::url('civicrm/pledge', | |
396 | 'reset=1' | |
397 | ); | |
398 | break; | |
399 | ||
400 | case 'contribution': | |
401 | $honorId = CRM_Utils_Request::retrieve('honorId', 'Positive', $this, FALSE); | |
402 | ||
403 | if ($honorId) { | |
404 | $cid = $honorId; | |
405 | } | |
406 | else { | |
407 | $cid = $this->_contactId; | |
408 | } | |
409 | ||
410 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
411 | "reset=1&force=1&cid={$cid}&selectedChild=contribute" | |
412 | ); | |
413 | break; | |
414 | ||
415 | case 'search': | |
416 | case 'advanced': | |
417 | $extraParams = "force=1"; | |
418 | if ($qfKey) { | |
419 | $extraParams .= "&qfKey=$qfKey"; | |
420 | } | |
421 | ||
422 | $this->assign('searchKey', $qfKey); | |
423 | if ($context == 'advanced') { | |
424 | $url = CRM_Utils_System::url('civicrm/contact/search/advanced', $extraParams); | |
425 | } | |
426 | else { | |
427 | $url = CRM_Utils_System::url('civicrm/contribute/search', $extraParams); | |
428 | } | |
429 | break; | |
430 | ||
431 | case 'home': | |
432 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
433 | break; | |
434 | ||
435 | case 'activity': | |
436 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
437 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity" | |
438 | ); | |
439 | break; | |
440 | ||
441 | case 'member': | |
442 | case 'membership': | |
443 | $componentId = CRM_Utils_Request::retrieve('compId', 'Positive', $this); | |
444 | $componentAction = CRM_Utils_Request::retrieve('compAction', 'Integer', $this); | |
445 | ||
446 | $context = 'membership'; | |
447 | $searchKey = NULL; | |
448 | if ($compContext) { | |
449 | $context = 'search'; | |
450 | if ($qfKey) { | |
451 | $searchKey = "&key=$qfKey"; | |
452 | } | |
453 | $compContext = "&compContext={$compContext}"; | |
454 | } | |
455 | if ($componentAction & CRM_Core_Action::VIEW) { | |
456 | $action = 'view'; | |
457 | } | |
458 | else { | |
459 | $action = 'update'; | |
460 | } | |
461 | $url = CRM_Utils_System::url('civicrm/contact/view/membership', | |
462 | "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}" | |
463 | ); | |
464 | break; | |
465 | ||
466 | case 'participant': | |
467 | $componentId = CRM_Utils_Request::retrieve('compId', 'Positive', $this); | |
468 | $componentAction = CRM_Utils_Request::retrieve('compAction', 'Integer', $this); | |
469 | ||
470 | $context = 'participant'; | |
471 | $searchKey = NULL; | |
472 | if ($compContext) { | |
473 | $context = 'search'; | |
474 | if ($qfKey) { | |
475 | $searchKey = "&key=$qfKey"; | |
476 | } | |
477 | $compContext = "&compContext={$compContext}"; | |
478 | } | |
479 | if ($componentAction == CRM_Core_Action::VIEW) { | |
480 | $action = 'view'; | |
481 | } | |
482 | else { | |
483 | $action = 'update'; | |
484 | } | |
485 | $url = CRM_Utils_System::url('civicrm/contact/view/participant', | |
486 | "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}" | |
487 | ); | |
488 | break; | |
489 | ||
490 | case 'pledge': | |
491 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
492 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge" | |
493 | ); | |
494 | break; | |
495 | ||
496 | case 'standalone': | |
497 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
498 | break; | |
499 | ||
500 | case 'fulltext': | |
501 | $keyName = '&qfKey'; | |
502 | $urlParams = 'force=1'; | |
503 | $urlString = 'civicrm/contact/search/custom'; | |
504 | if ($this->_action == CRM_Core_Action::UPDATE) { | |
505 | if ($this->_contactId) { | |
506 | $urlParams .= '&cid=' . $this->_contactId; | |
507 | } | |
508 | $keyName = '&key'; | |
509 | $urlParams .= '&context=fulltext&action=view'; | |
510 | $urlString = 'civicrm/contact/view/contribution'; | |
511 | } | |
512 | if ($qfKey) { | |
513 | $urlParams .= "$keyName=$qfKey"; | |
514 | } | |
515 | $this->assign('searchKey', $qfKey); | |
516 | $url = CRM_Utils_System::url($urlString, $urlParams); | |
517 | break; | |
518 | ||
519 | default: | |
520 | $cid = NULL; | |
521 | if ($this->_contactId) { | |
522 | $cid = '&cid=' . $this->_contactId; | |
523 | } | |
524 | $url = CRM_Utils_System::url('civicrm/contribute/search', | |
525 | 'reset=1&force=1' . $cid | |
526 | ); | |
527 | break; | |
528 | } | |
529 | ||
530 | $session = CRM_Core_Session::singleton(); | |
531 | $session->pushUserContext($url); | |
532 | } | |
533 | } | |
534 |