3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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 * Set variables up before form is built.
58 public function preProcess() {
59 $this->_addProfileBottom
= CRM_Utils_Array
::value('addProfileBottom', $_GET, FALSE);
60 $this->_profileBottomNum
= CRM_Utils_Array
::value('addProfileNum', $_GET, 0);
61 $this->_addProfileBottomAdd
= CRM_Utils_Array
::value('addProfileBottomAdd', $_GET, FALSE);
62 $this->_profileBottomNumAdd
= CRM_Utils_Array
::value('addProfileNumAdd', $_GET, 0);
66 $this->assign('addProfileBottom', $this->_addProfileBottom
);
67 $this->assign('profileBottomNum', $this->_profileBottomNum
);
69 $urlParams = "id={$this->_id}&addProfileBottom=1&qfKey={$this->controller->_key}";
70 $this->assign('addProfileParams', $urlParams);
72 if ($addProfileBottom = CRM_Utils_Array
::value('custom_post_id_multiple', $_POST)) {
73 foreach (array_keys($addProfileBottom) as $profileNum) {
74 self
::buildMultipleProfileBottom($this, $profileNum);
78 $this->assign('addProfileBottomAdd', $this->_addProfileBottomAdd
);
79 $this->assign('profileBottomNumAdd', $this->_profileBottomNumAdd
);
81 $urlParamsAdd = "id={$this->_id}&addProfileBottomAdd=1&qfKey={$this->controller->_key}";
82 $this->assign('addProfileParamsAdd', $urlParamsAdd);
84 if ($addProfileBottomAdd = CRM_Utils_Array
::value('additional_custom_post_id_multiple', $_POST)) {
85 foreach (array_keys($addProfileBottomAdd) as $profileNum) {
86 self
::buildMultipleProfileBottom($this, $profileNum, 'additional_', ts('Profile for Additional Participants'));
92 * Set default values for the form.
93 * the default values are retrieved from the database
98 public function setDefaultValues() {
99 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
102 $eventId = $this->_id
;
104 $defaults = parent
::setDefaultValues();
106 $this->setShowHide($defaults);
107 if (isset($eventId)) {
108 $params = array('id' => $eventId);
109 CRM_Event_BAO_Event
::retrieve($params, $defaults);
111 $ufJoinParams = array(
112 'entity_table' => 'civicrm_event',
113 'module' => 'CiviEvent',
114 'entity_id' => $eventId,
117 list($defaults['custom_pre_id'],
118 $defaults['custom_post']
119 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
121 // Get the id for the event registration profile
122 $eventRegistrationIdParams = $eventRegistrationIdDefaults = array(
123 'name' => 'event_registration',
125 CRM_Core_BAO_UFGroup
::retrieve($eventRegistrationIdParams, $eventRegistrationIdDefaults);
127 // Set event registration as the default profile if none selected
128 if (!$defaults['custom_pre_id'] && count($defaults['custom_post']) == 0) {
129 $defaults['custom_pre_id'] = CRM_Utils_Array
::value('id', $eventRegistrationIdDefaults);
131 if (isset($defaults['custom_post']) && is_numeric($defaults['custom_post'])) {
132 $defaults['custom_post_id'] = $defaults['custom_post'];
134 elseif (!empty($defaults['custom_post'])) {
135 $defaults['custom_post_id'] = $defaults['custom_post'][0];
136 unset($defaults['custom_post'][0]);
137 $this->_profilePostMultiple
= $defaults['custom_post'];
138 foreach ($defaults['custom_post'] as $key => $value) {
139 self
::buildMultipleProfileBottom($this, $key);
140 $defaults["custom_post_id_multiple[$key]"] = $value;
144 $this->assign('profilePostMultiple', CRM_Utils_Array
::value('custom_post', $defaults));
146 if (!empty($defaults['is_multiple_registrations'])) {
147 // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
149 $ufJoinAddParams = array(
150 'entity_table' => 'civicrm_event',
151 'module' => 'CiviEvent_Additional',
152 'entity_id' => $eventId,
155 list($defaults['additional_custom_pre_id'],
156 $defaults['additional_custom_post']
157 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinAddParams);
159 if (isset($defaults['additional_custom_post']) && is_numeric($defaults['additional_custom_post'])) {
160 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'];
162 elseif (!empty($defaults['additional_custom_post'])) {
163 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'][0];
164 unset($defaults['additional_custom_post'][0]);
166 $this->_profilePostMultipleAdd
= $defaults['additional_custom_post'];
167 foreach ($defaults['additional_custom_post'] as $key => $value) {
168 self
::buildMultipleProfileBottom($this, $key, 'additional_', ts('Profile for Additional Participants'));
169 $defaults["additional_custom_post_id_multiple[$key]"] = $value;
172 $this->assign('profilePostMultipleAdd', CRM_Utils_Array
::value('additional_custom_post', $defaults));
176 $defaults['is_email_confirm'] = 0;
179 // provide defaults for required fields if empty (and as a 'hint' for approval message field)
180 $defaults['registration_link_text'] = CRM_Utils_Array
::value('registration_link_text', $defaults, ts('Register Now'));
181 $defaults['confirm_title'] = CRM_Utils_Array
::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
182 $defaults['thankyou_title'] = CRM_Utils_Array
::value('thankyou_title', $defaults, ts('Thank You for Registering'));
183 $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.'));
185 if (!empty($defaults['registration_start_date'])) {
186 list($defaults['registration_start_date'], $defaults['registration_start_date_time'])
187 = CRM_Utils_Date
::setDateDefaults($defaults['registration_start_date'], 'activityDateTime');
190 if (!empty($defaults['registration_end_date'])) {
191 list($defaults['registration_end_date'], $defaults['registration_end_date_time'])
192 = CRM_Utils_Date
::setDateDefaults($defaults['registration_end_date'], 'activityDateTime');
199 * Fix what blocks to show/hide based on the default values set
201 * @param array $defaults
202 * The array of default values.
206 public function setShowHide($defaults) {
207 $this->_showHide
= new CRM_Core_ShowHideBlocks(array('registration' => 1),
210 if (empty($defaults)) {
211 $this->_showHide
->addHide('registration');
212 $this->_showHide
->addHide('id-approval-text');
215 if (empty($defaults['requires_approval'])) {
216 $this->_showHide
->addHide('id-approval-text');
219 $this->assign('defaultsEmpty', empty($defaults));
220 $this->_showHide
->addToTemplate();
224 * Build the form object.
228 public function buildQuickForm() {
229 if ($this->_addProfileBottom
) {
230 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNum
);
233 if ($this->_addProfileBottomAdd
) {
234 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNumAdd
, 'additional_', ts('Profile for Additional Participants'));
237 $this->applyFilter('__ALL__', 'trim');
238 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
240 $this->addElement('checkbox',
241 'is_online_registration',
242 ts('Allow Online Registration'),
245 'onclick' => "return showHideByValue('is_online_registration'," .
247 "'registration_blocks'," .
254 $this->add('text', 'registration_link_text', ts('Registration Link Text'));
256 if (!$this->_isTemplate
) {
257 $this->addDateTime('registration_start_date', ts('Registration Start Date'), FALSE, array('formatType' => 'activityDateTime'));
258 $this->addDateTime('registration_end_date', ts('Registration End Date'), FALSE, array('formatType' => 'activityDateTime'));
262 'used' => 'Supervised',
263 'contact_type' => 'Individual',
265 $dedupeRuleFields = CRM_Dedupe_BAO_Rule
::dedupeRuleFields($params);
267 foreach ($dedupeRuleFields as $key => $fields) {
268 $ruleFields[$key] = ucwords(str_replace('_', ' ', $fields));
271 $this->addElement('checkbox',
272 'is_multiple_registrations',
273 ts('Register multiple participants?')
276 $this->addElement('checkbox',
277 'allow_same_participant_emails',
278 ts('Same email address?')
280 $this->assign('ruleFields', json_encode($ruleFields));
282 $dedupeRules = array(
283 '' => '- Unsupervised rule -',
285 $dedupeRules +
= CRM_Dedupe_BAO_RuleGroup
::getByType('Individual');
286 $this->add('select', 'dedupe_rule_group_id', ts('Duplicate matching rule'), $dedupeRules);
288 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
289 if (in_array('Awaiting approval', $participantStatuses) and in_array('Pending from approval', $participantStatuses) and in_array('Rejected', $participantStatuses)) {
290 $this->addElement('checkbox',
292 ts('Require participant approval?'),
294 array('onclick' => "return showHideByValue('requires_approval', '', 'id-approval-text', 'table-row', 'radio', false);")
296 $this->add('textarea', 'approval_req_text', ts('Approval message'), $attributes['approval_req_text']);
299 $this->add('text', 'expiration_time', ts('Pending participant expiration (hours)'));
300 $this->addRule('expiration_time', ts('Please enter the number of hours (as an integer).'), 'integer');
302 self
::buildRegistrationBlock($this);
303 self
::buildConfirmationBlock($this);
304 self
::buildMailBlock($this);
305 self
::buildThankYouBlock($this);
307 parent
::buildQuickForm();
311 * Build Registration Block.
313 * @param CRM_Core_Form $form
316 public function buildRegistrationBlock(&$form) {
317 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'intro_text') +
array('class' => 'collapsed');
318 $form->add('wysiwyg', 'intro_text', ts('Introductory Text'), $attributes);
319 $form->add('wysiwyg', 'footer_text', ts('Footer Text'), $attributes);
321 extract(self
::getProfileSelectorTypes());
323 $form->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
324 $form->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
326 $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
327 $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
331 * Subroutine to insert a Profile Editor widget.
332 * depends on getProfileSelectorTypes
334 * @param array &$form
337 * @param string $prefix
338 * Dom element ID prefix.
339 * @param string $label
341 * @param array $configs
342 * Optional, for addProfileSelector(), defaults to using getProfileSelectorTypes().
344 public function buildMultipleProfileBottom(&$form, $count, $prefix = '', $label = 'Include Profile', $configs = NULL) {
345 extract((is_null($configs)) ? self
::getProfileSelectorTypes() : $configs);
346 $element = $prefix . "custom_post_id_multiple[$count]";
347 $label .= '<br />' . ts('(bottom of page)');
348 $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
352 * Create initializers for addprofileSelector.
355 * ['allowCoreTypes' => array, 'allowSubTypes' => array, 'profileEntities' => array]
357 public static function getProfileSelectorTypes() {
359 'allowCoreTypes' => array(),
360 'allowSubTypes' => array(),
361 'profileEntities' => array(),
364 $configs['allowCoreTypes'] = array_merge(array(
367 ), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
368 $configs['allowCoreTypes'][] = 'Participant';
370 $id = CRM_Utils_Request
::retrieve('id', 'Integer');
372 $participantEventType = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Event", $id, 'event_type_id', 'id');
373 $participantRole = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'default_role_id');
374 $configs['allowSubTypes']['ParticipantEventName'] = array($id);
375 $configs['allowSubTypes']['ParticipantEventType'] = array($participantEventType);
376 $configs['allowSubTypes']['ParticipantRole'] = array($participantRole);
378 $configs['profileEntities'][] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel');
379 $configs['profileEntities'][] = array(
380 'entity_name' => 'participant_1',
381 'entity_type' => 'ParticipantModel',
382 'entity_sub_type' => '*',
389 * Build Confirmation Block.
391 * @param CRM_Core_Form $form
394 public function buildConfirmationBlock(&$form) {
395 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
396 // CRM-11182 - Optional confirmation page for free events
397 $is_monetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $form->_id
, 'is_monetary');
398 $form->assign('is_monetary', $is_monetary);
399 if ($is_monetary == "0") {
400 $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);"));
402 $form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']);
403 $form->add('wysiwyg', 'confirm_text', ts('Introductory Text'), $attributes['confirm_text'] +
array('class' => 'collapsed'));
404 $form->add('wysiwyg', 'confirm_footer_text', ts('Footer Text'), $attributes['confirm_text'] +
array('class' => 'collapsed'));
410 * @param CRM_Core_Form $form
413 public function buildMailBlock(&$form) {
414 $form->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
415 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
416 $form->addYesNo('is_email_confirm', ts('Send Confirmation Email?'), NULL, NULL, array('onclick' => "return showHideByValue('is_email_confirm','','confirmEmail','block','radio',false);"));
417 $form->add('textarea', 'confirm_email_text', ts('Text'), $attributes['confirm_email_text']);
418 $form->add('text', 'cc_confirm', ts('CC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'cc_confirm'));
419 $form->addRule('cc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
420 $form->add('text', 'bcc_confirm', ts('BCC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'bcc_confirm'));
421 $form->addRule('bcc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
422 $form->add('text', 'confirm_from_name', ts('Confirm From Name'));
423 $form->add('text', 'confirm_from_email', ts('Confirm From Email'));
424 $form->addRule('confirm_from_email', ts('Email is not valid.'), 'email');
428 * @param CRM_Core_Form $form
430 public function buildThankYouBlock(&$form) {
431 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
432 $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']);
433 $form->add('wysiwyg', 'thankyou_text', ts('Introductory Text'), $attributes['thankyou_text'] +
array('class' => 'collapsed'));
434 $form->add('wysiwyg', 'thankyou_footer_text', ts('Footer Text'), $attributes['thankyou_text'] +
array('class' => 'collapsed'));
438 * Add local and global form rules.
443 public function addRules() {
444 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
447 $this->addFormRule(array('CRM_Event_Form_ManageEvent_Registration', 'formRule'), $this);
451 * Global validation rules for the form.
453 * @param array $values
455 * @param CRM_Core_Form $form
458 * list of errors to be posted back to the form
460 public static function formRule($values, $files, $form) {
461 if (!empty($values['is_online_registration'])) {
463 if (!$values['confirm_title']) {
464 $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page');
466 if (!$values['thankyou_title']) {
467 $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page');
469 if ($values['is_email_confirm']) {
470 if (!$values['confirm_from_name']) {
471 $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.');
474 if (!$values['confirm_from_email']) {
475 $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.');
480 isset($values['registration_start_date']) &&
481 isset($values['registration_end_date'])
483 $start = CRM_Utils_Date
::processDate($values['registration_start_date']);
484 $end = CRM_Utils_Date
::processDate($values['registration_end_date']);
486 $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date');
490 //check that the selected profiles have either firstname+lastname or email required
492 CRM_Utils_Array
::value('custom_pre_id', $values),
493 CRM_Utils_Array
::value('custom_post_id', $values),
495 $additionalProfileIds = array(
496 CRM_Utils_Array
::value('additional_custom_pre_id', $values),
497 CRM_Utils_Array
::value('additional_custom_post_id', $values),
499 //additional profile fields default to main if not set
500 if (!is_numeric($additionalProfileIds[0])) {
501 $additionalProfileIds[0] = $profileIds[0];
503 if (!is_numeric($additionalProfileIds[1])) {
504 $additionalProfileIds[1] = $profileIds[1];
506 //add multiple profiles if set
507 self
::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple');
508 self
::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple');
509 $isProfileComplete = self
::isProfileComplete($profileIds);
510 $isAdditionalProfileComplete = self
::isProfileComplete($additionalProfileIds);
512 //Check main profiles have an email address available if 'send confirmation email' is selected
513 if ($values['is_email_confirm']) {
514 $emailFields = self
::getEmailFields($profileIds);
515 if (!count($emailFields)) {
516 $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected");
519 $additionalCustomPreId = $additionalCustomPostId = NULL;
520 $isPreError = $isPostError = TRUE;
521 if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) {
522 $types = array_merge(array('Individual'), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
523 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
525 //check for additional custom pre profile
526 $additionalCustomPreId = CRM_Utils_Array
::value('additional_custom_pre_id', $values);
527 if (!empty($additionalCustomPreId)) {
528 if (!($additionalCustomPreId == 'none')) {
529 $customPreId = $additionalCustomPreId;
536 $customPreId = !empty($values['custom_pre_id']) ?
$values['custom_pre_id'] : NULL;
538 //check whether the additional custom pre profile is of type 'Individual' and its subtypes
539 if (!empty($customPreId)) {
540 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPreId);
541 foreach ($types as $individualTypes) {
542 if (in_array($individualTypes, $profileTypes)) {
552 // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile
554 $additionalCustomPostId = CRM_Utils_Array
::value('additional_custom_post_id', $values);
555 if (!empty($additionalCustomPostId)) {
556 if (!($additionalCustomPostId == 'none')) {
557 $customPostId = $additionalCustomPostId;
560 $isPostError = FALSE;
564 $customPostId = !empty($values['custom_post_id']) ?
$values['custom_post_id'] : NULL;
566 //check whether the additional custom post profile is of type 'Individual' and its subtypes
567 if (!empty($customPostId)) {
568 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPostId);
569 foreach ($types as $individualTypes) {
570 if (in_array($individualTypes, $profileTypes)) {
571 $isPostError = FALSE;
577 $isPostError = FALSE;
580 if (empty($customPreId) && empty($customPostId)) {
581 $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
584 $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
588 if (!$isProfileComplete) {
589 $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.");
591 if (!$isAdditionalProfileComplete) {
592 $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.");
596 // $config = CRM_Core_Config::singleton();
597 // if ( $config->doNotAttachPDFReceipt ) {
598 // if (!empty($values['custom_post_id_multiple'])) {
599 // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) {
600 // if ( $customPostMultiple ) {
601 // $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' ) ) );
607 // if (!empty($values['is_multiple_registrations']) &&
608 // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) {
609 // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) {
610 // if ( $customPostMultiple ) {
611 // $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' ) ) );
618 if (!empty($errorMsg)) {
619 if (!empty($values['custom_post_id_multiple'])) {
620 foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) {
621 self
::buildMultipleProfileBottom($form, $count);
623 $form->assign('profilePostMultiple', $values['custom_post_id_multiple']);
625 if (!empty($values['additional_custom_post_id_multiple'])) {
626 foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) {
627 self
::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants'));
629 $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']);
634 if (!empty($errorMsg)) {
642 * Collect all email fields for an array of profile ids.
647 public static function getEmailFields($profileIds) {
648 $emailFields = array();
649 foreach ($profileIds as $profileId) {
650 if ($profileId && is_numeric($profileId)) {
651 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
652 foreach ($fields as $field) {
653 if (substr_count($field['name'], 'email')) {
654 $emailFields[] = $field;
663 * Check if a profile contains required fields.
668 public static function isProfileComplete($profileIds) {
669 $profileReqFields = array();
670 foreach ($profileIds as $profileId) {
671 if ($profileId && is_numeric($profileId)) {
672 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
673 foreach ($fields as $field) {
675 case substr_count($field['name'], 'email'):
676 $profileReqFields[] = 'email';
679 case substr_count($field['name'], 'first_name'):
680 $profileReqFields[] = 'first_name';
683 case substr_count($field['name'], 'last_name'):
684 $profileReqFields[] = 'last_name';
690 $profileComplete = (in_array('email', $profileReqFields)
691 ||
(in_array('first_name', $profileReqFields) && in_array('last_name', $profileReqFields))
693 return $profileComplete;
697 * Check if the profiles collect enough information to dedupe.
703 public static function canProfilesDedupe($profileIds, $rgId = 0) {
704 // find the unsupervised rule
706 'used' => 'Unsupervised',
707 'contact_type' => 'Individual',
710 $rgParams['id'] = $rgId;
712 $activeRg = CRM_Dedupe_BAO_RuleGroup
::dedupeRuleFieldsWeight($rgParams);
714 // get the combinations that could be a match for the rule
715 $okCombos = $combos = array();
716 CRM_Dedupe_BAO_RuleGroup
::combos($activeRg[0], $activeRg[1], $combos);
718 // create an index of what combinations involve each field
720 foreach ($combos as $comboid => $combo) {
721 foreach ($combo as $cfield) {
722 $index[$cfield][$comboid] = TRUE;
724 $combos[$comboid] = array_fill_keys($combo, 0);
725 $okCombos[$comboid] = array_fill_keys($combo, 2);
728 // get profiles and see if they have the necessary combos
729 $profileReqFields = array();
730 foreach ($profileIds as $profileId) {
731 if ($profileId && is_numeric($profileId)) {
732 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
734 // walk through the fields in the profile
735 foreach ($fields as $field) {
737 // check each of the fields in the index against the profile field
738 foreach ($index as $ifield => $icombos) {
739 if (strpos($field['name'], $ifield) !== FALSE) {
741 // we found the field in the profile, now record it in the index
742 foreach ($icombos as $icombo => $dontcare) {
743 $combos[$icombo][$ifield] = ($combos[$icombo][$ifield] != 2 && !$field['is_required']) ?
1 : 2;
745 if ($combos[$icombo] == $okCombos[$icombo]) {
746 // if any combo is complete with 2s (all fields are present and required), we can go home
756 // check the combos to see if everything is > 0
757 foreach ($combos as $comboid => $combo) {
759 foreach ($combo as $cfield) {
764 // this combo isn't complete--skip to the next combo
773 // no combo succeeded
778 * Add additional profiles from the form to an array of profile ids.
780 public static function addMultipleProfiles(&$profileIds, $values, $field) {
781 if ($multipleProfiles = CRM_Utils_Array
::value($field, $values)) {
782 foreach ($multipleProfiles as $profileId) {
783 $profileIds[] = $profileId;
789 * Process the form submission.
794 public function postProcess() {
795 $params = $this->exportValues();
797 $params['id'] = $this->_id
;
800 $params['is_online_registration'] = CRM_Utils_Array
::value('is_online_registration', $params, FALSE);
801 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE); // CRM-11182
802 $params['is_multiple_registrations'] = CRM_Utils_Array
::value('is_multiple_registrations', $params, FALSE);
803 $params['allow_same_participant_emails'] = CRM_Utils_Array
::value('allow_same_participant_emails', $params, FALSE);
804 $params['requires_approval'] = CRM_Utils_Array
::value('requires_approval', $params, FALSE);
806 // reset is_email confirm if not online reg
807 if (!$params['is_online_registration']) {
808 $params['is_email_confirm'] = FALSE;
811 if (!$this->_isTemplate
) {
812 $params['registration_start_date'] = CRM_Utils_Date
::processDate($params['registration_start_date'],
813 $params['registration_start_date_time'],
816 $params['registration_end_date'] = CRM_Utils_Date
::processDate($params['registration_end_date'],
817 $params['registration_end_date_time'],
822 CRM_Event_BAO_Event
::add($params);
824 // also update the ProfileModule tables
825 $ufJoinParams = array(
827 'module' => 'CiviEvent',
828 'entity_table' => 'civicrm_event',
829 'entity_id' => $this->_id
,
832 // first delete all past entries
833 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
837 if (!empty($params['custom_pre_id'])) {
838 $uf[1] = $params['custom_pre_id'];
842 if (!empty($params['custom_post_id'])) {
843 $uf[2] = $params['custom_post_id'];
846 if (!empty($params['custom_post_id_multiple'])) {
847 $uf = array_merge($uf, $params['custom_post_id_multiple']);
849 $uf = array_values($uf);
851 foreach ($uf as $weight => $ufGroupId) {
852 $ufJoinParams['weight'] = $weight +
$wt;
853 $ufJoinParams['uf_group_id'] = $ufGroupId;
854 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
855 unset($ufJoinParams['id']);
858 // also update the ProfileModule tables
859 $ufJoinParamsAdd = array(
861 'module' => 'CiviEvent_Additional',
862 'entity_table' => 'civicrm_event',
863 'entity_id' => $this->_id
,
866 // first delete all past entries
867 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParamsAdd);
868 if (!empty($params['is_multiple_registrations'])) {
872 if (array_key_exists('additional_custom_pre_id', $params)) {
873 if (empty($params['additional_custom_pre_id'])) {
874 $ufAdd[1] = $params['custom_pre_id'];
877 elseif (CRM_Utils_Array
::value('additional_custom_pre_id', $params) == 'none') {
880 $ufAdd[1] = $params['additional_custom_pre_id'];
885 if (array_key_exists('additional_custom_post_id', $params)) {
886 if (empty($params['additional_custom_post_id'])) {
887 $ufAdd[2] = $params['custom_post_id'];
889 elseif (CRM_Utils_Array
::value('additional_custom_post_id', $params) == 'none') {
892 $ufAdd[2] = $params['additional_custom_post_id'];
896 if (!empty($params['additional_custom_post_id_multiple'])) {
897 $additionalPostMultiple = array();
898 foreach ($params['additional_custom_post_id_multiple'] as $key => $value) {
899 if (is_null($value) && !empty($params['custom_post_id'])) {
900 $additionalPostMultiple[$key] = $params['custom_post_id'];
902 elseif ($value == 'none') {
906 $additionalPostMultiple[$key] = $value;
909 $ufAdd = array_merge($ufAdd, $additionalPostMultiple);
912 $ufAdd = array_values($ufAdd);
913 if (!empty($ufAdd)) {
914 foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) {
916 $ufJoinParamsAdd['weight'] = $weightAdd +
$wtAdd;
917 $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd;
919 CRM_Core_BAO_UFJoin
::create($ufJoinParamsAdd);
920 unset($ufJoinParamsAdd['id']);
925 // get the profiles to evaluate what they collect
927 CRM_Utils_Array
::value('custom_pre_id', $params),
928 CRM_Utils_Array
::value('custom_post_id', $params),
930 $additionalProfileIds = array(
931 CRM_Utils_Array
::value('additional_custom_pre_id', $params),
932 CRM_Utils_Array
::value('additional_custom_post_id', $params),
934 // additional profile fields default to main if not set
935 if (!is_numeric($additionalProfileIds[0])) {
936 $additionalProfileIds[0] = $profileIds[0];
938 if (!is_numeric($additionalProfileIds[1])) {
939 $additionalProfileIds[1] = $profileIds[1];
941 //add multiple profiles if set
942 self
::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple');
943 self
::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple');
946 $rgId = CRM_Utils_Array
::value('dedupe_rule_group_id', $params, 0);
948 switch (self
::canProfilesDedupe($profileIds, $rgId)) {
950 $dedupeTitle = 'Duplicate Matching Impossible';
951 $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 $dedupeTitle = 'Duplicate Contacts Possible';
956 $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.");
958 if (!empty($params['is_multiple_registrations'])) {
959 switch (self
::canProfilesDedupe($additionalProfileIds, $rgId)) {
961 $dedupeTitle = 'Duplicate Matching Impossible';
963 $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.");
966 $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.");
972 $dedupeTitle = 'Duplicate Contacts Possible';
973 $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.");
978 CRM_Core_Session
::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', array('expires' => 0));
981 // Update tab "disabled" css class
982 $this->ajaxResponse
['tabValid'] = !empty($params['is_online_registration']);
984 parent
::endPostProcess();
988 * Return a descriptive name for the page, used in wizard header
992 public function getTitle() {
993 return ts('Online Registration');