3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
35 class CRM_Contribute_Page_Tab
extends CRM_Core_Page
{
38 * The action links that we need to display for the browse screen
43 static $_links = NULL;
44 static $_honorLinks = NULL;
45 static $_recurLinks = NULL;
46 public $_permission = NULL;
47 public $_contactId = NULL;
51 * This method returns the links that are given for honor search row.
52 * currently the links added for each row are
61 static function &honorLinks() {
62 if (!(self
::$_honorLinks)) {
63 self
::$_honorLinks = array(
64 CRM_Core_Action
::VIEW
=> array(
66 'url' => 'civicrm/contact/view/contribution',
67 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&action=view&context=%%cxt%%&selectedChild=contribute',
68 'title' => ts('View Contribution'),
70 CRM_Core_Action
::UPDATE
=> array(
72 'url' => 'civicrm/contact/view/contribution',
73 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&context=%%cxt%%&subType=%%contributionType%%',
74 'title' => ts('Edit Contribution'),
76 CRM_Core_Action
::DELETE
=> array(
77 'name' => ts('Delete'),
78 'url' => 'civicrm/contact/view/contribution',
79 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&honorId=%%honorId%%&context=%%cxt%%',
80 'title' => ts('Delete Contribution'),
84 return self
::$_honorLinks;
89 * This method returns the links that are given for recur search row.
90 * currently the links added for each row are:
99 static function &recurLinks($recurID = FALSE, $context = 'contribution') {
100 if (!(self
::$_links)) {
101 self
::$_links = array(
102 CRM_Core_Action
::VIEW
=> array(
103 'name' => ts('View'),
104 'title' => ts('View Recurring Payment'),
105 'url' => 'civicrm/contact/view/contributionrecur',
106 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
108 CRM_Core_Action
::UPDATE
=> array(
109 'name' => ts('Edit'),
110 'title' => ts('Edit Recurring Payment'),
111 'url' => 'civicrm/contribute/updaterecur',
112 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
114 CRM_Core_Action
::DISABLE
=> array(
115 'name' => ts('Cancel'),
116 'title' => ts('Cancel'),
117 'ref' => 'crm-enable-disable',
123 $paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recurID, 'recur', 'obj');
124 if (is_object( $paymentProcessorObj) && $paymentProcessorObj->isSupported('cancelSubscription')) {
125 unset(self
::$_links[CRM_Core_Action
::DISABLE
]['extra'], self
::$_links[CRM_Core_Action
::DISABLE
]['ref']);
126 self
::$_links[CRM_Core_Action
::DISABLE
]['url'] = "civicrm/contribute/unsubscribe";
127 self
::$_links[CRM_Core_Action
::DISABLE
]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
129 if (is_object( $paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) {
130 self
::$_links[CRM_Core_Action
::RENEW
] = array('name' => ts('Change Billing Details'),
131 'title' => ts('Change Billing Details'),
132 'url' => 'civicrm/contribute/updatebilling',
133 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
138 return self
::$_links;
143 * This function is called when action is browse
149 CRM_Core_Resources
::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js');
151 // add annual contribution
153 list($annual['count'],
156 ) = CRM_Contribute_BAO_Contribution
::annual($this->_contactId
);
157 $this->assign('annual', $annual);
159 $controller = new CRM_Core_Controller_Simple(
160 'CRM_Contribute_Form_Search',
165 $controller->setEmbedded(TRUE);
166 $controller->reset();
167 $controller->set('cid', $this->_contactId
);
168 $controller->set('crid', $this->_crid
);
169 $controller->set('context', 'Search');
170 $controller->set('limit', 50);
171 $controller->process();
174 // add recurring block
175 $action = array_sum(array_keys($this->recurLinks()));
176 $params = CRM_Contribute_BAO_ContributionRecur
::getRecurContributions($this->_contactId
);
178 if (!empty($params)) {
179 foreach ($params as $ids => $recur) {
180 $action = array_sum(array_keys($this->recurLinks($ids)));
181 // no action allowed if it's not active
182 $params[$ids]['is_active'] = ($recur['contribution_status_id'] != 3);
184 if ($params[$ids]['is_active']) {
185 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($params[$ids]['id'], 'recur');
186 $hideUpdate = $details->membership_id
& $details->auto_renew
;
189 $action -= CRM_Core_Action
::UPDATE
;
192 $params[$ids]['action'] = CRM_Core_Action
::formLink(self
::recurLinks($ids), $action,
194 'cid' => $this->_contactId
,
196 'cxt' => 'contribution',
200 'contribution.selector.recurring',
206 // assign vars to templates
207 $this->assign('action', $this->_action
);
208 $this->assign('recurRows', $params);
209 $this->assign('recur', TRUE);
213 // form all action links
214 $action = array_sum(array_keys($this->honorLinks()));
217 $params = CRM_Contribute_BAO_Contribution
::getHonorContacts($this->_contactId
);
218 if (!empty($params)) {
219 foreach ($params as $ids => $honorId) {
220 $params[$ids]['action'] = CRM_Core_Action
::formLink(
224 'cid' => $honorId['honorId'],
226 'cxt' => 'contribution',
227 'contributionType' => $honorId['type_id'],
228 'honorId' => $this->_contactId
,
232 'contribution.selector.honoree',
238 // assign vars to templates
239 $this->assign('action', $this->_action
);
240 $this->assign('honorRows', $params);
241 $this->assign('honor', TRUE);
244 //enable/disable soft credit records for test contribution
246 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
249 $this->assign('isTest', $isTest);
251 $softCreditList = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionList($this->_contactId
, $isTest);
253 if (!empty($softCreditList)) {
254 $softCreditTotals = array();
256 list($softCreditTotals['amount'],
257 $softCreditTotals['avg'],
258 $softCreditTotals['currency']
259 ) = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionTotals($this->_contactId
, $isTest);
261 $this->assign('softCredit', TRUE);
262 $this->assign('softCreditRows', $softCreditList);
263 $this->assign('softCreditTotals', $softCreditTotals);
266 if ($this->_contactId
) {
267 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
268 $this->assign('displayName', $displayName);
269 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
);
274 * This function is called when action is view
280 $controller = new CRM_Core_Controller_Simple(
281 'CRM_Contribute_Form_ContributionView',
282 ts('View Contribution'),
285 $controller->setEmbedded(TRUE);
286 $controller->set('id', $this->_id
);
287 $controller->set('cid', $this->_contactId
);
289 return $controller->run();
293 * This function is called when action is update or new
299 // set https for offline cc transaction
300 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
301 if ($mode == 'test' ||
$mode == 'live') {
302 CRM_Utils_System
::redirectToSSL();
305 $controller = new CRM_Core_Controller_Simple(
306 'CRM_Contribute_Form_Contribution',
307 'Create Contribution',
310 $controller->setEmbedded(TRUE);
311 $controller->set('id', $this->_id
);
312 $controller->set('cid', $this->_contactId
);
314 return $controller->run();
317 function preProcess() {
318 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
319 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
320 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
322 if ($context == 'standalone') {
323 $this->_action
= CRM_Core_Action
::ADD
;
326 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
327 $this->assign('contactId', $this->_contactId
);
329 // check logged in url permission
330 CRM_Contact_Page_View
::checkUserPermission($this);
333 CRM_Contact_Page_View
::setTitle($this->_contactId
);
335 $this->assign('action', $this->_action
);
337 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit contributions')) {
338 // demote to view since user does not have edit contrib rights
339 $this->_permission
= CRM_Core_Permission
::VIEW
;
340 $this->assign('permission', 'view');
345 * This function is the main function that is called when the page
346 * loads, it decides the which action has to be taken for the page.
354 // check if we can process credit card contribs
355 CRM_Core_Payment
::allowBackofficeCreditCard($this);
359 if ($this->_action
& CRM_Core_Action
::VIEW
) {
362 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
369 return parent
::run();
372 function setContext() {
373 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
374 $context = CRM_Utils_Request
::retrieve('context', 'String',
375 $this, FALSE, 'search'
377 $compContext = CRM_Utils_Request
::retrieve('compContext', 'String', $this);
380 if ($context == 'search' && $compContext) {
381 $context = $compContext;
387 // make sure we dont get tricked with a bad key
389 if (!CRM_Core_Key
::valid($qfKey)) {
393 $session = CRM_Core_Session
::singleton();
397 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
401 $url = CRM_Utils_System
::url('civicrm/contribute',
406 case 'pledgeDashboard':
407 $url = CRM_Utils_System
::url('civicrm/pledge',
413 $honorId = CRM_Utils_Request
::retrieve('honorId', 'Positive', $this, FALSE);
419 $cid = $this->_contactId
;
422 $url = CRM_Utils_System
::url('civicrm/contact/view',
423 "reset=1&force=1&cid={$cid}&selectedChild=contribute"
429 $extraParams = "force=1";
431 $extraParams .= "&qfKey=$qfKey";
434 $this->assign('searchKey', $qfKey);
435 if ($context == 'advanced') {
436 $url = CRM_Utils_System
::url('civicrm/contact/search/advanced', $extraParams);
439 $url = CRM_Utils_System
::url('civicrm/contribute/search', $extraParams);
444 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
448 $url = CRM_Utils_System
::url('civicrm/contact/view',
449 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
455 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
456 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
458 $context = 'membership';
463 $searchKey = "&key=$qfKey";
465 $compContext = "&compContext={$compContext}";
467 if ($componentAction & CRM_Core_Action
::VIEW
) {
473 $url = CRM_Utils_System
::url('civicrm/contact/view/membership',
474 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}"
479 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
480 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
482 $context = 'participant';
487 $searchKey = "&key=$qfKey";
489 $compContext = "&compContext={$compContext}";
491 if ($componentAction == CRM_Core_Action
::VIEW
) {
497 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
498 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}"
503 $url = CRM_Utils_System
::url('civicrm/contact/view',
504 "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge"
509 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
514 $urlParams = 'force=1';
515 $urlString = 'civicrm/contact/search/custom';
516 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
517 if ($this->_contactId
) {
518 $urlParams .= '&cid=' . $this->_contactId
;
521 $urlParams .= '&context=fulltext&action=view';
522 $urlString = 'civicrm/contact/view/contribution';
525 $urlParams .= "$keyName=$qfKey";
527 $this->assign('searchKey', $qfKey);
528 $url = CRM_Utils_System
::url($urlString, $urlParams);
533 if ($this->_contactId
) {
534 $cid = '&cid=' . $this->_contactId
;
536 $url = CRM_Utils_System
::url('civicrm/contribute/search',
537 'reset=1&force=1' . $cid
542 $session = CRM_Core_Session
::singleton();
543 $session->pushUserContext($url);