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