3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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;
50 * This method returns the links that are given for recur search row.
51 * currently the links added for each row are:
56 * @param bool $recurID
57 * @param string $context
62 static function &recurLinks($recurID = FALSE, $context = 'contribution') {
63 if (!(self
::$_links)) {
64 self
::$_links = array(
65 CRM_Core_Action
::VIEW
=> array(
67 'title' => ts('View Recurring Payment'),
68 'url' => 'civicrm/contact/view/contributionrecur',
69 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
71 CRM_Core_Action
::UPDATE
=> array(
73 'title' => ts('Edit Recurring Payment'),
74 'url' => 'civicrm/contribute/updaterecur',
75 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
77 CRM_Core_Action
::DISABLE
=> array(
78 'name' => ts('Cancel'),
79 'title' => ts('Cancel'),
80 'ref' => 'crm-enable-disable',
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}";
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}",
101 return self
::$_links;
106 * This function is called when action is browse
112 // add annual contribution
114 list($annual['count'],
117 ) = CRM_Contribute_BAO_Contribution
::annual($this->_contactId
);
118 $this->assign('annual', $annual);
120 $controller = new CRM_Core_Controller_Simple(
121 'CRM_Contribute_Form_Search',
126 $controller->setEmbedded(TRUE);
127 $controller->reset();
128 $controller->set('cid', $this->_contactId
);
129 $controller->set('crid', $this->_crid
);
130 $controller->set('context', 'contribution');
131 $controller->set('limit', 50);
132 $controller->process();
135 // add recurring block
136 $action = array_sum(array_keys($this->recurLinks()));
137 $params = CRM_Contribute_BAO_ContributionRecur
::getRecurContributions($this->_contactId
);
139 if (!empty($params)) {
140 foreach ($params as $ids => $recur) {
141 $action = array_sum(array_keys($this->recurLinks($ids)));
142 // no action allowed if it's not active
143 $params[$ids]['is_active'] = ($recur['contribution_status_id'] != 3);
145 if ($params[$ids]['is_active']) {
146 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($params[$ids]['id'], 'recur');
147 $hideUpdate = $details->membership_id
& $details->auto_renew
;
150 $action -= CRM_Core_Action
::UPDATE
;
153 $params[$ids]['action'] = CRM_Core_Action
::formLink(self
::recurLinks($ids), $action,
155 'cid' => $this->_contactId
,
157 'cxt' => 'contribution',
161 'contribution.selector.recurring',
167 // assign vars to templates
168 $this->assign('action', $this->_action
);
169 $this->assign('recurRows', $params);
170 $this->assign('recur', TRUE);
173 //enable/disable soft credit records for test contribution
175 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
178 $this->assign('isTest', $isTest);
180 $softCreditList = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionList($this->_contactId
, NULL, $isTest);
182 if (!empty($softCreditList)) {
183 $softCreditTotals = array();
185 list($softCreditTotals['amount'],
186 $softCreditTotals['avg'],
187 $softCreditTotals['currency']
188 ) = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionTotals($this->_contactId
, $isTest);
190 $this->assign('softCredit', TRUE);
191 $this->assign('softCreditRows', $softCreditList);
192 $this->assign('softCreditTotals', $softCreditTotals);
195 if ($this->_contactId
) {
196 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
197 $this->assign('displayName', $displayName);
198 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
);
203 * This function is called when action is view
209 $controller = new CRM_Core_Controller_Simple(
210 'CRM_Contribute_Form_ContributionView',
211 ts('View Contribution'),
214 $controller->setEmbedded(TRUE);
215 $controller->set('id', $this->_id
);
216 $controller->set('cid', $this->_contactId
);
218 return $controller->run();
222 * This function is called when action is update or new
228 // set https for offline cc transaction
229 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
230 if ($mode == 'test' ||
$mode == 'live') {
231 CRM_Utils_System
::redirectToSSL();
234 $controller = new CRM_Core_Controller_Simple(
235 'CRM_Contribute_Form_Contribution',
236 'Create Contribution',
239 $controller->setEmbedded(TRUE);
240 $controller->set('id', $this->_id
);
241 $controller->set('cid', $this->_contactId
);
243 return $controller->run();
246 function preProcess() {
247 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
248 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
249 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
251 if ($context == 'standalone') {
252 $this->_action
= CRM_Core_Action
::ADD
;
255 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, empty($this->_id
));
256 if (empty($this->_contactId
)) {
257 $this->_contactId
= civicrm_api3('contribution', 'getvalue', array('id' => $this->_id
, 'return' => 'contact_id'));
259 $this->assign('contactId', $this->_contactId
);
261 // check logged in url permission
262 CRM_Contact_Page_View
::checkUserPermission($this);
264 $this->assign('action', $this->_action
);
266 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit contributions')) {
267 // demote to view since user does not have edit contrib rights
268 $this->_permission
= CRM_Core_Permission
::VIEW
;
269 $this->assign('permission', 'view');
274 * This function is the main function that is called when the page
275 * loads, it decides the which action has to be taken for the page.
283 // check if we can process credit card contribs
284 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
288 if ($this->_action
& CRM_Core_Action
::VIEW
) {
291 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
298 return parent
::run();
301 function setContext() {
302 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
303 $context = CRM_Utils_Request
::retrieve('context', 'String',
304 $this, FALSE, 'search'
306 $compContext = CRM_Utils_Request
::retrieve('compContext', 'String', $this);
308 $searchContext = CRM_Utils_Request
::retrieve('searchContext', 'String', $this);
311 if ($context == 'search' && $compContext) {
312 $context = $compContext;
318 // make sure we dont get tricked with a bad key
320 if (!CRM_Core_Key
::valid($qfKey)) {
324 $session = CRM_Core_Session
::singleton();
328 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
332 $url = CRM_Utils_System
::url('civicrm/contribute',
337 case 'pledgeDashboard':
338 $url = CRM_Utils_System
::url('civicrm/pledge',
344 $url = CRM_Utils_System
::url('civicrm/contact/view',
345 "reset=1&force=1&cid={$this->_contactId}&selectedChild=contribute"
351 $extraParams = "force=1";
353 $extraParams .= "&qfKey=$qfKey";
356 $this->assign('searchKey', $qfKey);
357 if ($context == 'advanced') {
358 $url = CRM_Utils_System
::url('civicrm/contact/search/advanced', $extraParams);
360 else if ($searchContext) {
361 $url = CRM_Utils_System
::url("civicrm/$searchContext/search", $extraParams);
364 $url = CRM_Utils_System
::url('civicrm/contribute/search', $extraParams);
369 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
373 $url = CRM_Utils_System
::url('civicrm/contact/view',
374 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
380 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
381 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
383 $context = 'membership';
388 $searchKey = "&key=$qfKey";
390 $compContext = "&compContext={$compContext}";
392 if ($componentAction & CRM_Core_Action
::VIEW
) {
398 $url = CRM_Utils_System
::url('civicrm/contact/view/membership',
399 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}"
404 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
405 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
407 $context = 'participant';
412 $searchKey = "&key=$qfKey";
414 $compContext = "&compContext={$compContext}";
416 if ($componentAction == CRM_Core_Action
::VIEW
) {
422 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
423 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}"
428 $url = CRM_Utils_System
::url('civicrm/contact/view',
429 "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge"
434 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
439 $urlParams = 'force=1';
440 $urlString = 'civicrm/contact/search/custom';
441 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
442 if ($this->_contactId
) {
443 $urlParams .= '&cid=' . $this->_contactId
;
446 $urlParams .= '&context=fulltext&action=view';
447 $urlString = 'civicrm/contact/view/contribution';
450 $urlParams .= "$keyName=$qfKey";
452 $this->assign('searchKey', $qfKey);
453 $url = CRM_Utils_System
::url($urlString, $urlParams);
458 if ($this->_contactId
) {
459 $cid = '&cid=' . $this->_contactId
;
461 $url = CRM_Utils_System
::url('civicrm/contribute/search',
462 'reset=1&force=1' . $cid
467 $session = CRM_Core_Session
::singleton();
468 $session->pushUserContext($url);