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('perm', 0);
79 $ufGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
80 $ufCreate = CRM_ACL_API
::group(CRM_Core_Permission
::CREATE
, NULL, 'civicrm_uf_group', $ufGroups);
81 $ufEdit = CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_uf_group', $ufGroups);
82 $checkPermission = array(
85 'manage event profiles',
88 if (CRM_Core_Permission
::check($checkPermission) ||
!empty($ufCreate) ||
!empty($ufEdit)) {
89 $this->assign('perm', 1);
92 $this->assign('addProfileBottomAdd', $this->_addProfileBottomAdd
);
93 $this->assign('profileBottomNumAdd', $this->_profileBottomNumAdd
);
95 $urlParamsAdd = "id={$this->_id}&addProfileBottomAdd=1&qfKey={$this->controller->_key}";
96 $this->assign('addProfileParamsAdd', $urlParamsAdd);
98 if ($addProfileBottomAdd = CRM_Utils_Array
::value('additional_custom_post_id_multiple', $_POST)) {
99 foreach (array_keys($addProfileBottomAdd) as $profileNum) {
100 self
::buildMultipleProfileBottom($this, $profileNum, 'additional_', ts('Profile for Additional Participants'));
106 * Set default values for the form.
107 * the default values are retrieved from the database
112 public function setDefaultValues() {
113 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
116 $eventId = $this->_id
;
118 $defaults = parent
::setDefaultValues();
120 $this->setShowHide($defaults);
121 if (isset($eventId)) {
122 $params = array('id' => $eventId);
123 CRM_Event_BAO_Event
::retrieve($params, $defaults);
125 $ufJoinParams = array(
126 'entity_table' => 'civicrm_event',
127 'module' => 'CiviEvent',
128 'entity_id' => $eventId,
131 list($defaults['custom_pre_id'],
132 $defaults['custom_post']
133 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
135 // Get the id for the event registration profile
136 $eventRegistrationIdParams = $eventRegistrationIdDefaults = array(
137 'name' => 'event_registration',
139 CRM_Core_BAO_UFGroup
::retrieve($eventRegistrationIdParams, $eventRegistrationIdDefaults);
141 // Set event registration as the default profile if none selected
142 if (!$defaults['custom_pre_id'] && count($defaults['custom_post']) == 0) {
143 $defaults['custom_pre_id'] = CRM_Utils_Array
::value('id', $eventRegistrationIdDefaults);
145 if (isset($defaults['custom_post']) && is_numeric($defaults['custom_post'])) {
146 $defaults['custom_post_id'] = $defaults['custom_post'];
148 elseif (!empty($defaults['custom_post'])) {
149 $defaults['custom_post_id'] = $defaults['custom_post'][0];
150 unset($defaults['custom_post'][0]);
151 $this->_profilePostMultiple
= $defaults['custom_post'];
152 foreach ($defaults['custom_post'] as $key => $value) {
153 self
::buildMultipleProfileBottom($this, $key);
154 $defaults["custom_post_id_multiple[$key]"] = $value;
158 $this->assign('profilePostMultiple', CRM_Utils_Array
::value('custom_post', $defaults));
160 if (!empty($defaults['is_multiple_registrations'])) {
161 // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active)
163 $ufJoinAddParams = array(
164 'entity_table' => 'civicrm_event',
165 'module' => 'CiviEvent_Additional',
166 'entity_id' => $eventId,
169 list($defaults['additional_custom_pre_id'],
170 $defaults['additional_custom_post']
171 ) = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinAddParams);
173 if (isset($defaults['additional_custom_post']) && is_numeric($defaults['additional_custom_post'])) {
174 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'];
176 elseif (!empty($defaults['additional_custom_post'])) {
177 $defaults['additional_custom_post_id'] = $defaults['additional_custom_post'][0];
178 unset($defaults['additional_custom_post'][0]);
180 $this->_profilePostMultipleAdd
= $defaults['additional_custom_post'];
181 foreach ($defaults['additional_custom_post'] as $key => $value) {
182 self
::buildMultipleProfileBottom($this, $key, 'additional_', ts('Profile for Additional Participants'));
183 $defaults["additional_custom_post_id_multiple[$key]"] = $value;
186 $this->assign('profilePostMultipleAdd', CRM_Utils_Array
::value('additional_custom_post', $defaults));
190 $defaults['is_email_confirm'] = 0;
193 // provide defaults for required fields if empty (and as a 'hint' for approval message field)
194 $defaults['registration_link_text'] = CRM_Utils_Array
::value('registration_link_text', $defaults, ts('Register Now'));
195 $defaults['confirm_title'] = CRM_Utils_Array
::value('confirm_title', $defaults, ts('Confirm Your Registration Information'));
196 $defaults['thankyou_title'] = CRM_Utils_Array
::value('thankyou_title', $defaults, ts('Thank You for Registering'));
197 $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.'));
199 if (!empty($defaults['registration_start_date'])) {
200 list($defaults['registration_start_date'], $defaults['registration_start_date_time'])
201 = CRM_Utils_Date
::setDateDefaults($defaults['registration_start_date'], 'activityDateTime');
204 if (!empty($defaults['registration_end_date'])) {
205 list($defaults['registration_end_date'], $defaults['registration_end_date_time'])
206 = CRM_Utils_Date
::setDateDefaults($defaults['registration_end_date'], 'activityDateTime');
213 * Fix what blocks to show/hide based on the default values set
215 * @param array $defaults
216 * The array of default values.
220 public function setShowHide($defaults) {
221 $this->_showHide
= new CRM_Core_ShowHideBlocks(array('registration' => 1),
224 if (empty($defaults)) {
225 $this->_showHide
->addHide('registration');
226 $this->_showHide
->addHide('id-approval-text');
229 if (empty($defaults['requires_approval'])) {
230 $this->_showHide
->addHide('id-approval-text');
233 $this->assign('defaultsEmpty', empty($defaults));
234 $this->_showHide
->addToTemplate();
238 * Build the form object.
242 public function buildQuickForm() {
243 if ($this->_addProfileBottom
) {
244 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNum
);
247 if ($this->_addProfileBottomAdd
) {
248 return self
::buildMultipleProfileBottom($this, $this->_profileBottomNumAdd
, 'additional_', ts('Profile for Additional Participants'));
251 $this->applyFilter('__ALL__', 'trim');
252 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
254 $this->addElement('checkbox',
255 'is_online_registration',
256 ts('Allow Online Registration'),
259 'onclick' => "return showHideByValue('is_online_registration'," .
261 "'registration_blocks'," .
268 $this->add('text', 'registration_link_text', ts('Registration Link Text'));
270 if (!$this->_isTemplate
) {
271 $this->addDateTime('registration_start_date', ts('Registration Start Date'), FALSE, array('formatType' => 'activityDateTime'));
272 $this->addDateTime('registration_end_date', ts('Registration End Date'), FALSE, array('formatType' => 'activityDateTime'));
276 'used' => 'Supervised',
277 'contact_type' => 'Individual',
279 $dedupeRuleFields = CRM_Dedupe_BAO_Rule
::dedupeRuleFields($params);
281 foreach ($dedupeRuleFields as $key => $fields) {
282 $ruleFields[$key] = ucwords(str_replace('_', ' ', $fields));
285 $this->addElement('checkbox',
286 'is_multiple_registrations',
287 ts('Register multiple participants?')
290 $this->addElement('checkbox',
291 'allow_same_participant_emails',
292 ts('Same email address?')
294 $this->assign('ruleFields', json_encode($ruleFields));
296 $dedupeRules = array(
297 '' => '- Unsupervised rule -',
299 $dedupeRules +
= CRM_Dedupe_BAO_RuleGroup
::getByType('Individual');
300 $this->add('select', 'dedupe_rule_group_id', ts('Duplicate matching rule'), $dedupeRules);
302 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
303 if (in_array('Awaiting approval', $participantStatuses) and in_array('Pending from approval', $participantStatuses) and in_array('Rejected', $participantStatuses)) {
304 $this->addElement('checkbox',
306 ts('Require participant approval?'),
308 array('onclick' => "return showHideByValue('requires_approval', '', 'id-approval-text', 'table-row', 'radio', false);")
310 $this->add('textarea', 'approval_req_text', ts('Approval message'), $attributes['approval_req_text']);
313 $this->add('text', 'expiration_time', ts('Pending participant expiration (hours)'));
314 $this->addRule('expiration_time', ts('Please enter the number of hours (as an integer).'), 'integer');
316 self
::buildRegistrationBlock($this);
317 self
::buildConfirmationBlock($this);
318 self
::buildMailBlock($this);
319 self
::buildThankYouBlock($this);
321 parent
::buildQuickForm();
325 * Build Registration Block.
327 * @param CRM_Core_Form $form
330 public function buildRegistrationBlock(&$form) {
331 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'intro_text') +
array('class' => 'collapsed');
332 $form->add('wysiwyg', 'intro_text', ts('Introductory Text'), $attributes);
333 $form->add('wysiwyg', 'footer_text', ts('Footer Text'), $attributes);
335 extract(self
::getProfileSelectorTypes());
337 $form->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
338 $form->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
340 $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
341 $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
345 * Subroutine to insert a Profile Editor widget.
346 * depends on getProfileSelectorTypes
348 * @param array &$form
351 * @param string $prefix
352 * Dom element ID prefix.
353 * @param string $label
355 * @param array $configs
356 * Optional, for addProfileSelector(), defaults to using getProfileSelectorTypes().
358 public function buildMultipleProfileBottom(&$form, $count, $prefix = '', $label = 'Include Profile', $configs = NULL) {
359 extract((is_null($configs)) ? self
::getProfileSelectorTypes() : $configs);
360 $element = $prefix . "custom_post_id_multiple[$count]";
361 $label .= '<br />' . ts('(bottom of page)');
362 $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
366 * Create initializers for addprofileSelector.
369 * ['allowCoreTypes' => array, 'allowSubTypes' => array, 'profileEntities' => array]
371 public static function getProfileSelectorTypes() {
373 'allowCoreTypes' => array(),
374 'allowSubTypes' => array(),
375 'profileEntities' => array(),
378 $configs['allowCoreTypes'] = array_merge(array(
381 ), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
382 $configs['allowCoreTypes'][] = 'Participant';
384 $id = CRM_Utils_Request
::retrieve('id', 'Integer');
386 $participantEventType = CRM_Core_DAO
::getFieldValue("CRM_Event_DAO_Event", $id, 'event_type_id', 'id');
387 $participantRole = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $id, 'default_role_id');
388 $configs['allowSubTypes']['ParticipantEventName'] = array($id);
389 $configs['allowSubTypes']['ParticipantEventType'] = array($participantEventType);
390 $configs['allowSubTypes']['ParticipantRole'] = array($participantRole);
392 $configs['profileEntities'][] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel');
393 $configs['profileEntities'][] = array(
394 'entity_name' => 'participant_1',
395 'entity_type' => 'ParticipantModel',
396 'entity_sub_type' => '*',
403 * Build Confirmation Block.
405 * @param CRM_Core_Form $form
408 public function buildConfirmationBlock(&$form) {
409 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
410 // CRM-11182 - Optional confirmation page for free events
411 $is_monetary = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $form->_id
, 'is_monetary');
412 $form->assign('is_monetary', $is_monetary);
413 if ($is_monetary == "0") {
414 $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);"));
416 $form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']);
417 $form->add('wysiwyg', 'confirm_text', ts('Introductory Text'), $attributes['confirm_text'] +
array('class' => 'collapsed'));
418 $form->add('wysiwyg', 'confirm_footer_text', ts('Footer Text'), $attributes['confirm_text'] +
array('class' => 'collapsed'));
424 * @param CRM_Core_Form $form
427 public function buildMailBlock(&$form) {
428 $form->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule');
429 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
430 $form->addYesNo('is_email_confirm', ts('Send Confirmation Email?'), NULL, NULL, array('onclick' => "return showHideByValue('is_email_confirm','','confirmEmail','block','radio',false);"));
431 $form->add('textarea', 'confirm_email_text', ts('Text'), $attributes['confirm_email_text']);
432 $form->add('text', 'cc_confirm', ts('CC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'cc_confirm'));
433 $form->addRule('cc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
434 $form->add('text', 'bcc_confirm', ts('BCC Confirmation To'), CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event', 'bcc_confirm'));
435 $form->addRule('bcc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList');
436 $form->add('text', 'confirm_from_name', ts('Confirm From Name'));
437 $form->add('text', 'confirm_from_email', ts('Confirm From Email'));
438 $form->addRule('confirm_from_email', ts('Email is not valid.'), 'email');
442 * @param CRM_Core_Form $form
444 public function buildThankYouBlock(&$form) {
445 $attributes = CRM_Core_DAO
::getAttribute('CRM_Event_DAO_Event');
446 $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']);
447 $form->add('wysiwyg', 'thankyou_text', ts('Introductory Text'), $attributes['thankyou_text'] +
array('class' => 'collapsed'));
448 $form->add('wysiwyg', 'thankyou_footer_text', ts('Footer Text'), $attributes['thankyou_text'] +
array('class' => 'collapsed'));
452 * Add local and global form rules.
457 public function addRules() {
458 if ($this->_addProfileBottom ||
$this->_addProfileBottomAdd
) {
461 $this->addFormRule(array('CRM_Event_Form_ManageEvent_Registration', 'formRule'), $this);
465 * Global validation rules for the form.
467 * @param array $values
469 * @param CRM_Core_Form $form
472 * list of errors to be posted back to the form
474 public static function formRule($values, $files, $form) {
475 if (!empty($values['is_online_registration'])) {
477 if (!$values['confirm_title']) {
478 $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page');
480 if (!$values['thankyou_title']) {
481 $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page');
483 if ($values['is_email_confirm']) {
484 if (!$values['confirm_from_name']) {
485 $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.');
488 if (!$values['confirm_from_email']) {
489 $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.');
494 isset($values['registration_start_date']) &&
495 isset($values['registration_end_date'])
497 $start = CRM_Utils_Date
::processDate($values['registration_start_date']);
498 $end = CRM_Utils_Date
::processDate($values['registration_end_date']);
500 $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date');
504 //check that the selected profiles have either firstname+lastname or email required
506 CRM_Utils_Array
::value('custom_pre_id', $values),
507 CRM_Utils_Array
::value('custom_post_id', $values),
509 $additionalProfileIds = array(
510 CRM_Utils_Array
::value('additional_custom_pre_id', $values),
511 CRM_Utils_Array
::value('additional_custom_post_id', $values),
513 //additional profile fields default to main if not set
514 if (!is_numeric($additionalProfileIds[0])) {
515 $additionalProfileIds[0] = $profileIds[0];
517 if (!is_numeric($additionalProfileIds[1])) {
518 $additionalProfileIds[1] = $profileIds[1];
520 //add multiple profiles if set
521 self
::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple');
522 self
::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple');
523 $isProfileComplete = self
::isProfileComplete($profileIds);
524 $isAdditionalProfileComplete = self
::isProfileComplete($additionalProfileIds);
526 //Check main profiles have an email address available if 'send confirmation email' is selected
527 if ($values['is_email_confirm']) {
528 $emailFields = self
::getEmailFields($profileIds);
529 if (!count($emailFields)) {
530 $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected");
533 $additionalCustomPreId = $additionalCustomPostId = NULL;
534 $isPreError = $isPostError = TRUE;
535 if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) {
536 $types = array_merge(array('Individual'), CRM_Contact_BAO_ContactType
::subTypes('Individual'));
537 $profiles = CRM_Core_BAO_UFGroup
::getProfiles($types);
539 //check for additional custom pre profile
540 $additionalCustomPreId = CRM_Utils_Array
::value('additional_custom_pre_id', $values);
541 if (!empty($additionalCustomPreId)) {
542 if (!($additionalCustomPreId == 'none')) {
543 $customPreId = $additionalCustomPreId;
550 $customPreId = !empty($values['custom_pre_id']) ?
$values['custom_pre_id'] : NULL;
552 //check whether the additional custom pre profile is of type 'Individual' and its subtypes
553 if (!empty($customPreId)) {
554 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPreId);
555 foreach ($types as $individualTypes) {
556 if (in_array($individualTypes, $profileTypes)) {
566 // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile
568 $additionalCustomPostId = CRM_Utils_Array
::value('additional_custom_post_id', $values);
569 if (!empty($additionalCustomPostId)) {
570 if (!($additionalCustomPostId == 'none')) {
571 $customPostId = $additionalCustomPostId;
574 $isPostError = FALSE;
578 $customPostId = !empty($values['custom_post_id']) ?
$values['custom_post_id'] : NULL;
580 //check whether the additional custom post profile is of type 'Individual' and its subtypes
581 if (!empty($customPostId)) {
582 $profileTypes = CRM_Core_BAO_UFGroup
::profileGroups($customPostId);
583 foreach ($types as $individualTypes) {
584 if (in_array($individualTypes, $profileTypes)) {
585 $isPostError = FALSE;
591 $isPostError = FALSE;
594 if (empty($customPreId) && empty($customPostId)) {
595 $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
598 $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'");
602 if (!$isProfileComplete) {
603 $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.");
605 if (!$isAdditionalProfileComplete) {
606 $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.");
610 // $config = CRM_Core_Config::singleton();
611 // if ( $config->doNotAttachPDFReceipt ) {
612 // if (!empty($values['custom_post_id_multiple'])) {
613 // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) {
614 // if ( $customPostMultiple ) {
615 // $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' ) ) );
621 // if (!empty($values['is_multiple_registrations']) &&
622 // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) {
623 // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) {
624 // if ( $customPostMultiple ) {
625 // $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' ) ) );
632 if (!empty($errorMsg)) {
633 if (!empty($values['custom_post_id_multiple'])) {
634 foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) {
635 self
::buildMultipleProfileBottom($form, $count);
637 $form->assign('profilePostMultiple', $values['custom_post_id_multiple']);
639 if (!empty($values['additional_custom_post_id_multiple'])) {
640 foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) {
641 self
::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants'));
643 $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']);
648 if (!empty($errorMsg)) {
656 * Collect all email fields for an array of profile ids.
661 public static function getEmailFields($profileIds) {
662 $emailFields = array();
663 foreach ($profileIds as $profileId) {
664 if ($profileId && is_numeric($profileId)) {
665 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
666 foreach ($fields as $field) {
667 if (substr_count($field['name'], 'email')) {
668 $emailFields[] = $field;
677 * Check if a profile contains required fields.
682 public static function isProfileComplete($profileIds) {
683 $profileReqFields = array();
684 foreach ($profileIds as $profileId) {
685 if ($profileId && is_numeric($profileId)) {
686 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
687 foreach ($fields as $field) {
689 case substr_count($field['name'], 'email'):
690 $profileReqFields[] = 'email';
693 case substr_count($field['name'], 'first_name'):
694 $profileReqFields[] = 'first_name';
697 case substr_count($field['name'], 'last_name'):
698 $profileReqFields[] = 'last_name';
704 $profileComplete = (in_array('email', $profileReqFields)
705 ||
(in_array('first_name', $profileReqFields) && in_array('last_name', $profileReqFields))
707 return $profileComplete;
711 * Check if the profiles collect enough information to dedupe.
717 public static function canProfilesDedupe($profileIds, $rgId = 0) {
718 // find the unsupervised rule
720 'used' => 'Unsupervised',
721 'contact_type' => 'Individual',
724 $rgParams['id'] = $rgId;
726 $activeRg = CRM_Dedupe_BAO_RuleGroup
::dedupeRuleFieldsWeight($rgParams);
728 // get the combinations that could be a match for the rule
729 $okCombos = $combos = array();
730 CRM_Dedupe_BAO_RuleGroup
::combos($activeRg[0], $activeRg[1], $combos);
732 // create an index of what combinations involve each field
734 foreach ($combos as $comboid => $combo) {
735 foreach ($combo as $cfield) {
736 $index[$cfield][$comboid] = TRUE;
738 $combos[$comboid] = array_fill_keys($combo, 0);
739 $okCombos[$comboid] = array_fill_keys($combo, 2);
742 // get profiles and see if they have the necessary combos
743 $profileReqFields = array();
744 foreach ($profileIds as $profileId) {
745 if ($profileId && is_numeric($profileId)) {
746 $fields = CRM_Core_BAO_UFGroup
::getFields($profileId);
748 // walk through the fields in the profile
749 foreach ($fields as $field) {
751 // check each of the fields in the index against the profile field
752 foreach ($index as $ifield => $icombos) {
753 if (strpos($field['name'], $ifield) !== FALSE) {
755 // we found the field in the profile, now record it in the index
756 foreach ($icombos as $icombo => $dontcare) {
757 $combos[$icombo][$ifield] = ($combos[$icombo][$ifield] != 2 && !$field['is_required']) ?
1 : 2;
759 if ($combos[$icombo] == $okCombos[$icombo]) {
760 // if any combo is complete with 2s (all fields are present and required), we can go home
770 // check the combos to see if everything is > 0
771 foreach ($combos as $comboid => $combo) {
773 foreach ($combo as $cfield) {
778 // this combo isn't complete--skip to the next combo
787 // no combo succeeded
792 * Add additional profiles from the form to an array of profile ids.
794 public static function addMultipleProfiles(&$profileIds, $values, $field) {
795 if ($multipleProfiles = CRM_Utils_Array
::value($field, $values)) {
796 foreach ($multipleProfiles as $profileId) {
797 $profileIds[] = $profileId;
803 * Process the form submission.
808 public function postProcess() {
809 $params = $this->exportValues();
811 $params['id'] = $this->_id
;
814 $params['is_online_registration'] = CRM_Utils_Array
::value('is_online_registration', $params, FALSE);
815 $params['is_confirm_enabled'] = CRM_Utils_Array
::value('is_confirm_enabled', $params, FALSE); // CRM-11182
816 $params['is_multiple_registrations'] = CRM_Utils_Array
::value('is_multiple_registrations', $params, FALSE);
817 $params['allow_same_participant_emails'] = CRM_Utils_Array
::value('allow_same_participant_emails', $params, FALSE);
818 $params['requires_approval'] = CRM_Utils_Array
::value('requires_approval', $params, FALSE);
820 // reset is_email confirm if not online reg
821 if (!$params['is_online_registration']) {
822 $params['is_email_confirm'] = FALSE;
825 if (!$this->_isTemplate
) {
826 $params['registration_start_date'] = CRM_Utils_Date
::processDate($params['registration_start_date'],
827 $params['registration_start_date_time'],
830 $params['registration_end_date'] = CRM_Utils_Date
::processDate($params['registration_end_date'],
831 $params['registration_end_date_time'],
836 CRM_Event_BAO_Event
::add($params);
838 // also update the ProfileModule tables
839 $ufJoinParams = array(
841 'module' => 'CiviEvent',
842 'entity_table' => 'civicrm_event',
843 'entity_id' => $this->_id
,
846 // first delete all past entries
847 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParams);
851 if (!empty($params['custom_pre_id'])) {
852 $uf[1] = $params['custom_pre_id'];
856 if (!empty($params['custom_post_id'])) {
857 $uf[2] = $params['custom_post_id'];
860 if (!empty($params['custom_post_id_multiple'])) {
861 $uf = array_merge($uf, $params['custom_post_id_multiple']);
863 $uf = array_values($uf);
865 foreach ($uf as $weight => $ufGroupId) {
866 $ufJoinParams['weight'] = $weight +
$wt;
867 $ufJoinParams['uf_group_id'] = $ufGroupId;
868 CRM_Core_BAO_UFJoin
::create($ufJoinParams);
869 unset($ufJoinParams['id']);
872 // also update the ProfileModule tables
873 $ufJoinParamsAdd = array(
875 'module' => 'CiviEvent_Additional',
876 'entity_table' => 'civicrm_event',
877 'entity_id' => $this->_id
,
880 // first delete all past entries
881 CRM_Core_BAO_UFJoin
::deleteAll($ufJoinParamsAdd);
882 if (!empty($params['is_multiple_registrations'])) {
886 if (array_key_exists('additional_custom_pre_id', $params)) {
887 if (empty($params['additional_custom_pre_id'])) {
888 $ufAdd[1] = $params['custom_pre_id'];
891 elseif (CRM_Utils_Array
::value('additional_custom_pre_id', $params) == 'none') {
894 $ufAdd[1] = $params['additional_custom_pre_id'];
899 if (array_key_exists('additional_custom_post_id', $params)) {
900 if (empty($params['additional_custom_post_id'])) {
901 $ufAdd[2] = $params['custom_post_id'];
903 elseif (CRM_Utils_Array
::value('additional_custom_post_id', $params) == 'none') {
906 $ufAdd[2] = $params['additional_custom_post_id'];
910 if (!empty($params['additional_custom_post_id_multiple'])) {
911 $additionalPostMultiple = array();
912 foreach ($params['additional_custom_post_id_multiple'] as $key => $value) {
913 if (is_null($value) && !empty($params['custom_post_id'])) {
914 $additionalPostMultiple[$key] = $params['custom_post_id'];
916 elseif ($value == 'none') {
920 $additionalPostMultiple[$key] = $value;
923 $ufAdd = array_merge($ufAdd, $additionalPostMultiple);
926 $ufAdd = array_values($ufAdd);
927 if (!empty($ufAdd)) {
928 foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) {
930 $ufJoinParamsAdd['weight'] = $weightAdd +
$wtAdd;
931 $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd;
933 CRM_Core_BAO_UFJoin
::create($ufJoinParamsAdd);
934 unset($ufJoinParamsAdd['id']);
939 // get the profiles to evaluate what they collect
941 CRM_Utils_Array
::value('custom_pre_id', $params),
942 CRM_Utils_Array
::value('custom_post_id', $params),
944 $additionalProfileIds = array(
945 CRM_Utils_Array
::value('additional_custom_pre_id', $params),
946 CRM_Utils_Array
::value('additional_custom_post_id', $params),
948 // additional profile fields default to main if not set
949 if (!is_numeric($additionalProfileIds[0])) {
950 $additionalProfileIds[0] = $profileIds[0];
952 if (!is_numeric($additionalProfileIds[1])) {
953 $additionalProfileIds[1] = $profileIds[1];
955 //add multiple profiles if set
956 self
::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple');
957 self
::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple');
960 $rgId = CRM_Utils_Array
::value('dedupe_rule_group_id', $params, 0);
962 switch (self
::canProfilesDedupe($profileIds, $rgId)) {
964 $dedupeTitle = 'Duplicate Matching Impossible';
965 $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.");
969 $dedupeTitle = 'Duplicate Contacts Possible';
970 $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.");
972 if (!empty($params['is_multiple_registrations'])) {
973 switch (self
::canProfilesDedupe($additionalProfileIds, $rgId)) {
975 $dedupeTitle = 'Duplicate Matching Impossible';
977 $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.");
980 $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.");
986 $dedupeTitle = 'Duplicate Contacts Possible';
987 $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.");
992 CRM_Core_Session
::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', array('expires' => 0));
995 // Update tab "disabled" css class
996 $this->ajaxResponse
['tabValid'] = !empty($params['is_online_registration']);
998 parent
::endPostProcess();
1002 * Return a descriptive name for the page, used in wizard header
1006 public function getTitle() {
1007 return ts('Online Registration');