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