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