ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjPrivacySecurityGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27{
28 private static array $ERROR_MESSAGE = [];
29
34 public function __construct($a_data, $a_id, $a_call_by_reference = true, $a_prepare_output = true)
35 {
36 $this->type = 'ps';
37 parent::__construct($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
39 }
40
41 public static function initErrorMessages(): void
42 {
43 global $DIC;
44
45 $lng = $DIC->language();
46
47 if (count(self::$ERROR_MESSAGE)) {
48 return;
49 }
52 ilSecuritySettings::$SECURITY_SETTINGS_ERR_CODE_AUTO_HTTPS => $lng->txt("ps_error_message_https_header_missing"),
55 ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MIN_LENGTH => $lng->txt('ps_error_message_invalid_password_min_length'),
56 ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_LENGTH => $lng->txt('ps_error_message_invalid_password_max_length'),
57 ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_AGE => $lng->txt('ps_error_message_invalid_password_max_age'),
58 ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_INVALID_LOGIN_MAX_ATTEMPTS => $lng->txt('ps_error_message_invalid_login_max_attempts'),
59 ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN1 => $lng->txt('ps_error_message_password_min1_because_chars'),
60 ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN2 => $lng->txt('ps_error_message_password_min2_because_chars_numbers'),
61 ilSecuritySettings::SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN3 => $lng->txt('ps_error_message_password_min3_because_chars_numbers_sc'),
63 ];
64 }
65
66 public function executeCommand(): void
67 {
68 $next_class = $this->ctrl->getNextClass($this);
69 $cmd = $this->ctrl->getCmd();
70
71 $this->prepareOutput();
72
73 if (!$this->rbac_system->checkAccess('visible,read', $this->object->getRefId())) {
74 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
75 }
76
77 switch ($next_class) {
78 case 'ilpermissiongui':
79 $this->tabs_gui->setTabActive('perm_settings');
80 $perm_gui = new ilPermissionGUI($this);
81 $this->ctrl->forwardCommand($perm_gui);
82 break;
83
84 default:
85 if (!$cmd || $cmd == 'view') {
86 $cmd = "showPrivacy";
87 }
88
89 $this->$cmd();
90 break;
91 }
92 }
93
98 public function getAdminTabs(): void
99 {
100 if ($this->rbac_system->checkAccess("visible,read", $this->object->getRefId())) {
101 $this->tabs_gui->addTarget(
102 "show_privacy",
103 $this->ctrl->getLinkTarget($this, "showPrivacy"),
104 'showPrivacy'
105 );
106 $this->tabs_gui->addTarget(
107 "show_security",
108 $this->ctrl->getLinkTarget($this, "showSecurity"),
109 'showSecurity'
110 );
111 }
112
113 if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
114 $this->tabs_gui->addTarget(
115 "perm_settings",
116 $this->ctrl->getLinkTargetByClass('ilpermissiongui', "perm"),
117 array(),
118 'ilpermissiongui'
119 );
120 }
121 }
122
123 protected function initPrivacyForm(): ilPropertyFormGUI
124 {
126
127 $this->tabs_gui->setTabActive('show_privacy');
128
129 $form = new ilPropertyFormGUI();
130 $form->setFormAction($this->ctrl->getFormAction($this));
131 $form->setTitle($this->lng->txt('ps_privacy_protection'));
132
134 $this->tpl->setOnScreenMessage('info', $this->lng->txt('ps_warning_modify'));
135 }
136
137 $value = [];
138 if ($privacy->enabledCourseExport()) {
139 $value[] = "export_course";
140 }
141 if ($privacy->enabledGroupExport()) {
142 $value[] = "export_group";
143 }
144 if ($privacy->enabledPRGUserExport()) {
145 $value[] = "export_prg";
146 }
147 if ($privacy->courseConfirmationRequired()) {
148 $value[] = "export_confirm_course";
149 }
150 if ($privacy->groupConfirmationRequired()) {
151 $value[] = "export_confirm_group";
152 }
153 if ($privacy->enabledGroupAccessTimes()) {
154 $value[] = "grp_access_times";
155 }
156 if ($privacy->enabledCourseAccessTimes()) {
157 $value[] = "crs_access_times";
158 }
159 if ($privacy->enabledLearningSequenceAccessTimes()) {
160 $value[] = "lso_access_times";
161 }
162 if ($privacy->participantsListInCoursesEnabled()) {
163 $value[] = 'participants_list_courses';
164 }
165 $group = new ilCheckboxGroupInputGUI($this->lng->txt('ps_profile_export'), 'profile_protection');
166 $group->setValue($value);
167 $check = new ilCheckboxOption();
168 $check->setTitle($this->lng->txt('ps_export_course'));
169 $check->setValue('export_course');
170 $group->addOption($check);
171 $check = new ilCheckboxOption();
172 $check->setTitle($this->lng->txt('ps_export_groups'));
173 $check->setValue('export_group');
174 $group->addOption($check);
175 $check = new ilCheckboxOption();
176 $check->setTitle($this->lng->txt('ps_export_prgs'));
177 $check->setValue('export_prg');
178 $group->addOption($check);
179 $check = new ilCheckboxOption();
180 $check->setTitle($this->lng->txt('ps_export_confirm'));
181 $check->setInfo($this->lng->txt('ps_export_confirm_info'));
182 $check->setValue('export_confirm_course');
183 $group->addOption($check);
184 $check = new ilCheckboxOption();
185 $check->setTitle($this->lng->txt('ps_export_confirm_group'));
186 $check->setInfo($this->lng->txt('ps_export_confirm_group_info'));
187 $check->setValue('export_confirm_group');
188 $group->addOption($check);
189 $check = new ilCheckboxOption();
190 $check->setTitle($this->lng->txt('ps_show_grp_access'));
191 $check->setValue('grp_access_times');
192 $group->addOption($check);
193 $check = new ilCheckboxOption();
194 $check->setTitle($this->lng->txt('ps_show_crs_access'));
195 $check->setValue('crs_access_times');
196 $group->addOption($check);
197 $check = new ilCheckboxOption();
198 $check->setTitle($this->lng->txt('ps_show_lso_access'));
199 $check->setValue('lso_access_times');
200 $group->addOption($check);
201 $form->addItem($group);
202 $check = new ilCheckboxOption();
203 $check->setTitle($this->lng->txt('ps_participants_list_courses'));
204 $check->setValue('participants_list_courses');
205 $group->addOption($check);
206
209 $form,
210 $this
211 );
212
213 if ($this->checkPermissionBool("write")) {
214 $form->addCommandButton('save_privacy', $this->lng->txt('save'));
215 }
216 return $form;
217 }
218
223 public function showPrivacy(?ilPropertyFormGUI $form = null): void
224 {
225 if (!$form instanceof ilPropertyFormGUI) {
226 $form = $this->initPrivacyForm();
227 }
228 $this->tpl->setContent($form->getHTML());
229 }
230
234 public function showSecurity(): void
235 {
237
238 $this->tabs_gui->setTabActive('show_security');
239
240 $form = new ilPropertyFormGUI();
241 $form->setFormAction($this->ctrl->getFormAction($this));
242 $form->setTitle($this->lng->txt('ps_security_protection'));
243
246 $form,
247 $this
248 );
249 $this->tpl->setContent($form->getHTML());
250 }
251
252 public function save_privacy(): void
253 {
254 if (!$this->access->checkAccess('write', '', $this->object->getRefId())) {
255 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
256 }
257
258 $form = $this->initPrivacyForm();
259 $valid = true;
260 if (!$form->checkInput()) {
261 $valid = false;
262 }
263
264 $profile_protection = $form->getInput('profile_protection') ?? [];
266
267 // to determine if agreements need to be reset - see below
268 $old_settings = array(
269 'export_course' => $privacy->enabledCourseExport(),
270 'export_group' => $privacy->enabledGroupExport(),
271 'export_prg' => $privacy->enabledPRGUserExport(),
272 'export_confirm_course' => $privacy->courseConfirmationRequired(),
273 'export_confirm_group' => $privacy->groupConfirmationRequired(),
274 'crs_access_times' => $privacy->enabledCourseAccessTimes(),
275 'grp_access_times' => $privacy->enabledGroupAccessTimes(),
276 'lso_access_times' => $privacy->enabledLearningSequenceAccessTimes(),
277 'participants_list_courses' => $privacy->participantsListInCoursesEnabled()
278 );
279
280 $privacy->enableCourseExport(in_array('export_course', $profile_protection));
281 $privacy->enableGroupExport(in_array('export_group', $profile_protection));
282 $privacy->enablePRGUserExport((bool) in_array('export_prg', $profile_protection));
283 $privacy->setCourseConfirmationRequired(in_array('export_confirm_course', $profile_protection));
284 $privacy->setGroupConfirmationRequired(in_array('export_confirm_group', $profile_protection));
285 $privacy->showGroupAccessTimes(in_array('grp_access_times', $profile_protection));
286 $privacy->showCourseAccessTimes(in_array('crs_access_times', $profile_protection));
287 $privacy->showLearningSequenceAccessTimes(in_array('lso_access_times', $profile_protection));
288
289 $privacy->enableParticipantsListInCourses(in_array('participants_list_courses', $profile_protection));
290
291 // validate settings
292 $code = $privacy->validate();
293 // if error code != 0, display error and do not save
294 if ($code !== 0) {
295 $msg = self::getErrorMessage($code);
296 $this->tpl->setOnScreenMessage('failure', $msg);
297 $form->setValuesByPost();
298 $this->showPrivacy($form);
299 return;
300 } elseif (!$valid) {
301 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
302 $form->setValuesByPost();
303 $this->showPrivacy($form);
304 return;
305 } else {
306 $privacy->save();
307 // reset agreements?
308 $do_reset = false;
309 if (!$old_settings['export_course'] && $privacy->enabledCourseExport()) {
310 $do_reset = true;
311 }
312 if (!$do_reset && !$old_settings['export_group'] && $privacy->enabledGroupExport()) {
313 $do_reset = true;
314 }
315 if (!$do_reset && !$old_settings['export_confirm_course'] && $privacy->courseConfirmationRequired()) {
316 $do_reset = true;
317 }
318 if (!$do_reset && !$old_settings['export_confirm_group'] && $privacy->groupConfirmationRequired()) {
319 $do_reset = true;
320 }
321 if (!$do_reset && !$old_settings['crs_access_times'] && $privacy->enabledCourseAccessTimes()) {
322 $do_reset = true;
323 }
324 if (!$do_reset && !$old_settings['grp_access_times'] && $privacy->enabledGroupAccessTimes()) {
325 $do_reset = true;
326 }
327 if (!$do_reset && !$old_settings['lso_access_times'] && $privacy->enabledLearningSequenceAccessTimes()) {
328 $do_reset = true;
329 }
330 if ($do_reset) {
332 }
333 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
334 }
335 $this->ctrl->redirect($this, 'showPrivacy');
336 }
337
341 public function save_security(): void
342 {
343 if (!$this->access->checkAccess('write', '', $this->object->getRefId())) {
344 $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
345 }
346 $this->showSecurity();
347 }
348
355 public static function getErrorMessage(int $code): string
356 {
358 if (array_key_exists($code, self::$ERROR_MESSAGE)) {
359 return self::$ERROR_MESSAGE[$code];
360 }
361 return '';
362 }
363
364 public function addToExternalSettingsForm(int $a_form_id): array
365 {
366 switch ($a_form_id) {
369 $subitems = [
370 'ps_export_course' => [
371 $privacy->enabledCourseExport(),
373 ],
374 'ps_export_confirm' => [
375 $privacy->courseConfirmationRequired(),
377 ],
378 'ps_show_crs_access' => [
379 $privacy->enabledCourseAccessTimes(),
381 ],
382 'ps_participants_list_courses' => [
383 $privacy->participantsListInCoursesEnabled(),
385 ]
386 ];
387 $fields = [
388 'ps_profile_export' => [null, null, $subitems]
389 ];
390 return [["showPrivacy", $fields]];
391
394 $subitems = [
395 'ps_export_groups' => [
396 $privacy->enabledGroupExport(),
398 ],
399 'ps_export_confirm_group' => [
400 $privacy->groupConfirmationRequired(),
402 ],
403 'ps_show_grp_access' => [
404 $privacy->enabledGroupAccessTimes(),
406 ]
407 ];
408 $fields = [
409 'ps_profile_export' => [null, null, $subitems]
410 ];
411 return [["showPrivacy", $fields]];
412
415 $subitems = [
416 'ps_export_prgs' => [
417 $privacy->enabledPRGUserExport(),
419 ]
420 ];
421 $fields = [
422 'ps_profile_export' => [null, null, $subitems]
423 ];
424 return [["showPrivacy", $fields]];
425 }
426 return [];
427 }
428}
$check
Definition: buildRTE.php:81
error(string $a_errmsg)
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
This class represents a property in a property form.
This class represents an option in a checkbox group.
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _hasAgreements()
Check if there is any user agreement.
static _reset()
Reset all.
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Contructor @access public.
save_security()
Save security settings.
showPrivacy(?ilPropertyFormGUI $form=null)
Show Privacy settings @access public.
static getErrorMessage(int $code)
return error message for error code
getAdminTabs()
Get tabs @access public.
Class ilObjectGUI Basic methods of all Output classes.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
prepareOutput(bool $show_sub_objects=true)
ilLanguage $lng
This class represents a property form user interface.
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN2
static int $SECURITY_SETTINGS_ERR_CODE_HTTP_NOT_AVAILABLE
const SECURITY_SETTINGS_ERR_CODE_INVALID_LOGIN_MAX_ATTEMPTS
static int $SECURITY_SETTINGS_ERR_CODE_HTTPS_NOT_AVAILABLE
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_LENGTH
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN3
static int $SECURITY_SETTINGS_ERR_CODE_AUTO_HTTPS
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_AGE
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MAX_LENGTH_LESS_MIN_LENGTH
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN1
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MIN_LENGTH
static _getInstance()
Get instance of ilSecuritySettings.
$valid
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26