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