ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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
5 include_once 'Services/Mail/classes/class.ilMailOptions.php';
6 
16 {
17  const MODE_DESKTOP = 1;
18  const MODE_REGISTRATION = 2;
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" => 32,
50  "size" => 40,
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  "group_export_hide" => true,
64  "lists_hide" => true,
65  "group" => "personal_data"),
66  "firstname" => array(
67  "input" => "text",
68  "maxlength" => 32,
69  "size" => 40,
70  "method" => "getFirstname",
71  "required_fix_value" => 1,
72  "visib_reg_fix_value" => 1,
73  'visib_lua_fix_value' => 1,
74  "course_export_fix_value" => 1,
75  "group_export_fix_value" => 1,
76  "group" => "personal_data"),
77  "lastname" => array(
78  "input" => "text",
79  "maxlength" => 32,
80  "size" => 40,
81  "method" => "getLastname",
82  "required_fix_value" => 1,
83  "visib_reg_fix_value" => 1,
84  'visib_lua_fix_value' => 1,
85  "course_export_fix_value" => 1,
86  "group_export_fix_value" => 1,
87  "group" => "personal_data"),
88  "title" => array(
89  "input" => "text",
90  "lang_var" => "person_title",
91  "maxlength" => 32,
92  "size" => 40,
93  "method" => "getUTitle",
94  "group" => "personal_data"),
95  "birthday" => array(
96  "input" => "birthday",
97  "lang_var" => "birthday",
98  "maxlength" => 32,
99  "size" => 40,
100  "method" => "getBirthday",
101  "group" => "personal_data"),
102  "gender" => array(
103  "input" => "radio",
104  "values" => array("f" => "gender_f", "m" => "gender_m"),
105  "method" => "getGender",
106  "group" => "personal_data"),
107  "upload" => array(
108  "input" => "picture",
109  "required_hide" => true,
110  "visib_reg_hide" => true,
111  "course_export_hide" => true,
112  "group_export_hide" => true,
113  "lists_hide" => true,
114  "lang_var" => "personal_picture",
115  "group" => "personal_data"),
116  "roles" => array(
117  "input" => "roles",
118  "changeable_hide" => true,
119  "required_hide" => true,
120  "visib_reg_hide" => true,
121  "export_hide" => true,
122  "course_export_hide" => true,
123  "lists_hide" => true,
124  "group" => "personal_data"),
125  "institution" => array(
126  "input" => "text",
127  "maxlength" => 80,
128  "size" => 40,
129  "method" => "getInstitution",
130  "group" => "contact_data"),
131  "department" => array(
132  "input" => "text",
133  "maxlength" => 80,
134  "size" => 40,
135  "method" => "getDepartment",
136  "group" => "contact_data"),
137  "street" => array(
138  "input" => "text",
139  "maxlength" => 40,
140  "size" => 40,
141  "method" => "getStreet",
142  "group" => "contact_data"),
143  "zipcode" => array(
144  "input" => "text",
145  "maxlength" => 10,
146  "size" => 10,
147  "method" => "getZipcode",
148  "group" => "contact_data"),
149  "city" => array(
150  "input" => "text",
151  "maxlength" => 40,
152  "size" => 40,
153  "method" => "getCity",
154  "group" => "contact_data"),
155  "country" => array(
156  "input" => "text",
157  "maxlength" => 40,
158  "size" => 40,
159  "method" => "getCountry",
160  "group" => "contact_data"),
161  "sel_country" => array(
162  "input" => "sel_country",
163  "method" => "getSelectedCountry",
164  "group" => "contact_data"),
165  "phone_office" => array(
166  "input" => "text",
167  "maxlength" => 40,
168  "size" => 40,
169  "method" => "getPhoneOffice",
170  "group" => "contact_data"),
171  "phone_home" => array(
172  "input" => "text",
173  "maxlength" => 40,
174  "size" => 40,
175  "method" => "getPhoneHome",
176  "group" => "contact_data"),
177  "phone_mobile" => array(
178  "input" => "text",
179  "maxlength" => 40,
180  "size" => 40,
181  "method" => "getPhoneMobile",
182  "group" => "contact_data"),
183  "fax" => array(
184  "input" => "text",
185  "maxlength" => 40,
186  "size" => 40,
187  "method" => "getFax",
188  "group" => "contact_data"),
189  "email" => array(
190  "input" => "email",
191  "maxlength" => 40,
192  "size" => 40,
193  "method" => "getEmail",
194  "group" => "contact_data"),
195  "hobby" => array(
196  "input" => "textarea",
197  "rows" => 3,
198  "cols" => 45,
199  "method" => "getHobby",
200  "lists_hide" => true,
201  "group" => "contact_data"),
202  "referral_comment" => array(
203  "input" => "textarea",
204  "rows" => 3,
205  "cols" => 45,
206  "method" => "getComment",
207  "course_export_hide" => true,
208  "group_export_hide" => true,
209  "lists_hide" => true,
210  "group" => "contact_data"),
211  "instant_messengers" => array(
212  "input" => "messenger",
213  "types" => array("icq","yahoo","msn","aim","skype","jabber","voip"),
214  "maxlength" => 40,
215  "size" => 40,
216  "course_export_hide" => true,
217  "group_export_hide" => true,
218  "lists_hide" => true,
219  "group" => "instant_messengers"),
220  "matriculation" => array(
221  "input" => "text",
222  "maxlength" => 40,
223  "size" => 40,
224  "method" => "getMatriculation",
225  "group" => "other"),
226  "delicious" => array(
227  "input" => "text",
228  "maxlength" => 40,
229  "size" => 40,
230  "method" => "getDelicious",
231  "group" => "other"),
232  "language" => array(
233  "input" => "language",
234  "method" => "getLanguage",
235  "required_hide" => true,
236  "visib_reg_hide" => true,
237  "course_export_hide" => true,
238  "group_export_hide" => true,
239  "group" => "settings"),
240  "skin_style" => array(
241  "input" => "skinstyle",
242  "required_hide" => true,
243  "visib_reg_hide" => true,
244  "course_export_hide" => true,
245  "group_export_hide" => true,
246  "group" => "settings"),
247  "hits_per_page" => array(
248  "input" => "hitsperpage",
249  "default" => 10,
250  "options" => array(
251  10 => 10, 15 => 15, 20 => 20, 30 => 30, 40 => 40,
252  50 => 50, 100 => 100, 9999 => 9999),
253  "required_hide" => true,
254  "visib_reg_hide" => true,
255  "course_export_hide" => true,
256  "group_export_hide" => true,
257  "group" => "settings"),
258  "show_users_online" => array(
259  "input" => "selection",
260  "default" => "y",
261  "options" => array(
262  "y" => "users_online_show_short_y",
263  "associated" => "users_online_show_short_associated",
264  "n" => "users_online_show_short_n"),
265  "required_hide" => true,
266  "visib_reg_hide" => true,
267  "course_export_hide" => true,
268  "group_export_hide" => true,
269  "group" => "settings"),
270  "hide_own_online_status" => array(
271  "input" => "selection",
272  "required_hide" => true,
273  "visib_reg_hide" => true,
274  "course_export_hide" => true,
275  "group_export_hide" => true,
276  "group" => "settings"),
277  "preferences" => array(
278  "visible_fix_value" => 1,
279  "changeable_fix_value" => 1,
280  "required_hide" => true,
281  "visib_reg_hide" => true,
282  "course_export_hide" => true,
283  "group_export_hide" => true,
284  "group" => "preferences"),
285  "mail_incoming_mail" => array(
286  "input" => "selection",
287  "default" => "y",
288  "options" => array(
289  IL_MAIL_LOCAL => "mail_incoming_local",
290  IL_MAIL_EMAIL => "mail_incoming_smtp",
291  IL_MAIL_BOTH => "mail_incoming_both"),
292  "required_hide" => true,
293  "visib_reg_hide" => true,
294  "course_export_hide" => true,
295  "group_export_hide" => true,
296  "export_hide" => true,
297  "search_hide" => true,
298  "group" => "settings")
299 
300  );
301 
305  function __construct()
306  {
307  $this->skip_groups = array();
308  $this->skip_fields = array();
309  }
310 
314  function getStandardFields()
315  {
316  $fields = array();
317  foreach (self::$user_field as $f => $p)
318  {
319  // skip hidden groups
320  if (in_array($p["group"], $this->skip_groups) ||
321  in_array($f, $this->skip_fields))
322  {
323  continue;
324  }
325  $fields[$f] = $p;
326  }
327  return $fields;
328  }
329 
335  {
336  global $ilSetting;
337 
338  $settings = $ilSetting->getAll();
339 
340  $fields = array();
341  foreach($this->getStandardFields() as $field => $info)
342  {
343  if($ilSetting->get('usr_settings_visib_lua_'.$field,1))
344  {
345  $fields[$field] = $info;
346  }
347  elseif($info['visib_lua_fix_value'])
348  {
349  $fields[$field] = $info;
350  }
351  }
352  return $fields;
353  }
354 
355 
359  function skipGroup($a_group)
360  {
361  $this->skip_groups[] = $a_group;
362  }
363 
367  function skipField($a_field)
368  {
369  $this->skip_fields[] = $a_field;
370  }
371 
375  function addStandardFieldsToForm($a_form, $a_user = NULL, array $custom_fields = NULL)
376  {
377  global $ilSetting, $lng, $rbacreview, $ilias;
378 
379  // custom registration settings
380  if(self::$mode == self::MODE_REGISTRATION)
381  {
382  include_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
383  $registration_settings = new ilRegistrationSettings();
384 
385  self::$user_field["username"]["group"] = "login_data";
386  self::$user_field["password"]["group"] = "login_data";
387  self::$user_field["language"]["default"] = $lng->lang_key;
388 
389  // different position for role
390  $roles = self::$user_field["roles"];
391  unset(self::$user_field["roles"]);
392  self::$user_field["roles"] = $roles;
393  self::$user_field["roles"]["group"] = "settings";
394 
395  // add code field if required
396  if($registration_settings->registrationCodeRequired() ||
397  $registration_settings->getAllowCodes())
398  {
399  include_once 'Services/Registration/classes/class.ilRegistrationCode.php';
400  $code = array(
401  "input" => "text",
402  "maxlength" => ilRegistrationCode::CODE_LENGTH,
403  "size" => 40,
404  "required" => (bool)$registration_settings->registrationCodeRequired(),
405  "group" => "login_data"
406  );
407  self::$user_field = array_merge(array("registration_code"=>$code), self::$user_field);
408  }
409  }
410 
411  $fields = $this->getStandardFields();
412  $current_group = "";
413  $custom_fields_done = false;
414  foreach ($fields as $f => $p)
415  {
416  // next group? -> diplay subheader
417  if (($p["group"] != $current_group) &&
419  {
420  if (is_array($custom_fields) && !$custom_fields_done)
421  {
422  // should be appended to "other" or at least before "settings"
423  if($current_group == "other" || $p["group"] == "settings")
424  {
425  // add "other" subheader
426  if($current_group != "other")
427  {
428  $sh = new ilFormSectionHeaderGUI();
429  $sh->setTitle($lng->txt("other"));
430  $a_form->addItem($sh);
431  }
432  foreach($custom_fields as $custom_field)
433  {
434  $a_form->addItem($custom_field);
435  }
436  $custom_fields_done = true;
437  }
438  }
439 
440  $sh = new ilFormSectionHeaderGUI();
441  $sh->setTitle($lng->txt($p["group"]));
442  $a_form->addItem($sh);
443  $current_group = $p["group"];
444  }
445 
446  $m = "";
447  if (isset($p["method"]))
448  {
449  $m = $p["method"];
450  }
451 
452  $lv = (isset($p["lang_var"]) && $p["lang_var"] != "")
453  ? $p["lang_var"]
454  : $f;
455 
456  switch ($p["input"])
457  {
458  case "login":
459  if ((int)$ilSetting->get('allow_change_loginname') || self::$mode == self::MODE_REGISTRATION)
460  {
461  $val = new ilTextInputGUI($lng->txt('username'),'username');
462  if($a_user)
463  {
464  $val->setValue($a_user->getLogin());
465  }
466  $val->setMaxLength(32);
467  $val->setSize(40);
468  $val->setRequired(true);
469  }
470  else
471  {
472  // user account name
473  $val = new ilNonEditableValueGUI($lng->txt("username"), 'ne_un');
474  if($a_user)
475  {
476  $val->setValue($a_user->getLogin());
477  }
478  }
479  $a_form->addItem($val);
480  break;
481 
482  case "text":
484  {
485  $ti = new ilTextInputGUI($lng->txt($lv), "usr_".$f);
486  if($a_user)
487  {
488  $ti->setValue($a_user->$m());
489  }
490  $ti->setMaxLength($p["maxlength"]);
491  $ti->setSize($p["size"]);
492  if($f == "registration_code")
493  {
494  $ti->setRequired($p['required']);
495  }
496  else
497  {
498  $ti->setRequired($ilSetting->get("require_".$f));
499  }
500  if(!$ti->getRequired())
501  {
502  $ti->setDisabled($ilSetting->get("usr_settings_disable_".$f));
503  }
504  $a_form->addItem($ti);
505  }
506  break;
507 
508  case "sel_country":
510  {
511  include_once("./Services/Form/classes/class.ilCountrySelectInputGUI.php");
512  $ci = new ilCountrySelectInputGUI($lng->txt($lv), "usr_".$f);
513  if($a_user)
514  {
515  $ci->setValue($a_user->$m());
516  }
517  $ci->setRequired($ilSetting->get("require_".$f));
518  if(!$ci->getRequired())
519  {
520  $ci->setDisabled($ilSetting->get("usr_settings_disable_".$f));
521  }
522  $a_form->addItem($ci);
523  }
524  break;
525 
526  case "birthday":
528  {
529  $bi = new ilBirthdayInputGUI($lng->txt($lv), "usr_".$f);
530  include_once "./Services/Calendar/classes/class.ilDateTime.php";
531  if ($a_user && strlen($a_user->$m()))
532  {
533  $date = new ilDateTime($a_user->$m(), IL_CAL_DATE);
534  $bi->setDate($date);
535  }
536  $bi->setShowEmpty(true);
537  $bi->setStartYear(1900);
538  $bi->setRequired($ilSetting->get("require_".$f));
539  if(!$bi->getRequired())
540  {
541  $bi->setDisabled($ilSetting->get("usr_settings_disable_".$f));
542  }
543  $a_form->addItem($bi);
544  }
545  break;
546 
547  case "radio":
549  {
550  $rg = new ilRadioGroupInputGUI($lng->txt($lv), "usr_".$f);
551  if($a_user)
552  {
553  $rg->setValue($a_user->$m());
554  }
555  foreach ($p["values"] as $k => $v)
556  {
557  $op = new ilRadioOption($lng->txt($v), $k);
558  $rg->addOption($op);
559  }
560  $rg->setRequired($ilSetting->get("require_".$f));
561  if(!$rg->getRequired())
562  {
563  $rg->setDisabled($ilSetting->get("usr_settings_disable_".$f));
564  }
565  $a_form->addItem($rg);
566  }
567  break;
568 
569  case "picture":
570  if (ilUserProfile::userSettingVisible("upload") && $a_user)
571  {
572  $ii = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile");
573  $im = ilObjUser::_getPersonalPicturePath($a_user->getId(), "small", true,
574  true);
575  $ii->setDisabled($ilSetting->get("usr_settings_disable_upload"));
576  if ($im != "")
577  {
578  $ii->setImage($im);
579  $ii->setAlt($lng->txt("personal_picture"));
580  }
581 
582  // ilinc link as info
583  if (ilUserProfile::userSettingVisible("upload") and
584  $ilSetting->get("ilinc_active"))
585  {
586  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
587  $ilinc_user = new ilObjiLincUser($a_user);
588 
589  if ($ilinc_user->id)
590  {
591  include_once ('./Modules/ILinc/classes/class.ilnetucateXMLAPI.php');
592  $ilincAPI = new ilnetucateXMLAPI();
593  $ilincAPI->uploadPicture($ilinc_user);
594  $response = $ilincAPI->sendRequest("uploadPicture");
595 
596  // return URL to user's personal page
597  $url = trim($response->data['url']['cdata']);
598  $desc =
599  $lng->txt("ilinc_upload_pic_text")." ".
600  '<a href="'.$url.'">'.$lng->txt("ilinc_upload_pic_linktext").'</a>';
601  $ii->setInfo($desc);
602  }
603  }
604 
605  $a_form->addItem($ii);
606  }
607  break;
608 
609  case "roles":
610  if(self::$mode == self::MODE_DESKTOP)
611  {
613  {
614  $global_roles = $rbacreview->getGlobalRoles();
615  foreach($global_roles as $role_id)
616  {
617  if (in_array($role_id,$rbacreview->assignedRoles($a_user->getId())))
618  {
619  $roleObj = $ilias->obj_factory->getInstanceByObjId($role_id);
620  $role_names .= $roleObj->getTitle().", ";
621  unset($roleObj);
622  }
623  }
624  $dr = new ilNonEditableValueGUI($lng->txt("default_roles"), "ne_dr");
625  $dr->setValue(substr($role_names,0,-2));
626  $a_form->addItem($dr);
627  }
628  }
629  else if(self::$mode == self::MODE_REGISTRATION)
630  {
631  if($registration_settings->roleSelectionEnabled())
632  {
633  include_once("./Services/AccessControl/classes/class.ilObjRole.php");
634  $options = array();
635  foreach (ilObjRole::_lookupRegisterAllowed() as $role)
636  {
637  $options[$role["id"]] = $role["title"];
638  }
639  $ta = new ilSelectInputGUI($lng->txt('default_role'), "usr_".$f);
640  $ta->setOptions($options);
641  $ta->setRequired($ilSetting->get("require_".$f));
642  if(!$ta->getRequired())
643  {
644  $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
645  }
646  $a_form->addItem($ta);
647  }
648  }
649  break;
650 
651  case "email":
653  {
654  $em = new ilEMailInputGUI($lng->txt($lv), "usr_".$f);
655  if($a_user)
656  {
657  $em->setValue($a_user->$m());
658  }
659  $em->setRequired($ilSetting->get("require_".$f));
660  if(!$em->getRequired())
661  {
662  $em->setDisabled($ilSetting->get("usr_settings_disable_".$f));
663  }
664  $a_form->addItem($em);
665  }
666  break;
667 
668  case "textarea":
670  {
671  $ta = new ilTextAreaInputGUI($lng->txt($lv), "usr_".$f);
672  if($a_user)
673  {
674  $ta->setValue($a_user->$m());
675  }
676  $ta->setRows($p["rows"]);
677  $ta->setCols($p["cols"]);
678  $ta->setRequired($ilSetting->get("require_".$f));
679  if(!$ta->getRequired())
680  {
681  $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
682  }
683  $a_form->addItem($ta);
684  }
685  break;
686 
687  case "messenger":
688  if (ilUserProfile::userSettingVisible("instant_messengers"))
689  {
690  $im_arr = $p["types"];
691  foreach ($im_arr as $im_name)
692  {
693  $im = new ilTextInputGUI($lng->txt("im_".$im_name), "usr_im_".$im_name);
694  if($a_user)
695  {
696  $im->setValue($a_user->getInstantMessengerId($im_name));
697  }
698  $im->setMaxLength($p["maxlength"]);
699  $im->setSize($p["size"]);
700  $im->setRequired($ilSetting->get("require_"."instant_messengers"));
701  if(!$im->getRequired())
702  {
703  $im->setDisabled($ilSetting->get("usr_settings_disable_"."instant_messengers"));
704  }
705  $a_form->addItem($im);
706  }
707  }
708  break;
709 
710  case "password":
711  if (self::$mode == self::MODE_REGISTRATION)
712  {
713  if(!$registration_settings->passwordGenerationEnabled())
714  {
715  $ta = new ilPasswordInputGUI($lng->txt($lv), "usr_".$f);
716  $ta->setRequired(true);
717  // $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
718  }
719  else
720  {
721  $ta = new ilNonEditableValueGUI($lng->txt($lv));
722  $ta->setValue($lng->txt("reg_passwd_via_mail"));
723  }
724  $a_form->addItem($ta);
725  }
726  break;
727 
728  case "language":
730  {
731  $ta = new ilSelectInputGUI($lng->txt($lv), "usr_".$f);
732  if($a_user)
733  {
734  $ta->setValue($a_user->$m());
735  }
736  $options = array();
737  foreach ($lng->getInstalledLanguages() as $lang_key)
738  {
739  $options[$lang_key] = $lng->txt("lang_".$lang_key);
740  }
741  $ta->setOptions($options);
742  $ta->setRequired($ilSetting->get("require_".$f));
743  if(!$ta->getRequired())
744  {
745  $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
746  }
747  $a_form->addItem($ta);
748  }
749  break;
750  }
751  }
752 
753  // append custom fields as "other"
754  if(is_array($custom_fields) && !$custom_fields_done)
755  {
756  // add "other" subheader
757  if($current_group != "other")
758  {
759  $sh = new ilFormSectionHeaderGUI();
760  $sh->setTitle($lng->txt("other"));
761  $a_form->addItem($sh);
762  }
763  foreach($custom_fields as $custom_field)
764  {
765  $a_form->addItem($custom_field);
766  }
767  }
768  }
769 
770 
774  static function userSettingVisible($a_setting)
775  {
776  global $ilSetting;
777 
778  if(self::$mode == self::MODE_DESKTOP)
779  {
780  return ($ilSetting->get("usr_settings_hide_".$a_setting) != 1);
781  }
782  else
783  {
784  if(isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true)
785  {
786  return true;
787  }
788  return ($ilSetting->get("usr_settings_visib_reg_".$a_setting, "1") || $ilSetting->get("require_".$a_setting, "0"));
789  }
790  }
791 
792  static function setMode($mode)
793  {
794  global $lng;
795 
796  if(in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION)))
797  {
798  self::$mode = $mode;
799  return true;
800  }
801  return false;
802  }
803 
804 }
805 ?>