a6f08e5d72eebff4d174e1ab9b2c5b46c8a4a42c
[civicrm-core.git] / CRM / Event / Form / Registration.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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)) {
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 (CRM_Utils_Array::value('requires_approval', $this->_values['event']) && !$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 || CRM_Utils_Array::value('payment_processor', $this->_values['event']))) {
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');
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 if ($pcpId && $pcpSupporter = CRM_PCP_BAO_PCP::displayName($pcpId)) {
460 $this->assign('pcpSupporterText', ts('This event registration is being made thanks to effort of <strong>%1</strong>, who supports our campaign. You can support it as well - once you complete the registration, you will be able to create your own Personal Campaign Page!', array(1 => $pcpSupporter)));
461 }
462 //CRM-6907
463 $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values['event'],
464 $config->defaultCurrency
465 );
466
467 //lets allow user to override campaign.
468 $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this);
469 if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
470 $this->_values['event']['campaign_id'] = $campID;
471 }
472 }
473
474 /**
475 * assign the minimal set of variables to the template
476 *
477 * @return void
478 * @access public
479 */
480 function assignToTemplate() {
481 //process only primary participant params
482 $this->_params = $this->get('params');
483 if (isset($this->_params[0])) {
484 $params = $this->_params[0];
485 }
486 $name = '';
487 if (CRM_Utils_Array::value('billing_first_name', $params)) {
488 $name = $params['billing_first_name'];
489 }
490
491 if (CRM_Utils_Array::value('billing_middle_name', $params)) {
492 $name .= " {$params['billing_middle_name']}";
493 }
494
495 if (CRM_Utils_Array::value('billing_last_name', $params)) {
496 $name .= " {$params['billing_last_name']}";
497 }
498 $this->assign('billingName', $name);
499 $this->set('name', $name);
500
501 $vars = array(
502 'amount', 'currencyID', 'credit_card_type',
503 'trxn_id', 'amount_level', 'receive_date',
504 );
505
506 foreach ($vars as $v) {
507 if (CRM_Utils_Array::value($v, $params)) {
508 if ($v == 'receive_date') {
509 $this->assign($v, CRM_Utils_Date::mysqlToIso($params[$v]));
510 }
511 else {
512 $this->assign($v, $params[$v]);
513 }
514 }
515 elseif (CRM_Utils_Array::value('amount', $params) == 0) {
516 $this->assign($v, CRM_Utils_Array::value($v, $params));
517 }
518 }
519
520 // assign the address formatted up for display
521 $addressParts = array(
522 "street_address-{$this->_bltID}",
523 "city-{$this->_bltID}",
524 "postal_code-{$this->_bltID}",
525 "state_province-{$this->_bltID}",
526 "country-{$this->_bltID}",
527 );
528 $addressFields = array();
529 foreach ($addressParts as $part) {
530 list($n, $id) = explode('-', $part);
531 if (isset($params['billing_' . $part])) {
532 $addressFields[$n] = CRM_Utils_Array::value('billing_' . $part, $params);
533 }
534 }
535
536 $this->assign('address', CRM_Utils_Address::format($addressFields));
537
538 if ($this->_contributeMode == 'direct' &&
539 !CRM_Utils_Array::value('is_pay_later', $params)
540 ) {
541 $date = CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $params));
542 $date = CRM_Utils_Date::mysqlToIso($date);
543 $this->assign('credit_card_exp_date', $date);
544 $this->assign('credit_card_number',
545 CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $params))
546 );
547 }
548
549 // get the email that the confirmation would have been sent to
550 $session = CRM_Core_Session::singleton();
551
552 // assign is_email_confirm to templates
553 if (isset($this->_values['event']['is_email_confirm'])) {
554 $this->assign('is_email_confirm', $this->_values['event']['is_email_confirm']);
555 }
556
557 // assign pay later stuff
558 $params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
559 $this->assign('is_pay_later', $params['is_pay_later']);
560 if ($params['is_pay_later']) {
561 $this->assign('pay_later_text', $this->_values['event']['pay_later_text']);
562 $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
563 }
564
565 // also assign all participantIDs to the template
566 // useful in generating confirmation numbers if needed
567 $this->assign('participantIDs',
568 $this->_participantIDS
569 );
570 }
571
572 /**
573 * Function to add the custom fields
574 *
575 * @return None
576 * @access public
577 */
578 function buildCustom($id, $name, $viewOnly = FALSE) {
579 $stateCountryMap = $fields = array();
580
581 if ($id) {
582 $button = substr($this->controller->getButtonName(), -4);
583 $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
584 $session = CRM_Core_Session::singleton();
585 $contactID = $session->get('userID');
586
587 // we don't allow conflicting fields to be
588 // configured via profile
589 $fieldsToIgnore = array(
590 'participant_fee_amount' => 1,
591 'participant_fee_level' => 1,
592 );
593 if ($contactID) {
594 //FIX CRM-9653
595 if (is_array($id)) {
596 $fields = array();
597 foreach ($id as $profileID) {
598 $field = CRM_Core_BAO_UFGroup::getFields($profileID, FALSE, CRM_Core_Action::ADD,
599 NULL, NULL, FALSE, NULL,
600 FALSE, NULL, CRM_Core_Permission::CREATE,
601 'field_name', TRUE
602 );
603 $fields = array_merge($fields, $field);
604 }
605 }
606 else {
607 if (CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) {
608 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD,
609 NULL, NULL, FALSE, NULL,
610 FALSE, NULL, CRM_Core_Permission::CREATE,
611 'field_name', TRUE
612 );
613 }
614 }
615 }
616 else {
617 $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD,
618 NULL, NULL, FALSE, NULL,
619 FALSE, NULL, CRM_Core_Permission::CREATE,
620 'field_name', TRUE
621 );
622 }
623
624 if (array_intersect_key($fields, $fieldsToIgnore)) {
625 $fields = array_diff_key($fields, $fieldsToIgnore);
626 CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'));
627 }
628 $addCaptcha = FALSE;
629 $fields = array_diff_assoc($fields, $this->_fields);
630 if (!CRM_Utils_Array::value('additional_participants', $this->_params[0]) &&
631 is_null($cid)
632 ) {
633 CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID);
634 }
635 $this->assign($name, $fields);
636 if (is_array($fields)) {
637 foreach ($fields as $key => $field) {
638 if ($viewOnly &&
639 isset($field['data_type']) &&
640 $field['data_type'] == 'File' || ($viewOnly && $field['name'] == 'image_URL')
641 ) {
642 // ignore file upload fields
643 continue;
644 }
645 //make the field optional if primary participant
646 //have been skip the additional participant.
647 if ($button == 'skip') {
648 $field['is_required'] = FALSE;
649 }
650 // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor
651 elseif ($field['add_captcha'] && !$contactID) {
652 // only add captcha for first page
653 $addCaptcha = TRUE;
654 }
655 list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2);
656 if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') {
657 if (!array_key_exists($index, $stateCountryMap)) {
658 $stateCountryMap[$index] = array();
659 }
660 $stateCountryMap[$index][$prefixName] = $key;
661 }
662 CRM_Core_BAO_UFGroup::buildProfile($this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE);
663
664 $this->_fields[$key] = $field;
665 }
666 }
667
668 CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
669
670 if ($addCaptcha && !$viewOnly) {
671 $captcha = CRM_Utils_ReCAPTCHA::singleton();
672 $captcha->add($this);
673 $this->assign('isCaptcha', TRUE);
674 }
675 }
676 }
677
678 static function initEventFee(&$form, $eventID) {
679 // get price info
680
681 // retrive all active price set fields.
682 $discountId = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
683 if (property_exists($form, '_discountId') && $form->_discountId) {
684 $discountId = $form->_discountId;
685 }
686 if ($discountId) {
687 $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
688 $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', TRUE, $priceSetId);
689 }
690 else {
691 $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', TRUE);
692 }
693
694 if (property_exists($form, '_context') && ($form->_context == 'standalone'
695 || $form->_context == 'participant')) {
696 $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event');
697 if (is_array( $discountedEvent)) {
698 foreach ($discountedEvent as $key => $priceSetId) {
699 $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId);
700 $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
701 $form->_values['discount'][$key] = CRM_Utils_Array::value('fields', $priceSet);
702 $fieldID = key($form->_values['discount'][$key]);
703 $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue(
704 'CRM_Price_DAO_PriceSet',
705 $priceSetId,
706 'title'
707 );
708 }
709 }
710 }
711 $eventFee = CRM_Utils_Array::value('fee', $form->_values);
712 if (!is_array($eventFee) || empty($eventFee)) {
713 $form->_values['fee'] = array();
714 }
715
716 //fix for non-upgraded price sets.CRM-4256.
717 if (isset($form->_isPaidEvent)) {
718 $isPaidEvent = $form->_isPaidEvent;
719 }
720 else {
721 $isPaidEvent = CRM_Utils_Array::value('is_monetary', $form->_values['event']);
722 }
723 if ($isPaidEvent && empty($form->_values['fee'])) {
724 if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') {
725 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))));
726 }
727 }
728 }
729
730 /**
731 * Function to handle process after the confirmation of payment by User
732 *
733 * @return None
734 * @access public
735 */
736 function confirmPostProcess($contactID = NULL, $contribution = NULL, $payment = NULL) {
737 // add/update contact information
738 $fields = array();
739 unset($this->_params['note']);
740
741 //to avoid conflict overwrite $this->_params
742 $this->_params = $this->get('value');
743
744 //get the amount of primary participant
745 if (CRM_Utils_Array::value('is_primary', $this->_params)) {
746 $this->_params['fee_amount'] = $this->get('primaryParticipantAmount');
747 }
748
749 // add participant record
750 $participant = $this->addParticipant($this->_params, $contactID);
751 $this->_participantIDS[] = $participant->id;
752
753 //setting register_by_id field and primaryContactId
754 if (CRM_Utils_Array::value('is_primary', $this->_params)) {
755 $this->set('registerByID', $participant->id);
756 $this->set('primaryContactId', $contactID);
757
758 // CRM-10032
759 $this->processFirstParticipant($participant->id);
760 }
761
762 CRM_Core_BAO_CustomValueTable::postProcess($this->_params,
763 CRM_Core_DAO::$_nullArray,
764 'civicrm_participant',
765 $participant->id,
766 'Participant'
767 );
768
769 $createPayment = (CRM_Utils_Array::value('amount', $this->_params, 0) != 0) ? TRUE : FALSE;
770
771 // force to create zero amount payment, CRM-5095
772 // we know the amout is zero since createPayment is false
773 if (!$createPayment &&
774 (isset($contribution) && $contribution->id) &&
775 $this->_priceSetId &&
776 $this->_lineItem
777 ) {
778 $createPayment = TRUE;
779 }
780
781 if ($createPayment && $this->_values['event']['is_monetary'] &&
782 CRM_Utils_Array::value('contributionID', $this->_params)
783 ) {
784 $paymentParams = array(
785 'participant_id' => $participant->id,
786 'contribution_id' => $contribution->id,
787 );
788 $ids = array();
789 $paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams, $ids);
790 }
791
792 //set only primary participant's params for transfer checkout.
793 if (($this->_contributeMode == 'checkout' || $this->_contributeMode == 'notify')
794 && CRM_Utils_Array::value('is_primary', $this->_params)
795 ) {
796 $this->_params['participantID'] = $participant->id;
797 $this->set('primaryParticipant', $this->_params);
798 }
799
800 $this->assign('action', $this->_action);
801
802 // create CMS user
803 if (CRM_Utils_Array::value('cms_create_account', $this->_params)) {
804 $this->_params['contactID'] = $contactID;
805
806 if (array_key_exists('email-5', $this->_params)) {
807 $mail = 'email-5';
808 } else {
809 foreach ($this->_params as $name => $dontCare) {
810 if (substr($name, 0, 5) == 'email') {
811 $mail = $name;
812 break;
813 }
814 }
815 }
816
817 // we should use primary email for
818 // 1. free event registration.
819 // 2. pay later participant.
820 // 3. waiting list participant.
821 // 4. require approval participant.
822 if (CRM_Utils_Array::value('is_pay_later', $this->_params) ||
823 $this->_allowWaitlist || $this->_requireApproval ||
824 !CRM_Utils_Array::value('is_monetary', $this->_values['event'])
825 ) {
826 $mail = 'email-Primary';
827 }
828
829 if (!CRM_Core_BAO_CMSUser::create($this->_params, $mail)) {
830 CRM_Core_Error::statusBounce(ts('Your profile is not saved and Account is not created.'));
831 }
832 }
833 }
834
835 /**
836 * Process the participant
837 *
838 * @return void
839 * @access public
840 */
841 public function addParticipant($params, $contactID) {
842
843 $transaction = new CRM_Core_Transaction();
844
845 $groupName = 'participant_role';
846 $query = "
847 SELECT v.label as label ,v.value as value
848 FROM civicrm_option_value v,
849 civicrm_option_group g
850 WHERE v.option_group_id = g.id
851 AND g.name = %1
852 AND v.is_active = 1
853 AND g.is_active = 1
854 ";
855 $p = array(1 => array($groupName, 'String'));
856
857 $dao = CRM_Core_DAO::executeQuery($query, $p);
858 if ($dao->fetch()) {
859 $roleID = $dao->value;
860 }
861
862 // handle register date CRM-4320
863 $registerDate = NULL;
864 if ($this->_allowConfirmation && $this->_participantId) {
865 $registerDate = $params['participant_register_date'];
866 }
867 elseif (CRM_Utils_Array::value('participant_register_date', $params) &&
868 is_array($params['participant_register_date']) &&
869 !empty($params['participant_register_date'])
870 ) {
871 $registerDate = CRM_Utils_Date::format($params['participant_register_date']);
872 }
873
874 $participantParams = array('id' => CRM_Utils_Array::value('participant_id', $params),
875 'contact_id' => $contactID,
876 'event_id' => $this->_eventId ? $this->_eventId : $params['event_id'],
877 'status_id' => CRM_Utils_Array::value('participant_status',
878 $params, 1
879 ),
880 'role_id' => CRM_Utils_Array::value('participant_role_id',
881 $params, $roleID
882 ),
883 'register_date' => ($registerDate) ? $registerDate : date('YmdHis'),
884 'source' => isset($params['participant_source']) ?
885 CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params),
886 'fee_level' => CRM_Utils_Array::value('amount_level', $params),
887 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
888 'fee_amount' => CRM_Utils_Array::value('fee_amount', $params),
889 'registered_by_id' => CRM_Utils_Array::value('registered_by_id', $params),
890 'discount_id' => CRM_Utils_Array::value('discount_id', $params),
891 'fee_currency' => CRM_Utils_Array::value('currencyID', $params),
892 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params),
893 );
894
895 if ($this->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
896 $participantParams['is_test'] = 1;
897 }
898 else {
899 $participantParams['is_test'] = 0;
900 }
901
902 if (CRM_Utils_Array::value('note', $this->_params)) {
903 $participantParams['note'] = $this->_params['note'];
904 }
905 elseif (CRM_Utils_Array::value('participant_note', $this->_params)) {
906 $participantParams['note'] = $this->_params['participant_note'];
907 }
908
909 // reuse id if one already exists for this one (can happen
910 // with back button being hit etc)
911 if (!$participantParams['id'] &&
912 CRM_Utils_Array::value('contributionID', $params)
913 ) {
914 $pID = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment',
915 $params['contributionID'],
916 'participant_id',
917 'contribution_id'
918 );
919 $participantParams['id'] = $pID;
920 }
921 $participantParams['discount_id'] = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
922
923 if (!$participantParams['discount_id']) {
924 $participantParams['discount_id'] = "null";
925 }
926
927 $participant = CRM_Event_BAO_Participant::create($participantParams);
928
929 $transaction->commit();
930
931 return $participant;
932 }
933
934 /* Calculate the total participant count as per params.
935 *
936 * @param array $params user params.
937 *
938 * @return $totalCount total participant count.
939 * @access public
940 */
941 public static function getParticipantCount(&$form, $params, $skipCurrent = FALSE) {
942 $totalCount = 0;
943 if (!is_array($params) || empty($params)) {
944 return $totalCount;
945 }
946
947 $priceSetId = $form->get('priceSetId');
948 $addParticipantNum = substr($form->_name, 12);
949 $priceSetFields = $priceSetDetails = array();
950 $hasPriceFieldsCount = FALSE;
951 if ($priceSetId) {
952 $priceSetDetails = $form->get('priceSet');
953 if (isset($priceSetDetails['optionsCountTotal'])
954 && $priceSetDetails['optionsCountTotal']
955 ) {
956 $hasPriceFieldsCount = TRUE;
957 $priceSetFields = $priceSetDetails['optionsCountDetails']['fields'];
958 }
959 }
960
961 $singleFormParams = FALSE;
962 foreach ($params as $key => $val) {
963 if (!is_numeric($key)) {
964 $singleFormParams = TRUE;
965 break;
966 }
967 }
968
969 //first format the params.
970 if ($singleFormParams) {
971 $params = self::formatPriceSetParams($form, $params);
972 $params = array($params);
973 }
974
975 foreach ($params as $key => $values) {
976 if (!is_numeric($key) ||
977 $values == 'skip' ||
978 ($skipCurrent && ($addParticipantNum == $key))
979 ) {
980 continue;
981 }
982 $count = 1;
983
984 $usedCache = FALSE;
985 $cacheCount = CRM_Utils_Array::value($key, $form->_lineItemParticipantsCount);
986 if ($cacheCount && is_numeric($cacheCount)) {
987 $count = $cacheCount;
988 $usedCache = TRUE;
989 }
990
991 if (!$usedCache && $hasPriceFieldsCount) {
992 $count = 0;
993 foreach ($values as $valKey => $value) {
994 if (strpos($valKey, 'price_') === FALSE) {
995 continue;
996 }
997 $priceFieldId = substr($valKey, 6);
998 if (!$priceFieldId ||
999 !is_array($value) ||
1000 !array_key_exists($priceFieldId, $priceSetFields)
1001 ) {
1002 continue;
1003 }
1004 foreach ($value as $optId => $optVal) {
1005 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1006 if ($currentCount) {
1007 $count += $currentCount;
1008 }
1009 }
1010 }
1011 if (!$count) {
1012 $count = 1;
1013 }
1014 }
1015 $totalCount += $count;
1016 }
1017 if (!$totalCount) {
1018 $totalCount = 1;
1019 }
1020
1021 return $totalCount;
1022 }
1023
1024 /* Format user submitted price set params.
1025 * Convert price set each param as an array.
1026 *
1027 * @param $params an array of user submitted params.
1028 *
1029 *
1030 * @return array $formatted, formatted price set params.
1031 * @access public
1032 */
1033 public static function formatPriceSetParams(&$form, $params) {
1034 if (!is_array($params) || empty($params)) {
1035 return $params;
1036 }
1037
1038 $priceSetId = $form->get('priceSetId');
1039 if (!$priceSetId) {
1040 return $params;
1041 }
1042 $priceSetDetails = $form->get('priceSet');
1043
1044 foreach ($params as $key => & $value) {
1045 $vals = array();
1046 if (strpos($key, 'price_') !== FALSE) {
1047 $fieldId = substr($key, 6);
1048 if (!array_key_exists($fieldId, $priceSetDetails['fields']) ||
1049 is_array($value) ||
1050 !$value
1051 ) {
1052 continue;
1053 }
1054 $field = $priceSetDetails['fields'][$fieldId];
1055 if ($field['html_type'] == 'Text') {
1056 $fieldOption = current($field['options']);
1057 $value = array($fieldOption['id'] => $value);
1058 }
1059 else {
1060 $value = array($value => TRUE);
1061 }
1062 }
1063 }
1064
1065 return $params;
1066 }
1067
1068 /* Calculate total count for each price set options.
1069 * those are currently selected by user.
1070 *
1071 * @param $form form object.
1072 *
1073 *
1074 * @return array $optionsCount, array of each option w/ count total.
1075 * @access public
1076 */
1077 function getPriceSetOptionCount(&$form) {
1078 $params = $form->get('params');
1079 $priceSet = $form->get('priceSet');
1080 $priceSetId = $form->get('priceSetId');
1081
1082 $optionsCount = array();
1083 if (!$priceSetId ||
1084 !is_array($priceSet) ||
1085 empty($priceSet) ||
1086 !is_array($params) ||
1087 empty($params)
1088 ) {
1089 return $optionsCount;
1090 }
1091
1092 $priceSetFields = $priceMaxFieldDetails = array();
1093 if (CRM_Utils_Array::value('optionsCountTotal', $priceSet)) {
1094 $priceSetFields = $priceSet['optionsCountDetails']['fields'];
1095 }
1096
1097 if (CRM_Utils_Array::value('optionsMaxValueTotal', $priceSet)) {
1098 $priceMaxFieldDetails = $priceSet['optionsMaxValueDetails']['fields'];
1099 }
1100
1101 $addParticipantNum = substr($form->_name, 12);
1102 foreach ($params as $pCnt => $values) {
1103 if ($values == 'skip' ||
1104 $pCnt == $addParticipantNum
1105 ) {
1106 continue;
1107 }
1108
1109 foreach ($values as $valKey => $value) {
1110 if (strpos($valKey, 'price_') === FALSE) {
1111 continue;
1112 }
1113
1114 $priceFieldId = substr($valKey, 6);
1115 if (!$priceFieldId ||
1116 !is_array($value) ||
1117 !(array_key_exists($priceFieldId, $priceSetFields) || array_key_exists($priceFieldId, $priceMaxFieldDetails))
1118 ) {
1119 continue;
1120 }
1121
1122 foreach ($value as $optId => $optVal) {
1123 if (CRM_Utils_Array::value('html_type', $priceSet['fields'][$priceFieldId]) == 'Text') {
1124 $currentCount = $optVal;
1125 }
1126 else {
1127 $currentCount = 1;
1128 }
1129
1130 if (isset($priceSetFields[$priceFieldId]) && isset($priceSetFields[$priceFieldId]['options'][$optId])) {
1131 $currentCount = $priceSetFields[$priceFieldId]['options'][$optId] * $optVal;
1132 }
1133
1134 $optionsCount[$optId] = $currentCount + CRM_Utils_Array::value($optId, $optionsCount, 0);
1135 }
1136 }
1137 }
1138
1139 return $optionsCount;
1140 }
1141
1142 function checkTemplateFileExists($suffix = '') {
1143 if ($this->_eventId) {
1144 $templateName = $this->_name;
1145 if (substr($templateName, 0, 12) == 'Participant_') {
1146 $templateName = 'AdditionalParticipant';
1147 }
1148
1149 $templateFile = "CRM/Event/Form/Registration/{$this->_eventId}/{$templateName}.{$suffix}tpl";
1150 $template = CRM_Core_Form::getTemplate();
1151 if ($template->template_exists($templateFile)) {
1152 return $templateFile;
1153 }
1154 }
1155 return NULL;
1156 }
1157
1158 function getTemplateFileName() {
1159 $fileName = $this->checkTemplateFileExists();
1160 return $fileName ? $fileName : parent::getTemplateFileName();
1161 }
1162
1163 function overrideExtraTemplateFileName() {
1164 $fileName = $this->checkTemplateFileExists('extra.');
1165 return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
1166 }
1167
1168 function getContactID() {
1169 $tempID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
1170
1171 // force to ignore the authenticated user
1172 if ($tempID === '0') {
1173 return $tempID;
1174 }
1175
1176 // check if the user is logged in and has a contact ID
1177 $session = CRM_Core_Session::singleton();
1178 $userID = $session->get('userID');
1179
1180 if ($tempID == $userID) {
1181 return $userID;
1182 }
1183
1184 //check if this is a checksum authentication
1185 $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this);
1186 if ($userChecksum) {
1187 //check for anonymous user.
1188 $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($tempID, $userChecksum);
1189 if ($validUser) {
1190 return $tempID;
1191 }
1192 }
1193 // check if user has permission, CRM-12062
1194 else if ($tempID && CRM_Contact_BAO_Contact_Permission::allow($tempID)) {
1195 return $tempID;
1196 }
1197
1198 return $userID;
1199 }
1200
1201 /* Validate price set submitted params for price option limit,
1202 * as well as user should select at least one price field option.
1203 *
1204 */
1205 static function validatePriceSet(&$form, $params) {
1206 $errors = array();
1207 $hasOptMaxValue = FALSE;
1208 if (!is_array($params) || empty($params)) {
1209 return $errors;
1210 }
1211
1212 $currentParticipantNum = substr($form->_name, 12);
1213 if (!$currentParticipantNum) {
1214 $currentParticipantNum = 0;
1215 }
1216
1217 $priceSetId = $form->get('priceSetId');
1218 $priceSetDetails = $form->get('priceSet');
1219 if (
1220 !$priceSetId ||
1221 !is_array($priceSetDetails) ||
1222 empty($priceSetDetails)
1223 ) {
1224 return $errors;
1225 }
1226
1227 $optionsCountDetails = $optionsMaxValueDetails = array();
1228 if (
1229 isset($priceSetDetails['optionsMaxValueTotal'])
1230 && $priceSetDetails['optionsMaxValueTotal']
1231 ) {
1232 $hasOptMaxValue = TRUE;
1233 $optionsMaxValueDetails = $priceSetDetails['optionsMaxValueDetails']['fields'];
1234 }
1235 if (
1236 isset($priceSetDetails['optionsCountTotal'])
1237 && $priceSetDetails['optionsCountTotal']
1238 ) {
1239 $hasOptCount = TRUE;
1240 $optionsCountDetails = $priceSetDetails['optionsCountDetails']['fields'];
1241 }
1242 $feeBlock = $form->_feeBlock;
1243
1244 if (empty($feeBlock)) {
1245 $feeBlock = $priceSetDetails['fields'];
1246 }
1247
1248 $optionMaxValues = $fieldSelected = array();
1249 foreach ($params as $pNum => $values) {
1250 if (!is_array($values) || $values == 'skip') {
1251 continue;
1252 }
1253
1254 foreach ($values as $valKey => $value) {
1255 if (strpos($valKey, 'price_') === FALSE) {
1256 continue;
1257 }
1258 $priceFieldId = substr($valKey, 6);
1259 $noneOptionValueSelected = FALSE;
1260 if (!$feeBlock[$priceFieldId]['is_required'] && $value == 0) {
1261 $noneOptionValueSelected = TRUE;
1262 }
1263
1264 if (
1265 !$priceFieldId ||
1266 (!$noneOptionValueSelected && !is_array($value))
1267 ) {
1268 continue;
1269 }
1270
1271 $fieldSelected[$pNum] = TRUE;
1272
1273 if (!$hasOptMaxValue || !is_array($value)) {
1274 continue;
1275 }
1276
1277 foreach ($value as $optId => $optVal) {
1278 if (CRM_Utils_Array::value('html_type', $feeBlock[$priceFieldId]) == 'Text') {
1279 $currentMaxValue = $optVal;
1280 }
1281 else {
1282 $currentMaxValue = 1;
1283 }
1284
1285 if (isset($optionsCountDetails[$priceFieldId]) && isset($optionsCountDetails[$priceFieldId]['options'][$optId])) {
1286 $currentMaxValue = $optionsCountDetails[$priceFieldId]['options'][$optId] * $optVal;
1287 }
1288 if (empty($optionMaxValues)) {
1289 $optionMaxValues[$priceFieldId][$optId] = $currentMaxValue;
1290 }
1291 else {
1292 $optionMaxValues[$priceFieldId][$optId] =
1293 $currentMaxValue + CRM_Utils_Array::value($optId, CRM_Utils_Array::value($priceFieldId, $optionMaxValues), 0);
1294 }
1295
1296 }
1297 }
1298 }
1299
1300 //validate for option max value.
1301 foreach ($optionMaxValues as $fieldId => $values) {
1302 $options = CRM_Utils_Array::value('options', $feeBlock[$fieldId], array());
1303 foreach ($values as $optId => $total) {
1304 $optMax = $optionsMaxValueDetails[$fieldId]['options'][$optId];
1305 $opDbCount = CRM_Utils_Array::value('db_total_count', $options[$optId], 0);
1306 $total += $opDbCount;
1307 if ($optMax && $total > $optMax) {
1308 if ($opDbCount && ($opDbCount >= $optMax)) {
1309 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1310 ts('Sorry, this option is currently sold out.');
1311 }
1312 elseif (($optMax - $opDbCount) == 1) {
1313 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1314 ts('Sorry, currently only a single seat is available for this option.', array(1 => ($optMax - $opDbCount)));
1315 }
1316 else {
1317 $errors[$currentParticipantNum]["price_{$fieldId}"] =
1318 ts('Sorry, currently only %1 seats are available for this option.', array(1 => ($optMax - $opDbCount)));
1319 }
1320 }
1321 }
1322 }
1323
1324 //validate for price field selection.
1325 foreach ($params as $pNum => $values) {
1326 if (!is_array($values) || $values == 'skip') {
1327 continue;
1328 }
1329 if (!CRM_Utils_Array::value($pNum, $fieldSelected)) {
1330 $errors[$pNum]['_qf_default'] = ts('Select at least one option from Event Fee(s).');
1331 }
1332 }
1333
1334 return $errors;
1335 }
1336
1337 // set the first participant ID if not set, CRM-10032
1338 function processFirstParticipant($participantID) {
1339 $this->_participantId = $participantID;
1340 $this->set('participantId', $this->_participantId);
1341
1342 $ids = $participantValues = array();
1343 $participantParams = array('id' => $this->_participantId);
1344 CRM_Event_BAO_Participant::getValues($participantParams, $participantValues, $ids);
1345 $this->_values['participant'] = $participantValues[$this->_participantId];
1346 $this->set('values', $this->_values);
1347
1348 // also set the allow confirmation stuff
1349 if (array_key_exists(
1350 $this->_values['participant']['status_id'],
1351 CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'")
1352 )) {
1353 $this->_allowConfirmation = TRUE;
1354 $this->set('allowConfirmation', TRUE);
1355 }
1356 }
1357
1358 function checkValidEvent($redirect = NULL) {
1359 // is the event active (enabled)?
1360 if (!$this->_values['event']['is_active']) {
1361 // form is inactive, die a fatal death
1362 CRM_Core_Error::statusBounce(ts('The event you requested is currently unavailable (contact the site administrator for assistance).'));
1363 }
1364
1365 // is online registration is enabled?
1366 if (!$this->_values['event']['is_online_registration']) {
1367 CRM_Core_Error::statusBounce(ts('Online registration is not currently available for this event (contact the site administrator for assistance).'), $redirect);
1368 }
1369
1370 // is this an event template ?
1371 if (CRM_Utils_Array::value('is_template', $this->_values['event'])) {
1372 CRM_Core_Error::statusBounce(ts('Event templates are not meant to be registered.'), $redirect);
1373 }
1374
1375 $now = date('YmdHis');
1376 $startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_start_date',
1377 $this->_values['event']
1378 ));
1379
1380 if (
1381 $startDate &&
1382 $startDate >= $now
1383 ) {
1384 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);
1385 }
1386
1387 $endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('registration_end_date',
1388 $this->_values['event']
1389 ));
1390 if (
1391 $endDate &&
1392 $endDate < $now
1393 ) {
1394 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);
1395 }
1396 }
1397 }
1398