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
211 * @internal param bool $force should we set show hide based on input defaults
215 function setShowHide($defaults) {
216 $this->_showHide
= new CRM_Core_ShowHideBlocks(array('registration' => 1),
219 if (empty($defaults)) {
220 $this->_showHide
->addHide('registration');
221 $this->_showHide
->addHide('id-approval-text');
224 if (empty($defaults['requires_approval'])) {
225 $this->_showHide
->addHide('id-approval-text');
228 $this->assign('defaultsEmpty', empty($defaults));
229 $this->_showHide
->addToTemplate();
233 * Function to build the form
238 public function buildQuickForm() {
239 if ($this->_addProfileBottom
) {
240 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNum
);
243 if ($this->_addProfileBottomAdd
) {
244 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNumAdd
, 'additional_', ts('Profile for Additional Participants'));
247 $this->applyFilter('__ALL__', 'trim');
248 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
250 $this->addElement('checkbox',
251 'is_online_registration',
252 ts('Allow Online Registration?'),
255 'onclick' => "return showHideByValue('is_online_registration',
257 'registration_blocks',
264 $this->add('text', 'registration_link_text', ts('Registration Link Text'));
266 if (!$this->_isTemplate
) {
267 $this->addDateTime('registration_start_date', ts('Registration Start Date'), FALSE, array('formatType' => 'activityDateTime'));
268 $this->addDateTime('registration_end_date', ts('Registration End Date'), FALSE, array('formatType' => 'activityDateTime'));
272 'used' => 'Supervised',
273 'contact_type' => 'Individual',
275 $dedupeRuleFields = CRM_Dedupe_BAO_Rule
::dedupeRuleFields($params);
277 foreach ($dedupeRuleFields as $key => $fields) {
278 $ruleFields[$key] = ucwords(str_replace('_', ' ', $fields));
281 $this->addElement('checkbox',
282 'is_multiple_registrations',
283 ts('Register multiple participants?')
286 $this->addElement('checkbox',
287 'allow_same_participant_emails',
288 ts('Same email address?')
290 $this->assign('ruleFields', json_encode($ruleFields));
292 $dedupeRules = array(
293 '' => '- Unsupervised rule -',
295 $dedupeRules +
= CRM_Dedupe_BAO_RuleGroup
::getByType('Individual');
296 $this->add('select', 'dedupe_rule_group_id', ts('Duplicate matching rule'), $dedupeRules);
298 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
299 if (in_array('Awaiting approval', $participantStatuses) and in_array('Pending from approval', $participantStatuses) and in_array('Rejected', $participantStatuses)) {
300 $this->addElement('checkbox',
302 ts('Require participant approval?'),
304 array('onclick' => "return showHideByValue('requires_approval', '', 'id-approval-text', 'table-row', 'radio', false);")
306 $this->add('textarea', 'approval_req_text', ts('Approval message'), $attributes['approval_req_text']);
309 $this->add('text', 'expiration_time', ts('Pending participant expiration (hours)'));
310 $this->addRule('expiration_time', ts('Please enter the number of hours (as an integer).'), 'integer');
312 self
::buildRegistrationBlock($this);
313 self
::buildConfirmationBlock($this);
314 self
::buildMailBlock($this);
315 self
::buildThankYouBlock($this);
317 parent
::buildQuickForm();
321 * Function to build Registration Block
325 * @internal param int $pageId
328 function buildRegistrationBlock(&$form) {
329 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
330 $form->addWysiwyg('intro_text', ts('Introductory Text'), $attributes['intro_text']);
331 // FIXME: This hack forces height of editor to 175px. Need to modify QF classes for editors to allow passing
332 // explicit height and width.
333 $form->addWysiwyg('footer_text', ts('Footer Text'), array('rows' => 2, 'cols' => 40));
335 extract( self
::getProfileSelectorTypes() );
337 $form->addProfileSelector( 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
338 $form->addProfileSelector( 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
340 $form->addProfileSelector( 'additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
341 $form->addProfileSelector( 'additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
345 * Subroutine to insert a Profile Editor widget
346 * depends on getProfileSelectorTypes
348 * @param array &$form
349 * @param int $count unique index
350 * @param string $prefix dom element ID prefix
351 * @param string $label Label
352 * @param array $configs Optional, for addProfileSelector(), defaults to using getProfileSelectorTypes()
354 function buildMultipleProfileBottom(&$form, $count, $prefix = '', $label = 'Include Profile', $configs = null) {
355 extract( ( is_null($configs) ) ? self
::getProfileSelectorTypes() : $configs );
356 $element = $prefix . "custom_post_id_multiple[$count]";
357 $label .= '<br />'.ts('(bottom of page)');
358 $form->addProfileSelector( $element, $label, $allowCoreTypes, $allowSubTypes, $profileEntitites);
362 * Create initializers for addprofileSelector
364 * @return array( 'allowCoreTypes' => array(), 'allowSubTypes' => array(), 'profileEntities' => array() )
366 static function getProfileSelectorTypes() {
368 'allowCoreTypes' => array(),
369 'allowSubTypes' => array(),
370 'profileEntities' => array(),
373 $configs['allowCoreTypes'][] = 'Contact';
374 $configs['allowCoreTypes'][] = 'Individual';
375 $configs['allowCoreTypes'][] = 'Participant';
377 $configs['profileEntities'][] = array('entity_name' => 'individual_entity', 'entity_type' => 'IndividualModel');
378 $configs['profileEntities'][] = array('entity_name' => 'participant_entity', 'entity_type' => 'ParticipantModel');
384 * Function to build Confirmation Block
389 function buildConfirmationBlock(&$form) {
390 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
392 // CRM-11182 - Optional confirmation page for free events
393 $is_monetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $form->_id
, 'is_monetary');
394 $form->assign('is_monetary', $is_monetary);
395 if ($is_monetary == "0") {
396 $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);"));
398 $form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']);
399 $form->addWysiwyg('confirm_text', ts('Introductory Text'), $attributes['confirm_text']);
400 // FIXME: This hack forces height of editor to 175px. Need to modify QF classes for editors to allow passing
401 // explicit height and width.
402 $form->addWysiwyg('confirm_footer_text', ts('Footer Text'), array('rows' => 2, 'cols' => 40));
406 * Function to build Email Block
411 function buildMailBlock(&$form) {
412 $form->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
413 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
414 $form->addYesNo('is_email_confirm', ts('Send Confirmation Email?'), NULL, NULL, array('onclick' => "return showHideByValue('is_email_confirm','','confirmEmail','block','radio',false);"));
415 $form->add('textarea', 'confirm_email_text', ts('Text'), $attributes['confirm_email_text']);
416 $form->add('text', 'cc_confirm', ts('CC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'cc_confirm'));
417 $form->addRule('cc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
418 $form->add('text', 'bcc_confirm', ts('BCC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'bcc_confirm'));
419 $form->addRule('bcc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
420 $form->add('text', 'confirm_from_name', ts('Confirm From Name'));
421 $form->add('text', 'confirm_from_email', ts('Confirm From Email'));
422 $form->addRule('confirm_from_email', ts('Email is not valid.'), 'email');
425 function buildThankYouBlock(&$form) {
426 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
427 $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']);
428 $form->addWysiwyg('thankyou_text', ts('Introductory Text'), $attributes['thankyou_text']);
429 // FIXME: This hack forces height of editor to 175px. Need to modify QF classes for editors to allow passing
430 // explicit height and width.
431 $form->addWysiwyg('thankyou_footer_text', ts('Footer Text'), array('rows' => 2, 'cols' => 40));
435 * Add local and global form rules
441 function addRules() {
442 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
445 $this->addFormRule(array('CRM_Event_Form_ManageEvent_Registration', 'formRule'), $this);
449 * global validation rules for the form
451 * @param array $fields posted values of the form
453 * @return array list of errors to be posted back to the form
457 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.');
477 isset($values['registration_start_date']) &&
478 isset($values['registration_end_date'])
480 $start = CRM_Utils_Date
::processDate($values['registration_start_date']);
481 $end = CRM_Utils_Date
::processDate($values['registration_end_date']);
483 $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date');
487 //check that the selected profiles have either firstname+lastname or email required
489 CRM_Utils_Array
::value('custom_pre_id', $values),
490 CRM_Utils_Array
::value('custom_post_id', $values),
492 $additionalProfileIds = array(
493 CRM_Utils_Array
::value('additional_custom_pre_id', $values),
494 CRM_Utils_Array
::value('additional_custom_post_id', $values),
496 //additional profile fields default to main if not set
497 if (!is_numeric($additionalProfileIds[0])) {
498 $additionalProfileIds[0] = $profileIds[0];
500 if (!is_numeric($additionalProfileIds[1])) {
501 $additionalProfileIds[1] = $profileIds[1];
503 //add multiple profiles if set
504 self
::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple');
505 self
::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple');
506 $isProfileComplete = self
::isProfileComplete($profileIds);
507 $isAdditionalProfileComplete = self
::isProfileComplete($additionalProfileIds);
509 //Check main profiles have an email address available if 'send confirmation email' is selected
510 if ($values['is_email_confirm']) {
511 $emailFields = self
::getEmailFields($profileIds);
512 if (!count($emailFields)) {
513 $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected");
516 $additionalCustomPreId = $additionalCustomPostId = NULL;
517 $isPreError = $isPostError = TRUE;
518 if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) {
519 $types = array_merge(array('Individual'), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
520 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
522 //check for additional custom pre profile
523 $additionalCustomPreId = CRM_Utils_Array
::value('additional_custom_pre_id', $values);
524 if (!empty($additionalCustomPreId)) {
525 if (!($additionalCustomPreId == 'none')) {
526 $customPreId = $additionalCustomPreId;
533 $customPreId = !empty($values['custom_pre_id']) ?
$values['custom_pre_id'] : NULL;
535 //check whether the additional custom pre profile is of type 'Individual' and its subtypes
536 if (!empty($customPreId)) {
537 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPreId);
538 foreach ($types as $individualTypes) {
539 if (in_array($individualTypes, $profileTypes)) {
549 // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile
551 $additionalCustomPostId = CRM_Utils_Array
::value('additional_custom_post_id', $values);
552 if (!empty($additionalCustomPostId)) {
553 if (!($additionalCustomPostId == 'none')) {
554 $customPostId = $additionalCustomPostId;
557 $isPostError = FALSE;
561 $customPostId = !empty($values['custom_post_id']) ?
$values['custom_post_id'] : NULL;
563 //check whether the additional custom post profile is of type 'Individual' and its subtypes
564 if (!empty($customPostId)) {
565 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPostId);
566 foreach ($types as $individualTypes) {
567 if (in_array($individualTypes, $profileTypes)) {
568 $isPostError = FALSE;
574 $isPostError = FALSE;
577 if (empty($customPreId) && empty($customPostId)) {
578 $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
581 $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
585 if (!$isProfileComplete) {
586 $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.");
588 if (!$isAdditionalProfileComplete) {
589 $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.");
593 // $config = CRM_Core_Config::singleton();
594 // if ( $config->doNotAttachPDFReceipt ) {
595 // if (!empty($values['custom_post_id_multiple'])) {
596 // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) {
597 // if ( $customPostMultiple ) {
598 // $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' ) ) );
604 // if (!empty($values['is_multiple_registrations']) &&
605 // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) {
606 // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) {
607 // if ( $customPostMultiple ) {
608 // $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' ) ) );
615 if (!empty($errorMsg)) {
616 if (!empty($values['custom_post_id_multiple'])) {
617 foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) {
618 self
::buildMultipleProfileBottom($form, $count);
620 $form->assign('profilePostMultiple', $values['custom_post_id_multiple']);
622 if (!empty($values['additional_custom_post_id_multiple'])) {
623 foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) {
624 self
::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants'));
626 $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']);
631 if (!empty($errorMsg)) {
639 * Collect all email fields for an array of profile ids
643 static function getEmailFields($profileIds) {
644 $emailFields = array();
645 foreach ($profileIds as $profileId) {
646 if ($profileId && is_numeric($profileId)) {
647 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
648 foreach ($fields as $field) {
649 if (substr_count($field['name'], 'email')) {
650 $emailFields[] = $field;
659 * Check if a profile contains required fields
663 static function isProfileComplete($profileIds) {
664 $profileReqFields = array();
665 foreach ($profileIds as $profileId) {
666 if ($profileId && is_numeric($profileId)) {
667 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
668 foreach ($fields as $field) {
670 case substr_count($field['name'], 'email'):
671 $profileReqFields[] = 'email';
674 case substr_count($field['name'], 'first_name'):
675 $profileReqFields[] = 'first_name';
678 case substr_count($field['name'], 'last_name'):
679 $profileReqFields[] = 'last_name';
685 $profileComplete = (in_array('email', $profileReqFields)
686 ||
(in_array('first_name', $profileReqFields) && in_array('last_name', $profileReqFields))
688 return $profileComplete;
692 * Check if the profiles collect enough information to dedupe
697 function canProfilesDedupe($profileIds, $rgId = 0) {
699 // find the unsupervised rule
702 'used' => 'Unsupervised',
703 'contact_type' => 'Individual',
706 $rgParams['id'] = $rgId;
708 $activeRg = CRM_Dedupe_BAO_RuleGroup
::dedupeRuleFieldsWeight($rgParams);
710 // get the combinations that could be a match for the rule
711 $okCombos = $combos = array();
712 CRM_Dedupe_BAO_RuleGroup
::combos($activeRg[0], $activeRg[1], $combos);
714 // create an index of what combinations involve each field
716 foreach ($combos as $comboid => $combo) {
717 foreach ($combo as $cfield) {
718 $index[$cfield][$comboid] = true;
720 $combos[$comboid] = array_fill_keys($combo, 0);
721 $okCombos[$comboid] = array_fill_keys($combo, 2);
724 // get profiles and see if they have the necessary combos
725 $profileReqFields = array();
726 foreach ($profileIds as $profileId) {
727 if ($profileId && is_numeric($profileId)) {
728 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
730 // walk through the fields in the profile
731 foreach ($fields as $field) {
733 // check each of the fields in the index against the profile field
734 foreach ($index as $ifield => $icombos) {
735 if(strpos($field['name'], $ifield) !== false) {
737 // we found the field in the profile, now record it in the index
738 foreach ($icombos as $icombo => $dontcare) {
739 $combos[$icombo][$ifield] = ($combos[$icombo][$ifield] != 2 && !$field['is_required']) ?
1 : 2;
741 if ($combos[$icombo] == $okCombos[$icombo]) {
742 // if any combo is complete with 2s (all fields are present and required), we can go home
752 // check the combos to see if everything is > 0
753 foreach ($combos as $comboid => $combo) {
755 foreach ($combo as $cfield) {
760 // this combo isn't complete--skip to the next combo
764 if ($complete) { return 1; }
767 // no combo succeeded
772 * Add additional profiles from the form to an array of profile ids.
775 static function addMultipleProfiles(&$profileIds, $values, $field) {
776 if ($multipleProfiles = CRM_Utils_Array
::value($field, $values)) {
777 foreach ($multipleProfiles as $profileId) {
778 $profileIds[] = $profileId;
784 * Function to process the form
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);
797 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE); // CRM-11182
798 $params['is_multiple_registrations'] = CRM_Utils_Array
::value('is_multiple_registrations', $params, FALSE);
799 $params['allow_same_participant_emails'] = CRM_Utils_Array
::value('allow_same_participant_emails', $params, FALSE);
800 $params['requires_approval'] = CRM_Utils_Array
::value('requires_approval', $params, FALSE);
802 // reset is_email confirm if not online reg
803 if (!$params['is_online_registration']) {
804 $params['is_email_confirm'] = FALSE;
807 if (!$this->_isTemplate
) {
808 $params['registration_start_date'] = CRM_Utils_Date
::processDate($params['registration_start_date'],
809 $params['registration_start_date_time'],
812 $params['registration_end_date'] = CRM_Utils_Date
::processDate($params['registration_end_date'],
813 $params['registration_end_date_time'],
818 CRM_Event_BAO_Event
::add($params);
820 // also update the ProfileModule tables
821 $ufJoinParams = array(
823 'module' => 'CiviEvent',
824 'entity_table' => 'civicrm_event',
825 'entity_id' => $this->_id
,
829 // first delete all past entries
830 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
834 if (!empty($params['custom_pre_id'])) {
835 $uf[1] = $params['custom_pre_id'];
839 if (!empty($params['custom_post_id'])) {
840 $uf[2] = $params['custom_post_id'];
843 if (!empty($params['custom_post_id_multiple'])) {
844 $uf = array_merge($uf, $params['custom_post_id_multiple']);
846 $uf = array_values($uf);
848 foreach ($uf as $weight => $ufGroupId) {
849 $ufJoinParams['weight'] = $weight +
$wt;
850 $ufJoinParams['uf_group_id'] = $ufGroupId;
851 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
852 unset($ufJoinParams['id']);
855 // also update the ProfileModule tables
856 $ufJoinParamsAdd = array(
858 'module' => 'CiviEvent_Additional',
859 'entity_table' => 'civicrm_event',
860 'entity_id' => $this->_id
,
863 // first delete all past entries
864 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParamsAdd);
865 if (!empty($params['is_multiple_registrations'])) {
869 if (array_key_exists('additional_custom_pre_id', $params)) {
870 if (empty($params['additional_custom_pre_id'])) {
871 $ufAdd[1] = $params['custom_pre_id'];
874 elseif (CRM_Utils_Array
::value('additional_custom_pre_id', $params) == 'none') {}
876 $ufAdd[1] = $params['additional_custom_pre_id'];
881 if (array_key_exists('additional_custom_post_id', $params)) {
882 if (empty($params['additional_custom_post_id'])) {
883 $ufAdd[2] = $params['custom_post_id'];
885 elseif (CRM_Utils_Array
::value('additional_custom_post_id', $params) == 'none') {}
887 $ufAdd[2] = $params['additional_custom_post_id'];
891 if (!empty($params['additional_custom_post_id_multiple'])) {
892 $additionalPostMultiple = array();
893 foreach ($params['additional_custom_post_id_multiple'] as $key => $value) {
894 if (!$value && !empty($params['custom_post_id'])) {
895 $additionalPostMultiple[$key] = $params['custom_post_id'];
897 elseif ($value == 'none') {
901 $additionalPostMultiple[$key] = $value;
904 $ufAdd = array_merge($ufAdd, $additionalPostMultiple);
907 $ufAdd = array_values($ufAdd);
908 if (!empty($ufAdd)) {
909 foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) {
911 $ufJoinParamsAdd['weight'] = $weightAdd +
$wtAdd;
912 $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd;
914 CRM_Core_BAO_UFJoin
::create($ufJoinParamsAdd);
915 unset($ufJoinParamsAdd['id']);
920 // get the profiles to evaluate what they collect
922 CRM_Utils_Array
::value('custom_pre_id', $params),
923 CRM_Utils_Array
::value('custom_post_id', $params),
925 $additionalProfileIds = array(
926 CRM_Utils_Array
::value('additional_custom_pre_id', $params),
927 CRM_Utils_Array
::value('additional_custom_post_id', $params),
929 // additional profile fields default to main if not set
930 if (!is_numeric($additionalProfileIds[0])) {
931 $additionalProfileIds[0] = $profileIds[0];
933 if (!is_numeric($additionalProfileIds[1])) {
934 $additionalProfileIds[1] = $profileIds[1];
936 //add multiple profiles if set
937 self
::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple');
938 self
::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple');
941 $rgId = CRM_Utils_Array
::value('dedupe_rule_group_id', $params, 0);
943 switch (self
::canProfilesDedupe($profileIds, $rgId)) {
945 $dedupeTitle = 'Duplicate Matching Impossible';
946 $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.");
949 $dedupeTitle = 'Duplicate Contacts Possible';
950 $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.");
952 if (!empty($params['is_multiple_registrations'])) {
953 switch(self
::canProfilesDedupe($additionalProfileIds, $rgId)) {
955 $dedupeTitle = 'Duplicate Matching Impossible';
957 $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.");
960 $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.");
965 $dedupeTitle = 'Duplicate Contacts Possible';
966 $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.");
971 CRM_Core_Session
::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', array('expires' => 0));
974 // Update tab "disabled" css class
975 $this->ajaxResponse
['tabValid'] = !empty($params['is_online_registration']);
977 parent
::endPostProcess();
982 * Return a descriptive name for the page, used in wizard header
987 public function getTitle() {
988 return ts('Online Registration');