3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * Event Info Page - Summmary about the event
39 class CRM_Event_Page_EventInfo
extends CRM_Core_Page
{
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.
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
, 'view event info'
60 CRM_Utils_System
::setUFMessage(ts('You do not have permission to view this event'));
61 return CRM_Utils_System
::permissionDenied();
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);
68 // Sometimes we want to suppress the Event Full msg
69 $noFullMsg = CRM_Utils_Request
::retrieve('noFullMsg', 'String', $this, FALSE, 'false');
71 // set breadcrumb to append to 2nd layer pages
72 $breadCrumbPath = CRM_Utils_System
::url('civicrm/event/info',
73 "id={$this->_id}&reset=1"
75 $additionalBreadCrumb = "<a href=\"$breadCrumbPath\">" . ts('Events') . '</a>';
77 //retrieve event information
78 $params = array('id' => $this->_id
);
79 CRM_Event_BAO_Event
::retrieve($params, $values['event']);
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.'));
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.'));
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());
94 $this->assign('isShowLocation', CRM_Utils_Array
::value('is_show_location', $values['event']));
97 if ($this->_id
&& !empty($values['event']['is_monetary'])) {
99 $config = CRM_Core_Config
::singleton();
100 $config->defaultCurrency
= CRM_Utils_Array
::value('currency',
102 $config->defaultCurrency
106 $discountId= CRM_Core_BAO_Discount
::findSet($this->_id
, 'civicrm_event');
108 $priceSetId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id');
110 $priceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $this->_id
);
113 // get price set options, - CRM-5209
115 $setDetails = CRM_Price_BAO_PriceSet
::getSetDetail($priceSetId, TRUE, TRUE);
117 $priceSetFields = $setDetails[$priceSetId]['fields'];
118 if (is_array($priceSetFields)) {
120 $visibility = CRM_Core_PseudoConstant
::visibility('name');
122 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
123 $adminFieldVisible = false;
124 if (CRM_Core_Permission
::check('administer CiviCRM')) {
125 $adminFieldVisible = true;
128 foreach ($priceSetFields as $fid => $fieldValues) {
129 if (!is_array($fieldValues['options']) ||
130 empty($fieldValues['options']) ||
131 (CRM_Utils_Array
::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == false)
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);
142 $labelClass = 'price_set_option-label';
145 $labelClass = 'price_set_field-label';
147 // show tax rate with amount
148 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
, 'contribution_invoice_settings');
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);
152 foreach ($fieldValues['options'] as $optionId => $optionVal) {
153 $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array
::value('is_display_amounts', $fieldValues);
154 if ($invoicing && isset($optionVal['tax_amount'])) {
155 $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField
::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm);
156 $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount'];
159 $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount'];
161 $values['feeBlock']['label'][$fieldCnt] = $optionVal['label'];
162 $values['feeBlock']['lClass'][$fieldCnt] = $labelClass;
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']);
173 $params = array('entity_id' => $this->_id
, 'entity_table' => 'civicrm_event');
174 $values['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
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']];
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
);
192 if (!empty($locations) && !empty($values['event']['is_map'])) {
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;
198 $minLat = $minLng = +
400;
199 foreach ($locations as $location) {
200 $sumLat +
= $location['lat'];
201 $sumLng +
= $location['lng'];
203 if ($location['lat'] > $maxLat) {
204 $maxLat = $location['lat'];
206 if ($location['lat'] < $minLat) {
207 $minLat = $location['lat'];
210 if ($location['lng'] > $maxLng) {
211 $maxLng = $location['lng'];
213 if ($location['lng'] < $minLng) {
214 $minLng = $location['lng'];
218 $center = array('lat' => (float ) $sumLat / count($locations),
219 'lng' => (float ) $sumLng / count($locations),
221 $span = array('lat' => (float )($maxLat - $minLat),
222 'lng' => (float )($maxLng - $minLng),
224 $this->assign_by_ref('center', $center);
225 $this->assign_by_ref('span', $span);
226 if ($action == CRM_Core_Action
::PREVIEW
) {
227 $mapURL = CRM_Utils_System
::url('civicrm/contact/map/event',
228 "eid={$this->_id}&reset=1&action=preview",
234 $mapURL = CRM_Utils_System
::url('civicrm/contact/map/event',
235 "eid={$this->_id}&reset=1",
241 $this->assign('skipLocationType', TRUE);
242 $this->assign('mapURL', $mapURL);
245 if (CRM_Core_Permission
::check('view event participants') &&
246 CRM_Core_Permission
::check('view all contacts')
248 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1', 'label');
249 $statusTypesPending = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 0', 'label');
250 $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes));
251 $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending));
252 $this->assign('findParticipants', $findParticipants);
255 $participantListingID = CRM_Utils_Array
::value('participant_listing_id', $values['event']);
256 if ($participantListingID) {
257 $participantListingURL = CRM_Utils_System
::url('civicrm/event/participant',
258 "reset=1&id={$this->_id}",
259 TRUE, NULL, TRUE, TRUE
261 $this->assign('participantListingURL', $participantListingURL);
264 $hasWaitingList = CRM_Utils_Array
::value('has_waitlist', $values['event']);
265 $eventFullMessage = CRM_Event_BAO_Participant
::eventFull($this->_id
,
270 $allowRegistration = FALSE;
271 if (!empty($values['event']['is_online_registration'])) {
272 if (CRM_Event_BAO_Event
::validRegistrationRequest($values['event'], $this->_id
)) {
273 // we always generate urls for the front end in joomla
274 $action_query = $action === CRM_Core_Action
::PREVIEW ?
"&action=$action" : '';
275 $url = CRM_Utils_System
::url('civicrm/event/register',
276 "id={$this->_id}&reset=1{$action_query}",
280 if (!$eventFullMessage ||
$hasWaitingList) {
281 $registerText = ts('Register Now');
282 if (!empty($values['event']['registration_link_text'])) {
283 $registerText = $values['event']['registration_link_text'];
286 // check if we're in shopping cart mode for events
287 $enable_cart = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
292 $link = CRM_Event_Cart_BAO_EventInCart
::get_registration_link($this->_id
);
293 $registerText = $link['label'];
295 $url = CRM_Utils_System
::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE);
299 $allowRegistration = CRM_Event_BAO_Event
::showHideRegistrationLink($values);
301 $this->assign('registerText', $registerText);
302 $this->assign('registerURL', $url);
303 $this->assign('eventCartEnabled', $enable_cart);
306 elseif (CRM_Core_Permission
::check('register for events')) {
307 $this->assign('registerClosed', TRUE);
311 $this->assign('allowRegistration', $allowRegistration);
313 $session = CRM_Core_Session
::singleton();
314 $params = array('contact_id' => $session->get('userID'),
315 'event_id' => CRM_Utils_Array
::value('id', $values['event']),
316 'role_id' => CRM_Utils_Array
::value('default_role_id', $values['event']),
319 if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event
::checkRegistration($params)) {
320 $statusMessage = $eventFullMessage;
321 if (CRM_Event_BAO_Event
::checkRegistration($params)) {
322 if ($noFullMsg == 'false') {
323 if ($values['event']['allow_same_participant_emails']) {
324 $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.');
327 $registerUrl = CRM_Utils_System
::url('civicrm/event/register',
328 "reset=1&id={$values['event']['id']}&cid=0"
330 $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 elseif ($hasWaitingList) {
335 $statusMessage = CRM_Utils_Array
::value('waitlist_text', $values['event']);
336 if (!$statusMessage) {
337 $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.');
341 CRM_Core_Session
::setStatus($statusMessage);
343 // we do not want to display recently viewed items, so turn off
344 $this->assign('displayRecent', FALSE);
346 // set page title = event title
347 CRM_Utils_System
::setTitle($values['event']['title']);
349 $this->assign('event', $values['event']);
350 if (isset($values['feeBlock'])) {
351 $this->assign('feeBlock', $values['feeBlock']);
353 $this->assign('location', $values['location']);
355 return parent
::run();
361 function getTemplateFileName() {
363 $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl";
364 $template = CRM_Core_Page
::getTemplate();
366 if ($template->template_exists($templateFile)) {
367 return $templateFile;
370 return parent
::getTemplateFileName();