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