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