3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
38 * This class generates form components for processing Event
41 class CRM_Event_Form_Registration_Register
extends CRM_Event_Form_Registration
{
44 * The fields involved in this page
50 * The defaults involved in this page
56 * The status message that user view.
59 protected $_waitlistMsg = NULL;
60 protected $_requireApprovalMsg = NULL;
62 public $_quickConfig = NULL;
65 * Allow deveopera to use hook_civicrm_buildForm()
66 * to override the registration dupe check
69 public $_skipDupeRegistrationCheck = FALSE;
75 * Function to set variables up before form is built
80 function preProcess() {
83 CRM_Contribute_Form_Contribution_Main
::preProcessPaymentOptions($this);
84 if ($this->_snippet
) {
89 //here we can't use parent $this->_allowWaitlist as user might
90 //walk back and we maight set this value in this postProcess.
91 //(we set when spaces < group count and want to allow become part of waiting )
93 $eventFull = CRM_Event_BAO_Participant
::eventFull($this->_eventId
, FALSE, CRM_Utils_Array
::value('has_waitlist', $this->_values
['event']));
95 $this->_allowWaitlist
= FALSE;
96 if ($eventFull && !$this->_allowConfirmation
&&
97 CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
99 $this->_allowWaitlist
= TRUE;
100 $this->_waitlistMsg
= CRM_Utils_Array
::value('waitlist_text', $this->_values
['event']);
101 if (!$this->_waitlistMsg
) {
102 $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.');
105 $this->set('allowWaitlist', $this->_allowWaitlist
);
107 //To check if the user is already registered for the event(CRM-2426)
108 if (!$this->_skipDupeRegistrationCheck
) {
109 self
::checkRegistration(NULL, $this);
112 $this->assign('availableRegistrations', $this->_availableRegistrations
);
114 // get the participant values from EventFees.php, CRM-4320
115 if ($this->_allowConfirmation
) {
116 CRM_Event_Form_EventFees
::preProcess($this);
121 * This function sets the default values for the form. For edit/view mode
122 * the default values are retrieved from the database
123 * Adding discussion from CRM-11915 as code comments
124 * When multiple payment processors are configured for a event and user does any selection changes for them on online event registeration page :
125 * The 'Register' page gets loaded through ajax and following happens :
126 * the setDefaults function is called with the variable _ppType set with selected payment processor type,
127 * so in the 'if' condition checked whether the selected payment processor's billing mode is of 'billing form mode'. If its not, don't setDefaults for billing form and return instead.
128 *- For payment processors of billing mode 'Notify' - return from setDefaults before the code for billing profile population execution .
129 * (done this is because for payment processors with 'Notify' mode billing profile form doesn't get rendered on UI)
135 function setDefaultValues() {
136 if ($this->_ppType
&& $this->_snippet
&& !($this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_FORM
)) {
137 // see function comment block for explanation of this
141 $contactID = parent
::getContactID();
143 //@todo CRM-11915 I observed that even when the billing block is not present the routine to retrieve the billing defaults is still called - which seems a bit redundant.
145 'first_name', 'middle_name', 'last_name',
146 "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}",
147 "country_id-{$this->_bltID}", "state_province_id-{$this->_bltID}",
150 foreach ($names as $name) {
153 $fields["state_province-{$this->_bltID}"] = 1;
154 $fields["country-{$this->_bltID}"] = 1;
155 $fields["email-{$this->_bltID}"] = 1;
156 $fields['email-Primary'] = 1;
158 CRM_Core_BAO_UFGroup
::setProfileDefaults($contactID, $fields, $this->_defaults
);
160 // use primary email address if billing email address is empty
161 if (empty($this->_defaults
["email-{$this->_bltID}"]) &&
162 !empty($this->_defaults
['email-Primary'])
164 $this->_defaults
["email-{$this->_bltID}"] = $this->_defaults
['email-Primary'];
167 foreach ($names as $name) {
168 if (isset($this->_defaults
[$name])) {
169 $this->_defaults
['billing_' . $name] = $this->_defaults
[$name];
173 $config = CRM_Core_Config
::singleton();
174 // set default country from config if no country set
175 if (!CRM_Utils_Array
::value("billing_country_id-{$this->_bltID}", $this->_defaults
)) {
176 $this->_defaults
["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry
;
179 // now fix all state country selectors
180 CRM_Core_BAO_Address
::fixAllStateSelects($this, $this->_defaults
);
182 if ($this->_snippet
) {
183 return $this->_defaults
;
190 if (!empty($this->_fields
)) {
191 $removeCustomFieldTypes = array('Participant');
192 foreach ($this->_fields
as $name => $dontCare) {
193 if (substr($name, 0, 7) == 'custom_') {
194 $id = substr($name, 7);
195 if (!$this->_allowConfirmation
&&
196 !CRM_Core_BAO_CustomGroup
::checkCustomField($id, $removeCustomFieldTypes)
200 // ignore component fields
202 elseif ((substr($name, 0, 12) == 'participant_')) {
210 if (!empty($fields)) {
211 CRM_Core_BAO_UFGroup
::setProfileDefaults($contactID, $fields, $this->_defaults
);
214 // Set default payment processor as default payment_processor radio button value
215 if (!empty($this->_paymentProcessors
)) {
216 foreach ($this->_paymentProcessors
as $pid => $value) {
217 if (CRM_Utils_Array
::value('is_default', $value)) {
218 $this->_defaults
['payment_processor'] = $pid;
223 //if event is monetary and pay later is enabled and payment
224 //processor is not available then freeze the pay later checkbox with
226 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
['event']) &&
227 !is_array($this->_paymentProcessor
)
229 $this->_defaults
['is_pay_later'] = 1;
232 //set custom field defaults
233 if (!empty($this->_fields
)) {
234 //load default campaign from page.
235 if (array_key_exists('participant_campaign_id', $this->_fields
)) {
236 $this->_defaults
['participant_campaign_id'] = CRM_Utils_Array
::value('campaign_id',
237 $this->_values
['event']
241 foreach ($this->_fields
as $name => $field) {
242 if ($customFieldID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
244 if (!isset($this->_defaults
[$name])) {
245 CRM_Core_BAO_CustomField
::setProfileDefaults($customFieldID, $name, $this->_defaults
,
246 NULL, CRM_Profile_Form
::MODE_REGISTER
253 //fix for CRM-3088, default value for discount set.
255 if (!empty($this->_values
['discount'])) {
256 $discountId = CRM_Core_BAO_Discount
::findSet($this->_eventId
, 'civicrm_event');
258 if (isset($this->_values
['event']['default_discount_fee_id'])) {
259 $discountKey = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionValue',
260 $this->_values
['event']['default_discount_fee_id'],
264 $this->_defaults
['amount'] = key(array_slice($this->_values
['discount'][$discountId],
265 $discountKey - 1, $discountKey, TRUE
271 // add this event's default participant role to defaults array
272 // (for cases where participant_role field is included in form via profile)
273 if ($this->_values
['event']['default_role_id']) {
274 $this->_defaults
['participant_role'] =
275 $this->_defaults
['participant_role_id'] = $this->_values
['event']['default_role_id'];
277 if ($this->_priceSetId
&& !empty($this->_feeBlock
)) {
278 foreach ($this->_feeBlock
as $key => $val) {
279 foreach ($val['options'] as $keys => $values) {
280 if ($values['is_default'] &&
281 !CRM_Utils_Array
::value('is_full', $values)
284 if ($val['html_type'] == 'CheckBox') {
285 $this->_defaults
["price_{$key}"][$keys] = 1;
288 $this->_defaults
["price_{$key}"] = $keys;
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;
304 if ($this->_additionalParticipantIds
) {
305 $hasAdditionalParticipants = TRUE;
306 $this->_defaults
['additional_participants'] = count($this->_additionalParticipantIds
);
309 $this->assign('hasAdditionalParticipants', $hasAdditionalParticipants);
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' );
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);
323 return $this->_defaults
;
327 * Function to build the form
332 public function buildQuickForm() {
333 // Build payment processor form
334 if ($this->_ppType
) {
335 CRM_Core_Payment_ProcessorForm
::buildQuickForm($this);
336 // Return if we are in an ajax callback
337 if ($this->_snippet
) {
342 $contactID = parent
::getContactID();
343 $this->assign('contact_id', $contactID);
344 $this->assign('display_name', CRM_Contact_BAO_Contact
::displayName($contactID));
346 $config = CRM_Core_Config
::singleton();
347 $this->add('hidden', 'scriptFee', NULL);
348 $this->add('hidden', 'scriptArray', NULL);
350 $bypassPayment = $allowGroupOnWaitlist = $isAdditionalParticipants = FALSE;
351 if ($this->_values
['event']['is_multiple_registrations']) {
352 // don't allow to add additional during confirmation if not preregistered.
353 if (!$this->_allowConfirmation ||
$this->_additionalParticipantIds
) {
354 // Hardcode maximum number of additional participants here for now. May need to make this configurable per event.
355 // Label is value + 1, since the code sees this is ADDITIONAL participants (in addition to "self")
356 $additionalOptions = array('' => ts('1'), 1 => ts('2'), 2 => ts('3'), 3 => ts('4'), 4 => ts('5'),
357 5 => ts('6'), 6 => ts('7'), 7 => ts('8'), 8 => ts('9'), 9 => ts('10'),
359 $element = $this->add('select', 'additional_participants',
360 ts('How many people are you registering?'),
363 array('onChange' => "allowParticipant()")
365 $isAdditionalParticipants = TRUE;
369 //hack to allow group to register w/ waiting
370 if ((CRM_Utils_Array
::value('is_multiple_registrations', $this->_values
['event']) ||
373 !$this->_allowConfirmation
&&
374 is_numeric($this->_availableRegistrations
)
375 && CRM_Utils_Array
::value('has_waitlist', $this->_values
['event'])
377 $bypassPayment = TRUE;
378 //case might be group become as a part of waitlist.
379 //If not waitlist then they require admin approve.
380 $allowGroupOnWaitlist = TRUE;
381 $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.", array(1 => $this->_availableRegistrations
));
383 if ($this->_requireApproval
) {
384 $this->_requireApprovalMsg
= CRM_Utils_Array
::value('approval_req_text', $this->_values
['event'],
385 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 //case where only approval needed - no waitlist.
391 if ($this->_requireApproval
&&
392 !$this->_allowWaitlist
&& !$bypassPayment
394 $this->_requireApprovalMsg
= CRM_Utils_Array
::value('approval_req_text', $this->_values
['event'],
395 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.')
399 //lets display status to primary page only.
400 $this->assign('waitlistMsg', $this->_waitlistMsg
);
401 $this->assign('requireApprovalMsg', $this->_requireApprovalMsg
);
402 $this->assign('allowGroupOnWaitlist', $allowGroupOnWaitlist);
403 $this->assign('isAdditionalParticipants', $isAdditionalParticipants);
405 $this->buildCustom($this->_values
['custom_pre_id'], 'customPre');
406 $this->buildCustom($this->_values
['custom_post_id'], 'customPost');
408 //lets get js on two different qf elements.
409 $showHidePayfieldName = NULL;
410 $showHidePaymentInformation = FALSE;
411 if ($this->_values
['event']['is_monetary']) {
412 self
::buildAmount($this);
416 $this->_paymentProcessors
= $this->get('paymentProcessors');
417 if (!empty($this->_paymentProcessors
)) {
418 $pps = $this->_paymentProcessors
;
419 foreach ($pps as $key => & $name) {
420 $pps[$key] = $name['name'];
424 if (CRM_Utils_Array
::value('is_pay_later', $this->_values
['event']) &&
425 ($this->_allowConfirmation ||
(!$this->_requireApproval
&& !$this->_allowWaitlist
))
427 $pps[0] = $this->_values
['event']['pay_later_text'];
430 if ($this->_values
['event']['is_monetary']) {
431 if (count($pps) > 1) {
432 $this->addRadio('payment_processor', ts('Payment Method'), $pps,
436 elseif (!empty($pps)) {
437 $ppKeys = array_keys($pps);
438 $currentPP = array_pop($ppKeys);
439 $this->addElement('hidden', 'payment_processor', $currentPP);
443 //lets add some qf element to bypass payment validations, CRM-4320
444 if ($bypassPayment) {
445 $this->addElement('hidden', 'bypass_payment', NULL, array('id' => 'bypass_payment'));
447 $this->assign('bypassPayment', $bypassPayment);
448 $this->assign('showHidePaymentInformation', $showHidePaymentInformation);
450 $userID = parent
::getContactID();
453 $createCMSUser = FALSE;
455 if ($this->_values
['custom_pre_id']) {
456 $profileID = $this->_values
['custom_pre_id'];
457 $createCMSUser = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user');
460 if (!$createCMSUser &&
461 $this->_values
['custom_post_id']
463 if (!is_array($this->_values
['custom_post_id'])) {
464 $profileIDs = array($this->_values
['custom_post_id']);
467 $profileIDs = $this->_values
['custom_post_id'];
469 foreach ($profileIDs as $pid) {
470 if (CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) {
472 $createCMSUser = TRUE;
478 if ($createCMSUser) {
479 CRM_Core_BAO_CMSUser
::buildForm($this, $profileID, TRUE);
483 //we have to load confirm contribution button in template
484 //when multiple payment processor as the user
485 //can toggle with payment processor selection
486 $billingModePaymentProcessors = 0;
487 if (!CRM_Utils_System
::isNull($this->_paymentProcessors
)) {
488 foreach ($this->_paymentProcessors
as $key => $values) {
489 if ($values['billing_mode'] == CRM_Core_Payment
::BILLING_MODE_BUTTON
) {
490 $billingModePaymentProcessors++
;
495 if ($billingModePaymentProcessors && count($this->_paymentProcessors
) == $billingModePaymentProcessors) {
496 $allAreBillingModeProcessors = TRUE;
498 $allAreBillingModeProcessors = FALSE;
501 if (!$allAreBillingModeProcessors ||
502 CRM_Utils_Array
::value('is_pay_later', $this->_values
['event']) ||
$bypassPayment
505 //freeze button to avoid multiple calls.
508 if (!CRM_Utils_Array
::value('is_monetary', $this->_values
['event'])) {
509 $js = array('onclick' => "return submitOnce(this,'" . $this->_name
. "','" . ts('Processing') . "');");
511 $this->addButtons(array(
514 'name' => ts('Continue >>'),
515 'spacing' => ' ',
523 $this->addFormRule(array('CRM_Event_Form_Registration_Register', 'formRule'), $this);
527 CRM_PCP_BAO_PCP
::buildPcp($this->_pcpId
, $this);
532 * build the radio/text form elements for the amount field
534 * @param object $form form object
535 * @param boolean $required true if you want to add formRule
536 * @param int $discountId discount id for the event
542 static public function buildAmount(&$form, $required = TRUE, $discountId = NULL) {
543 //if payment done, no need to build the fee block.
544 if (!empty($form->_paymentId
)) {
545 //fix to diaplay line item in update mode.
546 $form->assign('priceSet', isset($form->_priceSet
) ?
$form->_priceSet
: NULL);
550 $feeFields = CRM_Utils_Array
::value('fee', $form->_values
);
552 if (is_array($feeFields)) {
553 $form->_feeBlock
= &$form->_values
['fee'];
556 //check for discount.
557 $discountedFee = CRM_Utils_Array
::value('discount', $form->_values
);
558 if (is_array($discountedFee) && !empty($discountedFee)) {
560 $form->_discountId
= $discountId = CRM_Core_BAO_Discount
::findSet($form->_eventId
, 'civicrm_event');
563 $form->_feeBlock
= &$form->_values
['discount'][$discountId];
566 if (!is_array($form->_feeBlock
)) {
567 $form->_feeBlock
= array();
570 //its time to call the hook.
571 CRM_Utils_Hook
::buildAmount('event', $form, $form->_feeBlock
);
573 //reset required if participant is skipped.
574 $button = substr($form->controller
->getButtonName(), -4);
575 if ($required && $button == 'skip') {
579 $className = CRM_Utils_System
::getClassName($form);
581 //build the priceset fields.
582 if (isset($form->_priceSetId
) && $form->_priceSetId
) {
584 //format price set fields across option full.
585 self
::formatFieldsForOptionFull($form);
587 if (CRM_Utils_Array
::value('is_quick_config', $form->_priceSet
)) {
588 $form->_quickConfig
= $form->_priceSet
['is_quick_config'];
590 $form->add('hidden', 'priceSetId', $form->_priceSetId
);
592 foreach ($form->_feeBlock
as $field) {
593 if (CRM_Utils_Array
::value('visibility', $field) == 'public' ||
594 $className == 'CRM_Event_Form_Participant'
596 $fieldId = $field['id'];
597 $elementName = 'price_' . $fieldId;
599 $isRequire = CRM_Utils_Array
::value('is_required', $field);
600 if ($button == 'skip') {
604 //user might modified w/ hook.
605 $options = CRM_Utils_Array
::value('options', $field);
606 if (!is_array($options)) {
610 $optionFullIds = CRM_Utils_Array
::value('option_full_ids', $field, array());
612 //soft suppress required rule when option is full.
613 if (!empty($optionFullIds) && (count($options) == count($optionFullIds))) {
618 CRM_Price_BAO_Field
::addQuickFormElement($form,
629 $form->assign('priceSet', $form->_priceSet
);
632 $eventFeeBlockValues = array();
633 foreach ($form->_feeBlock
as $fee) {
634 if (is_array($fee)) {
637 $totalAmountJs = NULL;
638 if ($className == 'CRM_Event_Form_Participant') {
639 $totalAmountJs = array('onClick' => "fillTotalAmount(" . $fee['value'] . ")");
642 $eventFeeBlockValues['amount_id_' . $fee['amount_id']] = $fee['value'];
643 $elements[] = &$form->createElement('radio', NULL, '',
644 CRM_Utils_Money
::format($fee['value']) . ' ' .
651 $form->assign('eventFeeBlockValues', json_encode($eventFeeBlockValues));
653 $form->_defaults
['amount'] = CRM_Utils_Array
::value('default_fee_id', $form->_values
['event']);
654 $element = &$form->addGroup($elements, 'amount', ts('Event Fee(s)'), '<br />');
655 if (isset($form->_online
) && $form->_online
) {
659 $form->addRule('amount', ts('Fee Level is a required field.'), 'required');
664 public static function formatFieldsForOptionFull(&$form) {
665 $priceSet = $form->get('priceSet');
666 $priceSetId = $form->get('priceSetId');
668 !is_array($priceSet) ||
670 !CRM_Utils_Array
::value('optionsMaxValueTotal', $priceSet)
675 $skipParticipants = $formattedPriceSetDefaults = array();
676 if ($form->_allowConfirmation
&& (isset($form->_pId
) ||
isset($form->_additionalParticipantId
))) {
677 $participantId = isset($form->_pId
) ?
$form->_pId
: $form->_additionalParticipantId
;
678 $pricesetDefaults = CRM_Event_Form_EventFees
::setDefaultPriceSet($participantId,
681 // modify options full to respect the selected fields
682 // options on confirmation.
683 $formattedPriceSetDefaults = self
::formatPriceSetParams($form, $pricesetDefaultOptions);
685 // to skip current registered participants fields option count on confirmation.
686 $skipParticipants[] = $form->_participantId
;
687 if (!empty($form->_additionalParticipantIds
)) {
688 $skipParticipants = array_merge($skipParticipants, $form->_additionalParticipantIds
);
692 $className = CRM_Utils_System
::getClassName($form);
694 //get the current price event price set options count.
695 $currentOptionsCount = self
::getPriceSetOptionCount($form);
696 $recordedOptionsCount = CRM_Event_BAO_Participant
::priceSetOptionsCount($form->_eventId
, $skipParticipants);
698 foreach ($form->_feeBlock
as & $field) {
699 $optionFullIds = array();
700 $fieldId = $field['id'];
701 if (!is_array($field['options'])) {
704 foreach ($field['options'] as & $option) {
705 $optId = $option['id'];
706 $count = CRM_Utils_Array
::value('count', $option, 0);
707 $maxValue = CRM_Utils_Array
::value('max_value', $option, 0);
708 $dbTotalCount = CRM_Utils_Array
::value($optId, $recordedOptionsCount, 0);
709 $currentTotalCount = CRM_Utils_Array
::value($optId, $currentOptionsCount, 0);
711 // Do not consider current count for select field,
712 // since we are not going to freeze the options.
713 if ($field['html_type'] == 'Select') {
714 $totalCount = $dbTotalCount;
717 $totalCount = $currentTotalCount +
$dbTotalCount;
722 (($totalCount >= $maxValue) ||
($totalCount +
$count > $maxValue))
725 $optionFullIds[$optId] = $optId;
728 //here option is not full,
729 //but we don't want to allow participant to increase
730 //seats at the time of re-walking registration.
732 $form->_allowConfirmation
&&
733 !empty($formattedPriceSetDefaults)
735 if (!CRM_Utils_Array
::value("price_{$field}", $formattedPriceSetDefaults) ||
736 !CRM_Utils_Array
::value($opId, $formattedPriceSetDefaults["price_{$fieldId}"])
738 $optionFullIds[$optId] = $optId;
742 $option['is_full'] = $isFull;
743 $option['db_total_count'] = $dbTotalCount;
744 $option['total_option_count'] = $dbTotalCount +
$currentTotalCount;
747 //ignore option full for offline registration.
748 if ($className == 'CRM_Event_Form_Participant') {
749 $optionFullIds = array();
752 //finally get option ids in.
753 $field['option_full_ids'] = $optionFullIds;
760 * @param array $fields the input form values
761 * @param array $files the uploaded files if any
762 * @param array $options additional user data
764 * @return true if no errors, else array of errors
768 static function formRule($fields, $files, $self) {
770 //check that either an email or firstname+lastname is included in the form(CRM-9587)
771 self
::checkProfileComplete($fields, $errors, $self->_eventId
);
772 //To check if the user is already registered for the event(CRM-2426)
773 if (!$self->_skipDupeRegistrationCheck
) {
774 self
::checkRegistration($fields, $self);
776 //check for availability of registrations.
777 if (!$self->_allowConfirmation
&&
778 !CRM_Utils_Array
::value('bypass_payment', $fields) &&
779 is_numeric($self->_availableRegistrations
) &&
780 CRM_Utils_Array
::value('additional_participants', $fields) >= $self->_availableRegistrations
782 $errors['additional_participants'] = ts("There is only enough space left on this event for %1 participant(s).", array(1 => $self->_availableRegistrations
));
785 // during confirmation don't allow to increase additional participants, CRM-4320
786 if ($self->_allowConfirmation
&&
787 CRM_Utils_Array
::value('additional_participants', $fields) &&
788 is_array($self->_additionalParticipantIds
) &&
789 $fields['additional_participants'] > count($self->_additionalParticipantIds
)
791 $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.", array(1 => count($self->_additionalParticipantIds
)));
794 //don't allow to register w/ waiting if enough spaces available.
795 if (CRM_Utils_Array
::value('bypass_payment', $fields)) {
796 if (!is_numeric($self->_availableRegistrations
) ||
797 (!CRM_Utils_Array
::value('priceSetId', $fields) && CRM_Utils_Array
::value('additional_participants', $fields) < $self->_availableRegistrations
)
799 $errors['bypass_payment'] = ts("Oops. There are enough available spaces in this event. You can not add yourself to the waiting list.");
803 if (CRM_Utils_Array
::value('additional_participants', $fields) &&
804 !CRM_Utils_Rule
::positiveInteger($fields['additional_participants'])
806 $errors['additional_participants'] = ts('Please enter a whole number for Number of additional people.');
809 // priceset validations
810 if (CRM_Utils_Array
::value('priceSetId', $fields)) {
812 $formatted = self
::formatPriceSetParams($self, $fields);
813 $ppParams = array($formatted);
814 $priceSetErrors = self
::validatePriceSet($self, $ppParams);
815 $primaryParticipantCount = self
::getParticipantCount($self, $ppParams);
817 //get price set fields errors in.
818 $errors = array_merge($errors, CRM_Utils_Array
::value(0, $priceSetErrors, array()));
820 $totalParticipants = $primaryParticipantCount;
821 if (CRM_Utils_Array
::value('additional_participants', $fields)) {
822 $totalParticipants +
= $fields['additional_participants'];
825 if (!CRM_Utils_Array
::value('bypass_payment', $fields) &&
826 !$self->_allowConfirmation
&&
827 is_numeric($self->_availableRegistrations
) &&
828 $self->_availableRegistrations
< $totalParticipants
830 $errors['_qf_default'] = ts("Only %1 Registrations available.", array(1 => $self->_availableRegistrations
));
834 CRM_Price_BAO_Set
::processAmount($self->_values
['fee'], $fields, $lineItem);
835 if ($fields['amount'] < 0) {
836 $errors['_qf_default'] = ts('Event Fee(s) can not be less than zero. Please select the options accordingly');
840 if ($self->_values
['event']['is_monetary']) {
841 if (is_array($self->_paymentProcessor
)) {
842 $payment = CRM_Core_Payment
::singleton($self->_mode
, $self->_paymentProcessor
, $this);
843 $error = $payment->checkConfig($self->_mode
);
845 $errors['_qf_default'] = $error;
848 // return if this is express mode
849 $config = CRM_Core_Config
::singleton();
850 if ($self->_paymentProcessor
&&
851 $self->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_BUTTON
853 if (CRM_Utils_Array
::value($self->_expressButtonName
. '_x', $fields) ||
854 CRM_Utils_Array
::value($self->_expressButtonName
. '_y', $fields) ||
855 CRM_Utils_Array
::value($self->_expressButtonName
, $fields)
857 return empty($errors) ?
TRUE : $errors;
861 $isZeroAmount = $skipPayementValidation = FALSE;
862 if (CRM_Utils_Array
::value('priceSetId', $fields)) {
863 if (CRM_Utils_Array
::value('amount', $fields) == 0) {
864 $isZeroAmount = TRUE;
867 elseif (CRM_Utils_Array
::value('amount', $fields) &&
868 (isset($self->_values
['discount'][$fields['amount']])
869 && CRM_Utils_Array
::value('value', $self->_values
['discount'][$fields['amount']]) == 0
872 $isZeroAmount = TRUE;
874 elseif (CRM_Utils_Array
::value('amount', $fields) &&
875 (isset($self->_values
['fee'][$fields['amount']])
876 && CRM_Utils_Array
::value('value', $self->_values
['fee'][$fields['amount']]) == 0
879 $isZeroAmount = TRUE;
882 if ($isZeroAmount && !($self->_forcePayement
&& CRM_Utils_Array
::value('additional_participants', $fields))) {
883 $skipPayementValidation = TRUE;
886 // also return if paylater mode or zero fees for valid members
887 if (CRM_Utils_Array
::value('is_pay_later', $fields) ||
888 CRM_Utils_Array
::value('bypass_payment', $fields) ||
889 $skipPayementValidation ||
890 (!$self->_allowConfirmation
&& ($self->_requireApproval ||
$self->_allowWaitlist
))
892 return empty($errors) ?
TRUE : $errors;
894 if (!empty($self->_paymentFields
)) {
895 CRM_Core_Form
::validateMandatoryFields($self->_paymentFields
, $fields, $errors);
897 CRM_Core_Payment_Form
::validateCreditCard($fields, $errors);
900 foreach (CRM_Contact_BAO_Contact
::$_greetingTypes as $greeting) {
901 if ($greetingType = CRM_Utils_Array
::value($greeting, $fields)) {
902 $customizedValue = CRM_Core_OptionGroup
::getValue($greeting, 'Customized', 'name');
903 if ($customizedValue == $greetingType && empty($fields[$greeting . '_custom'])) {
904 $errors[$customizedGreeting] = ts('Custom %1 is a required field if %1 is of type Customized.',
905 array(1 => ucwords(str_replace('_', ' ', $greeting)))
910 return empty($errors) ?
TRUE : $errors;
914 * Check if profiles are complete when event registration occurs(CRM-9587)
917 static function checkProfileComplete($fields, &$errors, $eventId) {
919 foreach ($fields as $fieldname => $fieldvalue) {
920 if (substr($fieldname, 0, 6) == 'email-' && $fieldvalue) {
921 $email = $fieldvalue;
925 if (!$email && !(CRM_Utils_Array
::value('first_name', $fields) &&
926 CRM_Utils_Array
::value('last_name', $fields)
928 $defaults = $params = array('id' => $eventId);
929 CRM_Event_BAO_Event
::retrieve($params, $defaults);
930 $message = ts("Mandatory fields (first name and last name, OR email address) are missing from this form.");
931 $errors['_qf_default'] = $message;
936 * Function to process the form
942 public function postProcess() {
943 // get the submitted form values.
944 $params = $this->controller
->exportValues($this->_name
);
946 //set as Primary participant
947 $params['is_primary'] = 1;
949 if ($this->_values
['event']['is_pay_later'] && !array_key_exists('hidden_processor', $params)) {
950 $params['is_pay_later'] = 1;
953 $params['is_pay_later'] = 0;
956 $this->set('is_pay_later', $params['is_pay_later']);
958 // assign pay later stuff
959 $this->_params
['is_pay_later'] = CRM_Utils_Array
::value('is_pay_later', $params, FALSE);
960 $this->assign('is_pay_later', $params['is_pay_later']);
961 if ($params['is_pay_later']) {
962 $this->assign('pay_later_text', $this->_values
['event']['pay_later_text']);
963 $this->assign('pay_later_receipt', $this->_values
['event']['pay_later_receipt']);
966 if (!$this->_allowConfirmation
) {
967 // check if the participant is already registered
968 if (!$this->_skipDupeRegistrationCheck
) {
969 $params['contact_id'] = self
::checkRegistration($params, $this, FALSE, TRUE, TRUE);
973 if (CRM_Utils_Array
::value('image_URL', $params)) {
974 CRM_Contact_BAO_Contact
::processImageParams($params);
977 //carry campaign to partcipants.
978 if (array_key_exists('participant_campaign_id', $params)) {
979 $params['campaign_id'] = $params['participant_campaign_id'];
982 $params['campaign_id'] = CRM_Utils_Array
::value('campaign_id', $this->_values
['event']);
985 //hack to allow group to register w/ waiting
986 $primaryParticipantCount = self
::getParticipantCount($this, $params);
988 $totalParticipants = $primaryParticipantCount;
989 if (CRM_Utils_Array
::value('additional_participants', $params)) {
990 $totalParticipants +
= $params['additional_participants'];
992 if (!$this->_allowConfirmation
&&
993 CRM_Utils_Array
::value('bypass_payment', $params) &&
994 is_numeric($this->_availableRegistrations
) &&
995 $totalParticipants > $this->_availableRegistrations
997 $this->_allowWaitlist
= TRUE;
998 $this->set('allowWaitlist', TRUE);
1001 //carry participant id if pre-registered.
1002 if ($this->_allowConfirmation
&& $this->_participantId
) {
1003 $params['participant_id'] = $this->_participantId
;
1006 $params['defaultRole'] = 1;
1007 if (array_key_exists('participant_role', $params)) {
1008 $params['participant_role_id'] = $params['participant_role'];
1011 if (array_key_exists('participant_role_id', $params)) {
1012 $params['defaultRole'] = 0;
1014 if (!CRM_Utils_Array
::value('participant_role_id', $params) &&
1015 $this->_values
['event']['default_role_id']
1017 $params['participant_role_id'] = $this->_values
['event']['default_role_id'];
1020 $config = CRM_Core_Config
::singleton();
1021 $params['currencyID'] = $config->defaultCurrency
;
1023 if ($this->_values
['event']['is_monetary']) {
1024 // we first reset the confirm page so it accepts new values
1025 $this->controller
->resetPage('Confirm');
1027 //added for discount
1028 $discountId = CRM_Core_BAO_Discount
::findSet($this->_eventId
, 'civicrm_event');
1030 if (!empty($this->_values
['discount'][$discountId])) {
1031 $params['discount_id'] = $discountId;
1032 $params['amount_level'] = $this->_values
['discount'][$discountId][$params['amount']]['label'];
1034 $params['amount'] = $this->_values
['discount'][$discountId][$params['amount']]['value'];
1036 elseif (empty($params['priceSetId'])) {
1037 $params['amount_level'] = $this->_values
['fee'][$params['amount']]['label'];
1038 $params['amount'] = $this->_values
['fee'][$params['amount']]['value'];
1041 $lineItem = array();
1042 CRM_Price_BAO_Set
::processAmount($this->_values
['fee'], $params, $lineItem);
1043 $this->set('lineItem', array($lineItem));
1044 $this->set('lineItemParticipantsCount', array($primaryParticipantCount));
1047 $this->set('amount', $params['amount']);
1048 $this->set('amount_level', $params['amount_level']);
1050 // generate and set an invoiceID for this transaction
1051 $invoiceID = md5(uniqid(rand(), TRUE));
1052 $this->set('invoiceID', $invoiceID);
1054 if (is_array($this->_paymentProcessor
)) {
1055 $payment = CRM_Core_Payment
::singleton($this->_mode
, $this->_paymentProcessor
, $this);
1057 // default mode is direct
1058 $this->set('contributeMode', 'direct');
1060 if (isset($params["state_province_id-{$this->_bltID}"]) &&
1061 $params["state_province_id-{$this->_bltID}"]
1063 $params["state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant
::stateProvinceAbbreviation($params["state_province_id-{$this->_bltID}"]);
1066 if (isset($params["country_id-{$this->_bltID}"]) &&
1067 $params["country_id-{$this->_bltID}"]
1069 $params["country-{$this->_bltID}"] = CRM_Core_PseudoConstant
::countryIsoCode($params["country_id-{$this->_bltID}"]);
1071 if (isset($params['credit_card_exp_date'])) {
1072 $params['year'] = CRM_Core_Payment_Form
::getCreditCardExpirationYear($params);
1073 $params['month'] = CRM_Core_Payment_Form
::getCreditCardExpirationMonth($params);
1075 if ($this->_values
['event']['is_monetary']) {
1076 $params['ip_address'] = CRM_Utils_System
::ipAddress();
1077 $params['currencyID'] = $config->defaultCurrency
;
1078 $params['payment_action'] = 'Sale';
1079 $params['invoiceID'] = $invoiceID;
1082 $this->_params
= array();
1083 $this->_params
[] = $params;
1084 $this->set('params', $this->_params
);
1086 if ($this->_paymentProcessor
&&
1087 $this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_BUTTON
1089 //get the button name
1090 $buttonName = $this->controller
->getButtonName();
1091 if (in_array($buttonName,
1093 $this->_expressButtonName
,
1094 $this->_expressButtonName
. '_x',
1095 $this->_expressButtonName
. '_y',
1098 !CRM_Utils_Array
::value('is_pay_later', $params) &&
1099 !$this->_allowWaitlist
&&
1100 !$this->_requireApproval
1102 $this->set('contributeMode', 'express');
1104 // Send Event Name & Id in Params
1105 $params['eventName'] = $this->_values
['event']['title'];
1106 $params['eventId'] = $this->_values
['event']['id'];
1108 $params['cancelURL'] = CRM_Utils_System
::url('civicrm/event/register',
1109 "_qf_Register_display=1&qfKey={$this->controller->_key}",
1112 if (CRM_Utils_Array
::value('additional_participants', $params, FALSE)) {
1113 $urlArgs = "_qf_Participant_1_display=1&rfp=1&qfKey={$this->controller->_key}";
1116 $urlArgs = "_qf_Confirm_display=1&rfp=1&qfKey={$this->controller->_key}";
1118 $params['returnURL'] = CRM_Utils_System
::url('civicrm/event/register',
1122 $params['invoiceID'] = $invoiceID;
1124 //default action is Sale
1125 $params['payment_action'] = 'Sale';
1127 $token = $payment->setExpressCheckout($params);
1128 if (is_a($token, 'CRM_Core_Error')) {
1129 CRM_Core_Error
::displaySessionError($token);
1130 CRM_Utils_System
::redirect($params['cancelURL']);
1133 $this->set('token', $token);
1135 $paymentURL = $this->_paymentProcessor
['url_site'] . "/cgi-bin/webscr?cmd=_express-checkout&token=$token";
1137 CRM_Utils_System
::redirect($paymentURL);
1140 elseif ($this->_paymentProcessor
&&
1141 $this->_paymentProcessor
['billing_mode'] & CRM_Core_Payment
::BILLING_MODE_NOTIFY
1143 $this->set('contributeMode', 'notify');
1147 $session = CRM_Core_Session
::singleton();
1148 $params['description'] = ts('Online Event Registration') . ' ' . $this->_values
['event']['title'];
1150 $this->_params
= array();
1151 $this->_params
[] = $params;
1152 $this->set('params', $this->_params
);
1154 if (!CRM_Utils_Array
::value('additional_participants', $params)) {
1155 self
::processRegistration($this->_params
);
1159 // If registering > 1 participant, give status message
1160 if (CRM_Utils_Array
::value('additional_participants', $params, FALSE)) {
1161 $statusMsg = ts('Registration information for participant 1 has been saved.');
1162 CRM_Core_Session
::setStatus($statusMsg, ts('Saved'), 'success');
1168 * Function to process Registration of free event
1170 * @param array $param Form valuess
1171 * @param int contactID
1177 public function processRegistration($params, $contactID = NULL) {
1178 $session = CRM_Core_Session
::singleton();
1179 $this->_participantInfo
= array();
1181 // CRM-4320, lets build array of cancelled additional participant ids
1182 // those are drop or skip by primary at the time of confirmation.
1183 // get all in and then unset those are confirmed.
1184 $cancelledIds = $this->_additionalParticipantIds
;
1186 $participantCount = array();
1187 foreach ($params as $participantNum => $record) {
1188 if ($record == 'skip') {
1189 $participantCount[$participantNum] = 'skip';
1191 elseif ($participantNum) {
1192 $participantCount[$participantNum] = 'participant';
1196 $registerByID = NULL;
1197 foreach ($params as $key => $value) {
1198 if ($value != 'skip') {
1201 // setting register by Id and unset contactId.
1202 if (!CRM_Utils_Array
::value('is_primary', $value)) {
1204 $registerByID = $this->get('registerByID');
1205 if ($registerByID) {
1206 $value['registered_by_id'] = $registerByID;
1208 // get an email if one exists for the participant
1209 $participantEmail = '';
1210 foreach (array_keys($value) as $valueName) {
1211 if (substr($valueName, 0, 6) == 'email-') {
1212 $participantEmail = $value[$valueName];
1215 if ($participantEmail) {
1216 $this->_participantInfo
[] = $participantEmail;
1219 $this->_participantInfo
[] = $value['first_name'] . ' ' . $value['last_name'];
1222 elseif (CRM_Utils_Array
::value('contact_id', $value)) {
1223 $contactID = $value['contact_id'];
1226 $contactID = parent
::getContactID();
1229 CRM_Event_Form_Registration_Confirm
::fixLocationFields($value, $fields);
1230 //for free event or additional participant, dont create billing email address.
1231 if (!CRM_Utils_Array
::value('is_primary', $value) ||
!$this->_values
['event']['is_monetary']) {
1232 unset($value["email-{$this->_bltID}"]);
1235 $contactID = CRM_Event_Form_Registration_Confirm
::updateContactFields($contactID, $value, $fields);
1237 // lets store the contactID in the session
1238 // we dont store in userID in case the user is doing multiple
1240 // for things like tell a friend
1241 if (!parent
::getContactID() && CRM_Utils_Array
::value('is_primary', $value)) {
1242 $session->set('transaction.userID', $contactID);
1245 //lets get the status if require approval or waiting.
1247 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
1248 if ($this->_allowWaitlist
&& !$this->_allowConfirmation
) {
1249 $value['participant_status_id'] = $value['participant_status'] = array_search('On waitlist', $waitingStatuses);
1251 elseif ($this->_requireApproval
&& !$this->_allowConfirmation
) {
1252 $value['participant_status_id'] = $value['participant_status'] = array_search('Awaiting approval', $waitingStatuses);
1255 $this->set('value', $value);
1256 $this->confirmPostProcess($contactID, NULL, NULL);
1258 //lets get additional participant id to cancel.
1259 if ($this->_allowConfirmation
&& is_array($cancelledIds)) {
1260 $additonalId = CRM_Utils_Array
::value('participant_id', $value);
1261 if ($additonalId && $key = array_search($additonalId, $cancelledIds)) {
1262 unset($cancelledIds[$key]);
1268 // update status and send mail to cancelled additonal participants, CRM-4320
1269 if ($this->_allowConfirmation
&& is_array($cancelledIds) && !empty($cancelledIds)) {
1270 $cancelledId = array_search('Cancelled',
1271 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'")
1273 CRM_Event_BAO_Participant
::transitionParticipants($cancelledIds, $cancelledId);
1276 //set information about additional participants if exists
1277 if (count($this->_participantInfo
)) {
1278 $this->set('participantInfo', $this->_participantInfo
);
1281 //send mail Confirmation/Receipt
1282 if ($this->_contributeMode
!= 'checkout' ||
1283 $this->_contributeMode
!= 'notify'
1286 if ($this->_action
& CRM_Core_Action
::PREVIEW
) {
1290 //handle if no additional participant.
1291 if (!$registerByID) {
1292 $registerByID = $this->get('registerByID');
1294 $primaryContactId = $this->get('primaryContactId');
1296 //build an array of custom profile and assigning it to template.
1297 $additionalIDs = CRM_Event_BAO_Event
::buildCustomProfile($registerByID, NULL,
1298 $primaryContactId, $isTest, TRUE
1301 //lets carry all paticipant params w/ values.
1302 foreach ($additionalIDs as $participantID => $contactId) {
1303 $participantNum = NULL;
1304 if ($participantID == $registerByID) {
1305 $participantNum = 0;
1308 if ($participantNum = array_search('participant', $participantCount)) {
1309 unset($participantCount[$participantNum]);
1313 if ($participantNum === NULL) {
1317 //carry the participant submitted values.
1318 $this->_values
['params'][$participantID] = $params[$participantNum];
1321 //lets send mails to all with meanigful text, CRM-4320.
1322 $this->assign('isOnWaitlist', $this->_allowWaitlist
);
1323 $this->assign('isRequireApproval', $this->_requireApproval
);
1325 foreach ($additionalIDs as $participantID => $contactId) {
1326 if ($participantID == $registerByID) {
1327 //set as Primary Participant
1328 $this->assign('isPrimary', 1);
1330 $customProfile = CRM_Event_BAO_Event
::buildCustomProfile($participantID, $this->_values
, NULL, $isTest);
1332 if (count($customProfile)) {
1333 $this->assign('customProfile', $customProfile);
1334 $this->set('customProfile', $customProfile);
1338 $this->assign('isPrimary', 0);
1339 $this->assign('customProfile', NULL);
1342 //send Confirmation mail to Primary & additional Participants if exists
1343 CRM_Event_BAO_Event
::sendMail($contactId, $this->_values
, $participantID, $isTest);
1349 * Method to check if the user is already registered for the event
1350 * and if result found redirect to the event info page
1352 * @param array $fields the input form values(anonymous user)
1353 * @param array $self event data
1354 * @param boolean $isAdditional treat isAdditional participants a bit differently
1355 * @param boolean $returnContactId just find and return the contactID match to use
1356 * @param boolean $useDedupeRules force usage of dedupe rules
1361 static function checkRegistration($fields, &$self, $isAdditional = FALSE, $returnContactId = FALSE, $useDedupeRules = FALSE) {
1362 // CRM-3907, skip check for preview registrations
1363 // CRM-4320 participant need to walk wizard
1364 if (!$returnContactId &&
1365 ($self->_mode
== 'test' ||
$self->_allowConfirmation
)
1371 $session = CRM_Core_Session
::singleton();
1372 if (!$isAdditional) {
1373 $contactID = parent
::getContactID();
1376 if (!$contactID && is_array($fields) && $fields) {
1379 //as we are allowing w/ same email address,
1380 //lets check w/ other contact params.
1381 if ($self->_values
['event']['allow_same_participant_emails']) {
1383 $level = ($isAdditional) ?
'Supervised' : 'Unsupervised';
1385 $dedupeParams = CRM_Dedupe_Finder
::formatParams($params, 'Individual');
1387 // disable permission based on cache since event registration is public page/feature.
1388 $dedupeParams['check_permission'] = FALSE;
1389 $ids = CRM_Dedupe_Finder
::dupesByParams($dedupeParams, 'Individual', $level);
1390 $contactID = CRM_Utils_Array
::value(0, $ids);
1393 foreach ($fields as $fieldname => $fieldvalue) {
1394 if (substr($fieldname, 0, 6) == 'email-') {
1395 $emailString = trim($fieldvalue);
1396 if (!empty($emailString)) {
1397 $match = CRM_Contact_BAO_Contact
::matchContactOnEmail($emailString, 'Individual');
1398 if (!empty($match)) {
1399 $contactID = $match->contact_id
;
1407 if ($returnContactId) {
1409 // return contactID if contact already exists
1414 $participant = new CRM_Event_BAO_Participant();
1415 $participant->contact_id
= $contactID;
1416 $participant->event_id
= $self->_values
['event']['id'];
1417 if (!empty($fields['participant_role']) && is_numeric($fields['participant_role'])) {
1418 $participant->role_id
= $fields['participant_role'];
1421 $participant->role_id
= $self->_values
['event']['default_role_id'];
1423 $participant->is_test
= 0;
1424 $participant->find();
1425 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
1426 while ($participant->fetch()) {
1427 if (array_key_exists($participant->status_id
, $statusTypes)) {
1428 if (!$isAdditional && !$self->_values
['event']['allow_same_participant_emails']) {
1429 $registerUrl = CRM_Utils_System
::url('civicrm/event/register',
1430 "reset=1&id={$self->_values['event']['id']}&cid=0"
1432 if ($self->_pcpId
) {
1433 $registerUrl .= '&pcpId=' . $self->_pcpId
;
1436 $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 gotten this message in error, please contact the site administrator.") . ' ' . ts('You can also <a href="%1">register another participant</a>.', array(1 => $registerUrl));
1437 $session->setStatus($status, ts('Oops.'), 'alert');
1438 $url = CRM_Utils_System
::url('civicrm/event/info',
1439 "reset=1&id={$self->_values['event']['id']}&noFullMsg=true"
1441 if ($self->_action
& CRM_Core_Action
::PREVIEW
) {
1442 $url .= '&action=preview';
1445 if ($self->_pcpId
) {
1446 $url .= '&pcpId=' . $self->_pcpId
;
1449 CRM_Utils_System
::redirect($url);
1452 if ($isAdditional) {
1453 $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 gotten this message in error, please contact the site administrator.");
1454 $session->setStatus($status, ts('Oops.'), 'alert');
1455 return $participant->id
;