Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * Event Info Page - Summmary about the event | |
38 | */ | |
39 | class 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 | |
12cc37ef SB |
82 | CRM_Utils_System::setUFMessage(ts('The event you requested is currently unavailable (contact the site administrator for assistance).')); |
83 | return CRM_Utils_System::permissionDenied(); | |
6a488035 TO |
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()); | |
e2d09ab4 | 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 | |
d3e86119 | 106 | $discountId = CRM_Core_BAO_Discount::findSet($this->_id, 'civicrm_event'); |
6a488035 TO |
107 | if ($discountId) { |
108 | $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Discount', $discountId, 'price_set_id'); | |
0db6c3e1 TO |
109 | } |
110 | else { | |
9da8dc8c | 111 | $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $this->_id); |
6a488035 TO |
112 | } |
113 | ||
114 | // get price set options, - CRM-5209 | |
115 | if ($priceSetId) { | |
9da8dc8c | 116 | $setDetails = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, TRUE); |
6a488035 TO |
117 | |
118 | $priceSetFields = $setDetails[$priceSetId]['fields']; | |
119 | if (is_array($priceSetFields)) { | |
120 | $fieldCnt = 1; | |
121 | $visibility = CRM_Core_PseudoConstant::visibility('name'); | |
122 | ||
c7b3d063 | 123 | // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions |
ab8a593e | 124 | $adminFieldVisible = FALSE; |
c7b3d063 | 125 | if (CRM_Core_Permission::check('administer CiviCRM')) { |
4eeb9a5b | 126 | $adminFieldVisible = TRUE; |
c7b3d063 DG |
127 | } |
128 | ||
6a488035 TO |
129 | foreach ($priceSetFields as $fid => $fieldValues) { |
130 | if (!is_array($fieldValues['options']) || | |
131 | empty($fieldValues['options']) || | |
ab8a593e | 132 | (CRM_Utils_Array::value('visibility_id', $fieldValues) != array_search('public', $visibility) && $adminFieldVisible == FALSE) |
6a488035 TO |
133 | ) { |
134 | continue; | |
135 | } | |
136 | ||
137 | if (count($fieldValues['options']) > 1) { | |
138 | $values['feeBlock']['value'][$fieldCnt] = ''; | |
139 | $values['feeBlock']['label'][$fieldCnt] = $fieldValues['label']; | |
140 | $values['feeBlock']['lClass'][$fieldCnt] = 'price_set_option_group-label'; | |
141 | $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues); | |
142 | $fieldCnt++; | |
143 | $labelClass = 'price_set_option-label'; | |
144 | } | |
145 | else { | |
146 | $labelClass = 'price_set_field-label'; | |
147 | } | |
3a669c96 | 148 | // show tax rate with amount |
9265ab25 | 149 | $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); |
fe7983e7 PD |
150 | $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); |
151 | $displayOpt = CRM_Utils_Array::value('tax_display_settings', $invoiceSettings); | |
152 | $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); | |
6a488035 TO |
153 | foreach ($fieldValues['options'] as $optionId => $optionVal) { |
154 | $values['feeBlock']['isDisplayAmount'][$fieldCnt] = CRM_Utils_Array::value('is_display_amounts', $fieldValues); | |
fe7983e7 PD |
155 | if ($invoicing && isset($optionVal['tax_amount'])) { |
156 | $values['feeBlock']['value'][$fieldCnt] = CRM_Price_BAO_PriceField::getTaxLabel($optionVal, 'amount', $displayOpt, $taxTerm); | |
3a669c96 | 157 | $values['feeBlock']['tax_amount'][$fieldCnt] = $optionVal['tax_amount']; |
158 | } | |
159 | else { | |
160 | $values['feeBlock']['value'][$fieldCnt] = $optionVal['amount']; | |
161 | } | |
6a488035 TO |
162 | $values['feeBlock']['label'][$fieldCnt] = $optionVal['label']; |
163 | $values['feeBlock']['lClass'][$fieldCnt] = $labelClass; | |
164 | $fieldCnt++; | |
165 | } | |
166 | } | |
167 | } | |
168 | // Tell tpl we have price set fee data and whether it's a quick_config price set | |
169 | $this->assign('isPriceSet', 1); | |
170 | $this->assign('isQuickConfig', $setDetails[$priceSetId]['is_quick_config']); | |
171 | } | |
353ffa53 | 172 | } |
6a488035 TO |
173 | |
174 | $params = array('entity_id' => $this->_id, 'entity_table' => 'civicrm_event'); | |
175 | $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); | |
176 | ||
45618a70 | 177 | // fix phone type labels |
178 | if (!empty($values['location']['phone'])) { | |
179 | $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); | |
180 | foreach ($values['location']['phone'] as &$val) { | |
181 | if (!empty($val['phone_type_id'])) { | |
182 | $val['phone_type_display'] = $phoneTypes[$val['phone_type_id']]; | |
183 | } | |
184 | } | |
185 | } | |
186 | ||
6a488035 TO |
187 | //retrieve custom field information |
188 | $groupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this, $this->_id, 0, $values['event']['event_type_id']); | |
189 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); | |
190 | $this->assign('action', CRM_Core_Action::VIEW); | |
191 | //To show the event location on maps directly on event info page | |
192 | $locations = CRM_Event_BAO_Event::getMapInfo($this->_id); | |
8cc574cf | 193 | if (!empty($locations) && !empty($values['event']['is_map'])) { |
6a488035 TO |
194 | $this->assign('locations', $locations); |
195 | $this->assign('mapProvider', $config->mapProvider); | |
196 | $this->assign('mapKey', $config->mapAPIKey); | |
197 | $sumLat = $sumLng = 0; | |
198 | $maxLat = $maxLng = -400; | |
8d7a9d07 | 199 | $minLat = $minLng = 400; |
6a488035 TO |
200 | foreach ($locations as $location) { |
201 | $sumLat += $location['lat']; | |
202 | $sumLng += $location['lng']; | |
203 | ||
204 | if ($location['lat'] > $maxLat) { | |
205 | $maxLat = $location['lat']; | |
206 | } | |
207 | if ($location['lat'] < $minLat) { | |
208 | $minLat = $location['lat']; | |
209 | } | |
210 | ||
211 | if ($location['lng'] > $maxLng) { | |
212 | $maxLng = $location['lng']; | |
213 | } | |
214 | if ($location['lng'] < $minLng) { | |
215 | $minLng = $location['lng']; | |
216 | } | |
217 | } | |
218 | ||
6ea503d4 TO |
219 | $center = array( |
220 | 'lat' => (float ) $sumLat / count($locations), | |
6a488035 TO |
221 | 'lng' => (float ) $sumLng / count($locations), |
222 | ); | |
6ea503d4 | 223 | $span = array( |
353ffa53 TO |
224 | 'lat' => (float ) ($maxLat - $minLat), |
225 | 'lng' => (float ) ($maxLng - $minLng), | |
6a488035 TO |
226 | ); |
227 | $this->assign_by_ref('center', $center); | |
228 | $this->assign_by_ref('span', $span); | |
229 | if ($action == CRM_Core_Action::PREVIEW) { | |
230 | $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', | |
231 | "eid={$this->_id}&reset=1&action=preview", | |
232 | TRUE, NULL, TRUE, | |
233 | TRUE | |
234 | ); | |
235 | } | |
236 | else { | |
237 | $mapURL = CRM_Utils_System::url('civicrm/contact/map/event', | |
238 | "eid={$this->_id}&reset=1", | |
239 | TRUE, NULL, TRUE, | |
240 | TRUE | |
241 | ); | |
242 | } | |
243 | ||
244 | $this->assign('skipLocationType', TRUE); | |
245 | $this->assign('mapURL', $mapURL); | |
246 | } | |
247 | ||
248 | if (CRM_Core_Permission::check('view event participants') && | |
249 | CRM_Core_Permission::check('view all contacts') | |
250 | ) { | |
3283cc94 | 251 | $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1', 'label'); |
252 | $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0', 'label'); | |
6a488035 TO |
253 | $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); |
254 | $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); | |
255 | $this->assign('findParticipants', $findParticipants); | |
256 | } | |
257 | ||
258 | $participantListingID = CRM_Utils_Array::value('participant_listing_id', $values['event']); | |
259 | if ($participantListingID) { | |
260 | $participantListingURL = CRM_Utils_System::url('civicrm/event/participant', | |
261 | "reset=1&id={$this->_id}", | |
262 | TRUE, NULL, TRUE, TRUE | |
263 | ); | |
264 | $this->assign('participantListingURL', $participantListingURL); | |
265 | } | |
266 | ||
267 | $hasWaitingList = CRM_Utils_Array::value('has_waitlist', $values['event']); | |
268 | $eventFullMessage = CRM_Event_BAO_Participant::eventFull($this->_id, | |
269 | FALSE, | |
270 | $hasWaitingList | |
271 | ); | |
272 | ||
273 | $allowRegistration = FALSE; | |
a7488080 | 274 | if (!empty($values['event']['is_online_registration'])) { |
6a488035 TO |
275 | if (CRM_Event_BAO_Event::validRegistrationRequest($values['event'], $this->_id)) { |
276 | // we always generate urls for the front end in joomla | |
277 | $action_query = $action === CRM_Core_Action::PREVIEW ? "&action=$action" : ''; | |
278 | $url = CRM_Utils_System::url('civicrm/event/register', | |
279 | "id={$this->_id}&reset=1{$action_query}", | |
280 | TRUE, NULL, TRUE, | |
281 | TRUE | |
282 | ); | |
283 | if (!$eventFullMessage || $hasWaitingList) { | |
284 | $registerText = ts('Register Now'); | |
a7488080 | 285 | if (!empty($values['event']['registration_link_text'])) { |
6a488035 TO |
286 | $registerText = $values['event']['registration_link_text']; |
287 | } | |
288 | ||
289 | // check if we're in shopping cart mode for events | |
290 | $enable_cart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, | |
291 | 'enable_cart' | |
292 | ); | |
293 | ||
294 | if ($enable_cart) { | |
295 | $link = CRM_Event_Cart_BAO_EventInCart::get_registration_link($this->_id); | |
296 | $registerText = $link['label']; | |
297 | ||
298 | $url = CRM_Utils_System::url($link['path'], $link['query'] . $action_query, TRUE, NULL, TRUE, TRUE); | |
299 | } | |
300 | ||
301 | //Fixed for CRM-4855 | |
302 | $allowRegistration = CRM_Event_BAO_Event::showHideRegistrationLink($values); | |
303 | ||
304 | $this->assign('registerText', $registerText); | |
305 | $this->assign('registerURL', $url); | |
306 | $this->assign('eventCartEnabled', $enable_cart); | |
307 | } | |
308 | } | |
309 | elseif (CRM_Core_Permission::check('register for events')) { | |
310 | $this->assign('registerClosed', TRUE); | |
311 | } | |
312 | } | |
313 | ||
314 | $this->assign('allowRegistration', $allowRegistration); | |
315 | ||
316 | $session = CRM_Core_Session::singleton(); | |
6ea503d4 TO |
317 | $params = array( |
318 | 'contact_id' => $session->get('userID'), | |
6a488035 TO |
319 | 'event_id' => CRM_Utils_Array::value('id', $values['event']), |
320 | 'role_id' => CRM_Utils_Array::value('default_role_id', $values['event']), | |
321 | ); | |
322 | ||
323 | if ($eventFullMessage && ($noFullMsg == 'false') || CRM_Event_BAO_Event::checkRegistration($params)) { | |
324 | $statusMessage = $eventFullMessage; | |
325 | if (CRM_Event_BAO_Event::checkRegistration($params)) { | |
326 | if ($noFullMsg == 'false') { | |
327 | if ($values['event']['allow_same_participant_emails']) { | |
328 | $statusMessage = ts('It looks like you are already registered for this event. You may proceed if you want to create an additional registration.'); | |
329 | } | |
330 | else { | |
331 | $registerUrl = CRM_Utils_System::url('civicrm/event/register', | |
332 | "reset=1&id={$values['event']['id']}&cid=0" | |
333 | ); | |
334 | $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)); | |
335 | } | |
336 | } | |
337 | } | |
338 | elseif ($hasWaitingList) { | |
339 | $statusMessage = CRM_Utils_Array::value('waitlist_text', $values['event']); | |
340 | if (!$statusMessage) { | |
341 | $statusMessage = ts('Event is currently full, but you can register and be a part of waiting list.'); | |
342 | } | |
343 | } | |
344 | ||
345 | CRM_Core_Session::setStatus($statusMessage); | |
346 | } | |
347 | // we do not want to display recently viewed items, so turn off | |
348 | $this->assign('displayRecent', FALSE); | |
349 | ||
350 | // set page title = event title | |
351 | CRM_Utils_System::setTitle($values['event']['title']); | |
352 | ||
353 | $this->assign('event', $values['event']); | |
354 | if (isset($values['feeBlock'])) { | |
355 | $this->assign('feeBlock', $values['feeBlock']); | |
356 | } | |
357 | $this->assign('location', $values['location']); | |
358 | ||
fdf80679 CW |
359 | if (CRM_Core_Permission::check('access CiviEvent')) { |
360 | $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart'); | |
361 | $this->assign('manageEventLinks', CRM_Event_Page_ManageEvent::tabs($enableCart)); | |
362 | } | |
363 | ||
6a488035 TO |
364 | return parent::run(); |
365 | } | |
366 | ||
0cf587a7 EM |
367 | /** |
368 | * @return string | |
369 | */ | |
00be9182 | 370 | public function getTemplateFileName() { |
6a488035 TO |
371 | if ($this->_id) { |
372 | $templateFile = "CRM/Event/Page/{$this->_id}/EventInfo.tpl"; | |
373 | $template = CRM_Core_Page::getTemplate(); | |
374 | ||
375 | if ($template->template_exists($templateFile)) { | |
376 | return $templateFile; | |
377 | } | |
378 | } | |
379 | return parent::getTemplateFileName(); | |
380 | } | |
96025800 | 381 | |
6a488035 | 382 | } |