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