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