3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * This class generates form components for processing Event.
20 class CRM_Event_Form_ManageEvent_Registration
extends CRM_Event_Form_ManageEvent
{
23 * What blocks should we show and hide.
25 * @var CRM_Core_ShowHideBlocks
29 protected $_profilePostMultiple = [];
30 protected $_profilePostMultipleAdd = [];
33 * Set variables up before form is built.
35 public function preProcess() {
36 $this->_addProfileBottom
= CRM_Utils_Array
::value('addProfileBottom', $_GET, FALSE);
37 $this->_profileBottomNum
= CRM_Utils_Array
::value('addProfileNum', $_GET, 0);
38 $this->_addProfileBottomAdd
= CRM_Utils_Array
::value('addProfileBottomAdd', $_GET, FALSE);
39 $this->_profileBottomNumAdd
= CRM_Utils_Array
::value('addProfileNumAdd', $_GET, 0);
42 $this->setSelectedChild('registration');
44 $this->assign('addProfileBottom', $this->_addProfileBottom
);
45 $this->assign('profileBottomNum', $this->_profileBottomNum
);
47 $urlParams = "id={$this->_id}&addProfileBottom=1&qfKey={$this->controller->_key}";
48 $this->assign('addProfileParams', $urlParams);
50 if ($addProfileBottom = CRM_Utils_Array
::value('custom_post_id_multiple', $_POST)) {
51 foreach (array_keys($addProfileBottom) as $profileNum) {
52 self
::buildMultipleProfileBottom($this, $profileNum);
56 $this->assign('addProfileBottomAdd', $this->_addProfileBottomAdd
);
57 $this->assign('profileBottomNumAdd', $this->_profileBottomNumAdd
);
59 $urlParamsAdd = "id={$this->_id}&addProfileBottomAdd=1&qfKey={$this->controller->_key}";
60 $this->assign('addProfileParamsAdd', $urlParamsAdd);
62 if ($addProfileBottomAdd = CRM_Utils_Array
::value('additional_custom_post_id_multiple', $_POST)) {
63 foreach (array_keys($addProfileBottomAdd) as $profileNum) {
64 self
::buildMultipleProfileBottom($this, $profileNum, 'additional_', ts('Profile for Additional Participants'));
70 * Set default values for the form.
72 * The default values are retrieved from the database.
74 public function setDefaultValues() {
75 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
78 $eventId = $this->_id
;
80 $defaults = parent
::setDefaultValues();
82 $this->setShowHide($defaults);
83 if (isset($eventId)) {
84 $params = ['id' => $eventId];
85 CRM_Event_BAO_Event
::retrieve($params, $defaults);
88 'entity_table' => 'civicrm_event',
89 'module' => 'CiviEvent',
90 'entity_id' => $eventId,
93 list($defaults['custom_pre_id'],
94 $defaults['custom_post']
95 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
97 // Get the id for the event registration profile
98 $eventRegistrationIdParams = $eventRegistrationIdDefaults = [
99 'name' => 'event_registration',
101 CRM_Core_BAO_UFGroup
::retrieve($eventRegistrationIdParams, $eventRegistrationIdDefaults);
103 // Set event registration as the default profile if none selected
104 if (!$defaults['custom_pre_id'] && count($defaults['custom_post']) == 0) {
105 $defaults['custom_pre_id'] = $eventRegistrationIdDefaults['id'] ??
NULL;
107 if (isset($defaults['custom_post']) && is_numeric($defaults['custom_post'])) {
108 $defaults['custom_post_id'] = $defaults['custom_post'];
110 elseif (!empty($defaults['custom_post'])) {
111 $defaults['custom_post_id'] = $defaults['custom_post'][0];
112 unset($defaults['custom_post'][0]);
113 $this->_profilePostMultiple
= $defaults['custom_post'];
114 foreach ($defaults['custom_post'] as $key => $value) {
115 self
::buildMultipleProfileBottom($this, $key);
116 $defaults["custom_post_id_multiple[$key]"] = $value;
120 $this->assign('profilePostMultiple', CRM_Utils_Array
::value('custom_post', $defaults));
122 // CRM-17745: Make max additional participants configurable
123 if (empty($defaults['max_additional_participants'])) {
124 $defaults['max_additional_participants'] = 9;
127 if (!empty($defaults['is_multiple_registrations'])) {
128 // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
130 'entity_table' => 'civicrm_event',
131 'module' => 'CiviEvent_Additional',
132 'entity_id' => $eventId,
135 list($defaults['additional_custom_pre_id'],
136 $defaults['additional_custom_post']
137 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinAddParams);
139 if (isset($defaults['additional_custom_post']) && is_numeric($defaults['additional_custom_post'])) {
140 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'];
142 elseif (!empty($defaults['additional_custom_post'])) {
143 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'][0];
144 unset($defaults['additional_custom_post'][0]);
146 $this->_profilePostMultipleAdd
= $defaults['additional_custom_post'];
147 foreach ($defaults['additional_custom_post'] as $key => $value) {
148 self
::buildMultipleProfileBottom($this, $key, 'additional_', ts('Profile for Additional Participants'));
149 $defaults["additional_custom_post_id_multiple[$key]"] = $value;
152 $this->assign('profilePostMultipleAdd', CRM_Utils_Array
::value('additional_custom_post', $defaults, []));
155 // Avoid PHP notices in the template
156 $this->assign('profilePostMultipleAdd', []);
160 $defaults['is_email_confirm'] = 0;
163 // provide defaults for required fields if empty (and as a 'hint' for approval message field)
164 $defaults['registration_link_text'] = CRM_Utils_Array
::value('registration_link_text', $defaults, ts('Register Now'));
165 $defaults['confirm_title'] = CRM_Utils_Array
::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
166 $defaults['thankyou_title'] = CRM_Utils_Array
::value('thankyou_title', $defaults, ts('Thank You for Registering'));
167 $defaults['approval_req_text'] = CRM_Utils_Array
::value('approval_req_text', $defaults, ts('Participation in this event requires approval. Submit your registration request here. Once approved, you will receive an email with a link to a web page where you can complete the registration process.'));
173 * Fix what blocks to show/hide based on the default values set
175 * @param array $defaults
176 * The array of default values.
180 public function setShowHide($defaults) {
181 $this->_showHide
= new CRM_Core_ShowHideBlocks(['registration' => 1],
184 if (empty($defaults)) {
185 $this->_showHide
->addHide('registration');
186 $this->_showHide
->addHide('id-approval-text');
189 if (empty($defaults['requires_approval'])) {
190 $this->_showHide
->addHide('id-approval-text');
193 $this->assign('defaultsEmpty', empty($defaults));
194 $this->_showHide
->addToTemplate();
198 * Build the form object.
202 public function buildQuickForm() {
203 if ($this->_addProfileBottom
) {
204 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNum
);
207 if ($this->_addProfileBottomAdd
) {
208 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNumAdd
, 'additional_', ts('Profile for Additional Participants'));
211 $this->applyFilter('__ALL__', 'trim');
212 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
214 $this->addElement('checkbox',
215 'is_online_registration',
216 ts('Allow Online Registration'),
219 'onclick' => "return showHideByValue('is_online_registration'," .
221 "'registration_blocks'," .
228 $this->add('text', 'registration_link_text', ts('Registration Link Text'));
230 if (!$this->_isTemplate
) {
231 $this->add('datepicker', 'registration_start_date', ts('Registration Start Date'), [], FALSE, ['time' => TRUE]);
232 $this->add('datepicker', 'registration_end_date', ts('Registration End Date'), [], FALSE, ['time' => TRUE]);
236 'used' => 'Supervised',
237 'contact_type' => 'Individual',
239 $dedupeRuleFields = CRM_Dedupe_BAO_DedupeRule
::dedupeRuleFields($params);
241 foreach ($dedupeRuleFields as $key => $fields) {
242 $ruleFields[$key] = ucwords(str_replace('_', ' ', $fields));
245 $this->addElement('checkbox',
246 'is_multiple_registrations',
247 ts('Register multiple participants?')
250 // CRM-17745: Make maximum additional participants configurable
251 $numericOptions = CRM_Core_SelectValues
::getNumericOptions(1, 9);
252 $this->add('select', 'max_additional_participants', ts('Maximum additional participants'), $numericOptions, FALSE, ['class' => 'required']);
254 $this->addElement('checkbox',
255 'allow_same_participant_emails',
256 ts('Same email address?')
258 $this->assign('ruleFields', json_encode($ruleFields));
261 '' => ts('- Unsupervised rule -'),
263 $dedupeRules +
= CRM_Dedupe_BAO_DedupeRuleGroup
::getByType('Individual');
264 $this->add('select', 'dedupe_rule_group_id', ts('Duplicate matching rule'), $dedupeRules);
266 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
267 if (in_array('Awaiting approval', $participantStatuses) and in_array('Pending from approval', $participantStatuses) and in_array('Rejected', $participantStatuses)) {
268 $this->addElement('checkbox',
270 ts('Require participant approval?'),
272 ['onclick' => "return showHideByValue('requires_approval', '', 'id-approval-text', 'table-row', 'radio', false);"]
274 $this->add('textarea', 'approval_req_text', ts('Approval message'), $attributes['approval_req_text']);
277 $this->add('text', 'expiration_time', ts('Pending participant expiration (hours)'));
278 $this->addRule('expiration_time', ts('Please enter the number of hours (as an integer).'), 'integer');
279 $this->addField('allow_selfcancelxfer', ['label' => ts('Allow self-service cancellation or transfer?'), 'type' => 'advcheckbox']);
280 $this->add('text', 'selfcancelxfer_time', ts('Cancellation or transfer time limit (hours)'));
281 $this->addRule('selfcancelxfer_time', ts('Please enter the number of hours (as an integer).'), 'integer');
282 self
::buildRegistrationBlock($this);
283 self
::buildConfirmationBlock($this);
284 self
::buildMailBlock($this);
285 self
::buildThankYouBlock($this);
287 parent
::buildQuickForm();
291 * Build Registration Block.
293 * @param CRM_Core_Form $form
296 public function buildRegistrationBlock(&$form) {
297 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'intro_text') +
['class' => 'collapsed', 'preset' => 'civievent'];
298 $form->add('wysiwyg', 'intro_text', ts('Introductory Text'), $attributes);
299 $form->add('wysiwyg', 'footer_text', ts('Footer Text'), $attributes);
301 extract(self
::getProfileSelectorTypes());
303 $form->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
304 $form->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
306 $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
307 $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
311 * Subroutine to insert a Profile Editor widget.
312 * depends on getProfileSelectorTypes
314 * @param \CRM_Core_Form &$form
317 * @param string $prefix
318 * Dom element ID prefix.
319 * @param string $label
321 * @param array $configs
322 * Optional, for addProfileSelector(), defaults to using getProfileSelectorTypes().
324 public static function buildMultipleProfileBottom(&$form, $count, $prefix = '', $label = 'Include Profile', $configs = NULL) {
325 extract((is_null($configs)) ? self
::getProfileSelectorTypes() : $configs);
326 $element = $prefix . "custom_post_id_multiple[$count]";
327 $label .= '<br />' . ts('(bottom of page)');
328 $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
332 * Create initializers for addprofileSelector.
335 * ['allowCoreTypes' => array, 'allowSubTypes' => array, 'profileEntities' => array]
337 public static function getProfileSelectorTypes() {
339 'allowCoreTypes' => [],
340 'allowSubTypes' => [],
341 'profileEntities' => [],
345 $configs['allowCoreTypes'] = array_merge([
348 ], CRM_Contact_BAO_ContactType
::subTypes('Individual'));
349 $configs['allowCoreTypes'][] = 'Participant';
350 if (CRM_Core_Permission
::check('manage event profiles') && !CRM_Core_Permission
::check('administer CiviCRM')) {
351 $configs['usedFor'][] = 'CiviEvent';
354 $id = CRM_Utils_Request
::retrieve('id', 'Integer');
356 $participantEventType = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Event", $id, 'event_type_id', 'id');
357 $participantRole = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'default_role_id');
358 $configs['allowSubTypes']['ParticipantEventName'] = [$id];
359 $configs['allowSubTypes']['ParticipantEventType'] = [$participantEventType];
360 $configs['allowSubTypes']['ParticipantRole'] = [$participantRole];
362 $configs['profileEntities'][] = ['entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'];
363 $configs['profileEntities'][] = [
364 'entity_name' => 'participant_1',
365 'entity_type' => 'ParticipantModel',
366 'entity_sub_type' => '*',
373 * Build Confirmation Block.
375 * @param CRM_Core_Form $form
378 public function buildConfirmationBlock(&$form) {
379 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
380 // CRM-11182 - Optional confirmation page for free events
381 $is_monetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $form->_id
, 'is_monetary');
382 $form->assign('is_monetary', $is_monetary);
383 if ($is_monetary == "0") {
384 $form->addYesNo('is_confirm_enabled', ts('Use a confirmation screen?'), NULL, NULL, ['onclick' => "return showHideByValue('is_confirm_enabled','','confirm_screen_settings','block','radio',false);"]);
386 $form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']);
387 $form->add('wysiwyg', 'confirm_text', ts('Introductory Text'), $attributes['confirm_text'] +
['class' => 'collapsed', 'preset' => 'civievent']);
388 $form->add('wysiwyg', 'confirm_footer_text', ts('Footer Text'), $attributes['confirm_text'] +
['class' => 'collapsed', 'preset' => 'civievent']);
394 * @param CRM_Core_Form $form
396 public function buildMailBlock(&$form) {
397 $form->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
398 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
399 $form->addYesNo('is_email_confirm', ts('Send Confirmation Email?'), NULL, NULL, ['onclick' => "return showHideByValue('is_email_confirm','','confirmEmail','block','radio',false);"]);
400 $form->add('textarea', 'confirm_email_text', ts('Text'), $attributes['confirm_email_text']);
401 $form->add('text', 'cc_confirm', ts('CC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'cc_confirm'));
402 $form->addRule('cc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
403 $form->add('text', 'bcc_confirm', ts('BCC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'bcc_confirm'));
404 $form->addRule('bcc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
405 $form->add('text', 'confirm_from_name', ts('Confirm From Name'));
406 $form->add('text', 'confirm_from_email', ts('Confirm From Email'));
407 $form->addRule('confirm_from_email', ts('Email is not valid.'), 'email');
411 * @param CRM_Core_Form $form
413 public function buildThankYouBlock(&$form) {
414 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
415 $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']);
416 $form->add('wysiwyg', 'thankyou_text', ts('Introductory Text'), $attributes['thankyou_text'] +
['class' => 'collapsed', 'preset' => 'civievent']);
417 $form->add('wysiwyg', 'thankyou_footer_text', ts('Footer Text'), $attributes['thankyou_text'] +
['class' => 'collapsed', 'preset' => 'civievent']);
421 * Add local and global form rules.
425 public function addRules() {
426 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
429 $this->addFormRule(['CRM_Event_Form_ManageEvent_Registration', 'formRule'], $this);
433 * Global validation rules for the form.
435 * @param array $values
437 * @param CRM_Core_Form $form
440 * list of errors to be posted back to the form
442 public static function formRule($values, $files, $form) {
443 if (!empty($values['is_online_registration'])) {
445 if (!$values['confirm_title']) {
446 $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page');
448 if (!$values['thankyou_title']) {
449 $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page');
451 if ($values['is_email_confirm']) {
452 if (!$values['confirm_from_name']) {
453 $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.');
456 if (!$values['confirm_from_email']) {
457 $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.');
461 if (isset($values['registration_start_date']) && isset($values['registration_end_date'])) {
462 if ($values['registration_end_date'] < $values['registration_start_date']) {
463 $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date');
467 //check that the selected profiles have either firstname+lastname or email required
469 CRM_Utils_Array
::value('custom_pre_id', $values),
470 CRM_Utils_Array
::value('custom_post_id', $values),
472 $additionalProfileIds = [
473 CRM_Utils_Array
::value('additional_custom_pre_id', $values),
474 CRM_Utils_Array
::value('additional_custom_post_id', $values),
476 //additional profile fields default to main if not set
477 if (!is_numeric($additionalProfileIds[0])) {
478 $additionalProfileIds[0] = $profileIds[0];
480 if (!is_numeric($additionalProfileIds[1])) {
481 $additionalProfileIds[1] = $profileIds[1];
483 //add multiple profiles if set
484 self
::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple');
485 self
::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple');
486 $isProfileComplete = self
::isProfileComplete($profileIds);
487 $isAdditionalProfileComplete = self
::isProfileComplete($additionalProfileIds);
489 //Check main profiles have an email address available if 'send confirmation email' is selected
490 if ($values['is_email_confirm']) {
491 $emailFields = self
::getEmailFields($profileIds);
492 if (!count($emailFields)) {
493 $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected");
496 $additionalCustomPreId = $additionalCustomPostId = NULL;
497 $isPreError = $isPostError = TRUE;
498 if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) {
499 $types = array_merge(['Individual'], CRM_Contact_BAO_ContactType
::subTypes('Individual'));
500 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
502 //check for additional custom pre profile
503 $additionalCustomPreId = $values['additional_custom_pre_id'] ??
NULL;
504 if (!empty($additionalCustomPreId)) {
505 if (!($additionalCustomPreId == 'none')) {
506 $customPreId = $additionalCustomPreId;
513 $customPreId = !empty($values['custom_pre_id']) ?
$values['custom_pre_id'] : NULL;
515 //check whether the additional custom pre profile is of type 'Individual' and its subtypes
516 if (!empty($customPreId)) {
517 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPreId);
518 foreach ($types as $individualTypes) {
519 if (in_array($individualTypes, $profileTypes)) {
529 // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile
531 $additionalCustomPostId = $values['additional_custom_post_id'] ??
NULL;
532 if (!empty($additionalCustomPostId)) {
533 if (!($additionalCustomPostId == 'none')) {
534 $customPostId = $additionalCustomPostId;
537 $isPostError = FALSE;
541 $customPostId = !empty($values['custom_post_id']) ?
$values['custom_post_id'] : NULL;
543 //check whether the additional custom post profile is of type 'Individual' and its subtypes
544 if (!empty($customPostId)) {
545 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPostId);
546 foreach ($types as $individualTypes) {
547 if (in_array($individualTypes, $profileTypes)) {
548 $isPostError = FALSE;
554 $isPostError = FALSE;
557 if (empty($customPreId) && empty($customPostId)) {
558 $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
561 $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
565 if (!$isProfileComplete) {
566 $errorMsg['custom_pre_id'] = ts("Please include a Profile for online registration that contains an Email Address field and / or First Name + Last Name fields.");
568 if (!$isAdditionalProfileComplete) {
569 $errorMsg['additional_custom_pre_id'] = ts("Please include a Profile for online registration of additional participants that contains an Email Address field and / or First Name + Last Name fields.");
573 // $config = CRM_Core_Config::singleton();
574 // if ( $config->doNotAttachPDFReceipt ) {
575 // if (!empty($values['custom_post_id_multiple'])) {
576 // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) {
577 // if ( $customPostMultiple ) {
578 // $errorMsg["custom_post_id_multiple[{$count}]"] = ts('Please disable PDF receipt as an attachment in <a href="%1">Miscellaneous Settings</a> if you want to add additional profiles.', array( 1 => CRM_Utils_System::url( 'civicrm/admin/setting/misc', 'reset=1' ) ) );
584 // if (!empty($values['is_multiple_registrations']) &&
585 // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) {
586 // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) {
587 // if ( $customPostMultiple ) {
588 // $errorMsg["additional_custom_post_id_multiple[{$count}]"] = ts('Please disable PDF receipt as an attachment in <a href="%1">Miscellaneous Settings</a> if you want to add additional profiles.', array( 1 => CRM_Utils_System::url( 'civicrm/admin/setting/misc', 'reset=1' ) ) );
595 if (!empty($errorMsg)) {
596 if (!empty($values['custom_post_id_multiple'])) {
597 foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) {
598 self
::buildMultipleProfileBottom($form, $count);
600 $form->assign('profilePostMultiple', $values['custom_post_id_multiple']);
602 if (!empty($values['additional_custom_post_id_multiple'])) {
603 foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) {
604 self
::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants'));
606 $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']);
611 if (!empty($errorMsg)) {
619 * Collect all email fields for an array of profile ids.
624 public static function getEmailFields($profileIds) {
626 foreach ($profileIds as $profileId) {
627 if ($profileId && is_numeric($profileId)) {
628 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
629 foreach ($fields as $field) {
630 if (substr_count($field['name'], 'email')) {
631 $emailFields[] = $field;
640 * Check if a profile contains required fields.
645 public static function isProfileComplete($profileIds) {
646 $profileReqFields = [];
647 foreach ($profileIds as $profileId) {
648 if ($profileId && is_numeric($profileId)) {
649 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
650 foreach ($fields as $field) {
652 case substr_count($field['name'], 'email'):
653 $profileReqFields[] = 'email';
656 case substr_count($field['name'], 'first_name'):
657 $profileReqFields[] = 'first_name';
660 case substr_count($field['name'], 'last_name'):
661 $profileReqFields[] = 'last_name';
667 $profileComplete = (in_array('email', $profileReqFields)
668 ||
(in_array('first_name', $profileReqFields) && in_array('last_name', $profileReqFields))
670 return $profileComplete;
674 * Check if the profiles collect enough information to dedupe.
680 public static function canProfilesDedupe($profileIds, $rgId = 0) {
681 // find the unsupervised rule
683 'used' => 'Unsupervised',
684 'contact_type' => 'Individual',
687 $rgParams['id'] = $rgId;
689 $activeRg = CRM_Dedupe_BAO_DedupeRuleGroup
::dedupeRuleFieldsWeight($rgParams);
691 // get the combinations that could be a match for the rule
692 $okCombos = $combos = [];
693 CRM_Dedupe_BAO_DedupeRuleGroup
::combos($activeRg[0], $activeRg[1], $combos);
695 // create an index of what combinations involve each field
697 foreach ($combos as $comboid => $combo) {
698 foreach ($combo as $cfield) {
699 $index[$cfield][$comboid] = TRUE;
701 $combos[$comboid] = array_fill_keys($combo, 0);
702 $okCombos[$comboid] = array_fill_keys($combo, 2);
705 // get profiles and see if they have the necessary combos
706 $profileReqFields = [];
707 foreach ($profileIds as $profileId) {
708 if ($profileId && is_numeric($profileId)) {
709 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
711 // walk through the fields in the profile
712 foreach ($fields as $field) {
714 // check each of the fields in the index against the profile field
715 foreach ($index as $ifield => $icombos) {
716 if (strpos($field['name'], $ifield) !== FALSE) {
718 // we found the field in the profile, now record it in the index
719 foreach ($icombos as $icombo => $dontcare) {
720 $combos[$icombo][$ifield] = ($combos[$icombo][$ifield] != 2 && !$field['is_required']) ?
1 : 2;
722 if ($combos[$icombo] == $okCombos[$icombo]) {
723 // if any combo is complete with 2s (all fields are present and required), we can go home
733 // check the combos to see if everything is > 0
734 foreach ($combos as $comboid => $combo) {
736 foreach ($combo as $cfield) {
741 // this combo isn't complete--skip to the next combo
750 // no combo succeeded
755 * Add additional profiles from the form to an array of profile ids.
757 * @param array $profileIds
758 * @param array $values
759 * @param string $field
761 public static function addMultipleProfiles(&$profileIds, $values, $field) {
762 if ($multipleProfiles = CRM_Utils_Array
::value($field, $values)) {
763 foreach ($multipleProfiles as $profileId) {
764 $profileIds[] = $profileId;
770 * Process the form submission.
774 public function postProcess() {
775 $params = $this->exportValues();
777 $params['id'] = $this->_id
;
780 $params['is_online_registration'] = CRM_Utils_Array
::value('is_online_registration', $params, FALSE);
782 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE);
783 $params['is_multiple_registrations'] = CRM_Utils_Array
::value('is_multiple_registrations', $params, FALSE);
784 $params['allow_same_participant_emails'] = CRM_Utils_Array
::value('allow_same_participant_emails', $params, FALSE);
785 $params['requires_approval'] = CRM_Utils_Array
::value('requires_approval', $params, FALSE);
787 // reset is_email confirm if not online reg
788 if (!$params['is_online_registration']) {
789 $params['is_email_confirm'] = FALSE;
791 if (!empty($params['allow_selfcancelxfer'])) {
792 $params['selfcancelxfer_time'] = !empty($params['selfcancelxfer_time']) ?
$params['selfcancelxfer_time'] : 0;
795 CRM_Event_BAO_Event
::add($params);
797 // also update the ProfileModule tables
800 'module' => 'CiviEvent',
801 'entity_table' => 'civicrm_event',
802 'entity_id' => $this->_id
,
805 // first delete all past entries
806 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
810 if (!empty($params['custom_pre_id'])) {
811 $uf[1] = $params['custom_pre_id'];
815 if (!empty($params['custom_post_id'])) {
816 $uf[2] = $params['custom_post_id'];
819 if (!empty($params['custom_post_id_multiple'])) {
820 $uf = array_merge($uf, $params['custom_post_id_multiple']);
822 $uf = array_values($uf);
824 foreach ($uf as $weight => $ufGroupId) {
825 $ufJoinParams['weight'] = $weight +
$wt;
826 $ufJoinParams['uf_group_id'] = $ufGroupId;
827 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
828 unset($ufJoinParams['id']);
831 // also update the ProfileModule tables
834 'module' => 'CiviEvent_Additional',
835 'entity_table' => 'civicrm_event',
836 'entity_id' => $this->_id
,
839 // first delete all past entries
840 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParamsAdd);
841 if (!empty($params['is_multiple_registrations'])) {
845 if (array_key_exists('additional_custom_pre_id', $params)) {
846 if (empty($params['additional_custom_pre_id'])) {
847 $ufAdd[1] = $params['custom_pre_id'];
850 elseif (CRM_Utils_Array
::value('additional_custom_pre_id', $params) == 'none') {
853 $ufAdd[1] = $params['additional_custom_pre_id'];
858 if (array_key_exists('additional_custom_post_id', $params)) {
859 if (empty($params['additional_custom_post_id'])) {
860 $ufAdd[2] = $params['custom_post_id'];
862 elseif (CRM_Utils_Array
::value('additional_custom_post_id', $params) == 'none') {
865 $ufAdd[2] = $params['additional_custom_post_id'];
869 if (!empty($params['additional_custom_post_id_multiple'])) {
870 $additionalPostMultiple = [];
871 foreach ($params['additional_custom_post_id_multiple'] as $key => $value) {
872 if (is_null($value) && !empty($params['custom_post_id'])) {
873 $additionalPostMultiple[$key] = $params['custom_post_id'];
875 elseif ($value == 'none') {
879 $additionalPostMultiple[$key] = $value;
882 $ufAdd = array_merge($ufAdd, $additionalPostMultiple);
885 $ufAdd = array_values($ufAdd);
886 if (!empty($ufAdd)) {
887 foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) {
889 $ufJoinParamsAdd['weight'] = $weightAdd +
$wtAdd;
890 $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd;
892 CRM_Core_BAO_UFJoin
::create($ufJoinParamsAdd);
893 unset($ufJoinParamsAdd['id']);
898 // get the profiles to evaluate what they collect
900 CRM_Utils_Array
::value('custom_pre_id', $params),
901 CRM_Utils_Array
::value('custom_post_id', $params),
903 $additionalProfileIds = [
904 CRM_Utils_Array
::value('additional_custom_pre_id', $params),
905 CRM_Utils_Array
::value('additional_custom_post_id', $params),
907 // additional profile fields default to main if not set
908 if (!is_numeric($additionalProfileIds[0])) {
909 $additionalProfileIds[0] = $profileIds[0];
911 if (!is_numeric($additionalProfileIds[1])) {
912 $additionalProfileIds[1] = $profileIds[1];
914 //add multiple profiles if set
915 self
::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple');
916 self
::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple');
919 $rgId = CRM_Utils_Array
::value('dedupe_rule_group_id', $params, 0);
921 switch (self
::canProfilesDedupe($profileIds, $rgId)) {
923 $dedupeTitle = 'Duplicate Matching Impossible';
924 $cantDedupe = ts("The selected profiles do not contain the fields necessary to match registrations with existing contacts. This means all anonymous registrations will result in a new contact.");
928 $dedupeTitle = 'Duplicate Contacts Possible';
929 $cantDedupe = ts("The selected profiles can collect enough information to match registrations with existing contacts, but not all of the relevant fields are required. Anonymous registrations may result in duplicate contacts.");
931 if (!empty($params['is_multiple_registrations'])) {
932 switch (self
::canProfilesDedupe($additionalProfileIds, $rgId)) {
934 $dedupeTitle = 'Duplicate Matching Impossible';
936 $cantDedupe = ts("The selected profiles do not contain the fields necessary to match registrations with existing contacts. This means all anonymous registrations will result in a new contact.");
939 $cantDedupe = ts("The selected profiles do not contain the fields necessary to match additional participants with existing contacts. This means all additional participants will result in a new contact.");
945 $dedupeTitle = 'Duplicate Contacts Possible';
946 $cantDedupe = ts("The selected profiles can collect enough information to match additional participants with existing contacts, but not all of the relevant fields are required. This may result in duplicate contacts.");
951 CRM_Core_Session
::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', ['expires' => 0]);
954 // Update tab "disabled" css class
955 $this->ajaxResponse
['tabValid'] = !empty($params['is_online_registration']);
957 parent
::endPostProcess();
961 * Return a descriptive name for the page, used in wizard header
965 public function getTitle() {
966 return ts('Online Registration');