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