1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "./Services/Object/classes/class.ilObjectGUI.php";
5
6/**
7* Class ilObjUserGUI
8*
9* @author Stefan Meyer <meyer@leifos.com>
10* @author Sascha Hofmann <saschahofmann@gmx.de>
11* @version $Id$
12*
13* @ilCtrl_Calls ilObjUserGUI: ilLearningProgressGUI, ilObjectOwnershipManagementGUI
14*
15* @ingroup ServicesUser
16*/
17class ilObjUserGUI extends ilObjectGUI
18{
19    /** @var ILIAS\UI\Factory */
20    protected $uiFactory;
21
22    /** @var ILIAS\UI\Renderer */
23    protected $uiRenderer;
24
25    public $ilCtrl;
26
27    /**
28    * array of gender abbreviations
29    * @var		array
30    * @access	public
31    */
32    public $gender;
33
34    /**
35    * ILIAS3 object type abbreviation
36    * @var		string
37    * @access	public
38    */
39    public $type;
40
41    /**
42    * userfolder ref_id where user is assigned to
43    * @var		string
44    * @access	public
45    */
46    public $user_ref_id;
47
48    /**
49     * ilObjUserGUI constructor.
50     * @param $a_data
51     * @param $a_id
52     * @param bool $a_call_by_reference
53     * @param bool $a_prepare_output
54     * @param \ILIAS\UI\Factory $uiFactory
55     * @param \ILIAS\UI\Renderer $uiRenderer
56     */
57    public function __construct(
58        $a_data,
59        $a_id,
60        $a_call_by_reference = false,
61        $a_prepare_output = true,
62        ILIAS\UI\Factory $uiFactory = null,
63        ILIAS\UI\Renderer $uiRenderer = null
64    ) {
65        global $DIC;
66
67        if (null === $uiFactory) {
68            $uiFactory = $DIC->ui()->factory();
69        }
70        $this->uiFactory = $uiFactory;
71
72        if (null === $uiRenderer) {
73            $uiRenderer = $DIC->ui()->renderer();
74        }
75        $this->uiRenderer = $uiRenderer;
76
77        $ilCtrl = $DIC['ilCtrl'];
78        $lng = $DIC['lng'];
79
80        define('USER_FOLDER_ID', 7);
81
82        $this->type = "usr";
83        parent::__construct($a_data, $a_id, $a_call_by_reference, false);
84        $this->usrf_ref_id = &$this->ref_id;
85
86        $this->ctrl = $ilCtrl;
87        $this->ctrl->saveParameter($this, array('obj_id', 'letter'));
88        $this->ctrl->setParameterByClass("ilobjuserfoldergui", "letter", $_GET["letter"]);
89        $this->ctrl->setContext($this->object->getId(), 'usr');
90        $lng->loadLanguageModule('user');
91
92        // for gender selection. don't change this
93        // maybe deprecated
94        $this->gender = array(
95                              'n' => "salutation_n",
96                              'm' => "salutation_m",
97                              'f' => "salutation_f",
98                              );
99    }
100
101    public function executeCommand()
102    {
103        global $DIC;
104
105        $rbacsystem = $DIC['rbacsystem'];
106
107        $next_class = $this->ctrl->getNextClass($this);
108        $cmd = $this->ctrl->getCmd();
109
110        $this->prepareOutput();
111
112        switch ($next_class) {
113            case "illearningprogressgui":
114                include_once './Services/Tracking/classes/class.ilLearningProgressGUI.php';
115                $new_gui = new ilLearningProgressGUI(ilLearningProgressGUI::LP_CONTEXT_USER_FOLDER, USER_FOLDER_ID, $this->object->getId());
116                $this->ctrl->forwardCommand($new_gui);
117                break;
118
119            case "ilobjectownershipmanagementgui":
120                include_once("Services/Object/classes/class.ilObjectOwnershipManagementGUI.php");
121                $gui = new ilObjectOwnershipManagementGUI($this->object->getId());
122                $this->ctrl->forwardCommand($gui);
123                break;
124
125            default:
126                if ($cmd == "" || $cmd == "view") {
127                    $cmd = "edit";
128                }
129                $cmd .= "Object";
130                $return = $this->$cmd();
131
132                break;
133        }
134        return $return;
135    }
136
137    /* Overwritten from base class
138    */
139    public function setTitleAndDescription()
140    {
141        if (strtolower(get_class($this->object)) == 'ilobjuser') {
142            $this->tpl->setTitle('[' . $this->object->getLogin() . '] ' . $this->object->getTitle());
143            $this->tpl->setDescription($this->object->getLongDescription());
144            $this->tpl->setTitleIcon(ilUtil::getImagePath("icon_" . $this->object->getType() . ".svg"), $this->lng->txt("obj_" . $this->object->getType()));
145        } else {
146            parent::setTitleAndDescription();
147        }
148    }
149
150
151
152    public function cancelObject()
153    {
154        ilSession::clear("saved_post");
155
156        if (strtolower($_GET["baseClass"]) == 'iladministrationgui') {
157            $this->ctrl->redirectByClass("ilobjuserfoldergui", "view");
158        //$return_location = $_GET["cmd_return_location"];
159            //ilUtil::redirect($this->ctrl->getLinkTarget($this,$return_location));
160        } else {
161            $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
162        }
163    }
164
165    /**
166    * admin and normal tabs are equal for roles
167    */
168    public function getAdminTabs()
169    {
170        $this->getTabs();
171    }
172
173    /**
174    * get tabs
175    */
176    public function getTabs()
177    {
178        global $DIC;
179
180        $rbacsystem = $DIC['rbacsystem'];
181        $ilHelp = $DIC['ilHelp'];
182
183        $this->tabs_gui->clearTargets();
184
185        $ilHelp->setScreenIdComponent("usr");
186
187        if ($_GET["search"]) {
188            $this->tabs_gui->setBackTarget(
189                $this->lng->txt("search_results"),
190                $_SESSION["usr_search_link"]
191            );
192
193            $this->tabs_gui->addTarget(
194                "properties",
195                $this->ctrl->getLinkTarget($this, "edit"),
196                array("edit","","view"),
197                get_class($this),
198                "",
199                true
200            );
201        } else {
202            $this->tabs_gui->addTarget(
203                "properties",
204                $this->ctrl->getLinkTarget($this, "edit"),
205                array("edit","","view"),
206                get_class($this)
207            );
208        }
209
210        $this->tabs_gui->addTarget(
211            "role_assignment",
212            $this->ctrl->getLinkTarget($this, "roleassignment"),
213            array("roleassignment"),
214            get_class($this)
215        );
216
217        // learning progress
218        include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
219        if ($rbacsystem->checkAccess('read', $this->ref_id) and
220            ilObjUserTracking::_enabledLearningProgress() and
221            ilObjUserTracking::_enabledUserRelatedData()) {
222            $this->tabs_gui->addTarget(
223                'learning_progress',
224                $this->ctrl->getLinkTargetByClass('illearningprogressgui', ''),
225                '',
226                array('illplistofobjectsgui','illplistofsettingsgui','illearningprogressgui','illplistofprogressgui')
227            );
228        }
229
230        $this->tabs_gui->addTarget(
231            'user_ownership',
232            $this->ctrl->getLinkTargetByClass('ilobjectownershipmanagementgui', ''),
233            '',
234            'ilobjectownershipmanagementgui'
235        );
236    }
237
238    /**
239    * set back tab target
240    */
241    public function setBackTarget($a_text, $a_link)
242    {
243        $this->back_target = array("text" => $a_text,
244            "link" => $a_link);
245    }
246
247    /**
248    * display user create form
249    */
250
251    public function __checkUserDefinedRequiredFields()
252    {
253        include_once './Services/User/classes/class.ilUserDefinedFields.php';
254        $this->user_defined_fields = &ilUserDefinedFields::_getInstance();
255
256        foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
257            if ($definition['required'] and !strlen($_POST['udf'][$field_id])) {
258                return false;
259            }
260        }
261        return true;
262    }
263
264
265    public function __showUserDefinedFields()
266    {
267        include_once './Services/User/classes/class.ilUserDefinedFields.php';
268        $this->user_defined_fields = &ilUserDefinedFields::_getInstance();
269
270        if ($this->object->getType() == 'usr') {
271            $user_defined_data = $this->object->getUserDefinedData();
272        }
273        foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
274            $old = isset($_SESSION["error_post_vars"]["udf"][$field_id]) ?
275                $_SESSION["error_post_vars"]["udf"][$field_id] : $user_defined_data[$field_id];
276
277            if ($definition['field_type'] == UDF_TYPE_TEXT) {
278                $this->tpl->setCurrentBlock("field_text");
279                $this->tpl->setVariable("FIELD_NAME", 'udf[' . $definition['field_id'] . ']');
280                $this->tpl->setVariable("FIELD_VALUE", ilUtil::prepareFormOutput($old));
281                $this->tpl->parseCurrentBlock();
282            } else {
283                $this->tpl->setCurrentBlock("field_select");
284                $this->tpl->setVariable("SELECT_BOX", ilUtil::formSelect(
285                    $old,
286                    'udf[' . $definition['field_id'] . ']',
287                    $this->user_defined_fields->fieldValuesToSelectArray(
288                        $definition['field_values']
289                    ),
290                    false,
291                    true
292                ));
293                $this->tpl->parseCurrentBlock();
294            }
295            $this->tpl->setCurrentBlock("user_defined");
296
297            if ($definition['required']) {
298                $name = $definition['field_name'] . "<span class=\"asterisk\">*</span>";
299            } else {
300                $name = $definition['field_name'];
301            }
302            $this->tpl->setVariable("TXT_FIELD_NAME", $name);
303            $this->tpl->parseCurrentBlock();
304        }
305        return true;
306    }
307
308    public function initCreate()
309    {
310        global $DIC;
311
312        $tpl = $DIC['tpl'];
313        $rbacsystem = $DIC['rbacsystem'];
314        $rbacreview = $DIC['rbacreview'];
315        $ilUser = $DIC['ilUser'];
316
317        if ($this->usrf_ref_id != USER_FOLDER_ID) {
318            $this->tabs_gui->clearTargets();
319        }
320
321        // role selection
322        $obj_list = $rbacreview->getRoleListByObject(ROLE_FOLDER_ID);
323        $rol = array();
324        foreach ($obj_list as $obj_data) {
325            // allow only 'assign_users' marked roles if called from category
326            if ($this->object->getRefId() != USER_FOLDER_ID and !in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()))) {
327                include_once './Services/AccessControl/classes/class.ilObjRole.php';
328
329                if (!ilObjRole::_getAssignUsersStatus($obj_data['obj_id'])) {
330                    continue;
331                }
332            }
333            // exclude anonymous role from list
334            if ($obj_data["obj_id"] != ANONYMOUS_ROLE_ID) {
335                // do not allow to assign users to administrator role if current user does not has SYSTEM_ROLE_ID
336                if ($obj_data["obj_id"] != SYSTEM_ROLE_ID or in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()))) {
337                    $rol[$obj_data["obj_id"]] = $obj_data["title"];
338                }
339            }
340        }
341
342        // raise error if there is no global role user can be assigned to
343        if (!count($rol)) {
344            $this->ilias->raiseError($this->lng->txt("msg_no_roles_users_can_be_assigned_to"), $this->ilias->error_obj->MESSAGE);
345        }
346
347        $keys = array_keys($rol);
348
349        // set pre defined user role to default
350        if (in_array(4, $keys)) {
351            $this->default_role = 4;
352        } else {
353            if (count($keys) > 1 and in_array(2, $keys)) {
354                // remove admin role as preselectable role
355                foreach ($keys as $key => $val) {
356                    if ($val == 2) {
357                        unset($keys[$key]);
358                        break;
359                    }
360                }
361            }
362
363            $this->default_role = array_shift($keys);
364        }
365        $this->selectable_roles = $rol;
366    }
367
368    /**
369    * Display user create form
370    */
371    public function createObject()
372    {
373        global $DIC;
374
375        $tpl = $DIC['tpl'];
376        $rbacsystem = $DIC['rbacsystem'];
377        $rbacreview = $DIC['rbacreview'];
378        $ilUser = $DIC['ilUser'];
379
380        if (!$rbacsystem->checkAccess('create_usr', $this->usrf_ref_id) and
381            !$rbacsystem->checkAccess('cat_administrate_users', $this->usrf_ref_id)) {
382            $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
383        }
384
385        $this->initCreate();
386        $this->initForm("create");
387        return $tpl->setContent($this->form_gui->getHtml());
388    }
389
390    /**
391    * save user data
392    * @access	public
393    */
394    public function saveObject()
395    {
396        global $DIC;
397
398        $ilAccess = $DIC['ilAccess'];
399        $ilSetting = $DIC['ilSetting'];
400        $tpl = $DIC['tpl'];
401        $ilUser = $DIC['ilUser'];
402        $rbacadmin = $DIC['rbacadmin'];
403        $rbacsystem = $DIC['rbacsystem'];
404
405        include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
406
407        // User folder
408        if (!$rbacsystem->checkAccess('create_usr', $this->usrf_ref_id) &&
409            !$ilAccess->checkAccess('cat_administrate_users', "", $this->usrf_ref_id)) {
410            $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE);
411        }
412
413        $this->initCreate();
414        $this->initForm("create");
415
416        // Manipulate form so ignore required fields are no more required. This has to be done before ilPropertyFormGUI::checkInput() is called.
417        $profileMaybeIncomplete = false;
418        if ($this->form_gui->getInput('ignore_rf', false)) {
419            $profileMaybeIncomplete = $this->handleIgnoredRequiredFields();
420        }
421
422        if ($this->form_gui->checkInput()) {
423            // @todo: external account; time limit check and savings
424
425            // checks passed. save user
426            $userObj = $this->loadValuesFromForm();
427
428            $userObj->setPasswd($this->form_gui->getInput('passwd'), IL_PASSWD_PLAIN);
429            $userObj->setTitle($userObj->getFullname());
430            $userObj->setDescription($userObj->getEmail());
431
432            $udf = array();
433            foreach ($_POST as $k => $v) {
434                if (substr($k, 0, 4) == "udf_") {
435                    $udf[substr($k, 4)] = $v;
436                }
437            }
438            $userObj->setUserDefinedData($udf);
439
440            $userObj->create();
441
442            include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
443            if (ilAuthUtils::_isExternalAccountEnabled()) {
444                $userObj->setExternalAccount($_POST["ext_account"]);
445            }
446
447            // set a timestamp for last_password_change
448            // this ts is needed by ilSecuritySettings
449            $userObj->setLastPasswordChangeTS(time());
450
451            //insert user data in table user_data
452            $userObj->saveAsNew();
453
454            // setup user preferences
455            if ($this->isSettingChangeable('language')) {
456                $userObj->setLanguage($_POST["language"]);
457            }
458
459            // Set disk quota
460            require_once 'Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php';
461            if (ilDiskQuotaActivationChecker::_isActive()) {
462                // The disk quota is entered in megabytes but stored in bytes
463                $userObj->setPref("disk_quota", ilUtil::MB2Bytes($_POST["disk_quota"]));
464            }
465
466            if ($this->isSettingChangeable('skin_style')) {
467                //set user skin and style
468                $sknst = explode(":", $_POST["skin_style"]);
469
470                if ($userObj->getPref("style") != $sknst[1] ||
471                    $userObj->getPref("skin") != $sknst[0]) {
472                    $userObj->setPref("skin", $sknst[0]);
473                    $userObj->setPref("style", $sknst[1]);
474                }
475            }
476            if ($this->isSettingChangeable('hits_per_page')) {
477                $userObj->setPref("hits_per_page", $_POST["hits_per_page"]);
478            }
479            /*if($this->isSettingChangeable('show_users_online'))
480            {
481                $userObj->setPref("show_users_online", $_POST["show_users_online"]);
482            }*/
483            if ($this->isSettingChangeable('hide_own_online_status')) {
484                $userObj->setPref("hide_own_online_status", $_POST["hide_own_online_status"]);
485            }
486            if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
487                $userObj->setPref('bs_allow_to_contact_me', $_POST['bs_allow_to_contact_me'] ? 'y' : 'n');
488            }
489            if ($this->isSettingChangeable('chat_osc_accept_msg')) {
490                $userObj->setPref('chat_osc_accept_msg', $_POST['chat_osc_accept_msg'] ? 'y' : 'n');
491            }
492            if ((int) $ilSetting->get('session_reminder_enabled')) {
493                $userObj->setPref('session_reminder_enabled', (int) $_POST['session_reminder_enabled']);
494            }
495            $userObj->writePrefs();
496
497            //set role entries
498            $rbacadmin->assignUser($_POST["default_role"], $userObj->getId(), true);
499
500            $msg = $this->lng->txt("user_added");
501
502            $ilUser->setPref('send_info_mails', ($_POST['send_mail'] == 'y') ? 'y' : 'n');
503            $ilUser->writePrefs();
504
505            $this->object = $userObj;
506
507            if ($this->isSettingChangeable('upload')) {
508                $this->uploadUserPictureObject();
509            }
510
511            if ($profileMaybeIncomplete) {
512                include_once 'Services/User/classes/class.ilUserProfile.php';
513                if (ilUserProfile::isProfileIncomplete($this->object)) {
514                    $this->object->setProfileIncomplete(true);
515                    $this->object->update();
516                }
517            }
518
519            // send new account mail
520            if ($_POST['send_mail'] == 'y') {
521                include_once('Services/Mail/classes/class.ilAccountMail.php');
522                $acc_mail = new ilAccountMail();
523                $acc_mail->useLangVariablesAsFallback(true);
524                $acc_mail->setAttachConfiguredFiles(true);
525                $acc_mail->setUserPassword($_POST['passwd']);
526                $acc_mail->setUser($userObj);
527
528                if ($acc_mail->send()) {
529                    $msg = $msg . '<br />' . $this->lng->txt('mail_sent');
530                    ilUtil::sendSuccess($msg, true);
531                } else {
532                    $msg = $msg . '<br />' . $this->lng->txt('mail_not_sent');
533                    ilUtil::sendInfo($msg, true);
534                }
535            } else {
536                ilUtil::sendSuccess($msg, true);
537            }
538
539
540            if (strtolower($_GET["baseClass"]) == 'iladministrationgui') {
541                $this->ctrl->redirectByClass("ilobjuserfoldergui", "view");
542            } else {
543                $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
544            }
545        } else {
546            $this->form_gui->setValuesByPost();
547            $tpl->setContent($this->form_gui->getHtml());
548        }
549    }
550
551    /**
552    * Display user edit form
553    *
554    * @access	public
555    */
556    public function editObject()
557    {
558        global $ilias, $rbacsystem, $rbacreview, $rbacadmin, $styleDefinition, $ilUser
559            ,$ilSetting, $ilCtrl;
560
561        include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
562
563        //load ILIAS settings
564        $settings = $ilias->getAllSettings();
565
566        // User folder
567        if ($this->usrf_ref_id == USER_FOLDER_ID and !$rbacsystem->checkAccess('visible,read', $this->usrf_ref_id)) {
568            $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
569        }
570        // if called from local administration $this->usrf_ref_id is category id
571        // Todo: this has to be fixed. Do not mix user folder id and category id
572        if ($this->usrf_ref_id != USER_FOLDER_ID) {
573            // check if user is assigned to category
574            if (!$rbacsystem->checkAccess('cat_administrate_users', $this->object->getTimeLimitOwner())) {
575                $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
576            }
577        }
578
579        if ($this->usrf_ref_id != USER_FOLDER_ID) {
580            $this->tabs_gui->clearTargets();
581        }
582
583        // get form
584        $this->initForm("edit");
585        $this->getValues();
586        $this->showAcceptedTermsOfService();
587        $this->tpl->setContent($this->form_gui->getHTML());
588    }
589
590    /**
591     * @param object $a_mode [optional]
592     * @return object ilObjUser
593     */
594    protected function loadValuesFromForm($a_mode = 'create')
595    {
596        global $DIC;
597
598        $ilSetting = $DIC['ilSetting'];
599        $ilUser = $DIC['ilUser'];
600
601        switch ($a_mode) {
602            case 'create':
603                $user = new ilObjUser();
604                break;
605
606            case 'update':
607                $user = $this->object;
608                break;
609        }
610
611        $from = $this->form_gui->getItemByPostVar('time_limit_from')->getDate();
612        $user->setTimeLimitFrom($from
613            ? $from->get(IL_CAL_UNIX)
614            : null);
615
616        $until = $this->form_gui->getItemByPostVar('time_limit_until')->getDate();
617        $user->setTimeLimitUntil($until
618            ? $until->get(IL_CAL_UNIX)
619            : null);
620
621        $user->setTimeLimitUnlimited($this->form_gui->getInput('time_limit_unlimited'));
622
623        if ($a_mode == 'create') {
624            $user->setTimeLimitOwner($this->usrf_ref_id);
625        }
626
627        // Birthday
628        if ($this->isSettingChangeable('birthday')) {
629            $bd = $this->form_gui->getItemByPostVar('birthday');
630            $bd = $bd->getDate();
631            $user->setBirthday($bd
632                ? $bd->get(IL_CAL_DATE)
633                : null);
634        }
635
636        // Login
637        $user->setLogin($this->form_gui->getInput('login'));
638
639
640        // Gender
641        if ($this->isSettingChangeable('gender')) {
642            $user->setGender($this->form_gui->getInput('gender'));
643        }
644
645        // Title
646        if ($this->isSettingChangeable('title')) {
647            $user->setUTitle($this->form_gui->getInput('title'));
648        }
649
650        // Firstname
651        if ($this->isSettingChangeable('firstname')) {
652            $user->setFirstname($this->form_gui->getInput('firstname'));
653        }
654        // Lastname
655        if ($this->isSettingChangeable('lastname')) {
656            $user->setLastname($this->form_gui->getInput('lastname'));
657        }
658        $user->setFullname();
659
660        // Institution
661        if ($this->isSettingChangeable('institution')) {
662            $user->setInstitution($this->form_gui->getInput('institution'));
663        }
664
665        // Department
666        if ($this->isSettingChangeable('department')) {
667            $user->setDepartment($this->form_gui->getInput('department'));
668        }
669        // Street
670        if ($this->isSettingChangeable('street')) {
671            $user->setStreet($this->form_gui->getInput('street'));
672        }
673        // City
674        if ($this->isSettingChangeable('city')) {
675            $user->setCity($this->form_gui->getInput('city'));
676        }
677        // Zipcode
678        if ($this->isSettingChangeable('zipcode')) {
679            $user->setZipcode($this->form_gui->getInput('zipcode'));
680        }
681        // Country
682        if ($this->isSettingChangeable('country')) {
683            $user->setCountry($this->form_gui->getInput('country'));
684        }
685        // Selected Country
686        if ($this->isSettingChangeable('sel_country')) {
687            $user->setSelectedCountry($this->form_gui->getInput('sel_country'));
688        }
689        // Phone Office
690        if ($this->isSettingChangeable('phone_office')) {
691            $user->setPhoneOffice($this->form_gui->getInput('phone_office'));
692        }
693        // Phone Home
694        if ($this->isSettingChangeable('phone_home')) {
695            $user->setPhoneHome($this->form_gui->getInput('phone_home'));
696        }
697        // Phone Mobile
698        if ($this->isSettingChangeable('phone_mobile')) {
699            $user->setPhoneMobile($this->form_gui->getInput('phone_mobile'));
700        }
701        // Fax
702        if ($this->isSettingChangeable('fax')) {
703            $user->setFax($this->form_gui->getInput('fax'));
704        }
705        // Matriculation
706        if ($this->isSettingChangeable('matriculation')) {
707            $user->setMatriculation($this->form_gui->getInput('matriculation'));
708        }
709        // Email
710        if ($this->isSettingChangeable('email')) {
711            $user->setEmail($this->form_gui->getInput('email'));
712        }
713        // Second Email
714        if ($this->isSettingChangeable('second_email')) {
715            $user->setSecondEmail($this->form_gui->getInput('second_email'));
716        }
717        // Hobby
718        if ($this->isSettingChangeable('hobby')) {
719            $user->setHobby($this->form_gui->getInput('hobby'));
720        }
721        // Referral Comment
722        if ($this->isSettingChangeable('referral_comment')) {
723            $user->setComment($this->form_gui->getInput('referral_comment'));
724        }
725
726        // interests
727        $user->setGeneralInterests($this->form_gui->getInput('interests_general'));
728        $user->setOfferingHelp($this->form_gui->getInput('interests_help_offered'));
729        $user->setLookingForHelp($this->form_gui->getInput('interests_help_looking'));
730
731        // ClientIP
732        $user->setClientIP($this->form_gui->getInput('client_ip'));
733
734        // Google maps
735        $user->setLatitude($this->form_gui->getInput('latitude'));
736        $user->setLongitude($this->form_gui->getInput('longitude'));
737        $user->setLocationZoom($this->form_gui->getInput('loc_zoom'));
738
739        // External account
740        $user->setAuthMode($this->form_gui->getInput('auth_mode'));
741        $user->setExternalAccount($this->form_gui->getInput('ext_account'));
742
743        if ((int) $user->getActive() != (int) $this->form_gui->getInput('active')) {
744            $user->setActive($this->form_gui->getInput('active'), $ilUser->getId());
745        }
746
747        return $user;
748    }
749
750
751    /**
752    * Update user
753    */
754    public function updateObject()
755    {
756        global $DIC;
757
758        $tpl = $DIC['tpl'];
759        $rbacsystem = $DIC['rbacsystem'];
760        $ilias = $DIC['ilias'];
761        $ilUser = $DIC['ilUser'];
762        $ilSetting = $DIC['ilSetting'];
763
764        // User folder
765        if ($this->usrf_ref_id == USER_FOLDER_ID and !$rbacsystem->checkAccess('visible,read,write', $this->usrf_ref_id)) {
766            $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
767        }
768        // if called from local administration $this->usrf_ref_id is category id
769        // Todo: this has to be fixed. Do not mix user folder id and category id
770        if ($this->usrf_ref_id != USER_FOLDER_ID) {
771            // check if user is assigned to category
772            if (!$rbacsystem->checkAccess('cat_administrate_users', $this->object->getTimeLimitOwner())) {
773                $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
774            }
775        }
776        $this->initForm("edit");
777
778        // we do not want to store this dates, they are only printed out
779        unset($_POST['approve_date']);
780        $_POST['agree_date'] = $this->object->getAgreeDate();
781        unset($_POST['last_login']);
782
783        // Manipulate form so ignore required fields are no more required. This has to be done before ilPropertyFormGUI::checkInput() is called.
784        $profileMaybeIncomplete = false;
785        if ($this->form_gui->getInput('ignore_rf', false)) {
786            $profileMaybeIncomplete = $this->handleIgnoredRequiredFields();
787        }
788
789        if ($this->form_gui->checkInput()) {
790            // @todo: external account; time limit
791            // if not allowed or empty -> do no change password
792            if (ilAuthUtils::_allowPasswordModificationByAuthMode(ilAuthUtils::_getAuthMode($_POST['auth_mode']))
793                && trim($_POST['passwd']) != "") {
794                $this->object->setPasswd($_POST['passwd'], IL_PASSWD_PLAIN);
795            }
796
797            /*
798             * reset counter for failed logins
799             * if $_POST['active'] is set to 1
800             */
801            if ($_POST['active'] == 1) {
802                ilObjUser::_resetLoginAttempts($this->object->getId());
803            }
804
805            #$this->object->assignData($_POST);
806            $this->loadValuesFromForm('update');
807
808            $udf = array();
809            foreach ($_POST as $k => $v) {
810                if (substr($k, 0, 4) == "udf_") {
811                    $udf[substr($k, 4)] = $v;
812                }
813            }
814            $this->object->setUserDefinedData($udf);
815
816            try {
817                $this->object->updateLogin($_POST['login']);
818            } catch (ilUserException $e) {
819                ilUtil::sendFailure($e->getMessage());
820                $this->form_gui->setValuesByPost();
821                return $tpl->setContent($this->form_gui->getHtml());
822            }
823
824            $this->object->setTitle($this->object->getFullname());
825            $this->object->setDescription($this->object->getEmail());
826
827            if ($this->isSettingChangeable('language')) {
828                $this->object->setLanguage($this->form_gui->getInput('language'));
829            }
830
831            require_once 'Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php';
832            if (ilDiskQuotaActivationChecker::_isActive()) {
833                // set disk quota
834                $this->object->setPref("disk_quota", ilUtil::MB2Bytes($_POST["disk_quota"]));
835            }
836            if (ilDiskQuotaActivationChecker::_isPersonalWorkspaceActive()) {
837                // set personal workspace disk quota
838                $this->object->setPref("wsp_disk_quota", ilUtil::MB2Bytes($_POST["wsp_disk_quota"]));
839            }
840
841            if ($this->isSettingChangeable('skin_style')) {
842                //set user skin and style
843                $sknst = explode(":", $_POST["skin_style"]);
844
845                if ($this->object->getPref("style") != $sknst[1] ||
846                    $this->object->getPref("skin") != $sknst[0]) {
847                    $this->object->setPref("skin", $sknst[0]);
848                    $this->object->setPref("style", $sknst[1]);
849                }
850            }
851            if ($this->isSettingChangeable('hits_per_page')) {
852                $this->object->setPref("hits_per_page", $_POST["hits_per_page"]);
853            }
854            /*if($this->isSettingChangeable('show_users_online'))
855            {
856                $this->object->setPref("show_users_online", $_POST["show_users_online"]);
857            }*/
858            if ($this->isSettingChangeable('hide_own_online_status')) {
859                $this->object->setPref("hide_own_online_status", $_POST["hide_own_online_status"]);
860            }
861            if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
862                $this->object->setPref('bs_allow_to_contact_me', $_POST['bs_allow_to_contact_me'] ? 'y' : 'n');
863            }
864            if ($this->isSettingChangeable('chat_osc_accept_msg')) {
865                $this->object->setPref('chat_osc_accept_msg', $_POST['chat_osc_accept_msg'] ? 'y' : 'n');
866            }
867
868            // set a timestamp for last_password_change
869            // this ts is needed by ilSecuritySettings
870            $this->object->setLastPasswordChangeTS(time());
871
872            global $DIC;
873
874            $ilSetting = $DIC['ilSetting'];
875            if ((int) $ilSetting->get('session_reminder_enabled')) {
876                $this->object->setPref('session_reminder_enabled', (int) $_POST['session_reminder_enabled']);
877            }
878
879            // #10054 - profile may have been completed, check below is only for incomplete
880            $this->object->setProfileIncomplete(false);
881
882            $this->update = $this->object->update();
883
884
885            // If the current user is editing its own user account,
886            // we update his preferences.
887            if ($ilUser->getId() == $this->object->getId()) {
888                $ilUser->readPrefs();
889            }
890            $ilUser->setPref('send_info_mails', ($_POST['send_mail'] == 'y') ? 'y' : 'n');
891            $ilUser->writePrefs();
892
893            $mail_message = $this->__sendProfileMail();
894            $msg = $this->lng->txt('saved_successfully') . $mail_message;
895
896            // same personal image
897            if ($this->isSettingChangeable('upload')) {
898                $this->uploadUserPictureObject();
899            }
900
901            if ($profileMaybeIncomplete) {
902                include_once 'Services/User/classes/class.ilUserProfile.php';
903                if (ilUserProfile::isProfileIncomplete($this->object)) {
904                    $this->object->setProfileIncomplete(true);
905                    $this->object->update();
906                }
907            }
908
909            // feedback
910            ilUtil::sendSuccess($msg, true);
911
912            if (strtolower($_GET["baseClass"]) == 'iladministrationgui') {
913                $this->ctrl->redirectByClass("ilobjuserfoldergui", "view");
914            } else {
915                $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
916            }
917        } else {
918            $this->form_gui->setValuesByPost();
919            $tpl->setContent($this->form_gui->getHtml());
920        }
921    }
922
923    /**
924    * Get values from user object and put them into form
925    */
926    public function getValues()
927    {
928        global $DIC;
929
930        $ilUser = $DIC['ilUser'];
931        $ilSetting = $DIC['ilSetting'];
932
933        $data = array();
934
935        // login data
936        $data["auth_mode"] = $this->object->getAuthMode();
937        $data["login"] = $this->object->getLogin();
938        //$data["passwd"] = "********";
939        //$data["passwd2"] = "********";
940        $data["ext_account"] = $this->object->getExternalAccount();
941
942        // system information
943        $data["create_date"] = ilDatePresentation::formatDate(new ilDateTime($this->object->getCreateDate(), IL_CAL_DATETIME));
944        $data["owner"] = ilObjUser::_lookupLogin($this->object->getOwner());
945        $data["approve_date"] = ($this->object->getApproveDate() != "")
946            ? ilDatePresentation::formatDate(new ilDateTime($this->object->getApproveDate(), IL_CAL_DATETIME))
947            : null;
948        $data["agree_date"] = ($this->object->getAgreeDate() != "")
949            ? ilDatePresentation::formatDate(new ilDateTime($this->object->getAgreeDate(), IL_CAL_DATETIME))
950            : null;
951        $data["last_login"] = ($this->object->getLastLogin() != "")
952             ? ilDatePresentation::formatDate(new ilDateTime($this->object->getLastLogin(), IL_CAL_DATETIME))
953             : null;
954        $data["active"] = $this->object->getActive();
955        $data["time_limit_unlimited"] = $this->object->getTimeLimitUnlimited();
956
957        $data["time_limit_from"] = $this->object->getTimeLimitFrom()
958            ? new ilDateTime($this->object->getTimeLimitFrom(), IL_CAL_UNIX)
959            : null;
960        $data["time_limit_until"] = $this->object->getTimeLimitUntil()
961            ? new ilDateTime($this->object->getTimeLimitUntil(), IL_CAL_UNIX)
962            : null;
963
964
965        // BEGIN DiskQuota, Show disk space used
966        require_once 'Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php';
967        if (ilDiskQuotaActivationChecker::_isActive()) {
968            $data["disk_quota"] = ilUtil::Bytes2MB($this->object->getDiskQuota());
969        }
970        if (ilDiskQuotaActivationChecker::_isPersonalWorkspaceActive()) {
971            $data["wsp_disk_quota"] = ilUtil::Bytes2MB($this->object->getPersonalWorkspaceDiskQuota());
972        }
973        // W. Randelshofer 2008-09-09: Deactivated display of disk space usage,
974        // because determining the disk space usage may take several minutes.
975        /*
976        require_once "Modules/File/classes/class.ilObjFileAccess.php";
977        require_once "Modules/HTMLLearningModule/classes/class.ilObjFileBasedLMAccess.php";
978        require_once "Modules/ScormAicc/classes/class.ilObjSAHSLearningModuleAccess.php";
979        require_once "Services/Mail/classes/class.ilObjMailAccess.php";
980        require_once "Modules/Forum/classes/class.ilObjForumAccess.php";
981        require_once "Modules/MediaCast/classes/class.ilObjMediaCastAccess.php";
982        $data["disk_space_used"] =
983            ilObjFileAccess::_getDiskSpaceUsedBy($this->object->getId(), true).'<br>'.
984            ilObjFileBasedLMAccess::_getDiskSpaceUsedBy($this->object->getId(), true).'<br>'.
985            ilObjSAHSLearningModuleAccess::_getDiskSpaceUsedBy($this->object->getId(), true).'<br>'.
986            ilObjMailAccess::_getDiskSpaceUsedBy($this->object->getId(), true).'<br>'.
987            ilObjForumAccess::_getDiskSpaceUsedBy($this->object->getId(), true).'<br>'.
988            ilObjMediaCastAccess::_getDiskSpaceUsedBy($this->object->getId(), true).'<br>';
989        */
990        // END DiskQuota, Show disk space used
991
992        // personal data
993        $data["gender"] = $this->object->getGender();
994        $data["firstname"] = $this->object->getFirstname();
995        $data["lastname"] = $this->object->getLastname();
996        $data["title"] = $this->object->getUTitle();
997        $data['birthday'] = $this->object->getBirthday()
998            ? new ilDate($this->object->getBirthday(), IL_CAL_DATE)
999            : null;
1000        $data["institution"] = $this->object->getInstitution();
1001        $data["department"] = $this->object->getDepartment();
1002        $data["street"] = $this->object->getStreet();
1003        $data["city"] = $this->object->getCity();
1004        $data["zipcode"] = $this->object->getZipcode();
1005        $data["country"] = $this->object->getCountry();
1006        $data["sel_country"] = $this->object->getSelectedCountry();
1007        $data["phone_office"] = $this->object->getPhoneOffice();
1008        $data["phone_home"] = $this->object->getPhoneHome();
1009        $data["phone_mobile"] = $this->object->getPhoneMobile();
1010        $data["fax"] = $this->object->getFax();
1011        $data["email"] = $this->object->getEmail();
1012        $data["second_email"] = $this->object->getSecondEmail();
1013        $data["hobby"] = $this->object->getHobby();
1014        $data["referral_comment"] = $this->object->getComment();
1015
1016        // interests
1017        $data["interests_general"] = $this->object->getGeneralInterests();
1018        $data["interests_help_offered"] = $this->object->getOfferingHelp();
1019        $data["interests_help_looking"] = $this->object->getLookingForHelp();
1020
1021        // other data
1022        $data["matriculation"] = $this->object->getMatriculation();
1023        $data["client_ip"] = $this->object->getClientIP();
1024
1025        // user defined fields
1026        include_once './Services/User/classes/class.ilUserDefinedFields.php';
1027        $this->user_defined_fields = ilUserDefinedFields::_getInstance();
1028        $user_defined_data = $this->object->getUserDefinedData();
1029        foreach ($this->user_defined_fields->getDefinitions() as $field_id => $definition) {
1030            $data["udf_" . $field_id] = $user_defined_data["f_" . $field_id];
1031        }
1032
1033        // settings
1034        $data["language"] = $this->object->getLanguage();
1035        $data["skin_style"] = $this->object->skin . ":" . $this->object->prefs["style"];
1036        $data["hits_per_page"] = $this->object->prefs["hits_per_page"];
1037        //$data["show_users_online"] = $this->object->prefs["show_users_online"];
1038        $data["hide_own_online_status"] = $this->object->prefs["hide_own_online_status"];
1039        $data['bs_allow_to_contact_me'] = $this->object->prefs['bs_allow_to_contact_me'] == 'y';
1040        $data['chat_osc_accept_msg'] = $this->object->prefs['chat_osc_accept_msg'] == 'y';
1041        $data["session_reminder_enabled"] = (int) $this->object->prefs["session_reminder_enabled"];
1042
1043        $data["send_mail"] = ($this->object->prefs['send_info_mails'] == 'y');
1044
1045
1046        $this->form_gui->setValuesByArray($data);
1047    }
1048
1049    /**
1050    * Init user form
1051    */
1052    public function initForm($a_mode)
1053    {
1054        global $DIC;
1055
1056        $lng = $DIC['lng'];
1057        $ilCtrl = $DIC['ilCtrl'];
1058        $styleDefinition = $DIC['styleDefinition'];
1059        $ilSetting = $DIC['ilSetting'];
1060        $ilClientIniFile = $DIC['ilClientIniFile'];
1061        $ilUser = $DIC['ilUser'];
1062
1063        $settings = $ilSetting->getAll();
1064
1065        include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1066
1067        $this->form_gui = new ilPropertyFormGUI();
1068        $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
1069        if ($a_mode == "create") {
1070            $this->form_gui->setTitle($lng->txt("usr_new"));
1071        } else {
1072            $this->form_gui->setTitle($lng->txt("usr_edit"));
1073        }
1074
1075        // login data
1076        $sec_l = new ilFormSectionHeaderGUI();
1077        $sec_l->setTitle($lng->txt("login_data"));
1078        $this->form_gui->addItem($sec_l);
1079
1080        // authentication mode
1081        include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
1082        $active_auth_modes = ilAuthUtils::_getActiveAuthModes();
1083        $am = new ilSelectInputGUI($lng->txt("auth_mode"), "auth_mode");
1084        $option = array();
1085        foreach ($active_auth_modes as $auth_name => $auth_key) {
1086            if ($auth_name == 'default') {
1087                $name = $this->lng->txt('auth_' . $auth_name) . " (" . $this->lng->txt('auth_' . ilAuthUtils::_getAuthModeName($auth_key)) . ")";
1088            } else {
1089                // begin-patch ldap_multiple
1090                #$name = $this->lng->txt('auth_'.$auth_name);
1091                include_once './Services/Authentication/classes/class.ilAuthUtils.php';
1092                $name = ilAuthUtils::getAuthModeTranslation($auth_key, $auth_name);
1093                // end-patch ldap_multiple
1094            }
1095            $option[$auth_name] = $name;
1096        }
1097        $am->setOptions($option);
1098        $this->form_gui->addItem($am);
1099
1100        if ($a_mode == "edit") {
1101            $id = new ilNonEditableValueGUI($lng->txt("usr_id"), "id");
1102            $id->setValue($this->object->getId());
1103            $this->form_gui->addItem($id);
1104        }
1105
1106        // login
1107        $lo = new ilUserLoginInputGUI($lng->txt("login"), "login");
1108        $lo->setRequired(true);
1109        if ($a_mode == "edit") {
1110            $lo->setCurrentUserId($this->object->getId());
1111            try {
1112                include_once 'Services/Calendar/classes/class.ilDate.php';
1113
1114                $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->object->getId());
1115                $lo->setInfo(
1116                    sprintf(
1117                        $this->lng->txt('usr_loginname_history_info'),
1118                        ilDatePresentation::formatDate(new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1119                        $last_history_entry[0]
1120                    )
1121                );
1122            } catch (ilUserException $e) {
1123            }
1124        }
1125
1126        $this->form_gui->addItem($lo);
1127
1128        // passwords
1129        // @todo: do not show passwords, if there is not a single auth, that
1130        // allows password setting
1131        {
1132            $pw = new ilPasswordInputGUI($lng->txt("passwd"), "passwd");
1133            $pw->setUseStripSlashes(false);
1134            $pw->setSize(32);
1135            $pw->setMaxLength(80); // #17221
1136            $pw->setValidateAuthPost("auth_mode");
1137            if ($a_mode == "create") {
1138                $pw->setRequiredOnAuth(true);
1139            }
1140            $pw->setInfo(ilUtil::getPasswordRequirementsInfo());
1141            $this->form_gui->addItem($pw);
1142        }
1143        // @todo: invisible/hidden passwords
1144
1145        // external account
1146        include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
1147        if (ilAuthUtils::_isExternalAccountEnabled()) {
1148            $ext = new ilTextInputGUI($lng->txt("user_ext_account"), "ext_account");
1149            $ext->setSize(40);
1150            $ext->setMaxLength(250);
1151            $ext->setInfo($lng->txt("user_ext_account_desc"));
1152            $this->form_gui->addItem($ext);
1153        }
1154
1155        // login data
1156        $sec_si = new ilFormSectionHeaderGUI();
1157        $sec_si->setTitle($this->lng->txt("system_information"));
1158        $this->form_gui->addItem($sec_si);
1159
1160        // create date, approve date, agreement date, last login
1161        if ($a_mode == "edit") {
1162            $sia = array("create_date", "approve_date", "agree_date", "last_login", "owner");
1163            foreach ($sia as $a) {
1164                $siai = new ilNonEditableValueGUI($lng->txt($a), $a);
1165                $this->form_gui->addItem($siai);
1166            }
1167        }
1168
1169        // active
1170        $ac = new ilCheckboxInputGUI($lng->txt("active"), "active");
1171        $ac->setChecked(true);
1172        $this->form_gui->addItem($ac);
1173
1174        // access	@todo: get fields right (names change)
1175        $lng->loadLanguageModule('crs');
1176
1177        // access
1178        $radg = new ilRadioGroupInputGUI($lng->txt("time_limit"), "time_limit_unlimited");
1179        $radg->setValue(1);
1180        $op1 = new ilRadioOption($lng->txt("user_access_unlimited"), 1);
1181        $radg->addOption($op1);
1182        $op2 = new ilRadioOption($lng->txt("user_access_limited"), 0);
1183        $radg->addOption($op2);
1184
1185        //		$ac = new ilCheckboxInputGUI($lng->txt("time_limit"), "time_limit_unlimited");
1186        //		$ac->setChecked(true);
1187        //		$ac->setOptionTitle($lng->txt("crs_unlimited"));
1188
1189        // access.from
1190        $acfrom = new ilDateTimeInputGUI($this->lng->txt("crs_from"), "time_limit_from");
1191        $acfrom->setRequired(true);
1192        $acfrom->setShowTime(true);
1193        //		$ac->addSubItem($acfrom);
1194        $op2->addSubItem($acfrom);
1195
1196        // access.to
1197        $acto = new ilDateTimeInputGUI($this->lng->txt("crs_to"), "time_limit_until");
1198        $acto->setRequired(true);
1199        $acto->setShowTime(true);
1200        //		$ac->addSubItem($acto);
1201        $op2->addSubItem($acto);
1202
1203        //		$this->form_gui->addItem($ac);
1204        $this->form_gui->addItem($radg);
1205
1206        require_once 'Services/WebDAV/classes/class.ilDiskQuotaActivationChecker.php';
1207        if (ilDiskQuotaActivationChecker::_isActive()) {
1208            $lng->loadLanguageModule("file");
1209
1210            $quota_head = new ilFormSectionHeaderGUI();
1211            $quota_head->setTitle($lng->txt("repository_disk_quota"));
1212            $this->form_gui->addItem($quota_head);
1213
1214            // disk quota
1215            $disk_quota = new ilTextInputGUI($lng->txt("disk_quota"), "disk_quota");
1216            $disk_quota->setSize(10);
1217            $disk_quota->setMaxLength(11);
1218            $disk_quota->setInfo($this->lng->txt("enter_in_mb_desc"));
1219            $this->form_gui->addItem($disk_quota);
1220
1221            if ($a_mode == "edit") {
1222                // show which disk quota is in effect, and explain why
1223                require_once 'Services/WebDAV/classes/class.ilDiskQuotaChecker.php';
1224                $dq_info = ilDiskQuotaChecker::_lookupDiskQuota($this->object->getId());
1225                if ($dq_info['user_disk_quota'] > $dq_info['role_disk_quota']) {
1226                    $info_text = sprintf(
1227                        $lng->txt('disk_quota_is_1_instead_of_2_by_3'),
1228                        ilUtil::formatSize($dq_info['user_disk_quota'], 'short'),
1229                        ilUtil::formatSize($dq_info['role_disk_quota'], 'short'),
1230                        $dq_info['role_title']
1231                    );
1232                } elseif (is_infinite($dq_info['role_disk_quota'])) {
1233                    $info_text = sprintf($lng->txt('disk_quota_is_unlimited_by_1'), $dq_info['role_title']);
1234                } else {
1235                    $info_text = sprintf(
1236                        $lng->txt('disk_quota_is_1_by_2'),
1237                        ilUtil::formatSize($dq_info['role_disk_quota'], 'short'),
1238                        $dq_info['role_title']
1239                    );
1240                }
1241                $disk_quota->setInfo($this->lng->txt("enter_in_mb_desc") . '<br>' . $info_text);
1242
1243
1244                // disk usage
1245                $du_info = ilDiskQuotaChecker::_lookupDiskUsage($this->object->getId());
1246                $disk_usage = new ilNonEditableValueGUI($lng->txt("disk_usage"), "disk_usage");
1247                if ($du_info['last_update'] === null) {
1248                    $disk_usage->setValue($lng->txt('unknown'));
1249                } else {
1250                    $disk_usage->setValue(ilUtil::formatSize($du_info['disk_usage'], 'short'));
1251                    $info = '<table class="il_user_quota_disk_usage_overview">';
1252                    // write the count and size of each object type
1253                    foreach ($du_info['details'] as $detail_data) {
1254                        $info .= '<tr>' .
1255                            '<td class="std">' . $detail_data['count'] . '</td>' .
1256                            '<td class="std">' . $lng->txt($detail_data['type']) . '</td>' .
1257                            '<td class="std">' . ilUtil::formatSize($detail_data['size'], 'short') . '</td>' .
1258                            '</tr>'
1259                            ;
1260                    }
1261                    $info .= '</table>';
1262                    $info .= '<br>' . $this->lng->txt('last_update') . ': ' .
1263                        ilDatePresentation::formatDate(new ilDateTime($du_info['last_update'], IL_CAL_DATETIME));
1264                    $disk_usage->setInfo($info);
1265                }
1266                $this->form_gui->addItem($disk_usage);
1267
1268                // date when the last disk quota reminder was sent to the user
1269                if (true || $dq_info['last_reminder']) {
1270                    $reminder = new ilNonEditableValueGUI($lng->txt("disk_quota_last_reminder_sent"), "last_reminder");
1271                    $reminder->setValue(
1272                        ilDatePresentation::formatDate(new ilDateTime($dq_info['last_reminder'], IL_CAL_DATETIME))
1273                    );
1274                    $reminder->setInfo($this->lng->txt("disk_quota_last_reminder_sent_desc"));
1275                    $this->form_gui->addItem($reminder);
1276                }
1277            }
1278        }
1279
1280        if (ilDiskQuotaActivationChecker::_isPersonalWorkspaceActive()) {
1281            $lng->loadLanguageModule("file");
1282
1283            $quota_head = new ilFormSectionHeaderGUI();
1284            $quota_head->setTitle($lng->txt("personal_workspace_disk_quota"));
1285            $this->form_gui->addItem($quota_head);
1286
1287            // personal workspace disk quota
1288            $wsp_disk_quota = new ilTextInputGUI($lng->txt("disk_quota"), "wsp_disk_quota");
1289            $wsp_disk_quota->setSize(10);
1290            $wsp_disk_quota->setMaxLength(11);
1291            $wsp_disk_quota->setInfo($this->lng->txt("enter_in_mb_desc"));
1292            $this->form_gui->addItem($wsp_disk_quota);
1293
1294            if ($a_mode == "edit") {
1295                // show which disk quota is in effect, and explain why
1296                require_once 'Services/WebDAV/classes/class.ilDiskQuotaChecker.php';
1297                $dq_info = ilDiskQuotaChecker::_lookupPersonalWorkspaceDiskQuota($this->object->getId());
1298                if ($dq_info['user_wsp_disk_quota'] > $dq_info['role_wsp_disk_quota']) {
1299                    $info_text = sprintf(
1300                        $lng->txt('disk_quota_is_1_instead_of_2_by_3'),
1301                        ilUtil::formatSize($dq_info['user_wsp_disk_quota'], 'short'),
1302                        ilUtil::formatSize($dq_info['role_wsp_disk_quota'], 'short'),
1303                        $dq_info['role_title']
1304                    );
1305                } elseif (is_infinite($dq_info['role_wsp_disk_quota'])) {
1306                    $info_text = sprintf($lng->txt('disk_quota_is_unlimited_by_1'), $dq_info['role_title']);
1307                } else {
1308                    $info_text = sprintf(
1309                        $lng->txt('disk_quota_is_1_by_2'),
1310                        ilUtil::formatSize($dq_info['role_wsp_disk_quota'], 'short'),
1311                        $dq_info['role_title']
1312                    );
1313                }
1314                $wsp_disk_quota->setInfo($this->lng->txt("enter_in_mb_desc") . '<br>' . $info_text);
1315            }
1316
1317            // disk usage
1318            include_once "Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1319            $du_info = ilDiskQuotaHandler::getFilesizeByTypeAndOwner($this->object->getId());
1320            $disk_usage = new ilNonEditableValueGUI($lng->txt("disk_usage"), "disk_usage");
1321            if (!sizeof($du_info)) {
1322                $disk_usage->setValue($lng->txt('unknown'));
1323            } else {
1324                $disk_usage->setValue(ilUtil::formatSize(ilDiskQuotaHandler::getFilesizeByOwner($this->object->getId())));
1325                $info = '<table class="il_user_quota_disk_usage_overview">';
1326                // write the count and size of each object type
1327                foreach ($du_info as $detail_data) {
1328                    $info .= '<tr>' .
1329                        '<td class="std">' . $detail_data['count'] . '</td>' .
1330                        '<td class="std">' . $lng->txt("obj_" . $detail_data["src_type"]) . '</td>' .
1331                        '<td class="std">' . ilUtil::formatSize($detail_data['filesize'], 'short') . '</td>' .
1332                        '</tr>'
1333                        ;
1334                }
1335                $info .= '</table>';
1336                $disk_usage->setInfo($info);
1337            }
1338            $this->form_gui->addItem($disk_usage);
1339        }
1340
1341        // personal data
1342        if (
1343            $this->isSettingChangeable('gender') or
1344            $this->isSettingChangeable('firstname') or
1345            $this->isSettingChangeable('lastname') or
1346            $this->isSettingChangeable('title') or
1347            $this->isSettingChangeable('personal_image') or
1348            $this->isSettingChangeable('birhtday')
1349        ) {
1350            $sec_pd = new ilFormSectionHeaderGUI();
1351            $sec_pd->setTitle($this->lng->txt("personal_data"));
1352            $this->form_gui->addItem($sec_pd);
1353        }
1354
1355        // gender
1356        if ($this->isSettingChangeable('gender')) {
1357            $gndr = new ilRadioGroupInputGUI($lng->txt("salutation"), "gender");
1358            $gndr->setRequired(isset($settings["require_gender"]) && $settings["require_gender"]);
1359            $neutral = new ilRadioOption($lng->txt("salutation_n"), "n");
1360            $gndr->addOption($neutral);
1361            $female = new ilRadioOption($lng->txt("salutation_f"), "f");
1362            $gndr->addOption($female);
1363            $male = new ilRadioOption($lng->txt("salutation_m"), "m");
1364            $gndr->addOption($male);
1365            $this->form_gui->addItem($gndr);
1366        }
1367
1368        // firstname, lastname, title
1369        $fields = array("firstname" => true, "lastname" => true,
1370            "title" => isset($settings["require_title"]) && $settings["require_title"]);
1371        foreach ($fields as $field => $req) {
1372            if ($this->isSettingChangeable($field)) {
1373                // #18795
1374                $caption = ($field == "title")
1375                    ? "person_title"
1376                    : $field;
1377                $inp = new ilTextInputGUI($lng->txt($caption), $field);
1378                $inp->setSize(32);
1379                $inp->setMaxLength(32);
1380                $inp->setRequired($req);
1381                $this->form_gui->addItem($inp);
1382            }
1383        }
1384
1385        // personal image
1386        if ($this->isSettingChangeable('upload')) {
1387            $pi = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile");
1388            if ($a_mode == "edit" || $a_mode == "upload") {
1389                $pi->setImage(ilObjUser::_getPersonalPicturePath(
1390                    $this->object->getId(),
1391                    "small",
1392                    true,
1393                    true
1394                ));
1395            }
1396            $this->form_gui->addItem($pi);
1397        }
1398
1399        if ($this->isSettingChangeable('birthday')) {
1400            $birthday = new ilBirthdayInputGUI($lng->txt('birthday'), 'birthday');
1401            $birthday->setRequired(isset($settings["require_birthday"]) && $settings["require_birthday"]);
1402            $this->form_gui->addItem($birthday);
1403        }
1404
1405
1406        // institution, department, street, city, zip code, country, phone office
1407        // phone home, phone mobile, fax, e-mail
1408        $fields = array(
1409            array("institution", 40, 80),
1410            array("department", 40, 80),
1411            array("street", 40, 40),
1412            array("city", 40, 40),
1413            array("zipcode", 10, 10),
1414            array("country", 40, 40),
1415            array("sel_country"),
1416            array("phone_office", 30, 30),
1417            array("phone_home", 30, 30),
1418            array("phone_mobile", 30, 30),
1419            array("fax", 30, 30));
1420
1421        $counter = 0;
1422        foreach ($fields as $field) {
1423            if (!$counter++ and $this->isSettingChangeable($field[0])) {
1424                // contact data
1425                $sec_cd = new ilFormSectionHeaderGUI();
1426                $sec_cd->setTitle($this->lng->txt("contact_data"));
1427                $this->form_gui->addItem($sec_cd);
1428
1429                // org units
1430                if ($a_mode == "edit") {
1431                    $orgus = new ilNonEditableValueGUI($lng->txt('objs_orgu'), 'org_units');
1432                    $orgus->setValue($this->object->getOrgUnitsRepresentation());
1433                    $this->form_gui->addItem($orgus);
1434                }
1435            }
1436            if ($this->isSettingChangeable($field[0])) {
1437                if ($field[0] != "sel_country") {
1438                    $inp = new ilTextInputGUI($lng->txt($field[0]), $field[0]);
1439                    $inp->setSize($field[1]);
1440                    $inp->setMaxLength($field[2]);
1441                    $inp->setRequired(isset($settings["require_" . $field[0]]) &&
1442                        $settings["require_" . $field[0]]);
1443                    $this->form_gui->addItem($inp);
1444                } else {
1445                    // country selection
1446                    include_once("./Services/Form/classes/class.ilCountrySelectInputGUI.php");
1447                    $cs = new ilCountrySelectInputGUI($lng->txt($field[0]), $field[0]);
1448                    $cs->setRequired(isset($settings["require_" . $field[0]]) &&
1449                        $settings["require_" . $field[0]]);
1450                    $this->form_gui->addItem($cs);
1451                }
1452            }
1453        }
1454
1455        // email
1456        if ($this->isSettingChangeable('email')) {
1457            $em = new ilEMailInputGUI($lng->txt("email"), "email");
1458            $em->setRequired(isset($settings["require_email"]) &&
1459                $settings["require_email"]);
1460            $this->form_gui->addItem($em);
1461        }
1462
1463        // second email
1464        if ($this->isSettingChangeable('second_email')) {
1465            $em = new ilEMailInputGUI($lng->txt("second_email"), "second_email");
1466
1467            $this->form_gui->addItem($em);
1468        }
1469
1470        // interests/hobbies
1471        if ($this->isSettingChangeable('hobby')) {
1472            $hob = new ilTextAreaInputGUI($lng->txt("hobby"), "hobby");
1473            $hob->setRows(3);
1474            $hob->setCols(40);
1475            $hob->setRequired(isset($settings["require_hobby"]) &&
1476                $settings["require_hobby"]);
1477            $this->form_gui->addItem($hob);
1478        }
1479
1480        // referral comment
1481        if ($this->isSettingChangeable('referral_comment')) {
1482            $rc = new ilTextAreaInputGUI($lng->txt("referral_comment"), "referral_comment");
1483            $rc->setRows(3);
1484            $rc->setCols(40);
1485            $rc->setRequired(isset($settings["require_referral_comment"]) &&
1486                $settings["require_referral_comment"]);
1487            $this->form_gui->addItem($rc);
1488        }
1489
1490
1491        // interests
1492
1493        $sh = new ilFormSectionHeaderGUI();
1494        $sh->setTitle($lng->txt("interests"));
1495        $this->form_gui->addItem($sh);
1496
1497        $multi_fields = array("interests_general", "interests_help_offered", "interests_help_looking");
1498        foreach ($multi_fields as $multi_field) {
1499            if ($this->isSettingChangeable($multi_field)) {
1500                // see ilUserProfile
1501                $ti = new ilTextInputGUI($lng->txt($multi_field), $multi_field);
1502                $ti->setMulti(true);
1503                $ti->setMaxLength(40);
1504                $ti->setSize(40);
1505                $ti->setRequired(isset($settings["require_" . $multi_field]) &&
1506                    $settings["require_" . $multi_field]);
1507                $this->form_gui->addItem($ti);
1508            }
1509        }
1510
1511
1512        // other information
1513        if ($this->isSettingChangeable('user_profile_other')) {
1514            $sec_oi = new ilFormSectionHeaderGUI();
1515            $sec_oi->setTitle($this->lng->txt("user_profile_other"));
1516            $this->form_gui->addItem($sec_oi);
1517        }
1518
1519        // matriculation number
1520        if ($this->isSettingChangeable('matriculation')) {
1521            $mr = new ilTextInputGUI($lng->txt("matriculation"), "matriculation");
1522            $mr->setSize(40);
1523            $mr->setMaxLength(40);
1524            $mr->setRequired(isset($settings["require_matriculation"]) &&
1525                $settings["require_matriculation"]);
1526            $this->form_gui->addItem($mr);
1527        }
1528
1529        // client IP
1530        $ip = new ilTextInputGUI($lng->txt("client_ip"), "client_ip");
1531        $ip->setSize(40);
1532        $ip->setMaxLength(255);
1533        $ip->setInfo($this->lng->txt("current_ip") . " " . $_SERVER["REMOTE_ADDR"] . " <br />" .
1534            '<span class="warning">' . $this->lng->txt("current_ip_alert") . "</span>");
1535        $this->form_gui->addItem($ip);
1536
1537        // additional user defined fields
1538        include_once './Services/User/classes/class.ilUserDefinedFields.php';
1539        $user_defined_fields = ilUserDefinedFields::_getInstance();
1540
1541        if ($this->usrf_ref_id == USER_FOLDER_ID) {
1542            $all_defs = $user_defined_fields->getDefinitions();
1543        } else {
1544            $all_defs = $user_defined_fields->getChangeableLocalUserAdministrationDefinitions();
1545        }
1546
1547        foreach ($all_defs as $field_id => $definition) {
1548            include_once './Services/User/classes/class.ilCustomUserFieldsHelper.php';
1549            $f_property = ilCustomUserFieldsHelper::getInstance()->getFormPropertyForDefinition($definition, true);
1550            if ($f_property instanceof ilFormPropertyGUI) {
1551                $this->form_gui->addItem($f_property);
1552            }
1553        }
1554
1555        // settings
1556        if (
1557            $a_mode == 'create' or
1558            $this->isSettingChangeable('language') or
1559            $this->isSettingChangeable('skin_style') or
1560            $this->isSettingChangeable('hits_per_page') or
1561            $this->isSettingChangeable('hide_own_online_status') or
1562            $this->isSettingChangeable('bs_allow_to_contact_me') or
1563            $this->isSettingChangeable('chat_osc_accept_msg')
1564        ) {
1565            $sec_st = new ilFormSectionHeaderGUI();
1566            $sec_st->setTitle($this->lng->txt("settings"));
1567            $this->form_gui->addItem($sec_st);
1568        }
1569
1570        // role
1571        if ($a_mode == "create") {
1572            $role = new ilSelectInputGUI(
1573                $lng->txt("default_role"),
1574                'default_role'
1575            );
1576            $role->setRequired(true);
1577            $role->setValue($this->default_role);
1578            $role->setOptions($this->selectable_roles);
1579            $this->form_gui->addItem($role);
1580        }
1581
1582        // language
1583        if ($this->isSettingChangeable('language')) {
1584            $lang = new ilSelectInputGUI(
1585                $lng->txt("language"),
1586                'language'
1587            );
1588            $languages = $lng->getInstalledLanguages();
1589            $lng->loadLanguageModule("meta");
1590            $options = array();
1591            foreach ($languages as $l) {
1592                $options[$l] = $lng->txt("meta_l_" . $l);
1593            }
1594            $lang->setOptions($options);
1595            $lang->setValue($ilSetting->get("language"));
1596            $this->form_gui->addItem($lang);
1597        }
1598
1599        // skin/style
1600        if ($this->isSettingChangeable('skin_style')) {
1601            $sk = new ilSelectInputGUI(
1602                $lng->txt("skin_style"),
1603                'skin_style'
1604            );
1605            /**
1606             * @var ilStyleDefinition $styleDefinition
1607             */
1608            $skins = $styleDefinition->getAllSkins();
1609
1610            $options = array();
1611            if (is_array($skins)) {
1612                $sk = new ilSelectInputGUI($this->lng->txt("skin_style"), "skin_style");
1613
1614                $options = array();
1615                foreach ($skins as $skin) {
1616                    foreach ($skin->getStyles() as $style) {
1617                        include_once("./Services/Style/System/classes/class.ilSystemStyleSettings.php");
1618                        if (!ilSystemStyleSettings::_lookupActivatedStyle($skin->getId(), $style->getId())) {
1619                            continue;
1620                        }
1621
1622                        $options[$skin->getId() . ":" . $style->getId()] = $skin->getName() . " / " . $style->getName();
1623                    }
1624                }
1625            }
1626            $sk->setOptions($options);
1627            $sk->setValue($ilClientIniFile->readVariable("layout", "skin") .
1628                    ":" . $ilClientIniFile->readVariable("layout", "style"));
1629
1630            $this->form_gui->addItem($sk);
1631        }
1632
1633        // hits per page
1634        if ($this->isSettingChangeable('hits_per_page')) {
1635            $hpp = new ilSelectInputGUI(
1636                $lng->txt("hits_per_page"),
1637                'hits_per_page'
1638            );
1639            $options = array(10 => 10, 15 => 15, 20 => 20, 30 => 30, 40 => 40,
1640                50 => 50, 100 => 100, 9999 => $this->lng->txt("no_limit"));
1641            $hpp->setOptions($options);
1642            $hpp->setValue($ilSetting->get("hits_per_page"));
1643            $this->form_gui->addItem($hpp);
1644
1645            // users online
1646            /*$uo = new ilSelectInputGUI($lng->txt("users_online"),
1647                'show_users_online');
1648            $options = array(
1649                "y" => $lng->txt("users_online_show_y"),
1650                "associated" => $lng->txt("users_online_show_associated"),
1651                "n" => $lng->txt("users_online_show_n"));
1652            $uo->setOptions($options);
1653            $uo->setValue($ilSetting->get("show_users_online"));
1654            $this->form_gui->addItem($uo);*/
1655        }
1656
1657        // hide online status
1658        if ($this->isSettingChangeable('hide_own_online_status')) {
1659            $lng->loadLanguageModule("awrn");
1660
1661            $default = ($ilSetting->get('hide_own_online_status') == "n")
1662                ? $this->lng->txt("user_awrn_show")
1663                : $this->lng->txt("user_awrn_hide");
1664
1665            $options = array(
1666                "" => $this->lng->txt("user_awrn_default")." (".$default.")",
1667                "n" => $this->lng->txt("user_awrn_show"),
1668                "y" => $this->lng->txt("user_awrn_hide"));
1669            $os = new ilSelectInputGUI($lng->txt("awrn_user_show"), "hide_own_online_status");
1670            $os->setOptions($options);
1671            $os->setDisabled($ilSetting->get("usr_settings_disable_hide_own_online_status"));
1672            $os->setInfo($lng->txt("awrn_hide_from_awareness_info"));
1673            $this->form_gui->addItem($os);
1674
1675
1676            //$os = new ilCheckboxInputGUI($lng->txt("awrn_hide_from_awareness"), "hide_own_online_status");
1677            //$this->form_gui->addItem($os);
1678        }
1679
1680        // allow to contact me
1681        if ($this->isSettingChangeable('bs_allow_to_contact_me')) {
1682            $lng->loadLanguageModule('buddysystem');
1683            $os = new ilCheckboxInputGUI($lng->txt('buddy_allow_to_contact_me'), 'bs_allow_to_contact_me');
1684            if ($a_mode == 'create') {
1685                $os->setChecked(ilUtil::yn2tf($ilSetting->get('bs_allow_to_contact_me', 'n')));
1686            }
1687            $this->form_gui->addItem($os);
1688        }
1689        if ($this->isSettingChangeable('chat_osc_accept_msg')) {
1690            $lng->loadLanguageModule('chatroom');
1691            $chat_osc_acm = new ilCheckboxInputGUI($lng->txt('chat_osc_accept_msg'), 'chat_osc_accept_msg');
1692            if ($a_mode == 'create') {
1693                $chat_osc_acm->setChecked(ilUtil::yn2tf($ilSetting->get('chat_osc_accept_msg', 'n')));
1694            }
1695            $this->form_gui->addItem($chat_osc_acm);
1696        }
1697
1698        if ((int) $ilSetting->get('session_reminder_enabled')) {
1699            $cb = new ilCheckboxInputGUI($this->lng->txt('session_reminder'), 'session_reminder_enabled');
1700            $cb->setValue(1);
1701            $this->form_gui->addItem($cb);
1702        }
1703
1704        // Options
1705        if ($this->isSettingChangeable('send_mail')) {
1706            $sec_op = new ilFormSectionHeaderGUI();
1707            $sec_op->setTitle($this->lng->txt("options"));
1708            $this->form_gui->addItem($sec_op);
1709        }
1710
1711        // send email
1712        $se = new ilCheckboxInputGUI($lng->txt('inform_user_mail'), 'send_mail');
1713        $se->setInfo($lng->txt('inform_user_mail_info'));
1714        $se->setValue('y');
1715        $se->setChecked(($ilUser->getPref('send_info_mails') == 'y'));
1716        $this->form_gui->addItem($se);
1717
1718        // ignore required fields
1719        $irf = new ilCheckboxInputGUI($lng->txt('ignore_required_fields'), 'ignore_rf');
1720        $irf->setInfo($lng->txt('ignore_required_fields_info'));
1721        $irf->setValue(1);
1722        $this->form_gui->addItem($irf);
1723
1724        // @todo: handle all required fields
1725
1726        // command buttons
1727        if ($a_mode == "create" || $a_mode == "save") {
1728            $this->form_gui->addCommandButton("save", $lng->txt("save"));
1729        }
1730        if ($a_mode == "edit" || $a_mode == "update") {
1731            $this->form_gui->addCommandButton("update", $lng->txt("save"));
1732        }
1733        $this->form_gui->addCommandButton("cancel", $lng->txt("cancel"));
1734    }
1735
1736    /**
1737     * Check if setting is visible
1738     * This is the case when called from user folder.
1739     * Otherwise (category local user account depend on a setting)
1740     * @param array $settings
1741     * @param string $a_field
1742     * @return
1743     */
1744    protected function isSettingChangeable($a_field)
1745    {
1746        // TODO: Allow mixed field parameter to support checks against an array of field names.
1747
1748        global $DIC;
1749
1750        $ilSetting = $DIC['ilSetting'];
1751        static $settings = null;
1752
1753
1754
1755        if ($this->usrf_ref_id == USER_FOLDER_ID) {
1756            return true;
1757        }
1758
1759        if ($settings == null) {
1760            $settings = $ilSetting->getAll();
1761        }
1762        return (bool) $settings['usr_settings_changeable_lua_' . $a_field];
1763    }
1764
1765
1766    // BEGIN DiskQuota: Allow administrators to edit user picture
1767    /**
1768    * upload user image
1769    *
1770    * (original method by ratana ty)
1771    */
1772    public function uploadUserPictureObject()
1773    {
1774        global $DIC;
1775
1776        $ilUser = $DIC['ilUser'];
1777        $rbacsystem = $DIC['rbacsystem'];
1778
1779        // User folder
1780        if ($this->usrf_ref_id == USER_FOLDER_ID and
1781            !$rbacsystem->checkAccess('visible,read', $this->usrf_ref_id)) {
1782            $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
1783        }
1784        // if called from local administration $this->usrf_ref_id is category id
1785        // Todo: this has to be fixed. Do not mix user folder id and category id
1786        if ($this->usrf_ref_id != USER_FOLDER_ID) {
1787            // check if user is assigned to category
1788            if (!$rbacsystem->checkAccess('cat_administrate_users', $this->object->getTimeLimitOwner())) {
1789                $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
1790            }
1791        }
1792
1793        $userfile_input = $this->form_gui->getItemByPostVar("userfile");
1794
1795        if ($_FILES["userfile"]["tmp_name"] == "") {
1796            if ($userfile_input->getDeletionFlag()) {
1797                $this->object->removeUserPicture();
1798            }
1799            return;
1800        }
1801        if ($_FILES["userfile"]["size"] == 0) {
1802            ilUtil::sendFailure($this->lng->txt("msg_no_file"));
1803        } else {
1804            $webspace_dir = ilUtil::getWebspaceDir();
1805            $image_dir = $webspace_dir . "/usr_images";
1806            $store_file = "usr_" . $this->object->getId() . "." . "jpg";
1807
1808            // store filename
1809            $this->object->setPref("profile_image", $store_file);
1810            $this->object->update();
1811
1812            // move uploaded file
1813            $pi = pathinfo($_FILES["userfile"]["name"]);
1814            $uploaded_file = $image_dir . "/upload_" . $this->object->getId() . "." . $pi["extension"];
1815            if (!ilUtil::moveUploadedFile(
1816                $_FILES["userfile"]["tmp_name"],
1817                $_FILES["userfile"]["name"],
1818                $uploaded_file,
1819                false
1820            )) {
1821                ilUtil::sendFailure($this->lng->txt("upload_error", true));
1822                $this->ctrl->redirect($this, "showProfile");
1823            }
1824            chmod($uploaded_file, 0770);
1825
1826            // take quality 100 to avoid jpeg artefacts when uploading jpeg files
1827            // taking only frame [0] to avoid problems with animated gifs
1828            $show_file = "$image_dir/usr_" . $this->object->getId() . ".jpg";
1829            $thumb_file = "$image_dir/usr_" . $this->object->getId() . "_small.jpg";
1830            $xthumb_file = "$image_dir/usr_" . $this->object->getId() . "_xsmall.jpg";
1831            $xxthumb_file = "$image_dir/usr_" . $this->object->getId() . "_xxsmall.jpg";
1832            $uploaded_file = ilUtil::escapeShellArg($uploaded_file);
1833            $show_file = ilUtil::escapeShellArg($show_file);
1834            $thumb_file = ilUtil::escapeShellArg($thumb_file);
1835            $xthumb_file = ilUtil::escapeShellArg($xthumb_file);
1836            $xxthumb_file = ilUtil::escapeShellArg($xxthumb_file);
1837
1838            if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
1839                ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200^ -gravity center -extent 200x200 -quality 100 JPEG:" . $show_file);
1840                ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100^ -gravity center -extent 100x100 -quality 100 JPEG:" . $thumb_file);
1841                ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75^ -gravity center -extent 75x75 -quality 100 JPEG:" . $xthumb_file);
1842                ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30^ -gravity center -extent 30x30 -quality 100 JPEG:" . $xxthumb_file);
1843            } else {
1844                ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
1845                ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
1846                ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
1847                ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
1848            }
1849        }
1850    }
1851
1852    /**
1853    * remove user image
1854    */
1855    public function removeUserPictureObject()
1856    {
1857        $webspace_dir = ilUtil::getWebspaceDir();
1858        $image_dir = $webspace_dir . "/usr_images";
1859        $file = $image_dir . "/usr_" . $this->object->getID() . "." . "jpg";
1860        $thumb_file = $image_dir . "/usr_" . $this->object->getID() . "_small.jpg";
1861        $xthumb_file = $image_dir . "/usr_" . $this->object->getID() . "_xsmall.jpg";
1862        $xxthumb_file = $image_dir . "/usr_" . $this->object->getID() . "_xxsmall.jpg";
1863        $upload_file = $image_dir . "/upload_" . $this->object->getID();
1864
1865        // remove user pref file name
1866        $this->object->setPref("profile_image", "");
1867        $this->object->update();
1868        ilUtil::sendSuccess($this->lng->txt("user_image_removed"));
1869
1870        if (@is_file($file)) {
1871            unlink($file);
1872        }
1873        if (@is_file($thumb_file)) {
1874            unlink($thumb_file);
1875        }
1876        if (@is_file($xthumb_file)) {
1877            unlink($xthumb_file);
1878        }
1879        if (@is_file($xxthumb_file)) {
1880            unlink($xxthumb_file);
1881        }
1882        if (@is_file($upload_file)) {
1883            unlink($upload_file);
1884        }
1885
1886        $this->editObject();
1887    }
1888    // END DiskQuota: Allow administrators to edit user picture
1889
1890    /**
1891    * assign users to role
1892    *
1893    * @access	public
1894    */
1895    public function assignSaveObject()
1896    {
1897        global $DIC;
1898
1899        $rbacsystem = $DIC['rbacsystem'];
1900        $rbacadmin = $DIC['rbacadmin'];
1901        $rbacreview = $DIC['rbacreview'];
1902
1903        if (!$rbacsystem->checkAccess("edit_roleassignment", $this->usrf_ref_id)) {
1904            $this->ilias->raiseError($this->lng->txt("msg_no_perm_assign_role_to_user"), $this->ilias->error_obj->MESSAGE);
1905        }
1906
1907        $selected_roles = $_POST["role_id"] ? $_POST["role_id"] : array();
1908        $posted_roles = $_POST["role_id_ctrl"] ? $_POST["role_id_ctrl"] : array();
1909
1910        // prevent unassignment of system role from system user
1911        if ($this->object->getId() == SYSTEM_USER_ID and in_array(SYSTEM_ROLE_ID, $posted_roles)) {
1912            array_push($selected_roles, SYSTEM_ROLE_ID);
1913        }
1914
1915        $global_roles_all = $rbacreview->getGlobalRoles();
1916        $assigned_roles_all = $rbacreview->assignedRoles($this->object->getId());
1917        $assigned_roles = array_intersect($assigned_roles_all, $posted_roles);
1918        $assigned_global_roles_all = array_intersect($assigned_roles_all, $global_roles_all);
1919        $assigned_global_roles = array_intersect($assigned_global_roles_all, $posted_roles);
1920        $posted_global_roles = array_intersect($selected_roles, $global_roles_all);
1921
1922        if ((empty($selected_roles) and count($assigned_roles_all) == count($assigned_roles))
1923             or (empty($posted_global_roles) and count($assigned_global_roles_all) == count($assigned_global_roles))) {
1924            //$this->ilias->raiseError($this->lng->txt("msg_min_one_role")."<br/>".$this->lng->txt("action_aborted"),$this->ilias->error_obj->MESSAGE);
1925            // workaround. sometimes jumps back to wrong page
1926            ilUtil::sendFailure($this->lng->txt("msg_min_one_role") . "<br/>" . $this->lng->txt("action_aborted"), true);
1927            $this->ctrl->redirect($this, 'roleassignment');
1928        }
1929
1930        foreach (array_diff($assigned_roles, $selected_roles) as $role) {
1931            $rbacadmin->deassignUser($role, $this->object->getId());
1932        }
1933
1934        foreach (array_diff($selected_roles, $assigned_roles) as $role) {
1935            $rbacadmin->assignUser($role, $this->object->getId(), false);
1936        }
1937
1938        include_once "./Services/AccessControl/classes/class.ilObjRole.php";
1939
1940        // update object data entry (to update last modification date)
1941        $this->object->update();
1942
1943        ilUtil::sendSuccess($this->lng->txt("msg_roleassignment_changed"), true);
1944
1945        if (strtolower($_GET["baseClass"]) == 'iladministrationgui') {
1946            $this->ctrl->redirect($this, 'roleassignment');
1947        } else {
1948            $this->ctrl->redirectByClass('ilobjcategorygui', 'listUsers');
1949        }
1950    }
1951
1952    /**
1953    * display roleassignment panel
1954    *
1955    * @access	public
1956    */
1957    public function roleassignmentObject()
1958    {
1959        global $DIC;
1960
1961        $rbacreview = $DIC['rbacreview'];
1962        $rbacsystem = $DIC['rbacsystem'];
1963        $ilUser = $DIC['ilUser'];
1964        $ilTabs = $DIC['ilTabs'];
1965
1966        $ilTabs->activateTab("role_assignment");
1967
1968        if (!$rbacsystem->checkAccess("edit_roleassignment", $this->usrf_ref_id)) {
1969            $this->ilias->raiseError($this->lng->txt("msg_no_perm_assign_role_to_user"), $this->ilias->error_obj->MESSAGE);
1970        }
1971
1972        $_SESSION['filtered_roles'] = isset($_POST['filter']) ? $_POST['filter'] : $_SESSION['filtered_roles'];
1973
1974        if ($_SESSION['filtered_roles'] > 5) {
1975            $_SESSION['filtered_roles'] = 0;
1976        }
1977
1978        $this->tpl->addBlockfile('ADM_CONTENT', 'adm_content', 'tpl.usr_role_assignment.html', 'Services/User');
1979
1980        if (false) {
1981            $this->tpl->setCurrentBlock("filter");
1982            $this->tpl->setVariable("FILTER_TXT_FILTER", $this->lng->txt('filter'));
1983            $this->tpl->setVariable("SELECT_FILTER", $this->__buildFilterSelect());
1984            $this->tpl->setVariable("FILTER_ACTION", $this->ctrl->getFormAction($this));
1985            $this->tpl->setVariable("FILTER_NAME", 'roleassignment');
1986            $this->tpl->setVariable("FILTER_VALUE", $this->lng->txt('apply_filter'));
1987            $this->tpl->parseCurrentBlock();
1988        }
1989
1990        // init table
1991        include_once("./Services/User/classes/class.ilRoleAssignmentTableGUI.php");
1992        $tab = new ilRoleAssignmentTableGUI($this, "roleassignment");
1993
1994        // now get roles depending on filter settings
1995        $role_list = $rbacreview->getRolesByFilter($tab->filter["role_filter"], $this->object->getId());
1996        $assigned_roles = $rbacreview->assignedRoles($this->object->getId());
1997
1998        $counter = 0;
1999
2000        include_once('./Services/AccessControl/classes/class.ilObjRole.php');
2001
2002        $records = array();
2003        foreach ($role_list as $role) {
2004            // fetch context path of role
2005            $rolf = $rbacreview->getFoldersAssignedToRole($role["obj_id"], true);
2006
2007            // only list roles that are not set to status "deleted"
2008            if ($rbacreview->isDeleted($rolf[0])) {
2009                continue;
2010            }
2011
2012            // build context path
2013            $path = "";
2014
2015            if ($this->tree->isInTree($rolf[0])) {
2016                if ($rolf[0] == ROLE_FOLDER_ID) {
2017                    $path = $this->lng->txt("global");
2018                } else {
2019                    $tmpPath = $this->tree->getPathFull($rolf[0]);
2020
2021                    // count -1, to exclude the role folder itself
2022                    /*for ($i = 1; $i < (count($tmpPath)-1); $i++)
2023                    {
2024                        if ($path != "")
2025                        {
2026                            $path .= " > ";
2027                        }
2028
2029                        $path .= $tmpPath[$i]["title"];
2030                    }*/
2031
2032                    $path = $tmpPath[count($tmpPath) - 1]["title"];
2033                }
2034            } else {
2035                $path = "<b>Rolefolder " . $rolf[0] . " not found in tree! (Role " . $role["obj_id"] . ")</b>";
2036            }
2037
2038            $disabled = false;
2039
2040            // disable checkbox for system role for the system user
2041            if (($this->object->getId() == SYSTEM_USER_ID and $role["obj_id"] == SYSTEM_ROLE_ID)
2042                or (!in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId())) and $role["obj_id"] == SYSTEM_ROLE_ID)) {
2043                $disabled = true;
2044            }
2045
2046            // protected admin role
2047            if ($role['obj_id'] == SYSTEM_ROLE_ID && !$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID)) {
2048                include_once './Services/PrivacySecurity/classes/class.ilSecuritySettings.php';
2049                if (ilSecuritySettings::_getInstance()->isAdminRoleProtected()) {
2050                    $disabled = true;
2051                }
2052            }
2053
2054            if (substr($role["title"], 0, 3) == "il_") {
2055                if (!$assignable) {
2056                    $rolf_arr = $rbacreview->getFoldersAssignedToRole($role["obj_id"], true);
2057                    $rolf2 = $rolf_arr[0];
2058                } else {
2059                    $rolf2 = $rolf;
2060                }
2061
2062                $parent_node = $this->tree->getNodeData($rolf2);
2063
2064                $role["description"] = $this->lng->txt("obj_" . $parent_node["type"]) . "&nbsp;(#" . $parent_node["obj_id"] . ")";
2065            }
2066
2067            $role_ids[$counter] = $role["obj_id"];
2068
2069            $result_set[$counter][] = $checkbox = ilUtil::formCheckBox(in_array($role["obj_id"], $assigned_roles), "role_id[]", $role["obj_id"], $disabled) . "<input type=\"hidden\" name=\"role_id_ctrl[]\" value=\"" . $role["obj_id"] . "\"/>";
2070            $this->ctrl->setParameterByClass("ilobjrolegui", "ref_id", $rolf[0]);
2071            $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $role["obj_id"]);
2072            $result_set[$counter][] = $link = "<a href=\"" . $this->ctrl->getLinkTargetByClass("ilobjrolegui", "perm") . "\">" . ilObjRole::_getTranslation($role["title"]) . "</a>";
2073            $title = ilObjRole::_getTranslation($role["title"]);
2074            $result_set[$counter][] = $role["description"];
2075
2076            // Add link to objector local Rores
2077            if ($role["role_type"] == "local") {
2078                // Get Object to the role
2079                $obj_id = $rbacreview->getObjectOfRole($role["rol_id"]);
2080
2081                $obj_type = ilObject::_lookupType($obj_id);
2082
2083                $ref_ids = ilObject::_getAllReferences($obj_id);
2084
2085                foreach ($ref_ids as $ref_id) {
2086                }
2087
2088                require_once("./Services/Link/classes/class.ilLink.php");
2089
2090                $result_set[$counter][] = $context = "<a href='" . ilLink::_getLink($ref_id, ilObject::_lookupType($obj_id)) . "' target='_top'>" . $path . "</a>";
2091            } else {
2092                $result_set[$counter][] = $path;
2093                $context = $path;
2094            }
2095
2096            $records[] = array("path" => $path, "description" => $role["description"],
2097                "context" => $context, "checkbox" => $checkbox,
2098                "role" => $link, "title" => $title);
2099            ++$counter;
2100        }
2101
2102        if (true) {
2103            $tab->setData($records);
2104            $this->tpl->setVariable("ROLES_TABLE", $tab->getHTML());
2105            return;
2106        }
2107    }
2108
2109    /**
2110    * Apply filter
2111    */
2112    public function applyFilterObject()
2113    {
2114        include_once("./Services/User/classes/class.ilRoleAssignmentTableGUI.php");
2115        $table_gui = new ilRoleAssignmentTableGUI($this, "roleassignment");
2116        $table_gui->writeFilterToSession();        // writes filter to session
2117        $table_gui->resetOffset();                // sets record offest to 0 (first page)
2118        $this->roleassignmentObject();
2119    }
2120
2121    /**
2122    * Reset filter
2123    */
2124    public function resetFilterObject()
2125    {
2126        include_once("./Services/User/classes/class.ilRoleAssignmentTableGUI.php");
2127        $table_gui = new ilRoleAssignmentTableGUI($this, "roleassignment");
2128        $table_gui->resetOffset();                // sets record offest to 0 (first page)
2129        $table_gui->resetFilter();                // clears filter
2130        $this->roleassignmentObject();
2131    }
2132
2133    public function __getDateSelect($a_type, $a_varname, $a_selected)
2134    {
2135        switch ($a_type) {
2136            case "minute":
2137                for ($i = 0;$i <= 60;$i++) {
2138                    $days[$i] = $i < 10 ? "0" . $i : $i;
2139                }
2140                return ilUtil::formSelect($a_selected, $a_varname, $days, false, true);
2141
2142            case "hour":
2143                for ($i = 0;$i < 24;$i++) {
2144                    $days[$i] = $i < 10 ? "0" . $i : $i;
2145                }
2146                return ilUtil::formSelect($a_selected, $a_varname, $days, false, true);
2147
2148            case "day":
2149                for ($i = 1;$i < 32;$i++) {
2150                    $days[$i] = $i < 10 ? "0" . $i : $i;
2151                }
2152                return ilUtil::formSelect($a_selected, $a_varname, $days, false, true);
2153
2154            case "month":
2155                for ($i = 1;$i < 13;$i++) {
2156                    $month[$i] = $i < 10 ? "0" . $i : $i;
2157                }
2158                return ilUtil::formSelect($a_selected, $a_varname, $month, false, true);
2159
2160            case "year":
2161                if ($a_selected < date('Y', time())) {
2162                    $start = $a_selected;
2163                } else {
2164                    $start = date('Y', time());
2165                }
2166
2167                for ($i = $start;$i < date("Y", time()) + 11;++$i) {
2168                    $year[$i] = $i;
2169                }
2170                return ilUtil::formSelect($a_selected, $a_varname, $year, false, true);
2171        }
2172    }
2173
2174    public function __toUnix($a_time_arr)
2175    {
2176        return mktime(
2177            $a_time_arr["hour"],
2178            $a_time_arr["minute"],
2179            $a_time_arr["second"],
2180            $a_time_arr["month"],
2181            $a_time_arr["day"],
2182            $a_time_arr["year"]
2183        );
2184    }
2185
2186
2187
2188
2189    public function __unsetSessionVariables()
2190    {
2191        unset($_SESSION["filtered_roles"]);
2192    }
2193
2194    public function __buildFilterSelect()
2195    {
2196        $action[0] = $this->lng->txt('assigned_roles');
2197        $action[1] = $this->lng->txt('all_roles');
2198        $action[2] = $this->lng->txt('all_global_roles');
2199        $action[3] = $this->lng->txt('all_local_roles');
2200        $action[4] = $this->lng->txt('internal_local_roles_only');
2201        $action[5] = $this->lng->txt('non_internal_local_roles_only');
2202
2203        return ilUtil::formSelect($_SESSION['filtered_roles'], "filter", $action, false, true);
2204    }
2205
2206    public function hitsperpageObject()
2207    {
2208        parent::hitsperpageObject();
2209        $this->roleassignmentObject();
2210    }
2211
2212    /**
2213    * should be overwritten to add object specific items
2214    * (repository items are preloaded)
2215    */
2216    public function addAdminLocatorItems($a_do_not_add_object = false)
2217    {
2218        global $DIC;
2219
2220        $ilLocator = $DIC['ilLocator'];
2221
2222        $ilLocator->clearItems();
2223
2224        if ($_GET["admin_mode"] == "settings") {	// system settings
2225            $this->ctrl->setParameterByClass(
2226                "ilobjsystemfoldergui",
2227                "ref_id",
2228                SYSTEM_FOLDER_ID
2229            );
2230            $ilLocator->addItem(
2231                $this->lng->txt("administration"),
2232                $this->ctrl->getLinkTargetByClass(array("iladministrationgui", "ilobjsystemfoldergui"), ""),
2233                ilFrameTargetInfo::_getFrame("MainContent")
2234            );
2235
2236            if ($_GET['ref_id'] == USER_FOLDER_ID) {
2237                $ilLocator->addItem(
2238                    $this->lng->txt("obj_" . ilObject::_lookupType(
2239                        ilObject::_lookupObjId($_GET["ref_id"])
2240                    )),
2241                    $this->ctrl->getLinkTargetByClass("ilobjuserfoldergui", "view")
2242                );
2243            } elseif ($_GET['ref_id'] == ROLE_FOLDER_ID) {
2244                $ilLocator->addItem(
2245                    $this->lng->txt("obj_" . ilObject::_lookupType(
2246                        ilObject::_lookupObjId($_GET["ref_id"])
2247                    )),
2248                    $this->ctrl->getLinkTargetByClass("ilobjrolefoldergui", "view")
2249                );
2250            }
2251
2252            if ($_GET["obj_id"] > 0) {
2253                $ilLocator->addItem(
2254                    $this->object->getTitle(),
2255                    $this->ctrl->getLinkTarget($this, "view")
2256                );
2257            }
2258        } else {							// repository administration
2259            // ?
2260        }
2261    }
2262
2263    public function showUpperIcon()
2264    {
2265    }
2266
2267    public function __sendProfileMail()
2268    {
2269        global $DIC;
2270
2271        $ilUser = $DIC['ilUser'];
2272        $ilias = $DIC['ilias'];
2273
2274        if ($_POST['send_mail'] != 'y') {
2275            return '';
2276        }
2277        if (!strlen($this->object->getEmail())) {
2278            return '';
2279        }
2280
2281        // Choose language of user
2282        $usr_lang = new ilLanguage($this->object->getLanguage());
2283        $usr_lang->loadLanguageModule('crs');
2284        $usr_lang->loadLanguageModule('registration');
2285
2286        include_once "Services/Mail/classes/class.ilMimeMail.php";
2287
2288        /** @var ilMailMimeSenderFactory $senderFactory */
2289        $senderFactory = $GLOBALS['DIC']["mail.mime.sender.factory"];
2290
2291        $mmail = new ilMimeMail();
2292        $mmail->From($senderFactory->system());
2293        $mmail->To(ilMailOptions::getExternalEmailsByUser($this->object));
2294
2295        // mail subject
2296        $subject = $usr_lang->txt("profile_changed");
2297
2298
2299        // mail body
2300        $body = ($usr_lang->txt("reg_mail_body_salutation") . " " . $this->object->getFullname() . ",\n\n");
2301
2302        $date = $this->object->getApproveDate();
2303        // Approve
2304        if ((time() - strtotime($date)) < 10) {
2305            $body .= ($usr_lang->txt('reg_mail_body_approve') . "\n\n");
2306        } else {
2307            $body .= ($usr_lang->txt('reg_mail_body_profile_changed') . "\n\n");
2308        }
2309
2310        // Append login info only if password has been chacnged
2311        if ($_POST['passwd'] != '') {
2312            $body .= $usr_lang->txt("reg_mail_body_text2") . "\n" .
2313                ILIAS_HTTP_PATH . "/login.php?client_id=" . $ilias->client_id . "\n" .
2314                $usr_lang->txt("login") . ": " . $this->object->getLogin() . "\n" .
2315                $usr_lang->txt("passwd") . ": " . $_POST['passwd'] . "\n\n";
2316        }
2317        $body .= ($usr_lang->txt("reg_mail_body_text3") . "\n");
2318        $body .= $this->object->getProfileAsString($usr_lang);
2319
2320        $mmail->Subject($subject, true);
2321        $mmail->Body($body);
2322        $mmail->Send();
2323
2324
2325        return "<br/>" . $this->lng->txt("mail_sent");
2326    }
2327
2328    /**
2329     * Goto user profile screen
2330     */
2331    public static function _goto($a_target)
2332    {
2333        global $DIC;
2334
2335        $ilUser = $DIC['ilUser'];
2336        $ilCtrl = $DIC['ilCtrl'];
2337
2338        // #10888
2339        if ($a_target == md5("usrdelown")) {
2340            if ($ilUser->getId() != ANONYMOUS_USER_ID &&
2341                $ilUser->hasDeletionFlag()) {
2342                $ilCtrl->initBaseClass("ilpersonaldesktopgui");
2343                $ilCtrl->redirectByClass(array("ilpersonaldesktopgui", "ilpersonalsettingsgui"), "deleteOwnAccount3");
2344            }
2345            exit("This account is not flagged for deletion."); // #12160
2346        }
2347
2348        // badges
2349        if (substr($a_target, -4) == "_bdg") {
2350            $_GET["baseClass"] = "ilPersonalDesktopGUI";
2351            $_GET["cmd"] = "jumpToBadges";
2352            include("ilias.php");
2353            exit();
2354        }
2355
2356        if ('registration' == $a_target) {
2357            $_GET["baseClass"] = 'ilStartUpGUI';
2358            $ilCtrl->redirectByClass(array('ilStartUpGUI', 'ilAccountRegistrationGUI'), '');
2359        } elseif ('nameassist' == $a_target) {
2360            $_GET["baseClass"] = 'ilStartUpGUI';
2361            $ilCtrl->redirectByClass(array('ilStartUpGUI', 'ilPasswordAssistanceGUI'), 'showUsernameAssistanceForm');
2362        } elseif ('pwassist' == $a_target) {
2363            $_GET["baseClass"] = 'ilStartUpGUI';
2364            $ilCtrl->redirectByClass(array('ilStartUpGUI', 'ilPasswordAssistanceGUI'), '');
2365        } elseif ('agreement' == $a_target) {
2366            if ($ilUser->getId() > 0 && !$ilUser->isAnonymous()) {
2367                $ilCtrl->setTargetScript('ilias.php');
2368                $ilCtrl->initBaseClass('ilpersonaldesktopgui');
2369                $ilCtrl->redirectByClass(array('ilpersonaldesktopgui', 'ilpersonalprofilegui'), 'showUserAgreement');
2370            } else {
2371                $_GET['baseClass'] = 'ilStartUpGUI';
2372                $ilCtrl->setTargetScript('ilias.php');
2373                $ilCtrl->redirectByClass(array('ilStartUpGUI'), 'showTermsOfService');
2374            }
2375        }
2376
2377        if (substr($a_target, 0, 1) == "n") {
2378            $a_target = ilObjUser::_lookupId(ilUtil::stripSlashes(substr($a_target, 1)));
2379        }
2380
2381        if (strpos($a_target, 'contact_approved') !== false) {
2382            $_GET['cmd'] = 'approveContactRequest';
2383        } elseif (strpos($a_target, 'contact_ignored') !== false) {
2384            $_GET['cmd'] = 'ignoreContactRequest';
2385        } else {
2386            $_GET['cmd'] = 'view';
2387        }
2388
2389        $_GET["user_id"] = (int) $a_target;
2390        $_GET["baseClass"] = "ilPublicUserProfileGUI";
2391        $_GET["cmdClass"] = "ilpublicuserprofilegui";
2392        include("ilias.php");
2393        exit;
2394    }
2395
2396    /**
2397     *
2398     * Handles ignored required fields by changing the required flag of form elements
2399     *
2400     * @access	protected
2401     * @return	boolean	A flag whether the user profile is maybe incomplete after saving the form data
2402     *
2403     */
2404    protected function handleIgnoredRequiredFields()
2405    {
2406        $profileMaybeIncomplete = false;
2407
2408        require_once 'Services/User/classes/class.ilUserProfile.php';
2409
2410        foreach (ilUserProfile::getIgnorableRequiredSettings() as $fieldName) {
2411            $elm = $this->form_gui->getItemByPostVar($fieldName);
2412
2413            if (!$elm) {
2414                continue;
2415            }
2416
2417            if ($elm->getRequired()) {
2418                $profileMaybeIncomplete = true;
2419
2420                // Flag as optional
2421                $elm->setRequired(false);
2422            }
2423        }
2424
2425        include_once 'Services/User/classes/class.ilUserDefinedFields.php';
2426        $user_defined_fields = ilUserDefinedFields::_getInstance();
2427        foreach ($user_defined_fields->getDefinitions() as $field_id => $definition) {
2428            $elm = $this->form_gui->getItemByPostVar('udf_' . $definition['field_id']);
2429
2430            if (!$elm) {
2431                continue;
2432            }
2433
2434            if ($elm->getRequired() && $definition['changeable'] && $definition['required'] && $definition['visible']) {
2435                $profileMaybeIncomplete = true;
2436
2437                // Flag as optional
2438                $elm->setRequired(false);
2439            }
2440        }
2441
2442        return $profileMaybeIncomplete;
2443    }
2444
2445    /**
2446     *
2447     */
2448    protected function showAcceptedTermsOfService()
2449    {
2450        /** @var $agreeDate ilNonEditableValueGUI */
2451        $agreeDate = $this->form_gui->getItemByPostVar('agree_date');
2452        if ($agreeDate && $agreeDate->getValue()) {
2453            $this->lng->loadLanguageModule('tos');
2454            $helper = new \ilTermsOfServiceHelper();
2455
2456            $entity = $helper->getCurrentAcceptanceForUser($this->object);
2457            if ($entity->getId()) {
2458                $modal = $this->uiFactory
2459                    ->modal()
2460                    ->lightbox([
2461                        $this->uiFactory->modal()->lightboxTextPage($entity->getText(), $entity->getTitle())
2462                    ]);
2463
2464                $titleLink = $this->uiFactory
2465                    ->button()
2466                    ->shy($entity->getTitle(), '#')
2467                    ->withOnClick($modal->getShowSignal());
2468
2469                $agreementDocument = new ilNonEditableValueGUI(
2470                    $this->lng->txt('tos_agreement_document'),
2471                    '',
2472                    true
2473                );
2474                $agreementDocument->setValue($this->uiRenderer->render([$titleLink, $modal]));
2475                $agreeDate->addSubItem($agreementDocument);
2476            }
2477        } elseif ($agreeDate) {
2478            $agreeDate->setValue($this->lng->txt('tos_not_accepted_yet'));
2479        }
2480    }
2481} // END class.ilObjUserGUI
2482