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