ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjPrivacySecurityGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(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);
38  self::initErrorMessages();
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  }
50  $lng->loadLanguageModule('ps');
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  {
125  $privacy = ilPrivacySettings::getInstance();
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->courseConfirmationRequired()) {
145  $value[] = "export_confirm_course";
146  }
147  if ($privacy->groupConfirmationRequired()) {
148  $value[] = "export_confirm_group";
149  }
150  if ($privacy->enabledGroupAccessTimes()) {
151  $value[] = "grp_access_times";
152  }
153  if ($privacy->enabledCourseAccessTimes()) {
154  $value[] = "crs_access_times";
155  }
156  if ($privacy->enabledLearningSequenceAccessTimes()) {
157  $value[] = "lso_access_times";
158  }
159  if ($privacy->participantsListInCoursesEnabled()) {
160  $value[] = 'participants_list_courses';
161  }
162  $group = new ilCheckboxGroupInputGUI($this->lng->txt('ps_profile_export'), 'profile_protection');
163  $group->setValue($value);
164  $check = new ilCheckboxOption();
165  $check->setTitle($this->lng->txt('ps_export_course'));
166  $check->setValue('export_course');
167  $group->addOption($check);
168  $check = new ilCheckboxOption();
169  $check->setTitle($this->lng->txt('ps_export_groups'));
170  $check->setValue('export_group');
171  $group->addOption($check);
172  $check = new ilCheckboxOption();
173  $check->setTitle($this->lng->txt('ps_export_confirm'));
174  $check->setValue('export_confirm_course');
175  $group->addOption($check);
176  $check = new ilCheckboxOption();
177  $check->setTitle($this->lng->txt('ps_export_confirm_group'));
178  $check->setValue('export_confirm_group');
179  $group->addOption($check);
180  $check = new ilCheckboxOption();
181  $check->setTitle($this->lng->txt('ps_show_grp_access'));
182  $check->setValue('grp_access_times');
183  $group->addOption($check);
184  $check = new ilCheckboxOption();
185  $check->setTitle($this->lng->txt('ps_show_crs_access'));
186  $check->setValue('crs_access_times');
187  $group->addOption($check);
188  $check = new ilCheckboxOption();
189  $check->setTitle($this->lng->txt('ps_show_lso_access'));
190  $check->setValue('lso_access_times');
191  $group->addOption($check);
192  $form->addItem($group);
193  $check = new ilCheckboxOption();
194  $check->setTitle($this->lng->txt('ps_participants_list_courses'));
195  $check->setValue('participants_list_courses');
196  $group->addOption($check);
197 
200  $form,
201  $this
202  );
203 
204  if ($this->checkPermissionBool("write")) {
205  $form->addCommandButton('save_privacy', $this->lng->txt('save'));
206  }
207  return $form;
208  }
209 
214  public function showPrivacy(?ilPropertyFormGUI $form = null): void
215  {
216  if (!$form instanceof ilPropertyFormGUI) {
217  $form = $this->initPrivacyForm();
218  }
219  $this->tpl->setContent($form->getHTML());
220  }
221 
225  public function showSecurity(): void
226  {
227  $security = ilSecuritySettings::_getInstance();
228 
229  $this->tabs_gui->setTabActive('show_security');
230 
231  $form = new ilPropertyFormGUI();
232  $form->setFormAction($this->ctrl->getFormAction($this));
233  $form->setTitle($this->lng->txt('ps_security_protection'));
234 
237  $form,
238  $this
239  );
240  $this->tpl->setContent($form->getHTML());
241  }
242 
243  public function save_privacy(): void
244  {
245  if (!$this->access->checkAccess('write', '', $this->object->getRefId())) {
246  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
247  }
248 
249  $form = $this->initPrivacyForm();
250  $valid = true;
251  if (!$form->checkInput()) {
252  $valid = false;
253  }
254 
255  $profile_protection = $form->getInput('profile_protection') ?? [];
256  $privacy = ilPrivacySettings::getInstance();
257 
258  // to determine if agreements need to be reset - see below
259  $old_settings = array(
260  'export_course' => $privacy->enabledCourseExport(),
261  'export_group' => $privacy->enabledGroupExport(),
262  'export_confirm_course' => $privacy->courseConfirmationRequired(),
263  'export_confirm_group' => $privacy->groupConfirmationRequired(),
264  'crs_access_times' => $privacy->enabledCourseAccessTimes(),
265  'grp_access_times' => $privacy->enabledGroupAccessTimes(),
266  'lso_access_times' => $privacy->enabledLearningSequenceAccessTimes(),
267  'participants_list_courses' => $privacy->participantsListInCoursesEnabled()
268  );
269 
270  $privacy->enableCourseExport(in_array('export_course', $profile_protection));
271  $privacy->enableGroupExport(in_array('export_group', $profile_protection));
272  $privacy->setCourseConfirmationRequired(in_array('export_confirm_course', $profile_protection));
273  $privacy->setGroupConfirmationRequired(in_array('export_confirm_group', $profile_protection));
274  $privacy->showGroupAccessTimes(in_array('grp_access_times', $profile_protection));
275  $privacy->showCourseAccessTimes(in_array('crs_access_times', $profile_protection));
276  $privacy->showLearningSequenceAccessTimes(in_array('lso_access_times', $profile_protection));
277 
278  $privacy->enableParticipantsListInCourses(in_array('participants_list_courses', $profile_protection));
279 
280  // validate settings
281  $code = $privacy->validate();
282  // if error code != 0, display error and do not save
283  if ($code !== 0) {
284  $msg = self::getErrorMessage($code);
285  $this->tpl->setOnScreenMessage('failure', $msg);
286  $form->setValuesByPost();
287  $this->showPrivacy($form);
288  return;
289  } elseif (!$valid) {
290  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
291  $form->setValuesByPost();
292  $this->showPrivacy($form);
293  return;
294  } else {
295  $privacy->save();
296  // reset agreements?
297  $do_reset = false;
298  if (!$old_settings['export_course'] && $privacy->enabledCourseExport()) {
299  $do_reset = true;
300  }
301  if (!$do_reset && !$old_settings['export_group'] && $privacy->enabledGroupExport()) {
302  $do_reset = true;
303  }
304  if (!$do_reset && !$old_settings['export_confirm_course'] && $privacy->courseConfirmationRequired()) {
305  $do_reset = true;
306  }
307  if (!$do_reset && !$old_settings['export_confirm_group'] && $privacy->groupConfirmationRequired()) {
308  $do_reset = true;
309  }
310  if (!$do_reset && !$old_settings['crs_access_times'] && $privacy->enabledCourseAccessTimes()) {
311  $do_reset = true;
312  }
313  if (!$do_reset && !$old_settings['grp_access_times'] && $privacy->enabledGroupAccessTimes()) {
314  $do_reset = true;
315  }
316  if (!$do_reset && !$old_settings['lso_access_times'] && $privacy->enabledLearningSequenceAccessTimes()) {
317  $do_reset = true;
318  }
319  if ($do_reset) {
321  }
322  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
323  }
324  $this->ctrl->redirect($this, 'showPrivacy');
325  }
326 
330  public function save_security(): void
331  {
332  if (!$this->access->checkAccess('write', '', $this->object->getRefId())) {
333  $this->error->raiseError($this->lng->txt('no_permission'), $this->error->WARNING);
334  }
335  $this->showSecurity();
336  }
337 
344  public static function getErrorMessage(int $code): string
345  {
346  self::initErrorMessages();
347  if (array_key_exists($code, self::$ERROR_MESSAGE)) {
348  return self::$ERROR_MESSAGE[$code];
349  }
350  return '';
351  }
352 
353  public function addToExternalSettingsForm(int $a_form_id): array
354  {
355  switch ($a_form_id) {
357 
358  $privacy = ilPrivacySettings::getInstance();
359 
360  $subitems = array(
361  'ps_export_course' => array($privacy->enabledCourseExport(),
363  ),
364  'ps_export_confirm' => array($privacy->courseConfirmationRequired(),
366  ),
367  'ps_show_crs_access' => array($privacy->enabledCourseAccessTimes(),
369  ),
370  'ps_participants_list_courses' => [$privacy->participantsListInCoursesEnabled(),
372  ]
373  );
374  $fields = [
375  'ps_profile_export' => [null, null, $subitems]
376  ];
377  return array(array("showPrivacy", $fields));
378 
380 
381  $privacy = ilPrivacySettings::getInstance();
382 
383  $subitems = array(
384  'ps_export_groups' => array($privacy->enabledGroupExport(),
386  ),
387  'ps_export_confirm_group' => array($privacy->groupConfirmationRequired(),
389  ),
390  'ps_show_grp_access' => array($privacy->enabledGroupAccessTimes(),
392  )
393  );
394  $fields = array(
395  'ps_profile_export' => array(null, null, $subitems)
396  );
397  return [["showPrivacy", $fields]];
398  }
399  return [];
400  }
401 }
showSecurity()
Show Privacy settings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN2
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...
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MIN_LENGTH
__construct($a_data, $a_id, $a_call_by_reference=true, $a_prepare_output=true)
Contructor public.
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_LENGTH
prepareOutput(bool $show_sub_objects=true)
$valid
showPrivacy(?ilPropertyFormGUI $form=null)
Show Privacy settings public.
loadLanguageModule(string $a_module)
Load language module.
static int $SECURITY_SETTINGS_ERR_CODE_HTTP_NOT_AVAILABLE
static _reset()
Reset all.
const SECURITY_SETTINGS_ERR_CODE_INVALID_PASSWORD_MAX_AGE
static int $SECURITY_SETTINGS_ERR_CODE_AUTO_HTTPS
global $DIC
Definition: feed.php:28
ilLanguage $lng
static getErrorMessage(int $code)
return error message for error code
Class ilObjectGUI Basic methods of all Output classes.
save_security()
Save security settings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _hasAgreements()
Check if there is any user agreement.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN3
getErrorMessage($value)
Get the problem message.
__construct(Container $dic, ilPlugin $plugin)
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
static int $SECURITY_SETTINGS_ERR_CODE_HTTPS_NOT_AVAILABLE
const SECURITY_SETTINGS_ERR_CODE_INVALID_LOGIN_MAX_ATTEMPTS
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MIN_LENGTH_MIN1
const SECURITY_SETTINGS_ERR_CODE_PASSWORD_MAX_LENGTH_LESS_MIN_LENGTH
$check
Definition: buildRTE.php:81
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
static _getInstance()
Get instance of ilSecuritySettings.