| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 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. | |
| 13 | | | |
| 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. | |
| 18 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * |
| 30 | * |
| 31 | * @package CRM |
| 32 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 33 | * $Id$ |
| 34 | * |
| 35 | */ |
| 36 | |
| 37 | /** |
| 38 | * This class generates form components for processing Event |
| 39 | * |
| 40 | */ |
| 41 | class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent { |
| 42 | |
| 43 | /** |
| 44 | * What blocks should we show and hide. |
| 45 | * |
| 46 | * @var CRM_Core_ShowHideBlocks |
| 47 | */ |
| 48 | protected $_showHide; |
| 49 | |
| 50 | protected $_profilePostMultiple = array(); |
| 51 | protected $_profilePostMultipleAdd = array(); |
| 52 | |
| 53 | /** |
| 54 | * Set variables up before form is built. |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 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); |
| 63 | |
| 64 | parent::preProcess(); |
| 65 | |
| 66 | $this->assign('addProfileBottom', $this->_addProfileBottom); |
| 67 | $this->assign('profileBottomNum', $this->_profileBottomNum); |
| 68 | |
| 69 | $urlParams = "id={$this->_id}&addProfileBottom=1&qfKey={$this->controller->_key}"; |
| 70 | $this->assign('addProfileParams', $urlParams); |
| 71 | |
| 72 | if ($addProfileBottom = CRM_Utils_Array::value('custom_post_id_multiple', $_POST)) { |
| 73 | foreach (array_keys($addProfileBottom) as $profileNum) { |
| 74 | self::buildMultipleProfileBottom($this, $profileNum); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | $this->assign('addProfileBottomAdd', $this->_addProfileBottomAdd); |
| 79 | $this->assign('profileBottomNumAdd', $this->_profileBottomNumAdd); |
| 80 | |
| 81 | $urlParamsAdd = "id={$this->_id}&addProfileBottomAdd=1&qfKey={$this->controller->_key}"; |
| 82 | $this->assign('addProfileParamsAdd', $urlParamsAdd); |
| 83 | |
| 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')); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Set default values for the form. |
| 93 | * the default values are retrieved from the database |
| 94 | * |
| 95 | * |
| 96 | * @return void |
| 97 | */ |
| 98 | public function setDefaultValues() { |
| 99 | if ($this->_addProfileBottom || $this->_addProfileBottomAdd) { |
| 100 | return; |
| 101 | } |
| 102 | $eventId = $this->_id; |
| 103 | |
| 104 | $defaults = parent::setDefaultValues(); |
| 105 | |
| 106 | $this->setShowHide($defaults); |
| 107 | if (isset($eventId)) { |
| 108 | $params = array('id' => $eventId); |
| 109 | CRM_Event_BAO_Event::retrieve($params, $defaults); |
| 110 | |
| 111 | $ufJoinParams = array( |
| 112 | 'entity_table' => 'civicrm_event', |
| 113 | 'module' => 'CiviEvent', |
| 114 | 'entity_id' => $eventId, |
| 115 | ); |
| 116 | |
| 117 | list($defaults['custom_pre_id'], |
| 118 | $defaults['custom_post'] |
| 119 | ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); |
| 120 | |
| 121 | // Get the id for the event registration profile |
| 122 | $eventRegistrationIdParams = $eventRegistrationIdDefaults = array( |
| 123 | 'name' => 'event_registration', |
| 124 | ); |
| 125 | CRM_Core_BAO_UFGroup::retrieve($eventRegistrationIdParams, $eventRegistrationIdDefaults); |
| 126 | |
| 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); |
| 130 | } |
| 131 | if (isset($defaults['custom_post']) && is_numeric($defaults['custom_post'])) { |
| 132 | $defaults['custom_post_id'] = $defaults['custom_post']; |
| 133 | } |
| 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; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | $this->assign('profilePostMultiple', CRM_Utils_Array::value('custom_post', $defaults)); |
| 145 | |
| 146 | if (!empty($defaults['is_multiple_registrations'])) { |
| 147 | // CRM-4377: set additional participants’ profiles – set to ‘none’ if explicitly unset (non-active) |
| 148 | |
| 149 | $ufJoinAddParams = array( |
| 150 | 'entity_table' => 'civicrm_event', |
| 151 | 'module' => 'CiviEvent_Additional', |
| 152 | 'entity_id' => $eventId, |
| 153 | ); |
| 154 | |
| 155 | list($defaults['additional_custom_pre_id'], |
| 156 | $defaults['additional_custom_post'] |
| 157 | ) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinAddParams); |
| 158 | |
| 159 | if (isset($defaults['additional_custom_post']) && is_numeric($defaults['additional_custom_post'])) { |
| 160 | $defaults['additional_custom_post_id'] = $defaults['additional_custom_post']; |
| 161 | } |
| 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]); |
| 165 | |
| 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; |
| 170 | } |
| 171 | } |
| 172 | $this->assign('profilePostMultipleAdd', CRM_Utils_Array::value('additional_custom_post', $defaults)); |
| 173 | } |
| 174 | } |
| 175 | else { |
| 176 | $defaults['is_email_confirm'] = 0; |
| 177 | } |
| 178 | |
| 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.')); |
| 184 | |
| 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'); |
| 188 | } |
| 189 | |
| 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'); |
| 193 | } |
| 194 | |
| 195 | return $defaults; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Fix what blocks to show/hide based on the default values set |
| 200 | * |
| 201 | * @param array $defaults |
| 202 | * The array of default values. |
| 203 | * |
| 204 | * @return void |
| 205 | */ |
| 206 | public function setShowHide($defaults) { |
| 207 | $this->_showHide = new CRM_Core_ShowHideBlocks(array('registration' => 1), |
| 208 | '' |
| 209 | ); |
| 210 | if (empty($defaults)) { |
| 211 | $this->_showHide->addHide('registration'); |
| 212 | $this->_showHide->addHide('id-approval-text'); |
| 213 | } |
| 214 | else { |
| 215 | if (empty($defaults['requires_approval'])) { |
| 216 | $this->_showHide->addHide('id-approval-text'); |
| 217 | } |
| 218 | } |
| 219 | $this->assign('defaultsEmpty', empty($defaults)); |
| 220 | $this->_showHide->addToTemplate(); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Build the form object. |
| 225 | * |
| 226 | * @return void |
| 227 | */ |
| 228 | public function buildQuickForm() { |
| 229 | if ($this->_addProfileBottom) { |
| 230 | return self::buildMultipleProfileBottom($this, $this->_profileBottomNum); |
| 231 | } |
| 232 | |
| 233 | if ($this->_addProfileBottomAdd) { |
| 234 | return self::buildMultipleProfileBottom($this, $this->_profileBottomNumAdd, 'additional_', ts('Profile for Additional Participants')); |
| 235 | } |
| 236 | |
| 237 | $this->applyFilter('__ALL__', 'trim'); |
| 238 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event'); |
| 239 | |
| 240 | $this->addElement('checkbox', |
| 241 | 'is_online_registration', |
| 242 | ts('Allow Online Registration'), |
| 243 | NULL, |
| 244 | array( |
| 245 | 'onclick' => "return showHideByValue('is_online_registration'," . |
| 246 | "''," . |
| 247 | "'registration_blocks'," . |
| 248 | "'block'," . |
| 249 | "'radio'," . |
| 250 | "false );", |
| 251 | ) |
| 252 | ); |
| 253 | |
| 254 | $this->add('text', 'registration_link_text', ts('Registration Link Text')); |
| 255 | |
| 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')); |
| 259 | } |
| 260 | |
| 261 | $params = array( |
| 262 | 'used' => 'Supervised', |
| 263 | 'contact_type' => 'Individual', |
| 264 | ); |
| 265 | $dedupeRuleFields = CRM_Dedupe_BAO_Rule::dedupeRuleFields($params); |
| 266 | |
| 267 | foreach ($dedupeRuleFields as $key => $fields) { |
| 268 | $ruleFields[$key] = ucwords(str_replace('_', ' ', $fields)); |
| 269 | } |
| 270 | |
| 271 | $this->addElement('checkbox', |
| 272 | 'is_multiple_registrations', |
| 273 | ts('Register multiple participants?') |
| 274 | ); |
| 275 | |
| 276 | $this->addElement('checkbox', |
| 277 | 'allow_same_participant_emails', |
| 278 | ts('Same email address?') |
| 279 | ); |
| 280 | $this->assign('ruleFields', json_encode($ruleFields)); |
| 281 | |
| 282 | $dedupeRules = array( |
| 283 | '' => '- Unsupervised rule -', |
| 284 | ); |
| 285 | $dedupeRules += CRM_Dedupe_BAO_RuleGroup::getByType('Individual'); |
| 286 | $this->add('select', 'dedupe_rule_group_id', ts('Duplicate matching rule'), $dedupeRules); |
| 287 | |
| 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', |
| 291 | 'requires_approval', |
| 292 | ts('Require participant approval?'), |
| 293 | NULL, |
| 294 | array('onclick' => "return showHideByValue('requires_approval', '', 'id-approval-text', 'table-row', 'radio', false);") |
| 295 | ); |
| 296 | $this->add('textarea', 'approval_req_text', ts('Approval message'), $attributes['approval_req_text']); |
| 297 | } |
| 298 | |
| 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 | |
| 302 | self::buildRegistrationBlock($this); |
| 303 | self::buildConfirmationBlock($this); |
| 304 | self::buildMailBlock($this); |
| 305 | self::buildThankYouBlock($this); |
| 306 | |
| 307 | parent::buildQuickForm(); |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Build Registration Block. |
| 312 | * |
| 313 | * @param CRM_Core_Form $form |
| 314 | * |
| 315 | */ |
| 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); |
| 320 | |
| 321 | extract(self::getProfileSelectorTypes()); |
| 322 | //CRM-15427 |
| 323 | $form->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); |
| 324 | $form->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); |
| 325 | |
| 326 | $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); |
| 327 | $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor); |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * Subroutine to insert a Profile Editor widget. |
| 332 | * depends on getProfileSelectorTypes |
| 333 | * |
| 334 | * @param array &$form |
| 335 | * @param int $count |
| 336 | * Unique index. |
| 337 | * @param string $prefix |
| 338 | * Dom element ID prefix. |
| 339 | * @param string $label |
| 340 | * Label. |
| 341 | * @param array $configs |
| 342 | * Optional, for addProfileSelector(), defaults to using getProfileSelectorTypes(). |
| 343 | */ |
| 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, $usedFor); |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * Create initializers for addprofileSelector. |
| 353 | * |
| 354 | * @return array |
| 355 | * ['allowCoreTypes' => array, 'allowSubTypes' => array, 'profileEntities' => array] |
| 356 | */ |
| 357 | public static function getProfileSelectorTypes() { |
| 358 | $configs = array( |
| 359 | 'allowCoreTypes' => array(), |
| 360 | 'allowSubTypes' => array(), |
| 361 | 'profileEntities' => array(), |
| 362 | 'usedFor' => array(), |
| 363 | ); |
| 364 | |
| 365 | $configs['allowCoreTypes'] = array_merge(array( |
| 366 | 'Contact', |
| 367 | 'Individual', |
| 368 | ), CRM_Contact_BAO_ContactType::subTypes('Individual')); |
| 369 | $configs['allowCoreTypes'][] = 'Participant'; |
| 370 | if (CRM_Core_Permission::check('manage event profiles') && !CRM_Core_Permission::check('administer CiviCRM')) { |
| 371 | $configs['usedFor'][] = 'CiviEvent'; |
| 372 | } |
| 373 | //CRM-15427 |
| 374 | $id = CRM_Utils_Request::retrieve('id', 'Integer'); |
| 375 | if ($id) { |
| 376 | $participantEventType = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $id, 'event_type_id', 'id'); |
| 377 | $participantRole = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'default_role_id'); |
| 378 | $configs['allowSubTypes']['ParticipantEventName'] = array($id); |
| 379 | $configs['allowSubTypes']['ParticipantEventType'] = array($participantEventType); |
| 380 | $configs['allowSubTypes']['ParticipantRole'] = array($participantRole); |
| 381 | } |
| 382 | $configs['profileEntities'][] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'); |
| 383 | $configs['profileEntities'][] = array( |
| 384 | 'entity_name' => 'participant_1', |
| 385 | 'entity_type' => 'ParticipantModel', |
| 386 | 'entity_sub_type' => '*', |
| 387 | ); |
| 388 | |
| 389 | return $configs; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Build Confirmation Block. |
| 394 | * |
| 395 | * @param CRM_Core_Form $form |
| 396 | * |
| 397 | */ |
| 398 | public function buildConfirmationBlock(&$form) { |
| 399 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event'); |
| 400 | // CRM-11182 - Optional confirmation page for free events |
| 401 | $is_monetary = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_id, 'is_monetary'); |
| 402 | $form->assign('is_monetary', $is_monetary); |
| 403 | if ($is_monetary == "0") { |
| 404 | $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);")); |
| 405 | } |
| 406 | $form->add('text', 'confirm_title', ts('Title'), $attributes['confirm_title']); |
| 407 | $form->add('wysiwyg', 'confirm_text', ts('Introductory Text'), $attributes['confirm_text'] + array('class' => 'collapsed')); |
| 408 | $form->add('wysiwyg', 'confirm_footer_text', ts('Footer Text'), $attributes['confirm_text'] + array('class' => 'collapsed')); |
| 409 | } |
| 410 | |
| 411 | /** |
| 412 | * Build Email Block. |
| 413 | * |
| 414 | * @param CRM_Core_Form $form |
| 415 | * |
| 416 | */ |
| 417 | public function buildMailBlock(&$form) { |
| 418 | $form->registerRule('emailList', 'callback', 'emailList', 'CRM_Utils_Rule'); |
| 419 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event'); |
| 420 | $form->addYesNo('is_email_confirm', ts('Send Confirmation Email?'), NULL, NULL, array('onclick' => "return showHideByValue('is_email_confirm','','confirmEmail','block','radio',false);")); |
| 421 | $form->add('textarea', 'confirm_email_text', ts('Text'), $attributes['confirm_email_text']); |
| 422 | $form->add('text', 'cc_confirm', ts('CC Confirmation To'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'cc_confirm')); |
| 423 | $form->addRule('cc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList'); |
| 424 | $form->add('text', 'bcc_confirm', ts('BCC Confirmation To'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'bcc_confirm')); |
| 425 | $form->addRule('bcc_confirm', ts('Please enter a valid list of comma delimited email addresses'), 'emailList'); |
| 426 | $form->add('text', 'confirm_from_name', ts('Confirm From Name')); |
| 427 | $form->add('text', 'confirm_from_email', ts('Confirm From Email')); |
| 428 | $form->addRule('confirm_from_email', ts('Email is not valid.'), 'email'); |
| 429 | } |
| 430 | |
| 431 | /** |
| 432 | * @param CRM_Core_Form $form |
| 433 | */ |
| 434 | public function buildThankYouBlock(&$form) { |
| 435 | $attributes = CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event'); |
| 436 | $form->add('text', 'thankyou_title', ts('Title'), $attributes['thankyou_title']); |
| 437 | $form->add('wysiwyg', 'thankyou_text', ts('Introductory Text'), $attributes['thankyou_text'] + array('class' => 'collapsed')); |
| 438 | $form->add('wysiwyg', 'thankyou_footer_text', ts('Footer Text'), $attributes['thankyou_text'] + array('class' => 'collapsed')); |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Add local and global form rules. |
| 443 | * |
| 444 | * |
| 445 | * @return void |
| 446 | */ |
| 447 | public function addRules() { |
| 448 | if ($this->_addProfileBottom || $this->_addProfileBottomAdd) { |
| 449 | return; |
| 450 | } |
| 451 | $this->addFormRule(array('CRM_Event_Form_ManageEvent_Registration', 'formRule'), $this); |
| 452 | } |
| 453 | |
| 454 | /** |
| 455 | * Global validation rules for the form. |
| 456 | * |
| 457 | * @param array $values |
| 458 | * @param $files |
| 459 | * @param CRM_Core_Form $form |
| 460 | * |
| 461 | * @return array |
| 462 | * list of errors to be posted back to the form |
| 463 | */ |
| 464 | public static function formRule($values, $files, $form) { |
| 465 | if (!empty($values['is_online_registration'])) { |
| 466 | |
| 467 | if (!$values['confirm_title']) { |
| 468 | $errorMsg['confirm_title'] = ts('Please enter a Title for the registration Confirmation Page'); |
| 469 | } |
| 470 | if (!$values['thankyou_title']) { |
| 471 | $errorMsg['thankyou_title'] = ts('Please enter a Title for the registration Thank-you Page'); |
| 472 | } |
| 473 | if ($values['is_email_confirm']) { |
| 474 | if (!$values['confirm_from_name']) { |
| 475 | $errorMsg['confirm_from_name'] = ts('Please enter Confirmation Email FROM Name.'); |
| 476 | } |
| 477 | |
| 478 | if (!$values['confirm_from_email']) { |
| 479 | $errorMsg['confirm_from_email'] = ts('Please enter Confirmation Email FROM Email Address.'); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | if ( |
| 484 | isset($values['registration_start_date']) && |
| 485 | isset($values['registration_end_date']) |
| 486 | ) { |
| 487 | $start = CRM_Utils_Date::processDate($values['registration_start_date']); |
| 488 | $end = CRM_Utils_Date::processDate($values['registration_end_date']); |
| 489 | if ($end < $start) { |
| 490 | $errorMsg['registration_end_date'] = ts('Registration end date should be after Registration start date'); |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | //check that the selected profiles have either firstname+lastname or email required |
| 495 | $profileIds = array( |
| 496 | CRM_Utils_Array::value('custom_pre_id', $values), |
| 497 | CRM_Utils_Array::value('custom_post_id', $values), |
| 498 | ); |
| 499 | $additionalProfileIds = array( |
| 500 | CRM_Utils_Array::value('additional_custom_pre_id', $values), |
| 501 | CRM_Utils_Array::value('additional_custom_post_id', $values), |
| 502 | ); |
| 503 | //additional profile fields default to main if not set |
| 504 | if (!is_numeric($additionalProfileIds[0])) { |
| 505 | $additionalProfileIds[0] = $profileIds[0]; |
| 506 | } |
| 507 | if (!is_numeric($additionalProfileIds[1])) { |
| 508 | $additionalProfileIds[1] = $profileIds[1]; |
| 509 | } |
| 510 | //add multiple profiles if set |
| 511 | self::addMultipleProfiles($profileIds, $values, 'custom_post_id_multiple'); |
| 512 | self::addMultipleProfiles($additionalProfileIds, $values, 'additional_custom_post_id_multiple'); |
| 513 | $isProfileComplete = self::isProfileComplete($profileIds); |
| 514 | $isAdditionalProfileComplete = self::isProfileComplete($additionalProfileIds); |
| 515 | |
| 516 | //Check main profiles have an email address available if 'send confirmation email' is selected |
| 517 | if ($values['is_email_confirm']) { |
| 518 | $emailFields = self::getEmailFields($profileIds); |
| 519 | if (!count($emailFields)) { |
| 520 | $errorMsg['is_email_confirm'] = ts("Please add a profile with an email address if 'Send Confirmation Email?' is selected"); |
| 521 | } |
| 522 | } |
| 523 | $additionalCustomPreId = $additionalCustomPostId = NULL; |
| 524 | $isPreError = $isPostError = TRUE; |
| 525 | if (!empty($values['allow_same_participant_emails']) && !empty($values['is_multiple_registrations'])) { |
| 526 | $types = array_merge(array('Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual')); |
| 527 | $profiles = CRM_Core_BAO_UFGroup::getProfiles($types); |
| 528 | |
| 529 | //check for additional custom pre profile |
| 530 | $additionalCustomPreId = CRM_Utils_Array::value('additional_custom_pre_id', $values); |
| 531 | if (!empty($additionalCustomPreId)) { |
| 532 | if (!($additionalCustomPreId == 'none')) { |
| 533 | $customPreId = $additionalCustomPreId; |
| 534 | } |
| 535 | else { |
| 536 | $isPreError = FALSE; |
| 537 | } |
| 538 | } |
| 539 | else { |
| 540 | $customPreId = !empty($values['custom_pre_id']) ? $values['custom_pre_id'] : NULL; |
| 541 | } |
| 542 | //check whether the additional custom pre profile is of type 'Individual' and its subtypes |
| 543 | if (!empty($customPreId)) { |
| 544 | $profileTypes = CRM_Core_BAO_UFGroup::profileGroups($customPreId); |
| 545 | foreach ($types as $individualTypes) { |
| 546 | if (in_array($individualTypes, $profileTypes)) { |
| 547 | $isPreError = FALSE; |
| 548 | break; |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | else { |
| 553 | $isPreError = FALSE; |
| 554 | } |
| 555 | |
| 556 | // We don't have required Individual fields in the pre-custom profile, so now check the post-custom profile |
| 557 | if ($isPreError) { |
| 558 | $additionalCustomPostId = CRM_Utils_Array::value('additional_custom_post_id', $values); |
| 559 | if (!empty($additionalCustomPostId)) { |
| 560 | if (!($additionalCustomPostId == 'none')) { |
| 561 | $customPostId = $additionalCustomPostId; |
| 562 | } |
| 563 | else { |
| 564 | $isPostError = FALSE; |
| 565 | } |
| 566 | } |
| 567 | else { |
| 568 | $customPostId = !empty($values['custom_post_id']) ? $values['custom_post_id'] : NULL; |
| 569 | } |
| 570 | //check whether the additional custom post profile is of type 'Individual' and its subtypes |
| 571 | if (!empty($customPostId)) { |
| 572 | $profileTypes = CRM_Core_BAO_UFGroup::profileGroups($customPostId); |
| 573 | foreach ($types as $individualTypes) { |
| 574 | if (in_array($individualTypes, $profileTypes)) { |
| 575 | $isPostError = FALSE; |
| 576 | break; |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | else { |
| 581 | $isPostError = FALSE; |
| 582 | } |
| 583 | |
| 584 | if (empty($customPreId) && empty($customPostId)) { |
| 585 | $errorMsg['additional_custom_pre_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'"); |
| 586 | } |
| 587 | if ($isPostError) { |
| 588 | $errorMsg['additional_custom_post_id'] = ts("Allow multiple registrations from the same email address requires a profile of type 'Individual'"); |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | if (!$isProfileComplete) { |
| 593 | $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."); |
| 594 | } |
| 595 | if (!$isAdditionalProfileComplete) { |
| 596 | $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."); |
| 597 | } |
| 598 | |
| 599 | // // CRM-8485 |
| 600 | // $config = CRM_Core_Config::singleton(); |
| 601 | // if ( $config->doNotAttachPDFReceipt ) { |
| 602 | // if (!empty($values['custom_post_id_multiple'])) { |
| 603 | // foreach( $values['custom_post_id_multiple'] as $count => $customPostMultiple ) { |
| 604 | // if ( $customPostMultiple ) { |
| 605 | // $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' ) ) ); |
| 606 | // break; |
| 607 | // } |
| 608 | // } |
| 609 | // } |
| 610 | // |
| 611 | // if (!empty($values['is_multiple_registrations']) && |
| 612 | // CRM_Utils_Array::value('additional_custom_post_id_multiple', $values) ) { |
| 613 | // foreach( $values['additional_custom_post_id_multiple'] as $count => $customPostMultiple ) { |
| 614 | // if ( $customPostMultiple ) { |
| 615 | // $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' ) ) ); |
| 616 | // break; |
| 617 | // } |
| 618 | // } |
| 619 | // } |
| 620 | // } |
| 621 | |
| 622 | if (!empty($errorMsg)) { |
| 623 | if (!empty($values['custom_post_id_multiple'])) { |
| 624 | foreach ($values['custom_post_id_multiple'] as $count => $customPostMultiple) { |
| 625 | self::buildMultipleProfileBottom($form, $count); |
| 626 | } |
| 627 | $form->assign('profilePostMultiple', $values['custom_post_id_multiple']); |
| 628 | } |
| 629 | if (!empty($values['additional_custom_post_id_multiple'])) { |
| 630 | foreach ($values['additional_custom_post_id_multiple'] as $count => $customPostMultiple) { |
| 631 | self::buildMultipleProfileBottom($form, $count, 'additional_', ts('Profile for Additional Participants')); |
| 632 | } |
| 633 | $form->assign('profilePostMultipleAdd', $values['additional_custom_post_id_multiple']); |
| 634 | } |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | if (!empty($errorMsg)) { |
| 639 | return $errorMsg; |
| 640 | } |
| 641 | |
| 642 | return TRUE; |
| 643 | } |
| 644 | |
| 645 | /** |
| 646 | * Collect all email fields for an array of profile ids. |
| 647 | * |
| 648 | * @param $profileIds |
| 649 | * @return bool |
| 650 | */ |
| 651 | public static function getEmailFields($profileIds) { |
| 652 | $emailFields = array(); |
| 653 | foreach ($profileIds as $profileId) { |
| 654 | if ($profileId && is_numeric($profileId)) { |
| 655 | $fields = CRM_Core_BAO_UFGroup::getFields($profileId); |
| 656 | foreach ($fields as $field) { |
| 657 | if (substr_count($field['name'], 'email')) { |
| 658 | $emailFields[] = $field; |
| 659 | } |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | return $emailFields; |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * Check if a profile contains required fields. |
| 668 | * |
| 669 | * @param $profileIds |
| 670 | * @return bool |
| 671 | */ |
| 672 | public static function isProfileComplete($profileIds) { |
| 673 | $profileReqFields = array(); |
| 674 | foreach ($profileIds as $profileId) { |
| 675 | if ($profileId && is_numeric($profileId)) { |
| 676 | $fields = CRM_Core_BAO_UFGroup::getFields($profileId); |
| 677 | foreach ($fields as $field) { |
| 678 | switch (TRUE) { |
| 679 | case substr_count($field['name'], 'email'): |
| 680 | $profileReqFields[] = 'email'; |
| 681 | break; |
| 682 | |
| 683 | case substr_count($field['name'], 'first_name'): |
| 684 | $profileReqFields[] = 'first_name'; |
| 685 | break; |
| 686 | |
| 687 | case substr_count($field['name'], 'last_name'): |
| 688 | $profileReqFields[] = 'last_name'; |
| 689 | break; |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | $profileComplete = (in_array('email', $profileReqFields) |
| 695 | || (in_array('first_name', $profileReqFields) && in_array('last_name', $profileReqFields)) |
| 696 | ); |
| 697 | return $profileComplete; |
| 698 | } |
| 699 | |
| 700 | /** |
| 701 | * Check if the profiles collect enough information to dedupe. |
| 702 | * |
| 703 | * @param $profileIds |
| 704 | * @param int $rgId |
| 705 | * @return bool |
| 706 | */ |
| 707 | public static function canProfilesDedupe($profileIds, $rgId = 0) { |
| 708 | // find the unsupervised rule |
| 709 | $rgParams = array( |
| 710 | 'used' => 'Unsupervised', |
| 711 | 'contact_type' => 'Individual', |
| 712 | ); |
| 713 | if ($rgId > 0) { |
| 714 | $rgParams['id'] = $rgId; |
| 715 | } |
| 716 | $activeRg = CRM_Dedupe_BAO_RuleGroup::dedupeRuleFieldsWeight($rgParams); |
| 717 | |
| 718 | // get the combinations that could be a match for the rule |
| 719 | $okCombos = $combos = array(); |
| 720 | CRM_Dedupe_BAO_RuleGroup::combos($activeRg[0], $activeRg[1], $combos); |
| 721 | |
| 722 | // create an index of what combinations involve each field |
| 723 | $index = array(); |
| 724 | foreach ($combos as $comboid => $combo) { |
| 725 | foreach ($combo as $cfield) { |
| 726 | $index[$cfield][$comboid] = TRUE; |
| 727 | } |
| 728 | $combos[$comboid] = array_fill_keys($combo, 0); |
| 729 | $okCombos[$comboid] = array_fill_keys($combo, 2); |
| 730 | } |
| 731 | |
| 732 | // get profiles and see if they have the necessary combos |
| 733 | $profileReqFields = array(); |
| 734 | foreach ($profileIds as $profileId) { |
| 735 | if ($profileId && is_numeric($profileId)) { |
| 736 | $fields = CRM_Core_BAO_UFGroup::getFields($profileId); |
| 737 | |
| 738 | // walk through the fields in the profile |
| 739 | foreach ($fields as $field) { |
| 740 | |
| 741 | // check each of the fields in the index against the profile field |
| 742 | foreach ($index as $ifield => $icombos) { |
| 743 | if (strpos($field['name'], $ifield) !== FALSE) { |
| 744 | |
| 745 | // we found the field in the profile, now record it in the index |
| 746 | foreach ($icombos as $icombo => $dontcare) { |
| 747 | $combos[$icombo][$ifield] = ($combos[$icombo][$ifield] != 2 && !$field['is_required']) ? 1 : 2; |
| 748 | |
| 749 | if ($combos[$icombo] == $okCombos[$icombo]) { |
| 750 | // if any combo is complete with 2s (all fields are present and required), we can go home |
| 751 | return 2; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | // check the combos to see if everything is > 0 |
| 761 | foreach ($combos as $comboid => $combo) { |
| 762 | $complete = FALSE; |
| 763 | foreach ($combo as $cfield) { |
| 764 | if ($cfield > 0) { |
| 765 | $complete = TRUE; |
| 766 | } |
| 767 | else { |
| 768 | // this combo isn't complete--skip to the next combo |
| 769 | continue 2; |
| 770 | } |
| 771 | } |
| 772 | if ($complete) { |
| 773 | return 1; |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | // no combo succeeded |
| 778 | return 0; |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Add additional profiles from the form to an array of profile ids. |
| 783 | */ |
| 784 | public static function addMultipleProfiles(&$profileIds, $values, $field) { |
| 785 | if ($multipleProfiles = CRM_Utils_Array::value($field, $values)) { |
| 786 | foreach ($multipleProfiles as $profileId) { |
| 787 | $profileIds[] = $profileId; |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | /** |
| 793 | * Process the form submission. |
| 794 | * |
| 795 | * |
| 796 | * @return void |
| 797 | */ |
| 798 | public function postProcess() { |
| 799 | $params = $this->exportValues(); |
| 800 | |
| 801 | $params['id'] = $this->_id; |
| 802 | |
| 803 | // format params |
| 804 | $params['is_online_registration'] = CRM_Utils_Array::value('is_online_registration', $params, FALSE); |
| 805 | $params['is_confirm_enabled'] = CRM_Utils_Array::value('is_confirm_enabled', $params, FALSE); // CRM-11182 |
| 806 | $params['is_multiple_registrations'] = CRM_Utils_Array::value('is_multiple_registrations', $params, FALSE); |
| 807 | $params['allow_same_participant_emails'] = CRM_Utils_Array::value('allow_same_participant_emails', $params, FALSE); |
| 808 | $params['requires_approval'] = CRM_Utils_Array::value('requires_approval', $params, FALSE); |
| 809 | |
| 810 | // reset is_email confirm if not online reg |
| 811 | if (!$params['is_online_registration']) { |
| 812 | $params['is_email_confirm'] = FALSE; |
| 813 | } |
| 814 | |
| 815 | if (!$this->_isTemplate) { |
| 816 | $params['registration_start_date'] = CRM_Utils_Date::processDate($params['registration_start_date'], |
| 817 | $params['registration_start_date_time'], |
| 818 | TRUE |
| 819 | ); |
| 820 | $params['registration_end_date'] = CRM_Utils_Date::processDate($params['registration_end_date'], |
| 821 | $params['registration_end_date_time'], |
| 822 | TRUE |
| 823 | ); |
| 824 | } |
| 825 | |
| 826 | CRM_Event_BAO_Event::add($params); |
| 827 | |
| 828 | // also update the ProfileModule tables |
| 829 | $ufJoinParams = array( |
| 830 | 'is_active' => 1, |
| 831 | 'module' => 'CiviEvent', |
| 832 | 'entity_table' => 'civicrm_event', |
| 833 | 'entity_id' => $this->_id, |
| 834 | ); |
| 835 | |
| 836 | // first delete all past entries |
| 837 | CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); |
| 838 | |
| 839 | $uf = array(); |
| 840 | $wt = 2; |
| 841 | if (!empty($params['custom_pre_id'])) { |
| 842 | $uf[1] = $params['custom_pre_id']; |
| 843 | $wt = 1; |
| 844 | } |
| 845 | |
| 846 | if (!empty($params['custom_post_id'])) { |
| 847 | $uf[2] = $params['custom_post_id']; |
| 848 | } |
| 849 | |
| 850 | if (!empty($params['custom_post_id_multiple'])) { |
| 851 | $uf = array_merge($uf, $params['custom_post_id_multiple']); |
| 852 | } |
| 853 | $uf = array_values($uf); |
| 854 | if (!empty($uf)) { |
| 855 | foreach ($uf as $weight => $ufGroupId) { |
| 856 | $ufJoinParams['weight'] = $weight + $wt; |
| 857 | $ufJoinParams['uf_group_id'] = $ufGroupId; |
| 858 | CRM_Core_BAO_UFJoin::create($ufJoinParams); |
| 859 | unset($ufJoinParams['id']); |
| 860 | } |
| 861 | } |
| 862 | // also update the ProfileModule tables |
| 863 | $ufJoinParamsAdd = array( |
| 864 | 'is_active' => 1, |
| 865 | 'module' => 'CiviEvent_Additional', |
| 866 | 'entity_table' => 'civicrm_event', |
| 867 | 'entity_id' => $this->_id, |
| 868 | ); |
| 869 | |
| 870 | // first delete all past entries |
| 871 | CRM_Core_BAO_UFJoin::deleteAll($ufJoinParamsAdd); |
| 872 | if (!empty($params['is_multiple_registrations'])) { |
| 873 | $ufAdd = array(); |
| 874 | $wtAdd = 2; |
| 875 | |
| 876 | if (array_key_exists('additional_custom_pre_id', $params)) { |
| 877 | if (empty($params['additional_custom_pre_id'])) { |
| 878 | $ufAdd[1] = $params['custom_pre_id']; |
| 879 | $wtAdd = 1; |
| 880 | } |
| 881 | elseif (CRM_Utils_Array::value('additional_custom_pre_id', $params) == 'none') { |
| 882 | } |
| 883 | else { |
| 884 | $ufAdd[1] = $params['additional_custom_pre_id']; |
| 885 | $wtAdd = 1; |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | if (array_key_exists('additional_custom_post_id', $params)) { |
| 890 | if (empty($params['additional_custom_post_id'])) { |
| 891 | $ufAdd[2] = $params['custom_post_id']; |
| 892 | } |
| 893 | elseif (CRM_Utils_Array::value('additional_custom_post_id', $params) == 'none') { |
| 894 | } |
| 895 | else { |
| 896 | $ufAdd[2] = $params['additional_custom_post_id']; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | if (!empty($params['additional_custom_post_id_multiple'])) { |
| 901 | $additionalPostMultiple = array(); |
| 902 | foreach ($params['additional_custom_post_id_multiple'] as $key => $value) { |
| 903 | if (is_null($value) && !empty($params['custom_post_id'])) { |
| 904 | $additionalPostMultiple[$key] = $params['custom_post_id']; |
| 905 | } |
| 906 | elseif ($value == 'none') { |
| 907 | continue; |
| 908 | } |
| 909 | elseif ($value) { |
| 910 | $additionalPostMultiple[$key] = $value; |
| 911 | } |
| 912 | } |
| 913 | $ufAdd = array_merge($ufAdd, $additionalPostMultiple); |
| 914 | } |
| 915 | |
| 916 | $ufAdd = array_values($ufAdd); |
| 917 | if (!empty($ufAdd)) { |
| 918 | foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) { |
| 919 | |
| 920 | $ufJoinParamsAdd['weight'] = $weightAdd + $wtAdd; |
| 921 | $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd; |
| 922 | |
| 923 | CRM_Core_BAO_UFJoin::create($ufJoinParamsAdd); |
| 924 | unset($ufJoinParamsAdd['id']); |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | // get the profiles to evaluate what they collect |
| 930 | $profileIds = array( |
| 931 | CRM_Utils_Array::value('custom_pre_id', $params), |
| 932 | CRM_Utils_Array::value('custom_post_id', $params), |
| 933 | ); |
| 934 | $additionalProfileIds = array( |
| 935 | CRM_Utils_Array::value('additional_custom_pre_id', $params), |
| 936 | CRM_Utils_Array::value('additional_custom_post_id', $params), |
| 937 | ); |
| 938 | // additional profile fields default to main if not set |
| 939 | if (!is_numeric($additionalProfileIds[0])) { |
| 940 | $additionalProfileIds[0] = $profileIds[0]; |
| 941 | } |
| 942 | if (!is_numeric($additionalProfileIds[1])) { |
| 943 | $additionalProfileIds[1] = $profileIds[1]; |
| 944 | } |
| 945 | //add multiple profiles if set |
| 946 | self::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple'); |
| 947 | self::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple'); |
| 948 | |
| 949 | $cantDedupe = FALSE; |
| 950 | $rgId = CRM_Utils_Array::value('dedupe_rule_group_id', $params, 0); |
| 951 | |
| 952 | switch (self::canProfilesDedupe($profileIds, $rgId)) { |
| 953 | case 0: |
| 954 | $dedupeTitle = 'Duplicate Matching Impossible'; |
| 955 | $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."); |
| 956 | break; |
| 957 | |
| 958 | case 1: |
| 959 | $dedupeTitle = 'Duplicate Contacts Possible'; |
| 960 | $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."); |
| 961 | } |
| 962 | if (!empty($params['is_multiple_registrations'])) { |
| 963 | switch (self::canProfilesDedupe($additionalProfileIds, $rgId)) { |
| 964 | case 0: |
| 965 | $dedupeTitle = 'Duplicate Matching Impossible'; |
| 966 | if ($cantDedupe) { |
| 967 | $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 | } |
| 969 | else { |
| 970 | $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."); |
| 971 | } |
| 972 | break; |
| 973 | |
| 974 | case 1: |
| 975 | if (!$cantDedupe) { |
| 976 | $dedupeTitle = 'Duplicate Contacts Possible'; |
| 977 | $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 | } |
| 979 | } |
| 980 | } |
| 981 | if ($cantDedupe) { |
| 982 | CRM_Core_Session::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', array('expires' => 0)); |
| 983 | } |
| 984 | |
| 985 | // Update tab "disabled" css class |
| 986 | $this->ajaxResponse['tabValid'] = !empty($params['is_online_registration']); |
| 987 | |
| 988 | parent::endPostProcess(); |
| 989 | } |
| 990 | |
| 991 | /** |
| 992 | * Return a descriptive name for the page, used in wizard header |
| 993 | * |
| 994 | * @return string |
| 995 | */ |
| 996 | public function getTitle() { |
| 997 | return ts('Online Registration'); |
| 998 | } |
| 999 | |
| 1000 | } |