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
61 public static function &recurLinks($recurID = FALSE, $context = 'contribution') {
62 if (!(self
::$_links)) {
63 self
::$_links = array(
64 CRM_Core_Action
::VIEW
=> array(
66 'title' => ts('View Recurring Payment'),
67 'url' => 'civicrm/contact/view/contributionrecur',
68 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
70 CRM_Core_Action
::UPDATE
=> array(
72 'title' => ts('Edit Recurring Payment'),
73 'url' => 'civicrm/contribute/updaterecur',
74 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
76 CRM_Core_Action
::DISABLE
=> array(
77 'name' => ts('Cancel'),
78 'title' => ts('Cancel'),
79 'ref' => 'crm-enable-disable',
85 $paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recurID, 'recur', 'obj');
86 if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('cancelSubscription')) {
87 unset(self
::$_links[CRM_Core_Action
::DISABLE
]['extra'], self
::$_links[CRM_Core_Action
::DISABLE
]['ref']);
88 self
::$_links[CRM_Core_Action
::DISABLE
]['url'] = "civicrm/contribute/unsubscribe";
89 self
::$_links[CRM_Core_Action
::DISABLE
]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
91 if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) {
92 self
::$_links[CRM_Core_Action
::RENEW
] = array(
93 '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
110 public function browse() {
111 // add annual contribution
113 list($annual['count'],
116 ) = CRM_Contribute_BAO_Contribution
::annual($this->_contactId
);
117 $this->assign('annual', $annual);
119 $controller = new CRM_Core_Controller_Simple(
120 'CRM_Contribute_Form_Search',
125 $controller->setEmbedded(TRUE);
126 $controller->reset();
127 $controller->set('cid', $this->_contactId
);
128 $controller->set('crid', $this->_crid
);
129 $controller->set('context', 'contribution');
130 $controller->set('limit', 50);
131 $controller->process();
134 // add recurring block
135 $action = array_sum(array_keys($this->recurLinks()));
136 $params = CRM_Contribute_BAO_ContributionRecur
::getRecurContributions($this->_contactId
);
138 if (!empty($params)) {
139 foreach ($params as $ids => $recur) {
140 $action = array_sum(array_keys($this->recurLinks($ids)));
141 // no action allowed if it's not active
142 $params[$ids]['is_active'] = ($recur['contribution_status_id'] != 3);
144 if ($params[$ids]['is_active']) {
145 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($params[$ids]['id'], 'recur');
146 $hideUpdate = $details->membership_id
& $details->auto_renew
;
149 $action -= CRM_Core_Action
::UPDATE
;
152 $params[$ids]['action'] = CRM_Core_Action
::formLink(self
::recurLinks($ids), $action,
154 'cid' => $this->_contactId
,
156 'cxt' => 'contribution',
160 'contribution.selector.recurring',
166 // assign vars to templates
167 $this->assign('action', $this->_action
);
168 $this->assign('recurRows', $params);
169 $this->assign('recur', TRUE);
172 //enable/disable soft credit records for test contribution
174 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
177 $this->assign('isTest', $isTest);
179 $softCreditList = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionList($this->_contactId
, NULL, $isTest);
181 if (!empty($softCreditList)) {
182 $softCreditTotals = array();
184 list($softCreditTotals['amount'],
185 $softCreditTotals['avg'],
186 $softCreditTotals['currency']
187 ) = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionTotals($this->_contactId
, $isTest);
189 $this->assign('softCredit', TRUE);
190 $this->assign('softCreditRows', $softCreditList);
191 $this->assign('softCreditTotals', $softCreditTotals);
194 if ($this->_contactId
) {
195 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
196 $this->assign('displayName', $displayName);
197 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
);
202 * This function is called when action is view
206 public function view() {
207 $controller = new CRM_Core_Controller_Simple(
208 'CRM_Contribute_Form_ContributionView',
209 ts('View Contribution'),
212 $controller->setEmbedded(TRUE);
213 $controller->set('id', $this->_id
);
214 $controller->set('cid', $this->_contactId
);
216 return $controller->run();
220 * This function is called when action is update or new
224 public function edit() {
225 // set https for offline cc transaction
226 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
227 if ($mode == 'test' ||
$mode == 'live') {
228 CRM_Utils_System
::redirectToSSL();
231 $controller = new CRM_Core_Controller_Simple(
232 'CRM_Contribute_Form_Contribution',
233 'Create Contribution',
236 $controller->setEmbedded(TRUE);
237 $controller->set('id', $this->_id
);
238 $controller->set('cid', $this->_contactId
);
240 return $controller->run();
243 public function preProcess() {
244 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
245 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
246 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
248 if ($context == 'standalone') {
249 $this->_action
= CRM_Core_Action
::ADD
;
252 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, empty($this->_id
));
253 if (empty($this->_contactId
)) {
254 $this->_contactId
= civicrm_api3('contribution', 'getvalue', array('id' => $this->_id
, 'return' => 'contact_id'));
256 $this->assign('contactId', $this->_contactId
);
258 // check logged in url permission
259 CRM_Contact_Page_View
::checkUserPermission($this);
261 $this->assign('action', $this->_action
);
263 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit contributions')) {
264 // demote to view since user does not have edit contrib rights
265 $this->_permission
= CRM_Core_Permission
::VIEW
;
266 $this->assign('permission', 'view');
271 * This function is the main function that is called when the page
272 * loads, it decides the which action has to be taken for the page.
276 public function run() {
279 // check if we can process credit card contribs
280 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
284 if ($this->_action
& CRM_Core_Action
::VIEW
) {
287 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
294 return parent
::run();
297 public function setContext() {
298 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
299 $context = CRM_Utils_Request
::retrieve('context', 'String',
300 $this, FALSE, 'search'
302 $compContext = CRM_Utils_Request
::retrieve('compContext', 'String', $this);
304 $searchContext = CRM_Utils_Request
::retrieve('searchContext', 'String', $this);
307 if ($context == 'search' && $compContext) {
308 $context = $compContext;
314 // make sure we dont get tricked with a bad key
316 if (!CRM_Core_Key
::valid($qfKey)) {
320 $session = CRM_Core_Session
::singleton();
324 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
328 $url = CRM_Utils_System
::url('civicrm/contribute',
333 case 'pledgeDashboard':
334 $url = CRM_Utils_System
::url('civicrm/pledge',
340 $url = CRM_Utils_System
::url('civicrm/contact/view',
341 "reset=1&force=1&cid={$this->_contactId}&selectedChild=contribute"
347 $extraParams = "force=1";
349 $extraParams .= "&qfKey=$qfKey";
352 $this->assign('searchKey', $qfKey);
353 if ($context == 'advanced') {
354 $url = CRM_Utils_System
::url('civicrm/contact/search/advanced', $extraParams);
356 elseif ($searchContext) {
357 $url = CRM_Utils_System
::url("civicrm/$searchContext/search", $extraParams);
360 $url = CRM_Utils_System
::url('civicrm/contribute/search', $extraParams);
365 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
369 $url = CRM_Utils_System
::url('civicrm/contact/view',
370 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
376 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
377 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
379 $context = 'membership';
384 $searchKey = "&key=$qfKey";
386 $compContext = "&compContext={$compContext}";
388 if ($componentAction & CRM_Core_Action
::VIEW
) {
394 $url = CRM_Utils_System
::url('civicrm/contact/view/membership',
395 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}"
400 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
401 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
403 $context = 'participant';
408 $searchKey = "&key=$qfKey";
410 $compContext = "&compContext={$compContext}";
412 if ($componentAction == CRM_Core_Action
::VIEW
) {
418 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
419 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}"
424 $url = CRM_Utils_System
::url('civicrm/contact/view',
425 "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge"
430 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
435 $urlParams = 'force=1';
436 $urlString = 'civicrm/contact/search/custom';
437 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
438 if ($this->_contactId
) {
439 $urlParams .= '&cid=' . $this->_contactId
;
442 $urlParams .= '&context=fulltext&action=view';
443 $urlString = 'civicrm/contact/view/contribution';
446 $urlParams .= "$keyName=$qfKey";
448 $this->assign('searchKey', $qfKey);
449 $url = CRM_Utils_System
::url($urlString, $urlParams);
454 if ($this->_contactId
) {
455 $cid = '&cid=' . $this->_contactId
;
457 $url = CRM_Utils_System
::url('civicrm/contribute/search',
458 'reset=1&force=1' . $cid
463 $session = CRM_Core_Session
::singleton();
464 $session->pushUserContext($url);