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