Merge pull request #3513 from yashodha/CRM-14867
[civicrm-core.git] / CRM / Event / Form / Registration.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2014
33 * $Id$
34 *
35 */
36
37 /**
38 * This class generates form components for processing Event
39 *
40 */
41 class CRM_Event_Form_Registration extends CRM_Core_Form {
42
43 /**
44 * how many locationBlocks should we display?
45 *
46 * @var int
47 * @const
48 */
49 CONST LOCATION_BLOCKS = 1;
50
51 /**
52 * the id of the event we are proceessing
53 *
54 * @var int
55 * @protected
56 */
57 public $_eventId;
58
59 /**
60 * the array of ids of all the participant we are proceessing
61 *
62 * @var int
63 * @protected
64 */
65 protected $_participantIDS = NULL;
66
67 /**
68 * the id of the participant we are proceessing
69 *
70 * @var int
71 * @protected
72 */
73 protected $_participantId;
74
75 /**
76 * is participant able to walk registration wizard.
77 *
78 * @var Boolean
79 * @protected
80 */
81 public $_allowConfirmation;
82
83 /**
84 * is participant requires approval
85 *
86 * @var Boolean
87 * @public
88 */
89 public $_requireApproval;
90
91 /**
92 * is event configured for waitlist.
93 *
94 * @var Boolean
95 * @public
96 */
97 public $_allowWaitlist;
98
99 /**
100 * store additional participant ids
101 * when there are pre-registered.
102 *
103 * @var array
104 * @public
105 */
106 public $_additionalParticipantIds;
107
108 /**
109 * the mode that we are in
110 *
111 * @var string
112 * @protect
113 */
114 public $_mode;
115
116 /**
117 * the values for the contribution db object
118 *
119 * @var array
120 * @protected
121 */
122 public $_values;
123
124 /**
125 * the paymentProcessor attributes for this page
126 *
127 * @var array
128 * @protected
129 */
130 public $_paymentProcessor;
131
132 /**
133 * The params submitted by the form and computed by the app
134 *
135 * @var array
136 * @protected
137 */
138 protected $_params;
139
140 /**
141 * The fields involved in this contribution page
142 *
143 * @var array
144 * @protected
145 */
146 public $_fields;
147
148 /**
149 * The billing location id for this contribiution page
150 *
151 * @var int
152 * @protected
153 */
154 public $_bltID;
155
156 /**
157 * Price Set ID, if the new price set method is used
158 *
159 * @var int
160 * @protected
161 */
162 public $_priceSetId = NULL;
163
164 /**
165 * Array of fields for the price set
166 *
167 * @var array
168 * @protected
169 */
170 public $_priceSet;
171
172 public $_action;
173
174 public $_pcpId;
175
176 /* Is event already full.
177 *
178 * @var boolean
179 * @protected
180 */
181
182 public $_isEventFull;
183
184 public $_lineItem;
185 public $_lineItemParticipantsCount;
186 public $_availableRegistrations;
187
188 public $_forcePayement;
189
190 /**
191 * Function to set variables up before form is built
192 *
193 * @return void
194 * @access public
195 */
196 function preProcess() {
197 $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
198 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
199
200 //CRM-4320
201 $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this);
202
203 // current mode
204 $this->_mode = ($this->_action == 1024) ? 'test' : 'live';
205
206 $this->_values = $this->get('values');
207 $this->_fields = $this->get('fields');
208 $this->_bltID = $this->get('bltID');
209 $this->_paymentProcessor = $this->get('paymentProcessor');
210 $this->_priceSetId = $this->get('priceSetId');
211 $this->_priceSet = $this->get('priceSet');
212 $this->_lineItem = $this->get('lineItem');
213 $this->_isEventFull = $this->get('isEventFull');
214 $this->_lineItemParticipantsCount = $this->get('lineItemParticipants');
215 if (!is_array($this->_lineItem)) {
216 $this->_lineItem = array();
217 }
218 if (!is_array($this->_lineItemParticipantsCount)) {
219 $this->_lineItemParticipantsCount = array();
220 }
221 $this->_availableRegistrations = $this->get('availableRegistrations');
222 $this->_participantIDS = $this->get('participantIDs');
223
224 //check if participant allow to walk registration wizard.
225 $this->_allowConfirmation = $this->get('allowConfirmation');
226
227 // check for Approval
228 $this->_requireApproval = $this->get('requireApproval');
229
230 // check for waitlisting.
231 $this->_allowWaitlist = $this->get('allowWaitlist');
232
233 $this->_forcePayement = $this->get('forcePayement');
234
235 //get the additional participant ids.
236 $this->_additionalParticipantIds = $this->get('additionalParticipantIds');
237 $config = CRM_Core_Config::singleton();
238
239 if (!$this->_values) {
240 // create redirect URL to send folks back to event info page is registration not available
241 $infoUrl = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}",
242 FALSE, NULL, FALSE, TRUE
243 );
244
245 // this is the first time we are hitting this, so check for permissions here
246 if (!CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $this->_eventId, 'register for events')) {
247 CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'), $infoUrl);
248 }
249
250 // get all the values from the dao object
251 $this->_values = $this->_fields = array();
252 $this->_forcePayement = FALSE;
253
254 //retrieve event information
255 $params = array('id' => $this->_eventId);
256 CRM_Event_BAO_Event::retrieve($params, $this->_values['event']);
257
258 $this->checkValidEvent($infoUrl);
259 // get the participant values, CRM-4320
260 $this->_allowConfirmation = FALSE;
261 if ($this->_participantId) {
262 $this->processFirstParticipant($this->_participantId);
263 }
264 //check for additional participants.
265 if ($this->_allowConfirmation && $this->_values['event']['is_multiple_registrations']) {
266 $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId);
267 $cnt = 1;
268 foreach ($additionalParticipantIds as $additionalParticipantId) {
269 $this->_additionalParticipantIds[$cnt] = $additionalParticipantId;
270 $cnt++;
271 }
272 $this->set('additionalParticipantIds', $this->_additionalParticipantIds);
273 }
274
275 $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId, FALSE,
276 CRM_Utils_Array::value('has_waitlist', $this->_values['event'])
277 );
278
279 $this->_allowWaitlist = $this->_isEventFull = FALSE;
280 if ($eventFull && !$this->_allowConfirmation) {
281 $this->_isEventFull = TRUE;
282 //lets redirecting to info only when to waiting list.
283 $this->_allowWaitlist = CRM_Utils_Array::value('has_waitlist', $this->_values['event']);
284 if (!$this->_allowWaitlist) {
285 CRM_Utils_System::redirect($infoUrl);
286 }
287 }
288 $this->set('isEventFull', $this->_isEventFull);
289 $this->set('allowWaitlist', $this->_allowWaitlist);
290
291 //check for require requires approval.
292 $this->_requireApproval = FALSE;
293 if (!empty($this->_values['event']['requires_approval']) && !$this->_allowConfirmation) {
294 $this->_requireApproval = TRUE;
295 }
296 $this->set('requireApproval', $this->_requireApproval);
297
298 if (isset($this->_values['event']['default_role_id'])) {
299 $participant_role = CRM_Core_OptionGroup::values('participant_role');
300 $this->_values['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"];
301 }
302 // check for is_monetary status
303 $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']);
304 $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'is_pay_later');
305 //check for variour combination for paylater, payment
306 //process with paid event.
307 if ($isMonetary && (!$isPayLater || !empty($this->_values['event']['payment_processor']))) {
308 $ppID = CRM_Utils_Array::value('payment_processor',
309 $this->_values['event']
310 );
311 if (!$ppID) {
312 CRM_Core_Error::statusBounce(ts('A payment processor must be selected for this event registration page, or the event must be configured to give users the option to pay later (contact the site administrator for assistance).'), $infoUrl);
313 }
314 $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID);
315 $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds,
316 $this->_mode
317 );
318 $this->set('paymentProcessors', $this->_paymentProcessors);
319
320 //set default payment processor
321 if (!empty($this->_paymentProcessors) && empty($this->_paymentProcessor)) {
322 foreach ($this->_paymentProcessors as $ppId => $values) {
323 if ($values['is_default'] == 1 || (count($this->_paymentProcessors) == 1)) {
324 $defaultProcessorId = $ppId;
325 break;
326 }
327 }
328 }
329
330 if (isset($defaultProcessorId)) {
331 $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode);
332 }
333 // make sure we have a valid payment class, else abort
334 if ($this->_values['event']['is_monetary']) {
335 if (!CRM_Utils_System::isNull($this->_paymentProcessors)) {
336 foreach ($this->_paymentProcessors as $eachPaymentProcessor) {
337 // check selected payment processor is active
338 if (!$eachPaymentProcessor) {
339 CRM_Core_Error::fatal(ts('The site administrator must set a Payment Processor for this event in order to use online registration.'));
340 }
341 // ensure that processor has a valid config
342 $payment = CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this);
343 $error = $payment->checkConfig();
344 if (!empty($error)) {
345 CRM_Core_Error::fatal($error);
346 }
347 }
348 }
349 }
350 }
351 //init event fee.
352 self::initEventFee($this, $this->_eventId);
353
354 // get the profile ids
355 $ufJoinParams = array(
356 'entity_table' => 'civicrm_event',
357 // CRM-4377: CiviEvent for the main participant, CiviEvent_Additional for additional participants
358 'module' => 'CiviEvent',
359 'entity_id' => $this->_eventId,
360 );
361 list($this->_values['custom_pre_id'],
362 $this->_values['custom_post_id']
363 ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
364
365 // set profiles for additional participants
366 if ($this->_values['event']['is_multiple_registrations']) {
367 // CRM-4377: CiviEvent for the main participant, CiviEvent_Additional for additional participants
368 $ufJoinParams['module'] = 'CiviEvent_Additional';
369
370 list($this->_values['additional_custom_pre_id'],
371 $this->_values['additional_custom_post_id'], $preActive, $postActive
372 ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
373
374 // CRM-4377: we need to maintain backward compatibility, hence if there is profile for main contact
375 // set same profile for additional contacts.
376 if ($this->_values['custom_pre_id'] && !$this->_values['additional_custom_pre_id']) {
377 $this->_values['additional_custom_pre_id'] = $this->_values['custom_pre_id'];
378 }
379
380 if ($this->_values['custom_post_id'] && !$this->_values['additional_custom_post_id']) {
381 $this->_values['additional_custom_post_id'] = $this->_values['custom_post_id'];
382 }
383 // now check for no profile condition, in that case is_active = 0
384 if (isset($preActive) && !$preActive) {
385 unset($this->_values['additional_custom_pre_id']);
386 }
387 if (isset($postActive) && !$postActive) {
388 unset($this->_values['additional_custom_post_id']);
389 }
390 }
391 // get the billing location type
392 $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
393 // CRM-8108 remove ts from Billing as the location type can not be translated in CiviCRM!
394 //$this->_bltID = array_search( ts('Billing'), $locationTypes );
395 $this->_bltID = array_search('Billing', $locationTypes);
396 if (!$this->_bltID) {
397 CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
398 }
399 $this->set('bltID', $this->_bltID);
400
401 if ($this->_values['event']['is_monetary'] &&
402 ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)
403 ) {
404 CRM_Core_Payment_Form::setCreditCardFields($this);
405 }
406 $params = array('entity_id' => $this->_eventId, 'entity_table' => 'civicrm_event');
407 $this->_values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE);
408
409 $this->set('values', $this->_values);
410 $this->set('fields', $this->_fields);
411
412 $this->_availableRegistrations =
413 CRM_Event_BAO_Participant::eventFull(
414 $this->_values['event']['id'], TRUE,
415 CRM_Utils_Array::value('has_waitlist', $this->_values['event'])
416 );
417 $this->set('availableRegistrations', $this->_availableRegistrations);
418 }
419 $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor);
420
421 // check if this is a paypal auto return and redirect accordingly
422 if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) {
423 $url = CRM_Utils_System::url('civicrm/event/register',
424 "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"
425 );
426 CRM_Utils_System::redirect($url);
427 }
428 $this->_contributeMode = $this->get('contributeMode');
429 $this->assign('contributeMode', $this->_contributeMode);
430
431 // setting CMS page title
432 CRM_Utils_System::setTitle($this->_values['event']['title']);
433 $this->assign('title', $this->_values['event']['title']);
434
435 $this->assign('paidEvent', $this->_values['event']['is_monetary']);
436
437 // we do not want to display recently viewed items on Registration pages
438 $this->assign('displayRecent', FALSE);
439 // Registration page values are cleared from session, so can't use normal Printer Friendly view.
440 // Use Browser Print instead.
441 $this->assign('browserPrint', TRUE);
442
443 $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']);
444 $this->assign('isShowLocation', $isShowLocation);
445 // Handle PCP
446 $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this);
447 if ($pcpId) {
448 $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'event', $this->_values['event']);
449 $this->_pcpId = $pcp['pcpId'];
450 $this->_values['event']['intro_text'] = CRM_Utils_Array::value('intro_text', $pcp['pcpInfo']);
451 }
452
453 // assign all event properties so wizard templates can display event info.
454 $this->assign('event', $this->_values['event']);
455 $this->assign('location', $this->_values['location']);
456 $this->assign('bltID', $this->_bltID);
457 $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']);
458 $this->assign('isShowLocation', $isShowLocation);
459 //CRM-6907
460 $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values['event'],
461 $config->defaultCurrency
462 );
463
464 //lets allow user to override campaign.
465 $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this);
466 if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
467 $this->_values['event']['campaign_id'] = $campID;
468 }
469 }
470
471 /**
472 * assign the minimal set of variables to the template
473 *
474 * @return void
475 * @access public
476 */
477 function assignToTemplate() {
478 //process only primary participant params
479 $this->_params = $this->get('params');
480 if (isset($this->_params[0])) {
481 $params = $this->_params[0];
482 }
483 $name = '';
484 if (!empty($params['billing_first_name'])) {
485 $name = $params['billing_first_name'];
486 }
487
488 if (!empty($params['billing_middle_name'])) {
489 $name .= " {$params['billing_middle_name']}";
490 }
491
492 if (!empty($params['billing_last_name'])) {
493 $name .= " {$params['billing_last_name']}";
494 }
495 $this->assign('billingName', $name);
496 $this->set('name', $name);
497
498 $vars = array(
499 'amount', 'currencyID', 'credit_card_type',
500 'trxn_id', 'amount_level', 'receive_date',
501 );
502
503 foreach ($vars as $v) {
504 if (!empty($params[$v])) {
505 if ($v == 'receive_date') {
506 $this->assign($v, CRM_Utils_Date::mysqlToIso($params[$v]));
507 }
508 else {
509 $this->assign($v, $params[$v]);
510 }
511 }
512 elseif (CRM_Utils_Array::value('amount', $params) == 0) {
513 $this->assign($v, CRM_Utils_Array::value($v, $params));
514 }
515 }
516
517 // assign the address formatted up for display
518 $addressParts = array(
519 "street_address-{$this->_bltID}",
520 "city-{$this->_bltID}",
521 "postal_code-{$this->_bltID}",
522 "state_province-{$this->_bltID}",
523 "country-{$this->_bltID}",
524 );
525 $addressFields = array();
526 foreach ($addressParts as $part) {
527 list($n, $id) = explode('-', $part);
528 if (isset($params['billing_' . $part])) {
529 $addressFields[$n] = CRM_Utils_Array::value('billing_' . $part, $params);
530 }
531 }
532
533 $this->assign('address', CRM_Utils_Address::format($addressFields));
534
535 if ($this->_contributeMode == 'direct' && empty($params['is_pay_later'])) {
536 $date = CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $params));
537 $date = CRM_Utils_Date::mysqlToIso($date);
538 $this->assign('credit_card_exp_date', $date);
539 $this->assign('credit_card_number',
540 CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $params))
541 );
542 }
543
544 // get the email that the confirmation would have been sent to
545 $session = CRM_Core_Session::singleton();
546
547 // assign is_email_confirm to templates
548 if (isset($this->_values['event']['is_email_confirm'])) {
549 $this->assign('is_email_confirm', $this->_values['event']['is_email_confirm']);
550 }
551
552 // assign pay later stuff
553 $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
554 $this->assign('is_pay_later', $params['is_pay_later']);
555 if ($params['is_pay_later']) {
556 $this->assign('pay_later_text', $this->_values['event']['pay_later_text']);
557 $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
558 }
559
560 // also assign all participantIDs to the template
561 // useful in generating confirmation numbers if needed
562 $this->assign('participantIDs',
563 $this->_participantIDS
564 );
565 }
566
567 /**
568 * Function to add the custom fields
569 *
570 * @param $id
571 * @param $name
572 * @param bool $viewOnly
573 *
574 * @return void
575 * @access public
576 */
577 function buildCustom($id, $name, $viewOnly = FALSE) {
578 $stateCountryMap = $fields = array();
579
580 if ($id) {
581 $button = substr($this->controller->getButtonName(), -4);
582 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
583 $session = CRM_Core_Session::singleton();
584 $contactID = $session->get('userID');
585
586 // we don't allow conflicting fields to be
587 // configured via profile
588 $fieldsToIgnore = array(
589 'participant_fee_amount' => 1,
590 'participant_fee_level' => 1,
591 );
592 if ($contactID) {
593 //FIX CRM-9653
594 if (is_array($id)) {
595 $fields = array();
596 foreach ($id as $profileID) {
597 $field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD,
598 NULL, NULL, FALSE, NULL,
599 FALSE, NULL, CRM_Core_Permission::CREATE,
600 'field_name', TRUE
601 );
602 $fields = array_merge($fields, $field);
603 }
604 }
605 else {
606 if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
607 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD,
608 NULL, NULL, FALSE, NULL,
609 FALSE, NULL, CRM_Core_Permission::CREATE,
610 'field_name', TRUE
611 );
612 }
613 }
614 }
615 else {
616 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD,
617 NULL, NULL, FALSE, NULL,
618 FALSE, NULL, CRM_Core_Permission::CREATE,
619 'field_name', TRUE
620 );
621 }
622
623 if (array_intersect_key($fields, $fieldsToIgnore)) {
624 $fields = array_diff_key($fields, $fieldsToIgnore);
625 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
626 }
627 $addCaptcha = FALSE;
628
629 if (!empty($this->_fields)) {
630 $fields = @array_diff_assoc($fields, $this->_fields);
631 }
632
633 if (empty($this->_params[0]['additional_participants']) &&
634 is_null($cid)
635 ) {
636 CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
637 }
638 $this->assign($name, $fields);
639 if (is_array($fields)) {
640 foreach ($fields as $key => $field) {
641 if ($viewOnly &&
642 isset($field['data_type']) &&
643 $field['data_type'] == 'File' || ($viewOnly && $field['name'] == 'image_URL')
644 ) {
645 // ignore file upload fields
646 continue;
647 }
648 //make the field optional if primary participant
649 //have been skip the additional participant.
650 if ($button == 'skip') {
651 $field['is_required'] = FALSE;
652 }
653 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
654 elseif ($field['add_captcha'] && !$contactID) {
655 // only add captcha for first page
656 $addCaptcha = TRUE;
657 }
658 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
659 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
660 if (!array_key_exists($index, $stateCountryMap)) {
661 $stateCountryMap[$index] = array();
662 }
663 $stateCountryMap[$index][$prefixName] = $key;
664 }
665 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
666
667 $this->_fields[$key] = $field;
668 }
669 }
670
671 CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
672
673 if ($addCaptcha && !$viewOnly) {
674 $captcha = CRM_Utils_ReCAPTCHA::singleton();
675 $captcha->add($this);
676 $this->assign('isCaptcha', TRUE);
677 }
678 }
679 }
680
681 /**
682 * @param $form
683 * @param $eventID
684 *
685 * @throws Exception
686 */
687 static function initEventFee(&$form, $eventID) {
688 // get price info
689
690 // retrive all active price set fields.
691 $discountId = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
692 if (property_exists($form, '_discountId') && $form->_discountId) {
693 $discountId = $form->_discountId;
694 }
695 if ($discountId) {
696 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
697 $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', TRUE, $priceSetId);
698 }
699 else {
700 $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', TRUE);
701 }
702
703 if (property_exists($form, '_context') && ($form->_context == 'standalone'
704 || $form->_context == 'participant')) {
705 $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event');
706 if (is_array( $discountedEvent)) {
707 foreach ($discountedEvent as $key => $priceSetId) {
708 $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId);
709 $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
710 $form->_values['discount'][$key] = CRM_Utils_Array::value('fields', $priceSet);
711 $fieldID = key($form->_values['discount'][$key]);
712 $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue(
713 'CRM_Price_DAO_PriceSet',
714 $priceSetId,
715 'title'
716 );
717 }
718 }
719 }
720 $eventFee = CRM_Utils_Array::value('fee', $form->_values);
721 if (!is_array($eventFee) || empty($eventFee)) {
722 $form->_values['fee'] = array();
723 }
724
725 //fix for non-upgraded price sets.CRM-4256.
726 if (isset($form->_isPaidEvent)) {
727 $isPaidEvent = $form->_isPaidEvent;
728 }
729 else {
730 $isPaidEvent = CRM_Utils_Array::value('is_monetary', $form->_values['event']);
731 }
732 if ($isPaidEvent && empty($form->_values['fee'])) {
733 if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') {
734 CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId))));
735 }
736 }
737 }
738
739 /**
740 * Function to handle process after the confirmation of payment by User
741 *
742 * @param null $contactID
743 * @param null $contribution
744 * @param null $payment
745 *
746 * @return void
747 * @access public
748 */
749 function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
750 // add/update contact information
751 $fields = array();
752 unset($this->_params['note']);
753
754 //to avoid conflict overwrite $this->_params
755 $this->_params = $this->get('value');
756
757 //get the amount of primary participant
758 if (!empty($this->_params['is_primary'])) {
759 $this->_params['fee_amount'] = $this->get('primaryParticipantAmount');
760 }
761
762 // add participant record
763 $participant = $this->addParticipant($this->_params, $contactID);
764 $this->_participantIDS[] = $participant->id;
765
766 //setting register_by_id field and primaryContactId
767 if (!empty($this->_params['is_primary'])) {
768 $this->set('registerByID', $participant->id);
769 $this->set('primaryContactId', $contactID);
770
771 // CRM-10032
772 $this->processFirstParticipant($participant->id);
773 }
774
775 CRM_Core_BAO_CustomValueTable::postProcess($this->_params,
776 CRM_Core_DAO::$_nullArray,
777 'civicrm_participant',
778 $participant->id,
779 'Participant'
780 );
781
782 $createPayment = (CRM_Utils_Array::value('amount', $this->_params, 0) != 0) ? TRUE : FALSE;
783
784 // force to create zero amount payment, CRM-5095
785 // we know the amout is zero since createPayment is false
786 if (!$createPayment &&
787 (isset($contribution) && $contribution->id) &&
788 $this->_priceSetId &&
789 $this->_lineItem
790 ) {
791 $createPayment = TRUE;
792 }
793
794 if ($createPayment && $this->_values['event']['is_monetary'] && !empty($this->_params['contributionID'])) {
795 $paymentParams = array(
796 'participant_id' => $participant->id,
797 'contribution_id' => $contribution->id,
798 );
799 $ids = array();
800 $paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams, $ids);
801 }
802
803 //set only primary participant's params for transfer checkout.
804 if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify') && !empty($this->_params['is_primary'])) {
805 $this->_params['participantID'] = $participant->id;
806 $this->set('primaryParticipant', $this->_params);
807 }
808
809 $this->assign('action', $this->_action);
810
811 // create CMS user
812 if (!empty($this->_params['cms_create_account'])) {
813 $this->_params['contactID'] = $contactID;
814
815 if (array_key_exists('email-5', $this->_params)) {
816 $mail = 'email-5';
817 } else {
818 foreach ($this->_params as $name => $dontCare) {
819 if (substr($name, 0, 5) == 'email') {
820 $mail = $name;
821 break;
822 }
823 }
824 }
825
826 // we should use primary email for
827 // 1. free event registration.
828 // 2. pay later participant.
829 // 3. waiting list participant.
830 // 4. require approval participant.
831 if (!empty($this->_params['is_pay_later']) ||
832 $this->_allowWaitlist || $this->_requireApproval || empty($this->_values['event']['is_monetary'])) {
833 $mail = 'email-Primary';
834 }
835
836 if (!CRM_Core_BAO_CMSUser::create($this->_params, $mail)) {
837 CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.'));
838 }
839 }
840 }
841
842 /**
843 * Process the participant
844 *
845 * @param $params
846 * @param $contactID
847 *
848 * @return void
849 * @access public
850 */
851 public function addParticipant($params, $contactID) {
852
853 $transaction = new CRM_Core_Transaction();
854
855 $groupName = 'participant_role';
856 $query = "
857 SELECT v.label as label ,v.value as value
858 FROM civicrm_option_value v,
859 civicrm_option_group g
860 WHERE v.option_group_id = g.id
861 AND g.name = %1
862 AND v.is_active = 1
863 AND g.is_active = 1
864 ";
865 $p = array(1 => array($groupName, 'String'));
866
867 $dao = CRM_Core_DAO::executeQuery($query, $p);
868 if ($dao->fetch()) {
869 $roleID = $dao->value;
870 }
871
872 // handle register date CRM-4320
873 $registerDate = NULL;
874 if ($this->_allowConfirmation && $this->_participantId) {
875 $registerDate = $params['participant_register_date'];
876 }
877 elseif (!empty($params['participant_register_date']) &&
878 is_array($params['participant_register_date']) &&
879 !empty($params['participant_register_date'])
880 ) {
881 $registerDate = CRM_Utils_Date::format($params['participant_register_date']);
882 }
883
884 $participantParams = array('id' => CRM_Utils_Array::value('participant_id', $params),
885 'contact_id' => $contactID,
886 'event_id' => $this->_eventId ? $this->_eventId : $params['event_id'],
887 'status_id' => CRM_Utils_Array::value('participant_status',
888 $params, 1
889 ),
890 'role_id' => CRM_Utils_Array::value('participant_role_id',
891 $params, $roleID
892 ),
893 'register_date' => ($registerDate) ? $registerDate : date('YmdHis'),
894 'source' => isset($params['participant_source']) ?
895 CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params),
896 'fee_level' => CRM_Utils_Array::value('amount_level', $params),
897 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
898 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params),
899 'registered_by_id' => CRM_Utils_Array::value('registered_by_id', $params),
900 'discount_id' => CRM_Utils_Array::value('discount_id', $params),
901 'fee_currency' => CRM_Utils_Array::value('currencyID', $params),
902 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params),
903 );
904
905 if ($this->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
906 $participantParams['is_test'] = 1;
907 }
908 else {
909 $participantParams['is_test'] = 0;
910 }
911
912 if (!empty($this->_params['note'])) {
913 $participantParams['note'] = $this->_params['note'];
914 }
915 elseif (!empty($this->_params['participant_note'])) {
916 $participantParams['note'] = $this->_params['participant_note'];
917 }
918
919 // reuse id if one already exists for this one (can happen
920 // with back button being hit etc)
921 if (!$participantParams['id'] && !empty($params['contributionID'])) {
922 $pID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
923 $params['contributionID'],
924 'participant_id',
925 'contribution_id'
926 );
927 $participantParams['id'] = $pID;
928 }
929 $participantParams['discount_id'] = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
930
931 if (!$participantParams['discount_id']) {
932 $participantParams['discount_id'] = "null";
933 }
934
935 $participant = CRM_Event_BAO_Participant::create($participantParams);
936
937 $transaction->commit();
938
939 return $participant;
940 }
941
942 /* Calculate the total participant count as per params.
943 *
944 * @param array $params user params.
945 *
946 * @return $totalCount total participant count.
947 * @access public
948 */
949 /**
950 * @param $form
951 * @param $params
952 * @param bool $skipCurrent
953 *
954 * @return int|string
955 */
956 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
957 $totalCount = 0;
958 if (!is_array($params) || empty($params)) {
959 return $totalCount;
960 }
961
962 $priceSetId = $form->get('priceSetId');
963 $addParticipantNum = substr($form->_name, 12);
964 $priceSetFields = $priceSetDetails = array();
965 $hasPriceFieldsCount = FALSE;
966 if ($priceSetId) {
967 $priceSetDetails = $form->get('priceSet');
968 if (isset($priceSetDetails['optionsCountTotal'])
969 && $priceSetDetails['optionsCountTotal']
970 ) {
971 $hasPriceFieldsCount = TRUE;
972 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
973 }
974 }
975
976 $singleFormParams = FALSE;
977 foreach ($params as $key => $val) {
978 if (!is_numeric($key)) {
979 $singleFormParams = TRUE;
980 break;
981 }
982 }
983
984 //first format the params.
985 if ($singleFormParams) {
986 $params = self::formatPriceSetParams($form, $params);
987 $params = array($params);
988 }
989
990 foreach ($params as $key => $values) {
991 if (!is_numeric($key) ||
992 $values == 'skip' ||
993 ($skipCurrent && ($addParticipantNum == $key))
994 ) {
995 continue;
996 }
997 $count = 1;
998
999 $usedCache = FALSE;
1000 $cacheCount = CRM_Utils_Array::value($key, $form->_lineItemParticipantsCount);
1001 if ($cacheCount && is_numeric($cacheCount)) {
1002 $count = $cacheCount;
1003 $usedCache = TRUE;
1004 }
1005
1006 if (!$usedCache && $hasPriceFieldsCount) {
1007 $count = 0;
1008 foreach ($values as $valKey => $value) {
1009 if (strpos($valKey, 'price_') === FALSE) {
1010 continue;
1011 }
1012 $priceFieldId = substr($valKey, 6);
1013 if (!$priceFieldId ||
1014 !is_array($value) ||
1015 !array_key_exists($priceFieldId, $priceSetFields)
1016 ) {
1017 continue;
1018 }
1019 foreach ($value as $optId => $optVal) {
1020 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1021 if ($currentCount) {
1022 $count += $currentCount;
1023 }
1024 }
1025 }
1026 if (!$count) {
1027 $count = 1;
1028 }
1029 }
1030 $totalCount += $count;
1031 }
1032 if (!$totalCount) {
1033 $totalCount = 1;
1034 }
1035
1036 return $totalCount;
1037 }
1038
1039 /* Format user submitted price set params.
1040 * Convert price set each param as an array.
1041 *
1042 * @param $params an array of user submitted params.
1043 *
1044 *
1045 * @return array $formatted, formatted price set params.
1046 * @access public
1047 */
1048 /**
1049 * @param $form
1050 * @param $params
1051 *
1052 * @return mixed
1053 */
1054 public static function formatPriceSetParams(&$form, $params) {
1055 if (!is_array($params) || empty($params)) {
1056 return $params;
1057 }
1058
1059 $priceSetId = $form->get('priceSetId');
1060 if (!$priceSetId) {
1061 return $params;
1062 }
1063 $priceSetDetails = $form->get('priceSet');
1064
1065 foreach ($params as $key => & $value) {
1066 $vals = array();
1067 if (strpos($key, 'price_') !== FALSE) {
1068 $fieldId = substr($key, 6);
1069 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1070 is_array($value) ||
1071 !$value
1072 ) {
1073 continue;
1074 }
1075 $field = $priceSetDetails['fields'][$fieldId];
1076 if ($field['html_type'] == 'Text') {
1077 $fieldOption = current($field['options']);
1078 $value = array($fieldOption['id'] => $value);
1079 }
1080 else {
1081 $value = array($value => TRUE);
1082 }
1083 }
1084 }
1085
1086 return $params;
1087 }
1088
1089 /* Calculate total count for each price set options.
1090 * those are currently selected by user.
1091 *
1092 * @param $form form object.
1093 *
1094 *
1095 * @return array $optionsCount, array of each option w/ count total.
1096 * @access public
1097 */
1098 /**
1099 * @param $form
1100 *
1101 * @return array
1102 */
1103 public static function getPriceSetOptionCount(&$form) {
1104 $params = $form->get('params');
1105 $priceSet = $form->get('priceSet');
1106 $priceSetId = $form->get('priceSetId');
1107
1108 $optionsCount = array();
1109 if (!$priceSetId ||
1110 !is_array($priceSet) ||
1111 empty($priceSet) ||
1112 !is_array($params) ||
1113 empty($params)
1114 ) {
1115 return $optionsCount;
1116 }
1117
1118 $priceSetFields = $priceMaxFieldDetails = array();
1119 if (!empty($priceSet['optionsCountTotal'])) {
1120 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1121 }
1122
1123 if (!empty($priceSet['optionsMaxValueTotal'])) {
1124 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1125 }
1126
1127 $addParticipantNum = substr($form->_name, 12);
1128 foreach ($params as $pCnt => $values) {
1129 if ($values == 'skip' ||
1130 $pCnt == $addParticipantNum
1131 ) {
1132 continue;
1133 }
1134
1135 foreach ($values as $valKey => $value) {
1136 if (strpos($valKey, 'price_') === FALSE) {
1137 continue;
1138 }
1139
1140 $priceFieldId = substr($valKey, 6);
1141 if (!$priceFieldId ||
1142 !is_array($value) ||
1143 !(array_key_exists($priceFieldId, $priceSetFields) || array_key_exists($priceFieldId, $priceMaxFieldDetails))
1144 ) {
1145 continue;
1146 }
1147
1148 foreach ($value as $optId => $optVal) {
1149 if (CRM_Utils_Array::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1150 $currentCount = $optVal;
1151 }
1152 else {
1153 $currentCount = 1;
1154 }
1155
1156 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1157 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1158 }
1159
1160 $optionsCount[$optId] = $currentCount + CRM_Utils_Array::value($optId, $optionsCount, 0);
1161 }
1162 }
1163 }
1164
1165 return $optionsCount;
1166 }
1167
1168 /**
1169 * @param string $suffix
1170 *
1171 * @return null|string
1172 */
1173 function checkTemplateFileExists($suffix = '') {
1174 if ($this->_eventId) {
1175 $templateName = $this->_name;
1176 if (substr($templateName, 0, 12) == 'Participant_') {
1177 $templateName = 'AdditionalParticipant';
1178 }
1179
1180 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1181 $template = CRM_Core_Form::getTemplate();
1182 if ($template->template_exists($templateFile)) {
1183 return $templateFile;
1184 }
1185 }
1186 return NULL;
1187 }
1188
1189 /**
1190 * @return null|string
1191 */
1192 function getTemplateFileName() {
1193 $fileName = $this->checkTemplateFileExists();
1194 return $fileName ? $fileName : parent::getTemplateFileName();
1195 }
1196
1197 /**
1198 * @return null|string
1199 */
1200 function overrideExtraTemplateFileName() {
1201 $fileName = $this->checkTemplateFileExists('extra.');
1202 return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
1203 }
1204
1205 /**
1206 * Validate price set submitted params for price option limit,
1207 * as well as user should select at least one price field option.
1208 * @param unknown_type $form
1209 * @param unknown_type $params
1210 * @return multitype:|Ambigous <multitype:, string, string>
1211 */
1212 static function validatePriceSet(&$form, $params) {
1213 $errors = array();
1214 $hasOptMaxValue = FALSE;
1215 if (!is_array($params) || empty($params)) {
1216 return $errors;
1217 }
1218
1219 $currentParticipantNum = substr($form->_name, 12);
1220 if (!$currentParticipantNum) {
1221 $currentParticipantNum = 0;
1222 }
1223
1224 $priceSetId = $form->get('priceSetId');
1225 $priceSetDetails = $form->get('priceSet');
1226 if (
1227 !$priceSetId ||
1228 !is_array($priceSetDetails) ||
1229 empty($priceSetDetails)
1230 ) {
1231 return $errors;
1232 }
1233
1234 $optionsCountDetails = $optionsMaxValueDetails = array();
1235 if (
1236 isset($priceSetDetails['optionsMaxValueTotal'])
1237 && $priceSetDetails['optionsMaxValueTotal']
1238 ) {
1239 $hasOptMaxValue = TRUE;
1240 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1241 }
1242 if (
1243 isset($priceSetDetails['optionsCountTotal'])
1244 && $priceSetDetails['optionsCountTotal']
1245 ) {
1246 $hasOptCount = TRUE;
1247 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1248 }
1249 $feeBlock = $form->_feeBlock;
1250
1251 if (empty($feeBlock)) {
1252 $feeBlock = $priceSetDetails['fields'];
1253 }
1254
1255 $optionMaxValues = $fieldSelected = array();
1256 foreach ($params as $pNum => $values) {
1257 if (!is_array($values) || $values == 'skip') {
1258 continue;
1259 }
1260
1261 foreach ($values as $valKey => $value) {
1262 if (strpos($valKey, 'price_') === FALSE) {
1263 continue;
1264 }
1265 $priceFieldId = substr($valKey, 6);
1266 $noneOptionValueSelected = FALSE;
1267 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1268 $noneOptionValueSelected = TRUE;
1269 }
1270
1271 if (
1272 !$priceFieldId ||
1273 (!$noneOptionValueSelected && !is_array($value))
1274 ) {
1275 continue;
1276 }
1277
1278 $fieldSelected[$pNum] = TRUE;
1279
1280 if (!$hasOptMaxValue || !is_array($value)) {
1281 continue;
1282 }
1283
1284 foreach ($value as $optId => $optVal) {
1285 if (CRM_Utils_Array::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1286 $currentMaxValue = $optVal;
1287 }
1288 else {
1289 $currentMaxValue = 1;
1290 }
1291
1292 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1293 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1294 }
1295 if (empty($optionMaxValues)) {
1296 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1297 }
1298 else {
1299 $optionMaxValues[$priceFieldId][$optId] =
1300 $currentMaxValue + CRM_Utils_Array::value($optId, CRM_Utils_Array::value($priceFieldId, $optionMaxValues), 0);
1301 }
1302
1303 }
1304 }
1305 }
1306
1307 //validate for option max value.
1308 foreach ($optionMaxValues as $fieldId => $values) {
1309 $options = CRM_Utils_Array::value('options', $feeBlock[$fieldId], array());
1310 foreach ($values as $optId => $total) {
1311 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1312 $opDbCount = CRM_Utils_Array::value('db_total_count', $options[$optId], 0);
1313 $total += $opDbCount;
1314 if ($optMax && $total > $optMax) {
1315 if ($opDbCount && ($opDbCount >= $optMax)) {
1316 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1317 ts('Sorry, this option is currently sold out.');
1318 }
1319 elseif (($optMax - $opDbCount) == 1) {
1320 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1321 ts('Sorry, currently only a single seat is available for this option.', array(1 => ($optMax - $opDbCount)));
1322 }
1323 else {
1324 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1325 ts('Sorry, currently only %1 seats are available for this option.', array(1 => ($optMax - $opDbCount)));
1326 }
1327 }
1328 }
1329 }
1330
1331 //validate for price field selection.
1332 foreach ($params as $pNum => $values) {
1333 if (!is_array($values) || $values == 'skip') {
1334 continue;
1335 }
1336 if (empty($fieldSelected[$pNum])) {
1337 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1338 }
1339 }
1340
1341 return $errors;
1342 }
1343
1344 // set the first participant ID if not set, CRM-10032
1345 /**
1346 * @param $participantID
1347 */
1348 function processFirstParticipant($participantID) {
1349 $this->_participantId = $participantID;
1350 $this->set('participantId', $this->_participantId);
1351
1352 $ids = $participantValues = array();
1353 $participantParams = array('id' => $this->_participantId);
1354 CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids);
1355 $this->_values['participant'] = $participantValues[$this->_participantId];
1356 $this->set('values', $this->_values);
1357
1358 // also set the allow confirmation stuff
1359 if (array_key_exists(
1360 $this->_values['participant']['status_id'],
1361 CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'")
1362 )) {
1363 $this->_allowConfirmation = TRUE;
1364 $this->set('allowConfirmation', TRUE);
1365 }
1366 }
1367
1368 /**
1369 * @todo - combine this with CRM_Event_BAO_Event::validRegistrationRequest
1370 * (probably extract relevant values here & call that with them & handle bounces & redirects here -as
1371 * those belong in the form layer)
1372 *
1373 * @param string $redirect
1374 */
1375 function checkValidEvent($redirect = NULL) {
1376 // is the event active (enabled)?
1377 if (!$this->_values['event']['is_active']) {
1378 // form is inactive, die a fatal death
1379 CRM_Core_Error::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1380 }
1381
1382 // is online registration is enabled?
1383 if (!$this->_values['event']['is_online_registration']) {
1384 CRM_Core_Error::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1385 }
1386
1387 // is this an event template ?
1388 if (!empty($this->_values['event']['is_template'])) {
1389 CRM_Core_Error::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1390 }
1391
1392 $now = date('YmdHis');
1393 $startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_start_date',
1394 $this->_values['event']
1395 ));
1396
1397 if (
1398 $startDate &&
1399 $startDate >= $now
1400 ) {
1401 CRM_Core_Error::statusBounce(ts('Registration for this event begins on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_start_date', $this->_values['event'])))), $redirect);
1402 }
1403
1404 $endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_end_date',
1405 $this->_values['event']
1406 ));
1407 if (
1408 $endDate &&
1409 $endDate < $now
1410 ) {
1411 CRM_Core_Error::statusBounce(ts('Registration for this event ended on %1', array(1 => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('registration_end_date', $this->_values['event'])))), $redirect);
1412 }
1413 }
1414 }
1415