Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Event / Page / EventInfo.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
31 * @copyright CiviCRM LLC (c) 2004-2013
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
91 $this->assign('isShowLocation', CRM_Utils_Array::value('is_show_location', $values['event']));
92
93 // show event fees.
94 if ($this->_id && CRM_Utils_Array::value('is_monetary', $values['event'])) {
95 //CRM-6907
96 $config = CRM_Core_Config::singleton();
97 $config->defaultCurrency = CRM_Utils_Array::value('currency',
98 $values['event'],
99 $config->defaultCurrency
100 );
101
102 //CRM-10434
103 $discountId= CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event');
104 if ($discountId) {
105 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
106 } else {
107 $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $this->_id);
108 }
109
110 // get price set options, - CRM-5209
111 if ($priceSetId) {
112 $setDetails = CRM_Price_BAO_Set::getSetDetail($priceSetId, TRUE, TRUE);
113
114 $priceSetFields = $setDetails[$priceSetId]['fields'];
115 if (is_array($priceSetFields)) {
116 $fieldCnt = 1;
117 $visibility = CRM_Core_PseudoConstant::visibility('name');
118
119 foreach ($priceSetFields as $fid => $fieldValues) {
120 if (!is_array($fieldValues['options']) ||
121 empty($fieldValues['options']) ||
122 CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility)
123 ) {
124 continue;
125 }
126
127 if (count($fieldValues['options']) > 1) {
128 $values['feeBlock']['value'][$fieldCnt] = '';
129 $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
130 $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
131 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
132 $fieldCnt++;
133 $labelClass = 'price_set_option-label';
134 }
135 else {
136 $labelClass = 'price_set_field-label';
137 }
138
139 foreach ($fieldValues['options'] as $optionId => $optionVal) {
140 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues);
141 $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
142 $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
143 $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
144 $fieldCnt++;
145 }
146 }
147 }
148 // Tell tpl we have price set fee data and whether it's a quick_config price set
149 $this->assign('isPriceSet', 1);
150 $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
151 }
152 }
153
154 $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event');
155 $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
156
157 //retrieve custom field information
158 $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']);
159 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree);
160 $this->assign('action', CRM_Core_Action::VIEW);
161 //To show the event location on maps directly on event info page
162 $locations = CRM_Event_BAO_Event::getMapInfo($this->_id);
163 if (!empty($locations) && CRM_Utils_Array::value('is_map', $values['event'])) {
164 $this->assign('locations', $locations);
165 $this->assign('mapProvider', $config->mapProvider);
166 $this->assign('mapKey', $config->mapAPIKey);
167 $sumLat = $sumLng = 0;
168 $maxLat = $maxLng = -400;
169 $minLat = $minLng = + 400;
170 foreach ($locations as $location) {
171 $sumLat += $location['lat'];
172 $sumLng += $location['lng'];
173
174 if ($location['lat'] > $maxLat) {
175 $maxLat = $location['lat'];
176 }
177 if ($location['lat'] < $minLat) {
178 $minLat = $location['lat'];
179 }
180
181 if ($location['lng'] > $maxLng) {
182 $maxLng = $location['lng'];
183 }
184 if ($location['lng'] < $minLng) {
185 $minLng = $location['lng'];
186 }
187 }
188
189 $center = array('lat' => (float ) $sumLat / count($locations),
190 'lng' => (float ) $sumLng / count($locations),
191 );
192 $span = array('lat' => (float )($maxLat - $minLat),
193 'lng' => (float )($maxLng - $minLng),
194 );
195 $this->assign_by_ref('center', $center);
196 $this->assign_by_ref('span', $span);
197 if ($action == CRM_Core_Action::PREVIEW) {
198 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
199 "eid={$this->_id}&reset=1&action=preview",
200 TRUE, NULL, TRUE,
201 TRUE
202 );
203 }
204 else {
205 $mapURL = CRM_Utils_System::url('civicrm/contact/map/event',
206 "eid={$this->_id}&reset=1",
207 TRUE, NULL, TRUE,
208 TRUE
209 );
210 }
211
212 $this->assign('skipLocationType', TRUE);
213 $this->assign('mapURL', $mapURL);
214 }
215
216 if (CRM_Core_Permission::check('view event participants') &&
217 CRM_Core_Permission::check('view all contacts')
218 ) {
219 $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
220 $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0');
221 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
222 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
223 $this->assign('findParticipants', $findParticipants);
224 }
225
226 $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']);
227 if ($participantListingID) {
228 $participantListingURL = CRM_Utils_System::url('civicrm/event/participant',
229 "reset=1&id={$this->_id}",
230 TRUE, NULL, TRUE, TRUE
231 );
232 $this->assign('participantListingURL', $participantListingURL);
233 }
234
235 $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']);
236 $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id,
237 FALSE,
238 $hasWaitingList
239 );
240
241 $allowRegistration = FALSE;
242 if (CRM_Utils_Array::value('is_online_registration', $values['event'])) {
243 if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) {
244 // we always generate urls for the front end in joomla
245 $action_query = $action === CRM_Core_Action::PREVIEW ? "&action=$action" : '';
246 $url = CRM_Utils_System::url('civicrm/event/register',
247 "id={$this->_id}&reset=1{$action_query}",
248 TRUE, NULL, TRUE,
249 TRUE
250 );
251 if (!$eventFullMessage || $hasWaitingList) {
252 $registerText = ts('Register Now');
253 if (CRM_Utils_Array::value('registration_link_text', $values['event'])) {
254 $registerText = $values['event']['registration_link_text'];
255 }
256
257 // check if we're in shopping cart mode for events
258 $enable_cart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
259 'enable_cart'
260 );
261
262 if ($enable_cart) {
263 $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id);
264 $registerText = $link['label'];
265
266 $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
267 }
268
269 //Fixed for CRM-4855
270 $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values);
271
272 $this->assign('registerText', $registerText);
273 $this->assign('registerURL', $url);
274 $this->assign('eventCartEnabled', $enable_cart);
275 }
276 }
277 elseif (CRM_Core_Permission::check('register for events')) {
278 $this->assign('registerClosed', TRUE);
279 }
280 }
281
282 $this->assign('allowRegistration', $allowRegistration);
283
284 $session = CRM_Core_Session::singleton();
285 $params = array('contact_id' => $session->get('userID'),
286 'event_id' => CRM_Utils_Array::value('id', $values['event']),
287 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']),
288 );
289
290 if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event::checkRegistration($params)) {
291 $statusMessage = $eventFullMessage;
292 if (CRM_Event_BAO_Event::checkRegistration($params)) {
293 if ($noFullMsg == 'false') {
294 if ($values['event']['allow_same_participant_emails']) {
295 $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.');
296 }
297 else {
298 $registerUrl = CRM_Utils_System::url('civicrm/event/register',
299 "reset=1&id={$values['event']['id']}&cid=0"
300 );
301 $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));
302 }
303 }
304 }
305 elseif ($hasWaitingList) {
306 $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']);
307 if (!$statusMessage) {
308 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
309 }
310 }
311
312 CRM_Core_Session::setStatus($statusMessage);
313 }
314 // we do not want to display recently viewed items, so turn off
315 $this->assign('displayRecent', FALSE);
316
317 // set page title = event title
318 CRM_Utils_System::setTitle($values['event']['title']);
319
320 $this->assign('event', $values['event']);
321 if (isset($values['feeBlock'])) {
322 $this->assign('feeBlock', $values['feeBlock']);
323 }
324 $this->assign('location', $values['location']);
325
326 return parent::run();
327 }
328
329 function getTemplateFileName() {
330 if ($this->_id) {
331 $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
332 $template = CRM_Core_Page::getTemplate();
333
334 if ($template->template_exists($templateFile)) {
335 return $templateFile;
336 }
337 }
338 return parent::getTemplateFileName();
339 }
340}
341