3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 $_recurLinks = NULL;
45 public $_permission = NULL;
46 public $_contactId = NULL;
52 * This method returns the links that are given for recur search row.
53 * currently the links added for each row are:
58 * @param bool $recurID
59 * @param string $context
64 static function &recurLinks($recurID = FALSE, $context = 'contribution') {
65 if (!(self
::$_links)) {
66 self
::$_links = array(
67 CRM_Core_Action
::VIEW
=> array(
69 'title' => ts('View Recurring Payment'),
70 'url' => 'civicrm/contact/view/contributionrecur',
71 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
73 CRM_Core_Action
::UPDATE
=> array(
75 'title' => ts('Edit Recurring Payment'),
76 'url' => 'civicrm/contribute/updaterecur',
77 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
79 CRM_Core_Action
::DISABLE
=> array(
80 'name' => ts('Cancel'),
81 'title' => ts('Cancel'),
82 'ref' => 'crm-enable-disable',
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}";
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}",
103 return self
::$_links;
108 * This function is called when action is browse
114 // add annual contribution
116 list($annual['count'],
119 ) = CRM_Contribute_BAO_Contribution
::annual($this->_contactId
);
120 $this->assign('annual', $annual);
122 $controller = new CRM_Core_Controller_Simple(
123 'CRM_Contribute_Form_Search',
128 $controller->setEmbedded(TRUE);
129 $controller->reset();
130 $controller->set('cid', $this->_contactId
);
131 $controller->set('crid', $this->_crid
);
132 $controller->set('context', 'Search');
133 $controller->set('limit', 50);
134 $controller->process();
137 // add recurring block
138 $action = array_sum(array_keys($this->recurLinks()));
139 $params = CRM_Contribute_BAO_ContributionRecur
::getRecurContributions($this->_contactId
);
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);
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
;
152 $action -= CRM_Core_Action
::UPDATE
;
155 $params[$ids]['action'] = CRM_Core_Action
::formLink(self
::recurLinks($ids), $action,
157 'cid' => $this->_contactId
,
159 'cxt' => 'contribution',
163 'contribution.selector.recurring',
169 // assign vars to templates
170 $this->assign('action', $this->_action
);
171 $this->assign('recurRows', $params);
172 $this->assign('recur', TRUE);
175 //enable/disable soft credit records for test contribution
177 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
180 $this->assign('isTest', $isTest);
182 $softCreditList = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionList($this->_contactId
, NULL, $isTest);
184 if (!empty($softCreditList)) {
185 $softCreditTotals = array();
187 list($softCreditTotals['amount'],
188 $softCreditTotals['avg'],
189 $softCreditTotals['currency']
190 ) = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionTotals($this->_contactId
, $isTest);
192 $this->assign('softCredit', TRUE);
193 $this->assign('softCreditRows', $softCreditList);
194 $this->assign('softCreditTotals', $softCreditTotals);
197 if ($this->_contactId
) {
198 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
199 $this->assign('displayName', $displayName);
200 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
);
205 * This function is called when action is view
211 $controller = new CRM_Core_Controller_Simple(
212 'CRM_Contribute_Form_ContributionView',
213 ts('View Contribution'),
216 $controller->setEmbedded(TRUE);
217 $controller->set('id', $this->_id
);
218 $controller->set('cid', $this->_contactId
);
220 return $controller->run();
224 * This function is called when action is update or new
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();
236 $controller = new CRM_Core_Controller_Simple(
237 'CRM_Contribute_Form_Contribution',
238 'Create Contribution',
241 $controller->setEmbedded(TRUE);
242 $controller->set('id', $this->_id
);
243 $controller->set('cid', $this->_contactId
);
245 return $controller->run();
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);
253 if ($context == 'standalone') {
254 $this->_action
= CRM_Core_Action
::ADD
;
257 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
258 $this->assign('contactId', $this->_contactId
);
260 // check logged in url permission
261 CRM_Contact_Page_View
::checkUserPermission($this);
264 CRM_Contact_Page_View
::setTitle($this->_contactId
);
266 $this->assign('action', $this->_action
);
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');
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.
285 // check if we can process credit card contribs
286 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
290 if ($this->_action
& CRM_Core_Action
::VIEW
) {
293 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
300 return parent
::run();
303 function setContext() {
304 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
305 $context = CRM_Utils_Request
::retrieve('context', 'String',
306 $this, FALSE, 'search'
308 $compContext = CRM_Utils_Request
::retrieve('compContext', 'String', $this);
310 $searchContext = CRM_Utils_Request
::retrieve('searchContext', 'String', $this);
313 if ($context == 'search' && $compContext) {
314 $context = $compContext;
320 // make sure we dont get tricked with a bad key
322 if (!CRM_Core_Key
::valid($qfKey)) {
326 $session = CRM_Core_Session
::singleton();
330 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
334 $url = CRM_Utils_System
::url('civicrm/contribute',
339 case 'pledgeDashboard':
340 $url = CRM_Utils_System
::url('civicrm/pledge',
346 $url = CRM_Utils_System
::url('civicrm/contact/view',
347 "reset=1&force=1&cid={$this->_contactId}&selectedChild=contribute"
353 $extraParams = "force=1";
355 $extraParams .= "&qfKey=$qfKey";
358 $this->assign('searchKey', $qfKey);
359 if ($context == 'advanced') {
360 $url = CRM_Utils_System
::url('civicrm/contact/search/advanced', $extraParams);
362 else if ($searchContext) {
363 $url = CRM_Utils_System
::url("civicrm/$searchContext/search", $extraParams);
366 $url = CRM_Utils_System
::url('civicrm/contribute/search', $extraParams);
371 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
375 $url = CRM_Utils_System
::url('civicrm/contact/view',
376 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
382 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
383 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
385 $context = 'membership';
390 $searchKey = "&key=$qfKey";
392 $compContext = "&compContext={$compContext}";
394 if ($componentAction & CRM_Core_Action
::VIEW
) {
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}"
406 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
407 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
409 $context = 'participant';
414 $searchKey = "&key=$qfKey";
416 $compContext = "&compContext={$compContext}";
418 if ($componentAction == CRM_Core_Action
::VIEW
) {
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}"
430 $url = CRM_Utils_System
::url('civicrm/contact/view',
431 "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge"
436 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
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
;
448 $urlParams .= '&context=fulltext&action=view';
449 $urlString = 'civicrm/contact/view/contribution';
452 $urlParams .= "$keyName=$qfKey";
454 $this->assign('searchKey', $qfKey);
455 $url = CRM_Utils_System
::url($urlString, $urlParams);
460 if ($this->_contactId
) {
461 $cid = '&cid=' . $this->_contactId
;
463 $url = CRM_Utils_System
::url('civicrm/contribute/search',
464 'reset=1&force=1' . $cid
469 $session = CRM_Core_Session
::singleton();
470 $session->pushUserContext($url);