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