Merge pull request #15833 from yashodha/participant_edit
[civicrm-core.git] / CRM / Event / Page / EventInfo.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
f299f7db 6 | Copyright CiviCRM LLC (c) 2004-2020 |
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
f299f7db 31 * @copyright CiviCRM LLC (c) 2004-2020
6a488035
TO
32 */
33
34/**
35 * Event Info Page - Summmary about the event
36 */
37class CRM_Event_Page_EventInfo extends CRM_Core_Page {
38
39 /**
40 * Run the page.
41 *
42 * This method is called after the page is created. It checks for the
43 * type of action and executes that action.
44 * Finally it calls the parent's run method.
45 *
46 * @return void
6a488035 47 */
00be9182 48 public function run() {
6a488035
TO
49 //get the event id.
50 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
51 $config = CRM_Core_Config::singleton();
52 // ensure that the user has permission to see this page
53 if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW,
353ffa53
TO
54 $this->_id, 'view event info'
55 )
56 ) {
6a488035
TO
57 CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
58 return CRM_Utils_System::permissionDenied();
59 }
60
61 $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
edc80cda 62 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'register');
6a488035
TO
63 $this->assign('context', $context);
64
65 // Sometimes we want to suppress the Event Full msg
66 $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
67
68 // set breadcrumb to append to 2nd layer pages
69 $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info',
70 "id={$this->_id}&reset=1"
71 );
6a488035
TO
72
73 //retrieve event information
be2fb01f 74 $params = ['id' => $this->_id];
6a488035
TO
75 CRM_Event_BAO_Event::retrieve($params, $values['event']);
76
77 if (!$values['event']['is_active']) {
12cc37ef
SB
78 CRM_Utils_System::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
79 return CRM_Utils_System::permissionDenied();
6a488035
TO
80 }
81
c6d4092b
RO
82 if (!$values['event']['is_public']) {
83 CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
84 }
85
6a488035
TO
86 if (!empty($values['event']['is_template'])) {
87 // form is an Event Template
e22ec653 88 CRM_Core_Error::statusBounce(ts('The page you requested is currently unavailable.'));
6a488035
TO
89 }
90
4b351970
DG
91 // Add Event Type to $values in case folks want to display it
92 $values['event']['event_type'] = CRM_Utils_Array::value($values['event']['event_type_id'], CRM_Event_PseudoConstant::eventType());
e2d09ab4 93
6a488035
TO
94 $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
95
96 // show event fees.
8cc574cf 97 if ($this->_id && !empty($values['event']['is_monetary'])) {
85939a77 98 CRM_Contribute_BAO_Contribution_Utils::overrideDefaultCurrency($values['event']);
6a488035
TO
99
100 //CRM-10434
d3e86119 101 $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
6a488035
TO
102 if ($discountId) {
103 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
0db6c3e1
TO
104 }
105 else {
9da8dc8c 106 $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
6a488035
TO
107 }
108
109 // get price set options, - CRM-5209
110 if ($priceSetId) {
9da8dc8c 111 $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
6a488035
TO
112
113 $priceSetFields = $setDetails[$priceSetId]['fields'];
114 if (is_array($priceSetFields)) {
115 $fieldCnt = 1;
116 $visibility = CRM_Core_PseudoConstant::visibility('name');
117
c7b3d063 118 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
ab8a593e 119 $adminFieldVisible = FALSE;
c7b3d063 120 if (CRM_Core_Permission::check('administer CiviCRM')) {
4eeb9a5b 121 $adminFieldVisible = TRUE;
c7b3d063
DG
122 }
123
6a488035
TO
124 foreach ($priceSetFields as $fid => $fieldValues) {
125 if (!is_array($fieldValues['options']) ||
126 empty($fieldValues['options']) ||
ab8a593e 127 (CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE)
6a488035
TO
128 ) {
129 continue;
130 }
131
132 if (count($fieldValues['options']) > 1) {
133 $values['feeBlock']['value'][$fieldCnt] = '';
134 $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
135 $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
136 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
137 $fieldCnt++;
138 $labelClass = 'price_set_option-label';
139 }
140 else {
141 $labelClass = 'price_set_field-label';
142 }
3a669c96 143 // show tax rate with amount
aaffa79f 144 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
fe7983e7
PD
145 $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
146 $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings);
147 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
6a488035 148 foreach ($fieldValues['options'] as $optionId => $optionVal) {
c6833879
BS
149 if (CRM_Utils_Array::value('visibility_id', $optionVal) != array_search('public', $visibility) &&
150 $adminFieldVisible == FALSE
151 ) {
152 continue;
153 }
154
6a488035 155 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
fe7983e7
PD
156 if ($invoicing && isset($optionVal['tax_amount'])) {
157 $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
3a669c96 158 $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
159 }
160 else {
161 $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
162 }
6a488035
TO
163 $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
164 $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
165 $fieldCnt++;
166 }
167 }
168 }
169 // Tell tpl we have price set fee data and whether it's a quick_config price set
170 $this->assign('isPriceSet', 1);
171 $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
172 }
353ffa53 173 }
6a488035 174
be2fb01f 175 $params = ['entity_id' => $this->_id, 'entity_table' => 'civicrm_event'];
6a488035
TO
176 $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
177
45618a70 178 // fix phone type labels
179 if (!empty($values['location']['phone'])) {
180 $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
181 foreach ($values['location']['phone'] as &$val) {
182 if (!empty($val['phone_type_id'])) {
183 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
184 }
185 }
186 }
187
6a488035 188 //retrieve custom field information
0b330e6d 189 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, $this->_id, 0, $values['event']['event_type_id'], NULL, TRUE, NULL, FALSE, TRUE, NULL, TRUE);
e34e6979 190 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
6a488035
TO
191 $this->assign('action', CRM_Core_Action::VIEW);
192 //To show the event location on maps directly on event info page
193 $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
8cc574cf 194 if (!empty($locations) && !empty($values['event']['is_map'])) {
6a488035
TO
195 $this->assign('locations', $locations);
196 $this->assign('mapProvider', $config->mapProvider);
197 $this->assign('mapKey', $config->mapAPIKey);
198 $sumLat = $sumLng = 0;
199 $maxLat = $maxLng = -400;
8d7a9d07 200 $minLat = $minLng = 400;
6a488035
TO
201 foreach ($locations as $location) {
202 $sumLat += $location['lat'];
203 $sumLng += $location['lng'];
204
205 if ($location['lat'] > $maxLat) {
206 $maxLat = $location['lat'];
207 }
208 if ($location['lat'] < $minLat) {
209 $minLat = $location['lat'];
210 }
211
212 if ($location['lng'] > $maxLng) {
213 $maxLng = $location['lng'];
214 }
215 if ($location['lng'] < $minLng) {
216 $minLng = $location['lng'];
217 }
218 }
219
be2fb01f 220 $center = [
6ea503d4 221 'lat' => (float ) $sumLat / count($locations),
6a488035 222 'lng' => (float ) $sumLng / count($locations),
be2fb01f
CW
223 ];
224 $span = [
353ffa53
TO
225 'lat' => (float ) ($maxLat - $minLat),
226 'lng' => (float ) ($maxLng - $minLng),
be2fb01f 227 ];
6a488035
TO
228 $this->assign_by_ref('center', $center);
229 $this->assign_by_ref('span', $span);
230 if ($action == CRM_Core_Action::PREVIEW) {
231 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
232 "eid={$this->_id}&reset=1&action=preview",
53c223bf 233 FALSE, NULL, TRUE,
6a488035
TO
234 TRUE
235 );
236 }
237 else {
238 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
239 "eid={$this->_id}&reset=1",
53c223bf 240 FALSE, NULL, TRUE,
6a488035
TO
241 TRUE
242 );
243 }
244
245 $this->assign('skipLocationType', TRUE);
246 $this->assign('mapURL', $mapURL);
247 }
248
4cdc90e9
DH
249 if (CRM_Core_Permission::check('view event participants')) {
250 $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
251 $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
252 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
253 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
254 $this->assign('findParticipants', $findParticipants);
255 }
6a488035
TO
256
257 $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
258 if ($participantListingID) {
259 $participantListingURL = CRM_Utils_System::url('civicrm/event/participant',
260 "reset=1&id={$this->_id}",
53c223bf 261 FALSE, NULL, TRUE, TRUE
6a488035
TO
262 );
263 $this->assign('participantListingURL', $participantListingURL);
264 }
265
266 $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
267 $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id,
268 FALSE,
269 $hasWaitingList
270 );
271
272 $allowRegistration = FALSE;
5c6fa26c 273 $isEventOpenForRegistration = CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id);
a7488080 274 if (!empty($values['event']['is_online_registration'])) {
5c6fa26c 275 if ($isEventOpenForRegistration == 1) {
6a488035
TO
276 // we always generate urls for the front end in joomla
277 $action_query = $action === CRM_Core_Action::PREVIEW ? "&action=$action" : '';
278 $url = CRM_Utils_System::url('civicrm/event/register',
279 "id={$this->_id}&reset=1{$action_query}",
53c223bf 280 FALSE, NULL, TRUE,
6a488035
TO
281 TRUE
282 );
283 if (!$eventFullMessage || $hasWaitingList) {
284 $registerText = ts('Register Now');
a7488080 285 if (!empty($values['event']['registration_link_text'])) {
6a488035
TO
286 $registerText = $values['event']['registration_link_text'];
287 }
288
289 // check if we're in shopping cart mode for events
aaffa79f 290 $enable_cart = Civi::settings()->get('enable_cart');
6a488035
TO
291 if ($enable_cart) {
292 $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
293 $registerText = $link['label'];
294
53c223bf 295 $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, FALSE, NULL, TRUE, TRUE);
6a488035
TO
296 }
297
298 //Fixed for CRM-4855
299 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
300
301 $this->assign('registerText', $registerText);
302 $this->assign('registerURL', $url);
303 $this->assign('eventCartEnabled', $enable_cart);
304 }
305 }
306 elseif (CRM_Core_Permission::check('register for events')) {
307 $this->assign('registerClosed', TRUE);
308 }
309 }
310
311 $this->assign('allowRegistration', $allowRegistration);
312
313 $session = CRM_Core_Session::singleton();
be2fb01f 314 $params = [
6ea503d4 315 'contact_id' => $session->get('userID'),
6a488035
TO
316 'event_id' => CRM_Utils_Array::value('id', $values['event']),
317 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']),
be2fb01f 318 ];
6a488035
TO
319
320 if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event::checkRegistration($params)) {
321 $statusMessage = $eventFullMessage;
322 if (CRM_Event_BAO_Event::checkRegistration($params)) {
323 if ($noFullMsg == 'false') {
324 if ($values['event']['allow_same_participant_emails']) {
325 $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.');
326 }
327 else {
328 $registerUrl = CRM_Utils_System::url('civicrm/event/register',
329 "reset=1&id={$values['event']['id']}&cid=0"
330 );
be2fb01f 331 $statusMessage = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', [1 => $registerUrl]);
6a488035
TO
332 }
333 }
334 }
335 elseif ($hasWaitingList) {
336 $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
337 if (!$statusMessage) {
338 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
339 }
340 }
5c6fa26c
JM
341 if ($isEventOpenForRegistration == 1) {
342 CRM_Core_Session::setStatus($statusMessage);
343 }
6a488035
TO
344 }
345 // we do not want to display recently viewed items, so turn off
346 $this->assign('displayRecent', FALSE);
347
348 // set page title = event title
349 CRM_Utils_System::setTitle($values['event']['title']);
350
351 $this->assign('event', $values['event']);
352 if (isset($values['feeBlock'])) {
353 $this->assign('feeBlock', $values['feeBlock']);
354 }
355 $this->assign('location', $values['location']);
356
fdf80679 357 if (CRM_Core_Permission::check('access CiviEvent')) {
aaffa79f 358 $enableCart = Civi::settings()->get('enable_cart');
fdf80679
CW
359 $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs($enableCart));
360 }
361
6a488035
TO
362 return parent::run();
363 }
364
0cf587a7
EM
365 /**
366 * @return string
367 */
00be9182 368 public function getTemplateFileName() {
6a488035
TO
369 if ($this->_id) {
370 $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
371 $template = CRM_Core_Page::getTemplate();
372
373 if ($template->template_exists($templateFile)) {
374 return $templateFile;
375 }
376 }
377 return parent::getTemplateFileName();
378 }
96025800 379
6a488035 380}