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