Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Contribute_Page_Tab extends CRM_Core_Page { | |
18 | ||
19 | /** | |
04d15518 | 20 | * The permission we have on this contact |
6a488035 | 21 | * |
04d15518 | 22 | * @var string |
6a488035 | 23 | */ |
6a488035 | 24 | public $_permission = NULL; |
04d15518 MWMC |
25 | |
26 | /** | |
27 | * The contact ID for the contributions we are acting on | |
28 | * @var int | |
29 | */ | |
6a488035 | 30 | public $_contactId = NULL; |
04d15518 MWMC |
31 | |
32 | /** | |
33 | * The recurring contribution ID (if any) | |
34 | * @var int | |
35 | */ | |
6a488035 TO |
36 | public $_crid = NULL; |
37 | ||
6a488035 TO |
38 | /** |
39 | * This method returns the links that are given for recur search row. | |
40 | * currently the links added for each row are: | |
41 | * - View | |
42 | * - Edit | |
43 | * - Cancel | |
44 | * | |
57ee0d9b | 45 | * @param int $recurID |
6c8f6e67 EM |
46 | * @param string $context |
47 | * | |
6a488035 | 48 | * @return array |
6a488035 | 49 | */ |
57ee0d9b | 50 | public static function recurLinks(int $recurID, $context = 'contribution') { |
2a7f3ed7 | 51 | $paymentProcessorObj = Civi\Payment\System::singleton()->getById(CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorID($recurID)); |
04d15518 MWMC |
52 | $links = [ |
53 | CRM_Core_Action::VIEW => [ | |
54 | 'name' => ts('View'), | |
55 | 'title' => ts('View Recurring Payment'), | |
56 | 'url' => 'civicrm/contact/view/contributionrecur', | |
57 | 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}", | |
58 | ], | |
2a7f3ed7 | 59 | ]; |
7d238e35 JJ |
60 | |
61 | $templateContribution = CRM_Contribute_BAO_ContributionRecur::getTemplateContribution($recurID); | |
2a7f3ed7 | 62 | if ( |
63 | (CRM_Core_Permission::check('edit contributions') || $context !== 'contribution') && | |
64 | ($paymentProcessorObj->supports('ChangeSubscriptionAmount') | |
65 | || $paymentProcessorObj->supports('EditRecurringContribution') | |
66 | )) { | |
67 | $links[CRM_Core_Action::UPDATE] = [ | |
04d15518 MWMC |
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}", | |
2a7f3ed7 | 72 | ]; |
73 | } | |
74 | ||
75 | $links[CRM_Core_Action::DISABLE] = [ | |
76 | 'name' => ts('Cancel'), | |
77 | 'title' => ts('Cancel'), | |
78 | 'ref' => 'crm-enable-disable', | |
04d15518 | 79 | ]; |
6a488035 | 80 | |
57ee0d9b | 81 | if ($paymentProcessorObj->supports('cancelRecurring')) { |
82 | unset($links[CRM_Core_Action::DISABLE]['extra'], $links[CRM_Core_Action::DISABLE]['ref']); | |
83 | $links[CRM_Core_Action::DISABLE]['url'] = "civicrm/contribute/unsubscribe"; | |
84 | $links[CRM_Core_Action::DISABLE]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}"; | |
85 | } | |
04d15518 | 86 | |
57ee0d9b | 87 | if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo')) { |
88 | $links[CRM_Core_Action::RENEW] = [ | |
89 | 'name' => ts('Change Billing Details'), | |
90 | 'title' => ts('Change Billing Details'), | |
91 | 'url' => 'civicrm/contribute/updatebilling', | |
92 | 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}", | |
93 | ]; | |
94 | } | |
b14db14b EM |
95 | if (!empty($templateContribution['id']) && $paymentProcessorObj->supportsEditRecurringContribution()) { |
96 | // Use constant CRM_Core_Action::PREVIEW as there is no such thing as view template. | |
97 | // And reusing view will mangle the actions. | |
98 | $links[CRM_Core_Action::PREVIEW] = [ | |
99 | 'name' => ts('View Template'), | |
100 | 'title' => ts('View Template Contribution'), | |
101 | 'url' => 'civicrm/contact/view/contribution', | |
102 | 'qs' => "reset=1&id={$templateContribution['id']}&cid=%%cid%%&action=view&context={$context}&force_create_template=1", | |
103 | ]; | |
104 | } | |
f68ea0a7 | 105 | |
04d15518 | 106 | return $links; |
6a488035 | 107 | } |
6a488035 | 108 | |
2d852c61 | 109 | /** |
110 | * Get the recur links to return for self service. | |
111 | * | |
112 | * These are the links to present to a logged in user wishing | |
113 | * to service their own | |
114 | * | |
115 | * @param int $recurID | |
116 | * | |
117 | * @return array|array[] | |
118 | * @throws \CRM_Core_Exception | |
119 | * @throws \CiviCRM_API3_Exception | |
120 | */ | |
121 | public static function selfServiceRecurLinks(int $recurID): array { | |
122 | $links = []; | |
123 | $paymentProcessorObj = Civi\Payment\System::singleton()->getById(CRM_Contribute_BAO_ContributionRecur::getPaymentProcessorID($recurID)); | |
124 | if ($paymentProcessorObj->supports('cancelRecurring') | |
125 | && $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'cancel') | |
126 | ) { | |
127 | $url = $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'cancel'); | |
128 | $links[CRM_Core_Action::DISABLE] = [ | |
129 | 'url' => $url, | |
130 | 'name' => ts('Cancel'), | |
131 | 'title' => ts('Cancel'), | |
132 | // Only display on-site links in a popup. | |
133 | 'class' => (stripos($url, 'http') !== FALSE) ? 'no-popup' : '', | |
134 | ]; | |
135 | } | |
136 | ||
137 | if ($paymentProcessorObj->supports('UpdateSubscriptionBillingInfo') | |
138 | && $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'billing') | |
139 | ) { | |
140 | $url = $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'billing'); | |
141 | $links[CRM_Core_Action::RENEW] = [ | |
142 | 'name' => ts('Change Billing Details'), | |
143 | 'title' => ts('Change Billing Details'), | |
144 | 'url' => $url, | |
145 | // Only display on-site links in a popup. | |
146 | 'class' => (stripos($url, 'http') !== FALSE) ? 'no-popup' : '', | |
147 | ]; | |
148 | } | |
149 | ||
150 | if (($paymentProcessorObj->supports('ChangeSubscriptionAmount') | |
151 | || $paymentProcessorObj->supports('EditRecurringContribution')) | |
152 | && $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'update') | |
153 | ) { | |
154 | $url = $paymentProcessorObj->subscriptionURL($recurID, 'recur', 'update'); | |
155 | $links[CRM_Core_Action::UPDATE] = [ | |
156 | 'name' => ts('Edit'), | |
157 | 'title' => ts('Edit Recurring Payment'), | |
158 | 'url' => $url, | |
159 | // Only display on-site links in a popup. | |
160 | 'class' => (stripos($url, 'http') !== FALSE) ? 'no-popup' : '', | |
161 | ]; | |
162 | } | |
163 | return $links; | |
164 | } | |
165 | ||
166 | /** | |
167 | * Get recurring links appropriate to viewing a user dashboard. | |
168 | * | |
169 | * A contact should be able to see links appropriate to them (e.g | |
170 | * payment processor cancel page) if viewing their own dashboard and | |
171 | * links appropriate to the contact they are viewing, if they have | |
172 | * permission, if viewing another user. | |
173 | * | |
174 | * @param int $recurID | |
175 | * @param int $contactID | |
176 | * | |
177 | * @return array|array[] | |
178 | * @throws \CRM_Core_Exception | |
179 | * @throws \CiviCRM_API3_Exception | |
180 | */ | |
181 | public static function dashboardRecurLinks(int $recurID, int $contactID): array { | |
182 | $links = []; | |
183 | if ($contactID && $contactID === CRM_Core_Session::getLoggedInContactID()) { | |
184 | $links = self::selfServiceRecurLinks($recurID); | |
185 | } | |
186 | $links += self::recurLinks($recurID, 'dashboard'); | |
187 | return $links; | |
188 | } | |
189 | ||
6a488035 | 190 | /** |
fe482240 | 191 | * called when action is browse. |
6a488035 | 192 | * |
6a488035 | 193 | */ |
00be9182 | 194 | public function browse() { |
6a488035 | 195 | // add annual contribution |
be2fb01f | 196 | $annual = []; |
2a7f3ed7 | 197 | [$annual['count'], $annual['amount'], $annual['avg']] = CRM_Contribute_BAO_Contribution::annual($this->_contactId); |
6a488035 TO |
198 | $this->assign('annual', $annual); |
199 | ||
200 | $controller = new CRM_Core_Controller_Simple( | |
201 | 'CRM_Contribute_Form_Search', | |
202 | ts('Contributions'), | |
203 | $this->_action, | |
204 | FALSE, FALSE, TRUE | |
205 | ); | |
206 | $controller->setEmbedded(TRUE); | |
207 | $controller->reset(); | |
208 | $controller->set('cid', $this->_contactId); | |
209 | $controller->set('crid', $this->_crid); | |
7a49693c | 210 | $controller->set('context', 'contribution'); |
c2874d9c | 211 | $controller->set('limit', 50); |
6a488035 TO |
212 | $controller->process(); |
213 | $controller->run(); | |
214 | ||
215 | // add recurring block | |
46097c9c MW |
216 | $this->addRecurringContributionsBlock(); |
217 | ||
218 | // enable/disable soft credit records for test contribution | |
219 | $isTest = 0; | |
220 | if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { | |
221 | $isTest = 1; | |
222 | } | |
223 | $this->assign('isTest', $isTest); | |
224 | ||
225 | $softCreditList = CRM_Contribute_BAO_ContributionSoft::getSoftContributionList($this->_contactId, NULL, $isTest); | |
226 | ||
227 | if (!empty($softCreditList)) { | |
be2fb01f | 228 | $softCreditTotals = []; |
46097c9c | 229 | |
d9c8c3c8 PF |
230 | list($softCreditTotals['count'], |
231 | $softCreditTotals['cancel']['count'], | |
232 | $softCreditTotals['amount'], | |
46097c9c | 233 | $softCreditTotals['avg'], |
1330f57a SL |
234 | // to get cancel amount |
235 | $softCreditTotals['cancel']['amount'] | |
46097c9c MW |
236 | ) = CRM_Contribute_BAO_ContributionSoft::getSoftContributionTotals($this->_contactId, $isTest); |
237 | ||
238 | $this->assign('softCredit', TRUE); | |
239 | $this->assign('softCreditRows', $softCreditList); | |
240 | $this->assign('softCreditTotals', $softCreditTotals); | |
241 | } | |
242 | ||
243 | if ($this->_contactId) { | |
244 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
245 | $this->assign('displayName', $displayName); | |
7255972e MWMC |
246 | $tabCount = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId); |
247 | $this->assign('tabCount', $tabCount); | |
248 | $this->ajaxResponse['tabCount'] = $tabCount; | |
46097c9c MW |
249 | } |
250 | } | |
251 | ||
252 | /** | |
253 | * Get all the recurring contribution information and assign to the template | |
254 | */ | |
255 | private function addRecurringContributionsBlock() { | |
2a7f3ed7 | 256 | [$activeContributions, $activeContributionsCount] = $this->getActiveRecurringContributions(); |
257 | [$inactiveRecurringContributions, $inactiveContributionsCount] = $this->getInactiveRecurringContributions(); | |
5963b706 CR |
258 | |
259 | if (!empty($activeContributions) || !empty($inactiveRecurringContributions)) { | |
260 | // assign vars to templates | |
261 | $this->assign('action', $this->_action); | |
262 | $this->assign('activeRecurRows', $activeContributions); | |
51e31e45 | 263 | $this->assign('contributionRecurCount', $activeContributionsCount + $inactiveContributionsCount); |
5963b706 CR |
264 | $this->assign('inactiveRecurRows', $inactiveRecurringContributions); |
265 | $this->assign('recur', TRUE); | |
266 | } | |
267 | } | |
268 | ||
269 | /** | |
270 | * Loads active recurring contributions for the current contact and formats | |
271 | * them to be used on the form. | |
272 | * | |
04d15518 | 273 | * @return array |
5963b706 CR |
274 | */ |
275 | private function getActiveRecurringContributions() { | |
9e475c2d | 276 | try { |
be2fb01f | 277 | $contributionRecurResult = civicrm_api3('ContributionRecur', 'get', [ |
9e475c2d | 278 | 'contact_id' => $this->_contactId, |
be2fb01f | 279 | 'contribution_status_id' => ['NOT IN' => CRM_Contribute_BAO_ContributionRecur::getInactiveStatuses()], |
0b3146b3 | 280 | 'options' => ['limit' => 0, 'sort' => 'is_test, start_date DESC'], |
be2fb01f | 281 | ]); |
9c1bc317 | 282 | $recurContributions = $contributionRecurResult['values'] ?? NULL; |
5963b706 CR |
283 | } |
284 | catch (Exception $e) { | |
be2fb01f | 285 | $recurContributions = []; |
5963b706 CR |
286 | } |
287 | ||
288 | return $this->buildRecurringContributionsArray($recurContributions); | |
289 | } | |
290 | ||
291 | /** | |
292 | * Loads inactive recurring contributions for the current contact and formats | |
293 | * them to be used on the form. | |
294 | * | |
04d15518 | 295 | * @return array |
5963b706 CR |
296 | */ |
297 | private function getInactiveRecurringContributions() { | |
9e475c2d | 298 | try { |
be2fb01f | 299 | $contributionRecurResult = civicrm_api3('ContributionRecur', 'get', [ |
9e475c2d | 300 | 'contact_id' => $this->_contactId, |
be2fb01f | 301 | 'contribution_status_id' => ['IN' => CRM_Contribute_BAO_ContributionRecur::getInactiveStatuses()], |
0b3146b3 | 302 | 'options' => ['limit' => 0, 'sort' => 'is_test, start_date DESC'], |
be2fb01f | 303 | ]); |
9c1bc317 | 304 | $recurContributions = $contributionRecurResult['values'] ?? NULL; |
9e475c2d MW |
305 | } |
306 | catch (Exception $e) { | |
307 | $recurContributions = NULL; | |
308 | } | |
6a488035 | 309 | |
5963b706 CR |
310 | return $this->buildRecurringContributionsArray($recurContributions); |
311 | } | |
6a488035 | 312 | |
5963b706 CR |
313 | /** |
314 | * @param $recurContributions | |
315 | * | |
04d15518 | 316 | * @return array |
5963b706 CR |
317 | */ |
318 | private function buildRecurringContributionsArray($recurContributions) { | |
e2ef9c65 | 319 | $liveRecurringContributionCount = 0; |
5963b706 | 320 | foreach ($recurContributions as $recurId => $recurDetail) { |
44c118da MWMC |
321 | // Is recurring contribution active? |
322 | $recurContributions[$recurId]['is_active'] = !in_array(CRM_Contribute_PseudoConstant::contributionStatus($recurDetail['contribution_status_id'], 'name'), CRM_Contribute_BAO_ContributionRecur::getInactiveStatuses()); | |
323 | if ($recurContributions[$recurId]['is_active']) { | |
57ee0d9b | 324 | $actionMask = array_sum(array_keys(self::recurLinks((int) $recurId))); |
44c118da MWMC |
325 | } |
326 | else { | |
327 | $actionMask = CRM_Core_Action::mask([CRM_Core_Permission::VIEW]); | |
328 | } | |
46097c9c | 329 | |
e2ef9c65 PN |
330 | if (empty($recurDetail['is_test'])) { |
331 | $liveRecurringContributionCount++; | |
332 | } | |
333 | ||
5963b706 CR |
334 | // Get the name of the payment processor |
335 | if (!empty($recurDetail['payment_processor_id'])) { | |
336 | $recurContributions[$recurId]['payment_processor'] = CRM_Financial_BAO_PaymentProcessor::getPaymentProcessorName($recurDetail['payment_processor_id']); | |
337 | } | |
338 | // Get the label for the contribution status | |
339 | if (!empty($recurDetail['contribution_status_id'])) { | |
340 | $recurContributions[$recurId]['contribution_status'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', $recurDetail['contribution_status_id']); | |
341 | } | |
6a488035 | 342 | |
57ee0d9b | 343 | $recurContributions[$recurId]['action'] = CRM_Core_Action::formLink(self::recurLinks((int) $recurId), $actionMask, |
be2fb01f | 344 | [ |
44c118da MWMC |
345 | 'cid' => $this->_contactId, |
346 | 'crid' => $recurId, | |
347 | 'cxt' => 'contribution', | |
be2fb01f | 348 | ], |
44c118da MWMC |
349 | ts('more'), |
350 | FALSE, | |
351 | 'contribution.selector.recurring', | |
352 | 'Contribution', | |
353 | $recurId | |
354 | ); | |
6a488035 | 355 | } |
5963b706 | 356 | |
e2ef9c65 | 357 | return [$recurContributions, $liveRecurringContributionCount]; |
6a488035 TO |
358 | } |
359 | ||
360 | /** | |
fe482240 | 361 | * called when action is view. |
6a488035 | 362 | * |
9e475c2d | 363 | * @return mixed |
6a488035 | 364 | */ |
00be9182 | 365 | public function view() { |
6a488035 TO |
366 | $controller = new CRM_Core_Controller_Simple( |
367 | 'CRM_Contribute_Form_ContributionView', | |
368 | ts('View Contribution'), | |
369 | $this->_action | |
370 | ); | |
371 | $controller->setEmbedded(TRUE); | |
372 | $controller->set('id', $this->_id); | |
373 | $controller->set('cid', $this->_contactId); | |
374 | ||
375 | return $controller->run(); | |
376 | } | |
377 | ||
378 | /** | |
fe482240 | 379 | * called when action is update or new. |
6a488035 | 380 | * |
9e475c2d MW |
381 | * @return mixed |
382 | * @throws \CRM_Core_Exception | |
383 | * @throws \Exception | |
6a488035 | 384 | */ |
00be9182 | 385 | public function edit() { |
6a488035 | 386 | // set https for offline cc transaction |
19046166 | 387 | $mode = CRM_Utils_Request::retrieve('mode', 'Alphanumeric', $this); |
6a488035 TO |
388 | if ($mode == 'test' || $mode == 'live') { |
389 | CRM_Utils_System::redirectToSSL(); | |
390 | } | |
391 | ||
392 | $controller = new CRM_Core_Controller_Simple( | |
393 | 'CRM_Contribute_Form_Contribution', | |
394 | 'Create Contribution', | |
395 | $this->_action | |
396 | ); | |
397 | $controller->setEmbedded(TRUE); | |
398 | $controller->set('id', $this->_id); | |
399 | $controller->set('cid', $this->_contactId); | |
400 | ||
401 | return $controller->run(); | |
402 | } | |
403 | ||
04d15518 MWMC |
404 | /** |
405 | * @throws \CRM_Core_Exception | |
406 | * @throws \CiviCRM_API3_Exception | |
407 | */ | |
00be9182 | 408 | public function preProcess() { |
edc80cda | 409 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this); |
6a488035 | 410 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
353ffa53 | 411 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
6a488035 TO |
412 | |
413 | if ($context == 'standalone') { | |
414 | $this->_action = CRM_Core_Action::ADD; | |
415 | } | |
416 | else { | |
f9009fe0 EM |
417 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, empty($this->_id)); |
418 | if (empty($this->_contactId)) { | |
be2fb01f | 419 | $this->_contactId = civicrm_api3('contribution', 'getvalue', [ |
1330f57a SL |
420 | 'id' => $this->_id, |
421 | 'return' => 'contact_id', | |
422 | ]); | |
f9009fe0 | 423 | } |
6a488035 TO |
424 | $this->assign('contactId', $this->_contactId); |
425 | ||
426 | // check logged in url permission | |
427 | CRM_Contact_Page_View::checkUserPermission($this); | |
6a488035 TO |
428 | } |
429 | $this->assign('action', $this->_action); | |
430 | ||
431 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit contributions')) { | |
432 | // demote to view since user does not have edit contrib rights | |
433 | $this->_permission = CRM_Core_Permission::VIEW; | |
434 | $this->assign('permission', 'view'); | |
435 | } | |
436 | } | |
437 | ||
438 | /** | |
dc195289 | 439 | * the main function that is called when the page |
6a488035 TO |
440 | * loads, it decides the which action has to be taken for the page. |
441 | * | |
04d15518 MWMC |
442 | * @throws \CRM_Core_Exception |
443 | * @throws \CiviCRM_API3_Exception | |
6a488035 | 444 | */ |
00be9182 | 445 | public function run() { |
6a488035 TO |
446 | $this->preProcess(); |
447 | ||
448 | // check if we can process credit card contribs | |
9be1374d | 449 | $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); |
6a488035 TO |
450 | |
451 | $this->setContext(); | |
452 | ||
453 | if ($this->_action & CRM_Core_Action::VIEW) { | |
454 | $this->view(); | |
455 | } | |
456 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
457 | $this->edit(); | |
458 | } | |
459 | else { | |
460 | $this->browse(); | |
461 | } | |
462 | ||
04d15518 | 463 | parent::run(); |
6a488035 TO |
464 | } |
465 | ||
04d15518 MWMC |
466 | /** |
467 | * @throws \CRM_Core_Exception | |
468 | */ | |
00be9182 | 469 | public function setContext() { |
6a488035 | 470 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); |
edc80cda | 471 | $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', |
6a488035 TO |
472 | $this, FALSE, 'search' |
473 | ); | |
474 | $compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this); | |
475 | ||
29571f63 AS |
476 | $searchContext = CRM_Utils_Request::retrieve('searchContext', 'String', $this); |
477 | ||
6a488035 TO |
478 | //swap the context. |
479 | if ($context == 'search' && $compContext) { | |
480 | $context = $compContext; | |
481 | } | |
482 | else { | |
483 | $compContext = NULL; | |
484 | } | |
485 | ||
486 | // make sure we dont get tricked with a bad key | |
487 | // so check format | |
488 | if (!CRM_Core_Key::valid($qfKey)) { | |
489 | $qfKey = NULL; | |
490 | } | |
491 | ||
6a488035 TO |
492 | switch ($context) { |
493 | case 'user': | |
494 | $url = CRM_Utils_System::url('civicrm/user', 'reset=1'); | |
495 | break; | |
496 | ||
497 | case 'dashboard': | |
498 | $url = CRM_Utils_System::url('civicrm/contribute', | |
499 | 'reset=1' | |
500 | ); | |
501 | break; | |
502 | ||
503 | case 'pledgeDashboard': | |
504 | $url = CRM_Utils_System::url('civicrm/pledge', | |
505 | 'reset=1' | |
506 | ); | |
507 | break; | |
508 | ||
509 | case 'contribution': | |
6a488035 | 510 | $url = CRM_Utils_System::url('civicrm/contact/view', |
8381af80 | 511 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=contribute" |
6a488035 TO |
512 | ); |
513 | break; | |
514 | ||
515 | case 'search': | |
516 | case 'advanced': | |
517 | $extraParams = "force=1"; | |
518 | if ($qfKey) { | |
519 | $extraParams .= "&qfKey=$qfKey"; | |
520 | } | |
521 | ||
522 | $this->assign('searchKey', $qfKey); | |
523 | if ($context == 'advanced') { | |
524 | $url = CRM_Utils_System::url('civicrm/contact/search/advanced', $extraParams); | |
525 | } | |
4c9b6178 | 526 | elseif ($searchContext) { |
29571f63 AS |
527 | $url = CRM_Utils_System::url("civicrm/$searchContext/search", $extraParams); |
528 | } | |
6a488035 TO |
529 | else { |
530 | $url = CRM_Utils_System::url('civicrm/contribute/search', $extraParams); | |
531 | } | |
532 | break; | |
533 | ||
534 | case 'home': | |
535 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
536 | break; | |
537 | ||
538 | case 'activity': | |
539 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
540 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity" | |
541 | ); | |
542 | break; | |
543 | ||
544 | case 'member': | |
545 | case 'membership': | |
546 | $componentId = CRM_Utils_Request::retrieve('compId', 'Positive', $this); | |
547 | $componentAction = CRM_Utils_Request::retrieve('compAction', 'Integer', $this); | |
548 | ||
549 | $context = 'membership'; | |
550 | $searchKey = NULL; | |
551 | if ($compContext) { | |
552 | $context = 'search'; | |
553 | if ($qfKey) { | |
554 | $searchKey = "&key=$qfKey"; | |
555 | } | |
556 | $compContext = "&compContext={$compContext}"; | |
557 | } | |
558 | if ($componentAction & CRM_Core_Action::VIEW) { | |
559 | $action = 'view'; | |
560 | } | |
561 | else { | |
562 | $action = 'update'; | |
563 | } | |
564 | $url = CRM_Utils_System::url('civicrm/contact/view/membership', | |
565 | "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}" | |
566 | ); | |
567 | break; | |
568 | ||
569 | case 'participant': | |
570 | $componentId = CRM_Utils_Request::retrieve('compId', 'Positive', $this); | |
571 | $componentAction = CRM_Utils_Request::retrieve('compAction', 'Integer', $this); | |
572 | ||
573 | $context = 'participant'; | |
574 | $searchKey = NULL; | |
575 | if ($compContext) { | |
576 | $context = 'search'; | |
577 | if ($qfKey) { | |
578 | $searchKey = "&key=$qfKey"; | |
579 | } | |
580 | $compContext = "&compContext={$compContext}"; | |
581 | } | |
582 | if ($componentAction == CRM_Core_Action::VIEW) { | |
583 | $action = 'view'; | |
584 | } | |
585 | else { | |
586 | $action = 'update'; | |
587 | } | |
588 | $url = CRM_Utils_System::url('civicrm/contact/view/participant', | |
589 | "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}" | |
590 | ); | |
591 | break; | |
592 | ||
593 | case 'pledge': | |
594 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
595 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge" | |
596 | ); | |
597 | break; | |
598 | ||
599 | case 'standalone': | |
600 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
601 | break; | |
602 | ||
603 | case 'fulltext': | |
353ffa53 | 604 | $keyName = '&qfKey'; |
6a488035 TO |
605 | $urlParams = 'force=1'; |
606 | $urlString = 'civicrm/contact/search/custom'; | |
607 | if ($this->_action == CRM_Core_Action::UPDATE) { | |
608 | if ($this->_contactId) { | |
609 | $urlParams .= '&cid=' . $this->_contactId; | |
610 | } | |
611 | $keyName = '&key'; | |
612 | $urlParams .= '&context=fulltext&action=view'; | |
613 | $urlString = 'civicrm/contact/view/contribution'; | |
614 | } | |
615 | if ($qfKey) { | |
616 | $urlParams .= "$keyName=$qfKey"; | |
617 | } | |
618 | $this->assign('searchKey', $qfKey); | |
619 | $url = CRM_Utils_System::url($urlString, $urlParams); | |
620 | break; | |
621 | ||
622 | default: | |
623 | $cid = NULL; | |
624 | if ($this->_contactId) { | |
625 | $cid = '&cid=' . $this->_contactId; | |
626 | } | |
627 | $url = CRM_Utils_System::url('civicrm/contribute/search', | |
628 | 'reset=1&force=1' . $cid | |
629 | ); | |
630 | break; | |
631 | } | |
632 | ||
633 | $session = CRM_Core_Session::singleton(); | |
634 | $session->pushUserContext($url); | |
635 | } | |
96025800 | 636 | |
6a488035 | 637 | } |