3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2016
34 * This class generates form components for processing Event.
36 class CRM_Event_Form_ManageEvent_Registration
extends CRM_Event_Form_ManageEvent
{
39 * What blocks should we show and hide.
41 * @var CRM_Core_ShowHideBlocks
45 protected $_profilePostMultiple = array();
46 protected $_profilePostMultipleAdd = array();
49 * Set variables up before form is built.
51 public function preProcess() {
52 $this->_addProfileBottom
= CRM_Utils_Array
::value('addProfileBottom', $_GET, FALSE);
53 $this->_profileBottomNum
= CRM_Utils_Array
::value('addProfileNum', $_GET, 0);
54 $this->_addProfileBottomAdd
= CRM_Utils_Array
::value('addProfileBottomAdd', $_GET, FALSE);
55 $this->_profileBottomNumAdd
= CRM_Utils_Array
::value('addProfileNumAdd', $_GET, 0);
59 $this->assign('addProfileBottom', $this->_addProfileBottom
);
60 $this->assign('profileBottomNum', $this->_profileBottomNum
);
62 $urlParams = "id={$this->_id}&addProfileBottom=1&qfKey={$this->controller->_key}";
63 $this->assign('addProfileParams', $urlParams);
65 if ($addProfileBottom = CRM_Utils_Array
::value('custom_post_id_multiple', $_POST)) {
66 foreach (array_keys($addProfileBottom) as $profileNum) {
67 self
::buildMultipleProfileBottom($this, $profileNum);
71 $this->assign('addProfileBottomAdd', $this->_addProfileBottomAdd
);
72 $this->assign('profileBottomNumAdd', $this->_profileBottomNumAdd
);
74 $urlParamsAdd = "id={$this->_id}&addProfileBottomAdd=1&qfKey={$this->controller->_key}";
75 $this->assign('addProfileParamsAdd', $urlParamsAdd);
77 if ($addProfileBottomAdd = CRM_Utils_Array
::value('additional_custom_post_id_multiple', $_POST)) {
78 foreach (array_keys($addProfileBottomAdd) as $profileNum) {
79 self
::buildMultipleProfileBottom($this, $profileNum, 'additional_', ts('Profile for Additional Participants'));
85 * Set default values for the form.
87 * The default values are retrieved from the database.
89 public function setDefaultValues() {
90 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
93 $eventId = $this->_id
;
95 $defaults = parent
::setDefaultValues();
97 $this->setShowHide($defaults);
98 if (isset($eventId)) {
99 $params = array('id' => $eventId);
100 CRM_Event_BAO_Event
::retrieve($params, $defaults);
102 $ufJoinParams = array(
103 'entity_table' => 'civicrm_event',
104 'module' => 'CiviEvent',
105 'entity_id' => $eventId,
108 list($defaults['custom_pre_id'],
109 $defaults['custom_post']
110 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
112 // Get the id for the event registration profile
113 $eventRegistrationIdParams = $eventRegistrationIdDefaults = array(
114 'name' => 'event_registration',
116 CRM_Core_BAO_UFGroup
::retrieve($eventRegistrationIdParams, $eventRegistrationIdDefaults);
118 // Set event registration as the default profile if none selected
119 if (!$defaults['custom_pre_id'] && count($defaults['custom_post']) == 0) {
120 $defaults['custom_pre_id'] = CRM_Utils_Array
::value('id', $eventRegistrationIdDefaults);
122 if (isset($defaults['custom_post']) && is_numeric($defaults['custom_post'])) {
123 $defaults['custom_post_id'] = $defaults['custom_post'];
125 elseif (!empty($defaults['custom_post'])) {
126 $defaults['custom_post_id'] = $defaults['custom_post'][0];
127 unset($defaults['custom_post'][0]);
128 $this->_profilePostMultiple
= $defaults['custom_post'];
129 foreach ($defaults['custom_post'] as $key => $value) {
130 self
::buildMultipleProfileBottom($this, $key);
131 $defaults["custom_post_id_multiple[$key]"] = $value;
135 $this->assign('profilePostMultiple', CRM_Utils_Array
::value('custom_post', $defaults));
137 // CRM-17745: Make max additional participants configurable
138 if (empty($defaults['max_additional_participants'])) {
139 $defaults['max_additional_participants'] = 9;
142 if (!empty($defaults['is_multiple_registrations'])) {
143 // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
145 $ufJoinAddParams = array(
146 'entity_table' => 'civicrm_event',
147 'module' => 'CiviEvent_Additional',
148 'entity_id' => $eventId,
151 list($defaults['additional_custom_pre_id'],
152 $defaults['additional_custom_post']
153 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinAddParams);
155 if (isset($defaults['additional_custom_post']) && is_numeric($defaults['additional_custom_post'])) {
156 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'];
158 elseif (!empty($defaults['additional_custom_post'])) {
159 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'][0];
160 unset($defaults['additional_custom_post'][0]);
162 $this->_profilePostMultipleAdd
= $defaults['additional_custom_post'];
163 foreach ($defaults['additional_custom_post'] as $key => $value) {
164 self
::buildMultipleProfileBottom($this, $key, 'additional_', ts('Profile for Additional Participants'));
165 $defaults["additional_custom_post_id_multiple[$key]"] = $value;
168 $this->assign('profilePostMultipleAdd', CRM_Utils_Array
::value('additional_custom_post', $defaults));
172 $defaults['is_email_confirm'] = 0;
175 // provide defaults for required fields if empty (and as a 'hint' for approval message field)
176 $defaults['registration_link_text'] = CRM_Utils_Array
::value('registration_link_text', $defaults, ts('Register Now'));
177 $defaults['confirm_title'] = CRM_Utils_Array
::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
178 $defaults['thankyou_title'] = CRM_Utils_Array
::value('thankyou_title', $defaults, ts('Thank You for Registering'));
179 $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.'));
181 if (!empty($defaults['registration_start_date'])) {
182 list($defaults['registration_start_date'], $defaults['registration_start_date_time'])
183 = CRM_Utils_Date
::setDateDefaults($defaults['registration_start_date'], 'activityDateTime');
186 if (!empty($defaults['registration_end_date'])) {
187 list($defaults['registration_end_date'], $defaults['registration_end_date_time'])
188 = CRM_Utils_Date
::setDateDefaults($defaults['registration_end_date'], 'activityDateTime');
195 * Fix what blocks to show/hide based on the default values set
197 * @param array $defaults
198 * The array of default values.
202 public function setShowHide($defaults) {
203 $this->_showHide
= new CRM_Core_ShowHideBlocks(array('registration' => 1),
206 if (empty($defaults)) {
207 $this->_showHide
->addHide('registration');
208 $this->_showHide
->addHide('id-approval-text');
211 if (empty($defaults['requires_approval'])) {
212 $this->_showHide
->addHide('id-approval-text');
215 $this->assign('defaultsEmpty', empty($defaults));
216 $this->_showHide
->addToTemplate();
220 * Build the form object.
224 public function buildQuickForm() {
225 if ($this->_addProfileBottom
) {
226 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNum
);
229 if ($this->_addProfileBottomAdd
) {
230 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNumAdd
, 'additional_', ts('Profile for Additional Participants'));
233 $this->applyFilter('__ALL__', 'trim');
234 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
236 $this->addElement('checkbox',
237 'is_online_registration',
238 ts('Allow Online Registration'),
241 'onclick' => "return showHideByValue('is_online_registration'," .
243 "'registration_blocks'," .
250 $this->add('text', 'registration_link_text', ts('Registration Link Text'));
252 if (!$this->_isTemplate
) {
253 $this->addDateTime('registration_start_date', ts('Registration Start Date'), FALSE, array('formatType' => 'activityDateTime'));
254 $this->addDateTime('registration_end_date', ts('Registration End Date'), FALSE, array('formatType' => 'activityDateTime'));
258 'used' => 'Supervised',
259 'contact_type' => 'Individual',
261 $dedupeRuleFields = CRM_Dedupe_BAO_Rule
::dedupeRuleFields($params);
263 foreach ($dedupeRuleFields as $key => $fields) {
264 $ruleFields[$key] = ucwords(str_replace('_', ' ', $fields));
267 $this->addElement('checkbox',
268 'is_multiple_registrations',
269 ts('Register multiple participants?')
272 // CRM-17745: Make maximum additional participants configurable
273 $numericOptions = CRM_Core_SelectValues
::getNumericOptions(1, 9);
274 $this->add('select', 'max_additional_participants', ts('Maximum additional participants'), $numericOptions, FALSE, array('class' => 'required'));
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');
301 $this->addField('allow_selfcancelxfer', array('label' => ts('Allow self-service cancellation or transfer?'), 'type' => 'advcheckbox'));
302 $this->add('text', 'selfcancelxfer_time', ts('Cancellation or transfer time limit (hours)'));
303 $this->addRule('selfcancelxfer_time', ts('Please enter the number of hours (as an integer).'), 'integer');
304 self
::buildRegistrationBlock($this);
305 self
::buildConfirmationBlock($this);
306 self
::buildMailBlock($this);
307 self
::buildThankYouBlock($this);
309 parent
::buildQuickForm();
313 * Build Registration Block.
315 * @param CRM_Core_Form $form
318 public function buildRegistrationBlock(&$form) {
319 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'intro_text') +
array('class' => 'collapsed');
320 $form->add('wysiwyg', 'intro_text', ts('Introductory Text'), $attributes);
321 $form->add('wysiwyg', 'footer_text', ts('Footer Text'), $attributes);
323 extract(self
::getProfileSelectorTypes());
325 $form->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
326 $form->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
328 $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
329 $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
333 * Subroutine to insert a Profile Editor widget.
334 * depends on getProfileSelectorTypes
336 * @param array &$form
339 * @param string $prefix
340 * Dom element ID prefix.
341 * @param string $label
343 * @param array $configs
344 * Optional, for addProfileSelector(), defaults to using getProfileSelectorTypes().
346 public function buildMultipleProfileBottom(&$form, $count, $prefix = '', $label = 'Include Profile', $configs = NULL) {
347 extract((is_null($configs)) ? self
::getProfileSelectorTypes() : $configs);
348 $element = $prefix . "custom_post_id_multiple[$count]";
349 $label .= '<br />' . ts('(bottom of page)');
350 $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
354 * Create initializers for addprofileSelector.
357 * ['allowCoreTypes' => array, 'allowSubTypes' => array, 'profileEntities' => array]
359 public static function getProfileSelectorTypes() {
361 'allowCoreTypes' => array(),
362 'allowSubTypes' => array(),
363 'profileEntities' => array(),
364 'usedFor' => array(),
367 $configs['allowCoreTypes'] = array_merge(array(
370 ), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
371 $configs['allowCoreTypes'][] = 'Participant';
372 if (CRM_Core_Permission
::check('manage event profiles') && !CRM_Core_Permission
::check('administer CiviCRM')) {
373 $configs['usedFor'][] = 'CiviEvent';
376 $id = CRM_Utils_Request
::retrieve('id', 'Integer');
378 $participantEventType = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Event", $id, 'event_type_id', 'id');
379 $participantRole = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'default_role_id');
380 $configs['allowSubTypes']['ParticipantEventName'] = array($id);
381 $configs['allowSubTypes']['ParticipantEventType'] = array($participantEventType);
382 $configs['allowSubTypes']['ParticipantRole'] = array($participantRole);
384 $configs['profileEntities'][] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel');
385 $configs['profileEntities'][] = array(
386 'entity_name' => 'participant_1',
387 'entity_type' => 'ParticipantModel',
388 'entity_sub_type' => '*',
395 * Build Confirmation Block.
397 * @param CRM_Core_Form $form
400 public function buildConfirmationBlock(&$form) {
401 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
402 // CRM-11182 - Optional confirmation page for free events
403 $is_monetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $form->_id
, 'is_monetary');
404 $form->assign('is_monetary', $is_monetary);
405 if ($is_monetary == "0") {
406 $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);"));
408 $form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']);
409 $form->add('wysiwyg', 'confirm_text', ts('Introductory Text'), $attributes['confirm_text'] +
array('class' => 'collapsed'));
410 $form->add('wysiwyg', 'confirm_footer_text', ts('Footer Text'), $attributes['confirm_text'] +
array('class' => 'collapsed'));
416 * @param CRM_Core_Form $form
419 public function buildMailBlock(&$form) {
420 $form->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
421 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
422 $form->addYesNo('is_email_confirm', ts('Send Confirmation Email?'), NULL, NULL, array('onclick' => "return showHideByValue('is_email_confirm','','confirmEmail','block','radio',false);"));
423 $form->add('textarea', 'confirm_email_text', ts('Text'), $attributes['confirm_email_text']);
424 $form->add('text', 'cc_confirm', ts('CC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'cc_confirm'));
425 $form->addRule('cc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
426 $form->add('text', 'bcc_confirm', ts('BCC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'bcc_confirm'));
427 $form->addRule('bcc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
428 $form->add('text', 'confirm_from_name', ts('Confirm From Name'));
429 $form->add('text', 'confirm_from_email', ts('Confirm From Email'));
430 $form->addRule('confirm_from_email', ts('Email is not valid.'), 'email');
434 * @param CRM_Core_Form $form
436 public function buildThankYouBlock(&$form) {
437 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
438 $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']);
439 $form->add('wysiwyg', 'thankyou_text', ts('Introductory Text'), $attributes['thankyou_text'] +
array('class' => 'collapsed'));
440 $form->add('wysiwyg', 'thankyou_footer_text', ts('Footer Text'), $attributes['thankyou_text'] +
array('class' => 'collapsed'));
444 * Add local and global form rules.
449 public function addRules() {
450 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
453 $this->addFormRule(array('CRM_Event_Form_ManageEvent_Registration', 'formRule'), $this);
457 * Global validation rules for the form.
459 * @param array $values
461 * @param CRM_Core_Form $form
464 * list of errors to be posted back to the form
466 public static function formRule($values, $files, $form) {
467 if (!empty($values['is_online_registration'])) {
469 if (!$values['confirm_title']) {
470 $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page');
472 if (!$values['thankyou_title']) {
473 $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page');
475 if ($values['is_email_confirm']) {
476 if (!$values['confirm_from_name']) {
477 $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.');
480 if (!$values['confirm_from_email']) {
481 $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.');
486 isset($values['registration_start_date']) &&
487 isset($values['registration_end_date'])
489 $start = CRM_Utils_Date
::processDate($values['registration_start_date']);
490 $end = CRM_Utils_Date
::processDate($values['registration_end_date']);
492 $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date');
496 //check that the selected profiles have either firstname+lastname or email required
498 CRM_Utils_Array
::value('custom_pre_id', $values),
499 CRM_Utils_Array
::value('custom_post_id', $values),
501 $additionalProfileIds = array(
502 CRM_Utils_Array
::value('additional_custom_pre_id', $values),
503 CRM_Utils_Array
::value('additional_custom_post_id', $values),
505 //additional profile fields default to main if not set
506 if (!is_numeric($additionalProfileIds[0])) {
507 $additionalProfileIds[0] = $profileIds[0];
509 if (!is_numeric($additionalProfileIds[1])) {
510 $additionalProfileIds[1] = $profileIds[1];
512 //add multiple profiles if set
513 self
::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple');
514 self
::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple');
515 $isProfileComplete = self
::isProfileComplete($profileIds);
516 $isAdditionalProfileComplete = self
::isProfileComplete($additionalProfileIds);
518 //Check main profiles have an email address available if 'send confirmation email' is selected
519 if ($values['is_email_confirm']) {
520 $emailFields = self
::getEmailFields($profileIds);
521 if (!count($emailFields)) {
522 $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected");
525 $additionalCustomPreId = $additionalCustomPostId = NULL;
526 $isPreError = $isPostError = TRUE;
527 if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) {
528 $types = array_merge(array('Individual'), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
529 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
531 //check for additional custom pre profile
532 $additionalCustomPreId = CRM_Utils_Array
::value('additional_custom_pre_id', $values);
533 if (!empty($additionalCustomPreId)) {
534 if (!($additionalCustomPreId == 'none')) {
535 $customPreId = $additionalCustomPreId;
542 $customPreId = !empty($values['custom_pre_id']) ?
$values['custom_pre_id'] : NULL;
544 //check whether the additional custom pre profile is of type 'Individual' and its subtypes
545 if (!empty($customPreId)) {
546 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPreId);
547 foreach ($types as $individualTypes) {
548 if (in_array($individualTypes, $profileTypes)) {
558 // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile
560 $additionalCustomPostId = CRM_Utils_Array
::value('additional_custom_post_id', $values);
561 if (!empty($additionalCustomPostId)) {
562 if (!($additionalCustomPostId == 'none')) {
563 $customPostId = $additionalCustomPostId;
566 $isPostError = FALSE;
570 $customPostId = !empty($values['custom_post_id']) ?
$values['custom_post_id'] : NULL;
572 //check whether the additional custom post profile is of type 'Individual' and its subtypes
573 if (!empty($customPostId)) {
574 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPostId);
575 foreach ($types as $individualTypes) {
576 if (in_array($individualTypes, $profileTypes)) {
577 $isPostError = FALSE;
583 $isPostError = FALSE;
586 if (empty($customPreId) && empty($customPostId)) {
587 $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
590 $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
594 if (!$isProfileComplete) {
595 $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.");
597 if (!$isAdditionalProfileComplete) {
598 $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.");
602 // $config = CRM_Core_Config::singleton();
603 // if ( $config->doNotAttachPDFReceipt ) {
604 // if (!empty($values['custom_post_id_multiple'])) {
605 // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) {
606 // if ( $customPostMultiple ) {
607 // $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' ) ) );
613 // if (!empty($values['is_multiple_registrations']) &&
614 // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) {
615 // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) {
616 // if ( $customPostMultiple ) {
617 // $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' ) ) );
624 if (!empty($errorMsg)) {
625 if (!empty($values['custom_post_id_multiple'])) {
626 foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) {
627 self
::buildMultipleProfileBottom($form, $count);
629 $form->assign('profilePostMultiple', $values['custom_post_id_multiple']);
631 if (!empty($values['additional_custom_post_id_multiple'])) {
632 foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) {
633 self
::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants'));
635 $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']);
640 if (!empty($errorMsg)) {
648 * Collect all email fields for an array of profile ids.
653 public static function getEmailFields($profileIds) {
654 $emailFields = array();
655 foreach ($profileIds as $profileId) {
656 if ($profileId && is_numeric($profileId)) {
657 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
658 foreach ($fields as $field) {
659 if (substr_count($field['name'], 'email')) {
660 $emailFields[] = $field;
669 * Check if a profile contains required fields.
674 public static function isProfileComplete($profileIds) {
675 $profileReqFields = array();
676 foreach ($profileIds as $profileId) {
677 if ($profileId && is_numeric($profileId)) {
678 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
679 foreach ($fields as $field) {
681 case substr_count($field['name'], 'email'):
682 $profileReqFields[] = 'email';
685 case substr_count($field['name'], 'first_name'):
686 $profileReqFields[] = 'first_name';
689 case substr_count($field['name'], 'last_name'):
690 $profileReqFields[] = 'last_name';
696 $profileComplete = (in_array('email', $profileReqFields)
697 ||
(in_array('first_name', $profileReqFields) && in_array('last_name', $profileReqFields))
699 return $profileComplete;
703 * Check if the profiles collect enough information to dedupe.
709 public static function canProfilesDedupe($profileIds, $rgId = 0) {
710 // find the unsupervised rule
712 'used' => 'Unsupervised',
713 'contact_type' => 'Individual',
716 $rgParams['id'] = $rgId;
718 $activeRg = CRM_Dedupe_BAO_RuleGroup
::dedupeRuleFieldsWeight($rgParams);
720 // get the combinations that could be a match for the rule
721 $okCombos = $combos = array();
722 CRM_Dedupe_BAO_RuleGroup
::combos($activeRg[0], $activeRg[1], $combos);
724 // create an index of what combinations involve each field
726 foreach ($combos as $comboid => $combo) {
727 foreach ($combo as $cfield) {
728 $index[$cfield][$comboid] = TRUE;
730 $combos[$comboid] = array_fill_keys($combo, 0);
731 $okCombos[$comboid] = array_fill_keys($combo, 2);
734 // get profiles and see if they have the necessary combos
735 $profileReqFields = array();
736 foreach ($profileIds as $profileId) {
737 if ($profileId && is_numeric($profileId)) {
738 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
740 // walk through the fields in the profile
741 foreach ($fields as $field) {
743 // check each of the fields in the index against the profile field
744 foreach ($index as $ifield => $icombos) {
745 if (strpos($field['name'], $ifield) !== FALSE) {
747 // we found the field in the profile, now record it in the index
748 foreach ($icombos as $icombo => $dontcare) {
749 $combos[$icombo][$ifield] = ($combos[$icombo][$ifield] != 2 && !$field['is_required']) ?
1 : 2;
751 if ($combos[$icombo] == $okCombos[$icombo]) {
752 // if any combo is complete with 2s (all fields are present and required), we can go home
762 // check the combos to see if everything is > 0
763 foreach ($combos as $comboid => $combo) {
765 foreach ($combo as $cfield) {
770 // this combo isn't complete--skip to the next combo
779 // no combo succeeded
784 * Add additional profiles from the form to an array of profile ids.
786 * @param array $profileIds
787 * @param array $values
788 * @param string $field
790 public static function addMultipleProfiles(&$profileIds, $values, $field) {
791 if ($multipleProfiles = CRM_Utils_Array
::value($field, $values)) {
792 foreach ($multipleProfiles as $profileId) {
793 $profileIds[] = $profileId;
799 * Process the form submission.
804 public function postProcess() {
805 $params = $this->exportValues();
807 $params['id'] = $this->_id
;
810 $params['is_online_registration'] = CRM_Utils_Array
::value('is_online_registration', $params, FALSE);
811 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE); // CRM-11182
812 $params['is_multiple_registrations'] = CRM_Utils_Array
::value('is_multiple_registrations', $params, FALSE);
813 $params['allow_same_participant_emails'] = CRM_Utils_Array
::value('allow_same_participant_emails', $params, FALSE);
814 $params['requires_approval'] = CRM_Utils_Array
::value('requires_approval', $params, FALSE);
816 // reset is_email confirm if not online reg
817 if (!$params['is_online_registration']) {
818 $params['is_email_confirm'] = FALSE;
820 if (!empty($params['allow_selfcancelxfer'])) {
821 $params['selfcancelxfer_time'] = !empty($params['selfcancelxfer_time']) ?
$params['selfcancelxfer_time'] : 0;
824 if (!$this->_isTemplate
) {
825 $params['registration_start_date'] = CRM_Utils_Date
::processDate($params['registration_start_date'],
826 $params['registration_start_date_time'],
829 $params['registration_end_date'] = CRM_Utils_Date
::processDate($params['registration_end_date'],
830 $params['registration_end_date_time'],
835 CRM_Event_BAO_Event
::add($params);
837 // also update the ProfileModule tables
838 $ufJoinParams = array(
840 'module' => 'CiviEvent',
841 'entity_table' => 'civicrm_event',
842 'entity_id' => $this->_id
,
845 // first delete all past entries
846 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
850 if (!empty($params['custom_pre_id'])) {
851 $uf[1] = $params['custom_pre_id'];
855 if (!empty($params['custom_post_id'])) {
856 $uf[2] = $params['custom_post_id'];
859 if (!empty($params['custom_post_id_multiple'])) {
860 $uf = array_merge($uf, $params['custom_post_id_multiple']);
862 $uf = array_values($uf);
864 foreach ($uf as $weight => $ufGroupId) {
865 $ufJoinParams['weight'] = $weight +
$wt;
866 $ufJoinParams['uf_group_id'] = $ufGroupId;
867 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
868 unset($ufJoinParams['id']);
871 // also update the ProfileModule tables
872 $ufJoinParamsAdd = array(
874 'module' => 'CiviEvent_Additional',
875 'entity_table' => 'civicrm_event',
876 'entity_id' => $this->_id
,
879 // first delete all past entries
880 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParamsAdd);
881 if (!empty($params['is_multiple_registrations'])) {
885 if (array_key_exists('additional_custom_pre_id', $params)) {
886 if (empty($params['additional_custom_pre_id'])) {
887 $ufAdd[1] = $params['custom_pre_id'];
890 elseif (CRM_Utils_Array
::value('additional_custom_pre_id', $params) == 'none') {
893 $ufAdd[1] = $params['additional_custom_pre_id'];
898 if (array_key_exists('additional_custom_post_id', $params)) {
899 if (empty($params['additional_custom_post_id'])) {
900 $ufAdd[2] = $params['custom_post_id'];
902 elseif (CRM_Utils_Array
::value('additional_custom_post_id', $params) == 'none') {
905 $ufAdd[2] = $params['additional_custom_post_id'];
909 if (!empty($params['additional_custom_post_id_multiple'])) {
910 $additionalPostMultiple = array();
911 foreach ($params['additional_custom_post_id_multiple'] as $key => $value) {
912 if (is_null($value) && !empty($params['custom_post_id'])) {
913 $additionalPostMultiple[$key] = $params['custom_post_id'];
915 elseif ($value == 'none') {
919 $additionalPostMultiple[$key] = $value;
922 $ufAdd = array_merge($ufAdd, $additionalPostMultiple);
925 $ufAdd = array_values($ufAdd);
926 if (!empty($ufAdd)) {
927 foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) {
929 $ufJoinParamsAdd['weight'] = $weightAdd +
$wtAdd;
930 $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd;
932 CRM_Core_BAO_UFJoin
::create($ufJoinParamsAdd);
933 unset($ufJoinParamsAdd['id']);
938 // get the profiles to evaluate what they collect
940 CRM_Utils_Array
::value('custom_pre_id', $params),
941 CRM_Utils_Array
::value('custom_post_id', $params),
943 $additionalProfileIds = array(
944 CRM_Utils_Array
::value('additional_custom_pre_id', $params),
945 CRM_Utils_Array
::value('additional_custom_post_id', $params),
947 // additional profile fields default to main if not set
948 if (!is_numeric($additionalProfileIds[0])) {
949 $additionalProfileIds[0] = $profileIds[0];
951 if (!is_numeric($additionalProfileIds[1])) {
952 $additionalProfileIds[1] = $profileIds[1];
954 //add multiple profiles if set
955 self
::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple');
956 self
::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple');
959 $rgId = CRM_Utils_Array
::value('dedupe_rule_group_id', $params, 0);
961 switch (self
::canProfilesDedupe($profileIds, $rgId)) {
963 $dedupeTitle = 'Duplicate Matching Impossible';
964 $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.");
968 $dedupeTitle = 'Duplicate Contacts Possible';
969 $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.");
971 if (!empty($params['is_multiple_registrations'])) {
972 switch (self
::canProfilesDedupe($additionalProfileIds, $rgId)) {
974 $dedupeTitle = 'Duplicate Matching Impossible';
976 $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.");
979 $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.");
985 $dedupeTitle = 'Duplicate Contacts Possible';
986 $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.");
991 CRM_Core_Session
::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', array('expires' => 0));
994 // Update tab "disabled" css class
995 $this->ajaxResponse
['tabValid'] = !empty($params['is_online_registration']);
997 parent
::endPostProcess();
1001 * Return a descriptive name for the page, used in wizard header
1005 public function getTitle() {
1006 return ts('Online Registration');