ILIAS  Release_4_1_x_branch Revision 61804
 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() || $ti->getValue())
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() || $ci->getValue())
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  $date = null;
532  if ($a_user && strlen($a_user->$m()))
533  {
534  $date = new ilDateTime($a_user->$m(), IL_CAL_DATE);
535  $bi->setDate($date);
536  }
537  $bi->setShowEmpty(true);
538  $bi->setStartYear(1900);
539  $bi->setRequired($ilSetting->get("require_".$f));
540  if(!$bi->getRequired() || $date)
541  {
542  $bi->setDisabled($ilSetting->get("usr_settings_disable_".$f));
543  }
544  $a_form->addItem($bi);
545  }
546  break;
547 
548  case "radio":
550  {
551  $rg = new ilRadioGroupInputGUI($lng->txt($lv), "usr_".$f);
552  if($a_user)
553  {
554  $rg->setValue($a_user->$m());
555  }
556  foreach ($p["values"] as $k => $v)
557  {
558  $op = new ilRadioOption($lng->txt($v), $k);
559  $rg->addOption($op);
560  }
561  $rg->setRequired($ilSetting->get("require_".$f));
562  if(!$rg->getRequired() || $rg->getValue())
563  {
564  $rg->setDisabled($ilSetting->get("usr_settings_disable_".$f));
565  }
566  $a_form->addItem($rg);
567  }
568  break;
569 
570  case "picture":
571  if (ilUserProfile::userSettingVisible("upload") && $a_user)
572  {
573  $ii = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile");
574  $im = ilObjUser::_getPersonalPicturePath($a_user->getId(), "small", true,
575  true);
576  $ii->setDisabled($ilSetting->get("usr_settings_disable_upload"));
577  if ($im != "")
578  {
579  $ii->setImage($im);
580  $ii->setAlt($lng->txt("personal_picture"));
581  }
582 
583  // ilinc link as info
584  if (ilUserProfile::userSettingVisible("upload") and
585  $ilSetting->get("ilinc_active"))
586  {
587  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
588  $ilinc_user = new ilObjiLincUser($a_user);
589 
590  if ($ilinc_user->id)
591  {
592  include_once ('./Modules/ILinc/classes/class.ilnetucateXMLAPI.php');
593  $ilincAPI = new ilnetucateXMLAPI();
594  $ilincAPI->uploadPicture($ilinc_user);
595  $response = $ilincAPI->sendRequest("uploadPicture");
596 
597  // return URL to user's personal page
598  $url = trim($response->data['url']['cdata']);
599  $desc =
600  $lng->txt("ilinc_upload_pic_text")." ".
601  '<a href="'.$url.'">'.$lng->txt("ilinc_upload_pic_linktext").'</a>';
602  $ii->setInfo($desc);
603  }
604  }
605 
606  $a_form->addItem($ii);
607  }
608  break;
609 
610  case "roles":
611  if(self::$mode == self::MODE_DESKTOP)
612  {
614  {
615  $global_roles = $rbacreview->getGlobalRoles();
616  foreach($global_roles as $role_id)
617  {
618  if (in_array($role_id,$rbacreview->assignedRoles($a_user->getId())))
619  {
620  $roleObj = $ilias->obj_factory->getInstanceByObjId($role_id);
621  $role_names .= $roleObj->getTitle().", ";
622  unset($roleObj);
623  }
624  }
625  $dr = new ilNonEditableValueGUI($lng->txt("default_roles"), "ne_dr");
626  $dr->setValue(substr($role_names,0,-2));
627  $a_form->addItem($dr);
628  }
629  }
630  else if(self::$mode == self::MODE_REGISTRATION)
631  {
632  if($registration_settings->roleSelectionEnabled())
633  {
634  include_once("./Services/AccessControl/classes/class.ilObjRole.php");
635  $options = array();
636  foreach (ilObjRole::_lookupRegisterAllowed() as $role)
637  {
638  $options[$role["id"]] = $role["title"];
639  }
640  $ta = new ilSelectInputGUI($lng->txt('default_role'), "usr_".$f);
641  $ta->setOptions($options);
642  $ta->setRequired($ilSetting->get("require_".$f));
643  if(!$ta->getRequired())
644  {
645  $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
646  }
647  $a_form->addItem($ta);
648  }
649  }
650  break;
651 
652  case "email":
654  {
655  $em = new ilEMailInputGUI($lng->txt($lv), "usr_".$f);
656  if($a_user)
657  {
658  $em->setValue($a_user->$m());
659  }
660  $em->setRequired($ilSetting->get("require_".$f));
661  if(!$em->getRequired() || $em->getValue())
662  {
663  $em->setDisabled($ilSetting->get("usr_settings_disable_".$f));
664  }
665  $a_form->addItem($em);
666  }
667  break;
668 
669  case "textarea":
671  {
672  $ta = new ilTextAreaInputGUI($lng->txt($lv), "usr_".$f);
673  if($a_user)
674  {
675  $ta->setValue($a_user->$m());
676  }
677  $ta->setRows($p["rows"]);
678  $ta->setCols($p["cols"]);
679  $ta->setRequired($ilSetting->get("require_".$f));
680  if(!$ta->getRequired() || $ta->getValue())
681  {
682  $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
683  }
684  $a_form->addItem($ta);
685  }
686  break;
687 
688  case "messenger":
689  if (ilUserProfile::userSettingVisible("instant_messengers"))
690  {
691  $im_arr = $p["types"];
692  foreach ($im_arr as $im_name)
693  {
694  $im = new ilTextInputGUI($lng->txt("im_".$im_name), "usr_im_".$im_name);
695  if($a_user)
696  {
697  $im->setValue($a_user->getInstantMessengerId($im_name));
698  }
699  $im->setMaxLength($p["maxlength"]);
700  $im->setSize($p["size"]);
701  $im->setRequired($ilSetting->get("require_"."instant_messengers"));
702  if(!$im->getRequired() || $im->getValue())
703  {
704  $im->setDisabled($ilSetting->get("usr_settings_disable_"."instant_messengers"));
705  }
706  $a_form->addItem($im);
707  }
708  }
709  break;
710 
711  case "password":
712  if (self::$mode == self::MODE_REGISTRATION)
713  {
714  if(!$registration_settings->passwordGenerationEnabled())
715  {
716  $ta = new ilPasswordInputGUI($lng->txt($lv), "usr_".$f);
717  $ta->setRequired(true);
718  // $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
719  }
720  else
721  {
722  $ta = new ilNonEditableValueGUI($lng->txt($lv));
723  $ta->setValue($lng->txt("reg_passwd_via_mail"));
724  }
725  $a_form->addItem($ta);
726  }
727  break;
728 
729  case "language":
731  {
732  $ta = new ilSelectInputGUI($lng->txt($lv), "usr_".$f);
733  if($a_user)
734  {
735  $ta->setValue($a_user->$m());
736  }
737  $options = array();
738  foreach ($lng->getInstalledLanguages() as $lang_key)
739  {
740  $options[$lang_key] = $lng->txt("lang_".$lang_key);
741  }
742  $ta->setOptions($options);
743  $ta->setRequired($ilSetting->get("require_".$f));
744  if(!$ta->getRequired() || $ta->getValue())
745  {
746  $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
747  }
748  $a_form->addItem($ta);
749  }
750  break;
751  }
752  }
753 
754  // append custom fields as "other"
755  if(is_array($custom_fields) && !$custom_fields_done)
756  {
757  // add "other" subheader
758  if($current_group != "other")
759  {
760  $sh = new ilFormSectionHeaderGUI();
761  $sh->setTitle($lng->txt("other"));
762  $a_form->addItem($sh);
763  }
764  foreach($custom_fields as $custom_field)
765  {
766  $a_form->addItem($custom_field);
767  }
768  }
769  }
770 
771 
775  static function userSettingVisible($a_setting)
776  {
777  global $ilSetting;
778 
779  if(self::$mode == self::MODE_DESKTOP)
780  {
781  return ($ilSetting->get("usr_settings_hide_".$a_setting) != 1);
782  }
783  else
784  {
785  if(isset(self::$user_field[$a_setting]["visib_reg_hide"]) && self::$user_field[$a_setting]["visib_reg_hide"] === true)
786  {
787  return true;
788  }
789  return ($ilSetting->get("usr_settings_visib_reg_".$a_setting, "1") || $ilSetting->get("require_".$a_setting, "0"));
790  }
791  }
792 
793  static function setMode($mode)
794  {
795  global $lng;
796 
797  if(in_array($mode, array(self::MODE_DESKTOP, self::MODE_REGISTRATION)))
798  {
799  self::$mode = $mode;
800  return true;
801  }
802  return false;
803  }
804 
805 }
806 ?>