Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Pledge_Page_Tab extends CRM_Core_Page { | |
36 | public $_permission = NULL; | |
37 | public $_contactId = NULL; | |
38 | ||
39 | /** | |
fe482240 | 40 | * called when action is browse. |
6a488035 | 41 | * |
e7483cbe | 42 | * @return void |
6a488035 | 43 | */ |
00be9182 | 44 | public function browse() { |
6a488035 TO |
45 | $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Search', ts('Pledges'), $this->_action); |
46 | $controller->setEmbedded(TRUE); | |
47 | $controller->reset(); | |
48 | $controller->set('cid', $this->_contactId); | |
49 | $controller->set('context', 'pledge'); | |
3bba4de0 | 50 | $controller->set('limit', '25'); |
6a488035 TO |
51 | $controller->process(); |
52 | $controller->run(); | |
53 | ||
54 | if ($this->_contactId) { | |
55 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
56 | $this->assign('displayName', $displayName); | |
4e8065a9 | 57 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('pledge', $this->_contactId); |
3dcb6fea CW |
58 | // Refresh other tabs with related data |
59 | $this->ajaxResponse['updateTabs'] = array( | |
0faf81a7 | 60 | '#tab_contribute' => CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId), |
3dcb6fea CW |
61 | '#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId), |
62 | ); | |
6a488035 TO |
63 | } |
64 | } | |
65 | ||
66 | /** | |
fe482240 | 67 | * called when action is view. |
6a488035 | 68 | * |
76e7a76c | 69 | * @return null |
6a488035 | 70 | */ |
00be9182 | 71 | public function view() { |
6a488035 TO |
72 | $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_PledgeView', |
73 | 'View Pledge', | |
74 | $this->_action | |
75 | ); | |
76 | $controller->setEmbedded(TRUE); | |
77 | $controller->set('id', $this->_id); | |
78 | $controller->set('cid', $this->_contactId); | |
79 | ||
80 | return $controller->run(); | |
81 | } | |
82 | ||
83 | /** | |
fe482240 | 84 | * called when action is update or new. |
6a488035 | 85 | * |
76e7a76c | 86 | * @return null |
6a488035 | 87 | */ |
00be9182 | 88 | public function edit() { |
6a488035 TO |
89 | $controller = new CRM_Core_Controller_Simple('CRM_Pledge_Form_Pledge', |
90 | 'Create Pledge', | |
91 | $this->_action | |
92 | ); | |
93 | $controller->setEmbedded(TRUE); | |
94 | $controller->set('id', $this->_id); | |
95 | $controller->set('cid', $this->_contactId); | |
96 | ||
97 | return $controller->run(); | |
98 | } | |
99 | ||
00be9182 | 100 | public function preProcess() { |
353ffa53 | 101 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); |
6a488035 | 102 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
353ffa53 | 103 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
6a488035 TO |
104 | |
105 | if ($context == 'standalone') { | |
106 | $this->_action = CRM_Core_Action::ADD; | |
107 | } | |
108 | else { | |
109 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
110 | $this->assign('contactId', $this->_contactId); | |
111 | ||
112 | // check logged in url permission | |
113 | CRM_Contact_Page_View::checkUserPermission($this); | |
6a488035 TO |
114 | } |
115 | ||
116 | $this->assign('action', $this->_action); | |
117 | ||
118 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit pledges')) { | |
119 | // demote to view since user does not have edit pledge rights | |
120 | $this->_permission = CRM_Core_Permission::VIEW; | |
121 | $this->assign('permission', 'view'); | |
122 | } | |
123 | } | |
124 | ||
125 | /** | |
dc195289 | 126 | * the main function that is called when the page loads, it decides the which action has to be taken for the page. |
6a488035 | 127 | * |
76e7a76c | 128 | * @return null |
6a488035 | 129 | */ |
00be9182 | 130 | public function run() { |
6a488035 TO |
131 | $this->preProcess(); |
132 | ||
133 | // check if we can process credit card registration | |
9be1374d | 134 | $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); |
6a488035 | 135 | |
341c6436 | 136 | self::setContext($this); |
6a488035 TO |
137 | |
138 | if ($this->_action & CRM_Core_Action::VIEW) { | |
139 | $this->view(); | |
140 | } | |
141 | elseif ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE)) { | |
142 | $this->edit(); | |
143 | } | |
144 | elseif ($this->_action & CRM_Core_Action::DETACH) { | |
145 | CRM_Pledge_BAO_Pledge::cancel($this->_id); | |
146 | $session = CRM_Core_Session::singleton(); | |
147 | $session->setStatus(ts('Pledge has been Cancelled and all scheduled (not completed) payments have been cancelled.<br />')); | |
148 | CRM_Utils_System::redirect($session->popUserContext()); | |
149 | } | |
150 | else { | |
151 | $this->browse(); | |
152 | } | |
153 | ||
154 | return parent::run(); | |
155 | } | |
156 | ||
2e2605fe EM |
157 | /** |
158 | * Get context. | |
159 | * | |
160 | * @param $form | |
161 | */ | |
96c00f73 | 162 | public static function setContext(&$form) { |
341c6436 | 163 | $context = CRM_Utils_Request::retrieve('context', 'String', $form, FALSE, 'search'); |
6a488035 | 164 | |
341c6436 | 165 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $form); |
6a488035 TO |
166 | //validate the qfKey |
167 | if (!CRM_Utils_Rule::qfKey($qfKey)) { | |
168 | $qfKey = NULL; | |
169 | } | |
170 | ||
171 | switch ($context) { | |
172 | case 'dashboard': | |
173 | case 'pledgeDashboard': | |
174 | $url = CRM_Utils_System::url('civicrm/pledge', 'reset=1'); | |
175 | break; | |
176 | ||
177 | case 'search': | |
178 | $urlParams = 'force=1'; | |
179 | if ($qfKey) { | |
180 | $urlParams .= "&qfKey=$qfKey"; | |
181 | } | |
182 | ||
183 | $url = CRM_Utils_System::url('civicrm/pledge/search', $urlParams); | |
184 | break; | |
185 | ||
186 | case 'user': | |
187 | $url = CRM_Utils_System::url('civicrm/user', 'reset=1'); | |
188 | break; | |
189 | ||
190 | case 'pledge': | |
191 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
96c00f73 | 192 | "reset=1&force=1&cid={$form->_contactId}&selectedChild=pledge" |
6a488035 TO |
193 | ); |
194 | break; | |
195 | ||
196 | case 'home': | |
197 | $url = CRM_Utils_System::url('civicrm/dashboard', 'force=1'); | |
198 | break; | |
199 | ||
200 | case 'activity': | |
201 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
96c00f73 | 202 | "reset=1&force=1&cid={$form->_contactId}&selectedChild=activity" |
6a488035 TO |
203 | ); |
204 | break; | |
205 | ||
206 | case 'standalone': | |
207 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
208 | break; | |
209 | ||
210 | default: | |
211 | $cid = NULL; | |
341c6436 | 212 | if ($form->_contactId) { |
213 | $cid = '&cid=' . $form->_contactId; | |
6a488035 TO |
214 | } |
215 | $url = CRM_Utils_System::url('civicrm/pledge/search', | |
216 | 'force=1' . $cid | |
217 | ); | |
218 | break; | |
219 | } | |
220 | $session = CRM_Core_Session::singleton(); | |
221 | $session->pushUserContext($url); | |
222 | } | |
96025800 | 223 | |
6a488035 | 224 | } |