ILIAS  release_8 Revision v8.24
class.ilObjUserGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 protected bool $update;
28 protected array $selectable_roles; // Missing array type.
29 protected int $default_role;
34 protected array $back_target;
36 protected \ILIAS\User\StandardGUIRequest $user_request;
37 protected int $usrf_ref_id;
41 public array $gender; // Missing array type.
42 public int $user_ref_id;
43 protected string $requested_letter = "";
44 protected string $requested_baseClass = "";
45 protected string $requested_search = "";
46
47 public function __construct(
48 $a_data,
49 int $a_id,
50 bool $a_call_by_reference = false,
51 bool $a_prepare_output = true,
52 ILIAS\UI\Factory $uiFactory = null,
53 ILIAS\UI\Renderer $uiRenderer = null
54 ) {
55 global $DIC;
56
57 if (null === $uiFactory) {
58 $uiFactory = $DIC->ui()->factory();
59 }
60 $this->uiFactory = $uiFactory;
61
62 if (null === $uiRenderer) {
63 $uiRenderer = $DIC->ui()->renderer();
64 }
65 $this->uiRenderer = $uiRenderer;
66
67 $ilCtrl = $DIC['ilCtrl'];
68 $lng = $DIC['lng'];
69
70 $this->type = "usr";
71 parent::__construct($a_data, $a_id, $a_call_by_reference, false);
72 $this->usrf_ref_id = $this->ref_id;
73
74 $this->ctrl = $ilCtrl;
75 $this->ctrl->saveParameter($this, array('obj_id', 'letter'));
76 $this->ctrl->setParameterByClass("ilobjuserfoldergui", "letter", $this->requested_letter);
77 //$this->ctrl->setContext($this->object->getId(), 'usr');
78 $lng->loadLanguageModule('user');
79
80 // for gender selection. don't change this
81 // maybe deprecated
82 $this->gender = array(
83 'n' => "salutation_n",
84 'm' => "salutation_m",
85 'f' => "salutation_f",
86 );
87
88 $this->user_request = new \ILIAS\User\StandardGUIRequest(
89 $DIC->http(),
90 $DIC->refinery()
91 );
92
93 $this->requested_letter = $this->user_request->getLetter();
94 $this->requested_baseClass = $this->user_request->getBaseClass();
95 $this->requested_search = $this->user_request->getSearch();
96 }
97
98 public function executeCommand(): void
99 {
100 $next_class = $this->ctrl->getNextClass($this);
101 $cmd = $this->ctrl->getCmd();
102
103 $this->prepareOutput();
104
105 switch ($next_class) {
106 case "illearningprogressgui":
107 $new_gui = new ilLearningProgressGUI(
110 $this->object->getId()
111 );
112 $this->ctrl->forwardCommand($new_gui);
113 break;
114
115 case "ilobjectownershipmanagementgui":
116 $gui = new ilObjectOwnershipManagementGUI($this->object->getId());
117 $this->ctrl->forwardCommand($gui);
118 break;
119
120 default:
121 if ($cmd == "" || $cmd == "view") {
122 $cmd = "edit";
123 }
124 $cmd .= "Object";
125 $this->$cmd();
126 break;
127 }
128 }
129
130 protected function setTitleAndDescription(): void
131 {
132 if (strtolower(get_class($this->object)) == 'ilobjuser') {
133 $this->tpl->setTitle('[' . $this->object->getLogin() . '] ' . $this->object->getTitle());
134 $this->tpl->setDescription($this->object->getLongDescription());
135 $this->tpl->setTitleIcon(
136 ilUtil::getImagePath("icon_" . $this->object->getType() . ".svg"),
137 $this->lng->txt("obj_" . $this->object->getType())
138 );
139 } else {
140 parent::setTitleAndDescription();
141 }
142 }
143
144 public function cancelObject(): void
145 {
146 ilSession::clear("saved_post");
147
148 if (strtolower($this->requested_baseClass) == 'iladministrationgui') {
149 $this->ctrl->redirectByClass("ilobjuserfoldergui", "view");
150 } else {
151 $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
152 }
153 }
154
155 public function getAdminTabs(): void
156 {
157 $this->getTabs();
158 }
159
160 protected function getTabs(): void
161 {
162 global $DIC;
163
164 $rbacsystem = $DIC['rbacsystem'];
165 $ilHelp = $DIC['ilHelp'];
166
167 $this->tabs_gui->clearTargets();
168
169 $ilHelp->setScreenIdComponent("usr");
170
171 if ($this->requested_search) {
172 $this->tabs_gui->setBackTarget(
173 $this->lng->txt("search_results"),
174 ilSession::get("usr_search_link")
175 );
176
177 $this->tabs_gui->addTarget(
178 "properties",
179 $this->ctrl->getLinkTarget($this, "edit"),
180 array("edit", "", "view"),
181 get_class($this),
182 "",
183 true
184 );
185 } else {
186 $this->tabs_gui->addTarget(
187 "properties",
188 $this->ctrl->getLinkTarget($this, "edit"),
189 array("edit", "", "view"),
190 get_class($this)
191 );
192 }
193
194 $this->tabs_gui->addTarget(
195 "role_assignment",
196 $this->ctrl->getLinkTarget($this, "roleassignment"),
197 array("roleassignment"),
198 get_class($this)
199 );
200
201 // learning progress
202 if ($rbacsystem->checkAccess('read', $this->ref_id) and
205 $this->tabs_gui->addTarget(
206 'learning_progress',
207 $this->ctrl->getLinkTargetByClass('illearningprogressgui', ''),
208 '',
209 array('illplistofobjectsgui', 'illplistofsettingsgui', 'illearningprogressgui', 'illplistofprogressgui')
210 );
211 }
212
213 $this->tabs_gui->addTarget(
214 'user_ownership',
215 $this->ctrl->getLinkTargetByClass('ilobjectownershipmanagementgui', ''),
216 '',
217 'ilobjectownershipmanagementgui'
218 );
219 }
220
224 public function setBackTarget(
225 string $a_text,
226 string $a_link
227 ): void {
228 $this->back_target = array("text" => $a_text,
229 "link" => $a_link
230 );
231 }
232
233 public function __checkUserDefinedRequiredFields(): bool
234 {
235 $this->user_defined_fields = ilUserDefinedFields::_getInstance();
236
237 $udfs = $this->user_request->getUDFs();
238 foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
239 if ($definition['required'] and !strlen($udfs[$field_id])) {
240 return false;
241 }
242 }
243 return true;
244 }
245
246 public function __showUserDefinedFields(): void
247 {
248 $user_defined_data = null;
249 $this->user_defined_fields = ilUserDefinedFields::_getInstance();
250
251 if ($this->object->getType() == 'usr') {
252 $user_defined_data = $this->object->getUserDefinedData();
253 }
254 foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
255 $error_post_vars = ilSession::get("error_post_vars");
256 $old = $error_post_vars["udf"][$field_id] ?? $user_defined_data[$field_id];
257
258 if ($definition['field_type'] == UDF_TYPE_TEXT) {
259 $this->tpl->setCurrentBlock("field_text");
260 $this->tpl->setVariable("FIELD_NAME", 'udf[' . $definition['field_id'] . ']');
261 $this->tpl->setVariable("FIELD_VALUE", ilLegacyFormElementsUtil::prepareFormOutput($old));
262 } else {
263 $this->tpl->setCurrentBlock("field_select");
264 $this->tpl->setVariable(
265 "SELECT_BOX",
267 $old,
268 'udf[' . $definition['field_id'] . ']',
269 $this->user_defined_fields->fieldValuesToSelectArray(
270 $definition['field_values']
271 ),
272 false,
273 true
274 )
275 );
276 }
277 $this->tpl->parseCurrentBlock();
278 $this->tpl->setCurrentBlock("user_defined");
279
280 if ($definition['required']) {
281 $name = $definition['field_name'] . "<span class=\"asterisk\">*</span>";
282 } else {
283 $name = $definition['field_name'];
284 }
285 $this->tpl->setVariable("TXT_FIELD_NAME", $name);
286 $this->tpl->parseCurrentBlock();
287 }
288 }
289
290 public function initCreate(): void
291 {
292 global $DIC;
293
294 $rbacreview = $DIC['rbacreview'];
295 $ilUser = $DIC['ilUser'];
296
297 if ($this->usrf_ref_id != USER_FOLDER_ID) {
298 $this->tabs_gui->clearTargets();
299 }
300
301 // role selection
302 $obj_list = $rbacreview->getRoleListByObject(ROLE_FOLDER_ID);
303 $rol = array();
304 foreach ($obj_list as $obj_data) {
305 // allow only 'assign_users' marked roles if called from category
306 if ($this->object->getRefId() != USER_FOLDER_ID and !in_array(
308 $rbacreview->assignedRoles($ilUser->getId())
309 )) {
310 if (!ilObjRole::_getAssignUsersStatus($obj_data['obj_id'])) {
311 continue;
312 }
313 }
314 // exclude anonymous role from list
315 if ($obj_data["obj_id"] != ANONYMOUS_ROLE_ID) {
316 // do not allow to assign users to administrator role if current user does not has SYSTEM_ROLE_ID
317 if ($obj_data["obj_id"] != SYSTEM_ROLE_ID or in_array(
319 $rbacreview->assignedRoles($ilUser->getId())
320 )) {
321 $rol[$obj_data["obj_id"]] = $obj_data["title"];
322 }
323 }
324 }
325
326 // raise error if there is no global role user can be assigned to
327 if (!count($rol)) {
328 $this->ilias->raiseError(
329 $this->lng->txt("msg_no_roles_users_can_be_assigned_to"),
330 $this->ilias->error_obj->MESSAGE
331 );
332 }
333
334 $keys = array_keys($rol);
335
336 // set pre defined user role to default
337 if (in_array(4, $keys)) {
338 $this->default_role = 4;
339 } else {
340 if (count($keys) > 1 and in_array(2, $keys)) {
341 // remove admin role as preselectable role
342 foreach ($keys as $key => $val) {
343 if ($val == 2) {
344 unset($keys[$key]);
345 break;
346 }
347 }
348 }
349
350 $this->default_role = array_shift($keys);
351 }
352 $this->selectable_roles = $rol;
353 }
354
358 public function createObject(): void
359 {
360 global $DIC;
361
362 $tpl = $DIC['tpl'];
363 $rbacsystem = $DIC['rbacsystem'];
364
365 if (!$rbacsystem->checkAccess('create_usr', $this->usrf_ref_id)
366 && !$rbacsystem->checkAccess('cat_administrate_users', $this->usrf_ref_id)) {
367 $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
368 }
369
370 $this->initCreate();
371 $this->initForm("create");
372 $tpl->setContent($this->form_gui->getHTML());
373 }
374
378 public function saveObject(): void
379 {
380 global $DIC;
381
382 $ilAccess = $DIC['ilAccess'];
383 $ilSetting = $DIC['ilSetting'];
384 $tpl = $DIC['tpl'];
385 $ilUser = $DIC['ilUser'];
386 $rbacadmin = $DIC['rbacadmin'];
387 $rbacsystem = $DIC['rbacsystem'];
388
389 // User folder
390 if (!$rbacsystem->checkAccess('create_usr', $this->usrf_ref_id)
391 && !$ilAccess->checkAccess('cat_administrate_users', "", $this->usrf_ref_id)) {
392 $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
393 }
394
395 $this->initCreate();
396 $this->initForm("create");
397
398 // Manipulate form so ignore required fields are no more required. This has to be done before ilPropertyFormGUI::checkInput() is called.
399 $profileMaybeIncomplete = false;
400 if ($this->form_gui->getInput('ignore_rf', false)) {
401 $profileMaybeIncomplete = $this->handleIgnoredRequiredFields();
402 }
403
404 if ($this->form_gui->checkInput()) {
405 // @todo: external account; time limit check and savings
406
407 // checks passed. save user
408 $userObj = $this->loadValuesFromForm();
409 if ($this->user->getId() === (int) SYSTEM_USER_ID
410 || !in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->object->getId()))
411 || in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->user->getId()))) {
412 $userObj->setPasswd($this->form_gui->getInput('passwd'), ilObjUser::PASSWD_PLAIN);
413 }
414 $userObj->setTitle($userObj->getFullname());
415 $userObj->setDescription($userObj->getEmail());
416
417 $this->loadUserDefinedDataFromForm($userObj);
418
419 $userObj->create();
420
422 $userObj->setExternalAccount($this->form_gui->getInput("ext_account"));
423 }
424
425 // set a timestamp for last_password_change
426 // this ts is needed by ilSecuritySettings
427 $userObj->setLastPasswordChangeTS(time());
428
429 //insert user data in table user_data
430 $userObj->saveAsNew();
431
432 // setup user preferences
433 if ($this->isSettingChangeable('language')) {
434 $userObj->setLanguage($this->form_gui->getInput("language"));
435 }
436
437 if ($this->isSettingChangeable('skin_style')) {
438 //set user skin and style
439 $sknst = explode(":", $this->form_gui->getInput("skin_style"));
440
441 if ($userObj->getPref("style") != $sknst[1] ||
442 $userObj->getPref("skin") != $sknst[0]) {
443 $userObj->setPref("skin", $sknst[0]);
444 $userObj->setPref("style", $sknst[1]);
445 }
446 }
447 if ($this->isSettingChangeable('hits_per_page')) {
448 $userObj->setPref("hits_per_page", $this->form_gui->getInput("hits_per_page"));
449 }
450 if ($this->isSettingChangeable('hide_own_online_status')) {
451 $userObj->setPref(
452 "hide_own_online_status",
453 $this->form_gui->getInput("hide_own_online_status")
454 );
455 }
456 if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
457 $userObj->setPref(
458 'bs_allow_to_contact_me',
459 $this->form_gui->getInput("bs_allow_to_contact_me") ? 'y' : 'n'
460 );
461 }
462 if ($this->isSettingChangeable('chat_osc_accept_msg')) {
463 $userObj->setPref(
464 'chat_osc_accept_msg',
465 $this->form_gui->getInput("chat_osc_accept_msg") ? 'y' : 'n'
466 );
467 }
468 if ($this->isSettingChangeable('chat_broadcast_typing')) {
469 $userObj->setPref(
470 'chat_broadcast_typing',
471 $this->form_gui->getInput("chat_broadcast_typing") ? 'y' : 'n'
472 );
473 }
474 if ((int) $ilSetting->get('session_reminder_enabled')) {
475 $userObj->setPref(
476 'session_reminder_enabled',
477 (int) $this->form_gui->getInput("session_reminder_enabled")
478 );
479 }
480 $userObj->writePrefs();
481
482 //set role entries
483 $rbacadmin->assignUser(
484 $this->form_gui->getInput("default_role"),
485 $userObj->getId(),
486 true
487 );
488
489 $msg = $this->lng->txt("user_added");
490
491 $ilUser->setPref(
492 'send_info_mails',
493 ($this->form_gui->getInput("send_mail") == 'y') ? 'y' : 'n'
494 );
495 $ilUser->writePrefs();
496
497 $this->object = $userObj;
498
499 if ($this->isSettingChangeable('upload')) {
500 $this->uploadUserPictureObject();
501 }
502
503 if ($profileMaybeIncomplete) {
504 if (ilUserProfile::isProfileIncomplete($this->object)) {
505 $this->object->setProfileIncomplete(true);
506 $this->object->update();
507 }
508 }
509
510 // send new account mail
511 if ($this->form_gui->getInput("send_mail") == 'y') {
512 $acc_mail = new ilAccountMail();
513 $acc_mail->useLangVariablesAsFallback(true);
514 $acc_mail->setAttachConfiguredFiles(true);
515 $acc_mail->setUserPassword($this->form_gui->getInput("passwd"));
516 $acc_mail->setUser($userObj);
517
518 if ($acc_mail->send()) {
519 $msg .= '<br />' . $this->lng->txt('mail_sent');
520 $this->tpl->setOnScreenMessage('success', $msg, true);
521 } else {
522 $msg .= '<br />' . $this->lng->txt('mail_not_sent');
523 $this->tpl->setOnScreenMessage('info', $msg, true);
524 }
525 } else {
526 $this->tpl->setOnScreenMessage('success', $msg, true);
527 }
528
529 if (strtolower($this->requested_baseClass) == 'iladministrationgui') {
530 $this->ctrl->redirectByClass("ilobjuserfoldergui", "view");
531 } else {
532 $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
533 }
534 } else {
535 $this->form_gui->setValuesByPost();
536 $tpl->setContent($this->form_gui->getHTML());
537 }
538 }
539
543 public function editObject(): void
544 {
545 $this->checkUserWriteRight();
546
547 if ($this->usrf_ref_id != USER_FOLDER_ID) {
548 $this->tabs_gui->clearTargets();
549 }
550
551 // get form
552 $this->initForm("edit");
553 $this->getValues();
554 $this->showAcceptedTermsOfService();
555 $this->tpl->setContent($this->form_gui->getHTML());
556 }
557
558 protected function loadValuesFromForm(string $a_mode = 'create'): ilObjUser
559 {
560 global $DIC;
561
562 $user = null;
563 $ilUser = $DIC['ilUser'];
564
565 switch ($a_mode) {
566 case 'create':
567 $user = new ilObjUser();
568 break;
569
570 case 'update':
571 $user = $this->object;
572 break;
573 }
574
575 $from = $this->form_gui->getItemByPostVar('time_limit_from')->getDate();
576 $user->setTimeLimitFrom($from
577 ? $from->get(IL_CAL_UNIX)
578 : null);
579
580 $until = $this->form_gui->getItemByPostVar('time_limit_until')->getDate();
581 $user->setTimeLimitUntil($until
582 ? $until->get(IL_CAL_UNIX)
583 : null);
584
585 $user->setTimeLimitUnlimited($this->form_gui->getInput('time_limit_unlimited'));
586
587 if ($a_mode == 'create') {
588 $user->setTimeLimitOwner($this->usrf_ref_id);
589 }
590
591 // Birthday
592 if ($this->isSettingChangeable('birthday')) {
593 $bd = $this->form_gui->getItemByPostVar('birthday');
594 $bd = $bd->getDate();
595 $user->setBirthday($bd
596 ? $bd->get(IL_CAL_DATE)
597 : null);
598 }
599
600 // Login
601 $user->setLogin($this->form_gui->getInput('login'));
602
603 // Gender
604 if ($this->isSettingChangeable('gender')) {
605 $user->setGender($this->form_gui->getInput('gender'));
606 }
607
608 // Title
609 if ($this->isSettingChangeable('title')) {
610 $user->setUTitle($this->form_gui->getInput('title'));
611 }
612
613 // Firstname
614 if ($this->isSettingChangeable('firstname')) {
615 $user->setFirstname($this->form_gui->getInput('firstname'));
616 }
617 // Lastname
618 if ($this->isSettingChangeable('lastname')) {
619 $user->setLastname($this->form_gui->getInput('lastname'));
620 }
621 $user->setFullname();
622
623 // Institution
624 if ($this->isSettingChangeable('institution')) {
625 $user->setInstitution($this->form_gui->getInput('institution'));
626 }
627
628 // Department
629 if ($this->isSettingChangeable('department')) {
630 $user->setDepartment($this->form_gui->getInput('department'));
631 }
632 // Street
633 if ($this->isSettingChangeable('street')) {
634 $user->setStreet($this->form_gui->getInput('street'));
635 }
636 // City
637 if ($this->isSettingChangeable('city')) {
638 $user->setCity($this->form_gui->getInput('city'));
639 }
640 // Zipcode
641 if ($this->isSettingChangeable('zipcode')) {
642 $user->setZipcode($this->form_gui->getInput('zipcode'));
643 }
644 // Country
645 if ($this->isSettingChangeable('country')) {
646 $user->setCountry($this->form_gui->getInput('country'));
647 }
648 // Selected Country
649 if ($this->isSettingChangeable('sel_country')) {
650 $user->setSelectedCountry($this->form_gui->getInput('sel_country'));
651 }
652 // Phone Office
653 if ($this->isSettingChangeable('phone_office')) {
654 $user->setPhoneOffice($this->form_gui->getInput('phone_office'));
655 }
656 // Phone Home
657 if ($this->isSettingChangeable('phone_home')) {
658 $user->setPhoneHome($this->form_gui->getInput('phone_home'));
659 }
660 // Phone Mobile
661 if ($this->isSettingChangeable('phone_mobile')) {
662 $user->setPhoneMobile($this->form_gui->getInput('phone_mobile'));
663 }
664 // Fax
665 if ($this->isSettingChangeable('fax')) {
666 $user->setFax($this->form_gui->getInput('fax'));
667 }
668 // Matriculation
669 if ($this->isSettingChangeable('matriculation')) {
670 $user->setMatriculation($this->form_gui->getInput('matriculation'));
671 }
672 // Email
673 if ($this->isSettingChangeable('email')) {
674 $user->setEmail($this->form_gui->getInput('email'));
675 }
676 // Second Email
677 if ($this->isSettingChangeable('second_email')) {
678 $user->setSecondEmail($this->form_gui->getInput('second_email'));
679 }
680 // Hobby
681 if ($this->isSettingChangeable('hobby')) {
682 $user->setHobby($this->form_gui->getInput('hobby'));
683 }
684 // Referral Comment
685 if ($this->isSettingChangeable('referral_comment')) {
686 $user->setComment($this->form_gui->getInput('referral_comment'));
687 }
688
689 $general_interests = is_array($this->form_gui->getInput('interests_general'))
690 ? $this->form_gui->getInput('interests_general')
691 : [];
692 $user->setGeneralInterests($general_interests);
693
694 $offering_help = is_array($this->form_gui->getInput('interests_help_offered'))
695 ? $this->form_gui->getInput('interests_help_offered')
696 : [];
697 $user->setOfferingHelp($offering_help);
698
699 $looking_for_help = is_array($this->form_gui->getInput('interests_help_looking'))
700 ? $this->form_gui->getInput('interests_help_looking')
701 : [];
702 $user->setLookingForHelp($looking_for_help);
703
704 // ClientIP
705 $user->setClientIP($this->form_gui->getInput('client_ip'));
706
707 // Google maps
708 $user->setLatitude($this->form_gui->getInput('latitude'));
709 $user->setLongitude($this->form_gui->getInput('longitude'));
710 $zoom = (int) $this->form_gui->getInput('loc_zoom');
711 if ($zoom == 0) {
712 $zoom = null;
713 }
714 $user->setLocationZoom($zoom);
715
716 // External account
717 $user->setAuthMode($this->form_gui->getInput('auth_mode'));
718 $user->setExternalAccount($this->form_gui->getInput('ext_account'));
719
720 if ((int) $user->getActive() != (int) $this->form_gui->getInput('active')) {
721 $user->setActive($this->form_gui->getInput('active'), $ilUser->getId());
722 }
723
724 return $user;
725 }
726
727 protected function loadUserDefinedDataFromForm(?ilObjUser $user = null): void
728 {
729 if (!$user) {
730 $user = $this->object;
731 }
732
733 $user_defined_fields = ilUserDefinedFields::_getInstance();
734 if ($this->usrf_ref_id == USER_FOLDER_ID) {
735 $all_defs = $user_defined_fields->getDefinitions();
736 } else {
737 $all_defs = $user_defined_fields->getChangeableLocalUserAdministrationDefinitions();
738 }
739 $udf = [];
740 foreach ($all_defs as $definition) {
741 $f = "udf_" . $definition['field_id'];
742 $item = $this->form_gui->getItemByPostVar($f);
743 if ($item && !$item->getDisabled()) {
744 $udf[$definition['field_id']] = $this->form_gui->getInput($f);
745 }
746 }
747 $user->setUserDefinedData($udf);
748 }
749
750 public function updateObject(): void
751 {
752 $this->checkUserWriteRight();
753 $this->initForm('edit');
754
755 // Manipulate form so ignore required fields are no more required. This has to be done before ilPropertyFormGUI::checkInput() is called.
756 $profileMaybeIncomplete = false;
757 if ($this->form_gui->getInput('ignore_rf', false)) {
758 $profileMaybeIncomplete = $this->handleIgnoredRequiredFields();
759 }
760
761 if ($this->form_gui->checkInput()) {
762 // @todo: external account; time limit
763 // if not allowed or empty -> do no change password
765 ilAuthUtils::_getAuthMode($this->form_gui->getInput('auth_mode'))
766 ) && trim($this->form_gui->getInput('passwd')) !== ''
767 && ($this->user->getId() === (int) SYSTEM_USER_ID
768 || !in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->object->getId()))
769 || in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->user->getId())))
770 ) {
771 $this->object->setPasswd($this->form_gui->getInput('passwd'), ilObjUser::PASSWD_PLAIN);
772 }
773
774 /*
775 * reset counter for failed logins
776 */
777 if ((int) $this->form_gui->getInput("active") == 1) {
778 $this->object->setLoginAttempts(0);
779 }
780
781 #$this->object->assignData($_POST);
782 $this->loadValuesFromForm('update');
783
784 $this->loadUserDefinedDataFromForm();
785
786 try {
787 $this->object->updateLogin($this->form_gui->getInput("login"));
788 } catch (ilUserException $e) {
789 $this->tpl->setOnScreenMessage('failure', $e->getMessage());
790 $this->form_gui->setValuesByPost();
791 $this->tpl->setContent($this->form_gui->getHTML());
792 return;
793 }
794
795 $this->object->setTitle($this->object->getFullname());
796 $this->object->setDescription($this->object->getEmail());
797
798 if ($this->isSettingChangeable('language')) {
799 $this->object->setLanguage($this->form_gui->getInput('language'));
800 }
801
802 if ($this->isSettingChangeable('skin_style')) {
803 //set user skin and style
804 $sknst = explode(":", $this->form_gui->getInput("skin_style"));
805
806 if ($this->object->getPref("style") != $sknst[1] ||
807 $this->object->getPref("skin") != $sknst[0]) {
808 $this->object->setPref("skin", $sknst[0]);
809 $this->object->setPref("style", $sknst[1]);
810 }
811 }
812 if ($this->isSettingChangeable('hits_per_page')) {
813 $this->object->setPref("hits_per_page", $this->form_gui->getInput("hits_per_page"));
814 }
815 if ($this->isSettingChangeable('hide_own_online_status')) {
816 $this->object->setPref(
817 "hide_own_online_status",
818 ($this->form_gui->getInput("hide_own_online_status") ?? false)
819 );
820 }
821 if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
822 $this->object->setPref(
823 'bs_allow_to_contact_me',
824 ($this->form_gui->getInput("bs_allow_to_contact_me") ?? false) ? 'y' : 'n'
825 );
826 }
827 if ($this->isSettingChangeable('chat_osc_accept_msg')) {
828 $this->object->setPref(
829 'chat_osc_accept_msg',
830 ($this->form_gui->getInput("chat_osc_accept_msg") ?? false) ? 'y' : 'n'
831 );
832 }
833 if ($this->isSettingChangeable('chat_broadcast_typing')) {
834 $this->object->setPref(
835 'chat_broadcast_typing',
836 ($this->form_gui->getInput("chat_broadcast_typing") ?? false) ? 'y' : 'n'
837 );
838 }
839
840 // set a timestamp for last_password_change
841 // this ts is needed by ilSecuritySettings
842 $this->object->setLastPasswordChangeTS(time());
843
844 global $DIC;
845
846 $ilSetting = $DIC['ilSetting'];
847 if ((int) $ilSetting->get('session_reminder_enabled')) {
848 $this->object->setPref(
849 'session_reminder_enabled',
850 (int) $this->form_gui->getInput("session_reminder_enabled")
851 );
852 }
853
854 // #10054 - profile may have been completed, check below is only for incomplete
855 $this->object->setProfileIncomplete(false);
856
857 $this->update = $this->object->update();
858
859 // If the current user is editing its own user account,
860 // we update his preferences.
861 if ($this->user->getId() == $this->object->getId()) {
862 $this->user->readPrefs();
863 }
864 $this->user->setPref(
865 'send_info_mails',
866 ($this->form_gui->getInput("send_mail") == 'y') ? 'y' : 'n'
867 );
868 $this->user->writePrefs();
869
870 $mail_message = $this->__sendProfileMail();
871 $msg = $this->lng->txt('saved_successfully') . $mail_message;
872
873 // same personal image
874 if ($this->isSettingChangeable('upload')) {
875 $this->uploadUserPictureObject();
876 }
877
878 if ($profileMaybeIncomplete) {
880 $user = $this->object;
882 $this->object->setProfileIncomplete(true);
883 $this->object->update();
884 }
885 }
886
887 // feedback
888 $this->tpl->setOnScreenMessage('success', $msg, true);
889
890 if (strtolower($this->requested_baseClass) == 'iladministrationgui') {
891 $this->ctrl->redirectByClass("ilobjuserfoldergui", "view");
892 } else {
893 $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
894 }
895 } else {
896 $this->form_gui->setValuesByPost();
897 $this->tabs_gui->activateTab('properties');
898 $this->tpl->setContent($this->form_gui->getHtml());
899 }
900 }
901
905 public function getValues(): void
906 {
907 $data = array();
908
909 // login data
910 $data["auth_mode"] = $this->object->getAuthMode();
911 $data["login"] = $this->object->getLogin();
912 //$data["passwd"] = "********";
913 //$data["passwd2"] = "********";
914 $data["ext_account"] = $this->object->getExternalAccount();
915
916 // system information
918 $this->object->getCreateDate(),
920 ));
921 $data["owner"] = ilObjUser::_lookupLogin($this->object->getOwner());
922 $data["approve_date"] = ($this->object->getApproveDate() != "")
923 ? ilDatePresentation::formatDate(new ilDateTime($this->object->getApproveDate(), IL_CAL_DATETIME))
924 : null;
925 $data["agree_date"] = ($this->object->getAgreeDate() != "")
927 : null;
928 $data["last_login"] = ($this->object->getLastLogin() != "")
930 : null;
931 $data["active"] = $this->object->getActive();
932 $data["time_limit_unlimited"] = $this->object->getTimeLimitUnlimited() ? '1' : '0';
933
934 $data["time_limit_from"] = $this->object->getTimeLimitFrom()
935 ? new ilDateTime($this->object->getTimeLimitFrom(), IL_CAL_UNIX)
936 : null;
937 $data["time_limit_until"] = $this->object->getTimeLimitUntil()
938 ? new ilDateTime($this->object->getTimeLimitUntil(), IL_CAL_UNIX)
939 : null;
940
941 // personal data
942 $data["gender"] = $this->object->getGender();
943 $data["firstname"] = $this->object->getFirstname();
944 $data["lastname"] = $this->object->getLastname();
945 $data["title"] = $this->object->getUTitle();
946 $data['birthday'] = $this->object->getBirthday()
947 ? new ilDate($this->object->getBirthday(), IL_CAL_DATE)
948 : null;
949 $data["institution"] = $this->object->getInstitution();
950 $data["department"] = $this->object->getDepartment();
951 $data["street"] = $this->object->getStreet();
952 $data["city"] = $this->object->getCity();
953 $data["zipcode"] = $this->object->getZipcode();
954 $data["country"] = $this->object->getCountry();
955 $data["sel_country"] = $this->object->getSelectedCountry();
956 $data["phone_office"] = $this->object->getPhoneOffice();
957 $data["phone_home"] = $this->object->getPhoneHome();
958 $data["phone_mobile"] = $this->object->getPhoneMobile();
959 $data["fax"] = $this->object->getFax();
960 $data["email"] = $this->object->getEmail();
961 $data["second_email"] = $this->object->getSecondEmail();
962 $data["hobby"] = $this->object->getHobby();
963 $data["referral_comment"] = $this->object->getComment();
964
965 // interests
966 $data["interests_general"] = $this->object->getGeneralInterests();
967 $data["interests_help_offered"] = $this->object->getOfferingHelp();
968 $data["interests_help_looking"] = $this->object->getLookingForHelp();
969
970 // other data
971 $data["matriculation"] = $this->object->getMatriculation();
972 $data["client_ip"] = $this->object->getClientIP();
973
974 // user defined fields
975 $this->user_defined_fields = ilUserDefinedFields::_getInstance();
976 $user_defined_data = $this->object->getUserDefinedData();
977 foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
978 $data["udf_" . $field_id] = $user_defined_data["f_" . $field_id] ?? "";
979 }
980
981 // settings
982 $data["language"] = $this->object->getLanguage();
983 $data["skin_style"] = $this->object->skin . ":" . $this->object->prefs["style"];
984 $data["hits_per_page"] = $this->object->prefs["hits_per_page"] ?? "";
985 $data["hide_own_online_status"] = $this->object->prefs["hide_own_online_status"] ?? "";
986 $data['bs_allow_to_contact_me'] = ($this->object->prefs['bs_allow_to_contact_me'] ?? "") == 'y';
987 $data['chat_osc_accept_msg'] = ($this->object->prefs['chat_osc_accept_msg'] ?? "") == 'y';
988 $data['chat_broadcast_typing'] = ($this->object->prefs['chat_broadcast_typing'] ?? "") == 'y';
989 $data["session_reminder_enabled"] = (int) ($this->object->prefs["session_reminder_enabled"] ?? 0);
990
991 $data["send_mail"] = (($this->object->prefs['send_info_mails'] ?? "") == 'y');
992
993 $this->form_gui->setValuesByArray($data);
994 }
995
999 public function initForm(string $a_mode): void
1000 {
1001 global $DIC;
1002
1003 $lng = $DIC['lng'];
1004 $ilCtrl = $DIC['ilCtrl'];
1005 $ilSetting = $DIC['ilSetting'];
1006 $ilClientIniFile = $DIC['ilClientIniFile'];
1007 $ilUser = $DIC['ilUser'];
1008
1009 $settings = $ilSetting->getAll();
1010
1011 $this->form_gui = new ilPropertyFormGUI();
1012 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1013 if ($a_mode == "create") {
1014 $this->form_gui->setTitle($lng->txt("usr_new"));
1015 } else {
1016 $this->form_gui->setTitle($lng->txt("usr_edit"));
1017 }
1018
1019 // login data
1020 $sec_l = new ilFormSectionHeaderGUI();
1021 $sec_l->setTitle($lng->txt("login_data"));
1022 $this->form_gui->addItem($sec_l);
1023
1024 // authentication mode
1025 $active_auth_modes = ilAuthUtils::_getActiveAuthModes();
1026 $am = new ilSelectInputGUI($lng->txt("auth_mode"), "auth_mode");
1027 $option = array();
1028 foreach ($active_auth_modes as $auth_name => $auth_key) {
1029 if ($auth_name == 'default') {
1030 $name = $this->lng->txt('auth_' . $auth_name) . " (" . $this->lng->txt('auth_' . ilAuthUtils::_getAuthModeName($auth_key)) . ")";
1031 } else {
1032 // begin-patch ldap_multiple
1033 #$name = $this->lng->txt('auth_'.$auth_name);
1034 $name = ilAuthUtils::getAuthModeTranslation($auth_key, $auth_name);
1035 // end-patch ldap_multiple
1036 }
1037 $option[$auth_name] = $name;
1038 }
1039 $am->setOptions($option);
1040 $this->form_gui->addItem($am);
1041
1042 if ($a_mode == "edit") {
1043 $id = new ilNonEditableValueGUI($lng->txt("usr_id"), "id");
1044 $id->setValue($this->object->getId());
1045 $this->form_gui->addItem($id);
1046 }
1047
1048 // login
1049 $lo = new ilUserLoginInputGUI($lng->txt("login"), "login");
1050 $lo->setRequired(true);
1051 if ($a_mode == "edit") {
1052 $lo->setCurrentUserId($this->object->getId());
1053 try {
1054 $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->object->getId());
1055 $lo->setInfo(
1056 sprintf(
1057 $this->lng->txt('usr_loginname_history_info'),
1058 ilDatePresentation::formatDate(new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1059 $last_history_entry[0]
1060 )
1061 );
1062 } catch (ilUserException $e) {
1063 }
1064 }
1065
1066 $this->form_gui->addItem($lo);
1067
1068 if ($this->user->getId() === (int) SYSTEM_USER_ID
1069 || !in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->object->getId()))
1070 || in_array(SYSTEM_ROLE_ID, $this->rbac_review->assignedRoles($this->user->getId()))) {
1071
1072 // passwords
1073 // @todo: do not show passwords, if there is not a single auth, that
1074 // allows password setting
1075 $pw = new ilPasswordInputGUI($lng->txt("passwd"), "passwd");
1076 $pw->setUseStripSlashes(false);
1077 $pw->setSize(32);
1078 $pw->setMaxLength(80); // #17221
1079 $pw->setValidateAuthPost("auth_mode");
1080 if ($a_mode == "create") {
1081 $pw->setRequiredOnAuth(true);
1082 }
1084 $this->form_gui->addItem($pw);
1085 // @todo: invisible/hidden passwords
1086 }
1087
1088 // external account
1090 $ext = new ilTextInputGUI($lng->txt("user_ext_account"), "ext_account");
1091 $ext->setSize(40);
1092 $ext->setMaxLength(250);
1093 $ext->setInfo($lng->txt("user_ext_account_desc"));
1094 $this->form_gui->addItem($ext);
1095 }
1096
1097 // login data
1098 $sec_si = new ilFormSectionHeaderGUI();
1099 $sec_si->setTitle($this->lng->txt("system_information"));
1100 $this->form_gui->addItem($sec_si);
1101
1102 // create date, approve date, agreement date, last login
1103 if ($a_mode == "edit") {
1104 $sia = array("create_date", "approve_date", "agree_date", "last_login", "owner");
1105 foreach ($sia as $a) {
1106 $siai = new ilNonEditableValueGUI($lng->txt($a), $a);
1107 $this->form_gui->addItem($siai);
1108 }
1109 }
1110
1111 // active
1112 $ac = new ilCheckboxInputGUI($lng->txt("active"), "active");
1113 $ac->setChecked(true);
1114 $this->form_gui->addItem($ac);
1115
1116 // access @todo: get fields right (names change)
1117 $lng->loadLanguageModule('crs');
1118
1119 // access
1120 $radg = new ilRadioGroupInputGUI($lng->txt("time_limit"), "time_limit_unlimited");
1121 $radg->setValue(1);
1122 $radg->setRequired(true);
1123 $op1 = new ilRadioOption($lng->txt("user_access_unlimited"), '1');
1124 $radg->addOption($op1);
1125 $op2 = new ilRadioOption($lng->txt("user_access_limited"), '0');
1126 $radg->addOption($op2);
1127
1128 // access.from
1129 $acfrom = new ilDateTimeInputGUI($this->lng->txt("crs_from"), "time_limit_from");
1130 $acfrom->setRequired(true);
1131 $acfrom->setShowTime(true);
1132 $acfrom->setMinuteStepSize(1);
1133 $op2->addSubItem($acfrom);
1134
1135 // access.to
1136 $acto = new ilDateTimeInputGUI($this->lng->txt("crs_to"), "time_limit_until");
1137 $acto->setRequired(true);
1138 $acto->setShowTime(true);
1139 $acto->setMinuteStepSize(1);
1140 $op2->addSubItem($acto);
1141
1142 // $this->form_gui->addItem($ac);
1143 $this->form_gui->addItem($radg);
1144
1145 // personal data
1146 if (
1147 $this->isSettingChangeable('gender') or
1148 $this->isSettingChangeable('firstname') or
1149 $this->isSettingChangeable('lastname') or
1150 $this->isSettingChangeable('title') or
1151 $this->isSettingChangeable('personal_image') or
1152 $this->isSettingChangeable('birhtday')
1153 ) {
1154 $sec_pd = new ilFormSectionHeaderGUI();
1155 $sec_pd->setTitle($this->lng->txt("personal_data"));
1156 $this->form_gui->addItem($sec_pd);
1157 }
1158
1159 // gender
1160 if ($this->isSettingChangeable('gender')) {
1161 $gndr = new ilRadioGroupInputGUI($lng->txt("salutation"), "gender");
1162 $gndr->setRequired(isset($settings["require_gender"]) && $settings["require_gender"]);
1163 $neutral = new ilRadioOption($lng->txt("salutation_n"), "n");
1164 $gndr->addOption($neutral);
1165 $female = new ilRadioOption($lng->txt("salutation_f"), "f");
1166 $gndr->addOption($female);
1167 $male = new ilRadioOption($lng->txt("salutation_m"), "m");
1168 $gndr->addOption($male);
1169 $this->form_gui->addItem($gndr);
1170 }
1171
1172 // firstname, lastname, title
1173 $fields = [
1174 "firstname" => true,
1175 "lastname" => true,
1176 "title" => isset($settings["require_title"]) && $settings["require_title"]
1177 ];
1178 foreach ($fields as $field => $req) {
1179 $max_len = $field === 'title' ? 32 : 128;
1180 if ($this->isSettingChangeable($field)) {
1181 // #18795
1182 $caption = ($field == "title")
1183 ? "person_title"
1184 : $field;
1185 $inp = new ilTextInputGUI($lng->txt($caption), $field);
1186 $inp->setSize(32);
1187 $inp->setMaxLength($max_len);
1188 $inp->setRequired($req);
1189 $this->form_gui->addItem($inp);
1190 }
1191 }
1192
1193 // personal image
1194 if ($this->isSettingChangeable('upload')) {
1195 $pi = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile");
1196 if ($a_mode == "edit" || $a_mode == "upload") {
1198 $this->object->getId(),
1199 "small",
1200 true,
1201 true
1202 ));
1203 }
1204 $this->form_gui->addItem($pi);
1205 }
1206
1207 if ($this->isSettingChangeable('birthday')) {
1208 $birthday = new ilBirthdayInputGUI($lng->txt('birthday'), 'birthday');
1209 $birthday->setRequired(isset($settings["require_birthday"]) && $settings["require_birthday"]);
1210 $this->form_gui->addItem($birthday);
1211 }
1212
1213 // institution, department, street, city, zip code, country, phone office
1214 // phone home, phone mobile, fax, e-mail
1215 $fields = array(
1216 array("institution", 40, 80),
1217 array("department", 40, 80),
1218 array("street", 40, 40),
1219 array("city", 40, 40),
1220 array("zipcode", 10, 10),
1221 array("country", 40, 40),
1222 array("sel_country"),
1223 array("phone_office", 30, 30),
1224 array("phone_home", 30, 30),
1225 array("phone_mobile", 30, 30),
1226 array("fax", 30, 30)
1227 );
1228
1229 $counter = 0;
1230 foreach ($fields as $field) {
1231 if (!$counter++ and $this->isSettingChangeable($field[0])) {
1232 // contact data
1233 $sec_cd = new ilFormSectionHeaderGUI();
1234 $sec_cd->setTitle($this->lng->txt("contact_data"));
1235 $this->form_gui->addItem($sec_cd);
1236
1237 // org units
1238 if ($a_mode == "edit") {
1239 $orgus = new ilNonEditableValueGUI($lng->txt('objs_orgu'), 'org_units');
1240 $orgus->setValue($this->object->getOrgUnitsRepresentation());
1241 $this->form_gui->addItem($orgus);
1242 }
1243 }
1244 if ($this->isSettingChangeable($field[0])) {
1245 if ($field[0] != "sel_country") {
1246 $inp = new ilTextInputGUI($lng->txt($field[0]), $field[0]);
1247 $inp->setSize($field[1]);
1248 $inp->setMaxLength($field[2]);
1249 $inp->setRequired(isset($settings["require_" . $field[0]]) &&
1250 $settings["require_" . $field[0]]);
1251 $this->form_gui->addItem($inp);
1252 } else {
1253 // country selection
1254 $cs = new ilCountrySelectInputGUI($lng->txt($field[0]), $field[0]);
1255 $cs->setRequired(isset($settings["require_" . $field[0]]) &&
1256 $settings["require_" . $field[0]]);
1257 $this->form_gui->addItem($cs);
1258 }
1259 }
1260 }
1261
1262 // email
1263 if ($this->isSettingChangeable('email')) {
1264 $em = new ilEMailInputGUI($lng->txt("email"), "email");
1265 $em->setRequired(isset($settings["require_email"]) &&
1266 $settings["require_email"]);
1267 $em->setMaxLength(128);
1268 $this->form_gui->addItem($em);
1269 }
1270
1271 // second email
1272 if ($this->isSettingChangeable('second_email')) {
1273 $em = new ilEMailInputGUI($lng->txt("second_email"), "second_email");
1274
1275 $this->form_gui->addItem($em);
1276 }
1277
1278 // interests/hobbies
1279 if ($this->isSettingChangeable('hobby')) {
1280 $hob = new ilTextAreaInputGUI($lng->txt("hobby"), "hobby");
1281 $hob->setRows(3);
1282 $hob->setCols(40);
1283 $hob->setRequired(isset($settings["require_hobby"]) &&
1284 $settings["require_hobby"]);
1285 $this->form_gui->addItem($hob);
1286 }
1287
1288 // referral comment
1289 if ($this->isSettingChangeable('referral_comment')) {
1290 $rc = new ilTextAreaInputGUI($lng->txt("referral_comment"), "referral_comment");
1291 $rc->setRows(3);
1292 $rc->setCols(40);
1293 $rc->setRequired(isset($settings["require_referral_comment"]) &&
1294 $settings["require_referral_comment"]);
1295 $this->form_gui->addItem($rc);
1296 }
1297
1298 // interests
1299
1300 $sh = new ilFormSectionHeaderGUI();
1301 $sh->setTitle($lng->txt("interests"));
1302 $this->form_gui->addItem($sh);
1303
1304 $multi_fields = array("interests_general", "interests_help_offered", "interests_help_looking");
1305 foreach ($multi_fields as $multi_field) {
1306 if ($this->isSettingChangeable($multi_field)) {
1307 // see ilUserProfile
1308 $ti = new ilTextInputGUI($lng->txt($multi_field), $multi_field);
1309 $ti->setMulti(true);
1310 $ti->setMaxLength(40);
1311 $ti->setSize(40);
1312 $ti->setRequired(isset($settings["require_" . $multi_field]) &&
1313 $settings["require_" . $multi_field]);
1314 $this->form_gui->addItem($ti);
1315 }
1316 }
1317
1318 // other information
1319 if ($this->isSettingChangeable('user_profile_other')) {
1320 $sec_oi = new ilFormSectionHeaderGUI();
1321 $sec_oi->setTitle($this->lng->txt("user_profile_other"));
1322 $this->form_gui->addItem($sec_oi);
1323 }
1324
1325 // matriculation number
1326 if ($this->isSettingChangeable('matriculation')) {
1327 $mr = new ilTextInputGUI($lng->txt("matriculation"), "matriculation");
1328 $mr->setSize(40);
1329 $mr->setMaxLength(40);
1330 $mr->setRequired(isset($settings["require_matriculation"]) &&
1331 $settings["require_matriculation"]);
1332 $this->form_gui->addItem($mr);
1333 }
1334
1335 // client IP
1336 $ip = new ilTextInputGUI($lng->txt("client_ip"), "client_ip");
1337 $ip->setSize(40);
1338 $ip->setMaxLength(255);
1339 $ip->setInfo($this->lng->txt("current_ip") . " " . $_SERVER["REMOTE_ADDR"] . " <br />" .
1340 '<span class="warning">' . $this->lng->txt("current_ip_alert") . "</span>");
1341 $this->form_gui->addItem($ip);
1342
1343 // additional user defined fields
1344 $user_defined_fields = ilUserDefinedFields::_getInstance();
1345
1346 if ($this->usrf_ref_id == USER_FOLDER_ID) {
1347 $all_defs = $user_defined_fields->getDefinitions();
1348 } else {
1349 $all_defs = $user_defined_fields->getChangeableLocalUserAdministrationDefinitions();
1350 }
1351
1352 foreach ($all_defs as $definition) {
1353 $f_property = ilCustomUserFieldsHelper::getInstance()->getFormPropertyForDefinition($definition, true);
1354 if ($f_property instanceof ilFormPropertyGUI) {
1355 $this->form_gui->addItem($f_property);
1356 }
1357 }
1358
1359 // settings
1360 if (
1361 $a_mode == 'create' or
1362 $this->isSettingChangeable('language') or
1363 $this->isSettingChangeable('skin_style') or
1364 $this->isSettingChangeable('hits_per_page') or
1365 $this->isSettingChangeable('hide_own_online_status') or
1366 $this->isSettingChangeable('bs_allow_to_contact_me') or
1367 $this->isSettingChangeable('chat_osc_accept_msg') or
1368 $this->isSettingChangeable('chat_broadcast_typing')
1369 ) {
1370 $sec_st = new ilFormSectionHeaderGUI();
1371 $sec_st->setTitle($this->lng->txt("settings"));
1372 $this->form_gui->addItem($sec_st);
1373 }
1374
1375 // role
1376 if ($a_mode == "create") {
1377 $role = new ilSelectInputGUI(
1378 $lng->txt("default_role"),
1379 'default_role'
1380 );
1381 $role->setRequired(true);
1382 $role->setValue($this->default_role);
1383 $role->setOptions($this->selectable_roles);
1384 $this->form_gui->addItem($role);
1385 }
1386
1387 // language
1388 if ($this->isSettingChangeable('language')) {
1389 $languages = $this->lng->getInstalledLanguages();
1390 $this->lng->loadLanguageModule('meta');
1391 $options = [];
1392 foreach ($languages as $l) {
1393 $options[$l] = $lng->txt("meta_l_" . $l);
1394 }
1395 $lang = new ilSelectInputGUI(
1396 $this->lng->txt('language'),
1397 'language'
1398 );
1399 $lang->setOptions($options);
1400 $lang->setValue($ilSetting->get("language"));
1401 if (count($options) <= 1) {
1402 $lang->setDisabled(true);
1403 }
1404 $this->form_gui->addItem($lang);
1405 }
1406
1407 // skin/style
1408 if ($this->isSettingChangeable('skin_style')) {
1409 $sk = new ilSelectInputGUI(
1410 $lng->txt("skin_style"),
1411 'skin_style'
1412 );
1413
1414 $skins = ilStyleDefinition::getAllSkins();
1415
1416 $options = array();
1417 if (is_array($skins)) {
1418 $sk = new ilSelectInputGUI($this->lng->txt("skin_style"), "skin_style");
1419
1420 $options = array();
1421 foreach ($skins as $skin) {
1422 foreach ($skin->getStyles() as $style) {
1423 if (!ilSystemStyleSettings::_lookupActivatedStyle($skin->getId(), $style->getId())) {
1424 continue;
1425 }
1426
1427 $options[$skin->getId() . ":" . $style->getId()] = $skin->getName() . " / " . $style->getName();
1428 }
1429 }
1430 }
1431 $sk->setOptions($options);
1432 $sk->setValue($ilClientIniFile->readVariable("layout", "skin") .
1433 ":" . $ilClientIniFile->readVariable("layout", "style"));
1434
1435 $this->form_gui->addItem($sk);
1436 }
1437
1438 // hits per page
1439 if ($this->isSettingChangeable('hits_per_page')) {
1440 $hpp = new ilSelectInputGUI(
1441 $lng->txt("hits_per_page"),
1442 'hits_per_page'
1443 );
1444 $options = array(10 => 10,
1445 15 => 15,
1446 20 => 20,
1447 30 => 30,
1448 40 => 40,
1449 50 => 50,
1450 100 => 100,
1451 9999 => $this->lng->txt("no_limit")
1452 );
1453 $hpp->setOptions($options);
1454 $hpp->setValue($ilSetting->get("hits_per_page"));
1455 $this->form_gui->addItem($hpp);
1456 }
1457
1458 // hide online status
1459 if ($this->isSettingChangeable('hide_own_online_status')) {
1460 $lng->loadLanguageModule("awrn");
1461
1462 $default = ($ilSetting->get('hide_own_online_status') == "n")
1463 ? $this->lng->txt("user_awrn_show")
1464 : $this->lng->txt("user_awrn_hide");
1465
1466 $options = array(
1467 "" => $this->lng->txt("user_awrn_default") . " (" . $default . ")",
1468 "n" => $this->lng->txt("user_awrn_show"),
1469 "y" => $this->lng->txt("user_awrn_hide")
1470 );
1471 $os = new ilSelectInputGUI($lng->txt("awrn_user_show"), "hide_own_online_status");
1472 $os->setOptions($options);
1473 $os->setDisabled((bool) $ilSetting->get("usr_settings_disable_hide_own_online_status"));
1474 $os->setInfo($lng->txt("awrn_hide_from_awareness_info"));
1475 $this->form_gui->addItem($os);
1476
1477 //$os = new ilCheckboxInputGUI($lng->txt("awrn_hide_from_awareness"), "hide_own_online_status");
1478 //$this->form_gui->addItem($os);
1479 }
1480
1481 // allow to contact me
1482 if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
1483 $lng->loadLanguageModule('buddysystem');
1484 $os = new ilCheckboxInputGUI($lng->txt('buddy_allow_to_contact_me'), 'bs_allow_to_contact_me');
1485 if ($a_mode == 'create') {
1486 $os->setChecked(ilUtil::yn2tf($ilSetting->get('bs_allow_to_contact_me', 'n')));
1487 }
1488 $this->form_gui->addItem($os);
1489 }
1490 if ($this->isSettingChangeable('chat_osc_accept_msg')) {
1491 $lng->loadLanguageModule('chatroom');
1492 $chat_osc_acm = new ilCheckboxInputGUI($lng->txt('chat_osc_accept_msg'), 'chat_osc_accept_msg');
1493 if ($a_mode == 'create') {
1494 $chat_osc_acm->setChecked(ilUtil::yn2tf($ilSetting->get('chat_osc_accept_msg', 'n')));
1495 }
1496 $this->form_gui->addItem($chat_osc_acm);
1497 }
1498
1499 if ((int) $ilSetting->get('session_reminder_enabled')) {
1500 $cb = new ilCheckboxInputGUI($this->lng->txt('session_reminder'), 'session_reminder_enabled');
1501 $cb->setValue(1);
1502 $this->form_gui->addItem($cb);
1503 }
1504
1505 // Options
1506 if ($this->isSettingChangeable('send_mail')) {
1507 $sec_op = new ilFormSectionHeaderGUI();
1508 $sec_op->setTitle($this->lng->txt("options"));
1509 $this->form_gui->addItem($sec_op);
1510 }
1511
1512 // send email
1513 $se = new ilCheckboxInputGUI($lng->txt('inform_user_mail'), 'send_mail');
1514 $se->setInfo($lng->txt('inform_user_mail_info'));
1515 $se->setValue('y');
1516 $se->setChecked(($ilUser->getPref('send_info_mails') == 'y'));
1517 $this->form_gui->addItem($se);
1518
1519 // ignore required fields
1520 $irf = new ilCheckboxInputGUI($lng->txt('ignore_required_fields'), 'ignore_rf');
1521 $irf->setInfo($lng->txt('ignore_required_fields_info'));
1522 $irf->setValue(1);
1523 $this->form_gui->addItem($irf);
1524
1525 // @todo: handle all required fields
1526
1527 // command buttons
1528 if ($a_mode == "create" || $a_mode == "save") {
1529 $this->form_gui->addCommandButton("save", $lng->txt("save"));
1530 }
1531 if ($a_mode == "edit" || $a_mode == "update") {
1532 $this->form_gui->addCommandButton("update", $lng->txt("save"));
1533 }
1534 $this->form_gui->addCommandButton("cancel", $lng->txt("cancel"));
1535 }
1536
1537 protected function isSettingChangeable(string $a_field): bool
1538 {
1539 global $DIC;
1540
1541 $ilSetting = $DIC['ilSetting'];
1542 static $settings = null;
1543
1544 if ($this->usrf_ref_id == USER_FOLDER_ID) {
1545 return true;
1546 }
1547
1548 if ($settings == null) {
1549 $settings = $ilSetting->getAll();
1550 }
1551 return (bool) ($settings['usr_settings_changeable_lua_' . $a_field] ?? false);
1552 }
1553
1558 public function uploadUserPictureObject(): void
1559 {
1560 global $DIC;
1561
1562 $rbacsystem = $DIC['rbacsystem'];
1563
1564 // User folder
1565 if ($this->usrf_ref_id == USER_FOLDER_ID and
1566 !$rbacsystem->checkAccess('visible,read', $this->usrf_ref_id)) {
1567 $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
1568 }
1569 // if called from local administration $this->usrf_ref_id is category id
1570 // Todo: this has to be fixed. Do not mix user folder id and category id
1571 if ($this->usrf_ref_id != USER_FOLDER_ID) {
1572 // check if user is assigned to category
1573 if (!$rbacsystem->checkAccess('cat_administrate_users', $this->object->getTimeLimitOwner())) {
1574 $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
1575 }
1576 }
1577
1578 $userfile_input = $this->form_gui->getItemByPostVar("userfile");
1579
1580 if ($_FILES["userfile"]["tmp_name"] == "") {
1581 if ($userfile_input->getDeletionFlag()) {
1582 $this->object->removeUserPicture();
1583 }
1584 return;
1585 }
1586 if ($_FILES["userfile"]["size"] == 0) {
1587 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("msg_no_file"));
1588 } else {
1589 $webspace_dir = ilFileUtils::getWebspaceDir();
1590 $image_dir = $webspace_dir . "/usr_images";
1591 $store_file = "usr_" . $this->object->getId() . "." . "jpg";
1592
1593 // store filename
1594 $this->object->setPref("profile_image", $store_file);
1595 $this->object->update();
1596
1597 // move uploaded file
1598 $pi = pathinfo($_FILES["userfile"]["name"]);
1599 $uploaded_file = $image_dir . "/upload_" . $this->object->getId() . "." . $pi["extension"];
1601 $_FILES["userfile"]["tmp_name"],
1602 $_FILES["userfile"]["name"],
1603 $uploaded_file,
1604 false
1605 )) {
1606 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("upload_error", true));
1607 $this->ctrl->redirect($this, "showProfile");
1608 }
1609 chmod($uploaded_file, 0770);
1610
1611 // take quality 100 to avoid jpeg artefacts when uploading jpeg files
1612 // taking only frame [0] to avoid problems with animated gifs
1613 $show_file = "$image_dir/usr_" . $this->object->getId() . ".jpg";
1614 $thumb_file = "$image_dir/usr_" . $this->object->getId() . "_small.jpg";
1615 $xthumb_file = "$image_dir/usr_" . $this->object->getId() . "_xsmall.jpg";
1616 $xxthumb_file = "$image_dir/usr_" . $this->object->getId() . "_xxsmall.jpg";
1617 $uploaded_file = ilShellUtil::escapeShellArg($uploaded_file);
1618 $show_file = ilShellUtil::escapeShellArg($show_file);
1619 $thumb_file = ilShellUtil::escapeShellArg($thumb_file);
1620 $xthumb_file = ilShellUtil::escapeShellArg($xthumb_file);
1621 $xxthumb_file = ilShellUtil::escapeShellArg($xxthumb_file);
1622
1623 if (ilShellUtil::isConvertVersionAtLeast("6.3.8-3")) {
1625 $uploaded_file . "[0] -geometry 200x200^ -gravity center -extent 200x200 -quality 100 JPEG:" . $show_file
1626 );
1628 $uploaded_file . "[0] -geometry 100x100^ -gravity center -extent 100x100 -quality 100 JPEG:" . $thumb_file
1629 );
1631 $uploaded_file . "[0] -geometry 75x75^ -gravity center -extent 75x75 -quality 100 JPEG:" . $xthumb_file
1632 );
1634 $uploaded_file . "[0] -geometry 30x30^ -gravity center -extent 30x30 -quality 100 JPEG:" . $xxthumb_file
1635 );
1636 } else {
1637 ilShellUtil::execConvert($uploaded_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
1638 ilShellUtil::execConvert($uploaded_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
1639 ilShellUtil::execConvert($uploaded_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
1640 ilShellUtil::execConvert($uploaded_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
1641 }
1642 }
1643 }
1644
1648 public function removeUserPictureObject(): void
1649 {
1650 $webspace_dir = ilFileUtils::getWebspaceDir();
1651 $image_dir = $webspace_dir . "/usr_images";
1652 $file = $image_dir . "/usr_" . $this->object->getId() . "." . "jpg";
1653 $thumb_file = $image_dir . "/usr_" . $this->object->getId() . "_small.jpg";
1654 $xthumb_file = $image_dir . "/usr_" . $this->object->getId() . "_xsmall.jpg";
1655 $xxthumb_file = $image_dir . "/usr_" . $this->object->getId() . "_xxsmall.jpg";
1656 $upload_file = $image_dir . "/upload_" . $this->object->getId();
1657
1658 // remove user pref file name
1659 $this->object->setPref("profile_image", "");
1660 $this->object->update();
1661 $this->tpl->setOnScreenMessage('success', $this->lng->txt("user_image_removed"));
1662
1663 if (is_file($file)) {
1664 unlink($file);
1665 }
1666 if (is_file($thumb_file)) {
1667 unlink($thumb_file);
1668 }
1669 if (is_file($xthumb_file)) {
1670 unlink($xthumb_file);
1671 }
1672 if (is_file($xxthumb_file)) {
1673 unlink($xxthumb_file);
1674 }
1675 if (is_file($upload_file)) {
1676 unlink($upload_file);
1677 }
1678
1679 $this->editObject();
1680 }
1681
1685 public function assignSaveObject(): void
1686 {
1687 global $DIC;
1688
1689 $rbacsystem = $DIC['rbacsystem'];
1690 $rbacadmin = $DIC['rbacadmin'];
1691 $rbacreview = $DIC['rbacreview'];
1692
1693 if (!$rbacsystem->checkAccess("edit_roleassignment", $this->usrf_ref_id)) {
1694 $this->ilias->raiseError(
1695 $this->lng->txt("msg_no_perm_assign_role_to_user"),
1696 $this->ilias->error_obj->MESSAGE
1697 );
1698 }
1699
1700 $selected_roles = $this->user_request->getRoleIds();
1701 $posted_roles = $this->user_request->getPostedRoleIds();
1702
1703 // prevent unassignment of system role from system user
1704 if ($this->object->getId() == SYSTEM_USER_ID and in_array(SYSTEM_ROLE_ID, $posted_roles)) {
1705 $selected_roles[] = SYSTEM_ROLE_ID;
1706 }
1707
1708 $global_roles_all = $rbacreview->getGlobalRoles();
1709 $assigned_roles_all = $rbacreview->assignedRoles($this->object->getId());
1710 $assigned_roles = array_intersect($assigned_roles_all, $posted_roles);
1711 $assigned_global_roles_all = array_intersect($assigned_roles_all, $global_roles_all);
1712 $assigned_global_roles = array_intersect($assigned_global_roles_all, $posted_roles);
1713
1714 $user_not_allowed_to_change_admin_role_assginements =
1715 !in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($this->user->getId()));
1716
1717 if ($user_not_allowed_to_change_admin_role_assginements
1718 && in_array(SYSTEM_ROLE_ID, $assigned_roles_all)) {
1719 $selected_roles[] = SYSTEM_ROLE_ID;
1720 }
1721
1722 $posted_global_roles = array_intersect($selected_roles, $global_roles_all);
1723
1724 if (empty($selected_roles) && count($assigned_roles_all) === count($assigned_roles)
1725 || empty($posted_global_roles) && count($assigned_global_roles_all) === count($assigned_global_roles)) {
1726 $this->tpl->setOnScreenMessage(
1727 'failure',
1728 $this->lng->txt('msg_min_one_role') . '<br/>' . $this->lng->txt('action_aborted'),
1729 true
1730 );
1731 $this->ctrl->redirect($this, 'roleassignment');
1732 }
1733
1734 foreach (array_diff($assigned_roles, $selected_roles) as $role) {
1735 if ($this->object->getId() === (int) SYSTEM_USER_ID && $role === SYSTEM_ROLE_ID
1736 || $user_not_allowed_to_change_admin_role_assginements && $role === SYSTEM_ROLE_ID) {
1737 continue;
1738 }
1739 $rbacadmin->deassignUser($role, $this->object->getId());
1740 }
1741
1742 foreach (array_diff($selected_roles, $assigned_roles) as $role) {
1743 if ($this->object->getId() === (int) SYSTEM_USER_ID && $role === SYSTEM_ROLE_ID
1744 || $user_not_allowed_to_change_admin_role_assginements && $role === SYSTEM_ROLE_ID) {
1745 continue;
1746 }
1747 $rbacadmin->assignUser($role, $this->object->getId(), false);
1748 }
1749
1750 // update object data entry (to update last modification date)
1751 $this->object->update();
1752
1753 $this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_roleassignment_changed"), true);
1754
1755 if (strtolower($this->requested_baseClass) == 'iladministrationgui') {
1756 $this->ctrl->redirect($this, 'roleassignment');
1757 } else {
1758 $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
1759 }
1760 }
1761
1765 public function roleassignmentObject(): void
1766 {
1767 global $DIC;
1768
1769 $rbacsystem = $DIC['rbacsystem'];
1770 $ilTabs = $DIC['ilTabs'];
1771 $access = $DIC->access();
1772
1773 $ilTabs->activateTab("role_assignment");
1774
1775 if ($this->object->getId() === (int) ANONYMOUS_USER_ID
1776 || !$rbacsystem->checkAccess("edit_roleassignment", $this->usrf_ref_id)
1777 && !$access->isCurrentUserBasedOnPositionsAllowedTo("read_users", array($this->object->getId()))
1778 ) {
1779 $this->ilias->raiseError(
1780 $this->lng->txt("msg_no_perm_assign_role_to_user"),
1781 $this->ilias->error_obj->MESSAGE
1782 );
1783 }
1784
1785 $filtered_roles = ilSession::get("filtered_roles");
1786 $req_filtered_roles = $this->user_request->getFilteredRoles();
1788 "filtered_roles",
1789 ($req_filtered_roles > 0) ? $req_filtered_roles : $filtered_roles
1790 );
1791
1792 $filtered_roles = ilSession::get("filtered_roles");
1793 if ($filtered_roles > 5) {
1794 ilSession::set("filtered_roles", 0);
1795 }
1796
1797 $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.usr_role_assignment.html', 'Services/User');
1798
1799 // init table
1800 $tab = new ilRoleAssignmentTableGUI($this, "roleassignment");
1801
1802 $tab->parse($this->object->getId());
1803 $this->tpl->setVariable("ROLES_TABLE", $tab->getHTML());
1804 }
1805
1809 public function applyFilterObject(): void
1810 {
1811 $table_gui = new ilRoleAssignmentTableGUI($this, "roleassignment");
1812 $table_gui->writeFilterToSession(); // writes filter to session
1813 $table_gui->resetOffset(); // sets record offest to 0 (first page)
1814 $this->roleassignmentObject();
1815 }
1816
1820 public function resetFilterObject(): void
1821 {
1822 $table_gui = new ilRoleAssignmentTableGUI($this, "roleassignment");
1823 $table_gui->resetOffset(); // sets record offest to 0 (first page)
1824 $table_gui->resetFilter(); // clears filter
1825 $this->roleassignmentObject();
1826 }
1827
1828 public function __getDateSelect(
1829 string $a_type,
1830 string $a_varname,
1831 string $a_selected
1832 ): string {
1833 $year = null;
1834 switch ($a_type) {
1835 case "minute":
1836 for ($i = 0; $i <= 60; $i++) {
1837 $days[$i] = $i < 10 ? "0" . $i : $i;
1838 }
1839 return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $days, false, true);
1840
1841 case "hour":
1842 for ($i = 0; $i < 24; $i++) {
1843 $days[$i] = $i < 10 ? "0" . $i : $i;
1844 }
1845 return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $days, false, true);
1846
1847 case "day":
1848 for ($i = 1; $i < 32; $i++) {
1849 $days[$i] = $i < 10 ? "0" . $i : $i;
1850 }
1851 return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $days, false, true);
1852
1853 case "month":
1854 for ($i = 1; $i < 13; $i++) {
1855 $month[$i] = $i < 10 ? "0" . $i : $i;
1856 }
1857 return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $month, false, true);
1858
1859 case "year":
1860 if ($a_selected < date('Y')) {
1861 $start = $a_selected;
1862 } else {
1863 $start = date('Y');
1864 }
1865
1866 for ($i = $start; $i < ((int) date("Y") + 11); ++$i) {
1867 $year[$i] = $i;
1868 }
1869 return ilLegacyFormElementsUtil::formSelect($a_selected, $a_varname, $year, false, true);
1870 }
1871 return "";
1872 }
1873
1874 public function __toUnix(array $a_time_arr): int // Missing array type.
1875 {
1876 return mktime(
1877 $a_time_arr["hour"],
1878 $a_time_arr["minute"],
1879 $a_time_arr["second"],
1880 $a_time_arr["month"],
1881 $a_time_arr["day"],
1882 $a_time_arr["year"]
1883 );
1884 }
1885
1886 public function __unsetSessionVariables(): void
1887 {
1888 ilSession::clear("filtered_roles");
1889 }
1890
1891 public function __buildFilterSelect(): string
1892 {
1893 $action[0] = $this->lng->txt('assigned_roles');
1894 $action[1] = $this->lng->txt('all_roles');
1895 $action[2] = $this->lng->txt('all_global_roles');
1896 $action[3] = $this->lng->txt('all_local_roles');
1897 $action[4] = $this->lng->txt('internal_local_roles_only');
1898 $action[5] = $this->lng->txt('non_internal_local_roles_only');
1899
1901 ilSession::get("filtered_roles"),
1902 "filter",
1903 $action,
1904 false,
1905 true
1906 );
1907 }
1908
1913 protected function addAdminLocatorItems(bool $do_not_add_object = false): void
1914 {
1915 global $DIC;
1916
1917 $ilLocator = $DIC['ilLocator'];
1918
1919 $ilLocator->clearItems();
1920
1921 if ($this->admin_mode == "settings") { // system settings
1922 $this->ctrl->setParameterByClass(
1923 "ilobjsystemfoldergui",
1924 "ref_id",
1926 );
1927 $ilLocator->addItem(
1928 $this->lng->txt("administration"),
1929 $this->ctrl->getLinkTargetByClass(array("iladministrationgui", "ilobjsystemfoldergui"), ""),
1930 ilFrameTargetInfo::_getFrame("MainContent")
1931 );
1932
1933 if ($this->requested_ref_id == USER_FOLDER_ID) {
1934 $ilLocator->addItem(
1935 $this->lng->txt("obj_" . ilObject::_lookupType(
1936 ilObject::_lookupObjId($this->requested_ref_id)
1937 )),
1938 $this->ctrl->getLinkTargetByClass("ilobjuserfoldergui", "view")
1939 );
1940 } elseif ($this->requested_ref_id == ROLE_FOLDER_ID) {
1941 $ilLocator->addItem(
1942 $this->lng->txt("obj_" . ilObject::_lookupType(
1943 ilObject::_lookupObjId($this->requested_ref_id)
1944 )),
1945 $this->ctrl->getLinkTargetByClass("ilobjrolefoldergui", "view")
1946 );
1947 }
1948
1949 if ($this->obj_id > 0) {
1950 $ilLocator->addItem(
1951 $this->object->getTitle(),
1952 $this->ctrl->getLinkTarget($this, "view")
1953 );
1954 }
1955 }
1956 }
1957
1958 public function __sendProfileMail(): string
1959 {
1960 global $DIC;
1961
1962 $ilias = $DIC['ilias'];
1963
1964 if ($this->user_request->getSendMail() != 'y') {
1965 return '';
1966 }
1967 if (!strlen($this->object->getEmail())) {
1968 return '';
1969 }
1970
1971 // Choose language of user
1972 $usr_lang = new ilLanguage($this->object->getLanguage());
1973 $usr_lang->loadLanguageModule('crs');
1974 $usr_lang->loadLanguageModule('registration');
1975
1977 $senderFactory = $GLOBALS['DIC']["mail.mime.sender.factory"];
1978
1979 $mmail = new ilMimeMail();
1980 $mmail->From($senderFactory->system());
1981
1982 $mailOptions = new \ilMailOptions($this->object->getId());
1983 $mmail->To($mailOptions->getExternalEmailAddresses());
1984
1985 // mail subject
1986 $subject = $usr_lang->txt("profile_changed");
1987
1988 // mail body
1989 $body = $usr_lang->txt("reg_mail_body_salutation")
1990 . " " . $this->object->getFullname() . ",\n\n";
1991
1992 $date = $this->object->getApproveDate();
1993 // Approve
1994 if ((time() - strtotime($date)) < 10) {
1995 $body .= $usr_lang->txt('reg_mail_body_approve') . "\n\n";
1996 } else {
1997 $body .= $usr_lang->txt('reg_mail_body_profile_changed') . "\n\n";
1998 }
1999
2000 // Append login info only if password has been changed
2001 if ($this->user_request->getPassword() != '') {
2002 $body .= $usr_lang->txt("reg_mail_body_text2") . "\n" .
2003 ILIAS_HTTP_PATH . "/login.php?client_id=" . $ilias->client_id . "\n" .
2004 $usr_lang->txt("login") . ": " . $this->object->getLogin() . "\n" .
2005 $usr_lang->txt("passwd") . ": " . $this->user_request->getPassword() . "\n\n";
2006 }
2007 $body .= $usr_lang->txt("reg_mail_body_text3") . "\n";
2008 $body .= $this->object->getProfileAsString($usr_lang);
2010
2011
2012 $mmail->Subject($subject, true);
2013 $mmail->Body($body);
2014 $mmail->Send();
2015
2016 return "<br/>" . $this->lng->txt("mail_sent");
2017 }
2018
2022 public static function _goto(string $a_target): void
2023 {
2024 global $DIC;
2025
2026 $ilUser = $DIC['ilUser'];
2027
2029 $ilCtrl = $DIC['ilCtrl'];
2030
2031 if (strstr($a_target, ilPersonalProfileGUI::CHANGE_EMAIL_CMD) === $a_target
2032 && $ilUser->getId() !== ANONYMOUS_USER_ID) {
2033 $class = ilPersonalProfileGUI::class;
2035 $ilCtrl->clearParametersByClass($class);
2036 $ilCtrl->setParameterByClass($class, 'token', str_replace($cmd, '', $a_target));
2037 $ilCtrl->redirectByClass(['ildashboardgui', $class], $cmd);
2038 }
2039
2040 // #10888
2041 if ($a_target == md5("usrdelown")) {
2042 if ($ilUser->getId() != ANONYMOUS_USER_ID &&
2043 $ilUser->hasDeletionFlag()) {
2044 $ilCtrl->setTargetScript('ilias.php');
2045 $ilCtrl->redirectByClass(['ildashboardgui', 'ilpersonalsettingsgui'], "deleteOwnAccount3");
2046 }
2047 exit("This account is not flagged for deletion."); // #12160
2048 }
2049
2050 // badges
2051 if (substr($a_target, -4) == "_bdg") {
2052 $ilCtrl->redirectByClass("ilDashboardGUI", "jumpToBadges");
2053 }
2054
2055 if ('registration' == $a_target) {
2056 $ilCtrl->redirectByClass(array('ilStartUpGUI', 'ilAccountRegistrationGUI'), '');
2057 } elseif ('nameassist' == $a_target) {
2058 $ilCtrl->redirectByClass(array('ilStartUpGUI', 'ilPasswordAssistanceGUI'), 'showUsernameAssistanceForm');
2059 } elseif ('pwassist' == $a_target) {
2060 $ilCtrl->redirectByClass(array('ilStartUpGUI', 'ilPasswordAssistanceGUI'), '');
2061 } elseif ('agreement' == $a_target) {
2062 $ilCtrl->setTargetScript('ilias.php');
2063 if ($ilUser->getId() > 0 && !$ilUser->isAnonymous()) {
2064 $ilCtrl->redirectByClass(array('ildashboardgui', 'ilpersonalprofilegui'), 'showUserAgreement');
2065 } else {
2066 $ilCtrl->redirectByClass(array('ilStartUpGUI'), 'showTermsOfService');
2067 }
2068 }
2069
2070 if (strpos($a_target, "n") === 0) {
2071 $a_target = ilObjUser::_lookupId(ilUtil::stripSlashes(substr($a_target, 1)));
2072 }
2073
2074 $cmd = "view";
2075 if (strpos($a_target, 'contact_approved') !== false) {
2076 $cmd = 'approveContactRequest';
2077 } elseif (strpos($a_target, 'contact_ignored') !== false) {
2078 $cmd = 'ignoreContactRequest';
2079 }
2080
2081 $ilCtrl->setParameterByClass("ilpublicuserprofilegui", "user_id", (int) $a_target);
2082 $ilCtrl->redirectByClass(["ilPublicUserProfileGUI"], $cmd);
2083 }
2084
2089 protected function handleIgnoredRequiredFields(): bool
2090 {
2091 $profile_maybe_incomplete = false;
2092
2093 foreach (ilUserProfile::getIgnorableRequiredSettings() as $fieldName) {
2094 $elm = $this->form_gui->getItemByPostVar($fieldName);
2095
2096 if (!$elm) {
2097 continue;
2098 }
2099
2100 if ($elm->getRequired()) {
2101 $profile_maybe_incomplete = true;
2102
2103 // Flag as optional
2104 $elm->setRequired(false);
2105 }
2106 }
2107
2108 $user_defined_fields = ilUserDefinedFields::_getInstance();
2109 foreach ($user_defined_fields->getDefinitions() as $definition) {
2110 $elm = $this->form_gui->getItemByPostVar('udf_' . $definition['field_id']);
2111
2112 if (!$elm) {
2113 continue;
2114 }
2115 if ($elm->getRequired() && $definition['required']) {
2116 $profile_maybe_incomplete = true;
2117
2118 // Flag as optional
2119 $elm->setRequired(false);
2120 }
2121 }
2122
2123 return $profile_maybe_incomplete;
2124 }
2125
2126 protected function showAcceptedTermsOfService(): void
2127 {
2129 $agreeDate = $this->form_gui->getItemByPostVar('agree_date');
2130 if ($agreeDate && $agreeDate->getValue()) {
2131 $this->lng->loadLanguageModule('tos');
2132 $helper = new \ilTermsOfServiceHelper();
2134 $user = $this->object;
2135 $entity = $helper->getCurrentAcceptanceForUser($user);
2136 if ($entity->getId()) {
2137 $modal = $this->uiFactory
2138 ->modal()
2139 ->lightbox([
2140 $this->uiFactory->modal()->lightboxTextPage($entity->getText(), $entity->getTitle())
2141 ]);
2142
2143 $titleLink = $this->uiFactory
2144 ->button()
2145 ->shy($entity->getTitle(), '#')
2146 ->withOnClick($modal->getShowSignal());
2147
2148 $agreementDocument = new ilNonEditableValueGUI(
2149 $this->lng->txt('tos_agreement_document'),
2150 '',
2151 true
2152 );
2153 $agreementDocument->setValue($this->uiRenderer->render([$titleLink, $modal]));
2154 $agreeDate->addSubItem($agreementDocument);
2155 }
2156 } elseif ($agreeDate) {
2157 $agreeDate->setValue($this->lng->txt('tos_not_accepted_yet'));
2158 }
2159 }
2160
2161 private function checkUserWriteRight(): void
2162 {
2163 if ($this->usrf_ref_id == USER_FOLDER_ID
2164 && (
2165 !$this->rbac_system->checkAccess('visible,read', $this->usrf_ref_id)
2166 || !$this->rbac_system->checkAccess('write', $this->usrf_ref_id)
2167 && (
2168 !$this->access->checkPositionAccess(\ilObjUserFolder::ORG_OP_EDIT_USER_ACCOUNTS, $this->usrf_ref_id)
2169 || $this->access->checkPositionAccess(\ilObjUserFolder::ORG_OP_EDIT_USER_ACCOUNTS, $this->usrf_ref_id)
2170 && !in_array(
2171 $this->object->getId(),
2172 $this->access->filterUserIdsByPositionOfCurrentUser(
2175 [$this->object->getId()]
2176 )
2177 )
2178 )
2179 )
2180 ) {
2181 $this->ilias->raiseError($this->lng->txt('msg_no_perm_modify_user'), $this->ilias->error_obj->MESSAGE);
2182 }
2183
2184 // if called from local administration $this->usrf_ref_id is category id
2185 // Todo: this has to be fixed. Do not mix user folder id and category id
2186 if ($this->usrf_ref_id != USER_FOLDER_ID
2187 && !$this->rbac_system->checkAccess('cat_administrate_users', $this->object->getTimeLimitOwner())) {
2188 $this->ilias->raiseError($this->lng->txt('msg_no_perm_modify_user'), $this->ilias->error_obj->MESSAGE);
2189 }
2190 }
2191}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
const UDF_TYPE_TEXT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilAccountMail.
static _allowPasswordModificationByAuthMode($a_auth_mode)
Allow password modification.
static _getActiveAuthModes()
static _isExternalAccountEnabled()
Check if an external account name is required.
static getAuthModeTranslation(string $a_auth_key, string $auth_name='')
static _getAuthMode(?string $a_auth_mode)
static _getAuthModeName($a_auth_key)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
redirectByClass( $a_class, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
setTargetScript(string $a_target_script)
@inheritDoc
clearParametersByClass(string $a_class)
@inheritDoc
getFormAction(object $a_gui_obj, string $a_fallback_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
setParameterByClass(string $a_class, string $a_parameter, $a_value)
@inheritDoc
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...
@classDescription Date and time handling
Class for single dates.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static moveUploadedFile(string $a_file, string $a_name, string $a_target, bool $a_raise_errors=true, string $a_mode="move_uploaded")
move uploaded file
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getFrame(string $a_class)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
loadLanguageModule(string $a_module)
Load language module.
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)
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 _getInstallationSignature()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getAssignUsersStatus(int $a_role_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilPropertyFormGUI $form_gui
initForm(string $a_mode)
Init user form.
string $requested_baseClass
__toUnix(array $a_time_arr)
saveObject()
save user data
loadUserDefinedDataFromForm(?ilObjUser $user=null)
editObject()
Display user edit form.
getAdminTabs()
administration tabs show only permissions and trash folder
ILIAS UI Factory $uiFactory
setBackTarget(string $a_text, string $a_link)
set back tab target
isSettingChangeable(string $a_field)
handleIgnoredRequiredFields()
Handles ignored required fields by changing the required flag of form elements.
ILIAS UI Renderer $uiRenderer
applyFilterObject()
Apply filter.
cancelObject()
cancel action and go back to previous page
resetFilterObject()
Reset filter.
roleassignmentObject()
display role assignment panel
ILIAS User StandardGUIRequest $user_request
ilUserDefinedFields $user_defined_fields
uploadUserPictureObject()
upload user image (original method by ratana ty)
__construct( $a_data, int $a_id, bool $a_call_by_reference=false, bool $a_prepare_output=true, ILIAS\UI\Factory $uiFactory=null, ILIAS\UI\Renderer $uiRenderer=null)
loadValuesFromForm(string $a_mode='create')
removeUserPictureObject()
remove user image
createObject()
Display user create form.
getValues()
Get values from user object and put them into form.
assignSaveObject()
assign users to role
__getDateSelect(string $a_type, string $a_varname, string $a_selected)
addAdminLocatorItems(bool $do_not_add_object=false)
should be overwritten to add object specific items (repository items are preloaded)
getTabs()
@abstract overwrite in derived GUI class of your object type
User class.
static _getLastHistoryDataByUserId(int $a_usr_id)
Returns the last used loginname and the changedate of the passed user_id.
static _lookupId($a_user_str)
const PASSWD_PLAIN
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)
static _lookupLogin(int $a_user_id)
Class ilObjectGUI Basic methods of all Output classes.
prepareOutput(bool $show_sub_objects=true)
ilLanguage $lng
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
This class represents a selection list property in a property form.
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
static escapeShellArg(string $a_arg)
static isConvertVersionAtLeast(string $a_version)
Compare convert version numbers.
static execConvert(string $args)
execute convert command
static _lookupActivatedStyle(string $a_skin, string $a_style)
lookup if a style is activated
This class represents a text area property in a property form.
This class represents a text property in a property form.
Additional user data fields definition.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isProfileIncomplete(ilObjUser $a_user, bool $a_include_udf=true, bool $a_personal_data_only=true)
Check if all required personal data fields are set.
static getIgnorableRequiredSettings()
Returns an array of all ignorable profiel fields.
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static yn2tf(string $a_yn)
const SYSTEM_ROLE_ID
Definition: constants.php:29
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
const USER_FOLDER_ID
Definition: constants.php:33
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
const ANONYMOUS_USER_ID
Definition: constants.php:27
const SYSTEM_FOLDER_ID
Definition: constants.php:35
const ROLE_FOLDER_ID
Definition: constants.php:34
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
exit
Definition: login.php:28
if($format !==null) $name
Definition: metadata.php:247
$i
Definition: metadata.php:41
$keys
Definition: metadata.php:204
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
catch(\Exception $e) $req
Definition: xapiproxy.php:93
header include for all ilias files.
global $ilSetting
Definition: privfeed.php:17
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10
$lng
$lang
Definition: xapiexit.php:26