3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2019
34 * This class generates form components for processing Event.
36 class CRM_Event_Form_ManageEvent_Registration
extends CRM_Event_Form_ManageEvent
{
39 * What blocks should we show and hide.
41 * @var CRM_Core_ShowHideBlocks
45 protected $_profilePostMultiple = [];
46 protected $_profilePostMultipleAdd = [];
49 * Set variables up before form is built.
51 public function preProcess() {
52 $this->_addProfileBottom
= CRM_Utils_Array
::value('addProfileBottom', $_GET, FALSE);
53 $this->_profileBottomNum
= CRM_Utils_Array
::value('addProfileNum', $_GET, 0);
54 $this->_addProfileBottomAdd
= CRM_Utils_Array
::value('addProfileBottomAdd', $_GET, FALSE);
55 $this->_profileBottomNumAdd
= CRM_Utils_Array
::value('addProfileNumAdd', $_GET, 0);
58 $this->assign('selectedChild', 'registration');
60 $this->assign('addProfileBottom', $this->_addProfileBottom
);
61 $this->assign('profileBottomNum', $this->_profileBottomNum
);
63 $urlParams = "id={$this->_id}&addProfileBottom=1&qfKey={$this->controller->_key}";
64 $this->assign('addProfileParams', $urlParams);
66 if ($addProfileBottom = CRM_Utils_Array
::value('custom_post_id_multiple', $_POST)) {
67 foreach (array_keys($addProfileBottom) as $profileNum) {
68 self
::buildMultipleProfileBottom($this, $profileNum);
72 $this->assign('addProfileBottomAdd', $this->_addProfileBottomAdd
);
73 $this->assign('profileBottomNumAdd', $this->_profileBottomNumAdd
);
75 $urlParamsAdd = "id={$this->_id}&addProfileBottomAdd=1&qfKey={$this->controller->_key}";
76 $this->assign('addProfileParamsAdd', $urlParamsAdd);
78 if ($addProfileBottomAdd = CRM_Utils_Array
::value('additional_custom_post_id_multiple', $_POST)) {
79 foreach (array_keys($addProfileBottomAdd) as $profileNum) {
80 self
::buildMultipleProfileBottom($this, $profileNum, 'additional_', ts('Profile for Additional Participants'));
86 * Set default values for the form.
88 * The default values are retrieved from the database.
90 public function setDefaultValues() {
91 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
94 $eventId = $this->_id
;
96 $defaults = parent
::setDefaultValues();
98 $this->setShowHide($defaults);
99 if (isset($eventId)) {
100 $params = ['id' => $eventId];
101 CRM_Event_BAO_Event
::retrieve($params, $defaults);
104 'entity_table' => 'civicrm_event',
105 'module' => 'CiviEvent',
106 'entity_id' => $eventId,
109 list($defaults['custom_pre_id'],
110 $defaults['custom_post']
111 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
113 // Get the id for the event registration profile
114 $eventRegistrationIdParams = $eventRegistrationIdDefaults = [
115 'name' => 'event_registration',
117 CRM_Core_BAO_UFGroup
::retrieve($eventRegistrationIdParams, $eventRegistrationIdDefaults);
119 // Set event registration as the default profile if none selected
120 if (!$defaults['custom_pre_id'] && count($defaults['custom_post']) == 0) {
121 $defaults['custom_pre_id'] = CRM_Utils_Array
::value('id', $eventRegistrationIdDefaults);
123 if (isset($defaults['custom_post']) && is_numeric($defaults['custom_post'])) {
124 $defaults['custom_post_id'] = $defaults['custom_post'];
126 elseif (!empty($defaults['custom_post'])) {
127 $defaults['custom_post_id'] = $defaults['custom_post'][0];
128 unset($defaults['custom_post'][0]);
129 $this->_profilePostMultiple
= $defaults['custom_post'];
130 foreach ($defaults['custom_post'] as $key => $value) {
131 self
::buildMultipleProfileBottom($this, $key);
132 $defaults["custom_post_id_multiple[$key]"] = $value;
136 $this->assign('profilePostMultiple', CRM_Utils_Array
::value('custom_post', $defaults));
138 // CRM-17745: Make max additional participants configurable
139 if (empty($defaults['max_additional_participants'])) {
140 $defaults['max_additional_participants'] = 9;
143 if (!empty($defaults['is_multiple_registrations'])) {
144 // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
147 'entity_table' => 'civicrm_event',
148 'module' => 'CiviEvent_Additional',
149 'entity_id' => $eventId,
152 list($defaults['additional_custom_pre_id'],
153 $defaults['additional_custom_post']
154 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinAddParams);
156 if (isset($defaults['additional_custom_post']) && is_numeric($defaults['additional_custom_post'])) {
157 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'];
159 elseif (!empty($defaults['additional_custom_post'])) {
160 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'][0];
161 unset($defaults['additional_custom_post'][0]);
163 $this->_profilePostMultipleAdd
= $defaults['additional_custom_post'];
164 foreach ($defaults['additional_custom_post'] as $key => $value) {
165 self
::buildMultipleProfileBottom($this, $key, 'additional_', ts('Profile for Additional Participants'));
166 $defaults["additional_custom_post_id_multiple[$key]"] = $value;
169 $this->assign('profilePostMultipleAdd', CRM_Utils_Array
::value('additional_custom_post', $defaults));
173 $defaults['is_email_confirm'] = 0;
176 // provide defaults for required fields if empty (and as a 'hint' for approval message field)
177 $defaults['registration_link_text'] = CRM_Utils_Array
::value('registration_link_text', $defaults, ts('Register Now'));
178 $defaults['confirm_title'] = CRM_Utils_Array
::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
179 $defaults['thankyou_title'] = CRM_Utils_Array
::value('thankyou_title', $defaults, ts('Thank You for Registering'));
180 $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.'));
186 * Fix what blocks to show/hide based on the default values set
188 * @param array $defaults
189 * The array of default values.
193 public function setShowHide($defaults) {
194 $this->_showHide
= new CRM_Core_ShowHideBlocks(['registration' => 1],
197 if (empty($defaults)) {
198 $this->_showHide
->addHide('registration');
199 $this->_showHide
->addHide('id-approval-text');
202 if (empty($defaults['requires_approval'])) {
203 $this->_showHide
->addHide('id-approval-text');
206 $this->assign('defaultsEmpty', empty($defaults));
207 $this->_showHide
->addToTemplate();
211 * Build the form object.
215 public function buildQuickForm() {
216 if ($this->_addProfileBottom
) {
217 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNum
);
220 if ($this->_addProfileBottomAdd
) {
221 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNumAdd
, 'additional_', ts('Profile for Additional Participants'));
224 $this->applyFilter('__ALL__', 'trim');
225 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
227 $this->addElement('checkbox',
228 'is_online_registration',
229 ts('Allow Online Registration'),
232 'onclick' => "return showHideByValue('is_online_registration'," .
234 "'registration_blocks'," .
241 $this->add('text', 'registration_link_text', ts('Registration Link Text'));
243 if (!$this->_isTemplate
) {
244 $this->add('datepicker', 'registration_start_date', ts('Registration Start Date'), [], FALSE, ['time' => TRUE]);
245 $this->add('datepicker', 'registration_end_date', ts('Registration End Date'), [], FALSE, ['time' => TRUE]);
249 'used' => 'Supervised',
250 'contact_type' => 'Individual',
252 $dedupeRuleFields = CRM_Dedupe_BAO_Rule
::dedupeRuleFields($params);
254 foreach ($dedupeRuleFields as $key => $fields) {
255 $ruleFields[$key] = ucwords(str_replace('_', ' ', $fields));
258 $this->addElement('checkbox',
259 'is_multiple_registrations',
260 ts('Register multiple participants?')
263 // CRM-17745: Make maximum additional participants configurable
264 $numericOptions = CRM_Core_SelectValues
::getNumericOptions(1, 9);
265 $this->add('select', 'max_additional_participants', ts('Maximum additional participants'), $numericOptions, FALSE, ['class' => 'required']);
267 $this->addElement('checkbox',
268 'allow_same_participant_emails',
269 ts('Same email address?')
271 $this->assign('ruleFields', json_encode($ruleFields));
274 '' => '- Unsupervised rule -',
276 $dedupeRules +
= CRM_Dedupe_BAO_RuleGroup
::getByType('Individual');
277 $this->add('select', 'dedupe_rule_group_id', ts('Duplicate matching rule'), $dedupeRules);
279 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
280 if (in_array('Awaiting approval', $participantStatuses) and in_array('Pending from approval', $participantStatuses) and in_array('Rejected', $participantStatuses)) {
281 $this->addElement('checkbox',
283 ts('Require participant approval?'),
285 ['onclick' => "return showHideByValue('requires_approval', '', 'id-approval-text', 'table-row', 'radio', false);"]
287 $this->add('textarea', 'approval_req_text', ts('Approval message'), $attributes['approval_req_text']);
290 $this->add('text', 'expiration_time', ts('Pending participant expiration (hours)'));
291 $this->addRule('expiration_time', ts('Please enter the number of hours (as an integer).'), 'integer');
292 $this->addField('allow_selfcancelxfer', ['label' => ts('Allow self-service cancellation or transfer?'), 'type' => 'advcheckbox']);
293 $this->add('text', 'selfcancelxfer_time', ts('Cancellation or transfer time limit (hours)'));
294 $this->addRule('selfcancelxfer_time', ts('Please enter the number of hours (as an integer).'), 'integer');
295 self
::buildRegistrationBlock($this);
296 self
::buildConfirmationBlock($this);
297 self
::buildMailBlock($this);
298 self
::buildThankYouBlock($this);
300 parent
::buildQuickForm();
304 * Build Registration Block.
306 * @param CRM_Core_Form $form
309 public function buildRegistrationBlock(&$form) {
310 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'intro_text') +
['class' => 'collapsed', 'preset' => 'civievent'];
311 $form->add('wysiwyg', 'intro_text', ts('Introductory Text'), $attributes);
312 $form->add('wysiwyg', 'footer_text', ts('Footer Text'), $attributes);
314 extract(self
::getProfileSelectorTypes());
316 $form->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
317 $form->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
319 $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
320 $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
324 * Subroutine to insert a Profile Editor widget.
325 * depends on getProfileSelectorTypes
327 * @param array &$form
330 * @param string $prefix
331 * Dom element ID prefix.
332 * @param string $label
334 * @param array $configs
335 * Optional, for addProfileSelector(), defaults to using getProfileSelectorTypes().
337 public function buildMultipleProfileBottom(&$form, $count, $prefix = '', $label = 'Include Profile', $configs = NULL) {
338 extract((is_null($configs)) ? self
::getProfileSelectorTypes() : $configs);
339 $element = $prefix . "custom_post_id_multiple[$count]";
340 $label .= '<br />' . ts('(bottom of page)');
341 $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
345 * Create initializers for addprofileSelector.
348 * ['allowCoreTypes' => array, 'allowSubTypes' => array, 'profileEntities' => array]
350 public static function getProfileSelectorTypes() {
352 'allowCoreTypes' => [],
353 'allowSubTypes' => [],
354 'profileEntities' => [],
358 $configs['allowCoreTypes'] = array_merge([
361 ], CRM_Contact_BAO_ContactType
::subTypes('Individual'));
362 $configs['allowCoreTypes'][] = 'Participant';
363 if (CRM_Core_Permission
::check('manage event profiles') && !CRM_Core_Permission
::check('administer CiviCRM')) {
364 $configs['usedFor'][] = 'CiviEvent';
367 $id = CRM_Utils_Request
::retrieve('id', 'Integer');
369 $participantEventType = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Event", $id, 'event_type_id', 'id');
370 $participantRole = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'default_role_id');
371 $configs['allowSubTypes']['ParticipantEventName'] = [$id];
372 $configs['allowSubTypes']['ParticipantEventType'] = [$participantEventType];
373 $configs['allowSubTypes']['ParticipantRole'] = [$participantRole];
375 $configs['profileEntities'][] = ['entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'];
376 $configs['profileEntities'][] = [
377 'entity_name' => 'participant_1',
378 'entity_type' => 'ParticipantModel',
379 'entity_sub_type' => '*',
386 * Build Confirmation Block.
388 * @param CRM_Core_Form $form
391 public function buildConfirmationBlock(&$form) {
392 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
393 // CRM-11182 - Optional confirmation page for free events
394 $is_monetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $form->_id
, 'is_monetary');
395 $form->assign('is_monetary', $is_monetary);
396 if ($is_monetary == "0") {
397 $form->addYesNo('is_confirm_enabled', ts('Use a confirmation screen?'), NULL, NULL, ['onclick' => "return showHideByValue('is_confirm_enabled','','confirm_screen_settings','block','radio',false);"]);
399 $form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']);
400 $form->add('wysiwyg', 'confirm_text', ts('Introductory Text'), $attributes['confirm_text'] +
['class' => 'collapsed', 'preset' => 'civievent']);
401 $form->add('wysiwyg', 'confirm_footer_text', ts('Footer Text'), $attributes['confirm_text'] +
['class' => 'collapsed', 'preset' => 'civievent']);
407 * @param CRM_Core_Form $form
410 public function buildMailBlock(&$form) {
411 $form->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
412 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
413 $form->addYesNo('is_email_confirm', ts('Send Confirmation Email?'), NULL, NULL, ['onclick' => "return showHideByValue('is_email_confirm','','confirmEmail','block','radio',false);"]);
414 $form->add('textarea', 'confirm_email_text', ts('Text'), $attributes['confirm_email_text']);
415 $form->add('text', 'cc_confirm', ts('CC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'cc_confirm'));
416 $form->addRule('cc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
417 $form->add('text', 'bcc_confirm', ts('BCC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'bcc_confirm'));
418 $form->addRule('bcc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
419 $form->add('text', 'confirm_from_name', ts('Confirm From Name'));
420 $form->add('text', 'confirm_from_email', ts('Confirm From Email'));
421 $form->addRule('confirm_from_email', ts('Email is not valid.'), 'email');
425 * @param CRM_Core_Form $form
427 public function buildThankYouBlock(&$form) {
428 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
429 $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']);
430 $form->add('wysiwyg', 'thankyou_text', ts('Introductory Text'), $attributes['thankyou_text'] +
['class' => 'collapsed', 'preset' => 'civievent']);
431 $form->add('wysiwyg', 'thankyou_footer_text', ts('Footer Text'), $attributes['thankyou_text'] +
['class' => 'collapsed', 'preset' => 'civievent']);
435 * Add local and global form rules.
440 public function addRules() {
441 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
444 $this->addFormRule(['CRM_Event_Form_ManageEvent_Registration', 'formRule'], $this);
448 * Global validation rules for the form.
450 * @param array $values
452 * @param CRM_Core_Form $form
455 * list of errors to be posted back to the form
457 public static function formRule($values, $files, $form) {
458 if (!empty($values['is_online_registration'])) {
460 if (!$values['confirm_title']) {
461 $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page');
463 if (!$values['thankyou_title']) {
464 $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page');
466 if ($values['is_email_confirm']) {
467 if (!$values['confirm_from_name']) {
468 $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.');
471 if (!$values['confirm_from_email']) {
472 $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.');
476 if (isset($values['registration_start_date']) && isset($values['registration_end_date'])) {
477 if ($values['registration_end_date'] < $values['registration_start_date']) {
478 $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date');
482 //check that the selected profiles have either firstname+lastname or email required
484 CRM_Utils_Array
::value('custom_pre_id', $values),
485 CRM_Utils_Array
::value('custom_post_id', $values),
487 $additionalProfileIds = [
488 CRM_Utils_Array
::value('additional_custom_pre_id', $values),
489 CRM_Utils_Array
::value('additional_custom_post_id', $values),
491 //additional profile fields default to main if not set
492 if (!is_numeric($additionalProfileIds[0])) {
493 $additionalProfileIds[0] = $profileIds[0];
495 if (!is_numeric($additionalProfileIds[1])) {
496 $additionalProfileIds[1] = $profileIds[1];
498 //add multiple profiles if set
499 self
::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple');
500 self
::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple');
501 $isProfileComplete = self
::isProfileComplete($profileIds);
502 $isAdditionalProfileComplete = self
::isProfileComplete($additionalProfileIds);
504 //Check main profiles have an email address available if 'send confirmation email' is selected
505 if ($values['is_email_confirm']) {
506 $emailFields = self
::getEmailFields($profileIds);
507 if (!count($emailFields)) {
508 $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected");
511 $additionalCustomPreId = $additionalCustomPostId = NULL;
512 $isPreError = $isPostError = TRUE;
513 if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) {
514 $types = array_merge(['Individual'], CRM_Contact_BAO_ContactType
::subTypes('Individual'));
515 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
517 //check for additional custom pre profile
518 $additionalCustomPreId = CRM_Utils_Array
::value('additional_custom_pre_id', $values);
519 if (!empty($additionalCustomPreId)) {
520 if (!($additionalCustomPreId == 'none')) {
521 $customPreId = $additionalCustomPreId;
528 $customPreId = !empty($values['custom_pre_id']) ?
$values['custom_pre_id'] : NULL;
530 //check whether the additional custom pre profile is of type 'Individual' and its subtypes
531 if (!empty($customPreId)) {
532 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPreId);
533 foreach ($types as $individualTypes) {
534 if (in_array($individualTypes, $profileTypes)) {
544 // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile
546 $additionalCustomPostId = CRM_Utils_Array
::value('additional_custom_post_id', $values);
547 if (!empty($additionalCustomPostId)) {
548 if (!($additionalCustomPostId == 'none')) {
549 $customPostId = $additionalCustomPostId;
552 $isPostError = FALSE;
556 $customPostId = !empty($values['custom_post_id']) ?
$values['custom_post_id'] : NULL;
558 //check whether the additional custom post profile is of type 'Individual' and its subtypes
559 if (!empty($customPostId)) {
560 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPostId);
561 foreach ($types as $individualTypes) {
562 if (in_array($individualTypes, $profileTypes)) {
563 $isPostError = FALSE;
569 $isPostError = FALSE;
572 if (empty($customPreId) && empty($customPostId)) {
573 $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
576 $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
580 if (!$isProfileComplete) {
581 $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.");
583 if (!$isAdditionalProfileComplete) {
584 $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.");
588 // $config = CRM_Core_Config::singleton();
589 // if ( $config->doNotAttachPDFReceipt ) {
590 // if (!empty($values['custom_post_id_multiple'])) {
591 // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) {
592 // if ( $customPostMultiple ) {
593 // $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' ) ) );
599 // if (!empty($values['is_multiple_registrations']) &&
600 // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) {
601 // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) {
602 // if ( $customPostMultiple ) {
603 // $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' ) ) );
610 if (!empty($errorMsg)) {
611 if (!empty($values['custom_post_id_multiple'])) {
612 foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) {
613 self
::buildMultipleProfileBottom($form, $count);
615 $form->assign('profilePostMultiple', $values['custom_post_id_multiple']);
617 if (!empty($values['additional_custom_post_id_multiple'])) {
618 foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) {
619 self
::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants'));
621 $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']);
626 if (!empty($errorMsg)) {
634 * Collect all email fields for an array of profile ids.
639 public static function getEmailFields($profileIds) {
641 foreach ($profileIds as $profileId) {
642 if ($profileId && is_numeric($profileId)) {
643 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
644 foreach ($fields as $field) {
645 if (substr_count($field['name'], 'email')) {
646 $emailFields[] = $field;
655 * Check if a profile contains required fields.
660 public static function isProfileComplete($profileIds) {
661 $profileReqFields = [];
662 foreach ($profileIds as $profileId) {
663 if ($profileId && is_numeric($profileId)) {
664 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
665 foreach ($fields as $field) {
667 case substr_count($field['name'], 'email'):
668 $profileReqFields[] = 'email';
671 case substr_count($field['name'], 'first_name'):
672 $profileReqFields[] = 'first_name';
675 case substr_count($field['name'], 'last_name'):
676 $profileReqFields[] = 'last_name';
682 $profileComplete = (in_array('email', $profileReqFields)
683 ||
(in_array('first_name', $profileReqFields) && in_array('last_name', $profileReqFields))
685 return $profileComplete;
689 * Check if the profiles collect enough information to dedupe.
695 public static function canProfilesDedupe($profileIds, $rgId = 0) {
696 // find the unsupervised rule
698 'used' => 'Unsupervised',
699 'contact_type' => 'Individual',
702 $rgParams['id'] = $rgId;
704 $activeRg = CRM_Dedupe_BAO_RuleGroup
::dedupeRuleFieldsWeight($rgParams);
706 // get the combinations that could be a match for the rule
707 $okCombos = $combos = [];
708 CRM_Dedupe_BAO_RuleGroup
::combos($activeRg[0], $activeRg[1], $combos);
710 // create an index of what combinations involve each field
712 foreach ($combos as $comboid => $combo) {
713 foreach ($combo as $cfield) {
714 $index[$cfield][$comboid] = TRUE;
716 $combos[$comboid] = array_fill_keys($combo, 0);
717 $okCombos[$comboid] = array_fill_keys($combo, 2);
720 // get profiles and see if they have the necessary combos
721 $profileReqFields = [];
722 foreach ($profileIds as $profileId) {
723 if ($profileId && is_numeric($profileId)) {
724 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
726 // walk through the fields in the profile
727 foreach ($fields as $field) {
729 // check each of the fields in the index against the profile field
730 foreach ($index as $ifield => $icombos) {
731 if (strpos($field['name'], $ifield) !== FALSE) {
733 // we found the field in the profile, now record it in the index
734 foreach ($icombos as $icombo => $dontcare) {
735 $combos[$icombo][$ifield] = ($combos[$icombo][$ifield] != 2 && !$field['is_required']) ?
1 : 2;
737 if ($combos[$icombo] == $okCombos[$icombo]) {
738 // if any combo is complete with 2s (all fields are present and required), we can go home
748 // check the combos to see if everything is > 0
749 foreach ($combos as $comboid => $combo) {
751 foreach ($combo as $cfield) {
756 // this combo isn't complete--skip to the next combo
765 // no combo succeeded
770 * Add additional profiles from the form to an array of profile ids.
772 * @param array $profileIds
773 * @param array $values
774 * @param string $field
776 public static function addMultipleProfiles(&$profileIds, $values, $field) {
777 if ($multipleProfiles = CRM_Utils_Array
::value($field, $values)) {
778 foreach ($multipleProfiles as $profileId) {
779 $profileIds[] = $profileId;
785 * Process the form submission.
790 public function postProcess() {
791 $params = $this->exportValues();
793 $params['id'] = $this->_id
;
796 $params['is_online_registration'] = CRM_Utils_Array
::value('is_online_registration', $params, FALSE);
798 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE);
799 $params['is_multiple_registrations'] = CRM_Utils_Array
::value('is_multiple_registrations', $params, FALSE);
800 $params['allow_same_participant_emails'] = CRM_Utils_Array
::value('allow_same_participant_emails', $params, FALSE);
801 $params['requires_approval'] = CRM_Utils_Array
::value('requires_approval', $params, FALSE);
803 // reset is_email confirm if not online reg
804 if (!$params['is_online_registration']) {
805 $params['is_email_confirm'] = FALSE;
807 if (!empty($params['allow_selfcancelxfer'])) {
808 $params['selfcancelxfer_time'] = !empty($params['selfcancelxfer_time']) ?
$params['selfcancelxfer_time'] : 0;
811 CRM_Event_BAO_Event
::add($params);
813 // also update the ProfileModule tables
816 'module' => 'CiviEvent',
817 'entity_table' => 'civicrm_event',
818 'entity_id' => $this->_id
,
821 // first delete all past entries
822 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
826 if (!empty($params['custom_pre_id'])) {
827 $uf[1] = $params['custom_pre_id'];
831 if (!empty($params['custom_post_id'])) {
832 $uf[2] = $params['custom_post_id'];
835 if (!empty($params['custom_post_id_multiple'])) {
836 $uf = array_merge($uf, $params['custom_post_id_multiple']);
838 $uf = array_values($uf);
840 foreach ($uf as $weight => $ufGroupId) {
841 $ufJoinParams['weight'] = $weight +
$wt;
842 $ufJoinParams['uf_group_id'] = $ufGroupId;
843 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
844 unset($ufJoinParams['id']);
847 // also update the ProfileModule tables
850 'module' => 'CiviEvent_Additional',
851 'entity_table' => 'civicrm_event',
852 'entity_id' => $this->_id
,
855 // first delete all past entries
856 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParamsAdd);
857 if (!empty($params['is_multiple_registrations'])) {
861 if (array_key_exists('additional_custom_pre_id', $params)) {
862 if (empty($params['additional_custom_pre_id'])) {
863 $ufAdd[1] = $params['custom_pre_id'];
866 elseif (CRM_Utils_Array
::value('additional_custom_pre_id', $params) == 'none') {
869 $ufAdd[1] = $params['additional_custom_pre_id'];
874 if (array_key_exists('additional_custom_post_id', $params)) {
875 if (empty($params['additional_custom_post_id'])) {
876 $ufAdd[2] = $params['custom_post_id'];
878 elseif (CRM_Utils_Array
::value('additional_custom_post_id', $params) == 'none') {
881 $ufAdd[2] = $params['additional_custom_post_id'];
885 if (!empty($params['additional_custom_post_id_multiple'])) {
886 $additionalPostMultiple = [];
887 foreach ($params['additional_custom_post_id_multiple'] as $key => $value) {
888 if (is_null($value) && !empty($params['custom_post_id'])) {
889 $additionalPostMultiple[$key] = $params['custom_post_id'];
891 elseif ($value == 'none') {
895 $additionalPostMultiple[$key] = $value;
898 $ufAdd = array_merge($ufAdd, $additionalPostMultiple);
901 $ufAdd = array_values($ufAdd);
902 if (!empty($ufAdd)) {
903 foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) {
905 $ufJoinParamsAdd['weight'] = $weightAdd +
$wtAdd;
906 $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd;
908 CRM_Core_BAO_UFJoin
::create($ufJoinParamsAdd);
909 unset($ufJoinParamsAdd['id']);
914 // get the profiles to evaluate what they collect
916 CRM_Utils_Array
::value('custom_pre_id', $params),
917 CRM_Utils_Array
::value('custom_post_id', $params),
919 $additionalProfileIds = [
920 CRM_Utils_Array
::value('additional_custom_pre_id', $params),
921 CRM_Utils_Array
::value('additional_custom_post_id', $params),
923 // additional profile fields default to main if not set
924 if (!is_numeric($additionalProfileIds[0])) {
925 $additionalProfileIds[0] = $profileIds[0];
927 if (!is_numeric($additionalProfileIds[1])) {
928 $additionalProfileIds[1] = $profileIds[1];
930 //add multiple profiles if set
931 self
::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple');
932 self
::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple');
935 $rgId = CRM_Utils_Array
::value('dedupe_rule_group_id', $params, 0);
937 switch (self
::canProfilesDedupe($profileIds, $rgId)) {
939 $dedupeTitle = 'Duplicate Matching Impossible';
940 $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.");
944 $dedupeTitle = 'Duplicate Contacts Possible';
945 $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.");
947 if (!empty($params['is_multiple_registrations'])) {
948 switch (self
::canProfilesDedupe($additionalProfileIds, $rgId)) {
950 $dedupeTitle = 'Duplicate Matching Impossible';
952 $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.");
955 $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.");
961 $dedupeTitle = 'Duplicate Contacts Possible';
962 $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.");
967 CRM_Core_Session
::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', ['expires' => 0]);
970 // Update tab "disabled" css class
971 $this->ajaxResponse
['tabValid'] = !empty($params['is_online_registration']);
973 parent
::endPostProcess();
977 * Return a descriptive name for the page, used in wizard header
981 public function getTitle() {
982 return ts('Online Registration');