ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjUserGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 
37 {
40  private ilHelpGUI $help;
41  private ilTabsGUI $tabs;
43 
47 
49 
50  private string $requested_letter = '';
51  private string $requested_baseClass = '';
52  private string $requested_search = '';
56  private array $back_target;
57  private bool $update;
58  private array $selectable_roles;
59  private int $default_role;
60  private string $default_layout_and_style;
62 
63  private int $usrf_ref_id;
65 
66  public function __construct(
67  $a_data,
68  int $a_id,
69  bool $a_call_by_reference = false,
70  bool $a_prepare_output = true
71  ) {
73  global $DIC;
74  $this->ctrl = $DIC['ilCtrl'];
75  $this->tabs = $DIC['ilTabs'];
76  $this->help = $DIC['ilHelp'];
77  $this->mail_sender_factory = $DIC->mail()->mime()->senderFactory();
78 
79  $this->user_profile = new ilUserProfile();
80 
81  $this->default_layout_and_style = $DIC['ilClientIniFile']->readVariable('layout', 'skin') .
82  ':' . $DIC['ilClientIniFile']->readVariable('layout', 'style');
83 
84  $this->type = 'usr';
85  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
86  $this->usrf_ref_id = $this->ref_id;
87 
88  $this->uploads = $DIC->upload();
89  $this->irss = $DIC->resourceStorage();
90  $this->stakeholder = new ilUserProfilePictureStakeholder();
91 
92  $this->ctrl->saveParameter($this, ['obj_id', 'letter']);
93  $this->ctrl->setParameterByClass('ilobjuserfoldergui', 'letter', $this->requested_letter);
94  $this->lng->loadLanguageModule('user');
95 
96  $this->user_request = new UserGUIRequest(
97  $DIC->http(),
98  $DIC->refinery()
99  );
100 
101  $this->requested_letter = $this->user_request->getLetter();
102  $this->requested_baseClass = $this->user_request->getBaseClass();
103  $this->requested_search = $this->user_request->getSearch();
104  $this->legal_documents = $DIC['legalDocuments'];
105  }
106 
107  public function executeCommand(): void
108  {
109  $next_class = $this->ctrl->getNextClass($this);
110  $cmd = $this->ctrl->getCmd();
111 
112  $this->prepareOutput();
113 
114  switch ($next_class) {
115  case 'illearningprogressgui':
116  $new_gui = new ilLearningProgressGUI(
119  $this->object->getId()
120  );
121  $this->ctrl->forwardCommand($new_gui);
122  break;
123 
124  case 'ilobjectownershipmanagementgui':
125  $gui = new ilObjectOwnershipManagementGUI($this->object->getId());
126  $this->ctrl->forwardCommand($gui);
127  break;
128 
129  default:
130  if ($cmd == '' || $cmd == 'view') {
131  $cmd = 'edit';
132  }
133  $cmd .= 'Object';
134  $this->$cmd();
135  break;
136  }
137  }
138 
139  protected function setTitleAndDescription(): void
140  {
141  if (strtolower(get_class($this->object)) == 'ilobjuser') {
142  $this->tpl->setTitle('[' . $this->object->getLogin() . '] ' . $this->object->getTitle());
143  $this->tpl->setDescription($this->object->getLongDescription());
144  $this->tpl->setTitleIcon(
145  ilUtil::getImagePath('standard/icon_' . $this->object->getType() . '.svg'),
146  $this->lng->txt('obj_' . $this->object->getType())
147  );
148  } else {
149  parent::setTitleAndDescription();
150  }
151  }
152 
153  public function cancelObject(): void
154  {
155  ilSession::clear('saved_post');
156 
157  if (strtolower($this->requested_baseClass) == 'iladministrationgui') {
158  $this->ctrl->redirectByClass('ilobjuserfoldergui', 'view');
159  } else {
160  $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
161  }
162  }
163 
164  public function getAdminTabs(): void
165  {
166  $this->getTabs();
167  }
168 
169  protected function getTabs(): void
170  {
171  $this->tabs_gui->clearTargets();
172 
173  $this->help->setScreenIdComponent('usr');
174 
175  if ($this->requested_search) {
176  $this->tabs_gui->setBackTarget(
177  $this->lng->txt('search_results'),
178  ilSession::get('usr_search_link')
179  );
180 
181  $this->tabs_gui->addTarget(
182  'properties',
183  $this->ctrl->getLinkTarget($this, 'edit'),
184  ['edit', '', 'view'],
185  get_class($this),
186  '',
187  true
188  );
189  } else {
190  $this->tabs_gui->addTarget(
191  'properties',
192  $this->ctrl->getLinkTarget($this, 'edit'),
193  ['edit', '', 'view'],
194  get_class($this)
195  );
196  }
197 
198  if ($this->checkAccessToRolesTab()) {
199  $this->tabs_gui->addTarget(
200  'role_assignment',
201  $this->ctrl->getLinkTarget($this, 'roleassignment'),
202  ['roleassignment'],
203  get_class($this)
204  );
205  }
206 
207  // learning progress
208  if ($this->rbac_system->checkAccess('read', $this->ref_id) and
211  $this->tabs_gui->addTarget(
212  'learning_progress',
213  $this->ctrl->getLinkTargetByClass('illearningprogressgui', ''),
214  '',
215  ['illplistofobjectsgui', 'illplistofsettingsgui', 'illearningprogressgui', 'illplistofprogressgui']
216  );
217  }
218 
219  $this->tabs_gui->addTarget(
220  'user_ownership',
221  $this->ctrl->getLinkTargetByClass('ilobjectownershipmanagementgui', ''),
222  '',
223  'ilobjectownershipmanagementgui'
224  );
225  }
226 
230  public function setBackTarget(
231  string $a_text,
232  string $a_link
233  ): void {
234  $this->back_target = ['text' => $a_text, 'link' => $a_link];
235  }
236 
237  public function __checkUserDefinedRequiredFields(): bool
238  {
239  $this->user_defined_fields = ilUserDefinedFields::_getInstance();
240 
241  $udfs = $this->user_request->getUDFs();
242  foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
243  if ($definition['required'] and !strlen($udfs[$field_id])) {
244  return false;
245  }
246  }
247  return true;
248  }
249 
250  public function __showUserDefinedFields(): void
251  {
252  $user_defined_data = null;
253  $this->user_defined_fields = ilUserDefinedFields::_getInstance();
254 
255  if ($this->object->getType() == 'usr') {
256  $user_defined_data = $this->object->getUserDefinedData();
257  }
258  foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
259  $error_post_vars = ilSession::get('error_post_vars');
260  $old = $error_post_vars['udf'][$field_id] ?? $user_defined_data[$field_id];
261 
262  if ($definition['field_type'] == UDF_TYPE_TEXT) {
263  $this->tpl->setCurrentBlock('field_text');
264  $this->tpl->setVariable('FIELD_NAME', 'udf[' . $definition['field_id'] . ']');
265  $this->tpl->setVariable('FIELD_VALUE', ilLegacyFormElementsUtil::prepareFormOutput($old));
266  } else {
267  $this->tpl->setCurrentBlock('field_select');
268  $this->tpl->setVariable(
269  'SELECT_BOX',
271  $old,
272  'udf[' . $definition['field_id'] . ']',
273  $this->user_defined_fields->fieldValuesToSelectArray(
274  $definition['field_values']
275  ),
276  false,
277  true
278  )
279  );
280  }
281  $this->tpl->parseCurrentBlock();
282  $this->tpl->setCurrentBlock('user_defined');
283 
284  if ($definition['required']) {
285  $name = $definition['field_name'] . '<span class="asterisk">*</span>';
286  } else {
287  $name = $definition['field_name'];
288  }
289  $this->tpl->setVariable('TXT_FIELD_NAME', $name);
290  $this->tpl->parseCurrentBlock();
291  }
292  }
293 
294  public function initCreate(): void
295  {
296  if ($this->usrf_ref_id != USER_FOLDER_ID) {
297  $this->tabs_gui->clearTargets();
298  }
299 
300  // role selection
301  $obj_list = $this->rbac_review->getRoleListByObject(ROLE_FOLDER_ID);
302  $rol = [];
303  foreach ($obj_list as $obj_data) {
304  // allow only 'assign_users' marked roles if called from category
305  if ($this->object->getRefId() != USER_FOLDER_ID && !in_array(
307  $this->rbac_review->assignedRoles($this->user->getId())
308  )) {
309  if (!ilObjRole::_getAssignUsersStatus($obj_data['obj_id'])) {
310  continue;
311  }
312  }
313  // exclude anonymous role from list
314  if ($obj_data['obj_id'] != ANONYMOUS_ROLE_ID) {
315  // do not allow to assign users to administrator role if current user does not has SYSTEM_ROLE_ID
316  if ($obj_data['obj_id'] != SYSTEM_ROLE_ID || in_array(
318  $this->rbac_review->assignedRoles($this->user->getId())
319  )) {
320  $rol[$obj_data['obj_id']] = $obj_data['title'];
321  }
322  }
323  }
324 
325  if (!count($rol)) {
326  $this->ilias->raiseError(
327  $this->lng->txt('msg_no_roles_users_can_be_assigned_to'),
328  $this->ilias->error_obj->MESSAGE
329  );
330  }
331 
332  $keys = array_keys($rol);
333 
334  // set pre defined user role to default
335  if (in_array(4, $keys)) {
336  $this->default_role = 4;
337  } else {
338  if (count($keys) > 1 && in_array(2, $keys)) {
339  // remove admin role as preselectable role
340  foreach ($keys as $key => $val) {
341  if ($val == 2) {
342  unset($keys[$key]);
343  break;
344  }
345  }
346  }
347 
348  $this->default_role = array_shift($keys);
349  }
350  $this->selectable_roles = $rol;
351  }
352 
356  public function createObject(): void
357  {
358  if (!$this->rbac_system->checkAccess('create_usr', $this->usrf_ref_id)
359  && !$this->rbac_system->checkAccess('cat_administrate_users', $this->usrf_ref_id)) {
360  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
361  }
362 
363  $this->initCreate();
364  $this->initForm('create');
365  $this->renderForm();
366  }
367 
371  public function saveObject(): void
372  {
373  if (!$this->rbac_system->checkAccess('create_usr', $this->usrf_ref_id)
374  && !$this->access->checkAccess('cat_administrate_users', '', $this->usrf_ref_id)) {
375  $this->ilias->raiseError($this->lng->txt('permission_denied'), $this->ilias->error_obj->MESSAGE);
376  }
377 
378  $this->initCreate();
379  $this->initForm('create');
380 
381  // Manipulate form so ignore required fields are no more required. This has to be done before ilPropertyFormGUI::checkInput() is called.
382  $profile_maybe_incomplete = false;
383  if ($this->form_gui->getInput('ignore_rf', false)) {
384  $profile_maybe_incomplete = $this->handleIgnoredRequiredFields();
385  }
386 
387  if (!$this->form_gui->checkInput()) {
388  $this->form_gui->setValuesByPost();
389  $this->renderForm();
390  return;
391  }
392 
393  // checks passed. save user
394  $user_object = $this->loadValuesFromForm();
395  if ($this->user->getId() === (int) SYSTEM_USER_ID
396  || !in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->object->getId()))
397  || in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->user->getId()))) {
398  $user_object->setPasswd($this->form_gui->getInput('passwd'), ilObjUser::PASSWD_PLAIN);
399  }
400  $user_object->setTitle($user_object->getFullname());
401  $user_object->setDescription($user_object->getEmail());
402 
403  $this->loadUserDefinedDataFromForm($user_object);
404 
405  $user_object->create();
406 
408  $user_object->setExternalAccount($this->form_gui->getInput('ext_account'));
409  }
410 
411  // set a timestamp for last_password_change
412  // this ts is needed by ilSecuritySettings
413  $user_object->setLastPasswordChangeTS(time());
414 
415  //insert user data in table user_data
416  $user_object->saveAsNew();
417 
418  // setup user preferences
419  if ($this->isSettingChangeable('language')) {
420  $user_object->setLanguage($this->form_gui->getInput('language'));
421  }
422 
423  if ($this->isSettingChangeable('skin_style')) {
424  //set user skin and style
425  $sknst = explode(':', $this->form_gui->getInput('skin_style'));
426 
427  if ($user_object->getPref('style') != $sknst[1] ||
428  $user_object->getPref('skin') != $sknst[0]) {
429  $user_object->setPref('skin', $sknst[0]);
430  $user_object->setPref('style', $sknst[1]);
431  }
432  }
433  if ($this->isSettingChangeable('session_reminder')) {
434  $user_object->setPref('session_reminder_lead_time', (string) $this->form_gui->getInput('session_reminder_lead_time'));
435  }
436  if ($this->isSettingChangeable('hide_own_online_status')) {
437  $user_object->setPref(
438  'hide_own_online_status',
439  $this->form_gui->getInput('hide_own_online_status')
440  );
441  }
442  if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
443  $user_object->setPref(
444  'bs_allow_to_contact_me',
445  $this->form_gui->getInput('bs_allow_to_contact_me') ? 'y' : 'n'
446  );
447  }
448  if ($this->isSettingChangeable('chat_osc_accept_msg')) {
449  $user_object->setPref(
450  'chat_osc_accept_msg',
451  $this->form_gui->getInput('chat_osc_accept_msg') ? 'y' : 'n'
452  );
453  }
454  if ($this->isSettingChangeable('chat_broadcast_typing')) {
455  $user_object->setPref(
456  'chat_broadcast_typing',
457  $this->form_gui->getInput('chat_broadcast_typing') ? 'y' : 'n'
458  );
459  }
460  $user_object->writePrefs();
461 
462  //set role entries
463  $this->rbac_admin->assignUser(
464  (int) $this->form_gui->getInput('default_role'),
465  $user_object->getId(),
466  true
467  );
468 
469  $msg = $this->lng->txt('user_added');
470 
471  $this->user->setPref(
472  'send_info_mails',
473  ($this->form_gui->getInput('send_mail') == 'y') ? 'y' : 'n'
474  );
475  $this->user->writePrefs();
476 
477  $this->object = $user_object;
478 
479  if ($this->isSettingChangeable('upload')) {
480  $this->uploadUserPicture();
481  }
482 
483  if ($profile_maybe_incomplete
484  && $this->user_profile->isProfileIncomplete($this->object)) {
485  $this->object->setProfileIncomplete(true);
486  $this->object->update();
487  }
488 
489  // send new account mail
490  if ($this->form_gui->getInput('send_mail') == 'y') {
491  $acc_mail = new ilAccountMail();
492  $acc_mail->useLangVariablesAsFallback(true);
493  $acc_mail->setAttachConfiguredFiles(true);
494  $acc_mail->setUserPassword($this->form_gui->getInput('passwd'));
495  $acc_mail->setUser($user_object);
496 
497  if ($acc_mail->send()) {
498  $msg .= '<br />' . $this->lng->txt('mail_sent');
499  $this->tpl->setOnScreenMessage('success', $msg, true);
500  } else {
501  $msg .= '<br />' . $this->lng->txt('mail_not_sent');
502  $this->tpl->setOnScreenMessage('info', $msg, true);
503  }
504  } else {
505  $this->tpl->setOnScreenMessage('success', $msg, true);
506  }
507 
508  if (strtolower($this->requested_baseClass) == 'iladministrationgui') {
509  $this->ctrl->redirectByClass('ilobjuserfoldergui', 'view');
510  return;
511  }
512 
513  $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
514  }
515 
516  public function editObject(): void
517  {
518  $this->checkUserWriteRight();
519 
520  if ($this->usrf_ref_id != USER_FOLDER_ID) {
521  $this->tabs_gui->clearTargets();
522  }
523 
524  // get form
525  $this->initForm('edit');
526  $this->getValues();
527  $this->renderForm();
528  }
529 
530  protected function loadValuesFromForm(string $a_mode = 'create'): ilObjUser
531  {
532  $user = null;
533 
534  switch ($a_mode) {
535  case 'create':
536  $user = new ilObjUser();
537  break;
538 
539  case 'update':
541  break;
542  }
543 
544  $from = $this->form_gui->getItemByPostVar('time_limit_from')->getDate();
545  $user->setTimeLimitFrom($from
546  ? $from->get(IL_CAL_UNIX)
547  : null);
548 
549  $until = $this->form_gui->getItemByPostVar('time_limit_until')->getDate();
550  $user->setTimeLimitUntil($until
551  ? $until->get(IL_CAL_UNIX)
552  : null);
553 
554  $user->setTimeLimitUnlimited((bool) $this->form_gui->getInput('time_limit_unlimited'));
555 
556  if ($a_mode == 'create') {
557  $user->setTimeLimitOwner($this->usrf_ref_id);
558  }
559  if ($this->isSettingChangeable('birthday')) {
560  $bd = $this->form_gui->getItemByPostVar('birthday');
561  $bd = $bd->getDate();
562  $user->setBirthday($bd
563  ? $bd->get(IL_CAL_DATE)
564  : null);
565  }
566  $user->setLogin($this->form_gui->getInput('login'));
567  if ($this->isSettingChangeable('gender')) {
568  $user->setGender($this->form_gui->getInput('gender'));
569  }
570  if ($this->isSettingChangeable('title')) {
571  $user->setUTitle($this->form_gui->getInput('title'));
572  }
573  if ($this->isSettingChangeable('firstname')) {
574  $user->setFirstname($this->form_gui->getInput('firstname'));
575  }
576  if ($this->isSettingChangeable('lastname')) {
577  $user->setLastname($this->form_gui->getInput('lastname'));
578  }
579  $user->setFullname();
580  if ($this->isSettingChangeable('institution')) {
581  $user->setInstitution($this->form_gui->getInput('institution'));
582  }
583  if ($this->isSettingChangeable('department')) {
584  $user->setDepartment($this->form_gui->getInput('department'));
585  }
586  if ($this->isSettingChangeable('street')) {
587  $user->setStreet($this->form_gui->getInput('street'));
588  }
589  if ($this->isSettingChangeable('city')) {
590  $user->setCity($this->form_gui->getInput('city'));
591  }
592  if ($this->isSettingChangeable('zipcode')) {
593  $user->setZipcode($this->form_gui->getInput('zipcode'));
594  }
595  if ($this->isSettingChangeable('country')) {
596  $user->setCountry($this->form_gui->getInput('country'));
597  }
598  if ($this->isSettingChangeable('sel_country')) {
599  $user->setSelectedCountry($this->form_gui->getInput('sel_country'));
600  }
601  if ($this->isSettingChangeable('phone_office')) {
602  $user->setPhoneOffice($this->form_gui->getInput('phone_office'));
603  }
604  if ($this->isSettingChangeable('phone_home')) {
605  $user->setPhoneHome($this->form_gui->getInput('phone_home'));
606  }
607  if ($this->isSettingChangeable('phone_mobile')) {
608  $user->setPhoneMobile($this->form_gui->getInput('phone_mobile'));
609  }
610  if ($this->isSettingChangeable('fax')) {
611  $user->setFax($this->form_gui->getInput('fax'));
612  }
613  if ($this->isSettingChangeable('matriculation')) {
614  $user->setMatriculation($this->form_gui->getInput('matriculation'));
615  }
616  if ($this->isSettingChangeable('email')) {
617  $user->setEmail($this->form_gui->getInput('email'));
618  }
619  if ($this->isSettingChangeable('second_email')) {
620  $user->setSecondEmail($this->form_gui->getInput('second_email'));
621  }
622  if ($this->isSettingChangeable('hobby')) {
623  $user->setHobby($this->form_gui->getInput('hobby'));
624  }
625  if ($this->isSettingChangeable('referral_comment')) {
626  $user->setComment($this->form_gui->getInput('referral_comment'));
627  }
628 
629  $general_interests = is_array($this->form_gui->getInput('interests_general'))
630  ? $this->form_gui->getInput('interests_general')
631  : [];
632  $user->setGeneralInterests($general_interests);
633 
634  $offering_help = is_array($this->form_gui->getInput('interests_help_offered'))
635  ? $this->form_gui->getInput('interests_help_offered')
636  : [];
637  $user->setOfferingHelp($offering_help);
638 
639  $looking_for_help = is_array($this->form_gui->getInput('interests_help_looking'))
640  ? $this->form_gui->getInput('interests_help_looking')
641  : [];
642  $user->setLookingForHelp($looking_for_help);
643 
644  $user->setClientIP($this->form_gui->getInput('client_ip'));
645  $user->setLatitude($this->form_gui->getInput('latitude'));
646  $user->setLongitude($this->form_gui->getInput('longitude'));
647  $zoom = (int) $this->form_gui->getInput('loc_zoom');
648  if ($zoom == 0) {
649  $zoom = null;
650  }
651  $user->setLocationZoom($zoom);
652 
653  $user->setAuthMode($this->form_gui->getInput('auth_mode'));
654  $user->setExternalAccount($this->form_gui->getInput('ext_account'));
655 
656  if ((int) $user->getActive() != (int) $this->form_gui->getInput('active')) {
657  $user->setActive((bool) $this->form_gui->getInput('active'), $this->user->getId());
658  }
659 
660  return $user;
661  }
662 
663  protected function loadUserDefinedDataFromForm(?ilObjUser $user = null): void
664  {
665  if (!$user) {
667  }
668 
669  $user_defined_fields = ilUserDefinedFields::_getInstance();
670  if ($this->usrf_ref_id == USER_FOLDER_ID) {
671  $all_defs = $user_defined_fields->getDefinitions();
672  } else {
673  $all_defs = $user_defined_fields->getChangeableLocalUserAdministrationDefinitions();
674  }
675  $udf = [];
676  foreach ($all_defs as $definition) {
677  $f = "udf_" . $definition['field_id'];
678  $item = $this->form_gui->getItemByPostVar($f);
679  if ($item && !$item->getDisabled()) {
680  $udf[$definition['field_id']] = $this->form_gui->getInput($f);
681  }
682  }
683  $user->setUserDefinedData($udf);
684  }
685 
686  public function updateObject(): void
687  {
688  $this->checkUserWriteRight();
689  $this->initForm('edit');
690 
691  // Manipulate form so ignore required fields are no more required. This has to be done before ilPropertyFormGUI::checkInput() is called.
692  $profile_maybe_incomplete = false;
693  if ($this->form_gui->getInput('ignore_rf', false)) {
694  $profile_maybe_incomplete = $this->handleIgnoredRequiredFields();
695  }
696 
697  if ($this->form_gui->checkInput()) {
698  // @todo: external account; time limit
699  // if not allowed or empty -> do no change password
701  ilAuthUtils::_getAuthMode($this->form_gui->getInput('auth_mode'))
702  ) && trim($this->form_gui->getInput('passwd')) !== ''
703  && ($this->user->getId() === (int) SYSTEM_USER_ID
704  || !in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->object->getId()))
705  || in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->user->getId())))
706  ) {
707  $this->object->setPasswd($this->form_gui->getInput('passwd'), ilObjUser::PASSWD_PLAIN);
708  }
709 
710  if ((int) $this->form_gui->getInput('active') == 1) {
711  $this->object->setLoginAttempts(0);
712  }
713 
714  $this->loadValuesFromForm('update');
715 
717 
718  try {
719  $this->object->updateLogin($this->form_gui->getInput('login'));
720  } catch (ilUserException $e) {
721  $this->tpl->setOnScreenMessage('failure', $e->getMessage());
722  $this->form_gui->setValuesByPost();
723  $this->renderForm();
724  return;
725  }
726 
727  $this->object->setTitle($this->object->getFullname());
728  $this->object->setDescription($this->object->getEmail());
729 
730  if ($this->isSettingChangeable('language')) {
731  $this->object->setLanguage($this->form_gui->getInput('language'));
732  }
733 
734  if ($this->isSettingChangeable('skin_style')) {
735  //set user skin and style
736  $sknst = explode(':', $this->form_gui->getInput('skin_style'));
737 
738  if ($this->object->getPref('style') != $sknst[1] ||
739  $this->object->getPref('skin') != $sknst[0]) {
740  $this->object->setPref('skin', $sknst[0]);
741  $this->object->setPref('style', $sknst[1]);
742  }
743  }
744 
745  if ($this->isSettingChangeable('session_reminder')) {
746  $this->object->setPref('session_reminder_lead_time', (string) $this->form_gui->getInput('session_reminder_lead_time'));
747  }
748 
749  if ($this->isSettingChangeable('hide_own_online_status')) {
750  $this->object->setPref(
751  'hide_own_online_status',
752  ($this->form_gui->getInput('hide_own_online_status') ?? '0')
753  );
754  }
755  if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
756  $this->object->setPref(
757  'bs_allow_to_contact_me',
758  ($this->form_gui->getInput('bs_allow_to_contact_me') ?? false) ? 'y' : 'n'
759  );
760  }
761  if ($this->isSettingChangeable('chat_osc_accept_msg')) {
762  $this->object->setPref(
763  'chat_osc_accept_msg',
764  ($this->form_gui->getInput('chat_osc_accept_msg') ?? false) ? 'y' : 'n'
765  );
766  }
767  if ($this->isSettingChangeable('chat_broadcast_typing')) {
768  $this->object->setPref(
769  'chat_broadcast_typing',
770  ($this->form_gui->getInput('chat_broadcast_typing') ?? false) ? 'y' : 'n'
771  );
772  }
773 
774  // set a timestamp for last_password_change
775  // this ts is needed by ilSecuritySettings
776  $this->object->setLastPasswordChangeTS(time());
777 
778  // #10054 - profile may have been completed, check below is only for incomplete
779  $this->object->setProfileIncomplete(false);
780 
781  $this->update = $this->object->update();
782 
783  // If the current user is editing its own user account,
784  // we update his preferences.
785  if ($this->user->getId() == $this->object->getId()) {
786  $this->user->readPrefs();
787  }
788  $this->user->setPref(
789  'send_info_mails',
790  ($this->form_gui->getInput('send_mail') === 'y') ? 'y' : 'n'
791  );
792  $this->user->writePrefs();
793 
794  $mail_message = $this->__sendProfileMail();
795  $msg = $this->lng->txt('saved_successfully') . $mail_message;
796 
797  // same personal image
798  if ($this->isSettingChangeable('upload')) {
799  $this->uploadUserPicture();
800  }
801 
802  if ($profile_maybe_incomplete) {
805  if ($this->user_profile->isProfileIncomplete($user)) {
806  $this->object->setProfileIncomplete(true);
807  $this->object->update();
808  }
809  }
810 
811  // feedback
812  $this->tpl->setOnScreenMessage('success', $msg, true);
813 
814  if (strtolower($this->requested_baseClass) == 'iladministrationgui') {
815  $this->ctrl->redirectByClass('ilobjuserfoldergui', 'view');
816  } else {
817  $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
818  }
819  } else {
820  $this->form_gui->setValuesByPost();
821  $this->tabs_gui->activateTab('properties');
822  $this->tpl->setContent($this->form_gui->getHtml());
823  }
824  }
825 
826  public function getValues(): void
827  {
828  $data = [];
829 
830  // login data
831  $data['auth_mode'] = $this->object->getAuthMode();
832  $data['login'] = $this->object->getLogin();
833  $data['ext_account'] = $this->object->getExternalAccount();
834  $data['create_date'] = ilDatePresentation::formatDate(new ilDateTime(
835  $this->object->getCreateDate(),
837  ));
838  $data['owner'] = ilObjUser::_lookupLogin($this->object->getOwner());
839  $data['approve_date'] = ($this->object->getApproveDate() != '')
840  ? ilDatePresentation::formatDate(new ilDateTime($this->object->getApproveDate(), IL_CAL_DATETIME))
841  : null;
842 
843  $data['last_login'] = ($this->object->getLastLogin() != '')
844  ? ilDatePresentation::formatDate(new ilDateTime($this->object->getLastLogin(), IL_CAL_DATETIME))
845  : null;
846  $data['active'] = $this->object->getActive();
847  $data['time_limit_unlimited'] = $this->object->getTimeLimitUnlimited() ? '1' : '0';
848 
849  $data['time_limit_from'] = $this->object->getTimeLimitFrom()
850  ? new ilDateTime($this->object->getTimeLimitFrom(), IL_CAL_UNIX)
851  : null;
852  $data['time_limit_until'] = $this->object->getTimeLimitUntil()
853  ? new ilDateTime($this->object->getTimeLimitUntil(), IL_CAL_UNIX)
854  : null;
855 
856  $data['gender'] = $this->object->getGender();
857  $data['firstname'] = $this->object->getFirstname();
858  $data['lastname'] = $this->object->getLastname();
859  $data['title'] = $this->object->getUTitle();
860  $data['birthday'] = $this->object->getBirthday()
861  ? new ilDate($this->object->getBirthday(), IL_CAL_DATE)
862  : null;
863  $data['institution'] = $this->object->getInstitution();
864  $data['department'] = $this->object->getDepartment();
865  $data['street'] = $this->object->getStreet();
866  $data['city'] = $this->object->getCity();
867  $data['zipcode'] = $this->object->getZipcode();
868  $data['country'] = $this->object->getCountry();
869  $data['sel_country'] = $this->object->getSelectedCountry();
870  $data['phone_office'] = $this->object->getPhoneOffice();
871  $data['phone_home'] = $this->object->getPhoneHome();
872  $data['phone_mobile'] = $this->object->getPhoneMobile();
873  $data['fax'] = $this->object->getFax();
874  $data['email'] = $this->object->getEmail();
875  $data['second_email'] = $this->object->getSecondEmail();
876  $data['hobby'] = $this->object->getHobby();
877  $data['referral_comment'] = $this->object->getComment();
878 
879  $data['interests_general'] = $this->object->getGeneralInterests();
880  $data['interests_help_offered'] = $this->object->getOfferingHelp();
881  $data['interests_help_looking'] = $this->object->getLookingForHelp();
882 
883  $data['matriculation'] = $this->object->getMatriculation();
884  $data['client_ip'] = $this->object->getClientIP();
885 
886  $this->user_defined_fields = ilUserDefinedFields::_getInstance();
887  $user_defined_data = $this->object->getUserDefinedData();
888  foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
889  $data['udf_' . $field_id] = $user_defined_data['f_' . $field_id] ?? '';
890  }
891 
892  $data['language'] = $this->object->getLanguage();
893  $data['skin_style'] = $this->object->skin . ':' . $this->object->prefs['style'];
894  $data['session_reminder_lead_time'] =
895  $this->object->prefs['session_reminder_lead_time'] ??
896  ilSessionReminder::byLoggedInUser()->getGlobalSessionReminderLeadTime();
897  $data['hide_own_online_status'] = $this->object->prefs['hide_own_online_status'] ?? '';
898  $data['bs_allow_to_contact_me'] = ($this->object->prefs['bs_allow_to_contact_me'] ?? '') == 'y';
899  $data['chat_osc_accept_msg'] = ($this->object->prefs['chat_osc_accept_msg'] ?? '') == 'y';
900  $data['chat_broadcast_typing'] = ($this->object->prefs['chat_broadcast_typing'] ?? '') == 'y';
901 
902  $data['send_mail'] = (($this->object->prefs['send_info_mails'] ?? '') == 'y');
903 
904  $this->form_gui->setValuesByArray($data);
905  }
906 
910  public function initForm(string $a_mode): void
911  {
912  $settings = $this->settings->getAll();
913 
914  $this->form_gui = new ilPropertyFormGUI();
915  $this->form_gui->setFormAction($this->ctrl->getFormAction($this));
916  if ($a_mode == 'create') {
917  $this->form_gui->setTitle($this->lng->txt('usr_new'));
918  } else {
919  $this->form_gui->setTitle($this->lng->txt('usr_edit'));
920  }
921 
922  // login data
923  $sec_l = new ilFormSectionHeaderGUI();
924  $sec_l->setTitle($this->lng->txt('login_data'));
925  $this->form_gui->addItem($sec_l);
926 
927  // authentication mode
928  $active_auth_modes = ilAuthUtils::_getActiveAuthModes();
929  $am = new ilSelectInputGUI($this->lng->txt('auth_mode'), 'auth_mode');
930  $option = [];
931  foreach ($active_auth_modes as $auth_name => $auth_key) {
932  if ($auth_name == 'default') {
933  $name = $this->lng->txt('auth_' . $auth_name) . ' (' . $this->lng->txt('auth_' . ilAuthUtils::_getAuthModeName($auth_key)) . ')';
934  } else {
935  $name = ilAuthUtils::getAuthModeTranslation((string) $auth_key, $auth_name);
936  }
937  $option[$auth_name] = $name;
938  }
939  $am->setOptions($option);
940  $this->form_gui->addItem($am);
941 
942  if ($a_mode == 'edit') {
943  $id = new ilNonEditableValueGUI($this->lng->txt('usr_id'), 'id');
944  $id->setValue($this->object->getId());
945  $this->form_gui->addItem($id);
946  }
947 
948  $lo = new ilUserLoginInputGUI($this->lng->txt('login'), 'login');
949  $lo->setRequired(true);
950  if ($a_mode == 'edit') {
951  $lo->setCurrentUserId($this->object->getId());
952  try {
953  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->object->getId());
954  $lo->setInfo(
955  sprintf(
956  $this->lng->txt('usr_loginname_history_info'),
957  ilDatePresentation::formatDate(new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
958  $last_history_entry[0]
959  )
960  );
961  } catch (ilUserException $e) {
962  }
963  }
964 
965  $this->form_gui->addItem($lo);
966 
967  if ($this->user->getId() === (int) SYSTEM_USER_ID
968  || !in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->object->getId()))
969  || in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->user->getId()))) {
970  $pw = new ilPasswordInputGUI($this->lng->txt('passwd'), 'passwd');
971  $pw->setUseStripSlashes(false);
972  $pw->setSize(32);
973  $pw->setMaxLength(80);
974  $pw->setValidateAuthPost('auth_mode');
975  if ($a_mode == 'create') {
976  $pw->setRequiredOnAuth(true);
977  }
978  if ($this->user->getId() !== (int) SYSTEM_USER_ID
979  && in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->object->getId()))
980  && !in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->user->getId()))) {
981  $pw->setDisabled(true);
982  }
984  $this->form_gui->addItem($pw);
985  }
986 
988  $ext = new ilTextInputGUI($this->lng->txt('user_ext_account'), 'ext_account');
989  $ext->setSize(40);
990  $ext->setMaxLength(250);
991  $ext->setInfo($this->lng->txt('user_ext_account_desc'));
992  $this->form_gui->addItem($ext);
993  }
994 
995  $sec_si = new ilFormSectionHeaderGUI();
996  $sec_si->setTitle($this->lng->txt('system_information'));
997  $this->form_gui->addItem($sec_si);
998 
999  // create date, approve date, agreement date, last login
1000  if ($a_mode == 'edit') {
1001  $sia = [
1002  'create_date' => '',
1003  'approve_date' => '',
1004  ...$this->legal_documents->userManagementFields($this->object),
1005  'last_login' => '',
1006  'owner' => '',
1007  ];
1008  foreach ($sia as $a => $v) {
1009  if (is_string($v)) {
1010  $siai = new ilNonEditableValueGUI($this->lng->txt($a), $a);
1011  $siai->setValue($v);
1012  $this->form_gui->addItem($siai);
1013  } else {
1014  $this->form_gui->addItem($v);
1015  }
1016  }
1017  }
1018 
1019  $ac = new ilCheckboxInputGUI($this->lng->txt('active'), 'active');
1020  $ac->setChecked(true);
1021  $this->form_gui->addItem($ac);
1022 
1023  $this->lng->loadLanguageModule('crs');
1024 
1025  $radg = new ilRadioGroupInputGUI($this->lng->txt('time_limit'), 'time_limit_unlimited');
1026  $radg->setValue('1');
1027  $radg->setRequired(true);
1028  $op1 = new ilRadioOption($this->lng->txt('user_access_unlimited'), '1');
1029  $radg->addOption($op1);
1030  $op2 = new ilRadioOption($this->lng->txt('user_access_limited'), '0');
1031  $radg->addOption($op2);
1032 
1033  $acfrom = new ilDateTimeInputGUI($this->lng->txt('crs_from'), 'time_limit_from');
1034  $acfrom->setRequired(true);
1035  $acfrom->setShowTime(true);
1036  $acfrom->setMinuteStepSize(1);
1037  $op2->addSubItem($acfrom);
1038 
1039  $acto = new ilDateTimeInputGUI($this->lng->txt('crs_to'), 'time_limit_until');
1040  $acto->setRequired(true);
1041  $acto->setShowTime(true);
1042  $acto->setMinuteStepSize(1);
1043  $op2->addSubItem($acto);
1044 
1045  $this->form_gui->addItem($radg);
1046 
1047  if ($this->isSettingChangeable('gender')
1048  || $this->isSettingChangeable('firstname')
1049  || $this->isSettingChangeable('lastname')
1050  || $this->isSettingChangeable('title')
1051  || $this->isSettingChangeable('personal_image')
1052  || $this->isSettingChangeable('birhtday')
1053  ) {
1054  $sec_pd = new ilFormSectionHeaderGUI();
1055  $sec_pd->setTitle($this->lng->txt('personal_data'));
1056  $this->form_gui->addItem($sec_pd);
1057  }
1058 
1059  if ($this->isSettingChangeable('gender')) {
1060  $gndr = new ilRadioGroupInputGUI($this->lng->txt('salutation'), 'gender');
1061  $gndr->setRequired(isset($settings['require_gender']) && $settings['require_gender']);
1062  $neutral = new ilRadioOption($this->lng->txt('salutation_n'), 'n');
1063  $gndr->addOption($neutral);
1064  $female = new ilRadioOption($this->lng->txt('salutation_f'), 'f');
1065  $gndr->addOption($female);
1066  $male = new ilRadioOption($this->lng->txt('salutation_m'), 'm');
1067  $gndr->addOption($male);
1068  $this->form_gui->addItem($gndr);
1069  }
1070 
1071  $fields = [
1072  'firstname' => true,
1073  'lastname' => true,
1074  'title' => isset($settings['require_title']) && $settings['require_title']
1075  ];
1076  foreach ($fields as $field => $req) {
1077  $max_len = $field === 'title' ? 32 : 128;
1078  if ($this->isSettingChangeable($field)) {
1079  // #18795
1080  $caption = ($field == 'title')
1081  ? 'person_title'
1082  : $field;
1083  $inp = new ilTextInputGUI($this->lng->txt($caption), $field);
1084  $inp->setSize(32);
1085  $inp->setMaxLength($max_len);
1086  $inp->setRequired($req);
1087  $this->form_gui->addItem($inp);
1088  }
1089  }
1090 
1091  // personal image
1092  if ($this->isSettingChangeable('upload')) {
1093  $pi = new ilImageFileInputGUI($this->lng->txt('personal_picture'), 'userfile');
1094  if ($a_mode == 'edit' || $a_mode == 'upload') {
1096  $this->object->getId(),
1097  'small',
1098  true,
1099  true
1100  ));
1101  }
1102  $this->form_gui->addItem($pi);
1103  }
1104 
1105  if ($this->isSettingChangeable('birthday')) {
1106  $birthday = new ilBirthdayInputGUI($this->lng->txt('birthday'), 'birthday');
1107  $birthday->setRequired(isset($settings['require_birthday']) && $settings['require_birthday']);
1108  $this->form_gui->addItem($birthday);
1109  }
1110 
1111  // institution, department, street, city, zip code, country, phone office
1112  // phone home, phone mobile, fax, e-mail
1113  $fields = [
1114  ['institution', 40, 80],
1115  ['department', 40, 80],
1116  ['street', 40, 40],
1117  ['city', 40, 40],
1118  ['zipcode', 10, 10],
1119  ['country', 40, 40],
1120  ['sel_country'],
1121  ['phone_office', 30, 30],
1122  ['phone_home', 30, 30],
1123  ['phone_mobile', 30, 30],
1124  ['fax', 30, 30]
1125  ];
1126 
1127  $counter = 0;
1128  foreach ($fields as $field) {
1129  if (!$counter++ and $this->isSettingChangeable($field[0])) {
1130  // contact data
1131  $sec_cd = new ilFormSectionHeaderGUI();
1132  $sec_cd->setTitle($this->lng->txt('contact_data'));
1133  $this->form_gui->addItem($sec_cd);
1134 
1135  // org units
1136  if ($a_mode == 'edit') {
1137  $orgus = new ilNonEditableValueGUI($this->lng->txt('objs_orgu'), 'org_units');
1138  $orgus->setValue($this->object->getOrgUnitsRepresentation());
1139  $this->form_gui->addItem($orgus);
1140  }
1141  }
1142  if ($this->isSettingChangeable($field[0])) {
1143  if ($field[0] != 'sel_country') {
1144  $inp = new ilTextInputGUI($this->lng->txt($field[0]), $field[0]);
1145  $inp->setSize($field[1]);
1146  $inp->setMaxLength($field[2]);
1147  $inp->setRequired(isset($settings['require_' . $field[0]]) &&
1148  $settings['require_' . $field[0]]);
1149  $this->form_gui->addItem($inp);
1150  } else {
1151  // country selection
1152  $cs = new ilCountrySelectInputGUI($this->lng->txt($field[0]), $field[0]);
1153  $cs->setRequired(isset($settings['require_' . $field[0]]) &&
1154  $settings['require_' . $field[0]]);
1155  $this->form_gui->addItem($cs);
1156  }
1157  }
1158  }
1159 
1160  if ($this->isSettingChangeable('email')) {
1161  $em = new ilEMailInputGUI($this->lng->txt('email'), 'email');
1162  $em->setRequired(isset($settings['require_email']) && $settings['require_email']);
1163  $em->setMaxLength(128);
1164  $this->form_gui->addItem($em);
1165  }
1166 
1167  if ($this->isSettingChangeable('second_email')) {
1168  $em = new ilEMailInputGUI($this->lng->txt('second_email'), 'second_email');
1169 
1170  $this->form_gui->addItem($em);
1171  }
1172 
1173  if ($this->isSettingChangeable('hobby')) {
1174  $hob = new ilTextAreaInputGUI($this->lng->txt('hobby'), 'hobby');
1175  $hob->setRows(3);
1176  $hob->setCols(40);
1177  $hob->setRequired(isset($settings['require_hobby']) &&
1178  $settings['require_hobby']);
1179  $this->form_gui->addItem($hob);
1180  }
1181 
1182  if ($this->isSettingChangeable('referral_comment')) {
1183  $rc = new ilTextAreaInputGUI($this->lng->txt('referral_comment'), 'referral_comment');
1184  $rc->setRows(3);
1185  $rc->setCols(40);
1186  $rc->setRequired(isset($settings['require_referral_comment']) &&
1187  $settings['require_referral_comment']);
1188  $this->form_gui->addItem($rc);
1189  }
1190 
1191  $sh = new ilFormSectionHeaderGUI();
1192  $sh->setTitle($this->lng->txt('interests'));
1193  $this->form_gui->addItem($sh);
1194 
1195  $multi_fields = ['interests_general', 'interests_help_offered', 'interests_help_looking'];
1196  foreach ($multi_fields as $multi_field) {
1197  if ($this->isSettingChangeable($multi_field)) {
1198  // see ilUserProfile
1199  $ti = new ilTextInputGUI($this->lng->txt($multi_field), $multi_field);
1200  $ti->setMulti(true);
1201  $ti->setMaxLength(40);
1202  $ti->setSize(40);
1203  $ti->setRequired(isset($settings['require_' . $multi_field]) &&
1204  $settings['require_' . $multi_field]);
1205  $this->form_gui->addItem($ti);
1206  }
1207  }
1208 
1209  if ($this->isSettingChangeable('user_profile_other')) {
1210  $sec_oi = new ilFormSectionHeaderGUI();
1211  $sec_oi->setTitle($this->lng->txt('user_profile_other'));
1212  $this->form_gui->addItem($sec_oi);
1213  }
1214 
1215  if ($this->isSettingChangeable('matriculation')) {
1216  $mr = new ilTextInputGUI($this->lng->txt('matriculation'), 'matriculation');
1217  $mr->setSize(40);
1218  $mr->setMaxLength(40);
1219  $mr->setRequired(isset($settings['require_matriculation']) &&
1220  $settings['require_matriculation']);
1221  $this->form_gui->addItem($mr);
1222  }
1223 
1224  $ip = new ilTextInputGUI($this->lng->txt('client_ip'), 'client_ip');
1225  $ip->setSize(40);
1226  $ip->setMaxLength(255);
1227  $ip->setInfo($this->lng->txt('current_ip') . ' ' . $_SERVER['REMOTE_ADDR'] . ' <br />' .
1228  '<span class="warning">' . $this->lng->txt('current_ip_alert') . '</span>');
1229  $this->form_gui->addItem($ip);
1230 
1231  $user_defined_fields = ilUserDefinedFields::_getInstance();
1232 
1233  if ($this->usrf_ref_id == USER_FOLDER_ID) {
1234  $all_defs = $user_defined_fields->getDefinitions();
1235  } else {
1236  $all_defs = $user_defined_fields->getChangeableLocalUserAdministrationDefinitions();
1237  }
1238 
1239  foreach ($all_defs as $definition) {
1240  $f_property = ilCustomUserFieldsHelper::getInstance()->getFormPropertyForDefinition($definition, true);
1241  if ($f_property instanceof ilFormPropertyGUI) {
1242  $this->form_gui->addItem($f_property);
1243  }
1244  }
1245 
1246  if ($a_mode == 'create'
1247  || $this->isSettingChangeable('language')
1248  || $this->isSettingChangeable('skin_style')
1249  || $this->isSettingChangeable('hide_own_online_status')
1250  || $this->isSettingChangeable('bs_allow_to_contact_me')
1251  || $this->isSettingChangeable('chat_osc_accept_msg')
1252  || $this->isSettingChangeable('chat_broadcast_typing')
1253  || ($this->isSettingChangeable('session_reminder'))
1254  ) {
1255  $sec_st = new ilFormSectionHeaderGUI();
1256  $sec_st->setTitle($this->lng->txt('settings'));
1257  $this->form_gui->addItem($sec_st);
1258  }
1259 
1260  if ($a_mode == 'create') {
1261  $role = new ilSelectInputGUI(
1262  $this->lng->txt('default_role'),
1263  'default_role'
1264  );
1265  $role->setRequired(true);
1266  $role->setValue($this->default_role);
1267  $role->setOptions($this->selectable_roles);
1268  $this->form_gui->addItem($role);
1269  }
1270 
1271  if ($this->isSettingChangeable('language')) {
1272  $languages = $this->lng->getInstalledLanguages();
1273  $this->lng->loadLanguageModule('meta');
1274  $options = [];
1275  foreach ($languages as $l) {
1276  $options[$l] = $this->lng->txt('meta_l_' . $l);
1277  }
1278  $lang = new ilSelectInputGUI(
1279  $this->lng->txt('language'),
1280  'language'
1281  );
1282  $lang->setOptions($options);
1283  $lang->setValue($this->settings->get('language'));
1284  if (count($options) <= 1) {
1285  $lang->setDisabled(true);
1286  }
1287  $this->form_gui->addItem($lang);
1288  }
1289 
1290  if ($this->isSettingChangeable('skin_style')) {
1291  $sk = new ilSelectInputGUI(
1292  $this->lng->txt('skin_style'),
1293  'skin_style'
1294  );
1295 
1296  $skins = ilStyleDefinition::getAllSkins();
1297 
1298  $options = [];
1299  if (is_array($skins)) {
1300  $sk = new ilSelectInputGUI($this->lng->txt('skin_style'), 'skin_style');
1301 
1302  $options = [];
1303  foreach ($skins as $skin) {
1304  foreach ($skin->getStyles() as $style) {
1305  if (!ilSystemStyleSettings::_lookupActivatedStyle($skin->getId(), $style->getId())) {
1306  continue;
1307  }
1308 
1309  $options[$skin->getId() . ':' . $style->getId()] = $skin->getName() . ' / ' . $style->getName();
1310  }
1311  }
1312  }
1313  $sk->setOptions($options);
1314  $sk->setValue($this->default_layout_and_style);
1315 
1316  $this->form_gui->addItem($sk);
1317  }
1318 
1319  if ($this->isSettingChangeable('hide_own_online_status')) {
1320  $this->lng->loadLanguageModule('awrn');
1321 
1322  $default = ($this->settings->get('hide_own_online_status') == 'n')
1323  ? $this->lng->txt('user_awrn_show')
1324  : $this->lng->txt('user_awrn_hide');
1325 
1326  $options = [
1327  '' => $this->lng->txt('user_awrn_default') . ' (' . $default . ')',
1328  'n' => $this->lng->txt('user_awrn_show'),
1329  'y' => $this->lng->txt('user_awrn_hide')
1330  ];
1331  $os = new ilSelectInputGUI($this->lng->txt('awrn_user_show'), 'hide_own_online_status');
1332  $os->setOptions($options);
1333  $os->setDisabled((bool) $this->settings->get('usr_settings_disable_hide_own_online_status'));
1334  $os->setInfo($this->lng->txt('awrn_hide_from_awareness_info'));
1335  $this->form_gui->addItem($os);
1336  }
1337 
1338  if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
1339  $this->lng->loadLanguageModule('buddysystem');
1340  $os = new ilCheckboxInputGUI($this->lng->txt('buddy_allow_to_contact_me'), 'bs_allow_to_contact_me');
1341  if ($a_mode == 'create') {
1342  $os->setChecked(ilUtil::yn2tf($this->settings->get('bs_allow_to_contact_me', 'n')));
1343  }
1344  $this->form_gui->addItem($os);
1345  }
1346  if ($this->isSettingChangeable('chat_osc_accept_msg')) {
1347  $this->lng->loadLanguageModule('chatroom');
1348  $chat_osc_acm = new ilCheckboxInputGUI($this->lng->txt('chat_osc_accept_msg'), 'chat_osc_accept_msg');
1349  if ($a_mode == 'create') {
1350  $chat_osc_acm->setChecked(ilUtil::yn2tf($this->settings->get('chat_osc_accept_msg', 'n')));
1351  }
1352  $this->form_gui->addItem($chat_osc_acm);
1353  }
1354 
1355  if ($this->isSettingChangeable('session_reminder')) {
1356  $session_reminder = new ilNumberInputGUI(
1357  $this->lng->txt('session_reminder_input'),
1358  'session_reminder_lead_time'
1359  );
1360  $expires = ilSession::getSessionExpireValue();
1361  $session_reminder_object = ilSessionReminder::byLoggedInUser();
1362  $session_reminder->setInfo(
1363  sprintf(
1364  $this->lng->txt('session_reminder_lead_time_info'),
1367  ilDatePresentation::secondsToString($expires, true)
1368  )
1369  );
1370  $session_reminder->setValue(
1371  (string) $session_reminder_object->getGlobalSessionReminderLeadTime()
1372  );
1373  $session_reminder->setSize(3);
1374  $session_reminder->setMinValue(ilSessionReminder::LEAD_TIME_DISABLED);
1375  $session_reminder->setMaxValue($session_reminder_object->getMaxPossibleLeadTime());
1376  $this->form_gui->addItem($session_reminder);
1377  }
1378 
1379  if ($this->isSettingChangeable('send_mail')) {
1380  $sec_op = new ilFormSectionHeaderGUI();
1381  $sec_op->setTitle($this->lng->txt('options'));
1382  $this->form_gui->addItem($sec_op);
1383  }
1384 
1385  $se = new ilCheckboxInputGUI($this->lng->txt('inform_user_mail'), 'send_mail');
1386  $se->setInfo($this->lng->txt('inform_user_mail_info'));
1387  $se->setValue('y');
1388  $se->setChecked(($this->user->getPref('send_info_mails') == 'y'));
1389  $this->form_gui->addItem($se);
1390 
1391  $irf = new ilCheckboxInputGUI($this->lng->txt('ignore_required_fields'), 'ignore_rf');
1392  $irf->setInfo($this->lng->txt('ignore_required_fields_info'));
1393  $irf->setValue('1');
1394  $this->form_gui->addItem($irf);
1395 
1396  if ($a_mode == 'create' || $a_mode == 'save') {
1397  $this->form_gui->addCommandButton('save', $this->lng->txt('save'));
1398  }
1399  if ($a_mode == 'edit' || $a_mode == 'update') {
1400  $this->form_gui->addCommandButton('update', $this->lng->txt('save'));
1401  }
1402  $this->form_gui->addCommandButton('cancel', $this->lng->txt('cancel'));
1403  }
1404 
1405  protected function isSettingChangeable(string $a_field): bool
1406  {
1407  static $settings = null;
1408 
1409  if ($this->usrf_ref_id == USER_FOLDER_ID) {
1410  return true;
1411  }
1412 
1413  if ($settings == null) {
1414  $settings = $this->settings->getAll();
1415  }
1416  return (bool) ($settings['usr_settings_changeable_lua_' . $a_field] ?? false);
1417  }
1418 
1423  protected function uploadUserPicture(): void
1424  {
1425  $userfile_input = $this->form_gui->getItemByPostVar('userfile');
1426  if ($_FILES['userfile']['tmp_name'] == '') {
1427  if ($userfile_input->getDeletionFlag()) {
1428  $this->object->removeUserPicture();
1429  }
1430  return;
1431  }
1432  if ($_FILES['userfile']['size'] == 0) {
1433  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_file'));
1434  } else {
1435  $store_file = 'usr_' . $this->object->getId() . '.' . 'jpg';
1436 
1437  $rid = $this->moveFileToStorage();
1438 
1439  if ($rid === null) {
1440  return;
1441  }
1442 
1443  $this->object->setAvatarRid($rid->serialize());
1444  $this->irss->flavours()->ensure($rid, new ilUserProfilePictureDefinition());
1445 
1446  $this->object->setPref('profile_image', $store_file); // this may be dropped with the next release
1447  $this->object->update();
1448  }
1449  }
1450 
1452  {
1453  $uploads = $this->uploads->getResults();
1454  $upload_tmp_name = $_FILES['userfile']['tmp_name'];
1455  $avatar_upload_result = $uploads[$upload_tmp_name] ?? null;
1456 
1457  $existing_rid = null;
1458  if ($this->object->getAvatarRid() !== null) {
1459  $existing_rid = $this->irss->manage()->find($this->object->getAvatarRid());
1460  }
1461 
1462  $revision_title = 'Avatar for user ' . $this->object->getLogin();
1463  $this->stakeholder->setOwner($this->object->getId()); // The Resource is owned by the user we are editing
1464 
1465  if ($avatar_upload_result === null && file_exists($upload_tmp_name)) {
1466  $stream = Streams::ofResource(
1467  fopen($upload_tmp_name, 'r')
1468  );
1469 
1470  if ($existing_rid === null) {
1471  return $this->irss->manage()->stream($stream, $this->stakeholder, $revision_title);
1472  }
1473 
1474  $this->irss->manage()->appendNewRevisionFromStream(
1475  $existing_rid,
1476  $stream,
1477  $this->stakeholder,
1478  $revision_title
1479  );
1480  return $existing_rid;
1481  }
1482 
1483  if ($avatar_upload_result === null) {
1484  return null;
1485  }
1486 
1487  if ($existing_rid === null) {
1488  return $this->irss->manage()->upload(
1489  $avatar_upload_result,
1490  $this->stakeholder,
1491  $revision_title
1492  );
1493  }
1494 
1495  $this->irss->manage()->replaceWithUpload(
1496  $existing_rid,
1497  $avatar_upload_result,
1498  $this->stakeholder,
1499  $revision_title
1500  );
1501  return $existing_rid;
1502  }
1503 
1504  public function removeUserPictureObject(): void
1505  {
1506  $webspace_dir = ilFileUtils::getWebspaceDir();
1507  $image_dir = $webspace_dir . '/usr_images';
1508  $file = $image_dir . '/usr_' . $this->object->getId() . '.' . 'jpg';
1509  $thumb_file = $image_dir . '/usr_' . $this->object->getId() . '_small.jpg';
1510  $xthumb_file = $image_dir . '/usr_' . $this->object->getId() . '_xsmall.jpg';
1511  $xxthumb_file = $image_dir . '/usr_' . $this->object->getId() . '_xxsmall.jpg';
1512  $upload_file = $image_dir . '/upload_' . $this->object->getId();
1513 
1514  // remove user pref file name
1515  $this->object->setPref('profile_image', '');
1516  $this->object->update();
1517  $this->tpl->setOnScreenMessage('success', $this->lng->txt('user_image_removed'));
1518 
1519  if (is_file($file)) {
1520  unlink($file);
1521  }
1522  if (is_file($thumb_file)) {
1523  unlink($thumb_file);
1524  }
1525  if (is_file($xthumb_file)) {
1526  unlink($xthumb_file);
1527  }
1528  if (is_file($xxthumb_file)) {
1529  unlink($xxthumb_file);
1530  }
1531  if (is_file($upload_file)) {
1532  unlink($upload_file);
1533  }
1534 
1535  $this->editObject();
1536  }
1537 
1538  public function assignSaveObject(): void
1539  {
1540  if (!$this->rbac_system->checkAccess('edit_roleassignment', $this->usrf_ref_id)) {
1541  $this->ilias->raiseError(
1542  $this->lng->txt('msg_no_perm_assign_role_to_user'),
1543  $this->ilias->error_obj->MESSAGE
1544  );
1545  }
1546 
1547  $selected_roles = $this->user_request->getRoleIds();
1548  $posted_roles = $this->user_request->getPostedRoleIds();
1549 
1550  // prevent unassignment of system role from system user
1551  if ($this->object->getId() == SYSTEM_USER_ID && in_array(SYSTEM_ROLE_ID, $posted_roles)) {
1552  $selected_roles[] = SYSTEM_ROLE_ID;
1553  }
1554 
1555  $global_roles_all = $this->rbac_review->getGlobalRoles();
1556  $assigned_roles_all = $this->rbac_review->assignedRoles($this->object->getId());
1557  $assigned_roles = array_intersect($assigned_roles_all, $posted_roles);
1558  $assigned_global_roles_all = array_intersect($assigned_roles_all, $global_roles_all);
1559  $assigned_global_roles = array_intersect($assigned_global_roles_all, $posted_roles);
1560 
1561  $user_not_allowed_to_change_admin_role_assginements =
1562  !in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->user->getId()));
1563 
1564  if ($user_not_allowed_to_change_admin_role_assginements
1565  && in_array(SYSTEM_ROLE_ID, $assigned_roles_all)) {
1566  $selected_roles[] = SYSTEM_ROLE_ID;
1567  }
1568 
1569  $posted_global_roles = array_intersect($selected_roles, $global_roles_all);
1570 
1571  if (empty($selected_roles) && count($assigned_roles_all) === count($assigned_roles)
1572  || empty($posted_global_roles) && count($assigned_global_roles_all) === count($assigned_global_roles)) {
1573  $this->tpl->setOnScreenMessage(
1574  'failure',
1575  $this->lng->txt('msg_min_one_role') . '<br/>' . $this->lng->txt('action_aborted'),
1576  true
1577  );
1578  $this->ctrl->redirect($this, 'roleassignment');
1579  }
1580 
1581  foreach (array_diff($assigned_roles, $selected_roles) as $role) {
1582  if ($this->object->getId() === (int) SYSTEM_USER_ID && $role === SYSTEM_ROLE_ID
1583  || $user_not_allowed_to_change_admin_role_assginements && $role === SYSTEM_ROLE_ID) {
1584  continue;
1585  }
1586  $this->rbac_admin->deassignUser($role, $this->object->getId());
1587  }
1588 
1589  foreach (array_diff($selected_roles, $assigned_roles) as $role) {
1590  if ($this->object->getId() === (int) SYSTEM_USER_ID && $role === SYSTEM_ROLE_ID
1591  || $user_not_allowed_to_change_admin_role_assginements && $role === SYSTEM_ROLE_ID) {
1592  continue;
1593  }
1594  $this->rbac_admin->assignUser($role, $this->object->getId(), false);
1595  }
1596 
1597  $this->object->update();
1598 
1599  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_roleassignment_changed'), true);
1600 
1601  if (strtolower($this->requested_baseClass) == 'iladministrationgui') {
1602  $this->ctrl->redirect($this, 'roleassignment');
1603  } else {
1604  $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
1605  }
1606  }
1607 
1608  public function roleassignmentObject(): void
1609  {
1610  $this->tabs->activateTab('role_assignment');
1611 
1612  if (!$this->checkAccessToRolesTab()) {
1613  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('msg_no_perm_view_roles_of_user'), true);
1614  $this->ctrl->redirectByClass(self::class, 'edit');
1615  }
1616 
1617  $req_filtered_roles = $this->user_request->getFilteredRoles();
1619  'filtered_roles',
1620  ($req_filtered_roles > 0) ? $req_filtered_roles : ilSession::get('filtered_roles')
1621  );
1622 
1623  $filtered_roles = ilSession::get('filtered_roles');
1624  if ($filtered_roles > 5) {
1625  ilSession::set('filtered_roles', 0);
1626  }
1627 
1628  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.usr_role_assignment.html', 'components/ILIAS/User');
1629 
1630  // init table
1631  $tab = new ilRoleAssignmentTableGUI($this, 'roleassignment');
1632 
1633  $tab->parse($this->object->getId());
1634  $this->tpl->setVariable('ROLES_TABLE', $tab->getHTML());
1635  }
1636 
1637  public function applyFilterObject(): void
1638  {
1639  $table_gui = new ilRoleAssignmentTableGUI($this, 'roleassignment');
1640  $table_gui->writeFilterToSession();
1641  $table_gui->resetOffset();
1642  $this->roleassignmentObject();
1643  }
1644 
1645  public function resetFilterObject(): void
1646  {
1647  $table_gui = new ilRoleAssignmentTableGUI($this, 'roleassignment');
1648  $table_gui->resetOffset();
1649  $table_gui->resetFilter();
1650  $this->roleassignmentObject();
1651  }
1652 
1653  public function __getDateSelect(
1654  string $a_type,
1655  string $a_varname,
1656  string $a_selected
1657  ): string {
1658  $year = null;
1659  switch ($a_type) {
1660  case 'minute':
1661  for ($i = 0; $i <= 60; $i++) {
1662  $days[$i] = $i < 10 ? '0' . $i : $i;
1663  }
1664  return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $days, false, true);
1665 
1666  case 'hour':
1667  for ($i = 0; $i < 24; $i++) {
1668  $days[$i] = $i < 10 ? '0' . $i : $i;
1669  }
1670  return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $days, false, true);
1671 
1672  case 'day':
1673  for ($i = 1; $i < 32; $i++) {
1674  $days[$i] = $i < 10 ? '0' . $i : $i;
1675  }
1676  return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $days, false, true);
1677 
1678  case 'month':
1679  for ($i = 1; $i < 13; $i++) {
1680  $month[$i] = $i < 10 ? '0' . $i : $i;
1681  }
1682  return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $month, false, true);
1683 
1684  case 'year':
1685  if ($a_selected < date('Y')) {
1686  $start = $a_selected;
1687  } else {
1688  $start = date('Y');
1689  }
1690 
1691  for ($i = $start; $i < ((int) date('Y') + 11); ++$i) {
1692  $year[$i] = $i;
1693  }
1694  return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $year, false, true);
1695  }
1696  return '';
1697  }
1698 
1699  public function __toUnix(array $a_time_arr): int // Missing array type.
1700  {
1701  return mktime(
1702  $a_time_arr['hour'],
1703  $a_time_arr['minute'],
1704  $a_time_arr['second'],
1705  $a_time_arr['month'],
1706  $a_time_arr['day'],
1707  $a_time_arr['year']
1708  );
1709  }
1710 
1711  public function __unsetSessionVariables(): void
1712  {
1713  ilSession::clear('filtered_roles');
1714  }
1715 
1716  public function __buildFilterSelect(): string
1717  {
1718  $action[0] = $this->lng->txt('assigned_roles');
1719  $action[1] = $this->lng->txt('all_roles');
1720  $action[2] = $this->lng->txt('all_global_roles');
1721  $action[3] = $this->lng->txt('all_local_roles');
1722  $action[4] = $this->lng->txt('internal_local_roles_only');
1723  $action[5] = $this->lng->txt('non_internal_local_roles_only');
1724 
1726  ilSession::get('filtered_roles'),
1727  'filter',
1728  $action,
1729  false,
1730  true
1731  );
1732  }
1733 
1738  protected function addAdminLocatorItems(bool $do_not_add_object = false): void
1739  {
1740  $this->locator->clearItems();
1741 
1742  if ($this->admin_mode == 'settings') { // system settings
1743  $this->ctrl->setParameterByClass(
1744  'ilobjsystemfoldergui',
1745  'ref_id',
1747  );
1748  $this->locator->addItem(
1749  $this->lng->txt('administration'),
1750  $this->ctrl->getLinkTargetByClass(['iladministrationgui', 'ilobjsystemfoldergui'], ''),
1751  ilFrameTargetInfo::_getFrame('MainContent')
1752  );
1753 
1754  if ($this->requested_ref_id == USER_FOLDER_ID) {
1755  $this->locator->addItem(
1756  $this->lng->txt('obj_' . ilObject::_lookupType(
1757  ilObject::_lookupObjId($this->requested_ref_id)
1758  )),
1759  $this->ctrl->getLinkTargetByClass('ilobjuserfoldergui', 'view')
1760  );
1761  } elseif ($this->requested_ref_id == ROLE_FOLDER_ID) {
1762  $this->locator->addItem(
1763  $this->lng->txt('obj_' . ilObject::_lookupType(
1764  ilObject::_lookupObjId($this->requested_ref_id)
1765  )),
1766  $this->ctrl->getLinkTargetByClass('ilobjrolefoldergui', 'view')
1767  );
1768  }
1769 
1770  if ($this->obj_id > 0) {
1771  $this->locator->addItem(
1772  $this->object->getTitle(),
1773  $this->ctrl->getLinkTarget($this, 'view')
1774  );
1775  }
1776  }
1777  }
1778 
1779  public function __sendProfileMail(): string
1780  {
1781  if ($this->user_request->getSendMail() != 'y') {
1782  return '';
1783  }
1784  if (!strlen($this->object->getEmail())) {
1785  return '';
1786  }
1787 
1788  $usr_lang = new ilLanguage($this->object->getLanguage());
1789  $usr_lang->loadLanguageModule('crs');
1790  $usr_lang->loadLanguageModule('registration');
1791 
1792  $mmail = new ilMimeMail();
1793  $mmail->From($this->mail_sender_factory->system());
1794 
1795  $mailOptions = new ilMailOptions($this->object->getId());
1796  $mmail->To($mailOptions->getExternalEmailAddresses());
1797 
1798  $subject = $usr_lang->txt('profile_changed');
1799  $body = $usr_lang->txt('reg_mail_body_salutation')
1800  . ' ' . $this->object->getFullname() . ",\n\n";
1801 
1802  $date = $this->object->getApproveDate();
1803 
1804  if ($date !== null && (time() - strtotime($date)) < 10) {
1805  $body .= $usr_lang->txt('reg_mail_body_approve') . "\n\n";
1806  } else {
1807  $body .= $usr_lang->txt('reg_mail_body_profile_changed') . "\n\n";
1808  }
1809 
1810  // Append login info only if password has been changed
1811  if ($this->user_request->getPassword() != '') {
1812  $body .= $usr_lang->txt('reg_mail_body_text2') . "\n" .
1813  ILIAS_HTTP_PATH . '/login.php?client_id=' . $this->ilias->client_id . "\n" .
1814  $usr_lang->txt('login') . ': ' . $this->object->getLogin() . "\n" .
1815  $usr_lang->txt('passwd') . ': ' . $this->user_request->getPassword() . "\n\n";
1816  }
1817  $body .= $usr_lang->txt('reg_mail_body_text3') . "\n";
1818  $body .= $this->object->getProfileAsString($usr_lang);
1820 
1821 
1822  $mmail->Subject($subject, true);
1823  $mmail->Body($body);
1824  $mmail->Send();
1825 
1826  return '<br/>' . $this->lng->txt('mail_sent');
1827  }
1828 
1832  public static function _goto(string $a_target): void
1833  {
1834  global $DIC;
1835 
1836  $ilUser = $DIC['ilUser'];
1837 
1839  $ilCtrl = $DIC['ilCtrl'];
1840 
1841  // #10888
1842  if ($a_target == md5('usrdelown')) {
1843  if ($ilUser->getId() != ANONYMOUS_USER_ID &&
1844  $ilUser->hasDeletionFlag()) {
1845  $ilCtrl->setTargetScript('ilias.php');
1846  $ilCtrl->redirectByClass(['ildashboardgui', 'ilpersonalsettingsgui'], 'deleteOwnAccountStep2');
1847  }
1848  exit('This account is not flagged for deletion.'); // #12160
1849  }
1850 
1851  // badges
1852  if (substr($a_target, -4) == '_bdg') {
1853  $ilCtrl->redirectByClass('ilDashboardGUI', 'jumpToBadges');
1854  }
1855 
1856  if ('registration' == $a_target) {
1857  $ilCtrl->redirectByClass(['ilStartUpGUI', 'ilAccountRegistrationGUI'], '');
1858  } elseif ('nameassist' == $a_target) {
1859  $ilCtrl->redirectByClass(['ilStartUpGUI', 'ilPasswordAssistanceGUI'], 'showUsernameAssistanceForm');
1860  } elseif ('pwassist' == $a_target) {
1861  $ilCtrl->redirectByClass(['ilStartUpGUI', 'ilPasswordAssistanceGUI'], '');
1862  } else {
1863  $target = $DIC['legalDocuments']->findGotoLink($a_target);
1864  if ($target->isOK()) {
1865  $ilCtrl->setTargetScript('ilias.php');
1866  foreach ($target->value()->queryParams() as $key => $value) {
1867  $ilCtrl->setParameterByClass($target->value()->guiName(), (string) $key, $value);
1868  }
1869  $ilCtrl->redirectByClass($target->value()->guiPath(), $target->value()->command());
1870  }
1871  }
1872 
1873  if (strpos($a_target, 'n') === 0) {
1874  $a_target = ilObjUser::_lookupId(ilUtil::stripSlashes(substr($a_target, 1)));
1875  }
1876 
1877  $target_user = 0;
1878  $target_cmd = '';
1879  if (is_numeric($a_target)) {
1880  $target_user = (int) $a_target;
1881  } elseif ($target_array = explode('_', $a_target, 3)) {
1882  $target_cmd = $target_array[2];
1883  $target_user = (int) $target_array[0];
1884  }
1885 
1886  if ($target_user > 0) {
1887  $ilCtrl->setParameterByClass(ilPublicUserProfileGUI::class, 'user_id', $target_user);
1888  }
1889 
1890  $cmd = 'view';
1891  if ($target_cmd === 'contact_approved') {
1892  $cmd = 'approveContactRequest';
1893  } elseif ($target_cmd === 'contact_ignored') {
1894  $cmd = 'ignoreContactRequest';
1895  }
1896  $ilCtrl->redirectByClass([ilPublicUserProfileGUI::class], $cmd);
1897  }
1898 
1903  protected function handleIgnoredRequiredFields(): bool
1904  {
1905  $profile_maybe_incomplete = false;
1906 
1907  foreach ($this->user_profile->getIgnorableRequiredSettings() as $fieldName) {
1908  $elm = $this->form_gui->getItemByPostVar($fieldName);
1909 
1910  if (!$elm) {
1911  continue;
1912  }
1913 
1914  if ($elm->getRequired()) {
1915  $profile_maybe_incomplete = true;
1916 
1917  // Flag as optional
1918  $elm->setRequired(false);
1919  }
1920  }
1921 
1922  $user_defined_fields = ilUserDefinedFields::_getInstance();
1923  foreach ($user_defined_fields->getDefinitions() as $definition) {
1924  $elm = $this->form_gui->getItemByPostVar('udf_' . $definition['field_id']);
1925 
1926  if (!$elm) {
1927  continue;
1928  }
1929 
1930  if ($elm->getRequired() && $definition['required']) {
1931  $profile_maybe_incomplete = true;
1932 
1933  // Flag as optional
1934  $elm->setRequired(false);
1935  }
1936  }
1937 
1938  return $profile_maybe_incomplete;
1939  }
1940 
1941  private function checkUserWriteRight(): void
1942  {
1943  if ($this->usrf_ref_id === USER_FOLDER_ID
1944  && (
1945  !$this->rbac_system->checkAccess('visible,read', $this->usrf_ref_id)
1946  || !$this->rbac_system->checkAccess('write', $this->usrf_ref_id)
1947  && (
1948  !$this->access->checkPositionAccess(\ilObjUserFolder::ORG_OP_EDIT_USER_ACCOUNTS, $this->usrf_ref_id)
1949  || $this->access->checkPositionAccess(\ilObjUserFolder::ORG_OP_EDIT_USER_ACCOUNTS, $this->usrf_ref_id)
1950  && !in_array(
1951  $this->object->getId(),
1952  $this->access->filterUserIdsByPositionOfCurrentUser(
1955  [$this->object->getId()]
1956  )
1957  )
1958  )
1959  )
1960  ) {
1961  $this->ilias->raiseError($this->lng->txt('msg_no_perm_modify_user'), $this->ilias->error_obj->MESSAGE);
1962  }
1963 
1964  // if called from local administration $this->usrf_ref_id is category id
1965  // Todo: this has to be fixed. Do not mix user folder id and category id
1966  if ($this->usrf_ref_id != USER_FOLDER_ID
1967  && !$this->rbac_system->checkAccess('cat_administrate_users', $this->object->getTimeLimitOwner())) {
1968  $this->ilias->raiseError($this->lng->txt('msg_no_perm_modify_user'), $this->ilias->error_obj->MESSAGE);
1969  }
1970  }
1971 
1972  private function renderForm(): void
1973  {
1974  $this->tpl->setContent($this->legal_documents->userManagementModals() . $this->form_gui->getHTML());
1975  }
1976 
1977  private function checkAccessToRolesTab(): bool
1978  {
1979  return $this->object->getId() !== (int) ANONYMOUS_USER_ID
1980  && (
1981  $this->rbac_system->checkAccess('edit_roleassignment', $this->usrf_ref_id)
1982  || $this->access->checkPositionAccess(\ilObjUserFolder::ORG_OP_EDIT_USER_ACCOUNTS, $this->usrf_ref_id)
1983  && in_array(
1984  $this->object->getId(),
1985  $this->access->filterUserIdsByPositionOfCurrentUser(
1988  [$this->object->getId()]
1989  )
1990  )
1991  );
1992  }
1993 }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
setUTitle(string $a_str)
set user title (note: don&#39;t mix up this method with setTitle() that is derived from ilObject and sets...
string $default_layout_and_style
static get(string $a_var)
ilMailMimeSenderFactory $mail_sender_factory
setTimeLimitUnlimited(bool $a_unlimited)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setClientIP(string $a_str)
ilUserDefinedFields $user_defined_fields
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
createObject()
Display user create form.
const IL_CAL_DATETIME
const ANONYMOUS_USER_ID
Definition: constants.php:27
const USER_FOLDER_ID
Definition: constants.php:33
static getAuthModeTranslation(string $a_auth_key, string $auth_name='')
static _getAuthMode(?string $a_auth_mode)
string $requested_baseClass
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...
UserGUIRequest $user_request
handleIgnoredRequiredFields()
Handles ignored required fields by changing the required flag of form elements.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setMatriculation(string $a_str)
Additional user data fields definition.
prepareOutput(bool $show_sub_objects=true)
setPhoneOffice(string $a_str)
const SYSTEM_ROLE_ID
Definition: constants.php:29
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
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.
setSelectedCountry(string $a_val)
Set selected country (selection drop down)
setFullname()
builds a string with title + firstname + lastname method is used to build fullname in member variable...
const PASSWD_PLAIN
loadUserDefinedDataFromForm(?ilObjUser $user=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilUserProfile.
FileUpload $uploads
initForm(string $a_mode)
Init user form.
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
static _lookupId($a_user_str)
addAdminLocatorItems(bool $do_not_add_object=false)
should be overwritten to add object specific items (repository items are preloaded) ...
setOptions(array $a_options)
static _getActiveAuthModes()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static prepareFormOutput($a_str, bool $a_strip=false)
const IL_CAL_UNIX
Class ilObjectOwnershipManagementGUI.
setTimeLimitUntil(?int $a_until)
static _getAuthModeName($a_auth_key)
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
isSettingChangeable(string $a_field)
uploadUserPicture()
upload user image (original method by ratana ty)
setInstitution(string $a_str)
setCity(string $a_str)
const SYSTEM_FOLDER_ID
Definition: constants.php:35
setBackTarget(string $a_text, string $a_link)
set back tab target
setLatitude(?string $a_latitude)
setComment(string $a_str)
setGender(string $a_str)
static _allowPasswordModificationByAuthMode($a_auth_mode)
Allow password modification.
This class represents a date/time property in a property form.
static _lookupObjId(int $ref_id)
setExternalAccount(string $a_str)
catch(\Exception $e) $req
Definition: xapiproxy.php:78
setBirthday(?string $a_birthday)
static _getLastHistoryDataByUserId(int $a_usr_id)
Returns the last used loginname and the changedate of the passed user_id.
setLogin(string $a_str)
setActive(bool $a_active, int $a_owner=0)
set user active state and updates system fields appropriately
This class represents a property in a property form.
loadValuesFromForm(string $a_mode='create')
setDepartment(string $a_str)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setOfferingHelp(?array $value=null)
ResourceStakeholder $stakeholder
setPhoneHome(string $a_str)
__toUnix(array $a_time_arr)
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: shib_login.php:25
const UDF_TYPE_TEXT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Conductor $legal_documents
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjForumAdministration.
setHobby(string $a_str)
getResults()
Returns the results of the processing and moving operation of the uploaded files. ...
Class FileUpload.
Definition: FileUpload.php:34
setUseStripSlashes(bool $a_stat)
En/disable use of stripslashes.
static _isExternalAccountEnabled()
Check if an external account name is required.
setRequired(bool $a_required)
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
const ROLE_FOLDER_ID
Definition: constants.php:34
setCountry(string $a_str)
setEmail(string $a_str)
setFax(string $a_str)
setPhoneMobile(string $a_str)
setLastname(string $a_str)
static _getPersonalPicturePath(int $a_usr_id, string $a_size='small', bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
setStreet(string $a_str)
This class represents an image file property in a property form.
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
const IL_CAL_DATE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
setTimeLimitOwner(int $a_owner)
This class represents a text area property in a property form.
saveObject()
save user data
Class ilAccountMail.
setSecondEmail(?string $second_email)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
updateObject()
updates object entry in object_data
setLongitude(?string $a_longitude)
setLocationZoom(?int $a_locationzoom)
This class represents a text property in a property form.
static yn2tf(string $a_yn)
setZipcode(string $a_str)
ilPropertyFormGUI $form_gui
setUserDefinedData(array $a_data)
static _getFrame(string $a_class)
Class ilObjUserGUI.
static _getAssignUsersStatus(int $a_role_id)
static _lookupType(int $id, bool $reference=false)
setGeneralInterests(?array $value=null)
setTimeLimitFrom(?int $a_from)
setFirstname(string $a_str)
static getSessionExpireValue()
Returns the session expiration value.
static clear(string $a_var)
ilSetting $settings
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static set(string $a_var, $a_val)
Set a value.
setAuthMode(?string $a_str)
ResourceStorageServices $irss
ilUserProfile $user_profile
__getDateSelect(string $a_type, string $a_varname, string $a_selected)
static _getInstallationSignature()
static _lookupLogin(int $a_user_id)
setLookingForHelp(?array $value=null)