3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
38 * This class generates form components for processing Event
41 class CRM_Event_Form_ManageEvent_Registration
extends CRM_Event_Form_ManageEvent
{
44 * what blocks should we show and hide.
46 * @var CRM_Core_ShowHideBlocks
50 protected $_profilePostMultiple = array();
51 protected $_profilePostMultipleAdd = array();
54 * Function to set variables up before form is built
59 function preProcess() {
60 $this->_addProfileBottom
= CRM_Utils_Array
::value('addProfileBottom', $_GET, FALSE);
61 $this->_profileBottomNum
= CRM_Utils_Array
::value('addProfileNum', $_GET, 0);
62 $this->_addProfileBottomAdd
= CRM_Utils_Array
::value('addProfileBottomAdd', $_GET, FALSE);
63 $this->_profileBottomNumAdd
= CRM_Utils_Array
::value('addProfileNumAdd', $_GET, 0);
67 $this->assign('addProfileBottom', $this->_addProfileBottom
);
68 $this->assign('profileBottomNum', $this->_profileBottomNum
);
70 $urlParams = "id={$this->_id}&addProfileBottom=1&qfKey={$this->controller->_key}";
71 $this->assign('addProfileParams', $urlParams);
73 if ($addProfileBottom = CRM_Utils_Array
::value('custom_post_id_multiple', $_POST)) {
74 foreach (array_keys($addProfileBottom) as $profileNum) {
75 self
::buildMultipleProfileBottom($this, $profileNum);
79 $this->assign('addProfileBottomAdd', $this->_addProfileBottomAdd
);
80 $this->assign('profileBottomNumAdd', $this->_profileBottomNumAdd
);
82 $urlParamsAdd = "id={$this->_id}&addProfileBottomAdd=1&qfKey={$this->controller->_key}";
83 $this->assign('addProfileParamsAdd', $urlParamsAdd);
85 if ($addProfileBottomAdd = CRM_Utils_Array
::value('additional_custom_post_id_multiple', $_POST)) {
86 foreach (array_keys($addProfileBottomAdd) as $profileNum) {
87 self
::buildMultipleProfileBottom($this, $profileNum, 'additional_', ts('Profile for Additional Participants'));
93 * This function sets the default values for the form.
94 * the default values are retrieved from the database
100 function setDefaultValues() {
101 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
104 $eventId = $this->_id
;
106 $defaults = parent
::setDefaultValues();
108 $this->setShowHide($defaults);
109 if (isset($eventId)) {
110 $params = array('id' => $eventId);
111 CRM_Event_BAO_Event
::retrieve($params, $defaults);
113 $ufJoinParams = array(
114 'entity_table' => 'civicrm_event',
115 'module' => 'CiviEvent',
116 'entity_id' => $eventId,
119 list($defaults['custom_pre_id'],
120 $defaults['custom_post']
121 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
123 // Get the id for the event registration profile
124 $eventRegistrationIdParams = $eventRegistrationIdDefaults = array(
125 'name' => 'event_registration',
127 CRM_Core_BAO_UFGroup
::retrieve($eventRegistrationIdParams, $eventRegistrationIdDefaults);
129 // Set event registration as the default profile if none selected
130 if (!$defaults['custom_pre_id'] && count($defaults['custom_post']) == 0) {
131 $defaults['custom_pre_id'] = CRM_Utils_Array
::value('id', $eventRegistrationIdDefaults);
133 if (isset($defaults['custom_post']) && is_numeric($defaults['custom_post'])) {
134 $defaults['custom_post_id'] = $defaults['custom_post'];
136 elseif (!empty($defaults['custom_post'])) {
137 $defaults['custom_post_id'] = $defaults['custom_post'][0];
138 unset($defaults['custom_post'][0]);
139 $this->_profilePostMultiple
= $defaults['custom_post'];
140 foreach ($defaults['custom_post'] as $key => $value) {
141 self
::buildMultipleProfileBottom($this, $key);
142 $defaults["custom_post_id_multiple[$key]"] = $value;
146 $this->assign('profilePostMultiple', CRM_Utils_Array
::value('custom_post', $defaults));
148 if (!empty($defaults['is_multiple_registrations'])) {
149 // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
151 $ufJoinAddParams = array(
152 'entity_table' => 'civicrm_event',
153 'module' => 'CiviEvent_Additional',
154 'entity_id' => $eventId,
157 list($defaults['additional_custom_pre_id'],
158 $defaults['additional_custom_post']
159 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinAddParams);
161 if (isset($defaults['additional_custom_post']) && is_numeric($defaults['additional_custom_post'])) {
162 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'];
164 elseif (!empty($defaults['additional_custom_post'])) {
165 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'][0];
166 unset($defaults['additional_custom_post'][0]);
168 $this->_profilePostMultipleAdd
= $defaults['additional_custom_post'];
169 foreach ($defaults['additional_custom_post'] as $key => $value) {
170 self
::buildMultipleProfileBottom($this, $key, 'additional_', ts('Profile for Additional Participants'));
171 $defaults["additional_custom_post_id_multiple[$key]"] = $value;
174 $this->assign('profilePostMultipleAdd', CRM_Utils_Array
::value('additional_custom_post', $defaults));
178 $defaults['is_email_confirm'] = 0;
181 // provide defaults for required fields if empty (and as a 'hint' for approval message field)
182 $defaults['registration_link_text'] = CRM_Utils_Array
::value('registration_link_text', $defaults, ts('Register Now'));
183 $defaults['confirm_title'] = CRM_Utils_Array
::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
184 $defaults['thankyou_title'] = CRM_Utils_Array
::value('thankyou_title', $defaults, ts('Thank You for Registering'));
185 $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.'));
187 if (!empty($defaults['registration_start_date'])) {
188 list($defaults['registration_start_date'],
189 $defaults['registration_start_date_time']
190 ) = CRM_Utils_Date
::setDateDefaults($defaults['registration_start_date'],
195 if (!empty($defaults['registration_end_date'])) {
196 list($defaults['registration_end_date'],
197 $defaults['registration_end_date_time']
198 ) = CRM_Utils_Date
::setDateDefaults($defaults['registration_end_date'],
207 * Fix what blocks to show/hide based on the default values set
209 * @param array $defaults the array of default values
210 * @param boolean $force should we set show hide based on input defaults
214 function setShowHide($defaults) {
215 $this->_showHide
= new CRM_Core_ShowHideBlocks(array('registration' => 1),
218 if (empty($defaults)) {
219 $this->_showHide
->addHide('registration');
220 $this->_showHide
->addHide('id-approval-text');
223 if (empty($defaults['requires_approval'])) {
224 $this->_showHide
->addHide('id-approval-text');
227 $this->assign('defaultsEmpty', empty($defaults));
228 $this->_showHide
->addToTemplate();
232 * Function to build the form
237 public function buildQuickForm() {
238 if ($this->_addProfileBottom
) {
239 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNum
);
242 if ($this->_addProfileBottomAdd
) {
243 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNumAdd
, 'additional_', ts('Profile for Additional Participants'));
246 $this->applyFilter('__ALL__', 'trim');
247 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
249 $this->addElement('checkbox',
250 'is_online_registration',
251 ts('Allow Online Registration?'),
254 'onclick' => "return showHideByValue('is_online_registration',
256 'registration_blocks',
263 $this->add('text', 'registration_link_text', ts('Registration Link Text'));
265 if (!$this->_isTemplate
) {
266 $this->addDateTime('registration_start_date', ts('Registration Start Date'), FALSE, array('formatType' => 'activityDateTime'));
267 $this->addDateTime('registration_end_date', ts('Registration End Date'), FALSE, array('formatType' => 'activityDateTime'));
271 'used' => 'Supervised',
272 'contact_type' => 'Individual',
274 $dedupeRuleFields = CRM_Dedupe_BAO_Rule
::dedupeRuleFields($params);
276 foreach ($dedupeRuleFields as $key => $fields) {
277 $ruleFields[$key] = ucwords(str_replace('_', ' ', $fields));
280 $this->addElement('checkbox',
281 'is_multiple_registrations',
282 ts('Register multiple participants?')
285 $this->addElement('checkbox',
286 'allow_same_participant_emails',
287 ts('Same email address?')
289 $this->assign('ruleFields', json_encode($ruleFields));
291 $dedupeRules = array(
292 '' => '- Unsupervised rule -',
294 $dedupeRules +
= CRM_Dedupe_BAO_RuleGroup
::getByType('Individual');
295 $this->add('select', 'dedupe_rule_group_id', ts('Duplicate matching rule'), $dedupeRules);
297 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
298 if (in_array('Awaiting approval', $participantStatuses) and in_array('Pending from approval', $participantStatuses) and in_array('Rejected', $participantStatuses)) {
299 $this->addElement('checkbox',
301 ts('Require participant approval?'),
303 array('onclick' => "return showHideByValue('requires_approval', '', 'id-approval-text', 'table-row', 'radio', false);")
305 $this->add('textarea', 'approval_req_text', ts('Approval message'), $attributes['approval_req_text']);
308 $this->add('text', 'expiration_time', ts('Pending participant expiration (hours)'));
309 $this->addRule('expiration_time', ts('Please enter the number of hours (as an integer).'), 'integer');
311 self
::buildRegistrationBlock($this);
312 self
::buildConfirmationBlock($this);
313 self
::buildMailBlock($this);
314 self
::buildThankYouBlock($this);
316 parent
::buildQuickForm();
320 * Function to build Registration Block
325 function buildRegistrationBlock(&$form) {
326 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
327 $form->addWysiwyg('intro_text', ts('Introductory Text'), $attributes['intro_text']);
328 // FIXME: This hack forces height of editor to 175px. Need to modify QF classes for editors to allow passing
329 // explicit height and width.
330 $form->addWysiwyg('footer_text', ts('Footer Text'), array('rows' => 2, 'cols' => 40));
332 extract( self
::getProfileSelectorTypes() );
334 $form->addProfileSelector( 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
335 $form->addProfileSelector( 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
337 $form->addProfileSelector( 'additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
338 $form->addProfileSelector( 'additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
342 * Subroutine to insert a Profile Editor widget
343 * depends on getProfileSelectorTypes
345 * @param array &$form
346 * @param int $count unique index
347 * @param string $prefix dom element ID prefix
348 * @param string $label Label
349 * @param array $configs Optional, for addProfileSelector(), defaults to using getProfileSelectorTypes()
351 function buildMultipleProfileBottom(&$form, $count, $prefix = '', $label = 'Include Profile', $configs = null) {
352 extract( ( is_null($configs) ) ? self
::getProfileSelectorTypes() : $configs );
353 $element = $prefix . "custom_post_id_multiple[$count]";
354 $label .= '<br />'.ts('(bottom of page)');
355 $form->addProfileSelector( $element, $label, $allowCoreTypes, $allowSubTypes, $profileEntitites);
359 * Create initializers for addprofileSelector
361 * @return array( 'allowCoreTypes' => array(), 'allowSubTypes' => array(), 'profileEntities' => array() )
363 static function getProfileSelectorTypes() {
365 'allowCoreTypes' => array(),
366 'allowSubTypes' => array(),
367 'profileEntities' => array(),
370 $configs['allowCoreTypes'][] = 'Contact';
371 $configs['allowCoreTypes'][] = 'Individual';
372 $configs['allowCoreTypes'][] = 'Participant';
374 $configs['profileEntities'][] = array('entity_name' => 'individual_entity', 'entity_type' => 'IndividualModel');
375 $configs['profileEntities'][] = array('entity_name' => 'participant_entity', 'entity_type' => 'ParticipantModel');
381 * Function to build Confirmation Block
386 function buildConfirmationBlock(&$form) {
387 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
389 // CRM-11182 - Optional confirmation page for free events
390 $is_monetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $form->_id
, 'is_monetary');
391 $form->assign('is_monetary', $is_monetary);
392 if ($is_monetary == "0") {
393 $form->addYesNo('is_confirm_enabled', ts('Use a confirmation screen?'), NULL, NULL, array('onclick' => "return showHideByValue('is_confirm_enabled','','confirm_screen_settings','block','radio',false);"));
395 $form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']);
396 $form->addWysiwyg('confirm_text', ts('Introductory Text'), $attributes['confirm_text']);
397 // FIXME: This hack forces height of editor to 175px. Need to modify QF classes for editors to allow passing
398 // explicit height and width.
399 $form->addWysiwyg('confirm_footer_text', ts('Footer Text'), array('rows' => 2, 'cols' => 40));
403 * Function to build Email Block
408 function buildMailBlock(&$form) {
409 $form->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
410 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
411 $form->addYesNo('is_email_confirm', ts('Send Confirmation Email?'), NULL, NULL, array('onclick' => "return showHideByValue('is_email_confirm','','confirmEmail','block','radio',false);"));
412 $form->add('textarea', 'confirm_email_text', ts('Text'), $attributes['confirm_email_text']);
413 $form->add('text', 'cc_confirm', ts('CC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'cc_confirm'));
414 $form->addRule('cc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
415 $form->add('text', 'bcc_confirm', ts('BCC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'bcc_confirm'));
416 $form->addRule('bcc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
417 $form->add('text', 'confirm_from_name', ts('Confirm From Name'));
418 $form->add('text', 'confirm_from_email', ts('Confirm From Email'));
419 $form->addRule('confirm_from_email', ts('Email is not valid.'), 'email');
422 function buildThankYouBlock(&$form) {
423 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
424 $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']);
425 $form->addWysiwyg('thankyou_text', ts('Introductory Text'), $attributes['thankyou_text']);
426 // FIXME: This hack forces height of editor to 175px. Need to modify QF classes for editors to allow passing
427 // explicit height and width.
428 $form->addWysiwyg('thankyou_footer_text', ts('Footer Text'), array('rows' => 2, 'cols' => 40));
432 * Add local and global form rules
438 function addRules() {
439 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
442 $this->addFormRule(array('CRM_Event_Form_ManageEvent_Registration', 'formRule'), $this);
446 * global validation rules for the form
448 * @param array $fields posted values of the form
450 * @return array list of errors to be posted back to the form
454 static function formRule($values, $files, $form) {
455 if (!empty($values['is_online_registration'])) {
457 if (!$values['confirm_title']) {
458 $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page');
460 if (!$values['thankyou_title']) {
461 $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page');
463 if ($values['is_email_confirm']) {
464 if (!$values['confirm_from_name']) {
465 $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.');
468 if (!$values['confirm_from_email']) {
469 $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.');
474 isset($values['registration_start_date']) &&
475 isset($values['registration_end_date'])
477 $start = CRM_Utils_Date
::processDate($values['registration_start_date']);
478 $end = CRM_Utils_Date
::processDate($values['registration_end_date']);
480 $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date');
484 //check that the selected profiles have either firstname+lastname or email required
486 CRM_Utils_Array
::value('custom_pre_id', $values),
487 CRM_Utils_Array
::value('custom_post_id', $values),
489 $additionalProfileIds = array(
490 CRM_Utils_Array
::value('additional_custom_pre_id', $values),
491 CRM_Utils_Array
::value('additional_custom_post_id', $values),
493 //additional profile fields default to main if not set
494 if (!is_numeric($additionalProfileIds[0])) {
495 $additionalProfileIds[0] = $profileIds[0];
497 if (!is_numeric($additionalProfileIds[1])) {
498 $additionalProfileIds[1] = $profileIds[1];
500 //add multiple profiles if set
501 self
::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple');
502 self
::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple');
503 $isProfileComplete = self
::isProfileComplete($profileIds);
504 $isAdditionalProfileComplete = self
::isProfileComplete($additionalProfileIds);
506 //Check main profiles have an email address available if 'send confirmation email' is selected
507 if ($values['is_email_confirm']) {
508 $emailFields = self
::getEmailFields($profileIds);
509 if (!count($emailFields)) {
510 $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected");
513 $additionalCustomPreId = $additionalCustomPostId = NULL;
514 $isPreError = $isPostError = TRUE;
515 if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) {
516 $types = array_merge(array('Individual'), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
517 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
519 //check for additional custom pre profile
520 $additionalCustomPreId = CRM_Utils_Array
::value('additional_custom_pre_id', $values);
521 if (!empty($additionalCustomPreId)) {
522 if (!($additionalCustomPreId == 'none')) {
523 $customPreId = $additionalCustomPreId;
530 $customPreId = !empty($values['custom_pre_id']) ?
$values['custom_pre_id'] : NULL;
532 //check whether the additional custom pre profile is of type 'Individual' and its subtypes
533 if (!empty($customPreId)) {
534 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPreId);
535 foreach ($types as $individualTypes) {
536 if (in_array($individualTypes, $profileTypes)) {
546 // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile
548 $additionalCustomPostId = CRM_Utils_Array
::value('additional_custom_post_id', $values);
549 if (!empty($additionalCustomPostId)) {
550 if (!($additionalCustomPostId == 'none')) {
551 $customPostId = $additionalCustomPostId;
554 $isPostError = FALSE;
558 $customPostId = !empty($values['custom_post_id']) ?
$values['custom_post_id'] : NULL;
560 //check whether the additional custom post profile is of type 'Individual' and its subtypes
561 if (!empty($customPostId)) {
562 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPostId);
563 foreach ($types as $individualTypes) {
564 if (in_array($individualTypes, $profileTypes)) {
565 $isPostError = FALSE;
571 $isPostError = FALSE;
574 if (empty($customPreId) && empty($customPostId)) {
575 $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
578 $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
582 if (!$isProfileComplete) {
583 $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.");
585 if (!$isAdditionalProfileComplete) {
586 $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.");
590 // $config = CRM_Core_Config::singleton();
591 // if ( $config->doNotAttachPDFReceipt ) {
592 // if (!empty($values['custom_post_id_multiple'])) {
593 // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) {
594 // if ( $customPostMultiple ) {
595 // $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' ) ) );
601 // if (!empty($values['is_multiple_registrations']) &&
602 // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) {
603 // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) {
604 // if ( $customPostMultiple ) {
605 // $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' ) ) );
612 if (!empty($errorMsg)) {
613 if (!empty($values['custom_post_id_multiple'])) {
614 foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) {
615 self
::buildMultipleProfileBottom($form, $count);
617 $form->assign('profilePostMultiple', $values['custom_post_id_multiple']);
619 if (!empty($values['additional_custom_post_id_multiple'])) {
620 foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) {
621 self
::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants'));
623 $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']);
628 if (!empty($errorMsg)) {
636 * Collect all email fields for an array of profile ids
640 static function getEmailFields($profileIds) {
641 $emailFields = array();
642 foreach ($profileIds as $profileId) {
643 if ($profileId && is_numeric($profileId)) {
644 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
645 foreach ($fields as $field) {
646 if (substr_count($field['name'], 'email')) {
647 $emailFields[] = $field;
656 * Check if a profile contains required fields
660 static function isProfileComplete($profileIds) {
661 $profileReqFields = array();
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
694 function canProfilesDedupe($profileIds, $rgId = 0) {
696 // find the unsupervised rule
699 'used' => 'Unsupervised',
700 'contact_type' => 'Individual',
703 $rgParams['id'] = $rgId;
705 $activeRg = CRM_Dedupe_BAO_RuleGroup
::dedupeRuleFieldsWeight($rgParams);
707 // get the combinations that could be a match for the rule
708 $okCombos = $combos = array();
709 CRM_Dedupe_BAO_RuleGroup
::combos($activeRg[0], $activeRg[1], $combos);
711 // create an index of what combinations involve each field
713 foreach ($combos as $comboid => $combo) {
714 foreach ($combo as $cfield) {
715 $index[$cfield][$comboid] = true;
717 $combos[$comboid] = array_fill_keys($combo, 0);
718 $okCombos[$comboid] = array_fill_keys($combo, 2);
721 // get profiles and see if they have the necessary combos
722 $profileReqFields = array();
723 foreach ($profileIds as $profileId) {
724 if ($profileId && is_numeric($profileId)) {
725 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
727 // walk through the fields in the profile
728 foreach ($fields as $field) {
730 // check each of the fields in the index against the profile field
731 foreach ($index as $ifield => $icombos) {
732 if(strpos($field['name'], $ifield) !== false) {
734 // we found the field in the profile, now record it in the index
735 foreach ($icombos as $icombo => $dontcare) {
736 $combos[$icombo][$ifield] = ($combos[$icombo][$ifield] != 2 && !$field['is_required']) ?
1 : 2;
738 if ($combos[$icombo] == $okCombos[$icombo]) {
739 // if any combo is complete with 2s (all fields are present and required), we can go home
749 // check the combos to see if everything is > 0
750 foreach ($combos as $comboid => $combo) {
752 foreach ($combo as $cfield) {
757 // this combo isn't complete--skip to the next combo
761 if ($complete) { return 1; }
764 // no combo succeeded
769 * Add additional profiles from the form to an array of profile ids.
772 static function addMultipleProfiles(&$profileIds, $values, $field) {
773 if ($multipleProfiles = CRM_Utils_Array
::value($field, $values)) {
774 foreach ($multipleProfiles as $profileId) {
775 $profileIds[] = $profileId;
781 * Function to process the form
787 public function postProcess() {
788 $params = $this->exportValues();
790 $params['id'] = $this->_id
;
793 $params['is_online_registration'] = CRM_Utils_Array
::value('is_online_registration', $params, FALSE);
794 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE); // CRM-11182
795 $params['is_multiple_registrations'] = CRM_Utils_Array
::value('is_multiple_registrations', $params, FALSE);
796 $params['allow_same_participant_emails'] = CRM_Utils_Array
::value('allow_same_participant_emails', $params, FALSE);
797 $params['requires_approval'] = CRM_Utils_Array
::value('requires_approval', $params, FALSE);
799 // reset is_email confirm if not online reg
800 if (!$params['is_online_registration']) {
801 $params['is_email_confirm'] = FALSE;
804 if (!$this->_isTemplate
) {
805 $params['registration_start_date'] = CRM_Utils_Date
::processDate($params['registration_start_date'],
806 $params['registration_start_date_time'],
809 $params['registration_end_date'] = CRM_Utils_Date
::processDate($params['registration_end_date'],
810 $params['registration_end_date_time'],
815 CRM_Event_BAO_Event
::add($params);
817 // also update the ProfileModule tables
818 $ufJoinParams = array(
820 'module' => 'CiviEvent',
821 'entity_table' => 'civicrm_event',
822 'entity_id' => $this->_id
,
826 // first delete all past entries
827 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
831 if (!empty($params['custom_pre_id'])) {
832 $uf[1] = $params['custom_pre_id'];
836 if (!empty($params['custom_post_id'])) {
837 $uf[2] = $params['custom_post_id'];
840 if (!empty($params['custom_post_id_multiple'])) {
841 $uf = array_merge($uf, $params['custom_post_id_multiple']);
843 $uf = array_values($uf);
845 foreach ($uf as $weight => $ufGroupId) {
846 $ufJoinParams['weight'] = $weight +
$wt;
847 $ufJoinParams['uf_group_id'] = $ufGroupId;
848 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
849 unset($ufJoinParams['id']);
852 // also update the ProfileModule tables
853 $ufJoinParamsAdd = array(
855 'module' => 'CiviEvent_Additional',
856 'entity_table' => 'civicrm_event',
857 'entity_id' => $this->_id
,
860 // first delete all past entries
861 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParamsAdd);
862 if (!empty($params['is_multiple_registrations'])) {
866 if (array_key_exists('additional_custom_pre_id', $params)) {
867 if (empty($params['additional_custom_pre_id'])) {
868 $ufAdd[1] = $params['custom_pre_id'];
871 elseif (CRM_Utils_Array
::value('additional_custom_pre_id', $params) == 'none') {}
873 $ufAdd[1] = $params['additional_custom_pre_id'];
878 if (array_key_exists('additional_custom_post_id', $params)) {
879 if (empty($params['additional_custom_post_id'])) {
880 $ufAdd[2] = $params['custom_post_id'];
882 elseif (CRM_Utils_Array
::value('additional_custom_post_id', $params) == 'none') {}
884 $ufAdd[2] = $params['additional_custom_post_id'];
888 if (!empty($params['additional_custom_post_id_multiple'])) {
889 $additionalPostMultiple = array();
890 foreach ($params['additional_custom_post_id_multiple'] as $key => $value) {
891 if (!$value && !empty($params['custom_post_id'])) {
892 $additionalPostMultiple[$key] = $params['custom_post_id'];
894 elseif ($value == 'none') {
898 $additionalPostMultiple[$key] = $value;
901 $ufAdd = array_merge($ufAdd, $additionalPostMultiple);
904 $ufAdd = array_values($ufAdd);
905 if (!empty($ufAdd)) {
906 foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) {
908 $ufJoinParamsAdd['weight'] = $weightAdd +
$wtAdd;
909 $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd;
911 CRM_Core_BAO_UFJoin
::create($ufJoinParamsAdd);
912 unset($ufJoinParamsAdd['id']);
917 // get the profiles to evaluate what they collect
919 CRM_Utils_Array
::value('custom_pre_id', $params),
920 CRM_Utils_Array
::value('custom_post_id', $params),
922 $additionalProfileIds = array(
923 CRM_Utils_Array
::value('additional_custom_pre_id', $params),
924 CRM_Utils_Array
::value('additional_custom_post_id', $params),
926 // additional profile fields default to main if not set
927 if (!is_numeric($additionalProfileIds[0])) {
928 $additionalProfileIds[0] = $profileIds[0];
930 if (!is_numeric($additionalProfileIds[1])) {
931 $additionalProfileIds[1] = $profileIds[1];
933 //add multiple profiles if set
934 self
::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple');
935 self
::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple');
938 $rgId = CRM_Utils_Array
::value('dedupe_rule_group_id', $params, 0);
940 switch (self
::canProfilesDedupe($profileIds, $rgId)) {
942 $dedupeTitle = 'Duplicate Matching Impossible';
943 $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.");
946 $dedupeTitle = 'Duplicate Contacts Possible';
947 $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.");
949 if (!empty($params['is_multiple_registrations'])) {
950 switch(self
::canProfilesDedupe($additionalProfileIds, $rgId)) {
952 $dedupeTitle = 'Duplicate Matching Impossible';
954 $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.");
957 $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.");
962 $dedupeTitle = 'Duplicate Contacts Possible';
963 $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.");
968 CRM_Core_Session
::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', array('expires' => 0));
971 // Update tab "disabled" css class
972 $this->ajaxResponse
['tabValid'] = !empty($params['is_online_registration']);
974 parent
::endPostProcess();
979 * Return a descriptive name for the page, used in wizard header
984 public function getTitle() {
985 return ts('Online Registration');