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