ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilRegistrationSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\UI\Renderer as UIRenderer;
23use ILIAS\Data\Factory as DataFactory;
27use ILIAS\User\Settings\NewAccountMail\SettingsGUI as NewAccountMailSettingsGUI;
28
37{
38 public const CODE_TYPE_REGISTRATION = 1;
39 public const CODE_TYPE_EXTENSION = 2;
40
44 public int $ref_id;
45
51 protected ilLanguage $lng;
53 protected ilTabsGUI $tabs;
55 protected readonly ILIAS\HTTP\Services $http;
57 protected readonly Factory $ui_factory;
58 protected readonly UIRenderer $ui_renderer;
59 protected readonly ilUIService $ui_service;
60 protected readonly ilObjUser $user;
67
68 protected ?ilPropertyFormGUI $form_gui = null;
69
70 public function __construct()
71 {
72 global $DIC;
73
74 $this->tpl = $DIC->ui()->mainTemplate();
75 $this->ctrl = $DIC->ctrl();
76 $this->access = $DIC->access();
77 $this->rbacsystem = $DIC->rbac()->system();
78 $this->rbacreview = $DIC->rbac()->review();
79 $this->error = $DIC['ilErr'];
80 $this->tabs = $DIC->tabs();
81 $this->toolbar = $DIC->toolbar();
82
83 $this->lng = $DIC->language();
84 $this->lng->loadLanguageModule('administration');
85 $this->lng->loadLanguageModule('registration');
86 $this->lng->loadLanguageModule('user');
87 $this->registration_settings = new ilRegistrationSettings();
88
89 $this->http = $DIC->http();
90 $this->refinery = $DIC->refinery();
91 $this->ref_id = $this->initRefIdFromQuery();
92 $this->ui_factory = $DIC->ui()->factory();
93 $this->ui_renderer = $DIC->ui()->renderer();
94 $this->ui_service = $DIC->uiService();
95 $this->user = $DIC->user();
96 $this->code_repository = new RegistrationCodeRepository($DIC->database());
97 }
98
99 protected function initRefIdFromQuery(): int
100 {
101 if ($this->http->wrapper()->query()->has('ref_id')) {
102 return $this->http->wrapper()->query()->retrieve(
103 'ref_id',
104 $this->refinery->kindlyTo()->int()
105 );
106 }
107 return 0;
108 }
109
110 public function executeCommand(): void
111 {
112 $next_class = $this->ctrl->getNextClass($this);
113 $cmd = $this->ctrl->getCmd();
114
115 if ($this->http->wrapper()->query()->has('registration_codes_table_action')) {
116 $cmd = $this->http->wrapper()->query()->retrieve(
117 'registration_codes_table_action',
118 $this->refinery->kindlyTo()->string()
119 );
120 }
121
122 switch ($next_class) {
123 default:
124 if (!$cmd) {
125 $cmd = 'view';
126 }
127 $this->$cmd();
128 break;
129 }
130 }
131
132 protected function checkAccess(string $a_permission): void
133 {
134 if (!$this->checkAccessBool($a_permission)) {
135 $this->error->raiseError($this->lng->txt('msg_no_perm_read'), $this->error->WARNING);
136 }
137 }
138
139 protected function checkAccessBool(string $a_permission): bool
140 {
141 return $this->access->checkAccess($a_permission, '', $this->ref_id);
142 }
143
144 public function setSubTabs(string $activeTab = 'registration_settings'): void
145 {
146 $this->tabs->addSubTab(
147 "registration_settings",
148 $this->lng->txt("registration_tab_settings"),
149 $this->ctrl->getLinkTarget($this, 'view')
150 );
151 $this->tabs->addSubTab(
152 "registration_codes",
153 $this->lng->txt("registration_tab_codes"),
154 $this->ctrl->getLinkTarget($this, 'listCodes')
155 );
156 $this->tabs->activateSubTab($activeTab);
157 }
158
159 public function initForm(): ilPropertyFormGUI
160 {
162 $form_gui->setFormAction($this->ctrl->getFormAction($this, 'save'));
163 $form_gui->setTitle($this->lng->txt('reg_settings_header'));
164
165 $reg_type = new ilRadioGroupInputGUI($this->lng->txt('reg_type'), 'reg_type');
166 $reg_type->addOption(new ilRadioOption(
167 $this->lng->txt('reg_disabled'),
169 ));
170 $option = new ilRadioOption($this->lng->txt('reg_direct'), (string) ilRegistrationSettings::IL_REG_DIRECT);
171 $option->setInfo($this->lng->txt('reg_direct_info'));
172 $cd = new ilCheckboxInputGUI(
173 $this->lng->txt('reg_allow_codes'),
174 'reg_codes_' . ilRegistrationSettings::IL_REG_DIRECT
175 );
176 $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
177 $option->addSubItem($cd);
178 $reg_type->addOption($option);
179 $option = new ilRadioOption($this->lng->txt('reg_approve'), (string) ilRegistrationSettings::IL_REG_APPROVE);
180 $option->setInfo($this->lng->txt('reg_approve_info'));
181 $cd = new ilCheckboxInputGUI(
182 $this->lng->txt('reg_allow_codes'),
183 'reg_codes_' . ilRegistrationSettings::IL_REG_APPROVE
184 );
185 $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
186 $option->addSubItem($cd);
187 $reg_type->addOption($option);
188 $option = new ilRadioOption(
189 $this->lng->txt('reg_type_confirmation'),
191 );
192 $option->setInfo($this->lng->txt('reg_type_confirmation_info'));
193 $lt = new ilNumberInputGUI($this->lng->txt('reg_confirmation_hash_life_time'), 'reg_hash_life_time');
194 $lt->setSize(6); // #8511
195 $lt->setMaxLength(6);
197 $lt->setRequired(true);
198 $lt->setInfo($this->lng->txt('reg_confirmation_hash_life_time_info'));
199 $lt->setSuffix($this->lng->txt('seconds'));
200 $option->addSubItem($lt);
201 $cd = new ilCheckboxInputGUI(
202 $this->lng->txt('reg_allow_codes'),
203 'reg_codes_' . ilRegistrationSettings::IL_REG_ACTIVATION
204 );
205 $cd->setInfo($this->lng->txt('reg_allow_codes_info'));
206 $option->addSubItem($cd);
207 $reg_type->addOption($option);
208 $option = new ilRadioOption(
209 $this->lng->txt('registration_reg_type_codes'),
211 );
212 $option->setInfo($this->lng->txt('registration_reg_type_codes_info'));
213 $reg_type->addOption($option);
214 $form_gui->addItem($reg_type);
215
216 $pwd_gen = new ilCheckboxInputGUI($this->lng->txt('passwd_generation'), 'reg_pwd');
217 $pwd_gen->setValue('1');
218 $pwd_gen->setInfo($this->lng->txt('reg_info_pwd'));
219 $form_gui->addItem($pwd_gen);
220
221 $approver = new ilTextInputGUI($this->lng->txt('reg_notification'), 'reg_approver');
222 $approver->setSize(32);
223 $approver->setMaxLength(50);
224 $approver->setInfo($this->lng->txt('reg_notification_info'));
225 $form_gui->addItem($approver);
226
227 $roles = new ilRadioGroupInputGUI($this->lng->txt('reg_role_assignment'), 'reg_role_type');
228 $option = new ilRadioOption($this->lng->txt('reg_fixed'), (string) ilRegistrationSettings::IL_REG_ROLES_FIXED);
229 $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
230 $edit = $this->ctrl->getLinkTarget($this, 'editRoles');
231 $list->setHtml($this->parseRoleList($this->prepareRoleList(), $edit));
232 $option->addSubItem($list);
233 $roles->addOption($option);
234 $option = new ilRadioOption($this->lng->txt('reg_email'), (string) ilRegistrationSettings::IL_REG_ROLES_EMAIL);
235 $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
236 $edit = $this->ctrl->getLinkTarget($this, 'editEmailAssignments');
237 $list->setHtml($this->parseRoleList($this->prepareAutomaticRoleList(), $edit));
238 $option->addSubItem($list);
239 $roles->addOption($option);
240 $roles->setInfo($this->lng->txt('registration_codes_override_global_info'));
241 $form_gui->addItem($roles);
242
243 $limit = new ilCheckboxInputGUI($this->lng->txt('reg_access_limitations'), 'reg_access_limitation');
244 $limit->setValue('1');
245 $list = new ilCustomInputGUI($this->lng->txt('reg_available_roles'));
246 $edit = $this->ctrl->getLinkTarget($this, 'editRoleAccessLimitations');
247 $list->setHtml($this->parseRoleList($this->prepareAccessLimitationRoleList(), $edit));
248 $list->setInfo($this->lng->txt('registration_codes_override_global_info'));
249 $limit->addSubItem($list);
250 $form_gui->addItem($limit);
251
252 $domains = new ilTextInputGUI($this->lng->txt('reg_allowed_domains'), 'reg_allowed_domains');
253 $domains->setInfo($this->lng->txt('reg_allowed_domains_info'));
254 $form_gui->addItem($domains);
255
256 if ($this->rbacsystem->checkAccess("write", $this->ref_id)) {
257 $form_gui->addCommandButton('save', $this->lng->txt('save'));
258 } else {
259 foreach ($form_gui->getItems() as $item) {
260 if ($item instanceof ilFormSectionHeaderGUI) {
261 continue;
262 }
263
264 $item->setDisabled(true);
265 }
266 }
267 return $form_gui;
268 }
269
270 public function initFormValues(ilPropertyFormGUI $formGUI): void
271 {
273 if ($this->registration_settings->roleSelectionEnabled()) {
275 } elseif ($this->registration_settings->automaticRoleAssignmentEnabled()) {
277 }
278
280 $values = [
281 'reg_type' => $this->registration_settings->getRegistrationType(),
282 'reg_hash_life_time' => $this->registration_settings->getRegistrationHashLifetime(),
283 'reg_pwd' => $this->registration_settings->passwordGenerationEnabled(),
284 'reg_approver' => $this->registration_settings->getApproveRecipientLogins(),
285 'reg_role_type' => $role_type,
286 'reg_access_limitation' => $this->registration_settings->getAccessLimitation(),
287 'reg_allowed_domains' => implode(';', $this->registration_settings->getAllowedDomains())
288 ];
289
290 $allow_codes = $this->registration_settings->getAllowCodes();
291 $reg_type = $this->registration_settings->getRegistrationType();
292 if ($allow_codes && in_array($reg_type, [
296 ], true)) {
297 $values['reg_codes_' . $reg_type] = true;
298 }
299
300 $formGUI->setValuesByArray($values);
301 }
302
303 public function view(): void
304 {
305 $this->checkAccess('read');
306 $this->setSubTabs();
307
308 // edit new accout mail
309 $this->ctrl->setParameterByClass("ilobjuserfoldergui", "ref_id", USER_FOLDER_ID);
310 if ($this->checkAccessBool('write')) {
311 $this->toolbar->addButton(
312 $this->lng->txt('registration_user_new_account_mail'),
313 $this->ctrl->getLinkTargetByClass(
314 [
315 ilAdministrationGUI::class,
316 ilObjUserFolderGUI::class,
317 NewAccountMailSettingsGUI::class
318
319 ],
320 'show'
321 )
322 );
323 $this->ctrl->setParameterByClass(ilObjUserFolderGUI::class, 'ref_id', $_GET['ref_id']);
324 }
325
326 $form = $this->initForm();
327 $this->initFormValues($form);
328 $this->tpl->setContent($form->getHTML());
329 }
330
331 public function save(): bool
332 {
333 $this->checkAccess('write');
334
335 $form = $this->initForm();
336 $res = $form->checkInput();
337 $this->registration_settings->setRegistrationType((int) $form->getInput('reg_type'));
338 $this->registration_settings->setPasswordGenerationStatus((bool) $form->getInput('reg_pwd'));
339 $this->registration_settings->setApproveRecipientLogins($form->getInput('reg_approver'));
340 $this->registration_settings->setRoleType((int) $form->getInput('reg_role_type'));
341 $this->registration_settings->setAccessLimitation((bool) $form->getInput('reg_access_limitation'));
342 $this->registration_settings->setAllowedDomains((string) $form->getInput('reg_allowed_domains'));
343
344 $allow_codes = false;
345 $reg_type = (int) $form->getInput('reg_type');
346 if (in_array($reg_type, [
350 ], true)) {
351 $allow_codes = (bool) $form->getInput('reg_codes_' . $reg_type);
352 }
353 $this->registration_settings->setAllowCodes($allow_codes);
354
355 $hash_life_time = $form->getInput('reg_hash_life_time');
356 if (!preg_match('/^([0]|([1-9][0-9]*))([\.,][0-9]+)?$/', (string) $hash_life_time)) {
357 $this->registration_settings->setRegistrationHashLifetime(ilRegistrationSettings::REG_HASH_LIFETIME_MIN_VALUE);
358 } else {
359 $this->registration_settings->setRegistrationHashLifetime(max(
360 (int) $hash_life_time,
362 ));
363 }
364
365 if ($error_code = $this->registration_settings->validate()) {
366 switch ($error_code) {
368 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('reg_unknown_recipients') . ' ' . $this->registration_settings->getUnknown());
369 $this->view();
370 return false;
371
373 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('reg_approve_needs_recipient') . ' ' . $this->registration_settings->getUnknown());
374 $this->view();
375 return false;
376 }
377 }
378
379 $this->registration_settings->save();
380 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
381 $this->view();
382 return true;
383 }
384
385 protected function initRolesForm(): ilPropertyFormGUI
386 {
387 $role_form = new ilPropertyFormGUI();
388 $role_form->setFormAction($this->ctrl->getFormAction($this, 'save'));
389 $role_form->setTitle($this->lng->txt('reg_selectable_roles'));
390
391 $roles = new ilCheckboxGroupInputGUI($this->lng->txt('reg_available_roles'), 'roles');
392 $allowed_roles = [];
393 foreach ($this->rbacreview->getGlobalRoles() as $role) {
394 if ($role === SYSTEM_ROLE_ID || $role === ANONYMOUS_ROLE_ID) {
395 continue;
396 }
397 $role_option = new ilCheckboxOption(ilObjRole::_lookupTitle($role));
398 $role_option->setValue((string) $role);
399 $roles->addOption($role_option);
400 $allowed_roles[$role] = ilObjRole::_lookupAllowRegister($role);
401 }
402
403 $roles->setUseValuesAsKeys(true);
404 $roles->setValue($allowed_roles);
405 $role_form->addItem($roles);
406
407 if ($this->checkAccessBool('write')) {
408 $role_form->addCommandButton("updateRoles", $this->lng->txt("save"));
409 }
410 $role_form->addCommandButton("view", $this->lng->txt("cancel"));
411 return $role_form;
412 }
413
414 public function editRoles(?ilPropertyFormGUI $form = null): void
415 {
416 $this->checkAccess('write');
417 $this->tabs->clearTargets();
418 $this->tabs->setBackTarget(
419 $this->lng->txt("registration_settings"),
420 $this->ctrl->getLinkTarget($this, "view")
421 );
422 if (!$form instanceof ilPropertyFormGUI) {
423 $form = $this->initRolesForm();
424 }
425 $this->tpl->setContent($form->getHTML());
426 }
427
428 public function updateRoles(): bool
429 {
430 $this->checkAccess('write');
431 $form = $this->initRolesForm();
432 if ($form->checkInput()) {
433 $roles = (array) $form->getInput('roles');
434 if (count($roles) < 1) {
435 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_last_role_for_registration'));
436 $this->editRoles();
437 return false;
438 }
439 foreach ($this->rbacreview->getGlobalRoles() as $role) {
440 if ($role_obj = ilObjectFactory::getInstanceByObjId($role, false)) {
441 $role_obj->setAllowRegister(isset($roles[$role]) && (int) $roles[$role] === 1);
442 $role_obj->update();
443 }
444 }
445 }
446 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
447 $this->view();
448 return true;
449 }
450
451 public function editEmailAssignments(?ilPropertyFormGUI $form = null): void
452 {
453 $this->checkAccess('write');
454 $this->tabs->clearTargets();
455 $this->tabs->setBackTarget(
456 $this->lng->txt("registration_settings"),
457 $this->ctrl->getLinkTarget($this, "view")
458 );
459
460 $this->initRoleAssignments();
461 $form = $form ?? $this->initEmailAssignmentForm();
462 $this->tpl->setContent($form->getHTML());
463 }
464
466 {
467 $role_assignment_form = new ilPropertyFormGUI();
468 $role_assignment_form->setFormAction($this->ctrl->getFormAction($this));
469 $role_assignment_form->setTitle($this->lng->txt('reg_email_role_assignment'));
470
471 $global_roles = ["" => $this->lng->txt("links_select_one")];
472 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
473 if ($role_id === ANONYMOUS_ROLE_ID) {
474 continue;
475 }
476
477 $global_roles[$role_id] = ilObjRole::_lookupTitle($role_id);
478 $role_assignments = new ilCheckboxInputGUI(ilObjRole::_lookupTitle($role_id), "role_assigned_$role_id");
479
480 $domains = $this->assignments_obj->getDomainsByRole($role_id);
481
482 $domain = new ilTextInputGUI($this->lng->txt('reg_domain'), "domain_$role_id");
483 $domain->setMulti(true);
484 $domain->setValidationRegexp("/^@.*\.[a-zA-Z]{1,4}$/");
485 if (!empty($domains)) {
486 $domain->setValue($domains[0]);
487 $domain->setMultiValues($domains);
488 $role_assignments->setChecked(true);
489 }
490
491 $role_assignments->addSubItem($domain);
492 $role_assignment_form->addItem($role_assignments);
493 }
494
495 $default_role = new ilSelectInputGUI($this->lng->txt('reg_default'));
496 $default_role->setPostVar("default_role");
497 $default_role->setOptions($global_roles);
498 $default_role->setValue($this->assignments_obj->getDefaultRole());
499 $default_role->setRequired(true);
500 $role_assignment_form->addItem($default_role);
501
502 $role_assignment_form->addCommandButton("saveAssignment", $this->lng->txt("save"));
503 $role_assignment_form->addCommandButton("view", $this->lng->txt("cancel"));
504
505 return $role_assignment_form;
506 }
507
508 public function editRoleAccessLimitations(?ilPropertyFormGUI $form = null): void
509 {
510 global $DIC;
511
512 $this->checkAccess('write');
513 $this->tabs->clearTargets();
514 $this->tabs->setBackTarget(
515 $this->lng->txt("registration_settings"),
516 $this->ctrl->getLinkTarget($this, "view")
517 );
519 if (null === $form) {
520 $form = $this->initRoleAccessForm();
521 }
522 $this->tpl->setContent($form->getHTML());
523 }
524
526 {
527 $form = new ilPropertyFormGUI();
528 $form->setFormAction($this->ctrl->getFormAction($this));
529 $form->setTitle($this->lng->txt('reg_role_access_limitations'));
530 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
531 $role_access = new ilRadioGroupInputGUI($role['title'], "role_access_" . $role['id']);
532
533 $op_unlimited = new ilRadioOption($this->lng->txt('reg_access_limitation_mode_unlimited'), "unlimited");
534
535 $op_absolute = new ilRadioOption($this->lng->txt('reg_access_limitation_mode_absolute'), "absolute");
536 $absolute_date = new ilDateTime(
537 date("d.m.Y", $this->access_limitations_obj->getAbsolute($role['id'])),
539 );
540 $date = new ilDateTimeInputGUI("", "absolute_date_" . $role['id']);
541 $date->setDate($absolute_date);
542 $op_absolute->addSubItem($date);
543
544 $op_relative = new ilRadioOption($this->lng->txt('reg_access_limitation_mode_relative'), "relative");
545 $duration = new ilDurationInputGUI("", "duration_" . $role['id']);
546 $duration->setShowMinutes(false);
547 $duration->setShowHours(false);
548 $duration->setShowDays(true);
549 $duration->setShowMonths(true);
550 $duration->setDays($this->access_limitations_obj->getRelative($role['id'], 'd'));
551 $duration->setMonths($this->access_limitations_obj->getRelative($role['id'], 'm'));
552 $op_relative->addSubItem($duration);
553
554 $role_access->addOption($op_unlimited);
555 $role_access->addOption($op_absolute);
556 $role_access->addOption($op_relative);
557 $role_access->setValue(
558 $this->access_limitations_obj->getMode(
559 $role['id']
560 ) === 'null' ? 'unlimited' : $this->access_limitations_obj->getMode($role['id'])
561 );
562
563 $form->addItem($role_access);
564 }
565
566 $form->addCommandButton("saveRoleAccessLimitations", $this->lng->txt("save"));
567 $form->addCommandButton("view", $this->lng->txt("cancel"));
568
569 return $form;
570 }
571
572 public function saveAssignment(): bool
573 {
574 $this->checkAccess('write');
575 $this->initRoleAssignments();
576 $form = $this->initEmailAssignmentForm();
577 $is_valid = $form->checkInput();
578 $form->setValuesByPost();
579 if (!$is_valid) {
580 $this->editEmailAssignments($form);
581 return false;
582 }
583
584 $assignments_by_domain = [];
585 $problems_domains_by_field_id = [];
586 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
587 if ($role_id === ANONYMOUS_ROLE_ID) {
588 continue;
589 }
590
591 $role_assigned_input = $form->getInput("role_assigned_$role_id");
592 if (!$role_assigned_input) {
593 continue;
594 }
595
596 $domain_input = $form->getInput("domain_$role_id");
597 foreach ($domain_input as $domain) {
598 if (!is_string($domain) || $domain === '') {
599 continue;
600 }
601
602 if (isset($assignments_by_domain[$domain])) {
603 if (!isset($problems_domains_by_field_id["role_assigned_$role_id"])) {
604 $problems_domains_by_field_id["role_assigned_$role_id"] = [];
605 }
606
607 $problems_domains_by_field_id["domain_$role_id"][$domain] = $domain;
608 continue;
609 }
610
611 $assignments_by_domain[$domain] = $role_id;
612 }
613 }
614
615 if ($problems_domains_by_field_id !== []) {
616 foreach ($problems_domains_by_field_id as $field_id => $domains) {
617 $domain_string = implode(', ', $domains);
618 $alert = sprintf($this->lng->txt('reg_domain_already_assigned_p'), $domain_string);
619 if (count($domains) === 1) {
620 $alert = sprintf($this->lng->txt('reg_domain_already_assigned_s'), $domain_string);
621 }
622 $form->getItemByPostVar($field_id)->setAlert($alert);
623 }
624
625 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
626 $this->editEmailAssignments($form);
627 return false;
628 }
629
630 $this->assignments_obj->deleteAll();
631
632 $counter = 0;
633 foreach ($assignments_by_domain as $domain => $role_id) {
634 $this->assignments_obj->setDomain($counter, $domain);
635 $this->assignments_obj->setRole($counter, $role_id);
636 $counter++;
637 }
638 $default_role = $form->getInput("default_role");
639 $this->assignments_obj->setDefaultRole((int) $default_role);
640 $this->assignments_obj->save();
641 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
642 $this->view();
643 return true;
644 }
645
646 public function saveRoleAccessLimitations(): bool
647 {
648 $this->checkAccess('write');
650
651 $form = $this->initRoleAccessForm();
652 if (!$form->checkInput()) {
653 $form->setValuesByPost();
654 $this->editRoleAccessLimitations($form);
655 return false;
656 }
657
658 $this->access_limitations_obj->resetAccessLimitations();
659 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
660 $mode = $form->getInput('role_access_' . $role['id']);
661 $this->access_limitations_obj->setMode($mode, $role['id']);
662
663 if ($mode === 'absolute') {
664 $this->access_limitations_obj->setAbsolute($form->getInput('absolute_date_' . $role['id']), $role['id']);
665 }
666
667 if ($mode === 'relative') {
668 $this->access_limitations_obj->setRelative($form->getInput('duration_' . $role['id']), $role['id']);
669 }
670 }
671
672 if ($err = $this->access_limitations_obj->validate()) {
673 switch ($err) {
675 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('reg_access_limitation_missing_mode'));
676 break;
677
679 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('reg_access_limitation_out_of_date'));
680 break;
681 }
683 return false;
684 }
685
686 $this->access_limitations_obj->save();
687 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
688 $this->view();
689 return true;
690 }
691
697 private function parseRoleList(array $roles, string $url): string
698 {
699 $tpl = new ilTemplate('tpl.registration_roles.html', true, true, 'components/ILIAS/Registration');
700
701 $tpl->setVariable("EDIT", $this->lng->txt("edit"));
702 $tpl->setVariable("LINK_EDIT", $url);
703
704 if (is_array($roles) && count($roles)) {
705 foreach ($roles as $role) {
706 $tpl->setCurrentBlock("list_item");
707 $tpl->setVariable("LIST_ITEM_ITEM", $role);
709 }
710 } else {
711 $tpl->setVariable("NONE", $this->lng->txt('none'));
712 }
713 return $tpl->get();
714 }
715
716 /***
717 * @return string[]
718 */
719 private function prepareRoleList(): array
720 {
721 $all = [];
722 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
723 $all[] = $role['title'];
724 }
725
726 return $all;
727 }
728
732 private function prepareAutomaticRoleList(): array
733 {
734 $this->initRoleAssignments();
735 $all = [];
736 foreach ($this->assignments_obj->getAssignments() as $assignment) {
737 if ($assignment['domain'] !== '' && $assignment['role']) {
738 $all[] = $assignment['domain'] . ' -> ' . ilObjRole::_lookupTitle((int) $assignment['role']);
739 }
740 }
741
742 if ((string) $this->assignments_obj->getDefaultRole() !== '') {
743 $all[] = $this->lng->txt('reg_default') . ' -> ' . ilObjRole::_lookupTitle($this->assignments_obj->getDefaultRole());
744 }
745
746 return $all;
747 }
748
749 private function prepareAccessLimitationRoleList(): array
750 {
752 $all = [];
753 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
754 switch ($this->access_limitations_obj->getMode((int) $role['id'])) {
755 case 'absolute':
756 $txt_access_value = $this->lng->txt('reg_access_limitation_limited_until');
757 $txt_access_value .= " " . ilDatePresentation::formatDate(
758 new ilDateTime($this->access_limitations_obj->getAbsolute((int) $role['id']), IL_CAL_UNIX)
759 );
760 break;
761
762 case 'relative':
763 $months = $this->access_limitations_obj->getRelative($role['id'], 'm');
764 $days = $this->access_limitations_obj->getRelative($role['id'], 'd');
765
766 $txt_access_value = $this->lng->txt('reg_access_limitation_limited_time') . " ";
767
768 if ($months) {
769 if ($days) {
770 $txt_access_value .= ", ";
771 } else {
772 $txt_access_value .= " " . $this->lng->txt('and') . " ";
773 }
774 } elseif ($days) {
775 $txt_access_value .= " " . $this->lng->txt('and') . " ";
776 }
777
778 if ($months) {
779 $txt_access_value .= $months . " ";
780 $txt_access_value .= ($months === 1) ? $this->lng->txt('month') : $this->lng->txt('months');
781
782 if ($days) {
783 $txt_access_value .= " " . $this->lng->txt('and') . " ";
784 }
785 }
786
787 if ($days) {
788 $txt_access_value .= $days . " ";
789 $txt_access_value .= ($days === 1) ? $this->lng->txt('day') : $this->lng->txt('days');
790 }
791 break;
792
793 default:
794 $txt_access_value = $this->lng->txt('reg_access_limitation_none');
795 break;
796 }
797
798 $all[] = $role['title'] . ' (' . $txt_access_value . ')';
799 }
800
801 return $all;
802 }
803
804 private function initRoleAssignments(): void
805 {
806 if (!$this->assignments_obj instanceof ilRegistrationRoleAssignments) {
807 $this->assignments_obj = new ilRegistrationRoleAssignments();
808 }
809 }
810
811 private function initRoleAccessLimitations(): void
812 {
813 if (!$this->access_limitations_obj instanceof ilRegistrationRoleAccessLimitations) {
814 $this->access_limitations_obj = new ilRegistrationRoleAccessLimitations();
815 }
816 }
817
818 public function listCodes(): void
819 {
820 $this->checkAccess('read');
821 $this->setSubTabs('registration_codes');
822 if ($this->checkAccessBool('write')) {
823 $this->toolbar->addButton(
824 $this->lng->txt('registration_codes_add'),
825 $this->ctrl->getLinkTarget($this, 'addCodes')
826 );
827 }
828 $this->tpl->setContent($this->ui_renderer->render([
829 $this->getRegistrationFilter()->getFilterComponent(),
830 $this->getRegistrationCodeTable()->getTableComponent($this->getRegistrationFilter())
831 ]));
832 }
833
835 {
836 if (!isset($this->registration_codes_table)) {
837 $this->registration_codes_table = new RegistrationCodesTable(
838 $this->http->request(),
839 $this->lng,
840 $this->ui_factory,
841 new DataFactory(),
842 $this->rbacreview,
843 $this->ctrl->getLinkTarget($this, 'listCodes', '', true),
844 $this->user,
845 $this->code_repository,
846 $this->checkAccessBool('write'),
847 );
848 }
849
851 }
852
854 {
855 if (!isset($this->registration_code_filter)) {
856 $this->registration_code_filter = new RegistrationFilterComponent(
857 $this->ctrl->getLinkTarget($this, 'listCodes', '', true),
858 $this->ui_factory,
859 $this->ui_service,
860 $this->lng,
861 $this->rbacreview,
862 $this->code_repository
863 );
864 }
865
867 }
868
870 {
871 $this->form_gui = new ilPropertyFormGUI();
872 $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'createCodes'));
873 $this->form_gui->setTitle($this->lng->txt('registration_codes_edit_header'));
874
875 $count = new ilNumberInputGUI($this->lng->txt('registration_codes_number'), 'reg_codes_number');
876 $count->setSize(4);
877 $count->setMaxLength(4);
878 $count->setMinValue(1);
879 $count->setMaxValue(1000);
880 $count->setRequired(true);
881 $this->form_gui->addItem($count);
882
883 // type
884 $code_type = new ilCheckboxGroupInputGUI($this->lng->txt('registration_codes_type'), 'code_type');
885 $code_type->setRequired(true);
886
887 $code_type->addOption(
889 $this->lng->txt('registration_codes_type_reg'),
890 (string) self::CODE_TYPE_REGISTRATION,
891 $this->lng->txt('registration_codes_type_reg_info')
892 )
893 );
894 $code_type->addOption(
896 $this->lng->txt('registration_codes_type_ext'),
897 (string) self::CODE_TYPE_EXTENSION,
898 $this->lng->txt('registration_codes_type_ext_info')
899 )
900 );
901 $this->form_gui->addItem($code_type);
902
903 $sec = new ilFormSectionHeaderGUI();
904 $sec->setTitle($this->lng->txt('registration_codes_roles_title'));
905 $this->form_gui->addItem($sec);
906
907 $options = ["" => $this->lng->txt('registration_codes_no_assigned_role')];
908 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
909 if (!in_array($role_id, [SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID], true)) {
910 $options[$role_id] = ilObject::_lookupTitle($role_id);
911 }
912 }
913 $roles = new ilSelectInputGUI($this->lng->txt("registration_codes_roles"), "reg_codes_role");
914 $roles->setInfo($this->lng->txt("registration_codes_override_info"));
915 $roles->setOptions($options);
916 $this->form_gui->addItem($roles);
917
918 $local = new ilTextInputGUI($this->lng->txt("registration_codes_roles_local"), "reg_codes_local");
919 $local->setMulti(true);
920 $local->setDataSource($this->ctrl->getLinkTarget($this, "getLocalRoleAutoComplete", "", true));
921 $this->form_gui->addItem($local);
922
923 $sec = new ilFormSectionHeaderGUI();
924 $sec->setTitle($this->lng->txt('reg_access_limitations'));
925 $this->form_gui->addItem($sec);
926
927 $limit = new ilRadioGroupInputGUI($this->lng->txt("reg_access_limitation_mode"), "reg_limit");
928 $limit->setInfo($this->lng->txt("registration_codes_override_info"));
929 $this->form_gui->addItem($limit);
930
931 $opt = new ilRadioOption($this->lng->txt("registration_codes_roles_limitation_none"), "none");
932 $limit->addOption($opt);
933
934 $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_none"), "unlimited");
935 $limit->addOption($opt);
936
937 $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_mode_absolute"), "absolute");
938 $limit->addOption($opt);
939
940 $dt = new ilDateTimeInputGUI($this->lng->txt("reg_access_limitation_mode_absolute_target"), "abs_date");
941 $dt->setRequired(true);
942 $opt->addSubItem($dt);
943
944 $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_mode_relative"), "relative");
945 $limit->addOption($opt);
946
947 $dur = new ilDurationInputGUI($this->lng->txt("reg_access_limitation_mode_relative_target"), "rel_date");
948 $dur->setRequired(true);
949 $dur->setShowMonths(true);
950 $dur->setShowDays(true);
951 $dur->setShowHours(false);
952 $dur->setShowMinutes(false);
953 $opt->addSubItem($dur);
954
955 $this->form_gui->addCommandButton('createCodes', $this->lng->txt('create'));
956 $this->form_gui->addCommandButton('listCodes', $this->lng->txt('cancel'));
957 return $this->form_gui;
958 }
959
960 // see ilRoleAutoCompleteInputGUI
961 public function getLocalRoleAutoComplete(): void
962 {
963 $q = $_REQUEST["term"];
965 echo $list;
966 exit;
967 }
968
969 public function addCodes(): void
970 {
971 $this->checkAccess('write');
972 $this->setSubTabs('registration_codes');
973 $this->initAddCodesForm();
974
975 // default
976 $limit = $this->form_gui->getItemByPostVar("reg_limit");
977 $limit->setValue("none");
978 $this->tpl->setContent($this->form_gui->getHTML());
979 }
980
981 public function createCodes(): void
982 {
983 $this->checkAccess('write');
984 $this->setSubTabs('registration_codes');
985
986 $this->initAddCodesForm();
987 $valid = $this->form_gui->checkInput();
988 if ($valid) {
989 $number = $this->form_gui->getInput('reg_codes_number');
990 $role = (int) $this->form_gui->getInput('reg_codes_role');
991 $local = $this->form_gui->getInput("reg_codes_local");
992
993 if (is_array($local)) {
994 $role_ids = [];
995 foreach (array_unique($local) as $item) {
996 if (trim($item)) {
997 $role_id = $this->rbacreview->roleExists($item);
998 if ($role_id) {
999 $role_ids[] = $role_id;
1000 }
1001 }
1002 }
1003 if (count($role_ids)) {
1004 $local = $role_ids;
1005 }
1006 }
1007
1008 $date = null;
1009 $limit = $this->form_gui->getInput("reg_limit");
1010 switch ($limit) {
1011 case "absolute":
1012 $date_input = $this->form_gui->getItemByPostVar("abs_date");
1013 $date = $date_input->getDate()->get(IL_CAL_DATE);
1014 if ($date < date("Y-m-d")) {
1015 $date_input->setAlert($this->lng->txt("form_msg_wrong_date"));
1016 $valid = false;
1017 }
1018 break;
1019
1020 case "relative":
1021 $date = $this->form_gui->getInput("rel_date");
1022 if (!array_sum($date)) {
1023 $valid = false;
1024 } else {
1025 $date = serialize([
1026 "d" => $date["dd"],
1027 "m" => $date["MM"] % 12,
1028 "y" => (int) floor($date["MM"] / 12)
1029 ]);
1030 }
1031 break;
1032
1033 case "none":
1034 $limit = null;
1035 break;
1036 }
1037 }
1038
1039 if ($valid) {
1040 $stamp = time();
1041 for ($loop = 1; $loop <= $number; $loop++) {
1042 $code_types = (array) $this->form_gui->getInput('code_type');
1043
1045 $role,
1046 $stamp,
1047 $local,
1048 $limit,
1049 $date,
1050 in_array(self::CODE_TYPE_REGISTRATION, $code_types) ? true : false,
1051 in_array(self::CODE_TYPE_EXTENSION, $code_types) ? true : false
1052 );
1053 }
1054
1055 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
1056 $this->ctrl->redirect($this, "listCodes");
1057 } else {
1058 $this->form_gui->setValuesByPost();
1059 $this->tpl->setContent($this->form_gui->getHTML());
1060 }
1061 }
1062
1063 public function deleteCodes(): void
1064 {
1065 $this->checkAccess("write");
1066
1067 $ids = [];
1068 if ($this->http->wrapper()->post()->has('id')) {
1069 $ids = $this->http->wrapper()->post()->retrieve(
1070 'id',
1071 $this->refinery->kindlyTo()->listOf(
1072 $this->refinery->kindlyTo()->int()
1073 )
1074 );
1075 }
1076 $this->code_repository->deleteCodes($ids);
1077 $this->tpl->setOnScreenMessage('success', $this->lng->txt('info_deleted'), true);
1078 $this->ctrl->redirect($this, "listCodes");
1079 }
1080
1081 public function deleteConfirmation(): void
1082 {
1083 $this->checkAccess('write');
1084 $codes = [];
1085 if ($this->http->wrapper()->query()->has('registration_codes_code_ids')) {
1086 $ids = $this->http->wrapper()->query()->retrieve(
1087 'registration_codes_code_ids',
1088 $this->refinery->kindlyTo()->listOf(
1089 $this->refinery->kindlyTo()->string()
1090 )
1091 );
1092 if ($ids === ['ALL_OBJECTS']) {
1093 $codes = $this->code_repository->getCodesByFilter($this->getRegistrationFilter()->getFilterData());
1094 } else {
1095 $ids = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())->transform($ids);
1096 $codes = $this->code_repository->loadCodesByIds($ids);
1097 }
1098 }
1099 if (!count($codes)) {
1100 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_select_one'), true);
1101 $this->ctrl->redirect($this, 'listCodes');
1102 }
1103 $this->setSubTabs('registration_codes');
1104
1105 $gui = new ilConfirmationGUI();
1106 $gui->setHeaderText($this->lng->txt('info_delete_sure'));
1107 $gui->setCancel($this->lng->txt('cancel'), 'listCodes');
1108 $gui->setConfirm($this->lng->txt('confirm'), 'deleteCodes');
1109 $gui->setFormAction($this->ctrl->getFormAction($this, 'deleteCodes'));
1110
1111 foreach ($codes as $code) {
1112 $gui->addItem('id[]', (string) $code['code_id'], $code['code']);
1113 }
1114 $this->tpl->setContent($gui->getHTML());
1115 }
1116
1117 public function exportCodes(): void
1118 {
1119 $codes = [];
1120 if ($this->http->wrapper()->query()->has('registration_codes_code_ids')) {
1121 $ids = $this->http->wrapper()->query()->retrieve(
1122 'registration_codes_code_ids',
1123 $this->refinery->kindlyTo()->listOf(
1124 $this->refinery->kindlyTo()->string()
1125 )
1126 );
1127 if ($ids === ['ALL_OBJECTS']) {
1128 $codes = $this->code_repository->getCodesByFilter($this->getRegistrationFilter()->getFilterData());
1129 } else {
1130 $ids = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())->transform($ids);
1131 $codes = $this->code_repository->loadCodesByIds($ids);
1132 }
1133
1134 $codes = array_filter(array_map(
1135 static fn($code) => (string) ($code['code'] ?? ''),
1136 $codes
1137 ));
1138 }
1139
1140 if (count($codes)) {
1142 implode("\r\n", $codes),
1143 'ilias_registration_codes_' . date('d-m-Y') . '.txt',
1144 'text/plain'
1145 );
1146 } else {
1147 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('registration_export_codes_no_data'));
1148 $this->listCodes();
1149 }
1150 }
1151}
$duration
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
@ilCtrl_Calls ILIAS\User\Settings\NewAccountMail\SettingsGUI: ILIAS\User\Settings\NewAccountMail\Uplo...
const IL_CAL_DATE
const IL_CAL_UNIX
error(string $a_errmsg)
This class represents a property in a property form.
This class represents a checkbox property in a property form.
This class represents an option in a checkbox group.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a custom property in a property form.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
This class represents a date/time property in a property form.
@classDescription Date and time handling
This class represents a duration (typical hh:mm:ss) property in a property form.
Error Handling & global info handling.
setFormAction(string $a_formaction)
This class represents a section header in a property form.
language handling
This class represents a number property in a property form.
static _lookupRegisterAllowed()
get all roles that are activated in user registration
static _lookupAllowRegister(int $a_role_id)
check whether role is allowed in user registration or not
User class.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
setValuesByArray(array $a_values, bool $a_restrict_to_value_keys=false)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
This class represents a property in a property form.
This class represents an option in a radio group.
class ilRbacReview Contains Review functions of core Rbac.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
static create(int $role, int $stamp, array $local_roles, ?string $limit, ?string $limit_date, bool $reg_type, bool $ext_type)
Class class.ilregistrationEmailRoleAssignments.
Class ilRegistrationSettingsGUI.
readonly ILIAS Refinery Factory $refinery
readonly ILIAS HTTP Services $http
editRoleAccessLimitations(?ilPropertyFormGUI $form=null)
readonly RegistrationFilterComponent $registration_code_filter
editEmailAssignments(?ilPropertyFormGUI $form=null)
ilRegistrationRoleAssignments $assignments_obj
parseRoleList(array $roles, string $url)
readonly RegistrationCodesTable $registration_codes_table
setSubTabs(string $activeTab='registration_settings')
readonly RegistrationCodeRepository $code_repository
editRoles(?ilPropertyFormGUI $form=null)
initFormValues(ilPropertyFormGUI $formGUI)
ilRegistrationRoleAccessLimitations $access_limitations_obj
Class ilObjAuthSettingsGUI.
static getList(string $a_str)
Get completion list.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Filter service.
static deliverData(string $a_data, string $a_filename, string $mime="application/octet-stream")
const SYSTEM_ROLE_ID
Definition: constants.php:29
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
const USER_FOLDER_ID
Definition: constants.php:33
$valid
exit
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$_GET['cmd']
Definition: lti.php:26
$res
Definition: ltiservices.php:69
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:25
$url
Definition: shib_logout.php:70
$counter