3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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->isSupported('cancelSubscription')) {
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}";
88 if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) {
89 self
::$_links[CRM_Core_Action
::RENEW
] = array(
90 'name' => ts('Change Billing Details'),
91 'title' => ts('Change Billing Details'),
92 'url' => 'civicrm/contribute/updatebilling',
93 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
103 * called when action is browse.
106 public function browse() {
107 // add annual contribution
109 list($annual['count'],
112 ) = CRM_Contribute_BAO_Contribution
::annual($this->_contactId
);
113 $this->assign('annual', $annual);
115 $controller = new CRM_Core_Controller_Simple(
116 'CRM_Contribute_Form_Search',
121 $controller->setEmbedded(TRUE);
122 $controller->reset();
123 $controller->set('cid', $this->_contactId
);
124 $controller->set('crid', $this->_crid
);
125 $controller->set('context', 'contribution');
126 $controller->set('limit', 50);
127 $controller->process();
130 // add recurring block
131 $action = array_sum(array_keys($this->recurLinks()));
132 $params = CRM_Contribute_BAO_ContributionRecur
::getRecurContributions($this->_contactId
);
134 if (!empty($params)) {
135 foreach ($params as $ids => $recur) {
136 $action = array_sum(array_keys($this->recurLinks($ids)));
137 // no action allowed if it's not active
138 $params[$ids]['is_active'] = ($recur['contribution_status_id'] != 3);
140 if ($params[$ids]['is_active']) {
141 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($params[$ids]['id'], 'recur');
142 $hideUpdate = $details->membership_id
& $details->auto_renew
;
145 $action -= CRM_Core_Action
::UPDATE
;
148 $params[$ids]['action'] = CRM_Core_Action
::formLink(self
::recurLinks($ids), $action,
150 'cid' => $this->_contactId
,
152 'cxt' => 'contribution',
156 'contribution.selector.recurring',
162 // assign vars to templates
163 $this->assign('action', $this->_action
);
164 $this->assign('recurRows', $params);
165 $this->assign('recur', TRUE);
168 //enable/disable soft credit records for test contribution
170 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
173 $this->assign('isTest', $isTest);
175 $softCreditList = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionList($this->_contactId
, NULL, $isTest);
177 if (!empty($softCreditList)) {
178 $softCreditTotals = array();
180 list($softCreditTotals['amount'],
181 $softCreditTotals['avg'],
182 $softCreditTotals['currency']
183 ) = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionTotals($this->_contactId
, $isTest);
185 $this->assign('softCredit', TRUE);
186 $this->assign('softCreditRows', $softCreditList);
187 $this->assign('softCreditTotals', $softCreditTotals);
190 if ($this->_contactId
) {
191 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
192 $this->assign('displayName', $displayName);
193 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
);
198 * called when action is view.
202 public function view() {
203 $controller = new CRM_Core_Controller_Simple(
204 'CRM_Contribute_Form_ContributionView',
205 ts('View Contribution'),
208 $controller->setEmbedded(TRUE);
209 $controller->set('id', $this->_id
);
210 $controller->set('cid', $this->_contactId
);
212 return $controller->run();
216 * called when action is update or new.
220 public function edit() {
221 // set https for offline cc transaction
222 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
223 if ($mode == 'test' ||
$mode == 'live') {
224 CRM_Utils_System
::redirectToSSL();
227 $controller = new CRM_Core_Controller_Simple(
228 'CRM_Contribute_Form_Contribution',
229 'Create Contribution',
232 $controller->setEmbedded(TRUE);
233 $controller->set('id', $this->_id
);
234 $controller->set('cid', $this->_contactId
);
236 return $controller->run();
239 public function preProcess() {
240 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
241 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
242 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
244 if ($context == 'standalone') {
245 $this->_action
= CRM_Core_Action
::ADD
;
248 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, empty($this->_id
));
249 if (empty($this->_contactId
)) {
250 $this->_contactId
= civicrm_api3('contribution', 'getvalue', array(
252 'return' => 'contact_id',
255 $this->assign('contactId', $this->_contactId
);
257 // check logged in url permission
258 CRM_Contact_Page_View
::checkUserPermission($this);
260 $this->assign('action', $this->_action
);
262 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit contributions')) {
263 // demote to view since user does not have edit contrib rights
264 $this->_permission
= CRM_Core_Permission
::VIEW
;
265 $this->assign('permission', 'view');
270 * the main function that is called when the page
271 * loads, it decides the which action has to be taken for the page.
275 public function run() {
278 // check if we can process credit card contribs
279 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
283 if ($this->_action
& CRM_Core_Action
::VIEW
) {
286 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
293 return parent
::run();
296 public function setContext() {
297 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
298 $context = CRM_Utils_Request
::retrieve('context', 'String',
299 $this, FALSE, 'search'
301 $compContext = CRM_Utils_Request
::retrieve('compContext', 'String', $this);
303 $searchContext = CRM_Utils_Request
::retrieve('searchContext', 'String', $this);
306 if ($context == 'search' && $compContext) {
307 $context = $compContext;
313 // make sure we dont get tricked with a bad key
315 if (!CRM_Core_Key
::valid($qfKey)) {
319 $session = CRM_Core_Session
::singleton();
323 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
327 $url = CRM_Utils_System
::url('civicrm/contribute',
332 case 'pledgeDashboard':
333 $url = CRM_Utils_System
::url('civicrm/pledge',
339 $url = CRM_Utils_System
::url('civicrm/contact/view',
340 "reset=1&force=1&cid={$this->_contactId}&selectedChild=contribute"
346 $extraParams = "force=1";
348 $extraParams .= "&qfKey=$qfKey";
351 $this->assign('searchKey', $qfKey);
352 if ($context == 'advanced') {
353 $url = CRM_Utils_System
::url('civicrm/contact/search/advanced', $extraParams);
355 elseif ($searchContext) {
356 $url = CRM_Utils_System
::url("civicrm/$searchContext/search", $extraParams);
359 $url = CRM_Utils_System
::url('civicrm/contribute/search', $extraParams);
364 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
368 $url = CRM_Utils_System
::url('civicrm/contact/view',
369 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
375 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
376 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
378 $context = 'membership';
383 $searchKey = "&key=$qfKey";
385 $compContext = "&compContext={$compContext}";
387 if ($componentAction & CRM_Core_Action
::VIEW
) {
393 $url = CRM_Utils_System
::url('civicrm/contact/view/membership',
394 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}"
399 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
400 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
402 $context = 'participant';
407 $searchKey = "&key=$qfKey";
409 $compContext = "&compContext={$compContext}";
411 if ($componentAction == CRM_Core_Action
::VIEW
) {
417 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
418 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}"
423 $url = CRM_Utils_System
::url('civicrm/contact/view',
424 "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge"
429 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
434 $urlParams = 'force=1';
435 $urlString = 'civicrm/contact/search/custom';
436 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
437 if ($this->_contactId
) {
438 $urlParams .= '&cid=' . $this->_contactId
;
441 $urlParams .= '&context=fulltext&action=view';
442 $urlString = 'civicrm/contact/view/contribution';
445 $urlParams .= "$keyName=$qfKey";
447 $this->assign('searchKey', $qfKey);
448 $url = CRM_Utils_System
::url($urlString, $urlParams);
453 if ($this->_contactId
) {
454 $cid = '&cid=' . $this->_contactId
;
456 $url = CRM_Utils_System
::url('civicrm/contribute/search',
457 'reset=1&force=1' . $cid
462 $session = CRM_Core_Session
::singleton();
463 $session->pushUserContext($url);