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
42 static $_links = NULL;
43 static $_recurLinks = NULL;
44 public $_permission = NULL;
45 public $_contactId = NULL;
49 * This method returns the links that are given for recur search row.
50 * currently the links added for each row are:
55 * @param bool $recurID
56 * @param string $context
60 public static function &recurLinks($recurID = FALSE, $context = 'contribution') {
61 if (!(self
::$_links)) {
62 self
::$_links = array(
63 CRM_Core_Action
::VIEW
=> array(
65 'title' => ts('View Recurring Payment'),
66 'url' => 'civicrm/contact/view/contributionrecur',
67 'qs' => "reset=1&id=%%crid%%&cid=%%cid%%&context={$context}",
69 CRM_Core_Action
::UPDATE
=> array(
71 'title' => ts('Edit Recurring Payment'),
72 'url' => 'civicrm/contribute/updaterecur',
73 'qs' => "reset=1&action=update&crid=%%crid%%&cid=%%cid%%&context={$context}",
75 CRM_Core_Action
::DISABLE
=> array(
76 'name' => ts('Cancel'),
77 'title' => ts('Cancel'),
78 'ref' => 'crm-enable-disable',
84 $paymentProcessorObj = CRM_Financial_BAO_PaymentProcessor
::getProcessorForEntity($recurID, 'recur', 'obj');
85 if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('cancelSubscription')) {
86 unset(self
::$_links[CRM_Core_Action
::DISABLE
]['extra'], self
::$_links[CRM_Core_Action
::DISABLE
]['ref']);
87 self
::$_links[CRM_Core_Action
::DISABLE
]['url'] = "civicrm/contribute/unsubscribe";
88 self
::$_links[CRM_Core_Action
::DISABLE
]['qs'] = "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}";
90 if (is_object($paymentProcessorObj) && $paymentProcessorObj->isSupported('updateSubscriptionBillingInfo')) {
91 self
::$_links[CRM_Core_Action
::RENEW
] = array(
92 'name' => ts('Change Billing Details'),
93 'title' => ts('Change Billing Details'),
94 'url' => 'civicrm/contribute/updatebilling',
95 'qs' => "reset=1&crid=%%crid%%&cid=%%cid%%&context={$context}",
100 return self
::$_links;
105 * called when action is browse
109 public function browse() {
110 // add annual contribution
112 list($annual['count'],
115 ) = CRM_Contribute_BAO_Contribution
::annual($this->_contactId
);
116 $this->assign('annual', $annual);
118 $controller = new CRM_Core_Controller_Simple(
119 'CRM_Contribute_Form_Search',
124 $controller->setEmbedded(TRUE);
125 $controller->reset();
126 $controller->set('cid', $this->_contactId
);
127 $controller->set('crid', $this->_crid
);
128 $controller->set('context', 'contribution');
129 $controller->set('limit', 50);
130 $controller->process();
133 // add recurring block
134 $action = array_sum(array_keys($this->recurLinks()));
135 $params = CRM_Contribute_BAO_ContributionRecur
::getRecurContributions($this->_contactId
);
137 if (!empty($params)) {
138 foreach ($params as $ids => $recur) {
139 $action = array_sum(array_keys($this->recurLinks($ids)));
140 // no action allowed if it's not active
141 $params[$ids]['is_active'] = ($recur['contribution_status_id'] != 3);
143 if ($params[$ids]['is_active']) {
144 $details = CRM_Contribute_BAO_ContributionRecur
::getSubscriptionDetails($params[$ids]['id'], 'recur');
145 $hideUpdate = $details->membership_id
& $details->auto_renew
;
148 $action -= CRM_Core_Action
::UPDATE
;
151 $params[$ids]['action'] = CRM_Core_Action
::formLink(self
::recurLinks($ids), $action,
153 'cid' => $this->_contactId
,
155 'cxt' => 'contribution',
159 'contribution.selector.recurring',
165 // assign vars to templates
166 $this->assign('action', $this->_action
);
167 $this->assign('recurRows', $params);
168 $this->assign('recur', TRUE);
171 //enable/disable soft credit records for test contribution
173 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
176 $this->assign('isTest', $isTest);
178 $softCreditList = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionList($this->_contactId
, NULL, $isTest);
180 if (!empty($softCreditList)) {
181 $softCreditTotals = array();
183 list($softCreditTotals['amount'],
184 $softCreditTotals['avg'],
185 $softCreditTotals['currency']
186 ) = CRM_Contribute_BAO_ContributionSoft
::getSoftContributionTotals($this->_contactId
, $isTest);
188 $this->assign('softCredit', TRUE);
189 $this->assign('softCreditRows', $softCreditList);
190 $this->assign('softCreditTotals', $softCreditTotals);
193 if ($this->_contactId
) {
194 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
195 $this->assign('displayName', $displayName);
196 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('contribution', $this->_contactId
);
201 * called when action is view
205 public function view() {
206 $controller = new CRM_Core_Controller_Simple(
207 'CRM_Contribute_Form_ContributionView',
208 ts('View Contribution'),
211 $controller->setEmbedded(TRUE);
212 $controller->set('id', $this->_id
);
213 $controller->set('cid', $this->_contactId
);
215 return $controller->run();
219 * called when action is update or new
223 public function edit() {
224 // set https for offline cc transaction
225 $mode = CRM_Utils_Request
::retrieve('mode', 'String', $this);
226 if ($mode == 'test' ||
$mode == 'live') {
227 CRM_Utils_System
::redirectToSSL();
230 $controller = new CRM_Core_Controller_Simple(
231 'CRM_Contribute_Form_Contribution',
232 'Create Contribution',
235 $controller->setEmbedded(TRUE);
236 $controller->set('id', $this->_id
);
237 $controller->set('cid', $this->_contactId
);
239 return $controller->run();
242 public function preProcess() {
243 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
244 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
245 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
247 if ($context == 'standalone') {
248 $this->_action
= CRM_Core_Action
::ADD
;
251 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, empty($this->_id
));
252 if (empty($this->_contactId
)) {
253 $this->_contactId
= civicrm_api3('contribution', 'getvalue', array(
255 'return' => 'contact_id'
258 $this->assign('contactId', $this->_contactId
);
260 // check logged in url permission
261 CRM_Contact_Page_View
::checkUserPermission($this);
263 $this->assign('action', $this->_action
);
265 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit contributions')) {
266 // demote to view since user does not have edit contrib rights
267 $this->_permission
= CRM_Core_Permission
::VIEW
;
268 $this->assign('permission', 'view');
273 * the main function that is called when the page
274 * loads, it decides the which action has to be taken for the page.
278 public function run() {
281 // check if we can process credit card contribs
282 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
286 if ($this->_action
& CRM_Core_Action
::VIEW
) {
289 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
296 return parent
::run();
299 public function setContext() {
300 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
301 $context = CRM_Utils_Request
::retrieve('context', 'String',
302 $this, FALSE, 'search'
304 $compContext = CRM_Utils_Request
::retrieve('compContext', 'String', $this);
306 $searchContext = CRM_Utils_Request
::retrieve('searchContext', 'String', $this);
309 if ($context == 'search' && $compContext) {
310 $context = $compContext;
316 // make sure we dont get tricked with a bad key
318 if (!CRM_Core_Key
::valid($qfKey)) {
322 $session = CRM_Core_Session
::singleton();
326 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
330 $url = CRM_Utils_System
::url('civicrm/contribute',
335 case 'pledgeDashboard':
336 $url = CRM_Utils_System
::url('civicrm/pledge',
342 $url = CRM_Utils_System
::url('civicrm/contact/view',
343 "reset=1&force=1&cid={$this->_contactId}&selectedChild=contribute"
349 $extraParams = "force=1";
351 $extraParams .= "&qfKey=$qfKey";
354 $this->assign('searchKey', $qfKey);
355 if ($context == 'advanced') {
356 $url = CRM_Utils_System
::url('civicrm/contact/search/advanced', $extraParams);
358 elseif ($searchContext) {
359 $url = CRM_Utils_System
::url("civicrm/$searchContext/search", $extraParams);
362 $url = CRM_Utils_System
::url('civicrm/contribute/search', $extraParams);
367 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
371 $url = CRM_Utils_System
::url('civicrm/contact/view',
372 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
378 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
379 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
381 $context = 'membership';
386 $searchKey = "&key=$qfKey";
388 $compContext = "&compContext={$compContext}";
390 if ($componentAction & CRM_Core_Action
::VIEW
) {
396 $url = CRM_Utils_System
::url('civicrm/contact/view/membership',
397 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=member{$searchKey}{$compContext}"
402 $componentId = CRM_Utils_Request
::retrieve('compId', 'Positive', $this);
403 $componentAction = CRM_Utils_Request
::retrieve('compAction', 'Integer', $this);
405 $context = 'participant';
410 $searchKey = "&key=$qfKey";
412 $compContext = "&compContext={$compContext}";
414 if ($componentAction == CRM_Core_Action
::VIEW
) {
420 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
421 "reset=1&action={$action}&id={$componentId}&cid={$this->_contactId}&context={$context}&selectedChild=event{$searchKey}{$compContext}"
426 $url = CRM_Utils_System
::url('civicrm/contact/view',
427 "reset=1&force=1&cid={$this->_contactId}&selectedChild=pledge"
432 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
437 $urlParams = 'force=1';
438 $urlString = 'civicrm/contact/search/custom';
439 if ($this->_action
== CRM_Core_Action
::UPDATE
) {
440 if ($this->_contactId
) {
441 $urlParams .= '&cid=' . $this->_contactId
;
444 $urlParams .= '&context=fulltext&action=view';
445 $urlString = 'civicrm/contact/view/contribution';
448 $urlParams .= "$keyName=$qfKey";
450 $this->assign('searchKey', $qfKey);
451 $url = CRM_Utils_System
::url($urlString, $urlParams);
456 if ($this->_contactId
) {
457 $cid = '&cid=' . $this->_contactId
;
459 $url = CRM_Utils_System
::url('civicrm/contribute/search',
460 'reset=1&force=1' . $cid
465 $session = CRM_Core_Session
::singleton();
466 $session->pushUserContext($url);