3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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 * This method returns the links that are given for recur search row.
48 * currently the links added for each row are:
53 * @param bool $recurID
54 * @param string $context
58 public static function &recurLinks($recurID = FALSE, $context = 'contribution') {
59 if (!(self
::$_links)) {
60 self
::$_links = array(
61 CRM_Core_Action
::VIEW
=> array(
63 'title' => ts('View Recurring Payment'),
64 'url' => 'civicrm/contact/view/contributionrecur',
65 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
67 CRM_Core_Action
::UPDATE
=> array(
69 'title' => ts('Edit Recurring Payment'),
70 'url' => 'civicrm/contribute/updaterecur',
71 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
73 CRM_Core_Action
::DISABLE
=> array(
74 'name' => ts('Cancel'),
75 'title' => ts('Cancel'),
76 'ref' => 'crm-enable-disable',
82 $paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recurID, 'recur', 'obj');
83 if (is_object($paymentProcessorObj) && $paymentProcessorObj->supports('cancelRecurring')) {
84 unset(self
::$_links[CRM_Core_Action
::DISABLE
]['extra'], self
::$_links[CRM_Core_Action
::DISABLE
]['ref']);
85 self
::$_links[CRM_Core_Action
::DISABLE
]['url'] = "civicrm/contribute/unsubscribe";
86 self
::$_links[CRM_Core_Action
::DISABLE
]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
89 if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) {
90 self
::$_links[CRM_Core_Action
::RENEW
] = array(
91 'name' => ts('Change Billing Details'),
92 'title' => ts('Change Billing Details'),
93 'url' => 'civicrm/contribute/updatebilling',
94 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
104 * called when action is browse.
107 public function browse() {
108 // add annual contribution
110 list($annual['count'],
113 ) = CRM_Contribute_BAO_Contribution
::annual($this->_contactId
);
114 $this->assign('annual', $annual);
116 $controller = new CRM_Core_Controller_Simple(
117 'CRM_Contribute_Form_Search',
122 $controller->setEmbedded(TRUE);
123 $controller->reset();
124 $controller->set('cid', $this->_contactId
);
125 $controller->set('crid', $this->_crid
);
126 $controller->set('context', 'contribution');
127 $controller->set('limit', 50);
128 $controller->process();
131 // add recurring block
132 $action = array_sum(array_keys($this->recurLinks()));
133 $params = CRM_Contribute_BAO_ContributionRecur
::getRecurContributions($this->_contactId
);
135 if (!empty($params)) {
136 foreach ($params as $ids => $recur) {
137 $action = array_sum(array_keys($this->recurLinks($ids)));
138 // no action allowed if it's not active
139 $params[$ids]['is_active'] = ($recur['contribution_status_id'] != 3);
141 if ($params[$ids]['is_active']) {
142 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($params[$ids]['id'], 'recur');
143 $hideUpdate = $details->membership_id
& $details->auto_renew
;
146 $action -= CRM_Core_Action
::UPDATE
;
149 $params[$ids]['action'] = CRM_Core_Action
::formLink(self
::recurLinks($ids), $action,
151 'cid' => $this->_contactId
,
153 'cxt' => 'contribution',
157 'contribution.selector.recurring',
163 // assign vars to templates
164 $this->assign('action', $this->_action
);
165 $this->assign('recurRows', $params);
166 $this->assign('recur', TRUE);
169 //enable/disable soft credit records for test contribution
171 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
174 $this->assign('isTest', $isTest);
176 $softCreditList = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionList($this->_contactId
, NULL, $isTest);
178 if (!empty($softCreditList)) {
179 $softCreditTotals = array();
181 list($softCreditTotals['amount'],
182 $softCreditTotals['avg'],
183 $softCreditTotals['currency'],
184 $softCreditTotals['cancelAmount'] //to get cancel amount
185 ) = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionTotals($this->_contactId
, $isTest);
187 $this->assign('softCredit', TRUE);
188 $this->assign('softCreditRows', $softCreditList);
189 $this->assign('softCreditTotals', $softCreditTotals);
192 if ($this->_contactId
) {
193 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
194 $this->assign('displayName', $displayName);
195 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
);
200 * called when action is view.
204 public function view() {
205 $controller = new CRM_Core_Controller_Simple(
206 'CRM_Contribute_Form_ContributionView',
207 ts('View Contribution'),
210 $controller->setEmbedded(TRUE);
211 $controller->set('id', $this->_id
);
212 $controller->set('cid', $this->_contactId
);
214 return $controller->run();
218 * called when action is update or new.
222 public function edit() {
223 // set https for offline cc transaction
224 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
225 if ($mode == 'test' ||
$mode == 'live') {
226 CRM_Utils_System
::redirectToSSL();
229 $controller = new CRM_Core_Controller_Simple(
230 'CRM_Contribute_Form_Contribution',
231 'Create Contribution',
234 $controller->setEmbedded(TRUE);
235 $controller->set('id', $this->_id
);
236 $controller->set('cid', $this->_contactId
);
238 return $controller->run();
241 public function preProcess() {
242 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
243 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
244 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
246 if ($context == 'standalone') {
247 $this->_action
= CRM_Core_Action
::ADD
;
250 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, empty($this->_id
));
251 if (empty($this->_contactId
)) {
252 $this->_contactId
= civicrm_api3('contribution', 'getvalue', array(
254 'return' => 'contact_id',
257 $this->assign('contactId', $this->_contactId
);
259 // check logged in url permission
260 CRM_Contact_Page_View
::checkUserPermission($this);
262 $this->assign('action', $this->_action
);
264 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit contributions')) {
265 // demote to view since user does not have edit contrib rights
266 $this->_permission
= CRM_Core_Permission
::VIEW
;
267 $this->assign('permission', 'view');
272 * the main function that is called when the page
273 * loads, it decides the which action has to be taken for the page.
277 public function run() {
280 // check if we can process credit card contribs
281 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
285 if ($this->_action
& CRM_Core_Action
::VIEW
) {
288 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
295 return parent
::run();
298 public function setContext() {
299 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
300 $context = CRM_Utils_Request
::retrieve('context', 'String',
301 $this, FALSE, 'search'
303 $compContext = CRM_Utils_Request
::retrieve('compContext', 'String', $this);
305 $searchContext = CRM_Utils_Request
::retrieve('searchContext', 'String', $this);
308 if ($context == 'search' && $compContext) {
309 $context = $compContext;
315 // make sure we dont get tricked with a bad key
317 if (!CRM_Core_Key
::valid($qfKey)) {
321 $session = CRM_Core_Session
::singleton();
325 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
329 $url = CRM_Utils_System
::url('civicrm/contribute',
334 case 'pledgeDashboard':
335 $url = CRM_Utils_System
::url('civicrm/pledge',
341 $url = CRM_Utils_System
::url('civicrm/contact/view',
342 "reset=1&force=1&cid={$this->_contactId}&selectedChild=contribute"
348 $extraParams = "force=1";
350 $extraParams .= "&qfKey=$qfKey";
353 $this->assign('searchKey', $qfKey);
354 if ($context == 'advanced') {
355 $url = CRM_Utils_System
::url('civicrm/contact/search/advanced', $extraParams);
357 elseif ($searchContext) {
358 $url = CRM_Utils_System
::url("civicrm/$searchContext/search", $extraParams);
361 $url = CRM_Utils_System
::url('civicrm/contribute/search', $extraParams);
366 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
370 $url = CRM_Utils_System
::url('civicrm/contact/view',
371 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
377 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
378 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
380 $context = 'membership';
385 $searchKey = "&key=$qfKey";
387 $compContext = "&compContext={$compContext}";
389 if ($componentAction & CRM_Core_Action
::VIEW
) {
395 $url = CRM_Utils_System
::url('civicrm/contact/view/membership',
396 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}"
401 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
402 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
404 $context = 'participant';
409 $searchKey = "&key=$qfKey";
411 $compContext = "&compContext={$compContext}";
413 if ($componentAction == CRM_Core_Action
::VIEW
) {
419 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
420 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}"
425 $url = CRM_Utils_System
::url('civicrm/contact/view',
426 "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge"
431 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
436 $urlParams = 'force=1';
437 $urlString = 'civicrm/contact/search/custom';
438 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
439 if ($this->_contactId
) {
440 $urlParams .= '&cid=' . $this->_contactId
;
443 $urlParams .= '&context=fulltext&action=view';
444 $urlString = 'civicrm/contact/view/contribution';
447 $urlParams .= "$keyName=$qfKey";
449 $this->assign('searchKey', $qfKey);
450 $url = CRM_Utils_System
::url($urlString, $urlParams);
455 if ($this->_contactId
) {
456 $cid = '&cid=' . $this->_contactId
;
458 $url = CRM_Utils_System
::url('civicrm/contribute/search',
459 'reset=1&force=1' . $cid
464 $session = CRM_Core_Session
::singleton();
465 $session->pushUserContext($url);