ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilUserProfile.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4// mjansen@databay.de essential for mail constants, do not remove this include
5include_once 'Services/Mail/classes/class.ilMailOptions.php';
6
16{
17 const MODE_DESKTOP = 1;
19
20 private static $mode = self::MODE_DESKTOP;
21
22 // this array should be used in all places where user data is tackled
23 // in the future: registration, personal profile, user administration
24 // public profile, user import/export
25 // for now this is not implemented yet. Please list places, that already use it:
26 //
27 // - personal profile
28 // - (global) standard user profile fields settings
29 //
30 // the following attributes are defined (can be extended if needed):
31 // - input: input type
32 // standard inputs: text, radio, selection, textarea
33 // special inputs: login
34 // - input dependend attributes
35 // - maxlength, sizte for text
36 // - values array for radio
37 // - cols/rows for text areas
38 // - options array for selections
39 // - method: ilObjUser get-method, e.g. getFirstname
40 // - group: group id (id is also used as lang_var for sub headers in forms
41 // - lang_var: if key should not be used as lang var, this overwrites the usage in forms
42 // - settings property related attributes, settingsproperties are ("visible", "changeable",
43 // "searchable", "required", "export", "course_export" and "registration")
44 // - <settingsproperty>_hide: hide this property in settings (not implemented)
45 // - <settingsproperty>_fix_value: property has a fix value (cannot be changed)
46 private static $user_field = array(
47 "username" => array(
48 "input" => "login",
49 "maxlength" => 190,
50 "size" => 190,
51 "method" => "getLogin",
52 "course_export_fix_value" => 1,
53 "group_export_fix_value" => 1,
54 "changeable_hide" => true,
55 "required_hide" => true,
56 "group" => "personal_data"),
57 "password" => array(
58 "input" => "password",
59 "required_hide" => true,
60 "visib_reg_hide" => true,
61 'visib_lua_fix_value' => 0,
62 "course_export_hide" => true,
63 "export_hide" => false,
64 "group_export_hide" => true,
65 "lists_hide" => true,
66 "group" => "personal_data"),
67 "firstname" => array(
68 "input" => "text",
69 "maxlength" => 32,
70 "size" => 40,
71 "method" => "getFirstname",
72 "required_fix_value" => 1,
73 "visib_reg_fix_value" => 1,
74 'visib_lua_fix_value' => 1,
75 "course_export_fix_value" => 1,
76 "group_export_fix_value" => 1,
77 "group" => "personal_data"),
78 "lastname" => array(
79 "input" => "text",
80 "maxlength" => 32,
81 "size" => 40,
82 "method" => "getLastname",
83 "required_fix_value" => 1,
84 "visib_reg_fix_value" => 1,
85 'visib_lua_fix_value' => 1,
86 "course_export_fix_value" => 1,
87 "group_export_fix_value" => 1,
88 "group" => "personal_data"),
89 "title" => array(
90 "input" => "text",
91 "lang_var" => "person_title",
92 "maxlength" => 32,
93 "size" => 40,
94 "method" => "getUTitle",
95 "group" => "personal_data"),
96 "birthday" => array(
97 "input" => "birthday",
98 "lang_var" => "birthday",
99 "maxlength" => 32,
100 "size" => 40,
101 "method" => "getBirthday",
102 "group" => "personal_data"),
103 "gender" => array(
104 "input" => "radio",
105 "values" => array("n" => "salutation_n", "f" => "salutation_f", "m" => "salutation_m"),
106 "method" => "getGender",
107 "group" => "personal_data"),
108 "upload" => array(
109 "input" => "picture",
110 "required_hide" => true,
111 "visib_reg_hide" => true,
112 "course_export_hide" => true,
113 "group_export_hide" => true,
114 "lists_hide" => true,
115 "lang_var" => "personal_picture",
116 "group" => "personal_data"),
117 "roles" => array(
118 "input" => "roles",
119 "changeable_hide" => true,
120 "required_hide" => true,
121 "visib_reg_hide" => true,
122 "export_hide" => true,
123 "course_export_hide" => true,
124 "group_export_hide" => true,
125 "lists_hide" => true,
126 "group" => "personal_data"),
127 "interests_general" => array(
128 "input" => "multitext",
129 "maxlength" => 40,
130 "size" => 40,
131 "method" => "getGeneralInterests",
132 "course_export_hide" => true,
133 "group_export_hide" => true,
134 "lists_hide" => true,
135 "group" => "interests"),
136 "interests_help_offered" => array(
137 "input" => "multitext",
138 "maxlength" => 40,
139 "size" => 40,
140 "method" => "getOfferingHelp",
141 "course_export_hide" => true,
142 "group_export_hide" => true,
143 "lists_hide" => true,
144 "group" => "interests"),
145 "interests_help_looking" => array(
146 "input" => "multitext",
147 "maxlength" => 40,
148 "size" => 40,
149 "method" => "getLookingForHelp",
150 "course_export_hide" => true,
151 "group_export_hide" => true,
152 "lists_hide" => true,
153 "group" => "interests"),
154 "org_units" => array(
155 "input" => "noneditable",
156 "lang_var" => "objs_orgu",
157 "required_hide" => true,
158 "visib_reg_hide" => true,
159 "course_export_hide" => false,
160 "group_export_hide" => false,
161 "export_hide" => true,
162 "changeable_hide" => true,
163 "changeable_fix_value" => 0,
164 "changeable_lua_hide" => true,
165 "changeable_lua_fix_value" => 0,
166 "method" => "getOrgUnitsRepresentation",
167 "group" => "contact_data"),
168 "institution" => array(
169 "input" => "text",
170 "maxlength" => 80,
171 "size" => 40,
172 "method" => "getInstitution",
173 "group" => "contact_data"),
174 "department" => array(
175 "input" => "text",
176 "maxlength" => 80,
177 "size" => 40,
178 "method" => "getDepartment",
179 "group" => "contact_data"),
180 "street" => array(
181 "input" => "text",
182 "maxlength" => 40,
183 "size" => 40,
184 "method" => "getStreet",
185 "group" => "contact_data"),
186 "zipcode" => array(
187 "input" => "text",
188 "maxlength" => 10,
189 "size" => 10,
190 "method" => "getZipcode",
191 "group" => "contact_data"),
192 "city" => array(
193 "input" => "text",
194 "maxlength" => 40,
195 "size" => 40,
196 "method" => "getCity",
197 "group" => "contact_data"),
198 "country" => array(
199 "input" => "text",
200 "maxlength" => 40,
201 "size" => 40,
202 "method" => "getCountry",
203 "group" => "contact_data"),
204 "sel_country" => array(
205 "input" => "sel_country",
206 "method" => "getSelectedCountry",
207 "group" => "contact_data"),
208 "phone_office" => array(
209 "input" => "text",
210 "maxlength" => 40,
211 "size" => 40,
212 "method" => "getPhoneOffice",
213 "group" => "contact_data"),
214 "phone_home" => array(
215 "input" => "text",
216 "maxlength" => 40,
217 "size" => 40,
218 "method" => "getPhoneHome",
219 "group" => "contact_data"),
220 "phone_mobile" => array(
221 "input" => "text",
222 "maxlength" => 40,
223 "size" => 40,
224 "method" => "getPhoneMobile",
225 "group" => "contact_data"),
226 "fax" => array(
227 "input" => "text",
228 "maxlength" => 40,
229 "size" => 40,
230 "method" => "getFax",
231 "group" => "contact_data"),
232 "email" => array(
233 "input" => "email",
234 "maxlength" => 40,
235 "size" => 40,
236 "method" => "getEmail",
237 "group" => "contact_data"),
238 "second_email" => array(
239 "input" => "second_email",
240 "maxlength" => 40,
241 "size" => 40,
242 "method" => "getSecondEmail",
243 "group" => "contact_data"),
244 "hobby" => array(
245 "input" => "textarea",
246 "rows" => 3,
247 "cols" => 45,
248 "method" => "getHobby",
249 "lists_hide" => true,
250 "group" => "contact_data"),
251 "referral_comment" => array(
252 "input" => "textarea",
253 "rows" => 3,
254 "cols" => 45,
255 "method" => "getComment",
256 "course_export_hide" => true,
257 "group_export_hide" => true,
258 "lists_hide" => true,
259 "group" => "contact_data"),
260 "matriculation" => array(
261 "input" => "text",
262 "maxlength" => 40,
263 "size" => 40,
264 "method" => "getMatriculation",
265 "group" => "other"),
266 "language" => array(
267 "input" => "language",
268 "method" => "getLanguage",
269 "required_hide" => true,
270 "visib_reg_hide" => true,
271 "course_export_hide" => true,
272 "group_export_hide" => true,
273 "group" => "settings"),
274 "skin_style" => array(
275 "input" => "skinstyle",
276 "required_hide" => true,
277 "visib_reg_hide" => true,
278 "course_export_hide" => true,
279 "group_export_hide" => true,
280 "group" => "settings"),
281 "hits_per_page" => array(
282 "input" => "hitsperpage",
283 "default" => 10,
284 "options" => array(
285 10 => 10, 15 => 15, 20 => 20, 30 => 30, 40 => 40,
286 50 => 50, 100 => 100, 9999 => 9999),
287 "required_hide" => true,
288 "visib_reg_hide" => true,
289 "course_export_hide" => true,
290 "group_export_hide" => true,
291 "group" => "settings"),
292 /*"show_users_online" => array(
293 "input" => "selection",
294 "default" => "y",
295 "options" => array(
296 "y" => "users_online_show_short_y",
297 "associated" => "users_online_show_short_associated",
298 "n" => "users_online_show_short_n"),
299 "required_hide" => true,
300 "visib_reg_hide" => true,
301 "course_export_hide" => true,
302 "group_export_hide" => true,
303 "group" => "settings"),*/
304 "hide_own_online_status" => array(
305 "input" => "selection",
306 "lang_var" => "awrn_user_show",
307 "required_hide" => true,
308 "visib_reg_hide" => true,
309 "course_export_hide" => true,
310 "group_export_hide" => true,
311 "group" => "settings",
312 "default" => "y",
313 "options" => array(
314 "y" => "user_awrn_hide",
315 "n" => "user_awrn_show"
316 )),
317 "bs_allow_to_contact_me" => array(
318 "input" => "selection",
319 "lang_var" => "buddy_allow_to_contact_me",
320 "required_hide" => true,
321 "visib_reg_hide" => true,
322 "course_export_hide" => true,
323 "group_export_hide" => true,
324 "group" => "settings",
325 "default" => "y",
326 "options" => array(
327 "n" => "buddy_allow_to_contact_me_no",
328 "y" => "buddy_allow_to_contact_me_yes"
329 )
330 ),
331 "chat_osc_accept_msg" => array(
332 "input" => "selection",
333 "lang_var" => "chat_osc_accept_msg",
334 "required_hide" => true,
335 "visib_reg_hide" => true,
336 "course_export_hide" => true,
337 "group_export_hide" => true,
338 "group" => "settings",
339 "default" => "y",
340 "options" => array(
341 "n" => "chat_osc_accepts_messages_no",
342 "y" => "chat_osc_accepts_messages_yes"
343 )
344 ),
345 "preferences" => array(
346 "visible_fix_value" => 1,
347 "changeable_fix_value" => 1,
348 "required_hide" => true,
349 "visib_reg_hide" => true,
350 "course_export_hide" => true,
351 "group_export_hide" => true,
352 "group" => "preferences"),
353 "mail_incoming_mail" => array(
354 "input" => "selection",
355 "default" => "y",
356 "options" => array(
357 ilMailOptions::INCOMING_LOCAL => "mail_incoming_local",
358 ilMailOptions::INCOMING_EMAIL => "mail_incoming_smtp",
359 ilMailOptions::INCOMING_BOTH => "mail_incoming_both"),
360 "required_hide" => true,
361 "visib_reg_hide" => true,
362 "course_export_hide" => true,
363 "group_export_hide" => true,
364 "export_hide" => true,
365 "search_hide" => true,
366 "group" => "settings")
367
368 );
369
370
375
379 public function __construct()
380 {
381 global $DIC;
382
383 $lng = $DIC['lng'];
384
385 $this->skip_groups = array();
386 $this->skip_fields = array();
387
388 // for hide me from awareness tool text
389 // not nicest workaround, but better than using common block
390 $lng->loadLanguageModule("awrn");
391 $lng->loadLanguageModule("buddysystem");
392
393 $this->user_settings_config = new ilUserSettingsConfig();
394 }
395
399 public function getStandardFields()
400 {
401 $fields = array();
402 foreach (self::$user_field as $f => $p) {
403 // skip hidden groups
404 if (in_array($p["group"], $this->skip_groups) ||
405 in_array($f, $this->skip_fields)) {
406 continue;
407 }
408 $fields[$f] = $p;
409 }
410 return $fields;
411 }
412
418 {
419 global $DIC;
420
421 $ilSetting = $DIC['ilSetting'];
422
423 $settings = $ilSetting->getAll();
424
425 $fields = array();
426 foreach ($this->getStandardFields() as $field => $info) {
427 if ($ilSetting->get('usr_settings_visib_lua_' . $field, 1)) {
428 $fields[$field] = $info;
429 } elseif ($info['visib_lua_fix_value']) {
430 $fields[$field] = $info;
431 }
432 }
433 return $fields;
434 }
435
436
440 public function skipGroup($a_group)
441 {
442 $this->skip_groups[] = $a_group;
443 }
444
448 public function skipField($a_field)
449 {
450 $this->skip_fields[] = $a_field;
451 }
452
456 public function addStandardFieldsToForm($a_form, $a_user = null, array $custom_fields = null)
457 {
458 global $DIC;
459
460 $ilSetting = $DIC['ilSetting'];
461 $lng = $DIC['lng'];
462 $rbacreview = $DIC['rbacreview'];
463 $ilias = $DIC['ilias'];
464
465 // custom registration settings
466 if (self::$mode == self::MODE_REGISTRATION) {
467 include_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
468 $registration_settings = new ilRegistrationSettings();
469
470 self::$user_field["username"]["group"] = "login_data";
471 self::$user_field["password"]["group"] = "login_data";
472 self::$user_field["language"]["default"] = $lng->lang_key;
473
474 // different position for role
475 $roles = self::$user_field["roles"];
476 unset(self::$user_field["roles"]);
477 self::$user_field["roles"] = $roles;
478 self::$user_field["roles"]["group"] = "settings";
479 }
480
481 $fields = $this->getStandardFields();
482 $current_group = "";
483 $custom_fields_done = false;
484 foreach ($fields as $f => $p) {
485 // next group? -> diplay subheader
486 if (($p["group"] != $current_group) &&
488 if (is_array($custom_fields) && !$custom_fields_done) {
489 // should be appended to "other" or at least before "settings"
490 if ($current_group == "other" || $p["group"] == "settings") {
491 // add "other" subheader
492 if ($current_group != "other") {
493 $sh = new ilFormSectionHeaderGUI();
494 $sh->setTitle($lng->txt("other"));
495 $a_form->addItem($sh);
496 }
497 foreach ($custom_fields as $custom_field) {
498 $a_form->addItem($custom_field);
499 }
500 $custom_fields_done = true;
501 }
502 }
503
504 $sh = new ilFormSectionHeaderGUI();
505 $sh->setTitle($lng->txt($p["group"]));
506 $a_form->addItem($sh);
507 $current_group = $p["group"];
508 }
509
510 $m = "";
511 if (isset($p["method"])) {
512 $m = $p["method"];
513 }
514
515 $lv = (isset($p["lang_var"]) && $p["lang_var"] != "")
516 ? $p["lang_var"]
517 : $f;
518
519 switch ($p["input"]) {
520 case "login":
521 if ((int) $ilSetting->get('allow_change_loginname') || self::$mode == self::MODE_REGISTRATION) {
522 $val = new ilTextInputGUI($lng->txt('username'), 'username');
523 if ($a_user) {
524 $val->setValue($a_user->getLogin());
525 }
526 $val->setMaxLength($p['maxlength']);
527 $val->setSize(255);
528 $val->setRequired(true);
529 } else {
530 // user account name
531 $val = new ilNonEditableValueGUI($lng->txt("username"), 'ne_un');
532 if ($a_user) {
533 $val->setValue($a_user->getLogin());
534 }
535 }
536 $a_form->addItem($val);
537 break;
538
539 case "text":
541 $ti = new ilTextInputGUI($lng->txt($lv), "usr_" . $f);
542 if ($a_user) {
543 $ti->setValue($a_user->$m());
544 }
545 $ti->setMaxLength($p["maxlength"]);
546 $ti->setSize($p["size"]);
547 $ti->setRequired($ilSetting->get("require_" . $f));
548 if (!$ti->getRequired() || $ti->getValue()) {
549 $ti->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
550 }
551 $a_form->addItem($ti);
552 }
553 break;
554
555 case "sel_country":
557 include_once("./Services/Form/classes/class.ilCountrySelectInputGUI.php");
558 $ci = new ilCountrySelectInputGUI($lng->txt($lv), "usr_" . $f);
559 if ($a_user) {
560 $ci->setValue($a_user->$m());
561 }
562 $ci->setRequired($ilSetting->get("require_" . $f));
563 if (!$ci->getRequired() || $ci->getValue()) {
564 $ci->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
565 }
566 $a_form->addItem($ci);
567 }
568 break;
569
570 case "birthday":
572 $bi = new ilBirthdayInputGUI($lng->txt($lv), "usr_" . $f);
573 include_once "./Services/Calendar/classes/class.ilDateTime.php";
574 $date = null;
575 if ($a_user && strlen($a_user->$m())) {
576 $date = new ilDateTime($a_user->$m(), IL_CAL_DATE);
577 $bi->setDate($date);
578 }
579 $bi->setRequired($ilSetting->get("require_" . $f));
580 if (!$bi->getRequired() || $date) {
581 $bi->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
582 }
583 $a_form->addItem($bi);
584 }
585 break;
586
587 case "radio":
589 $rg = new ilRadioGroupInputGUI($lng->txt($lv), "usr_" . $f);
590 if ($a_user) {
591 $rg->setValue($a_user->$m());
592 }
593 foreach ($p["values"] as $k => $v) {
594 $op = new ilRadioOption($lng->txt($v), $k);
595 $rg->addOption($op);
596 }
597 $rg->setRequired($ilSetting->get("require_" . $f));
598 if (!$rg->getRequired() || $rg->getValue()) {
599 $rg->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
600 }
601 $a_form->addItem($rg);
602 }
603 break;
604
605 case "picture":
606 if (ilUserProfile::userSettingVisible("upload") && $a_user) {
607 $ii = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile");
608 $ii->setDisabled($ilSetting->get("usr_settings_disable_upload"));
609
610 $upload = $a_form->getFileUpload("userfile");
611 if ($upload["name"]) {
612 $ii->setPending($upload["name"]);
613 } else {
615 $a_user->getId(),
616 "small",
617 true,
618 true
619 );
620 if ($im != "") {
621 $ii->setImage($im);
622 $ii->setAlt($lng->txt("personal_picture"));
623 }
624 }
625
626 $a_form->addItem($ii);
627 }
628 break;
629
630 case "roles":
631 if (self::$mode == self::MODE_DESKTOP) {
633 $global_roles = $rbacreview->getGlobalRoles();
634 foreach ($global_roles as $role_id) {
635 if (in_array($role_id, $rbacreview->assignedRoles($a_user->getId()))) {
636 $roleObj = $ilias->obj_factory->getInstanceByObjId($role_id);
637 $role_names .= $roleObj->getTitle() . ", ";
638 unset($roleObj);
639 }
640 }
641 $dr = new ilNonEditableValueGUI($lng->txt("default_roles"), "ne_dr");
642 $dr->setValue(substr($role_names, 0, -2));
643 $a_form->addItem($dr);
644 }
645 } elseif (self::$mode == self::MODE_REGISTRATION) {
646 if ($registration_settings->roleSelectionEnabled()) {
647 include_once("./Services/AccessControl/classes/class.ilObjRole.php");
648 $options = array();
649 foreach (ilObjRole::_lookupRegisterAllowed() as $role) {
650 $options[$role["id"]] = $role["title"];
651 }
652 // registration form validation will take care of missing field / value
653 if ($options) {
654 if (sizeof($options) > 1) {
655 $ta = new ilSelectInputGUI($lng->txt('default_role'), "usr_" . $f);
656 $ta->setOptions($options);
657 $ta->setRequired($ilSetting->get("require_" . $f));
658 if (!$ta->getRequired()) {
659 $ta->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
660 }
661 }
662 // no need for select if only 1 option
663 else {
664 $ta = new ilHiddenInputGUI("usr_" . $f);
665 $ta->setValue(array_shift(array_keys($options)));
666 }
667 $a_form->addItem($ta);
668 }
669 }
670 }
671 break;
672
673 case "email":
675 $em = new ilEMailInputGUI($lng->txt($lv), "usr_" . $f);
676 if ($a_user) {
677 $em->setValue($a_user->$m());
678 }
679 $em->setRequired($ilSetting->get("require_" . $f));
680 if (!$em->getRequired() || $em->getValue()) {
681 $em->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
682 }
683 if (self::MODE_REGISTRATION == self::$mode) {
684 $em->setRetype(true);
685 }
686 $a_form->addItem($em);
687 }
688 break;
689 case "second_email":
691 $em = new ilEMailInputGUI($lng->txt($lv), "usr_" . $f);
692 if ($a_user) {
693 $em->setValue($a_user->$m());
694 }
695 $em->setRequired($ilSetting->get("require_" . $f));
696 if (!$em->getRequired() || $em->getValue()) {
697 $em->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
698 }
699 if (self::MODE_REGISTRATION == self::$mode) {
700 $em->setRetype(true);
701 }
702 $a_form->addItem($em);
703 }
704 break;
705 case "textarea":
707 $ta = new ilTextAreaInputGUI($lng->txt($lv), "usr_" . $f);
708 if ($a_user) {
709 $ta->setValue($a_user->$m());
710 }
711 $ta->setRows($p["rows"]);
712 $ta->setCols($p["cols"]);
713 $ta->setRequired($ilSetting->get("require_" . $f));
714 if (!$ta->getRequired() || $ta->getValue()) {
715 $ta->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
716 }
717 $a_form->addItem($ta);
718 }
719 break;
720
721 case "password":
722 if (self::$mode == self::MODE_REGISTRATION) {
723 if (!$registration_settings->passwordGenerationEnabled()) {
724 $ta = new ilPasswordInputGUI($lng->txt($lv), "usr_" . $f);
725 $ta->setUseStripSlashes(false);
726 $ta->setRequired(true);
728 // $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
729 } else {
730 $ta = new ilNonEditableValueGUI($lng->txt($lv));
731 $ta->setValue($lng->txt("reg_passwd_via_mail"));
732 }
733 $a_form->addItem($ta);
734 }
735 break;
736
737 case "language":
739 $ta = new ilSelectInputGUI($lng->txt($lv), "usr_" . $f);
740 if ($a_user) {
741 $ta->setValue($a_user->$m());
742 }
743 $options = array();
744 $lng->loadLanguageModule("meta");
745 foreach ($lng->getInstalledLanguages() as $lang_key) {
746 $options[$lang_key] = $lng->txt("meta_l_" . $lang_key);
747 }
748 asort($options); // #9728
749 $ta->setOptions($options);
750 $ta->setRequired($ilSetting->get("require_" . $f));
751 if (!$ta->getRequired() || $ta->getValue()) {
752 $ta->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
753 }
754 $a_form->addItem($ta);
755 }
756 break;
757
758 case "multitext":
760 $ti = new ilTextInputGUI($lng->txt($lv), "usr_" . $f);
761 $ti->setMulti(true);
762 if ($a_user) {
763 $ti->setValue($a_user->$m());
764 }
765 $ti->setMaxLength($p["maxlength"]);
766 $ti->setSize($p["size"]);
767 $ti->setRequired($ilSetting->get("require_" . $f));
768 if (!$ti->getRequired() || $ti->getValue()) {
769 $ti->setDisabled($ilSetting->get("usr_settings_disable_" . $f));
770 }
771 if ($this->ajax_href) {
772 // add field to ajax call
773 $ti->setDataSource($this->ajax_href . "&f=" . $f);
774 }
775 $a_form->addItem($ti);
776 }
777 break;
778 case "noneditable":
779 if (self::$mode == self::MODE_DESKTOP && ilUserProfile::userSettingVisible($f)) {
780 $ne = new ilNonEditableValueGUI($lng->txt($lv));
781 $ne->setValue($a_user->$m());
782 $a_form->addItem($ne);
783 }
784 break;
785 }
786 }
787
788 // append custom fields as "other"
789 if (is_array($custom_fields) && !$custom_fields_done) {
790 // add "other" subheader
791 if ($current_group != "other") {
792 $sh = new ilFormSectionHeaderGUI();
793 $sh->setTitle($lng->txt("other"));
794 $a_form->addItem($sh);
795 }
796 foreach ($custom_fields as $custom_field) {
797 $a_form->addItem($custom_field);
798 }
799 }
800 }
801
802 public function setAjaxCallback($a_href)
803 {
804 $this->ajax_href = $a_href;
805 }
806
810 public static function userSettingVisible($a_setting)
811 {
812 global $DIC;
813
814 $ilSetting = $DIC['ilSetting'];
815
816
818
819 if (self::$mode == self::MODE_DESKTOP) {
820 return ($user_settings_config->isVisible($a_setting));
821 } else {
822 if (isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true) {
823 return true;
824 }
825 return ($ilSetting->get("usr_settings_visib_reg_" . $a_setting, "1") || $ilSetting->get("require_" . $a_setting, "0"));
826 }
827 }
828
829 public static function setMode($mode)
830 {
831 global $DIC;
832
833 $lng = $DIC['lng'];
834
835 if (in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION))) {
836 self::$mode = $mode;
837 return true;
838 }
839 return false;
840 }
841
850 public static function isProfileIncomplete($a_user, $a_include_udf = true, $a_personal_data_only = true)
851 {
852 global $DIC;
853
854 $ilSetting = $DIC['ilSetting'];
855
857
858 // standard fields
859 foreach (self::$user_field as $field => $definition) {
860 // only if visible in personal data
861 if ($a_personal_data_only && !$user_settings_config->isVisible($field)) {
862 continue;
863 }
864
865 if ($ilSetting->get("require_" . $field) && $definition["method"]) {
866 $value = $a_user->{$definition["method"]}();
867 if ($value == "") {
868 return true;
869 }
870 }
871 }
872
873 // custom fields
874 if ($a_include_udf) {
875 $user_defined_data = $a_user->getUserDefinedData();
876
877 include_once './Services/User/classes/class.ilUserDefinedFields.php';
878 $user_defined_fields = ilUserDefinedFields::_getInstance();
879 foreach ($user_defined_fields->getRequiredDefinitions() as $field => $definition) {
880 // only if visible in personal data
881 if ($a_personal_data_only && !$definition["visible"]) {
882 continue;
883 }
884
885 if (!$user_defined_data["f_" . $field]) {
886 ilLoggerFactory::getLogger('user')->info('Profile is incomplete due to missing required udf.');
887 return true;
888 }
889 }
890 }
891
892 return false;
893 }
894
905 protected static function isEditableByUser($setting)
906 {
907 $user_settings_config = new ilUserSettingsConfig();
908 return $user_settings_config->isVisibleAndChangeable($setting);
909 }
910
920 public static function getIgnorableRequiredSettings()
921 {
927 global $DIC;
928
929 $ilSetting = $DIC['ilSetting'];
930
931 $ignorableSettings = array();
932
933 foreach (self::$user_field as $field => $definition) {
934 // !!!username and password must not be ignored!!!
935 if ('username' == $field ||
936 'password' == $field) {
937 continue;
938 }
939
940 // Field is not required -> continue
941 if (!$ilSetting->get('require_' . $field)) {
942 continue;
943 }
944
945 if (self::isEditableByUser($field)) {
946 $ignorableSettings[] = $field;
947 }
948 }
949
950 return $ignorableSettings;
951 }
952}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
This class represents a text property in a property form.
This class represents a selection list property in a property form.
@classDescription Date and time handling
This class represents a email property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
This class represents an image file property in a property form.
static getLogger($a_component_id)
Get component logger.
This class represents a non editable value in a property form.
static _lookupRegisterAllowed()
get all roles that are activated in user registration
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false, $html_export=false)
Get path to personal picture.
This class represents a password property in a property form.
This class represents a property in a property form.
This class represents an option in a radio group.
Class ilObjAuthSettingsGUI.
This class represents a selection list property in a property form.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static _getInstance()
Get instance.
Class ilUserProfile.
addStandardFieldsToForm($a_form, $a_user=null, array $custom_fields=null)
Add standard fields to form.
__construct()
Constructor.
getStandardFields()
Get standard user fields array.
getLocalUserAdministrationFields()
Get visible fields in local user administration.
skipField($a_field)
Skip a field.
static setMode($mode)
skipGroup($a_group)
Skip a group.
static isEditableByUser($setting)
Returns whether a profile setting is editable by an user in the profile gui.
static userSettingVisible($a_setting)
Checks whether user setting is visible.
static getIgnorableRequiredSettings()
Returns an array of all ignorable profiel fields.
static isProfileIncomplete($a_user, $a_include_udf=true, $a_personal_data_only=true)
Check if all required personal data fields are set.
User settings configuration (what preferences can be visible/changed/...)
static getPasswordRequirementsInfo()
infotext for ilPasswordInputGUI setInfo()
global $DIC
Definition: goto.php:24
global $ilSetting
Definition: privfeed.php:17
$lng