Merge pull request #2999 from GinkgoFJG/CRM-14545
[civicrm-core.git] / CRM / Event / Page / EventInfo.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Event Info Page - Summmary about the event
38 */
39class CRM_Event_Page_EventInfo extends CRM_Core_Page {
40
41 /**
42 * Run the page.
43 *
44 * This method is called after the page is created. It checks for the
45 * type of action and executes that action.
46 * Finally it calls the parent's run method.
47 *
48 * @return void
49 * @access public
50 *
51 */
52 function run() {
53 //get the event id.
54 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
55 $config = CRM_Core_Config::singleton();
56 // ensure that the user has permission to see this page
57 if (!CRM_Core_Permission::event(CRM_Core_Permission::VIEW,
58 $this->_id
59 )) {
60 CRM_Utils_System::setUFMessage(ts('You do not have permission to view this event'));
61 return CRM_Utils_System::permissionDenied();
62 }
63
64 $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
65 $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'register');
66 $this->assign('context', $context);
67
68 // Sometimes we want to suppress the Event Full msg
69 $noFullMsg = CRM_Utils_Request::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
70
71 // set breadcrumb to append to 2nd layer pages
72 $breadCrumbPath = CRM_Utils_System::url('civicrm/event/info',
73 "id={$this->_id}&reset=1"
74 );
75 $additionalBreadCrumb = "<a href=\"$breadCrumbPath\">" . ts('Events') . '</a>';
76
77 //retrieve event information
78 $params = array('id' => $this->_id);
79 CRM_Event_BAO_Event::retrieve($params, $values['event']);
80
81 if (!$values['event']['is_active']) {
82 // form is inactive, die a fatal death
83 CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
84 }
85
86 if (!empty($values['event']['is_template'])) {
87 // form is an Event Template
88 CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.'));
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());
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'])) {
6a488035
TO
98 //CRM-6907
99 $config = CRM_Core_Config::singleton();
100 $config->defaultCurrency = CRM_Utils_Array::value('currency',
101 $values['event'],
102 $config->defaultCurrency
103 );
104
105 //CRM-10434
106 $discountId= CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
107 if ($discountId) {
108 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
109 } else {
9da8dc8c 110 $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id);
6a488035
TO
111 }
112
113 // get price set options, - CRM-5209
114 if ($priceSetId) {
9da8dc8c 115 $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE);
6a488035
TO
116
117 $priceSetFields = $setDetails[$priceSetId]['fields'];
118 if (is_array($priceSetFields)) {
119 $fieldCnt = 1;
120 $visibility = CRM_Core_PseudoConstant::visibility('name');
121
122 foreach ($priceSetFields as $fid => $fieldValues) {
123 if (!is_array($fieldValues['options']) ||
124 empty($fieldValues['options']) ||
125 CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility)
126 ) {
127 continue;
128 }
129
130 if (count($fieldValues['options']) > 1) {
131 $values['feeBlock']['value'][$fieldCnt] = '';
132 $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
133 $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
134 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
135 $fieldCnt++;
136 $labelClass = 'price_set_option-label';
137 }
138 else {
139 $labelClass = 'price_set_field-label';
140 }
141
142 foreach ($fieldValues['options'] as $optionId => $optionVal) {
143 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
144 $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
145 $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
146 $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
147 $fieldCnt++;
148 }
149 }
150 }
151 // Tell tpl we have price set fee data and whether it's a quick_config price set
152 $this->assign('isPriceSet', 1);
153 $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
154 }
155 }
156
157 $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
158 $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
159
160 //retrieve custom field information
161 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']);
162 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
163 $this->assign('action', CRM_Core_Action::VIEW);
164 //To show the event location on maps directly on event info page
165 $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
8cc574cf 166 if (!empty($locations) && !empty($values['event']['is_map'])) {
6a488035
TO
167 $this->assign('locations', $locations);
168 $this->assign('mapProvider', $config->mapProvider);
169 $this->assign('mapKey', $config->mapAPIKey);
170 $sumLat = $sumLng = 0;
171 $maxLat = $maxLng = -400;
172 $minLat = $minLng = + 400;
173 foreach ($locations as $location) {
174 $sumLat += $location['lat'];
175 $sumLng += $location['lng'];
176
177 if ($location['lat'] > $maxLat) {
178 $maxLat = $location['lat'];
179 }
180 if ($location['lat'] < $minLat) {
181 $minLat = $location['lat'];
182 }
183
184 if ($location['lng'] > $maxLng) {
185 $maxLng = $location['lng'];
186 }
187 if ($location['lng'] < $minLng) {
188 $minLng = $location['lng'];
189 }
190 }
191
192 $center = array('lat' => (float ) $sumLat / count($locations),
193 'lng' => (float ) $sumLng / count($locations),
194 );
195 $span = array('lat' => (float )($maxLat - $minLat),
196 'lng' => (float )($maxLng - $minLng),
197 );
198 $this->assign_by_ref('center', $center);
199 $this->assign_by_ref('span', $span);
200 if ($action == CRM_Core_Action::PREVIEW) {
201 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
202 "eid={$this->_id}&reset=1&action=preview",
203 TRUE, NULL, TRUE,
204 TRUE
205 );
206 }
207 else {
208 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
209 "eid={$this->_id}&reset=1",
210 TRUE, NULL, TRUE,
211 TRUE
212 );
213 }
214
215 $this->assign('skipLocationType', TRUE);
216 $this->assign('mapURL', $mapURL);
217 }
218
219 if (CRM_Core_Permission::check('view event participants') &&
220 CRM_Core_Permission::check('view all contacts')
221 ) {
222 $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
223 $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0');
224 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
225 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
226 $this->assign('findParticipants', $findParticipants);
227 }
228
229 $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
230 if ($participantListingID) {
231 $participantListingURL = CRM_Utils_System::url('civicrm/event/participant',
232 "reset=1&id={$this->_id}",
233 TRUE, NULL, TRUE, TRUE
234 );
235 $this->assign('participantListingURL', $participantListingURL);
236 }
237
238 $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
239 $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id,
240 FALSE,
241 $hasWaitingList
242 );
243
244 $allowRegistration = FALSE;
a7488080 245 if (!empty($values['event']['is_online_registration'])) {
6a488035
TO
246 if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) {
247 // we always generate urls for the front end in joomla
248 $action_query = $action === CRM_Core_Action::PREVIEW ? "&action=$action" : '';
249 $url = CRM_Utils_System::url('civicrm/event/register',
250 "id={$this->_id}&reset=1{$action_query}",
251 TRUE, NULL, TRUE,
252 TRUE
253 );
254 if (!$eventFullMessage || $hasWaitingList) {
255 $registerText = ts('Register Now');
a7488080 256 if (!empty($values['event']['registration_link_text'])) {
6a488035
TO
257 $registerText = $values['event']['registration_link_text'];
258 }
259
260 // check if we're in shopping cart mode for events
261 $enable_cart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
262 'enable_cart'
263 );
264
265 if ($enable_cart) {
266 $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
267 $registerText = $link['label'];
268
269 $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
270 }
271
272 //Fixed for CRM-4855
273 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
274
275 $this->assign('registerText', $registerText);
276 $this->assign('registerURL', $url);
277 $this->assign('eventCartEnabled', $enable_cart);
278 }
279 }
280 elseif (CRM_Core_Permission::check('register for events')) {
281 $this->assign('registerClosed', TRUE);
282 }
283 }
284
285 $this->assign('allowRegistration', $allowRegistration);
286
287 $session = CRM_Core_Session::singleton();
288 $params = array('contact_id' => $session->get('userID'),
289 'event_id' => CRM_Utils_Array::value('id', $values['event']),
290 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']),
291 );
292
293 if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event::checkRegistration($params)) {
294 $statusMessage = $eventFullMessage;
295 if (CRM_Event_BAO_Event::checkRegistration($params)) {
296 if ($noFullMsg == 'false') {
297 if ($values['event']['allow_same_participant_emails']) {
298 $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.');
299 }
300 else {
301 $registerUrl = CRM_Utils_System::url('civicrm/event/register',
302 "reset=1&id={$values['event']['id']}&cid=0"
303 );
304 $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>.', array(1 => $registerUrl));
305 }
306 }
307 }
308 elseif ($hasWaitingList) {
309 $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
310 if (!$statusMessage) {
311 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
312 }
313 }
314
315 CRM_Core_Session::setStatus($statusMessage);
316 }
317 // we do not want to display recently viewed items, so turn off
318 $this->assign('displayRecent', FALSE);
319
320 // set page title = event title
321 CRM_Utils_System::setTitle($values['event']['title']);
322
323 $this->assign('event', $values['event']);
324 if (isset($values['feeBlock'])) {
325 $this->assign('feeBlock', $values['feeBlock']);
326 }
327 $this->assign('location', $values['location']);
328
329 return parent::run();
330 }
331
332 function getTemplateFileName() {
333 if ($this->_id) {
334 $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
335 $template = CRM_Core_Page::getTemplate();
336
337 if ($template->template_exists($templateFile)) {
338 return $templateFile;
339 }
340 }
341 return parent::getTemplateFileName();
342 }
343}
344