Add upgrade for label to name conversion
[civicrm-core.git] / CRM / Event / Page / EventInfo.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * Event Info Page - Summary about the event
20 */
21 class 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
31 */
32 public function run() {
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,
38 $this->_id, 'view event info'
39 )
40 ) {
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);
46 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this, FALSE, 'register');
47 $this->assign('context', $context);
48
49 $this->assign('iCal', CRM_Event_BAO_Event::getICalLinks($this->_id));
50
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 );
58
59 //retrieve event information
60 $params = ['id' => $this->_id];
61 $values = ['event' => NULL];
62 CRM_Event_BAO_Event::retrieve($params, $values['event']);
63
64 if (!$values['event']['is_active']) {
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();
67 }
68
69 if (!$values['event']['is_public']) {
70 CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
71 }
72
73 if (!empty($values['event']['is_template'])) {
74 // form is an Event Template
75 CRM_Core_Error::statusBounce(ts('The page you requested is currently unavailable.'));
76 }
77
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());
80
81 $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
82
83 $eventCurrency = CRM_Utils_Array::value('currency', $values['event'], $config->defaultCurrency);
84 $this->assign('eventCurrency', $eventCurrency);
85
86 // show event fees.
87 if ($this->_id && !empty($values['event']['is_monetary'])) {
88
89 //CRM-10434
90 $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
91 if ($discountId) {
92 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
93 }
94 else {
95 $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
96 }
97
98 // get price set options, - CRM-5209
99 if ($priceSetId) {
100 $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
101
102 $priceSetFields = $setDetails[$priceSetId]['fields'];
103 if (is_array($priceSetFields)) {
104 $fieldCnt = 1;
105 $visibility = CRM_Core_PseudoConstant::visibility('name');
106
107 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
108 $adminFieldVisible = FALSE;
109 if (CRM_Core_Permission::check('administer CiviCRM')) {
110 $adminFieldVisible = TRUE;
111 }
112
113 foreach ($priceSetFields as $fid => $fieldValues) {
114 if (!is_array($fieldValues['options']) ||
115 empty($fieldValues['options']) ||
116 (CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE)
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';
125 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = $fieldValues['is_display_amounts'] ?? NULL;
126 $fieldCnt++;
127 $labelClass = 'price_set_option-label';
128 }
129 else {
130 $labelClass = 'price_set_field-label';
131 }
132
133 foreach ($fieldValues['options'] as $optionId => $optionVal) {
134 if (CRM_Utils_Array::value('visibility_id', $optionVal) != array_search('public', $visibility) &&
135 $adminFieldVisible == FALSE
136 ) {
137 continue;
138 }
139
140 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = $fieldValues['is_display_amounts'] ?? NULL;
141 if (Civi::settings()->get('invoicing') && isset($optionVal['tax_amount'])) {
142 $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $eventCurrency);
143 $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
144 }
145 else {
146 $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
147 $values['feeBlock']['tax_amount'][$fieldCnt] = 0;
148 }
149 $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
150 $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
151 $fieldCnt++;
152 }
153 }
154 }
155 // Tell tpl we have price set fee data and whether it's a quick_config price set
156 $this->assign('isPriceSet', 1);
157 $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
158 }
159 }
160
161 $params = ['entity_id' => $this->_id, 'entity_table' => 'civicrm_event'];
162 $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
163
164 // fix phone type labels
165 if (!empty($values['location']['phone'])) {
166 $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
167 foreach ($values['location']['phone'] as &$val) {
168 if (!empty($val['phone_type_id'])) {
169 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
170 }
171 }
172 }
173
174 //retrieve custom field information
175 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', NULL, $this->_id, 0, $values['event']['event_type_id'], NULL,
176 TRUE, NULL, FALSE, CRM_Core_Permission::VIEW, NULL, TRUE);
177 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
178 $this->assign('action', CRM_Core_Action::VIEW);
179 //To show the event location on maps directly on event info page
180 $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
181 if (!empty($locations) && !empty($values['event']['is_map'])) {
182 $this->assign('locations', $locations);
183 $this->assign('mapProvider', $config->mapProvider);
184 $this->assign('mapKey', $config->mapAPIKey);
185 $sumLat = $sumLng = 0;
186 $maxLat = $maxLng = -400;
187 $minLat = $minLng = 400;
188 foreach ($locations as $location) {
189 $sumLat += $location['lat'];
190 $sumLng += $location['lng'];
191
192 if ($location['lat'] > $maxLat) {
193 $maxLat = $location['lat'];
194 }
195 if ($location['lat'] < $minLat) {
196 $minLat = $location['lat'];
197 }
198
199 if ($location['lng'] > $maxLng) {
200 $maxLng = $location['lng'];
201 }
202 if ($location['lng'] < $minLng) {
203 $minLng = $location['lng'];
204 }
205 }
206
207 $center = [
208 'lat' => (float ) $sumLat / count($locations),
209 'lng' => (float ) $sumLng / count($locations),
210 ];
211 $span = [
212 'lat' => (float ) ($maxLat - $minLat),
213 'lng' => (float ) ($maxLng - $minLng),
214 ];
215 $this->assign_by_ref('center', $center);
216 $this->assign_by_ref('span', $span);
217 if ($action == CRM_Core_Action::PREVIEW) {
218 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
219 "eid={$this->_id}&reset=1&action=preview",
220 FALSE, NULL, TRUE,
221 TRUE
222 );
223 }
224 else {
225 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
226 "eid={$this->_id}&reset=1",
227 FALSE, NULL, TRUE,
228 TRUE
229 );
230 }
231
232 $this->assign('skipLocationType', TRUE);
233 $this->assign('mapURL', $mapURL);
234 }
235
236 if (CRM_Core_Permission::check('view event participants')) {
237 $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label');
238 $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label');
239 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
240 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
241 $this->assign('findParticipants', $findParticipants);
242 }
243
244 $participantListingID = $values['event']['participant_listing_id'] ?? NULL;
245 if ($participantListingID) {
246 $participantListingURL = CRM_Utils_System::url('civicrm/event/participant',
247 "reset=1&id={$this->_id}",
248 FALSE, NULL, TRUE, TRUE
249 );
250 $this->assign('participantListingURL', $participantListingURL);
251 }
252
253 $hasWaitingList = $values['event']['has_waitlist'] ?? NULL;
254 $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id,
255 FALSE,
256 $hasWaitingList
257 );
258
259 $allowRegistration = FALSE;
260 $isEventOpenForRegistration = CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id);
261 if (!empty($values['event']['is_online_registration'])) {
262 if ($isEventOpenForRegistration == 1) {
263 // we always generate urls for the front end in joomla
264 $action_query = $action === CRM_Core_Action::PREVIEW ? "&action=$action" : '';
265 $url = CRM_Utils_System::url('civicrm/event/register',
266 "id={$this->_id}&reset=1{$action_query}",
267 FALSE, NULL, TRUE,
268 TRUE
269 );
270 if (!$eventFullMessage || $hasWaitingList) {
271 $registerText = ts('Register Now');
272 if (!empty($values['event']['registration_link_text'])) {
273 $registerText = $values['event']['registration_link_text'];
274 }
275
276 //Fixed for CRM-4855
277 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
278
279 $this->assign('registerText', $registerText);
280 $this->assign('registerURL', $url);
281 }
282 }
283 elseif (CRM_Core_Permission::check('register for events')) {
284 $this->assign('registerClosed', TRUE);
285 }
286 }
287
288 $this->assign('allowRegistration', $allowRegistration);
289
290 $session = CRM_Core_Session::singleton();
291 $params = [
292 'contact_id' => $session->get('userID'),
293 'event_id' => $values['event']['id'] ?? NULL,
294 'role_id' => $values['event']['default_role_id'] ?? NULL,
295 ];
296
297 if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event::checkRegistration($params)) {
298 $statusMessage = $eventFullMessage;
299 if (CRM_Event_BAO_Event::checkRegistration($params)) {
300 if ($noFullMsg == 'false') {
301 if ($values['event']['allow_same_participant_emails']) {
302 $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.');
303 }
304 else {
305 $registerUrl = CRM_Utils_System::url('civicrm/event/register',
306 "reset=1&id={$values['event']['id']}&cid=0"
307 );
308 $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]);
309 }
310 }
311 }
312 elseif ($hasWaitingList) {
313 $statusMessage = $values['event']['waitlist_text'] ?? NULL;
314 if (!$statusMessage) {
315 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
316 }
317 }
318 if ($isEventOpenForRegistration == 1) {
319 CRM_Core_Session::setStatus($statusMessage);
320 }
321 }
322 // we do not want to display recently viewed items, so turn off
323 $this->assign('displayRecent', FALSE);
324
325 // set page title = event title
326 CRM_Utils_System::setTitle($values['event']['title']);
327
328 $this->assign('event', $values['event']);
329 if (isset($values['feeBlock'])) {
330 $this->assign('feeBlock', $values['feeBlock']);
331 }
332 $this->assign('location', $values['location']);
333
334 if (CRM_Core_Permission::check(['access CiviEvent', 'edit all events'])) {
335 $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs());
336 }
337
338 return parent::run();
339 }
340
341 /**
342 * @return string
343 */
344 public function getTemplateFileName() {
345 if ($this->_id) {
346 $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
347 $template = CRM_Core_Page::getTemplate();
348
349 if ($template->template_exists($templateFile)) {
350 return $templateFile;
351 }
352 }
353 return parent::getTemplateFileName();
354 }
355
356 }