3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
33 class CRM_Contribute_Page_Tab
extends CRM_Core_Page
{
36 * The action links that we need to display for the browse screen.
40 static $_links = NULL;
41 static $_recurLinks = NULL;
42 public $_permission = NULL;
43 public $_contactId = NULL;
47 * Array with statuses that mark a recurring contribution as inactive.
51 private $inactiveStatuses = array('Cancelled', 'Chargeback', 'Refunded', 'Completed');
54 * This method returns the links that are given for recur search row.
55 * currently the links added for each row are:
60 * @param bool $recurID
61 * @param string $context
65 public static function &recurLinks($recurID = FALSE, $context = 'contribution') {
66 if (!(self
::$_links)) {
67 self
::$_links = array(
68 CRM_Core_Action
::VIEW
=> array(
70 'title' => ts('View Recurring Payment'),
71 'url' => 'civicrm/contact/view/contributionrecur',
72 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
74 CRM_Core_Action
::UPDATE
=> array(
76 'title' => ts('Edit Recurring Payment'),
77 'url' => 'civicrm/contribute/updaterecur',
78 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
80 CRM_Core_Action
::DISABLE
=> array(
81 'name' => ts('Cancel'),
82 'title' => ts('Cancel'),
83 'ref' => 'crm-enable-disable',
89 $links = self
::$_links;
90 $paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recurID, 'recur', 'obj');
91 if (is_object($paymentProcessorObj) && $paymentProcessorObj->supports('cancelRecurring')) {
92 unset($links[CRM_Core_Action
::DISABLE
]['extra'], $links[CRM_Core_Action
::DISABLE
]['ref']);
93 $links[CRM_Core_Action
::DISABLE
]['url'] = "civicrm/contribute/unsubscribe";
94 $links[CRM_Core_Action
::DISABLE
]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
97 if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) {
98 $links[CRM_Core_Action
::RENEW
] = array(
99 'name' => ts('Change Billing Details'),
100 'title' => ts('Change Billing Details'),
101 'url' => 'civicrm/contribute/updatebilling',
102 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
108 return self
::$_links;
112 * called when action is browse.
115 public function browse() {
116 // add annual contribution
118 list($annual['count'],
121 ) = CRM_Contribute_BAO_Contribution
::annual($this->_contactId
);
122 $this->assign('annual', $annual);
124 $controller = new CRM_Core_Controller_Simple(
125 'CRM_Contribute_Form_Search',
130 $controller->setEmbedded(TRUE);
131 $controller->reset();
132 $controller->set('cid', $this->_contactId
);
133 $controller->set('crid', $this->_crid
);
134 $controller->set('context', 'contribution');
135 $controller->set('limit', 50);
136 $controller->process();
139 // add recurring block
140 $this->addRecurringContributionsBlock();
142 // enable/disable soft credit records for test contribution
144 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
147 $this->assign('isTest', $isTest);
149 $softCreditList = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionList($this->_contactId
, NULL, $isTest);
151 if (!empty($softCreditList)) {
152 $softCreditTotals = array();
154 list($softCreditTotals['amount'],
155 $softCreditTotals['avg'],
156 $softCreditTotals['currency'],
157 $softCreditTotals['cancelAmount'] // to get cancel amount
158 ) = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionTotals($this->_contactId
, $isTest);
160 $this->assign('softCredit', TRUE);
161 $this->assign('softCreditRows', $softCreditList);
162 $this->assign('softCreditTotals', $softCreditTotals);
165 if ($this->_contactId
) {
166 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
167 $this->assign('displayName', $displayName);
168 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
);
173 * Get all the recurring contribution information and assign to the template
175 private function addRecurringContributionsBlock() {
176 $activeContributions = $this->getActiveRecurringContributions();
177 $inactiveRecurringContributions = $this->getInactiveRecurringContributions();
179 if (!empty($activeContributions) ||
!empty($inactiveRecurringContributions)) {
180 // assign vars to templates
181 $this->assign('action', $this->_action
);
182 $this->assign('activeRecurRows', $activeContributions);
183 $this->assign('inactiveRecurRows', $inactiveRecurringContributions);
184 $this->assign('recur', TRUE);
189 * Loads active recurring contributions for the current contact and formats
190 * them to be used on the form.
194 private function getActiveRecurringContributions() {
196 $contributionRecurResult = civicrm_api3('ContributionRecur', 'get', array(
197 'contact_id' => $this->_contactId
,
198 'contribution_status_id' => array('NOT IN' => $this->inactiveStatuses
),
199 'options' => array('limit' => 0, 'sort' => 'start_date ASC'),
201 $recurContributions = CRM_Utils_Array
::value('values', $contributionRecurResult);
203 catch (Exception
$e) {
204 $recurContributions = array();
207 return $this->buildRecurringContributionsArray($recurContributions);
211 * Loads inactive recurring contributions for the current contact and formats
212 * them to be used on the form.
216 private function getInactiveRecurringContributions() {
218 $contributionRecurResult = civicrm_api3('ContributionRecur', 'get', array(
219 'contact_id' => $this->_contactId
,
220 'contribution_status_id' => array('IN' => $this->inactiveStatuses
),
221 'options' => array('limit' => 0, 'sort' => 'start_date ASC'),
223 $recurContributions = CRM_Utils_Array
::value('values', $contributionRecurResult);
225 catch (Exception
$e) {
226 $recurContributions = NULL;
229 return $this->buildRecurringContributionsArray($recurContributions);
233 * @param $recurContributions
237 private function buildRecurringContributionsArray($recurContributions) {
238 foreach ($recurContributions as $recurId => $recurDetail) {
239 $action = array_sum(array_keys($this->recurLinks($recurId)));
240 // no action allowed if it's not active
241 $recurContributions[$recurId]['is_active'] = (!CRM_Contribute_BAO_Contribution
::isContributionStatusNegative($recurDetail['contribution_status_id']));
243 // Get the name of the payment processor
244 if (!empty($recurDetail['payment_processor_id'])) {
245 $recurContributions[$recurId]['payment_processor'] = CRM_Financial_BAO_PaymentProcessor
::getPaymentProcessorName($recurDetail['payment_processor_id']);
247 // Get the label for the contribution status
248 if (!empty($recurDetail['contribution_status_id'])) {
249 $recurContributions[$recurId]['contribution_status'] = CRM_Core_PseudoConstant
::getLabel('CRM_Contribute_BAO_ContributionRecur', 'contribution_status_id', $recurDetail['contribution_status_id']);
252 if ($recurContributions[$recurId]['is_active']) {
253 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($recurContributions[$recurId]['id'], 'recur');
254 $hideUpdate = $details->membership_id
& $details->auto_renew
;
257 $action -= CRM_Core_Action
::UPDATE
;
260 $recurContributions[$recurId]['action'] = CRM_Core_Action
::formLink(self
::recurLinks($recurId), $action,
262 'cid' => $this->_contactId
,
264 'cxt' => 'contribution',
268 'contribution.selector.recurring',
275 return $recurContributions;
279 * called when action is view.
283 public function view() {
284 $controller = new CRM_Core_Controller_Simple(
285 'CRM_Contribute_Form_ContributionView',
286 ts('View Contribution'),
289 $controller->setEmbedded(TRUE);
290 $controller->set('id', $this->_id
);
291 $controller->set('cid', $this->_contactId
);
293 return $controller->run();
297 * called when action is update or new.
300 * @throws \CRM_Core_Exception
303 public function edit() {
304 // set https for offline cc transaction
305 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
306 if ($mode == 'test' ||
$mode == 'live') {
307 CRM_Utils_System
::redirectToSSL();
310 $controller = new CRM_Core_Controller_Simple(
311 'CRM_Contribute_Form_Contribution',
312 'Create Contribution',
315 $controller->setEmbedded(TRUE);
316 $controller->set('id', $this->_id
);
317 $controller->set('cid', $this->_contactId
);
319 return $controller->run();
322 public function preProcess() {
323 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
324 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
325 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
327 if ($context == 'standalone') {
328 $this->_action
= CRM_Core_Action
::ADD
;
331 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, empty($this->_id
));
332 if (empty($this->_contactId
)) {
333 $this->_contactId
= civicrm_api3('contribution', 'getvalue', array(
335 'return' => 'contact_id',
338 $this->assign('contactId', $this->_contactId
);
340 // check logged in url permission
341 CRM_Contact_Page_View
::checkUserPermission($this);
343 $this->assign('action', $this->_action
);
345 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit contributions')) {
346 // demote to view since user does not have edit contrib rights
347 $this->_permission
= CRM_Core_Permission
::VIEW
;
348 $this->assign('permission', 'view');
353 * the main function that is called when the page
354 * loads, it decides the which action has to be taken for the page.
358 public function run() {
361 // check if we can process credit card contribs
362 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
366 if ($this->_action
& CRM_Core_Action
::VIEW
) {
369 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
376 return parent
::run();
379 public function setContext() {
380 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
381 $context = CRM_Utils_Request
::retrieve('context', 'String',
382 $this, FALSE, 'search'
384 $compContext = CRM_Utils_Request
::retrieve('compContext', 'String', $this);
386 $searchContext = CRM_Utils_Request
::retrieve('searchContext', 'String', $this);
389 if ($context == 'search' && $compContext) {
390 $context = $compContext;
396 // make sure we dont get tricked with a bad key
398 if (!CRM_Core_Key
::valid($qfKey)) {
402 $session = CRM_Core_Session
::singleton();
406 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
410 $url = CRM_Utils_System
::url('civicrm/contribute',
415 case 'pledgeDashboard':
416 $url = CRM_Utils_System
::url('civicrm/pledge',
422 $url = CRM_Utils_System
::url('civicrm/contact/view',
423 "reset=1&force=1&cid={$this->_contactId}&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);
438 elseif ($searchContext) {
439 $url = CRM_Utils_System
::url("civicrm/$searchContext/search", $extraParams);
442 $url = CRM_Utils_System
::url('civicrm/contribute/search', $extraParams);
447 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
451 $url = CRM_Utils_System
::url('civicrm/contact/view',
452 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
458 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
459 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
461 $context = 'membership';
466 $searchKey = "&key=$qfKey";
468 $compContext = "&compContext={$compContext}";
470 if ($componentAction & CRM_Core_Action
::VIEW
) {
476 $url = CRM_Utils_System
::url('civicrm/contact/view/membership',
477 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}"
482 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
483 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
485 $context = 'participant';
490 $searchKey = "&key=$qfKey";
492 $compContext = "&compContext={$compContext}";
494 if ($componentAction == CRM_Core_Action
::VIEW
) {
500 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
501 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}"
506 $url = CRM_Utils_System
::url('civicrm/contact/view',
507 "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge"
512 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
517 $urlParams = 'force=1';
518 $urlString = 'civicrm/contact/search/custom';
519 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
520 if ($this->_contactId
) {
521 $urlParams .= '&cid=' . $this->_contactId
;
524 $urlParams .= '&context=fulltext&action=view';
525 $urlString = 'civicrm/contact/view/contribution';
528 $urlParams .= "$keyName=$qfKey";
530 $this->assign('searchKey', $qfKey);
531 $url = CRM_Utils_System
::url($urlString, $urlParams);
536 if ($this->_contactId
) {
537 $cid = '&cid=' . $this->_contactId
;
539 $url = CRM_Utils_System
::url('civicrm/contribute/search',
540 'reset=1&force=1' . $cid
545 $session = CRM_Core_Session
::singleton();
546 $session->pushUserContext($url);