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