Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Event_Page_Tab extends CRM_Core_Page { | |
36 | ||
37 | public $_permission = NULL; | |
38 | public $_contactId = NULL; | |
39 | ||
40 | /** | |
fe482240 | 41 | * called when action is browse. |
6a488035 | 42 | */ |
00be9182 | 43 | public function browse() { |
6a488035 TO |
44 | $controller = new CRM_Core_Controller_Simple( |
45 | 'CRM_Event_Form_Search', | |
46 | ts('Events'), | |
47 | $this->_action | |
48 | ); | |
49 | $controller->setEmbedded(TRUE); | |
50 | $controller->reset(); | |
51 | $controller->set('cid', $this->_contactId); | |
52 | $controller->set('context', 'participant'); | |
53 | $controller->process(); | |
54 | $controller->run(); | |
55 | ||
56 | if ($this->_contactId) { | |
57 | $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId); | |
58 | $this->assign('displayName', $displayName); | |
4e8065a9 | 59 | $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('participant', $this->_contactId); |
fa9fbb61 | 60 | // Refresh other tabs with related data |
2840a035 | 61 | $this->ajaxResponse['updateTabs'] = array( |
fa9fbb61 | 62 | '#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId), |
2840a035 | 63 | ); |
c312052e CW |
64 | if (CRM_Core_Permission::access('CiviContribute')) { |
65 | $this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId); | |
66 | } | |
6a488035 TO |
67 | } |
68 | } | |
69 | ||
70 | /** | |
fe482240 | 71 | * called when action is view. |
6a488035 | 72 | * |
76e7a76c | 73 | * @return null |
6a488035 | 74 | */ |
00be9182 | 75 | public function view() { |
6a488035 TO |
76 | // build associated contributions |
77 | $this->associatedContribution(); | |
78 | ||
79 | $controller = new CRM_Core_Controller_Simple( | |
80 | 'CRM_Event_Form_ParticipantView', | |
81 | ts('View Participant'), | |
82 | $this->_action | |
83 | ); | |
84 | $controller->setEmbedded(TRUE); | |
85 | $controller->set('id', $this->_id); | |
86 | $controller->set('cid', $this->_contactId); | |
87 | ||
88 | return $controller->run(); | |
89 | } | |
90 | ||
91 | /** | |
fe482240 | 92 | * called when action is update or new. |
6a488035 | 93 | * |
76e7a76c | 94 | * @return null |
6a488035 | 95 | */ |
00be9182 | 96 | public function edit() { |
6a488035 TO |
97 | // set https for offline cc transaction |
98 | $mode = CRM_Utils_Request::retrieve('mode', 'String', $this); | |
99 | if ($mode == 'test' || $mode == 'live') { | |
100 | CRM_Utils_System::redirectToSSL(); | |
101 | } | |
102 | ||
103 | if ($this->_action != CRM_Core_Action::ADD) { | |
104 | // get associated contributions only on edit/delete | |
105 | $this->associatedContribution(); | |
106 | } | |
107 | ||
108 | $controller = new CRM_Core_Controller_Simple( | |
109 | 'CRM_Event_Form_Participant', | |
110 | 'Create Participation', | |
111 | $this->_action | |
112 | ); | |
113 | ||
114 | $controller->setEmbedded(TRUE); | |
115 | $controller->set('id', $this->_id); | |
116 | $controller->set('cid', $this->_contactId); | |
117 | ||
118 | return $controller->run(); | |
119 | } | |
120 | ||
00be9182 | 121 | public function preProcess() { |
353ffa53 | 122 | $context = CRM_Utils_Request::retrieve('context', 'String', $this); |
6a488035 | 123 | $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); |
353ffa53 | 124 | $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); |
6a488035 TO |
125 | |
126 | if ($context == 'standalone') { | |
127 | $this->_action = CRM_Core_Action::ADD; | |
128 | } | |
129 | else { | |
130 | $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE); | |
131 | $this->assign('contactId', $this->_contactId); | |
132 | ||
133 | // check logged in url permission | |
134 | CRM_Contact_Page_View::checkUserPermission($this); | |
6a488035 TO |
135 | } |
136 | ||
137 | $this->assign('action', $this->_action); | |
138 | ||
139 | if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit event participants')) { | |
140 | // demote to view since user does not have edit event participants rights | |
141 | $this->_permission = CRM_Core_Permission::VIEW; | |
142 | $this->assign('permission', 'view'); | |
143 | } | |
144 | } | |
145 | ||
146 | /** | |
dc195289 | 147 | * the main function that is called when the page loads, it decides the which action has to be taken for the page. |
6a488035 | 148 | * |
76e7a76c | 149 | * @return null |
6a488035 | 150 | */ |
00be9182 | 151 | public function run() { |
6a488035 TO |
152 | $this->preProcess(); |
153 | ||
154 | // check if we can process credit card registration | |
9be1374d | 155 | $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()); |
6a488035 TO |
156 | |
157 | // Only show credit card registration button if user has CiviContribute permission | |
158 | if (CRM_Core_Permission::access('CiviContribute')) { | |
159 | $this->assign('accessContribution', TRUE); | |
160 | } | |
161 | else { | |
162 | $this->assign('accessContribution', FALSE); | |
163 | } | |
164 | ||
165 | $this->setContext(); | |
166 | ||
167 | if ($this->_action & CRM_Core_Action::VIEW) { | |
168 | $this->view(); | |
169 | } | |
170 | elseif ($this->_action & (CRM_Core_Action::UPDATE | | |
171 | CRM_Core_Action::ADD | | |
172 | CRM_Core_Action::DELETE | |
353ffa53 TO |
173 | ) |
174 | ) { | |
6a488035 TO |
175 | $this->edit(); |
176 | } | |
177 | else { | |
178 | $this->browse(); | |
179 | } | |
180 | ||
181 | return parent::run(); | |
182 | } | |
183 | ||
00be9182 | 184 | public function setContext() { |
6a488035 TO |
185 | $context = CRM_Utils_Request::retrieve('context', |
186 | 'String', $this, FALSE, 'search' | |
187 | ); | |
188 | $compContext = CRM_Utils_Request::retrieve('compContext', | |
189 | 'String', $this | |
190 | ); | |
191 | ||
29571f63 AS |
192 | $searchContext = CRM_Utils_Request::retrieve('searchContext', 'String', $this); |
193 | ||
6a488035 TO |
194 | $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this); |
195 | ||
196 | //validate the qfKey | |
197 | if (!CRM_Utils_Rule::qfKey($qfKey)) { | |
198 | $qfKey = NULL; | |
199 | } | |
200 | ||
201 | switch ($context) { | |
202 | case 'dashboard': | |
203 | $url = CRM_Utils_System::url('civicrm/event', 'reset=1'); | |
204 | break; | |
205 | ||
206 | case 'search': | |
207 | $urlParams = 'force=1'; | |
208 | if ($qfKey) { | |
209 | $urlParams .= "&qfKey=$qfKey"; | |
210 | } | |
211 | $this->assign('searchKey', $qfKey); | |
212 | ||
213 | if ($compContext == 'advanced') { | |
214 | $url = CRM_Utils_System::url('civicrm/contact/search/advanced', $urlParams); | |
215 | } | |
4c9b6178 | 216 | elseif ($searchContext) { |
4c1b5b2e | 217 | $url = CRM_Utils_System::url("civicrm/$searchContext/search", $urlParams); |
29571f63 | 218 | } |
6a488035 TO |
219 | else { |
220 | $url = CRM_Utils_System::url('civicrm/event/search', $urlParams); | |
221 | } | |
222 | break; | |
223 | ||
224 | case 'user': | |
225 | $url = CRM_Utils_System::url('civicrm/user', 'reset=1'); | |
226 | break; | |
227 | ||
228 | case 'participant': | |
229 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
230 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=participant" | |
231 | ); | |
232 | break; | |
233 | ||
234 | case 'home': | |
235 | $url = CRM_Utils_System::url('civicrm/dashboard', 'force=1'); | |
236 | break; | |
237 | ||
238 | case 'activity': | |
239 | $url = CRM_Utils_System::url('civicrm/contact/view', | |
240 | "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity" | |
241 | ); | |
242 | break; | |
243 | ||
244 | case 'standalone': | |
245 | $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); | |
246 | break; | |
247 | ||
248 | case 'fulltext': | |
353ffa53 | 249 | $keyName = '&qfKey'; |
6a488035 TO |
250 | $urlParams = 'force=1'; |
251 | $urlString = 'civicrm/contact/search/custom'; | |
252 | if ($this->_action == CRM_Core_Action::UPDATE) { | |
253 | if ($this->_contactId) { | |
254 | $urlParams .= '&cid=' . $this->_contactId; | |
255 | } | |
256 | $keyName = '&key'; | |
257 | $urlParams .= '&context=fulltext&action=view'; | |
258 | $urlString = 'civicrm/contact/view/participant'; | |
259 | } | |
260 | if ($qfKey) { | |
261 | $urlParams .= "$keyName=$qfKey"; | |
262 | } | |
263 | $this->assign('searchKey', $qfKey); | |
264 | $url = CRM_Utils_System::url($urlString, $urlParams); | |
265 | break; | |
266 | ||
267 | default: | |
268 | $cid = NULL; | |
269 | if ($this->_contactId) { | |
270 | $cid = '&cid=' . $this->_contactId; | |
271 | } | |
272 | $url = CRM_Utils_System::url('civicrm/event/search', | |
273 | 'force=1' . $cid | |
274 | ); | |
275 | break; | |
276 | } | |
277 | $session = CRM_Core_Session::singleton(); | |
278 | $session->pushUserContext($url); | |
279 | } | |
280 | ||
281 | /** | |
dc195289 | 282 | * used for the to show the associated |
6a488035 | 283 | * contribution for the participant |
6a488035 | 284 | */ |
00be9182 | 285 | public function associatedContribution() { |
6a488035 TO |
286 | if (CRM_Core_Permission::access('CiviContribute')) { |
287 | $this->assign('accessContribution', TRUE); | |
288 | $controller = new CRM_Core_Controller_Simple( | |
289 | 'CRM_Contribute_Form_Search', | |
290 | ts('Contributions'), | |
291 | NULL, | |
292 | FALSE, FALSE, TRUE | |
293 | ); | |
294 | $controller->setEmbedded(TRUE); | |
295 | $controller->set('force', 1); | |
296 | $controller->set('cid', $this->_contactId); | |
297 | $controller->set('participantId', $this->_id); | |
298 | $controller->set('context', 'contribution'); | |
299 | $controller->process(); | |
300 | $controller->run(); | |
301 | } | |
302 | else { | |
303 | $this->assign('accessContribution', FALSE); | |
304 | } | |
305 | } | |
96025800 | 306 | |
6a488035 | 307 | } |