ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilPersonalSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
32 {
34  private string $entered_new_password;
35  private string $entered_current_password;
36  private string $password_error;
38  private string $upload_error;
43  private ilLanguage $lng;
44  private ilCtrl $ctrl;
47  private ilHelpGUI $help;
48  private ilTabsGUI $tabs;
50  private ilObjUser $user;
57 
59 
60  public function __construct()
61  {
63  global $DIC;
64 
65  $this->user_defined_fields = ilUserDefinedFields::_getInstance();
66 
67  $this->tpl = $DIC['tpl'];
68  $this->ui_factory = $DIC['ui.factory'];
69  $this->ui_renderer = $DIC['ui.renderer'];
70  $this->lng = $DIC['lng'];
71  $this->ctrl = $DIC['ilCtrl'];
72  $this->log = $DIC->logger();
73  $this->mail_sender_factory = $DIC->mail()->mime()->senderFactory();
74  $this->help = $DIC['ilHelp'];
75  $this->tabs = $DIC['ilTabs'];
76  $this->toolbar = $DIC['ilToolbar'];
77  $this->user = $DIC['ilUser'];
78  $this->settings = $DIC['ilSetting'];
79  $this->auth_session = $DIC['ilAuthSession'];
80  $this->rbac_system = $DIC['rbacsystem'];
81  $this->style_definition = $DIC['styleDefinition'];
82  $this->navigation_history = $DIC['ilNavigationHistory'];
83  $this->upload_error = '';
84  $this->password_error = '';
85  $this->lng->loadLanguageModule('user');
86  $this->ctrl->saveParameter($this, 'user_page');
87 
88  $this->user_settings_config = new ilUserSettingsConfig();
89  $this->request = new UserGUIRequest(
90  $DIC->http(),
91  $DIC['refinery']
92  );
93 
94  $this->starting_point_repository = new ilUserStartingPointRepository(
95  $this->user,
96  $DIC['ilDB'],
97  $DIC->logger(),
98  $DIC['tree'],
99  $DIC['rbacreview'],
100  $DIC['rbacsystem'],
102  );
103  $this->entered_new_password = $this->request->getNewPassword();
104  $this->entered_current_password = $this->request->getCurrentPassword();
105  }
106 
110  public function executeCommand(): void
111  {
112  $next_class = $this->ctrl->getNextClass();
113 
114  switch ($next_class) {
115  case 'ilmailoptionsgui':
116  if (!$this->rbac_system->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId())) {
117  throw new ilPermissionException($this->lng->txt('permission_denied'));
118  }
119 
120  $this->initSubTabs('showMailOptions');
121  $this->tabs->activateTab('mail_settings');
122  $this->setHeader();
123  $this->ctrl->forwardCommand(new ilMailOptionsGUI());
124  break;
125 
126  default:
127  $cmd = $this->ctrl->getCmd('showGeneralSettings');
128  $this->$cmd();
129  break;
130  }
131  }
132 
133  private function initSubTabs(string $a_cmd): void
134  {
135  $this->help->setScreenIdComponent('user');
136 
137  $showPassword = $a_cmd == 'showPassword';
138  $showGeneralSettings = $a_cmd == 'showGeneralSettings';
139 
140  $this->tabs->addTarget(
141  'general_settings',
142  $this->ctrl->getLinkTarget($this, 'showGeneralSettings'),
143  '',
144  '',
145  '',
146  $showGeneralSettings
147  );
148 
149  if ($this->allowPasswordChange()) {
150  $this->tabs->addTarget(
151  'password',
152  $this->ctrl->getLinkTarget($this, 'showPassword'),
153  '',
154  '',
155  '',
156  $showPassword
157  );
158  }
159 
160  if ($this->rbac_system->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId())
161  && $this->settings->get('show_mail_settings')) {
162  $this->ctrl->setParameter($this, 'referrer', 'ilPersonalSettingsGUI');
163 
164  $this->tabs->addTarget(
165  'mail_settings',
166  $this->ctrl->getLinkTargetByClass('ilMailOptionsGUI'),
167  '',
168  ['ilMailOptionsGUI']
169  );
170  }
171 
172  if ($this->settings->get('user_delete_own_account') &&
173  $this->user->getId() != SYSTEM_USER_ID) {
174  $this->tabs->addTab(
175  'delacc',
176  $this->lng->txt('user_delete_own_account'),
177  $this->ctrl->getLinkTarget($this, 'deleteOwnAccountStep1')
178  );
179  }
180  }
181 
182  public function setHeader(): void
183  {
184  $this->tpl->setTitle($this->lng->txt('personal_settings'));
185  }
186 
187  public function showPassword(
188  bool $a_no_init = false,
189  bool $hide_form = false
190  ): void {
191  $this->initSubTabs('showPersonalData');
192  $this->tabs->activateTab('password');
193 
194  $this->setHeader();
195  // check whether password of user have to be changed
196  // due to first login or password of user is expired
197  if ($this->user->isPasswordChangeDemanded()) {
198  $this->tpl->setOnScreenMessage('info', $this->lng->txt('password_change_on_first_login_demand'));
199  } elseif ($this->user->isPasswordExpired()) {
200  $msg = $this->lng->txt('password_expired');
201  $password_age = $this->user->getPasswordAge();
202  $this->tpl->setOnScreenMessage('info', sprintf($msg, $password_age));
203  }
204 
205  if (!$a_no_init && !$hide_form) {
206  $this->initPasswordForm();
207  }
208  $this->tpl->setContent(!$hide_form ? $this->form->getHTML() : '');
209  $this->tpl->printToStdout();
210  }
211 
212  public function initPasswordForm(): void
213  {
214  $this->form = new ilPropertyFormGUI();
215 
216  if ($this->allowPasswordChange()) {
217  $pw_info_set = false;
218  if ($this->user->getAuthMode(true) == ilAuthUtils::AUTH_LOCAL) {
219  // current password
220  $cpass = new ilPasswordInputGUI($this->lng->txt('current_password'), 'current_password');
222  $cpass->setRetype(false);
223  $cpass->setSkipSyntaxCheck(true);
224  $pw_info_set = true;
225  // only if a password exists.
226  if ($this->user->getPasswd()) {
227  $cpass->setRequired(true);
228  }
229  $this->form->addItem($cpass);
230  }
231 
232  // new password
233  $ipass = new ilPasswordInputGUI($this->lng->txt('desired_password'), 'new_password');
234  if ($pw_info_set === false) {
236  }
237  $ipass->setRequired(true);
238  $ipass->setUseStripSlashes(false);
239 
240  $this->form->addItem($ipass);
241  $this->form->addCommandButton('savePassword', $this->lng->txt('save'));
242 
243  switch ($this->user->getAuthMode(true)) {
245  $this->form->setTitle($this->lng->txt('chg_password'));
246  break;
247 
251  $this->form->setTitle($this->lng->txt('chg_ilias_and_webfolder_password'));
252  } else {
253  $this->form->setTitle($this->lng->txt('chg_ilias_password'));
254  }
255  break;
256  default:
257  $this->form->setTitle($this->lng->txt('chg_ilias_password'));
258  break;
259  }
260  $this->form->setFormAction($this->ctrl->getFormAction($this));
261  }
262  }
263 
267  protected function allowPasswordChange(): bool
268  {
269  if (\ilSession::get('used_external_auth_mode')) {
270  return false;
271  }
272 
273  $status = ilAuthUtils::isPasswordModificationEnabled($this->user->getAuthMode(true));
274  if ($status) {
275  return true;
276  }
277 
278  return \ilAuthUtils::isPasswordModificationHidden()
279  && ($this->user->isPasswordChangeDemanded() || $this->user->isPasswordExpired());
280  }
281 
282  public function savePassword(): void
283  {
284  if (!$this->allowPasswordChange()) {
285  $this->ctrl->redirect($this, 'showPersonalData');
286  return;
287  }
288 
289  $this->initPasswordForm();
290  if ($this->form->checkInput()) {
291  $cp = $this->form->getItemByPostVar('current_password');
292  $np = $this->form->getItemByPostVar('new_password');
293  $error = false;
294 
295  if ($this->user->getAuthMode(true) == ilAuthUtils::AUTH_LOCAL) {
296  if (!ilUserPasswordManager::getInstance()->verifyPassword($this->user, $this->entered_current_password)) {
297  $error = true;
298  $cp->setAlert($this->lng->txt('passwd_wrong'));
299  }
300  }
301 
302  if (!ilSecuritySettingsChecker::isPassword($this->entered_new_password, $custom_error)) {
303  $error = true;
304  if ($custom_error != '') {
305  $np->setAlert($custom_error);
306  } else {
307  $np->setAlert($this->lng->txt('passwd_invalid'));
308  }
309  }
310  $error_lng_var = '';
312  $this->entered_new_password,
313  $this->user,
314  $error_lng_var
315  )) {
316  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
317  $np->setAlert($this->lng->txt($error_lng_var));
318  $error = true;
319  }
320  if (($this->user->isPasswordExpired() || $this->user->isPasswordChangeDemanded())
321  && $this->entered_current_password == $this->entered_new_password) {
322  $error = true;
323  $np->setAlert($this->lng->txt('new_pass_equals_old_pass'));
324  }
325 
326  if (!$error) {
327  $this->user->resetPassword($this->entered_new_password, $this->entered_new_password);
328  if ($this->entered_current_password != $this->entered_new_password) {
329  $this->user->setLastPasswordChangeToNow();
330  $this->user->setPasswordPolicyResetStatus(false);
331  $this->user->update();
332  }
333 
334  if (ilSession::get('orig_request_target')) {
335  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
336  $target = ilSession::get('orig_request_target');
337  ilSession::set('orig_request_target', '');
338  ilUtil::redirect($target);
339  } else {
340  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'));
341  $this->showPassword(true, true);
342  return;
343  }
344  }
345  }
346  $this->form->setValuesByPost();
347  $this->showPassword(true);
348  }
349 
350  public function workWithUserSetting(string $setting): bool
351  {
352  return $this->user_settings_config->isVisibleAndChangeable($setting);
353  }
354 
355  public function userSettingVisible(string $setting): bool
356  {
357  return $this->user_settings_config->isVisible($setting);
358  }
359 
360  public function userSettingEnabled(string $setting): bool
361  {
362  return $this->user_settings_config->isChangeable($setting);
363  }
364 
365  public function showGeneralSettings(bool $a_no_init = false): void
366  {
367  $this->initSubTabs('showPersonalData');
368  $this->tabs->activateTab('general_settings');
369 
370  $this->setHeader();
371 
372  if (!$a_no_init) {
373  $this->initGeneralSettingsForm();
374  }
375  $this->tpl->setContent($this->form->getHTML());
376  $this->tpl->printToStdout();
377  }
378 
379  public function initGeneralSettingsForm(): void
380  {
381  $this->form = new ilPropertyFormGUI();
382 
383  // language
384  if ($this->userSettingVisible('language')) {
385  $languages = $this->lng->getInstalledLanguages();
386  $options = [];
387  foreach ($languages as $lang_key) {
388  $options[$lang_key] = ilLanguage::_lookupEntry($lang_key, 'meta', 'meta_l_' . $lang_key);
389  }
390 
391  $lang = new ilSelectInputGUI($this->lng->txt('language'), 'language');
392  $lang->setOptionsLangAttribute(fn($options, $key) => $key);
393  $lang->setOptions($options);
394  $lang->setValue($this->user->getLanguage());
395  if (count($options) <= 1 || $this->settings->get('usr_settings_disable_language') === '1') {
396  $lang->setDisabled(true);
397  }
398  $this->form->addItem($lang);
399  }
400 
401  // skin/style
402  if ($this->userSettingVisible('skin_style')) {
403  $skins = $this->style_definition->getAllSkins();
404  if (is_array($skins)) {
405  $si = new ilSelectInputGUI($this->lng->txt('skin_style'), 'skin_style');
406 
407  $options = [];
408  foreach ($skins as $skin) {
409  foreach ($skin->getStyles() as $style) {
410  if (!ilSystemStyleSettings::_lookupActivatedStyle($skin->getId(), $style->getId()) || $style->isSubstyle()) {
411  continue;
412  }
413 
414  $options[$skin->getId() . ':' . $style->getId()] = $skin->getName() . ' / ' . $style->getName();
415  }
416  }
417  $si->setOptions($options);
418  $si->setValue($this->user->skin . ':' . $this->user->prefs['style']);
419  $si->setDisabled((bool) $this->settings->get('usr_settings_disable_skin_style'));
420  $this->form->addItem($si);
421  }
422  }
423 
424  // help tooltips
425  $this->help->addPersonalSettingToLegacyForm($this->form);
426 
427  // hits per page
428  if ($this->userSettingVisible('hits_per_page')) {
429  $si = new ilSelectInputGUI($this->lng->txt('hits_per_page'), 'hits_per_page');
430 
431  $hits_options = [10,15,20,30,40,50,100,9999];
432  $options = [];
433 
434  foreach ($hits_options as $hits_option) {
435  $hstr = ($hits_option == 9999)
436  ? $this->lng->txt('no_limit')
437  : $hits_option;
438  $options[$hits_option] = $hstr;
439  }
440  $si->setOptions($options);
441  $si->setValue($this->user->prefs['hits_per_page']);
442  $si->setDisabled((bool) $this->settings->get('usr_settings_disable_hits_per_page'));
443  $this->form->addItem($si);
444  }
445 
446  $lv = new ilSelectInputGUI($this->lng->txt('user_store_last_visited'), 'store_last_visited');
447  $options = [
448  0 => $this->lng->txt('user_lv_keep_entries'),
449  1 => $this->lng->txt('user_lv_keep_only_for_session'),
450  2 => $this->lng->txt('user_lv_do_not_store')
451  ];
452  $lv->setOptions($options);
453  $last_visited = (int) ($this->user->prefs['store_last_visited'] ?? 0);
454  $lv->setValue($last_visited);
455  $this->form->addItem($lv);
456 
457 
458  if (ilSessionReminder::isGloballyActivated()) {
459  $cb = new ilCheckboxInputGUI($this->lng->txt('session_reminder'), 'session_reminder_enabled');
460  $cb->setInfo($this->lng->txt('session_reminder_info'));
461  $cb->setValue('1');
462  $cb->setChecked((bool) $this->user->getPref('session_reminder_enabled'));
463 
465  $lead_time_gui = new ilNumberInputGUI($this->lng->txt('session_reminder_lead_time'), 'session_reminder_lead_time');
466  $lead_time_gui->setInfo(sprintf($this->lng->txt('session_reminder_lead_time_info'), ilDatePresentation::secondsToString($expires, true)));
467 
469  $max_value = max($min_value, ($expires / 60) - 1);
470 
471  $current_user_value = $this->user->getPref('session_reminder_lead_time');
472  if ($current_user_value < $min_value ||
473  $current_user_value > $max_value) {
474  $current_user_value = ilSessionReminder::SUGGESTED_LEAD_TIME;
475  }
476  $value = min(
477  max(
478  $min_value,
479  $current_user_value
480  ),
481  $max_value
482  );
483 
484  $lead_time_gui->setValue((string) $value);
485  $lead_time_gui->setSize(3);
486  $lead_time_gui->setMinValue($min_value);
487  $lead_time_gui->setMaxValue($max_value);
488  $cb->addSubItem($lead_time_gui);
489 
490  $this->form->addItem($cb);
491  }
492 
493  // calendar settings (copied here to be reachable when calendar is inactive)
494  // they cannot be hidden/deactivated
495 
496  $this->lng->loadLanguageModule('dateplaner');
497  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
498 
499  $select = new ilSelectInputGUI($this->lng->txt('cal_user_timezone'), 'timezone');
501  $select->setInfo($this->lng->txt('cal_timezone_info'));
502  $select->setValue($user_settings->getTimeZone());
503  $this->form->addItem($select);
504 
505  $year = date('Y');
506  $select = new ilSelectInputGUI($this->lng->txt('cal_user_date_format'), 'date_format');
507  $select->setOptions([
508  ilCalendarSettings::DATE_FORMAT_DMY => '31.10.' . $year,
509  ilCalendarSettings::DATE_FORMAT_YMD => $year . '-10-31',
510  ilCalendarSettings::DATE_FORMAT_MDY => '10/31/' . $year
511  ]);
512  $select->setInfo($this->lng->txt('cal_date_format_info'));
513  $select->setValue($user_settings->getDateFormat());
514  $this->form->addItem($select);
515 
516  $select = new ilSelectInputGUI($this->lng->txt('cal_user_time_format'), 'time_format');
517  $select->setOptions([
520  ]);
521  $select->setInfo($this->lng->txt('cal_time_format_info'));
522  $select->setValue($user_settings->getTimeFormat());
523  $this->form->addItem($select);
524 
525  if ($this->starting_point_repository->isPersonalStartingPointEnabled()) {
526  $this->lng->loadLanguageModule('administration');
527  $si = new ilRadioGroupInputGUI($this->lng->txt('adm_user_starting_point'), 'usr_start');
528  $si->setRequired(true);
529  $si->setInfo($this->lng->txt('adm_user_starting_point_info'));
530  $def_opt = new ilRadioOption($this->lng->txt('adm_user_starting_point_inherit'), '0');
531  $def_opt->setInfo($this->lng->txt('adm_user_starting_point_inherit_info'));
532  $si->addOption($def_opt);
533  foreach ($this->starting_point_repository->getPossibleStartingPoints() as $value => $caption) {
535  continue;
536  }
537  $si->addOption(new ilRadioOption($this->lng->txt($caption), (string) $value));
538  }
539  $si->setValue((string) $this->starting_point_repository->getCurrentUserPersonalStartingPoint());
540  $this->form->addItem($si);
541 
542  // starting point: repository object
543  $repobj = new ilRadioOption(
544  $this->lng->txt('adm_user_starting_point_object'),
546  );
547  $repobj_id = new ilTextInputGUI($this->lng->txt('adm_user_starting_point_ref_id'), 'usr_start_ref_id');
548  $repobj_id->setInfo($this->lng->txt('adm_user_starting_point_ref_id_info'));
549  $repobj_id->setRequired(true);
550  $repobj_id->setSize(5);
552  $start_ref_id = $this->starting_point_repository->getCurrentUserPersonalStartingObject();
553  $repobj_id->setValue($start_ref_id);
554  if ($start_ref_id) {
555  $start_obj_id = ilObject::_lookupObjId($start_ref_id);
556  if ($start_obj_id) {
557  $repobj_id->setInfo($this->lng->txt('obj_' . ilObject::_lookupType($start_obj_id)) .
558  ': ' . ilObject::_lookupTitle($start_obj_id));
559  }
560  }
561  }
562  $repobj->addSubItem($repobj_id);
563  $si->addOption($repobj);
564  }
565 
566  $this->form->addCommandButton('saveGeneralSettings', $this->lng->txt('save'));
567  $this->form->setTitle($this->lng->txt('general_settings'));
568  $this->form->setFormAction($this->ctrl->getFormAction($this));
569  }
570 
571  public function saveGeneralSettings(): void
572  {
573  $this->initGeneralSettingsForm();
574  if ($this->form->checkInput()
575  && $this->checkPersonalStartingPoint()) {
576  if ($this->workWithUserSetting('skin_style')) {
577  //set user skin and style
578  if ($this->form->getInput('skin_style') != '') {
579  $sknst = explode(':', $this->form->getInput('skin_style'));
580 
581  if ($this->user->getPref('style') != $sknst[1] ||
582  $this->user->getPref('skin') != $sknst[0]) {
583  $this->user->setPref('skin', $sknst[0]);
584  $this->user->setPref('style', $sknst[1]);
585  }
586  }
587  }
588 
589  // language
590  if ($this->workWithUserSetting('language')) {
591  $this->user->setLanguage($this->form->getInput('language'));
592  }
593 
594  // hits per page
595  if ($this->workWithUserSetting('hits_per_page')) {
596  if ($this->form->getInput('hits_per_page') != '') {
597  $this->user->setPref('hits_per_page', $this->form->getInput('hits_per_page'));
598  }
599  }
600 
601  // help tooltips
602  $this->help->savePersonalSettingFromLegacyForm($this->form);
603 
604  $this->user->setPref('store_last_visited', $this->form->getInput('store_last_visited'));
605  if ((int) $this->form->getInput('store_last_visited') > 0) {
606  $this->navigation_history->deleteDBEntries();
607  if ((int) $this->form->getInput('store_last_visited') == 2) {
608  $this->navigation_history->deleteSessionEntries();
609  }
610  }
611 
612  if (ilSessionReminder::isGloballyActivated()) {
613  $this->user->setPref('session_reminder_enabled', $this->form->getInput('session_reminder_enabled'));
614  $this->user->setPref('session_reminder_lead_time', (string) $this->form->getInput('session_reminder_lead_time'));
615  }
616 
617  if ($this->starting_point_repository->isPersonalStartingPointEnabled()) {
618  $s_ref_id = $this->form->getInput('usr_start_ref_id');
619  $s_ref_id = ($s_ref_id === '')
620  ? null
621  : (int) $s_ref_id;
622  $this->starting_point_repository->setCurrentUserPersonalStartingPoint(
623  (int) $this->form->getInput('usr_start'),
624  $s_ref_id
625  );
626  }
627 
628  $this->user->update();
629 
630  // calendar settings
631  $user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
632  $user_settings->setTimeZone($this->form->getInput('timezone'));
633  $user_settings->setDateFormat((int) $this->form->getInput('date_format'));
634  $user_settings->setTimeFormat((int) $this->form->getInput('time_format'));
635  $user_settings->save();
636 
637  $this->tpl->setOnScreenMessage('success', $this->lng->txtlng('common', 'msg_obj_modified', $this->user->getLanguage()), true);
638 
639  $this->ctrl->redirect($this, 'showGeneralSettings');
640  }
641 
642  $this->form->setValuesByPost();
643  $this->showGeneralSettings(true);
644  }
645 
646  private function checkPersonalStartingPoint(): bool
647  {
648  if (!$this->starting_point_repository->isPersonalStartingPointEnabled()
649  || (int) $this->form->getInput('usr_start') !== ilUserStartingPointRepository::START_REPOSITORY_OBJ) {
650  return true;
651  }
652 
653  $ref_id = $this->form->getInput('usr_start_ref_id');
654  if (!is_numeric($ref_id) || !ilObject::_exists((int) $ref_id, true)) {
655  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('obj_ref_id_not_exist'), true);
656  return false;
657  }
658 
659  return true;
660  }
661 
662  protected function deleteOwnAccountStep1(): void
663  {
664  if (!(bool) $this->settings->get('user_delete_own_account') ||
665  $this->user->getId() == SYSTEM_USER_ID) {
666  $this->ctrl->redirect($this, 'showGeneralSettings');
667  }
668 
669  // too make sure
670  $this->user->removeDeletionFlag();
671 
672  $this->setHeader();
673  $this->initSubTabs('deleteOwnAccount');
674  $this->tabs->activateTab('delacc');
675 
676  $modal = $this->ui_factory->modal()->interruptive(
677  $this->lng->txt('delete_account'),
678  $this->lng->txt('user_delete_own_account_logout_confirmation'),
679  $this->ctrl->getFormActionByClass(ilPersonalSettingsGUI::class, 'deleteOwnAccountLogout')
680  )->withActionButtonLabel($this->lng->txt('user_delete_own_account_logout_button'));
681 
682  $this->tpl->setOnScreenMessage('info', $this->lng->txt('user_delete_own_account_info'));
683  $this->toolbar->addComponent(
684  $this->ui_factory->button()->standard(
685  $this->lng->txt('btn_next'),
686  $modal->getShowSignal()
687  )
688  );
689 
690  $this->tpl->setContent($this->ui_renderer->render($modal));
691 
692  $this->tpl->printToStdout();
693  }
694 
695  protected function abortDeleteOwnAccount(): void
696  {
697  $this->user->removeDeletionFlag();
698 
699  $this->tpl->setOnScreenMessage('info', $this->lng->txt('user_delete_own_account_aborted'), true);
700  $this->ctrl->redirect($this, 'showGeneralSettings');
701  }
702 
703  protected function deleteOwnAccountLogout(): void
704  {
705  $this->user->activateDeletionFlag();
706 
708  $this->auth_session->logout();
709 
710  $this->ctrl->redirectToURL('login.php?cmd=force_login&target=usr_' . md5('usrdelown'));
711  }
712 
713  protected function deleteOwnAccountStep2(): void
714  {
715  if (!(bool) $this->settings->get('user_delete_own_account') ||
716  $this->user->getId() == SYSTEM_USER_ID ||
717  !$this->user->hasDeletionFlag()) {
718  $this->ctrl->redirect($this, 'showGeneralSettings');
719  }
720 
721  $this->setHeader();
722  $this->initSubTabs('deleteOwnAccount');
723  $this->tabs->activateTab('delacc');
724 
725  $this->tpl->setOnScreenMessage(
726  'question',
727  $this->lng->txt('user_delete_own_account_final_confirmation')
728  );
729 
730  $this->toolbar->addComponent(
731  $this->ui_factory->button()->standard(
732  $this->lng->txt('confirm'),
733  $this->ctrl->getLinkTargetByClass(self::class, 'deleteOwnAccountStep3')
734  )
735  );
736 
737  $this->toolbar->addComponent(
738  $this->ui_factory->button()->standard(
739  $this->lng->txt('cancel'),
740  $this->ctrl->getLinkTargetByClass(self::class, 'abortDeleteOwnAccount')
741  )
742  );
743  $this->tpl->printToStdout();
744  }
745 
746  protected function deleteOwnAccountStep3(): void
747  {
748  if (!(bool) $this->settings->get('user_delete_own_account') ||
749  $this->user->getId() == SYSTEM_USER_ID ||
750  !$this->user->hasDeletionFlag()) {
751  $this->ctrl->redirect($this, 'showGeneralSettings');
752  }
753 
754  // build notification
755 
756  $ntf = new ilSystemNotification();
757  $ntf->setLangModules(['user']);
758  $ntf->addAdditionalInfo('profile', $this->user->getProfileAsString($this->lng), true);
759 
760  // mail message
762  $ntf->setIntroductionDirect(
763  sprintf(
764  $this->lng->txt('user_delete_own_account_email_body'),
765  $this->user->getLogin(),
766  ILIAS_HTTP_PATH,
768  )
769  );
770 
771  $message = $ntf->composeAndGetMessage($this->user->getId(), null, 'read', true);
772  $subject = $this->lng->txt('user_delete_own_account_email_subject');
773 
774 
775  // send notification
776  $user_email = $this->user->getEmail();
777  $admin_mail = $this->settings->get('user_delete_own_account_email');
778 
779  $mmail = new ilMimeMail();
780  $mmail->From($this->mail_sender_factory->system());
781 
782  if ($user_email !== '') {
783  $mmail->To($user_email);
784  $mmail->Bcc($admin_mail);
785  $mmail->Subject($subject, true);
786  $mmail->Body($message);
787  $mmail->Send();
788  } elseif ($admin_mail !== null || $admin_mail !== '') {
789  $mmail->To($admin_mail);
790  $mmail->Subject($subject, true);
791  $mmail->Body($message);
792  $mmail->Send();
793  }
794 
795  $this->log->root()->log('Account deleted: ' . $this->user->getLogin() . ' (' . $this->user->getId() . ')');
796 
797  $this->user->delete();
798 
799  // terminate session
800  $this->auth_session->logout();
801  $this->ctrl->redirectToURL('login.php?accdel=1');
802  }
803 }
static get(string $a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An entity that renders components to a string output.
Definition: Renderer.php:30
ilUserDefinedFields $user_defined_fields
This class represents a selection list property in a property form.
static _lookupActivatedStyle(string $a_skin, string $a_style)
lookup if a style is activated
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Additional user data fields definition.
Provides fluid interface to LoggingServices.
setInfo(string $a_info)
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
Help GUI class.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static isPassword(string $a_passwd, ?string &$customError=null)
ilGlobalTemplateInterface $tpl
showPassword(bool $a_no_init=false, bool $hide_form=false)
setOptions(array $a_options)
const IL_CAL_UNIX
static _getShortTimeZoneList()
get short timezone list
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
static _getInstanceByUserId(int $a_user_id)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilUserSettingsConfig $user_settings_config
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
$ref_id
Definition: ltiauth.php:67
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
ilUserStartingPointRepository $starting_point_repository
static _lookupTitle(int $obj_id)
const SESSION_CLOSE_USER
ilNavigationHistory $navigation_history
static isPasswordValidForUserContext(string $clear_text_password, $user, ?string &$error_language_variable=null)
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRequired(bool $a_required)
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
Last visited history for repository items.
static redirect(string $a_script)
$lang
Definition: xapiexit.php:26
GUI class for personal profile.
form( $class_path, string $cmd, string $submit_caption="")
allowPasswordChange()
Check, whether password change is allowed for user.
ilMailMimeSenderFactory $mail_sender_factory
static setClosingContext(int $a_context)
set closing context (for statistics)
ilStyleDefinition acts as a wrapper of style related actions.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$message
Definition: xapiexit.php:32
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
static _lookupType(int $id, bool $reference=false)
static setUseRelativeDates(bool $a_status)
set use relative dates
static getSessionExpireValue()
Returns the session expiration value.
static isPasswordModificationEnabled($a_authmode)
Check if password modification is enabled.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance()
Singleton method to reduce footprint (included files, created instances)
static set(string $a_var, $a_val)
Set a value.
showGeneralSettings(bool $a_no_init=false)