Fix queue code to use CiviCRM's version of what the time is, instead of server's.
[civicrm-core.git] / CRM / Event / Form / Registration / Register.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2019
31 */
32
33 /**
34 * This class generates form components for processing Event.
35 */
36 class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
37
38 /**
39 * The fields involved in this page.
40 *
41 * @var array
42 */
43 public $_fields;
44
45 /**
46 * The status message that user view.
47 *
48 * @var string
49 */
50 protected $_waitlistMsg;
51 protected $_requireApprovalMsg;
52
53 /**
54 * Deprecated parameter that we hope to remove.
55 *
56 * @var bool
57 */
58 public $_quickConfig;
59
60 /**
61 * Skip duplicate check.
62 *
63 * This can be set using hook_civicrm_buildForm() to override the registration dupe check.
64 * CRM-7604
65 *
66 * @var bool
67 */
68 public $_skipDupeRegistrationCheck = FALSE;
69
70 public $_paymentProcessorID;
71
72 /**
73 * Show fee block or not.
74 *
75 * @var bool
76 */
77 public $_noFees;
78
79 /**
80 * Fee Block.
81 *
82 * @var array
83 */
84 public $_feeBlock;
85
86 /**
87 * Array of payment related fields to potentially display on this form (generally credit card or debit card fields).
88 *
89 * This is rendered via billingBlock.tpl.
90 *
91 * @var array
92 */
93 public $_paymentFields = [];
94
95 /**
96 * Is this submission incurring no costs.
97 *
98 * @param array $fields
99 * @param \CRM_Event_Form_Registration_Register $form
100 *
101 * @return bool
102 */
103 protected static function isZeroAmount($fields, $form): bool {
104 $isZeroAmount = FALSE;
105 if (!empty($fields['priceSetId'])) {
106 if (empty($fields['amount'])) {
107 $isZeroAmount = TRUE;
108 }
109 }
110 elseif (!empty($fields['amount']) &&
111 (isset($form->_values['discount'][$fields['amount']])
112 && CRM_Utils_Array::value('value', $form->_values['discount'][$fields['amount']]) == 0
113 )
114 ) {
115 $isZeroAmount = TRUE;
116 }
117 elseif (!empty($fields['amount']) &&
118 (isset($form->_values['fee'][$fields['amount']])
119 && CRM_Utils_Array::value('value', $form->_values['fee'][$fields['amount']]) == 0
120 )
121 ) {
122 $isZeroAmount = TRUE;
123 }
124 return $isZeroAmount;
125 }
126
127 /**
128 * Get the contact id for the registration.
129 *
130 * @param array $fields
131 * @param CRM_Event_Form_Registration $form
132 * @param bool $isAdditional
133 *
134 * @return int|null
135 */
136 public static function getRegistrationContactID($fields, $form, $isAdditional) {
137 $contactID = NULL;
138 if (!$isAdditional) {
139 $contactID = $form->getContactID();
140 }
141 if (!$contactID && is_array($fields) && $fields) {
142 $contactID = CRM_Contact_BAO_Contact::getFirstDuplicateContact($fields, 'Individual', 'Unsupervised', [], FALSE, CRM_Utils_Array::value('dedupe_rule_group_id', $form->_values['event']), ['event_id' => CRM_Utils_Array::value('id', $form->_values['event'])]);
143 }
144 return $contactID;
145 }
146
147 /**
148 * Set variables up before form is built.
149 *
150 * @throws \CRM_Core_Exception
151 */
152 public function preProcess() {
153 parent::preProcess();
154
155 //CRM-4320.
156 //here we can't use parent $this->_allowWaitlist as user might
157 //walk back and we might set this value in this postProcess.
158 //(we set when spaces < group count and want to allow become part of waiting )
159 $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $this->_values['event']));
160
161 // Get payment processors if appropriate for this event
162 // We hide the payment fields if the event is full or requires approval,
163 // and the current user has not yet been approved CRM-12279
164 $this->_noFees = (($eventFull || $this->_requireApproval) && !$this->_allowConfirmation);
165 $this->_paymentProcessors = $this->_noFees ? [] : $this->get('paymentProcessors');
166 $this->preProcessPaymentOptions();
167
168 $this->_allowWaitlist = FALSE;
169 if ($eventFull && !$this->_allowConfirmation && !empty($this->_values['event']['has_waitlist'])) {
170 $this->_allowWaitlist = TRUE;
171 $this->_waitlistMsg = CRM_Utils_Array::value('waitlist_text', $this->_values['event']);
172 if (!$this->_waitlistMsg) {
173 $this->_waitlistMsg = ts('This event is currently full. However you can register now and get added to a waiting list. You will be notified if spaces become available.');
174 }
175 }
176 $this->set('allowWaitlist', $this->_allowWaitlist);
177
178 //To check if the user is already registered for the event(CRM-2426)
179 if (!$this->_skipDupeRegistrationCheck) {
180 self::checkRegistration(NULL, $this);
181 }
182
183 $this->assign('availableRegistrations', $this->_availableRegistrations);
184
185 // get the participant values from EventFees.php, CRM-4320
186 if ($this->_allowConfirmation) {
187 CRM_Event_Form_EventFees::preProcess($this);
188 }
189 }
190
191 /**
192 * Set default values for the form.
193 *
194 * @return array
195 *
196 * @throws \CRM_Core_Exception
197 * @throws \CiviCRM_API3_Exception
198 */
199 public function setDefaultValues() {
200 $this->_defaults = [];
201 if (!$this->_allowConfirmation && $this->_requireApproval) {
202 $this->_defaults['bypass_payment'] = 1;
203 }
204 $contactID = $this->getContactID();
205 CRM_Core_Payment_Form::setDefaultValues($this, $contactID);
206
207 CRM_Event_BAO_Participant::formatFieldsAndSetProfileDefaults($contactID, $this);
208
209 // Set default payment processor as default payment_processor radio button value
210 if (!empty($this->_paymentProcessors)) {
211 foreach ($this->_paymentProcessors as $pid => $value) {
212 if (!empty($value['is_default'])) {
213 $this->_defaults['payment_processor_id'] = $pid;
214 }
215 }
216 }
217
218 //if event is monetary and pay later is enabled and payment
219 //processor is not available then freeze the pay later checkbox with
220 //default check
221 if (!empty($this->_values['event']['is_pay_later']) &&
222 !is_array($this->_paymentProcessor)
223 ) {
224 $this->_defaults['is_pay_later'] = 1;
225 }
226
227 //set custom field defaults
228 if (!empty($this->_fields)) {
229 //load default campaign from page.
230 if (array_key_exists('participant_campaign_id', $this->_fields)) {
231 $this->_defaults['participant_campaign_id'] = CRM_Utils_Array::value('campaign_id',
232 $this->_values['event']
233 );
234 }
235
236 foreach ($this->_fields as $name => $field) {
237 if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
238 // fix for CRM-1743
239 if (!isset($this->_defaults[$name])) {
240 CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $this->_defaults,
241 NULL, CRM_Profile_Form::MODE_REGISTER
242 );
243 }
244 }
245 }
246 }
247
248 //fix for CRM-3088, default value for discount set.
249 $discountId = NULL;
250 if (!empty($this->_values['discount'])) {
251 $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
252 if ($discountId) {
253 if (isset($this->_values['event']['default_discount_fee_id'])) {
254 $discountKey = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
255 $this->_values['event']['default_discount_fee_id'],
256 'weight', 'id'
257 );
258
259 $this->_defaults['amount'] = key(array_slice($this->_values['discount'][$discountId],
260 $discountKey - 1, $discountKey, TRUE
261 ));
262 }
263 }
264 }
265
266 // add this event's default participant role to defaults array
267 // (for cases where participant_role field is included in form via profile)
268 if ($this->_values['event']['default_role_id']) {
269 $this->_defaults['participant_role']
270 = $this->_defaults['participant_role_id'] = $this->_values['event']['default_role_id'];
271 }
272 if ($this->_priceSetId && !empty($this->_feeBlock)) {
273 foreach ($this->_feeBlock as $key => $val) {
274 if (empty($val['options'])) {
275 continue;
276 }
277 $optionFullIds = CRM_Utils_Array::value('option_full_ids', $val, []);
278 foreach ($val['options'] as $keys => $values) {
279 if ($values['is_default'] && empty($values['is_full'])) {
280
281 if ($val['html_type'] == 'CheckBox') {
282 $this->_defaults["price_{$key}"][$keys] = 1;
283 }
284 else {
285 $this->_defaults["price_{$key}"] = $keys;
286 }
287 }
288 }
289 $unsetSubmittedOptions[$val['id']] = $optionFullIds;
290 }
291 //reset values for all options those are full.
292 CRM_Event_Form_Registration::resetElementValue($unsetSubmittedOptions, $this);
293 }
294
295 //set default participant fields, CRM-4320.
296 $hasAdditionalParticipants = FALSE;
297 if ($this->_allowConfirmation) {
298 $this->_contactId = $contactID;
299 $this->_discountId = $discountId;
300 $forcePayLater = CRM_Utils_Array::value('is_pay_later', $this->_defaults, FALSE);
301 $this->_defaults = array_merge($this->_defaults, CRM_Event_Form_EventFees::setDefaultValues($this));
302 $this->_defaults['is_pay_later'] = $forcePayLater;
303
304 if ($this->_additionalParticipantIds) {
305 $hasAdditionalParticipants = TRUE;
306 $this->_defaults['additional_participants'] = count($this->_additionalParticipantIds);
307 }
308 }
309 $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
310
311 // //hack to simplify credit card entry for testing
312 // $this->_defaults['credit_card_type'] = 'Visa';
313 // $this->_defaults['credit_card_number'] = '4807731747657838';
314 // $this->_defaults['cvv2'] = '000';
315 // $this->_defaults['credit_card_exp_date'] = array( 'Y' => '2010', 'M' => '05' );
316
317 // to process Custom data that are appended to URL
318 $getDefaults = CRM_Core_BAO_CustomGroup::extractGetParams($this, "'Contact', 'Individual', 'Contribution', 'Participant'");
319 if (!empty($getDefaults)) {
320 $this->_defaults = array_merge($this->_defaults, $getDefaults);
321 }
322
323 return $this->_defaults;
324 }
325
326 /**
327 * Build the form object.
328 */
329 public function buildQuickForm() {
330 // build profiles first so that we can determine address fields etc
331 // and then show copy address checkbox
332 $this->buildCustom($this->_values['custom_pre_id'], 'customPre');
333 $this->buildCustom($this->_values['custom_post_id'], 'customPost');
334
335 // CRM-18399: used by template to pass pre profile id as a url arg
336 $this->assign('custom_pre_id', $this->_values['custom_pre_id']);
337
338 CRM_Core_Payment_ProcessorForm::buildQuickForm($this);
339
340 $contactID = $this->getContactID();
341 if ($contactID) {
342 $this->assign('contact_id', $contactID);
343 $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID));
344 }
345
346 $this->add('hidden', 'scriptFee', NULL);
347 $this->add('hidden', 'scriptArray', NULL);
348
349 $bypassPayment = $allowGroupOnWaitlist = $isAdditionalParticipants = FALSE;
350 if ($this->_values['event']['is_multiple_registrations']) {
351 // don't allow to add additional during confirmation if not preregistered.
352 if (!$this->_allowConfirmation || $this->_additionalParticipantIds) {
353 // CRM-17745: Make maximum additional participants configurable
354 // Label is value + 1, since the code sees this is ADDITIONAL participants (in addition to "self")
355 $additionalOptions = [];
356 $additionalOptions[''] = 1;
357 for ($i = 1; $i <= $this->_values['event']['max_additional_participants']; $i++) {
358 $additionalOptions[$i] = $i + 1;
359 }
360 $this->add('select', 'additional_participants',
361 ts('How many people are you registering?'),
362 $additionalOptions,
363 NULL,
364 ['onChange' => "allowParticipant()"]
365 );
366 $isAdditionalParticipants = TRUE;
367 }
368 }
369
370 if (!$this->_allowConfirmation) {
371 $bypassPayment = TRUE;
372 }
373
374 //hack to allow group to register w/ waiting
375 if ((!empty($this->_values['event']['is_multiple_registrations']) ||
376 $this->_priceSetId
377 ) &&
378 !$this->_allowConfirmation &&
379 is_numeric($this->_availableRegistrations) && !empty($this->_values['event']['has_waitlist'])
380 ) {
381 $bypassPayment = TRUE;
382 //case might be group become as a part of waitlist.
383 //If not waitlist then they require admin approve.
384 $allowGroupOnWaitlist = TRUE;
385 $this->_waitlistMsg = ts("This event has only %1 space(s) left. If you continue and register more than %1 people (including yourself ), the whole group will be wait listed. Or, you can reduce the number of people you are registering to %1 to avoid being put on the waiting list.", [1 => $this->_availableRegistrations]);
386
387 if ($this->_requireApproval) {
388 $this->_requireApprovalMsg = CRM_Utils_Array::value('approval_req_text', $this->_values['event'],
389 ts('Registration for this event requires approval. Once your registration(s) have been reviewed, you will receive an email with a link to a web page where you can complete the registration process.')
390 );
391 }
392 }
393
394 //case where only approval needed - no waitlist.
395 if ($this->_requireApproval &&
396 !$this->_allowWaitlist && !$bypassPayment
397 ) {
398 $this->_requireApprovalMsg = CRM_Utils_Array::value('approval_req_text', $this->_values['event'],
399 ts('Registration for this event requires approval. Once your registration has been reviewed, you will receive an email with a link to a web page where you can complete the registration process.')
400 );
401 }
402
403 //lets display status to primary page only.
404 $this->assign('waitlistMsg', $this->_waitlistMsg);
405 $this->assign('requireApprovalMsg', $this->_requireApprovalMsg);
406 $this->assign('allowGroupOnWaitlist', $allowGroupOnWaitlist);
407 $this->assign('isAdditionalParticipants', $isAdditionalParticipants);
408
409 if ($this->_values['event']['is_monetary']) {
410 self::buildAmount($this);
411 }
412
413 $pps = [];
414 //@todo this processor adding fn is another one duplicated on contribute - a shared
415 // common class would make this sort of thing extractable
416 $onlinePaymentProcessorEnabled = FALSE;
417 if (!empty($this->_paymentProcessors)) {
418 foreach ($this->_paymentProcessors as $key => $name) {
419 if ($name['billing_mode'] == 1) {
420 $onlinePaymentProcessorEnabled = TRUE;
421 }
422 $pps[$key] = $name['name'];
423 }
424 }
425 if ($this->getContactID() === 0 && !$this->_values['event']['is_multiple_registrations']) {
426 //@todo we are blocking for multiple registrations because we haven't tested
427 $this->addCIDZeroOptions($onlinePaymentProcessorEnabled);
428 }
429 if (!empty($this->_values['event']['is_pay_later']) &&
430 ($this->_allowConfirmation || (!$this->_requireApproval && !$this->_allowWaitlist))
431 ) {
432 $pps[0] = $this->_values['event']['pay_later_text'];
433 }
434
435 if ($this->_values['event']['is_monetary']) {
436 if (count($pps) > 1) {
437 $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
438 NULL, "&nbsp;"
439 );
440 }
441 elseif (!empty($pps)) {
442 $ppKeys = array_keys($pps);
443 $currentPP = array_pop($ppKeys);
444 $this->addElement('hidden', 'payment_processor_id', $currentPP);
445 }
446 }
447
448 $this->addElement('hidden', 'bypass_payment', NULL, ['id' => 'bypass_payment']);
449
450 $this->assign('bypassPayment', $bypassPayment);
451
452 $userID = $this->getContactID();
453
454 if (!$userID) {
455 $createCMSUser = FALSE;
456
457 if ($this->_values['custom_pre_id']) {
458 $profileID = $this->_values['custom_pre_id'];
459 $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
460 }
461
462 if (!$createCMSUser &&
463 $this->_values['custom_post_id']
464 ) {
465 if (!is_array($this->_values['custom_post_id'])) {
466 $profileIDs = [$this->_values['custom_post_id']];
467 }
468 else {
469 $profileIDs = $this->_values['custom_post_id'];
470 }
471 foreach ($profileIDs as $pid) {
472 if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
473 $profileID = $pid;
474 $createCMSUser = TRUE;
475 break;
476 }
477 }
478 }
479
480 if ($createCMSUser) {
481 CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE);
482 }
483 }
484
485 //we have to load confirm contribution button in template
486 //when multiple payment processor as the user
487 //can toggle with payment processor selection
488 $billingModePaymentProcessors = 0;
489 if (!CRM_Utils_System::isNull($this->_paymentProcessors)) {
490 foreach ($this->_paymentProcessors as $key => $values) {
491 if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) {
492 $billingModePaymentProcessors++;
493 }
494 }
495 }
496
497 if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) {
498 $allAreBillingModeProcessors = TRUE;
499 }
500 else {
501 $allAreBillingModeProcessors = FALSE;
502 }
503
504 if (!$allAreBillingModeProcessors || !empty($this->_values['event']['is_pay_later']) || $bypassPayment
505 ) {
506
507 //freeze button to avoid multiple calls.
508 if (empty($this->_values['event']['is_monetary'])) {
509 $this->submitOnce = TRUE;
510 }
511
512 // CRM-11182 - Optional confirmation screen
513 // Change button label depending on whether the next action is confirm or register
514 if (
515 !$this->_values['event']['is_multiple_registrations']
516 && !$this->_values['event']['is_monetary']
517 && !$this->_values['event']['is_confirm_enabled']
518 ) {
519 $buttonLabel = ts('Register');
520 }
521 else {
522 $buttonLabel = ts('Continue');
523 }
524
525 $this->addButtons([
526 [
527 'type' => 'upload',
528 'name' => $buttonLabel,
529 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
530 'isDefault' => TRUE,
531 ],
532 ]);
533 }
534
535 $this->addFormRule(['CRM_Event_Form_Registration_Register', 'formRule'], $this);
536 $this->unsavedChangesWarn = TRUE;
537
538 // add pcp fields
539 if ($this->_pcpId) {
540 CRM_PCP_BAO_PCP::buildPcp($this->_pcpId, $this);
541 }
542 }
543
544 /**
545 * Build the radio/text form elements for the amount field
546 *
547 * @param CRM_Event_Form_Registration_Register $form
548 * Form object.
549 * @param bool $required
550 * True if you want to add formRule.
551 * @param int $discountId
552 * Discount id for the event.
553 *
554 * @throws \CRM_Core_Exception
555 */
556 public static function buildAmount(&$form, $required = TRUE, $discountId = NULL) {
557 // build amount only when needed, skip incase of event full and waitlisting is enabled
558 // and few other conditions check preProcess()
559 if (property_exists($form, '_noFees') && $form->_noFees) {
560 return;
561 }
562
563 //if payment done, no need to build the fee block.
564 if (!empty($form->_paymentId)) {
565 //fix to display line item in update mode.
566 $form->assign('priceSet', isset($form->_priceSet) ? $form->_priceSet : NULL);
567 return;
568 }
569
570 $feeFields = CRM_Utils_Array::value('fee', $form->_values);
571
572 if (is_array($feeFields)) {
573 $form->_feeBlock = &$form->_values['fee'];
574 }
575
576 //check for discount.
577 $discountedFee = CRM_Utils_Array::value('discount', $form->_values);
578 if (is_array($discountedFee) && !empty($discountedFee)) {
579 if (!$discountId) {
580 $form->_discountId = $discountId = CRM_Core_BAO_Discount::findSet($form->_eventId, 'civicrm_event');
581 }
582 if ($discountId) {
583 $form->_feeBlock = &$form->_values['discount'][$discountId];
584 }
585 }
586 if (!is_array($form->_feeBlock)) {
587 $form->_feeBlock = [];
588 }
589
590 //its time to call the hook.
591 CRM_Utils_Hook::buildAmount('event', $form, $form->_feeBlock);
592
593 //reset required if participant is skipped.
594 $button = substr($form->controller->getButtonName(), -4);
595 if ($required && $button == 'skip') {
596 $required = FALSE;
597 }
598
599 $className = CRM_Utils_System::getClassName($form);
600
601 //build the priceset fields.
602 if (isset($form->_priceSetId) && $form->_priceSetId) {
603
604 //format price set fields across option full.
605 self::formatFieldsForOptionFull($form);
606
607 if (!empty($form->_priceSet['is_quick_config'])) {
608 $form->_quickConfig = $form->_priceSet['is_quick_config'];
609 }
610 $form->add('hidden', 'priceSetId', $form->_priceSetId);
611
612 // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
613 $adminFieldVisible = FALSE;
614 if (CRM_Core_Permission::check('administer CiviCRM')) {
615 $adminFieldVisible = TRUE;
616 }
617
618 $hideAdminValues = TRUE;
619 if (CRM_Core_Permission::check('edit event participants')) {
620 $hideAdminValues = FALSE;
621 }
622
623 foreach ($form->_feeBlock as $field) {
624 // public AND admin visibility fields are included for back-office registration and back-office change selections
625 if (CRM_Utils_Array::value('visibility', $field) == 'public' ||
626 (CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE) ||
627 $className == 'CRM_Event_Form_Participant' ||
628 $className == 'CRM_Event_Form_ParticipantFeeSelection'
629 ) {
630 $fieldId = $field['id'];
631 $elementName = 'price_' . $fieldId;
632
633 $isRequire = CRM_Utils_Array::value('is_required', $field);
634 if ($button == 'skip') {
635 $isRequire = FALSE;
636 }
637
638 //user might modified w/ hook.
639 $options = CRM_Utils_Array::value('options', $field);
640 $formClasses = ['CRM_Event_Form_Participant', 'CRM_Event_Form_ParticipantFeeSelection'];
641
642 if (!is_array($options)) {
643 continue;
644 }
645 elseif ($hideAdminValues && !in_array($className, $formClasses)) {
646 $publicVisibilityID = CRM_Price_BAO_PriceField::getVisibilityOptionID('public');
647 $adminVisibilityID = CRM_Price_BAO_PriceField::getVisibilityOptionID('admin');
648
649 foreach ($options as $key => $currentOption) {
650 $optionVisibility = CRM_Utils_Array::value('visibility_id', $currentOption, $publicVisibilityID);
651 if ($optionVisibility == $adminVisibilityID) {
652 unset($options[$key]);
653 }
654 }
655 }
656
657 $optionFullIds = CRM_Utils_Array::value('option_full_ids', $field, []);
658
659 //soft suppress required rule when option is full.
660 if (!empty($optionFullIds) && (count($options) == count($optionFullIds))) {
661 $isRequire = FALSE;
662 }
663 if (!empty($options)) {
664 //build the element.
665 CRM_Price_BAO_PriceField::addQuickFormElement($form,
666 $elementName,
667 $fieldId,
668 FALSE,
669 $isRequire,
670 NULL,
671 $options,
672 $optionFullIds
673 );
674 }
675 }
676 }
677 $form->assign('priceSet', $form->_priceSet);
678 }
679 else {
680 $eventFeeBlockValues = [];
681 foreach ($form->_feeBlock as $fee) {
682 if (is_array($fee)) {
683
684 //CRM-7632, CRM-6201
685 $totalAmountJs = NULL;
686 if ($className == 'CRM_Event_Form_Participant') {
687 $totalAmountJs = ['onClick' => "fillTotalAmount(" . $fee['value'] . ")"];
688 }
689
690 $eventFeeBlockValues['amount_id_' . $fee['amount_id']] = $fee['value'];
691 $elements[] = &$form->createElement('radio', NULL, '',
692 CRM_Utils_Money::format($fee['value']) . ' ' .
693 $fee['label'],
694 $fee['amount_id'],
695 $totalAmountJs
696 );
697 }
698 }
699 $form->assign('eventFeeBlockValues', json_encode($eventFeeBlockValues));
700
701 $form->_defaults['amount'] = CRM_Utils_Array::value('default_fee_id', $form->_values['event']);
702 $element = &$form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
703 if (isset($form->_online) && $form->_online) {
704 $element->freeze();
705 }
706 if ($required) {
707 $form->addRule('amount', ts('Fee Level is a required field.'), 'required');
708 }
709 }
710 }
711
712 /**
713 * @param CRM_Event_Form_Registration $form
714 */
715 public static function formatFieldsForOptionFull(&$form) {
716 $priceSet = $form->get('priceSet');
717 $priceSetId = $form->get('priceSetId');
718 $defaultPricefieldIds = [];
719 if (!empty($form->_values['line_items'])) {
720 foreach ($form->_values['line_items'] as $lineItem) {
721 $defaultPricefieldIds[] = $lineItem['price_field_value_id'];
722 }
723 }
724 if (!$priceSetId ||
725 !is_array($priceSet) ||
726 empty($priceSet) || empty($priceSet['optionsMaxValueTotal'])
727 ) {
728 return;
729 }
730
731 $skipParticipants = $formattedPriceSetDefaults = [];
732 if (!empty($form->_allowConfirmation) && (isset($form->_pId) || isset($form->_additionalParticipantId))) {
733 $participantId = isset($form->_pId) ? $form->_pId : $form->_additionalParticipantId;
734 $pricesetDefaults = CRM_Event_Form_EventFees::setDefaultPriceSet($participantId,
735 $form->_eventId
736 );
737 // modify options full to respect the selected fields
738 // options on confirmation.
739 $formattedPriceSetDefaults = self::formatPriceSetParams($form, $pricesetDefaults);
740
741 // to skip current registered participants fields option count on confirmation.
742 $skipParticipants[] = $form->_participantId;
743 if (!empty($form->_additionalParticipantIds)) {
744 $skipParticipants = array_merge($skipParticipants, $form->_additionalParticipantIds);
745 }
746 }
747
748 $className = CRM_Utils_System::getClassName($form);
749
750 //get the current price event price set options count.
751 $currentOptionsCount = self::getPriceSetOptionCount($form);
752 $recordedOptionsCount = CRM_Event_BAO_Participant::priceSetOptionsCount($form->_eventId, $skipParticipants);
753 $optionFullTotalAmount = 0;
754 $currentParticipantNo = (int) substr($form->_name, 12);
755 foreach ($form->_feeBlock as & $field) {
756 $optionFullIds = [];
757 $fieldId = $field['id'];
758 if (!is_array($field['options'])) {
759 continue;
760 }
761 foreach ($field['options'] as & $option) {
762 $optId = $option['id'];
763 $count = CRM_Utils_Array::value('count', $option, 0);
764 $maxValue = CRM_Utils_Array::value('max_value', $option, 0);
765 $dbTotalCount = CRM_Utils_Array::value($optId, $recordedOptionsCount, 0);
766 $currentTotalCount = CRM_Utils_Array::value($optId, $currentOptionsCount, 0);
767
768 $totalCount = $currentTotalCount + $dbTotalCount;
769 $isFull = FALSE;
770 if ($maxValue &&
771 (($totalCount >= $maxValue) &&
772 (empty($form->_lineItem[$currentParticipantNo][$optId]['price_field_id']) || $dbTotalCount >= $maxValue))
773 ) {
774 $isFull = TRUE;
775 $optionFullIds[$optId] = $optId;
776 if ($field['html_type'] != 'Select') {
777 if (in_array($optId, $defaultPricefieldIds)) {
778 $optionFullTotalAmount += CRM_Utils_Array::value('amount', $option);
779 }
780 }
781 else {
782 if (!empty($defaultPricefieldIds) && in_array($optId, $defaultPricefieldIds)) {
783 unset($optionFullIds[$optId]);
784 }
785 }
786 }
787 //here option is not full,
788 //but we don't want to allow participant to increase
789 //seats at the time of re-walking registration.
790 if ($count &&
791 !empty($form->_allowConfirmation) &&
792 !empty($formattedPriceSetDefaults)
793 ) {
794 if (empty($formattedPriceSetDefaults["price_{$field}"]) || empty($formattedPriceSetDefaults["price_{$fieldId}"][$optId])) {
795 $optionFullIds[$optId] = $optId;
796 $isFull = TRUE;
797 }
798 }
799 $option['is_full'] = $isFull;
800 $option['db_total_count'] = $dbTotalCount;
801 $option['total_option_count'] = $dbTotalCount + $currentTotalCount;
802 }
803
804 //ignore option full for offline registration.
805 if ($className == 'CRM_Event_Form_Participant') {
806 $optionFullIds = [];
807 }
808
809 //finally get option ids in.
810 $field['option_full_ids'] = $optionFullIds;
811 }
812 $form->assign('optionFullTotalAmount', $optionFullTotalAmount);
813 }
814
815 /**
816 * Global form rule.
817 *
818 * @param array $fields
819 * The input form values.
820 * @param array $files
821 * The uploaded files if any.
822 * @param \CRM_Event_Form_Registration_Register $form
823 *
824 * @return bool|array
825 * true if no errors, else array of errors
826 *
827 * @throws \CRM_Core_Exception
828 */
829 public static function formRule($fields, $files, $form) {
830 $errors = [];
831 //check that either an email or firstname+lastname is included in the form(CRM-9587)
832 self::checkProfileComplete($fields, $errors, $form->_eventId);
833 //To check if the user is already registered for the event(CRM-2426)
834 if (!$form->_skipDupeRegistrationCheck) {
835 self::checkRegistration($fields, $form);
836 }
837 //check for availability of registrations.
838 if (!$form->_allowConfirmation && empty($fields['bypass_payment']) &&
839 is_numeric($form->_availableRegistrations) &&
840 CRM_Utils_Array::value('additional_participants', $fields) >= $form->_availableRegistrations
841 ) {
842 $errors['additional_participants'] = ts("There is only enough space left on this event for %1 participant(s).", [1 => $form->_availableRegistrations]);
843 }
844
845 // during confirmation don't allow to increase additional participants, CRM-4320
846 if ($form->_allowConfirmation && !empty($fields['additional_participants']) &&
847 is_array($form->_additionalParticipantIds) &&
848 $fields['additional_participants'] > count($form->_additionalParticipantIds)
849 ) {
850 $errors['additional_participants'] = ts("Oops. It looks like you are trying to increase the number of additional people you are registering for. You can confirm registration for a maximum of %1 additional people.", [1 => count($form->_additionalParticipantIds)]);
851 }
852
853 //don't allow to register w/ waiting if enough spaces available.
854 if (!empty($fields['bypass_payment']) && $form->_allowConfirmation) {
855 if (!is_numeric($form->_availableRegistrations) ||
856 (empty($fields['priceSetId']) && CRM_Utils_Array::value('additional_participants', $fields) < $form->_availableRegistrations)
857 ) {
858 $errors['bypass_payment'] = ts("Oops. There are enough available spaces in this event. You can not add yourself to the waiting list.");
859 }
860 }
861
862 if (!empty($fields['additional_participants']) &&
863 !CRM_Utils_Rule::positiveInteger($fields['additional_participants'])
864 ) {
865 $errors['additional_participants'] = ts('Please enter a whole number for Number of additional people.');
866 }
867
868 // priceset validations
869 if (!empty($fields['priceSetId']) &&
870 !$form->_requireApproval && !$form->_allowWaitlist
871 ) {
872 //format params.
873 $formatted = self::formatPriceSetParams($form, $fields);
874 $ppParams = [$formatted];
875 $priceSetErrors = self::validatePriceSet($form, $ppParams);
876 $primaryParticipantCount = self::getParticipantCount($form, $ppParams);
877
878 //get price set fields errors in.
879 $errors = array_merge($errors, CRM_Utils_Array::value(0, $priceSetErrors, []));
880
881 $totalParticipants = $primaryParticipantCount;
882 if (!empty($fields['additional_participants'])) {
883 $totalParticipants += $fields['additional_participants'];
884 }
885
886 if (empty($fields['bypass_payment']) &&
887 !$form->_allowConfirmation &&
888 is_numeric($form->_availableRegistrations) &&
889 $form->_availableRegistrations < $totalParticipants
890 ) {
891 $errors['_qf_default'] = ts("Only %1 Registrations available.", [1 => $form->_availableRegistrations]);
892 }
893
894 $lineItem = [];
895 CRM_Price_BAO_PriceSet::processAmount($form->_values['fee'], $fields, $lineItem);
896
897 $minAmt = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $fields['priceSetId'], 'min_amount');
898 if ($fields['amount'] < 0) {
899 $errors['_qf_default'] = ts('Event Fee(s) can not be less than zero. Please select the options accordingly');
900 }
901 elseif (!empty($minAmt) && $fields['amount'] < $minAmt) {
902 $errors['_qf_default'] = ts('A minimum amount of %1 should be selected from Event Fee(s).', [
903 1 => CRM_Utils_Money::format($minAmt),
904 ]);
905 }
906 }
907
908 // @todo - can we remove the 'is_monetary' concept?
909 if ($form->_values['event']['is_monetary']) {
910 if (empty($form->_requireApproval) && !empty($fields['amount']) && $fields['amount'] > 0 &&
911 !isset($fields['payment_processor_id'])) {
912 $errors['payment_processor_id'] = ts('Please select a Payment Method');
913 }
914
915 if (self::isZeroAmount($fields, $form)) {
916 return empty($errors) ? TRUE : $errors;
917 }
918
919 // also return if zero fees for valid members
920 if (!empty($fields['bypass_payment']) ||
921 (!$form->_allowConfirmation && ($form->_requireApproval || $form->_allowWaitlist))
922 ) {
923 return empty($errors) ? TRUE : $errors;
924 }
925 CRM_Core_Payment_Form::validatePaymentInstrument(
926 $fields['payment_processor_id'],
927 $fields,
928 $errors,
929 (!$form->_isBillingAddressRequiredForPayLater ? NULL : 'billing')
930 );
931 }
932
933 foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
934 if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
935 $customizedValue = CRM_Core_PseudoConstant::getKey('CRM_Contact_BAO_Contact', $greeting . '_id', 'Customized');
936 if ($customizedValue == $greetingType && empty($fields[$greeting . '_custom'])) {
937 $errors[$greeting . '_custom'] = ts('Custom %1 is a required field if %1 is of type Customized.',
938 [1 => ucwords(str_replace('_', ' ', $greeting))]
939 );
940 }
941 }
942 }
943 return empty($errors) ? TRUE : $errors;
944 }
945
946 /**
947 * Check if profiles are complete when event registration occurs(CRM-9587).
948 *
949 * @param array $fields
950 * @param array $errors
951 * @param int $eventId
952 */
953 public static function checkProfileComplete($fields, &$errors, $eventId) {
954 $email = '';
955 foreach ($fields as $fieldname => $fieldvalue) {
956 if (substr($fieldname, 0, 6) == 'email-' && $fieldvalue) {
957 $email = $fieldvalue;
958 }
959 }
960
961 if (!$email && !(!empty($fields['first_name']) && !empty($fields['last_name']))) {
962 $defaults = $params = ['id' => $eventId];
963 CRM_Event_BAO_Event::retrieve($params, $defaults);
964 $message = ts("Mandatory fields (first name and last name, OR email address) are missing from this form.");
965 $errors['_qf_default'] = $message;
966 }
967 }
968
969 /**
970 * Process the form submission.
971 */
972 public function postProcess() {
973 // get the submitted form values.
974 $params = $this->controller->exportValues($this->_name);
975
976 //set as Primary participant
977 $params['is_primary'] = 1;
978
979 if ($this->_values['event']['is_pay_later']
980 && (!array_key_exists('hidden_processor', $params) || $params['payment_processor_id'] == 0)
981 ) {
982 $params['is_pay_later'] = 1;
983 }
984 else {
985 $params['is_pay_later'] = 0;
986 }
987
988 $this->set('is_pay_later', $params['is_pay_later']);
989
990 // assign pay later stuff
991 $this->_params['is_pay_later'] = CRM_Utils_Array::value('is_pay_later', $params, FALSE);
992 $this->assign('is_pay_later', $params['is_pay_later']);
993 if ($params['is_pay_later']) {
994 $this->assign('pay_later_text', $this->_values['event']['pay_later_text']);
995 $this->assign('pay_later_receipt', $this->_values['event']['pay_later_receipt']);
996 }
997
998 if (!$this->_allowConfirmation) {
999 // check if the participant is already registered
1000 if (!$this->_skipDupeRegistrationCheck) {
1001 $params['contact_id'] = self::getRegistrationContactID($params, $this, FALSE);
1002 }
1003 }
1004
1005 if (!empty($params['image_URL'])) {
1006 CRM_Contact_BAO_Contact::processImageParams($params);
1007 }
1008
1009 //carry campaign to partcipants.
1010 if (array_key_exists('participant_campaign_id', $params)) {
1011 $params['campaign_id'] = $params['participant_campaign_id'];
1012 }
1013 else {
1014 $params['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values['event']);
1015 }
1016
1017 //hack to allow group to register w/ waiting
1018 $primaryParticipantCount = self::getParticipantCount($this, $params);
1019
1020 $totalParticipants = $primaryParticipantCount;
1021 if (!empty($params['additional_participants'])) {
1022 $totalParticipants += $params['additional_participants'];
1023 }
1024 if (!$this->_allowConfirmation && !empty($params['bypass_payment']) &&
1025 is_numeric($this->_availableRegistrations) &&
1026 $totalParticipants > $this->_availableRegistrations
1027 ) {
1028 $this->_allowWaitlist = TRUE;
1029 $this->set('allowWaitlist', TRUE);
1030 }
1031
1032 //carry participant id if pre-registered.
1033 if ($this->_allowConfirmation && $this->_participantId) {
1034 $params['participant_id'] = $this->_participantId;
1035 }
1036
1037 $params['defaultRole'] = 1;
1038 if (array_key_exists('participant_role', $params)) {
1039 $params['participant_role_id'] = $params['participant_role'];
1040 }
1041
1042 if (array_key_exists('participant_role_id', $params)) {
1043 $params['defaultRole'] = 0;
1044 }
1045 if (empty($params['participant_role_id']) &&
1046 $this->_values['event']['default_role_id']
1047 ) {
1048 $params['participant_role_id'] = $this->_values['event']['default_role_id'];
1049 }
1050
1051 $config = CRM_Core_Config::singleton();
1052 $params['currencyID'] = $config->defaultCurrency;
1053
1054 if ($this->_values['event']['is_monetary']) {
1055 // we first reset the confirm page so it accepts new values
1056 $this->controller->resetPage('Confirm');
1057
1058 //added for discount
1059 $discountId = CRM_Core_BAO_Discount::findSet($this->_eventId, 'civicrm_event');
1060 $params['amount_level'] = $this->getAmountLevel($params, $discountId);
1061 if (!empty($this->_values['discount'][$discountId])) {
1062 $params['discount_id'] = $discountId;
1063 $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
1064 }
1065 elseif (empty($params['priceSetId'])) {
1066 if (!empty($params['amount'])) {
1067 $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
1068 }
1069 else {
1070 $params['amount'] = '';
1071 }
1072 }
1073 else {
1074 $lineItem = [];
1075 CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem);
1076 if ($params['tax_amount']) {
1077 $this->set('tax_amount', $params['tax_amount']);
1078 }
1079 $submittedLineItems = $this->get('lineItem');
1080 if (!empty($submittedLineItems) && is_array($submittedLineItems)) {
1081 $submittedLineItems[0] = $lineItem;
1082 }
1083 else {
1084 $submittedLineItems = [$lineItem];
1085 }
1086 $submittedLineItems = array_filter($submittedLineItems);
1087 $this->set('lineItem', $submittedLineItems);
1088 $this->set('lineItemParticipantsCount', [$primaryParticipantCount]);
1089 }
1090
1091 $this->set('amount', $params['amount']);
1092 $this->set('amount_level', $params['amount_level']);
1093
1094 // generate and set an invoiceID for this transaction
1095 $invoiceID = md5(uniqid(rand(), TRUE));
1096 $this->set('invoiceID', $invoiceID);
1097
1098 if ($this->_paymentProcessor) {
1099 $payment = $this->_paymentProcessor['object'];
1100 $payment->setBaseReturnUrl('civicrm/event/register');
1101 }
1102
1103 // ContributeMode is a deprecated concept. It is short-hand for a bunch of
1104 // assumptions we are working to remove.
1105 $this->set('contributeMode', 'direct');
1106
1107 // This code is duplicated multiple places and should be consolidated.
1108 if (isset($params["state_province_id-{$this->_bltID}"]) &&
1109 $params["state_province_id-{$this->_bltID}"]
1110 ) {
1111 $params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($params["state_province_id-{$this->_bltID}"]);
1112 }
1113
1114 if (isset($params["country_id-{$this->_bltID}"]) &&
1115 $params["country_id-{$this->_bltID}"]
1116 ) {
1117 $params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($params["country_id-{$this->_bltID}"]);
1118 }
1119 if (isset($params['credit_card_exp_date'])) {
1120 $params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($params);
1121 $params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($params);
1122 }
1123 if ($this->_values['event']['is_monetary']) {
1124 $params['ip_address'] = CRM_Utils_System::ipAddress();
1125 $params['currencyID'] = $config->defaultCurrency;
1126 $params['invoiceID'] = $invoiceID;
1127 }
1128 $this->_params = $this->get('params');
1129 // Set the button so we know what
1130 $params['button'] = $this->controller->getButtonName();
1131 if (!empty($this->_params) && is_array($this->_params)) {
1132 $this->_params[0] = $params;
1133 }
1134 else {
1135 $this->_params = [];
1136 $this->_params[] = $params;
1137 }
1138 $this->set('params', $this->_params);
1139 if ($this->_paymentProcessor &&
1140 // Actually we don't really need to check if it supports pre-approval - we could just call
1141 // it regardless as the function we call re-acts tot the rests of the preApproval call.
1142 $this->_paymentProcessor['object']->supports('preApproval')
1143 && !$this->_allowWaitlist &&
1144 !$this->_requireApproval
1145 ) {
1146
1147 // The concept of contributeMode is deprecated - but still needs removal from the message templates.
1148 $this->set('contributeMode', 'express');
1149
1150 // Send Event Name & Id in Params
1151 $params['eventName'] = $this->_values['event']['title'];
1152 $params['eventId'] = $this->_values['event']['id'];
1153
1154 $params['cancelURL'] = CRM_Utils_System::url('civicrm/event/register',
1155 "_qf_Register_display=1&qfKey={$this->controller->_key}",
1156 TRUE, NULL, FALSE
1157 );
1158 if (!empty($params['additional_participants'])) {
1159 $urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}";
1160 }
1161 else {
1162 $urlArgs = "_qf_Confirm_display=1&rfp=1&qfKey={$this->controller->_key}";
1163 }
1164 $params['returnURL'] = CRM_Utils_System::url('civicrm/event/register',
1165 $urlArgs,
1166 TRUE, NULL, FALSE
1167 );
1168 $params['invoiceID'] = $invoiceID;
1169
1170 $params['component'] = 'event';
1171 $this->handlePreApproval($params);
1172 }
1173 elseif ($this->_paymentProcessor &&
1174 (int) $this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_NOTIFY
1175 ) {
1176 // The concept of contributeMode is deprecated - but still needs removal from the message templates.
1177 $this->set('contributeMode', 'notify');
1178 }
1179 }
1180 else {
1181 $params['description'] = ts('Online Event Registration') . ' ' . $this->_values['event']['title'];
1182
1183 $this->_params = [];
1184 $this->_params[] = $params;
1185 $this->set('params', $this->_params);
1186
1187 if (
1188 empty($params['additional_participants'])
1189 // CRM-11182 - Optional confirmation screen
1190 && !$this->_values['event']['is_confirm_enabled']
1191 ) {
1192 $this->processRegistration($this->_params);
1193 }
1194 }
1195
1196 // If registering > 1 participant, give status message
1197 if (!empty($params['additional_participants'])) {
1198 $statusMsg = ts('Registration information for participant 1 has been saved.');
1199 CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
1200 }
1201 }
1202
1203 /**
1204 * Method to check if the user is already registered for the event.
1205 * and if result found redirect to the event info page
1206 *
1207 * @param array $fields
1208 * The input form values(anonymous user).
1209 * @param CRM_Event_Form_Registration_Register $form
1210 * Event data.
1211 * @param bool $isAdditional
1212 * Treat isAdditional participants a bit differently.
1213 *
1214 * @return int
1215 */
1216 public static function checkRegistration($fields, $form, $isAdditional = FALSE) {
1217 // CRM-3907, skip check for preview registrations
1218 // CRM-4320 participant need to walk wizard
1219 if (
1220 ($form->_mode == 'test' || $form->_allowConfirmation)
1221 ) {
1222 return FALSE;
1223 }
1224
1225 $contactID = self::getRegistrationContactID($fields, $form, $isAdditional);
1226
1227 if ($contactID) {
1228 $participant = new CRM_Event_BAO_Participant();
1229 $participant->contact_id = $contactID;
1230 $participant->event_id = $form->_values['event']['id'];
1231 if (!empty($fields['participant_role']) && is_numeric($fields['participant_role'])) {
1232 $participant->role_id = $fields['participant_role'];
1233 }
1234 else {
1235 $participant->role_id = $form->_values['event']['default_role_id'];
1236 }
1237 $participant->is_test = 0;
1238 $participant->find();
1239 $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
1240 while ($participant->fetch()) {
1241 if (array_key_exists($participant->status_id, $statusTypes)) {
1242 if (!$isAdditional && !$form->_values['event']['allow_same_participant_emails']) {
1243 $registerUrl = CRM_Utils_System::url('civicrm/event/register',
1244 "reset=1&id={$form->_values['event']['id']}&cid=0"
1245 );
1246 if ($form->_pcpId) {
1247 $registerUrl .= '&pcpId=' . $form->_pcpId;
1248 }
1249
1250 $status = ts("It looks like you are already registered for this event. If you want to change your registration, or you feel that you've received this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', [1 => $registerUrl]);
1251 CRM_Core_Session::singleton()->setStatus($status, ts('Oops.'), 'alert');
1252 $url = CRM_Utils_System::url('civicrm/event/info',
1253 "reset=1&id={$form->_values['event']['id']}&noFullMsg=true"
1254 );
1255 if ($form->_action & CRM_Core_Action::PREVIEW) {
1256 $url .= '&action=preview';
1257 }
1258
1259 if ($form->_pcpId) {
1260 $url .= '&pcpId=' . $form->_pcpId;
1261 }
1262
1263 CRM_Utils_System::redirect($url);
1264 }
1265
1266 if ($isAdditional) {
1267 $status = ts("It looks like this participant is already registered for this event. If you want to change your registration, or you feel that you've received this message in error, please contact the site administrator.");
1268 CRM_Core_Session::singleton()->setStatus($status, ts('Oops.'), 'alert');
1269 return $participant->id;
1270 }
1271 }
1272 }
1273 }
1274 }
1275
1276 }