3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * Event Info Page - Summmary about the event
37 class CRM_Event_Page_EventInfo
extends CRM_Core_Page
{
42 * This method is called after the page is created. It checks for the
43 * type of action and executes that action.
44 * Finally it calls the parent's run method.
48 public function run() {
50 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE);
51 $config = CRM_Core_Config
::singleton();
52 // ensure that the user has permission to see this page
53 if (!CRM_Core_Permission
::event(CRM_Core_Permission
::VIEW
,
54 $this->_id
, 'view event info'
57 CRM_Utils_System
::setUFMessage(ts('You do not have permission to view this event'));
58 return CRM_Utils_System
::permissionDenied();
61 $action = CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
62 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'register');
63 $this->assign('context', $context);
65 // Sometimes we want to suppress the Event Full msg
66 $noFullMsg = CRM_Utils_Request
::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
68 // set breadcrumb to append to 2nd layer pages
69 $breadCrumbPath = CRM_Utils_System
::url('civicrm/event/info',
70 "id={$this->_id}&reset=1"
73 //retrieve event information
74 $params = array('id' => $this->_id
);
75 CRM_Event_BAO_Event
::retrieve($params, $values['event']);
77 if (!$values['event']['is_active']) {
78 // form is inactive, die a fatal death
79 CRM_Utils_System
::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
80 return CRM_Utils_System
::permissionDenied();
83 if (!$values['event']['is_public']) {
84 CRM_Utils_System
::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
87 if (!empty($values['event']['is_template'])) {
88 // form is an Event Template
89 CRM_Core_Error
::fatal(ts('The page you requested is currently unavailable.'));
92 // Add Event Type to $values in case folks want to display it
93 $values['event']['event_type'] = CRM_Utils_Array
::value($values['event']['event_type_id'], CRM_Event_PseudoConstant
::eventType());
95 $this->assign('isShowLocation', CRM_Utils_Array
::value('is_show_location', $values['event']));
98 if ($this->_id
&& !empty($values['event']['is_monetary'])) {
100 $config = CRM_Core_Config
::singleton();
101 $config->defaultCurrency
= CRM_Utils_Array
::value('currency',
103 $config->defaultCurrency
107 $discountId = CRM_Core_BAO_Discount
::findSet($this->_id
, 'civicrm_event');
109 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
112 $priceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $this->_id
);
115 // get price set options, - CRM-5209
117 $setDetails = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId, TRUE, TRUE);
119 $priceSetFields = $setDetails[$priceSetId]['fields'];
120 if (is_array($priceSetFields)) {
122 $visibility = CRM_Core_PseudoConstant
::visibility('name');
124 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
125 $adminFieldVisible = FALSE;
126 if (CRM_Core_Permission
::check('administer CiviCRM')) {
127 $adminFieldVisible = TRUE;
130 foreach ($priceSetFields as $fid => $fieldValues) {
131 if (!is_array($fieldValues['options']) ||
132 empty($fieldValues['options']) ||
133 (CRM_Utils_Array
::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE)
138 if (count($fieldValues['options']) > 1) {
139 $values['feeBlock']['value'][$fieldCnt] = '';
140 $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label'];
141 $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label';
142 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array
::value('is_display_amounts', $fieldValues);
144 $labelClass = 'price_set_option-label';
147 $labelClass = 'price_set_field-label';
149 // show tax rate with amount
150 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
151 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
152 $displayOpt = CRM_Utils_Array
::value('tax_display_settings', $invoiceSettings);
153 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
154 foreach ($fieldValues['options'] as $optionId => $optionVal) {
155 if (CRM_Utils_Array
::value('visibility_id', $optionVal) != array_search('public', $visibility) &&
156 $adminFieldVisible == FALSE
161 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array
::value('is_display_amounts', $fieldValues);
162 if ($invoicing && isset($optionVal['tax_amount'])) {
163 $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField
::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
164 $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
167 $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
169 $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
170 $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
175 // Tell tpl we have price set fee data and whether it's a quick_config price set
176 $this->assign('isPriceSet', 1);
177 $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']);
181 $params = array('entity_id' => $this->_id
, 'entity_table' => 'civicrm_event');
182 $values['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
184 // fix phone type labels
185 if (!empty($values['location']['phone'])) {
186 $phoneTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Phone', 'phone_type_id');
187 foreach ($values['location']['phone'] as &$val) {
188 if (!empty($val['phone_type_id'])) {
189 $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']];
194 //retrieve custom field information
195 $groupTree = CRM_Core_BAO_CustomGroup
::getTree('Event', NULL, $this->_id
, 0, $values['event']['event_type_id'], NULL, TRUE, NULL, FALSE, TRUE, NULL, TRUE);
196 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id
);
197 $this->assign('action', CRM_Core_Action
::VIEW
);
198 //To show the event location on maps directly on event info page
199 $locations = CRM_Event_BAO_Event
::getMapInfo($this->_id
);
200 if (!empty($locations) && !empty($values['event']['is_map'])) {
201 $this->assign('locations', $locations);
202 $this->assign('mapProvider', $config->mapProvider
);
203 $this->assign('mapKey', $config->mapAPIKey
);
204 $sumLat = $sumLng = 0;
205 $maxLat = $maxLng = -400;
206 $minLat = $minLng = 400;
207 foreach ($locations as $location) {
208 $sumLat +
= $location['lat'];
209 $sumLng +
= $location['lng'];
211 if ($location['lat'] > $maxLat) {
212 $maxLat = $location['lat'];
214 if ($location['lat'] < $minLat) {
215 $minLat = $location['lat'];
218 if ($location['lng'] > $maxLng) {
219 $maxLng = $location['lng'];
221 if ($location['lng'] < $minLng) {
222 $minLng = $location['lng'];
227 'lat' => (float ) $sumLat / count($locations),
228 'lng' => (float ) $sumLng / count($locations),
231 'lat' => (float ) ($maxLat - $minLat),
232 'lng' => (float ) ($maxLng - $minLng),
234 $this->assign_by_ref('center', $center);
235 $this->assign_by_ref('span', $span);
236 if ($action == CRM_Core_Action
::PREVIEW
) {
237 $mapURL = CRM_Utils_System
::url('civicrm/contact/map/event',
238 "eid={$this->_id}&reset=1&action=preview",
244 $mapURL = CRM_Utils_System
::url('civicrm/contact/map/event',
245 "eid={$this->_id}&reset=1",
251 $this->assign('skipLocationType', TRUE);
252 $this->assign('mapURL', $mapURL);
255 if (CRM_Core_Permission
::check('view event participants')) {
256 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
257 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
258 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
259 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
260 $this->assign('findParticipants', $findParticipants);
263 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $values['event']);
264 if ($participantListingID) {
265 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
266 "reset=1&id={$this->_id}",
267 FALSE, NULL, TRUE, TRUE
269 $this->assign('participantListingURL', $participantListingURL);
272 $hasWaitingList = CRM_Utils_Array
::value('has_waitlist', $values['event']);
273 $eventFullMessage = CRM_Event_BAO_Participant
::eventFull($this->_id
,
278 $allowRegistration = FALSE;
279 $isEventOpenForRegistration = CRM_Event_BAO_Event
::validRegistrationRequest($values['event'], $this->_id
);
280 if (!empty($values['event']['is_online_registration'])) {
281 if ($isEventOpenForRegistration == 1) {
282 // we always generate urls for the front end in joomla
283 $action_query = $action === CRM_Core_Action
::PREVIEW ?
"&action=$action" : '';
284 $url = CRM_Utils_System
::url('civicrm/event/register',
285 "id={$this->_id}&reset=1{$action_query}",
289 if (!$eventFullMessage ||
$hasWaitingList) {
290 $registerText = ts('Register Now');
291 if (!empty($values['event']['registration_link_text'])) {
292 $registerText = $values['event']['registration_link_text'];
295 // check if we're in shopping cart mode for events
296 $enable_cart = Civi
::settings()->get('enable_cart');
298 $link = CRM_Event_Cart_BAO_EventInCart
::get_registration_link($this->_id
);
299 $registerText = $link['label'];
301 $url = CRM_Utils_System
::url($link['path'], $link['query'] . $action_query, FALSE, NULL, TRUE, TRUE);
305 $allowRegistration = CRM_Event_BAO_Event
::showHideRegistrationLink($values);
307 $this->assign('registerText', $registerText);
308 $this->assign('registerURL', $url);
309 $this->assign('eventCartEnabled', $enable_cart);
312 elseif (CRM_Core_Permission
::check('register for events')) {
313 $this->assign('registerClosed', TRUE);
317 $this->assign('allowRegistration', $allowRegistration);
319 $session = CRM_Core_Session
::singleton();
321 'contact_id' => $session->get('userID'),
322 'event_id' => CRM_Utils_Array
::value('id', $values['event']),
323 'role_id' => CRM_Utils_Array
::value('default_role_id', $values['event']),
326 if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event
::checkRegistration($params)) {
327 $statusMessage = $eventFullMessage;
328 if (CRM_Event_BAO_Event
::checkRegistration($params)) {
329 if ($noFullMsg == 'false') {
330 if ($values['event']['allow_same_participant_emails']) {
331 $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.');
334 $registerUrl = CRM_Utils_System
::url('civicrm/event/register',
335 "reset=1&id={$values['event']['id']}&cid=0"
337 $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));
341 elseif ($hasWaitingList) {
342 $statusMessage = CRM_Utils_Array
::value('waitlist_text', $values['event']);
343 if (!$statusMessage) {
344 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
347 if ($isEventOpenForRegistration == 1) {
348 CRM_Core_Session
::setStatus($statusMessage);
351 // we do not want to display recently viewed items, so turn off
352 $this->assign('displayRecent', FALSE);
354 // set page title = event title
355 CRM_Utils_System
::setTitle($values['event']['title']);
357 $this->assign('event', $values['event']);
358 if (isset($values['feeBlock'])) {
359 $this->assign('feeBlock', $values['feeBlock']);
361 $this->assign('location', $values['location']);
363 if (CRM_Core_Permission
::check('access CiviEvent')) {
364 $enableCart = Civi
::settings()->get('enable_cart');
365 $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent
::tabs($enableCart));
368 return parent
::run();
374 public function getTemplateFileName() {
376 $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
377 $template = CRM_Core_Page
::getTemplate();
379 if ($template->template_exists($templateFile)) {
380 return $templateFile;
383 return parent
::getTemplateFileName();