3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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_Pledge_Page_Tab
extends CRM_Core_Page
{
36 public $_permission = NULL;
37 public $_contactId = NULL;
40 * This function is called when action is browse
46 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Search', ts('Pledges'), $this->_action
);
47 $controller->setEmbedded(TRUE);
49 $controller->set('cid', $this->_contactId
);
50 $controller->set('context', 'pledge');
51 $controller->set('limit', '25');
52 $controller->process();
55 if ($this->_contactId
) {
56 $displayName = CRM_Contact_BAO_Contact
::displayName($this->_contactId
);
57 $this->assign('displayName', $displayName);
58 $this->ajaxResponse
['tabCount'] = CRM_Contact_BAO_Contact
::getCountComponent('pledge', $this->_contactId
);
59 // Refresh other tabs with related data
60 $this->ajaxResponse
['updateTabs'] = array(
61 '#tab_activity' => CRM_Contact_BAO_Contact
::getCountComponent('activity', $this->_contactId
),
67 * This function is called when action is view
73 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_PledgeView',
77 $controller->setEmbedded(TRUE);
78 $controller->set('id', $this->_id
);
79 $controller->set('cid', $this->_contactId
);
81 return $controller->run();
85 * This function is called when action is update or new
91 $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Pledge',
95 $controller->setEmbedded(TRUE);
96 $controller->set('id', $this->_id
);
97 $controller->set('cid', $this->_contactId
);
99 return $controller->run();
102 function preProcess() {
103 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
104 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
105 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
107 if ($context == 'standalone') {
108 $this->_action
= CRM_Core_Action
::ADD
;
111 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
112 $this->assign('contactId', $this->_contactId
);
114 // check logged in url permission
115 CRM_Contact_Page_View
::checkUserPermission($this);
118 $this->assign('action', $this->_action
);
120 if ($this->_permission
== CRM_Core_Permission
::EDIT
&& !CRM_Core_Permission
::check('edit pledges')) {
121 // demote to view since user does not have edit pledge rights
122 $this->_permission
= CRM_Core_Permission
::VIEW
;
123 $this->assign('permission', 'view');
128 * This function is the main function that is called when the page loads, it decides the which action has to be taken for the page.
136 // check if we can process credit card registration
137 $this->assign('newCredit', CRM_Core_Config
::isEnabledBackOfficeCreditCardPayments());
139 self
::setContext($this);
141 if ($this->_action
& CRM_Core_Action
::VIEW
) {
144 elseif ($this->_action
& (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD | CRM_Core_Action
::DELETE
)) {
147 elseif ($this->_action
& CRM_Core_Action
::DETACH
) {
148 CRM_Pledge_BAO_Pledge
::cancel($this->_id
);
149 $session = CRM_Core_Session
::singleton();
150 $session->setStatus(ts('Pledge has been Cancelled and all scheduled (not completed) payments have been cancelled.<br />'));
151 CRM_Utils_System
::redirect($session->popUserContext());
157 return parent
::run();
160 public static function setContext(&$form) {
161 $context = CRM_Utils_Request
::retrieve('context', 'String', $form, FALSE, 'search');
163 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $form);
165 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
171 case 'pledgeDashboard':
172 $url = CRM_Utils_System
::url('civicrm/pledge', 'reset=1');
176 $urlParams = 'force=1';
178 $urlParams .= "&qfKey=$qfKey";
181 $url = CRM_Utils_System
::url('civicrm/pledge/search', $urlParams);
185 $url = CRM_Utils_System
::url('civicrm/user', 'reset=1');
189 $url = CRM_Utils_System
::url('civicrm/contact/view',
190 "reset=1&force=1&cid={$form->_contactId}&selectedChild=pledge"
195 $url = CRM_Utils_System
::url('civicrm/dashboard', 'force=1');
199 $url = CRM_Utils_System
::url('civicrm/contact/view',
200 "reset=1&force=1&cid={$form->_contactId}&selectedChild=activity"
205 $url = CRM_Utils_System
::url('civicrm/dashboard', 'reset=1');
210 if ($form->_contactId
) {
211 $cid = '&cid=' . $form->_contactId
;
213 $url = CRM_Utils_System
::url('civicrm/pledge/search',
218 $session = CRM_Core_Session
::singleton();
219 $session->pushUserContext($url);