ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 }
259 return $form_gui;
260 }
261
262 public function initFormValues(ilPropertyFormGUI $formGUI): void
263 {
265 if ($this->registration_settings->roleSelectionEnabled()) {
267 } elseif ($this->registration_settings->automaticRoleAssignmentEnabled()) {
269 }
270
272 $values = [
273 'reg_type' => $this->registration_settings->getRegistrationType(),
274 'reg_hash_life_time' => $this->registration_settings->getRegistrationHashLifetime(),
275 'reg_pwd' => $this->registration_settings->passwordGenerationEnabled(),
276 'reg_approver' => $this->registration_settings->getApproveRecipientLogins(),
277 'reg_role_type' => $role_type,
278 'reg_access_limitation' => $this->registration_settings->getAccessLimitation(),
279 'reg_allowed_domains' => implode(';', $this->registration_settings->getAllowedDomains())
280 ];
281
282 $allow_codes = $this->registration_settings->getAllowCodes();
283 $reg_type = $this->registration_settings->getRegistrationType();
284 if ($allow_codes && in_array($reg_type, [
288 ], true)) {
289 $values['reg_codes_' . $reg_type] = true;
290 }
291
292 $formGUI->setValuesByArray($values);
293 }
294
295 public function view(): void
296 {
297 $this->checkAccess('visible,read');
298 $this->setSubTabs();
299
300 // edit new accout mail
301 $this->ctrl->setParameterByClass("ilobjuserfoldergui", "ref_id", USER_FOLDER_ID);
302 if ($this->checkAccessBool('write')) {
303 $this->toolbar->addButton(
304 $this->lng->txt('registration_user_new_account_mail'),
305 $this->ctrl->getLinkTargetByClass(
306 [
307 ilAdministrationGUI::class,
308 ilObjUserFolderGUI::class,
309 NewAccountMailSettingsGUI::class
310
311 ],
312 'show'
313 )
314 );
315 $this->ctrl->setParameterByClass(ilObjUserFolderGUI::class, 'ref_id', $_GET['ref_id']);
316 }
317
318 $form = $this->initForm();
319 $this->initFormValues($form);
320 $this->tpl->setContent($form->getHTML());
321 }
322
323 public function save(): bool
324 {
325 $this->checkAccess('write');
326
327 $form = $this->initForm();
328 $res = $form->checkInput();
329 $this->registration_settings->setRegistrationType((int) $form->getInput('reg_type'));
330 $this->registration_settings->setPasswordGenerationStatus((bool) $form->getInput('reg_pwd'));
331 $this->registration_settings->setApproveRecipientLogins($form->getInput('reg_approver'));
332 $this->registration_settings->setRoleType((int) $form->getInput('reg_role_type'));
333 $this->registration_settings->setAccessLimitation((bool) $form->getInput('reg_access_limitation'));
334 $this->registration_settings->setAllowedDomains((string) $form->getInput('reg_allowed_domains'));
335
336 $allow_codes = false;
337 $reg_type = (int) $form->getInput('reg_type');
338 if (in_array($reg_type, [
342 ], true)) {
343 $allow_codes = (bool) $form->getInput('reg_codes_' . $reg_type);
344 }
345 $this->registration_settings->setAllowCodes($allow_codes);
346
347 $hash_life_time = $form->getInput('reg_hash_life_time');
348 if (!preg_match('/^([0]|([1-9][0-9]*))([\.,][0-9]+)?$/', (string) $hash_life_time)) {
349 $this->registration_settings->setRegistrationHashLifetime(ilRegistrationSettings::REG_HASH_LIFETIME_MIN_VALUE);
350 } else {
351 $this->registration_settings->setRegistrationHashLifetime(max(
352 (int) $hash_life_time,
354 ));
355 }
356
357 if ($error_code = $this->registration_settings->validate()) {
358 switch ($error_code) {
360 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('reg_unknown_recipients') . ' ' . $this->registration_settings->getUnknown());
361 $this->view();
362 return false;
363
365 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('reg_approve_needs_recipient') . ' ' . $this->registration_settings->getUnknown());
366 $this->view();
367 return false;
368 }
369 }
370
371 $this->registration_settings->save();
372 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
373 $this->view();
374 return true;
375 }
376
377 protected function initRolesForm(): ilPropertyFormGUI
378 {
379 $role_form = new ilPropertyFormGUI();
380 $role_form->setFormAction($this->ctrl->getFormAction($this, 'save'));
381 $role_form->setTitle($this->lng->txt('reg_selectable_roles'));
382
383 $roles = new ilCheckboxGroupInputGUI($this->lng->txt('reg_available_roles'), 'roles');
384 $allowed_roles = [];
385 foreach ($this->rbacreview->getGlobalRoles() as $role) {
386 if ($role === SYSTEM_ROLE_ID || $role === ANONYMOUS_ROLE_ID) {
387 continue;
388 }
389 $role_option = new ilCheckboxOption(ilObjRole::_lookupTitle($role));
390 $role_option->setValue((string) $role);
391 $roles->addOption($role_option);
392 $allowed_roles[$role] = ilObjRole::_lookupAllowRegister($role);
393 }
394
395 $roles->setUseValuesAsKeys(true);
396 $roles->setValue($allowed_roles);
397 $role_form->addItem($roles);
398
399 if ($this->checkAccessBool('write')) {
400 $role_form->addCommandButton("updateRoles", $this->lng->txt("save"));
401 }
402 $role_form->addCommandButton("view", $this->lng->txt("cancel"));
403 return $role_form;
404 }
405
406 public function editRoles(?ilPropertyFormGUI $form = null): void
407 {
408 $this->checkAccess('write');
409 $this->tabs->clearTargets();
410 $this->tabs->setBackTarget(
411 $this->lng->txt("registration_settings"),
412 $this->ctrl->getLinkTarget($this, "view")
413 );
414 if (!$form instanceof ilPropertyFormGUI) {
415 $form = $this->initRolesForm();
416 }
417 $this->tpl->setContent($form->getHTML());
418 }
419
420 public function updateRoles(): bool
421 {
422 $this->checkAccess('write');
423 $form = $this->initRolesForm();
424 if ($form->checkInput()) {
425 $roles = (array) $form->getInput('roles');
426 if (count($roles) < 1) {
427 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_last_role_for_registration'));
428 $this->editRoles();
429 return false;
430 }
431 foreach ($this->rbacreview->getGlobalRoles() as $role) {
432 if ($role_obj = ilObjectFactory::getInstanceByObjId($role, false)) {
433 $role_obj->setAllowRegister(isset($roles[$role]) && (int) $roles[$role] === 1);
434 $role_obj->update();
435 }
436 }
437 }
438 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
439 $this->view();
440 return true;
441 }
442
443 public function editEmailAssignments(?ilPropertyFormGUI $form = null): void
444 {
445 $this->checkAccess('write');
446 $this->tabs->clearTargets();
447 $this->tabs->setBackTarget(
448 $this->lng->txt("registration_settings"),
449 $this->ctrl->getLinkTarget($this, "view")
450 );
451
452 $this->initRoleAssignments();
453 $form = $form ?? $this->initEmailAssignmentForm();
454 $this->tpl->setContent($form->getHTML());
455 }
456
458 {
459 $role_assignment_form = new ilPropertyFormGUI();
460 $role_assignment_form->setFormAction($this->ctrl->getFormAction($this));
461 $role_assignment_form->setTitle($this->lng->txt('reg_email_role_assignment'));
462
463 $global_roles = ["" => $this->lng->txt("links_select_one")];
464 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
465 if ($role_id === ANONYMOUS_ROLE_ID) {
466 continue;
467 }
468
469 $global_roles[$role_id] = ilObjRole::_lookupTitle($role_id);
470 $role_assignments = new ilCheckboxInputGUI(ilObjRole::_lookupTitle($role_id), "role_assigned_$role_id");
471
472 $domains = $this->assignments_obj->getDomainsByRole($role_id);
473
474 $domain = new ilTextInputGUI($this->lng->txt('reg_domain'), "domain_$role_id");
475 $domain->setMulti(true);
476 $domain->setValidationRegexp("/^@.*\.[a-zA-Z]{1,4}$/");
477 if (!empty($domains)) {
478 $domain->setValue($domains[0]);
479 $domain->setMultiValues($domains);
480 $role_assignments->setChecked(true);
481 }
482
483 $role_assignments->addSubItem($domain);
484 $role_assignment_form->addItem($role_assignments);
485 }
486
487 $default_role = new ilSelectInputGUI($this->lng->txt('reg_default'));
488 $default_role->setPostVar("default_role");
489 $default_role->setOptions($global_roles);
490 $default_role->setValue($this->assignments_obj->getDefaultRole());
491 $default_role->setRequired(true);
492 $role_assignment_form->addItem($default_role);
493
494 $role_assignment_form->addCommandButton("saveAssignment", $this->lng->txt("save"));
495 $role_assignment_form->addCommandButton("view", $this->lng->txt("cancel"));
496
497 return $role_assignment_form;
498 }
499
500 public function editRoleAccessLimitations(?ilPropertyFormGUI $form = null): void
501 {
502 global $DIC;
503
504 $this->checkAccess('write');
505 $this->tabs->clearTargets();
506 $this->tabs->setBackTarget(
507 $this->lng->txt("registration_settings"),
508 $this->ctrl->getLinkTarget($this, "view")
509 );
511 if (null === $form) {
512 $form = $this->initRoleAccessForm();
513 }
514 $this->tpl->setContent($form->getHTML());
515 }
516
518 {
519 $form = new ilPropertyFormGUI();
520 $form->setFormAction($this->ctrl->getFormAction($this));
521 $form->setTitle($this->lng->txt('reg_role_access_limitations'));
522 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
523 $role_access = new ilRadioGroupInputGUI($role['title'], "role_access_" . $role['id']);
524
525 $op_unlimited = new ilRadioOption($this->lng->txt('reg_access_limitation_mode_unlimited'), "unlimited");
526
527 $op_absolute = new ilRadioOption($this->lng->txt('reg_access_limitation_mode_absolute'), "absolute");
528 $absolute_date = new ilDateTime(
529 date("d.m.Y", $this->access_limitations_obj->getAbsolute($role['id'])),
531 );
532 $date = new ilDateTimeInputGUI("", "absolute_date_" . $role['id']);
533 $date->setDate($absolute_date);
534 $op_absolute->addSubItem($date);
535
536 $op_relative = new ilRadioOption($this->lng->txt('reg_access_limitation_mode_relative'), "relative");
537 $duration = new ilDurationInputGUI("", "duration_" . $role['id']);
538 $duration->setShowMinutes(false);
539 $duration->setShowHours(false);
540 $duration->setShowDays(true);
541 $duration->setShowMonths(true);
542 $duration->setDays($this->access_limitations_obj->getRelative($role['id'], 'd'));
543 $duration->setMonths($this->access_limitations_obj->getRelative($role['id'], 'm'));
544 $op_relative->addSubItem($duration);
545
546 $role_access->addOption($op_unlimited);
547 $role_access->addOption($op_absolute);
548 $role_access->addOption($op_relative);
549 $role_access->setValue(
550 $this->access_limitations_obj->getMode(
551 $role['id']
552 ) === 'null' ? 'unlimited' : $this->access_limitations_obj->getMode($role['id'])
553 );
554
555 $form->addItem($role_access);
556 }
557
558 $form->addCommandButton("saveRoleAccessLimitations", $this->lng->txt("save"));
559 $form->addCommandButton("view", $this->lng->txt("cancel"));
560
561 return $form;
562 }
563
564 public function saveAssignment(): bool
565 {
566 $this->checkAccess('write');
567 $this->initRoleAssignments();
568 $form = $this->initEmailAssignmentForm();
569 $is_valid = $form->checkInput();
570 $form->setValuesByPost();
571 if (!$is_valid) {
572 $this->editEmailAssignments($form);
573 return false;
574 }
575
576 $assignments_by_domain = [];
577 $problems_domains_by_field_id = [];
578 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
579 if ($role_id === ANONYMOUS_ROLE_ID) {
580 continue;
581 }
582
583 $role_assigned_input = $form->getInput("role_assigned_$role_id");
584 if (!$role_assigned_input) {
585 continue;
586 }
587
588 $domain_input = $form->getInput("domain_$role_id");
589 foreach ($domain_input as $domain) {
590 if (!is_string($domain) || $domain === '') {
591 continue;
592 }
593
594 if (isset($assignments_by_domain[$domain])) {
595 if (!isset($problems_domains_by_field_id["role_assigned_$role_id"])) {
596 $problems_domains_by_field_id["role_assigned_$role_id"] = [];
597 }
598
599 $problems_domains_by_field_id["domain_$role_id"][$domain] = $domain;
600 continue;
601 }
602
603 $assignments_by_domain[$domain] = $role_id;
604 }
605 }
606
607 if ($problems_domains_by_field_id !== []) {
608 foreach ($problems_domains_by_field_id as $field_id => $domains) {
609 $domain_string = implode(', ', $domains);
610 $alert = sprintf($this->lng->txt('reg_domain_already_assigned_p'), $domain_string);
611 if (count($domains) === 1) {
612 $alert = sprintf($this->lng->txt('reg_domain_already_assigned_s'), $domain_string);
613 }
614 $form->getItemByPostVar($field_id)->setAlert($alert);
615 }
616
617 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
618 $this->editEmailAssignments($form);
619 return false;
620 }
621
622 $this->assignments_obj->deleteAll();
623
624 $counter = 0;
625 foreach ($assignments_by_domain as $domain => $role_id) {
626 $this->assignments_obj->setDomain($counter, $domain);
627 $this->assignments_obj->setRole($counter, $role_id);
628 $counter++;
629 }
630 $default_role = $form->getInput("default_role");
631 $this->assignments_obj->setDefaultRole((int) $default_role);
632 $this->assignments_obj->save();
633 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
634 $this->view();
635 return true;
636 }
637
638 public function saveRoleAccessLimitations(): bool
639 {
640 $this->checkAccess('write');
642
643 $form = $this->initRoleAccessForm();
644 if (!$form->checkInput()) {
645 $form->setValuesByPost();
646 $this->editRoleAccessLimitations($form);
647 return false;
648 }
649
650 $this->access_limitations_obj->resetAccessLimitations();
651 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
652 $mode = $form->getInput('role_access_' . $role['id']);
653 $this->access_limitations_obj->setMode($mode, $role['id']);
654
655 if ($mode === 'absolute') {
656 $this->access_limitations_obj->setAbsolute($form->getInput('absolute_date_' . $role['id']), $role['id']);
657 }
658
659 if ($mode === 'relative') {
660 $this->access_limitations_obj->setRelative($form->getInput('duration_' . $role['id']), $role['id']);
661 }
662 }
663
664 if ($err = $this->access_limitations_obj->validate()) {
665 switch ($err) {
667 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('reg_access_limitation_missing_mode'));
668 break;
669
671 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('reg_access_limitation_out_of_date'));
672 break;
673 }
675 return false;
676 }
677
678 $this->access_limitations_obj->save();
679 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
680 $this->view();
681 return true;
682 }
683
689 private function parseRoleList(array $roles, string $url): string
690 {
691 $tpl = new ilTemplate('tpl.registration_roles.html', true, true, 'components/ILIAS/Registration');
692
693 $tpl->setVariable("EDIT", $this->lng->txt("edit"));
694 $tpl->setVariable("LINK_EDIT", $url);
695
696 if (is_array($roles) && count($roles)) {
697 foreach ($roles as $role) {
698 $tpl->setCurrentBlock("list_item");
699 $tpl->setVariable("LIST_ITEM_ITEM", $role);
701 }
702 } else {
703 $tpl->setVariable("NONE", $this->lng->txt('none'));
704 }
705 return $tpl->get();
706 }
707
708 /***
709 * @return string[]
710 */
711 private function prepareRoleList(): array
712 {
713 $all = [];
714 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
715 $all[] = $role['title'];
716 }
717
718 return $all;
719 }
720
724 private function prepareAutomaticRoleList(): array
725 {
726 $this->initRoleAssignments();
727 $all = [];
728 foreach ($this->assignments_obj->getAssignments() as $assignment) {
729 if ($assignment['domain'] !== '' && $assignment['role']) {
730 $all[] = $assignment['domain'] . ' -> ' . ilObjRole::_lookupTitle((int) $assignment['role']);
731 }
732 }
733
734 if ((string) $this->assignments_obj->getDefaultRole() !== '') {
735 $all[] = $this->lng->txt('reg_default') . ' -> ' . ilObjRole::_lookupTitle($this->assignments_obj->getDefaultRole());
736 }
737
738 return $all;
739 }
740
741 private function prepareAccessLimitationRoleList(): array
742 {
744 $all = [];
745 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
746 switch ($this->access_limitations_obj->getMode((int) $role['id'])) {
747 case 'absolute':
748 $txt_access_value = $this->lng->txt('reg_access_limitation_limited_until');
749 $txt_access_value .= " " . ilDatePresentation::formatDate(
750 new ilDateTime($this->access_limitations_obj->getAbsolute((int) $role['id']), IL_CAL_UNIX)
751 );
752 break;
753
754 case 'relative':
755 $months = $this->access_limitations_obj->getRelative($role['id'], 'm');
756 $days = $this->access_limitations_obj->getRelative($role['id'], 'd');
757
758 $txt_access_value = $this->lng->txt('reg_access_limitation_limited_time') . " ";
759
760 if ($months) {
761 if ($days) {
762 $txt_access_value .= ", ";
763 } else {
764 $txt_access_value .= " " . $this->lng->txt('and') . " ";
765 }
766 } elseif ($days) {
767 $txt_access_value .= " " . $this->lng->txt('and') . " ";
768 }
769
770 if ($months) {
771 $txt_access_value .= $months . " ";
772 $txt_access_value .= ($months === 1) ? $this->lng->txt('month') : $this->lng->txt('months');
773
774 if ($days) {
775 $txt_access_value .= " " . $this->lng->txt('and') . " ";
776 }
777 }
778
779 if ($days) {
780 $txt_access_value .= $days . " ";
781 $txt_access_value .= ($days === 1) ? $this->lng->txt('day') : $this->lng->txt('days');
782 }
783 break;
784
785 default:
786 $txt_access_value = $this->lng->txt('reg_access_limitation_none');
787 break;
788 }
789
790 $all[] = $role['title'] . ' (' . $txt_access_value . ')';
791 }
792
793 return $all;
794 }
795
796 private function initRoleAssignments(): void
797 {
798 if (!$this->assignments_obj instanceof ilRegistrationRoleAssignments) {
799 $this->assignments_obj = new ilRegistrationRoleAssignments();
800 }
801 }
802
803 private function initRoleAccessLimitations(): void
804 {
805 if (!$this->access_limitations_obj instanceof ilRegistrationRoleAccessLimitations) {
806 $this->access_limitations_obj = new ilRegistrationRoleAccessLimitations();
807 }
808 }
809
810 public function listCodes(): void
811 {
812 $this->checkAccess('visible,read');
813 $this->setSubTabs('registration_codes');
814 if ($this->checkAccessBool('write')) {
815 $this->toolbar->addButton(
816 $this->lng->txt('registration_codes_add'),
817 $this->ctrl->getLinkTarget($this, 'addCodes')
818 );
819 }
820 $this->tpl->setContent($this->ui_renderer->render([
821 $this->getRegistrationFilter()->getFilterComponent(),
822 $this->getRegistrationCodeTable()->getTableComponent($this->getRegistrationFilter())
823 ]));
824 }
825
827 {
828 if (!isset($this->registration_codes_table)) {
829 $this->registration_codes_table = new RegistrationCodesTable(
830 $this->http->request(),
831 $this->lng,
832 $this->ui_factory,
833 new DataFactory(),
834 $this->rbacreview,
835 $this->ctrl->getLinkTarget($this, 'listCodes', '', true),
836 $this->user,
837 $this->code_repository,
838 $this->checkAccessBool('write'),
839 );
840 }
841
843 }
844
846 {
847 if (!isset($this->registration_code_filter)) {
848 $this->registration_code_filter = new RegistrationFilterComponent(
849 $this->ctrl->getLinkTarget($this, 'listCodes', '', true),
850 $this->ui_factory,
851 $this->ui_service,
852 $this->lng,
853 $this->rbacreview,
854 $this->code_repository
855 );
856 }
857
859 }
860
862 {
863 $this->form_gui = new ilPropertyFormGUI();
864 $this->form_gui->setFormAction($this->ctrl->getFormAction($this, 'createCodes'));
865 $this->form_gui->setTitle($this->lng->txt('registration_codes_edit_header'));
866
867 $count = new ilNumberInputGUI($this->lng->txt('registration_codes_number'), 'reg_codes_number');
868 $count->setSize(4);
869 $count->setMaxLength(4);
870 $count->setMinValue(1);
871 $count->setMaxValue(1000);
872 $count->setRequired(true);
873 $this->form_gui->addItem($count);
874
875 // type
876 $code_type = new ilCheckboxGroupInputGUI($this->lng->txt('registration_codes_type'), 'code_type');
877 $code_type->setRequired(true);
878
879 $code_type->addOption(
881 $this->lng->txt('registration_codes_type_reg'),
882 (string) self::CODE_TYPE_REGISTRATION,
883 $this->lng->txt('registration_codes_type_reg_info')
884 )
885 );
886 $code_type->addOption(
888 $this->lng->txt('registration_codes_type_ext'),
889 (string) self::CODE_TYPE_EXTENSION,
890 $this->lng->txt('registration_codes_type_ext_info')
891 )
892 );
893 $this->form_gui->addItem($code_type);
894
895 $sec = new ilFormSectionHeaderGUI();
896 $sec->setTitle($this->lng->txt('registration_codes_roles_title'));
897 $this->form_gui->addItem($sec);
898
899 $options = ["" => $this->lng->txt('registration_codes_no_assigned_role')];
900 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
901 if (!in_array($role_id, [SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID], true)) {
902 $options[$role_id] = ilObject::_lookupTitle($role_id);
903 }
904 }
905 $roles = new ilSelectInputGUI($this->lng->txt("registration_codes_roles"), "reg_codes_role");
906 $roles->setInfo($this->lng->txt("registration_codes_override_info"));
907 $roles->setOptions($options);
908 $this->form_gui->addItem($roles);
909
910 $local = new ilTextInputGUI($this->lng->txt("registration_codes_roles_local"), "reg_codes_local");
911 $local->setMulti(true);
912 $local->setDataSource($this->ctrl->getLinkTarget($this, "getLocalRoleAutoComplete", "", true));
913 $this->form_gui->addItem($local);
914
915 $sec = new ilFormSectionHeaderGUI();
916 $sec->setTitle($this->lng->txt('reg_access_limitations'));
917 $this->form_gui->addItem($sec);
918
919 $limit = new ilRadioGroupInputGUI($this->lng->txt("reg_access_limitation_mode"), "reg_limit");
920 $limit->setInfo($this->lng->txt("registration_codes_override_info"));
921 $this->form_gui->addItem($limit);
922
923 $opt = new ilRadioOption($this->lng->txt("registration_codes_roles_limitation_none"), "none");
924 $limit->addOption($opt);
925
926 $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_none"), "unlimited");
927 $limit->addOption($opt);
928
929 $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_mode_absolute"), "absolute");
930 $limit->addOption($opt);
931
932 $dt = new ilDateTimeInputGUI($this->lng->txt("reg_access_limitation_mode_absolute_target"), "abs_date");
933 $dt->setRequired(true);
934 $opt->addSubItem($dt);
935
936 $opt = new ilRadioOption($this->lng->txt("reg_access_limitation_mode_relative"), "relative");
937 $limit->addOption($opt);
938
939 $dur = new ilDurationInputGUI($this->lng->txt("reg_access_limitation_mode_relative_target"), "rel_date");
940 $dur->setRequired(true);
941 $dur->setShowMonths(true);
942 $dur->setShowDays(true);
943 $dur->setShowHours(false);
944 $dur->setShowMinutes(false);
945 $opt->addSubItem($dur);
946
947 $this->form_gui->addCommandButton('createCodes', $this->lng->txt('create'));
948 $this->form_gui->addCommandButton('listCodes', $this->lng->txt('cancel'));
949 return $this->form_gui;
950 }
951
952 // see ilRoleAutoCompleteInputGUI
953 public function getLocalRoleAutoComplete(): void
954 {
955 $q = $_REQUEST["term"];
957 echo $list;
958 exit;
959 }
960
961 public function addCodes(): void
962 {
963 $this->checkAccess('write');
964 $this->setSubTabs('registration_codes');
965 $this->initAddCodesForm();
966
967 // default
968 $limit = $this->form_gui->getItemByPostVar("reg_limit");
969 $limit->setValue("none");
970 $this->tpl->setContent($this->form_gui->getHTML());
971 }
972
973 public function createCodes(): void
974 {
975 $this->checkAccess('write');
976 $this->setSubTabs('registration_codes');
977
978 $this->initAddCodesForm();
979 $valid = $this->form_gui->checkInput();
980 if ($valid) {
981 $number = $this->form_gui->getInput('reg_codes_number');
982 $role = (int) $this->form_gui->getInput('reg_codes_role');
983 $local = $this->form_gui->getInput("reg_codes_local");
984
985 if (is_array($local)) {
986 $role_ids = [];
987 foreach (array_unique($local) as $item) {
988 if (trim($item)) {
989 $role_id = $this->rbacreview->roleExists($item);
990 if ($role_id) {
991 $role_ids[] = $role_id;
992 }
993 }
994 }
995 if (count($role_ids)) {
996 $local = $role_ids;
997 }
998 }
999
1000 $date = null;
1001 $limit = $this->form_gui->getInput("reg_limit");
1002 switch ($limit) {
1003 case "absolute":
1004 $date_input = $this->form_gui->getItemByPostVar("abs_date");
1005 $date = $date_input->getDate()->get(IL_CAL_DATE);
1006 if ($date < date("Y-m-d")) {
1007 $date_input->setAlert($this->lng->txt("form_msg_wrong_date"));
1008 $valid = false;
1009 }
1010 break;
1011
1012 case "relative":
1013 $date = $this->form_gui->getInput("rel_date");
1014 if (!array_sum($date)) {
1015 $valid = false;
1016 } else {
1017 $date = serialize([
1018 "d" => $date["dd"],
1019 "m" => $date["MM"] % 12,
1020 "y" => (int) floor($date["MM"] / 12)
1021 ]);
1022 }
1023 break;
1024
1025 case "none":
1026 $limit = null;
1027 break;
1028 }
1029 }
1030
1031 if ($valid) {
1032 $stamp = time();
1033 for ($loop = 1; $loop <= $number; $loop++) {
1034 $code_types = (array) $this->form_gui->getInput('code_type');
1035
1037 $role,
1038 $stamp,
1039 $local,
1040 $limit,
1041 $date,
1042 in_array(self::CODE_TYPE_REGISTRATION, $code_types) ? true : false,
1043 in_array(self::CODE_TYPE_EXTENSION, $code_types) ? true : false
1044 );
1045 }
1046
1047 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
1048 $this->ctrl->redirect($this, "listCodes");
1049 } else {
1050 $this->form_gui->setValuesByPost();
1051 $this->tpl->setContent($this->form_gui->getHTML());
1052 }
1053 }
1054
1055 public function deleteCodes(): void
1056 {
1057 $this->checkAccess("write");
1058
1059 $ids = [];
1060 if ($this->http->wrapper()->post()->has('id')) {
1061 $ids = $this->http->wrapper()->post()->retrieve(
1062 'id',
1063 $this->refinery->kindlyTo()->listOf(
1064 $this->refinery->kindlyTo()->int()
1065 )
1066 );
1067 }
1068 $this->code_repository->deleteCodes($ids);
1069 $this->tpl->setOnScreenMessage('success', $this->lng->txt('info_deleted'), true);
1070 $this->ctrl->redirect($this, "listCodes");
1071 }
1072
1073 public function deleteConfirmation(): void
1074 {
1075 $this->checkAccess('write');
1076 $codes = [];
1077 if ($this->http->wrapper()->query()->has('registration_codes_code_ids')) {
1078 $ids = $this->http->wrapper()->query()->retrieve(
1079 'registration_codes_code_ids',
1080 $this->refinery->kindlyTo()->listOf(
1081 $this->refinery->kindlyTo()->string()
1082 )
1083 );
1084 if ($ids === ['ALL_OBJECTS']) {
1085 $codes = $this->code_repository->getCodesByFilter($this->getRegistrationFilter()->getFilterData());
1086 } else {
1087 $ids = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())->transform($ids);
1088 $codes = $this->code_repository->loadCodesByIds($ids);
1089 }
1090 }
1091 if (!count($codes)) {
1092 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_select_one'), true);
1093 $this->ctrl->redirect($this, 'listCodes');
1094 }
1095 $this->setSubTabs('registration_codes');
1096
1097 $gui = new ilConfirmationGUI();
1098 $gui->setHeaderText($this->lng->txt('info_delete_sure'));
1099 $gui->setCancel($this->lng->txt('cancel'), 'listCodes');
1100 $gui->setConfirm($this->lng->txt('confirm'), 'deleteCodes');
1101 $gui->setFormAction($this->ctrl->getFormAction($this, 'deleteCodes'));
1102
1103 foreach ($codes as $code) {
1104 $gui->addItem('id[]', (string) $code['code_id'], $code['code']);
1105 }
1106 $this->tpl->setContent($gui->getHTML());
1107 }
1108
1109 public function exportCodes(): void
1110 {
1111 $codes = [];
1112 if ($this->http->wrapper()->query()->has('registration_codes_code_ids')) {
1113 $ids = $this->http->wrapper()->query()->retrieve(
1114 'registration_codes_code_ids',
1115 $this->refinery->kindlyTo()->listOf(
1116 $this->refinery->kindlyTo()->string()
1117 )
1118 );
1119 if ($ids === ['ALL_OBJECTS']) {
1120 $codes = $this->code_repository->getCodesByFilter($this->getRegistrationFilter()->getFilterData());
1121 } else {
1122 $ids = $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int())->transform($ids);
1123 $codes = $this->code_repository->loadCodesByIds($ids);
1124 }
1125
1126 $codes = array_filter(array_map(
1127 static fn($code) => (string) ($code['code'] ?? ''),
1128 $codes
1129 ));
1130 }
1131
1132 if (count($codes)) {
1134 implode("\r\n", $codes),
1135 'ilias_registration_codes_' . date('d-m-Y') . '.txt',
1136 'text/plain'
1137 );
1138 } else {
1139 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('registration_export_codes_no_data'));
1140 $this->listCodes();
1141 }
1142 }
1143}
$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:23
$url
Definition: shib_logout.php:68
$counter