ILIAS  Release_4_0_x_branch Revision 61816
 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  // this array should be used in all places where user data is tackled
18  // in the future: registration, personal profile, user administration
19  // public profile, user import/export
20  // for now this is not implemented yet. Please list places, that already use it:
21  //
22  // - personal profile
23  // - (global) standard user profile fields settings
24  //
25  // the following attributes are defined (can be extended if needed):
26  // - input: input type
27  // standard inputs: text, radio, selection, textarea
28  // special inputs: login
29  // - input dependend attributes
30  // - maxlength, sizte for text
31  // - values array for radio
32  // - cols/rows for text areas
33  // - options array for selections
34  // - method: ilObjUser get-method, e.g. getFirstname
35  // - group: group id (id is also used as lang_var for sub headers in forms
36  // - lang_var: if key should not be used as lang var, this overwrites the usage in forms
37  // - settings property related attributes, settingsproperties are ("visible", "changeable",
38  // "searchable", "required", "export", "course_export" and "registration")
39  // - <settingsproperty>_hide: hide this property in settings (not implemented)
40  // - <settingsproperty>_fix_value: property has a fix value (cannot be changed)
41  private static $user_field = array(
42  "username" => array(
43  "input" => "login",
44  "maxlength" => 32,
45  "size" => 40,
46  "method" => "getLogin",
47  "course_export_fix_value" => 1,
48  "changeable_hide" => true,
49  "required_hide" => true,
50  "group" => "personal_data"),
51  "firstname" => array(
52  "input" => "text",
53  "maxlength" => 32,
54  "size" => 40,
55  "method" => "getFirstname",
56  "required_fix_value" => 1,
57  "visib_reg_fix_value" => 1,
58  "course_export_fix_value" => 1,
59  "group" => "personal_data"),
60  "lastname" => array(
61  "input" => "text",
62  "maxlength" => 32,
63  "size" => 40,
64  "method" => "getLastname",
65  "required_fix_value" => 1,
66  "visib_reg_fix_value" => 1,
67  "course_export_fix_value" => 1,
68  "group" => "personal_data"),
69  "title" => array(
70  "input" => "text",
71  "lang_var" => "person_title",
72  "maxlength" => 32,
73  "size" => 40,
74  "method" => "getUTitle",
75  "group" => "personal_data"),
76  "birthday" => array(
77  "input" => "birthday",
78  "lang_var" => "birthday",
79  "maxlength" => 32,
80  "size" => 40,
81  "registration_hide" => true,
82  "method" => "getBirthday",
83  "group" => "personal_data"),
84  "gender" => array(
85  "input" => "radio",
86  "values" => array("f" => "gender_f", "m" => "gender_m"),
87  "method" => "getGender",
88  "group" => "personal_data"),
89  "upload" => array(
90  "input" => "picture",
91  "required_hide" => true,
92  "registration_hide" => true,
93  "course_export_hide" => true,
94  "lang_var" => "personal_picture",
95  "group" => "personal_data"),
96  "roles" => array(
97  "input" => "roles",
98  "changeable_hide" => true,
99  "required_hide" => true,
100  "registration_hide" => true,
101  "export_hide" => true,
102  "course_export_hide" => true,
103  "group" => "personal_data"),
104  "password" => array(
105  "input" => "password",
106  "required_hide" => true,
107  "registration_hide" => true,
108  "course_export_hide" => true,
109  "group" => "personal_data"),
110  "institution" => array(
111  "input" => "text",
112  "maxlength" => 80,
113  "size" => 40,
114  "method" => "getInstitution",
115  "group" => "contact_data"),
116  "department" => array(
117  "input" => "text",
118  "maxlength" => 80,
119  "size" => 40,
120  "method" => "getDepartment",
121  "group" => "contact_data"),
122  "street" => array(
123  "input" => "text",
124  "maxlength" => 40,
125  "size" => 40,
126  "method" => "getStreet",
127  "group" => "contact_data"),
128  "zipcode" => array(
129  "input" => "text",
130  "maxlength" => 10,
131  "size" => 10,
132  "method" => "getZipcode",
133  "group" => "contact_data"),
134  "city" => array(
135  "input" => "text",
136  "maxlength" => 40,
137  "size" => 40,
138  "method" => "getCity",
139  "group" => "contact_data"),
140  "country" => array(
141  "input" => "text",
142  "maxlength" => 40,
143  "size" => 40,
144  "method" => "getCountry",
145  "group" => "contact_data"),
146  "phone_office" => array(
147  "input" => "text",
148  "maxlength" => 40,
149  "size" => 40,
150  "method" => "getPhoneOffice",
151  "group" => "contact_data"),
152  "phone_home" => array(
153  "input" => "text",
154  "maxlength" => 40,
155  "size" => 40,
156  "method" => "getPhoneHome",
157  "group" => "contact_data"),
158  "phone_mobile" => array(
159  "input" => "text",
160  "maxlength" => 40,
161  "size" => 40,
162  "method" => "getPhoneMobile",
163  "group" => "contact_data"),
164  "fax" => array(
165  "input" => "text",
166  "maxlength" => 40,
167  "size" => 40,
168  "method" => "getFax",
169  "group" => "contact_data"),
170  "email" => array(
171  "input" => "email",
172  "maxlength" => 40,
173  "size" => 40,
174  "method" => "getEmail",
175  "group" => "contact_data"),
176  "hobby" => array(
177  "input" => "textarea",
178  "rows" => 3,
179  "cols" => 45,
180  "method" => "getHobby",
181  "group" => "contact_data"),
182  "referral_comment" => array(
183  "input" => "textarea",
184  "rows" => 3,
185  "cols" => 45,
186  "method" => "getComment",
187  "course_export_hide" => true,
188  "group" => "contact_data"),
189  "instant_messengers" => array(
190  "input" => "messenger",
191  "types" => array("icq","yahoo","msn","aim","skype","jabber","voip"),
192  "maxlength" => 40,
193  "size" => 40,
194  "registration_hide" => true,
195  "course_export_hide" => true,
196  "group" => "instant_messengers"),
197  "matriculation" => array(
198  "input" => "text",
199  "maxlength" => 40,
200  "size" => 40,
201  "method" => "getMatriculation",
202  "group" => "other"),
203  "delicious" => array(
204  "input" => "text",
205  "maxlength" => 40,
206  "size" => 40,
207  "method" => "getDelicious",
208  "group" => "other"),
209  "language" => array(
210  "input" => "language",
211  "method" => "getLanguage",
212  "required_hide" => true,
213  "registration_hide" => true,
214  "course_export_hide" => true,
215  "group" => "settings"),
216  "skin_style" => array(
217  "input" => "skinstyle",
218  "required_hide" => true,
219  "registration_hide" => true,
220  "course_export_hide" => true,
221  "group" => "settings"),
222  "hits_per_page" => array(
223  "input" => "hitsperpage",
224  "default" => 10,
225  "options" => array(
226  10 => 10, 15 => 15, 20 => 20, 30 => 30, 40 => 40,
227  50 => 50, 100 => 100, 9999 => 9999),
228  "required_hide" => true,
229  "registration_hide" => true,
230  "course_export_hide" => true,
231  "group" => "settings"),
232  "show_users_online" => array(
233  "input" => "selection",
234  "default" => "y",
235  "options" => array(
236  "y" => "users_online_show_short_y",
237  "associated" => "users_online_show_short_associated",
238  "n" => "users_online_show_short_n"),
239  "required_hide" => true,
240  "registration_hide" => true,
241  "course_export_hide" => true,
242  "group" => "settings"),
243  "hide_own_online_status" => array(
244  "input" => "selection",
245  "required_hide" => true,
246  "registration_hide" => true,
247  "course_export_hide" => true,
248  "group" => "settings"),
249  "preferences" => array(
250  "visible_fix_value" => 1,
251  "changeable_fix_value" => 1,
252  "required_hide" => true,
253  "registration_hide" => true,
254  "course_export_hide" => true,
255  "group" => "preferences"),
256  "mail_incoming_mail" => array(
257  "input" => "selection",
258  "default" => "y",
259  "options" => array(
260  IL_MAIL_LOCAL => "mail_incoming_local",
261  IL_MAIL_EMAIL => "mail_incoming_smtp",
262  IL_MAIL_BOTH => "mail_incoming_both"),
263  "required_hide" => true,
264  "registration_hide" => true,
265  "course_export_hide" => true,
266  "export_hide" => true,
267  "search_hide" => true,
268  "group" => "settings")
269 
270  );
271 
275  function __construct()
276  {
277  $this->skip_groups = array();
278  $this->skip_fields = array();
279  }
280 
284  function getStandardFields()
285  {
286  $fields = array();
287  foreach (self::$user_field as $f => $p)
288  {
289  // skip hidden groups
290  if (in_array($p["group"], $this->skip_groups) ||
291  in_array($f, $this->skip_fields))
292  {
293  continue;
294  }
295  $fields[$f] = $p;
296  }
297  return $fields;
298  }
299 
303  function skipGroup($a_group)
304  {
305  $this->skip_groups[] = $a_group;
306  }
307 
311  function skipField($a_field)
312  {
313  $this->skip_fields[] = $a_field;
314  }
315 
319  function addStandardFieldsToForm($a_form, $a_user)
320  {
321  global $ilSetting, $lng, $rbacreview, $ilias;
322 
323  $fields = $this->getStandardFields();
324 
325  $current_group = "";
326  foreach ($fields as $f => $p)
327  {
328 //var_dump($p);
329  // next group? -> diplay subheader
330  if (($p["group"] != $current_group) &&
332  {
333  // contact data
334  $sh = new ilFormSectionHeaderGUI();
335  $sh->setTitle($lng->txt($p["group"]));
336  $a_form->addItem($sh);
337  $current_group = $p["group"];
338  }
339 
340  $m = $p["method"];
341 
342  $lv = ($p["lang_var"] != "")
343  ? $p["lang_var"]
344  : $f;
345 
346  switch ($p["input"])
347  {
348  case "login":
349  if ((int)$ilSetting->get('allow_change_loginname'))
350  {
351  $val = new ilTextInputGUI($lng->txt('username'),'username');
352  $val->setValue($a_user->getLogin());
353  $val->setMaxLength(32);
354  $val->setSize(40);
355  $val->setRequired(true);
356  }
357  else
358  {
359  // user account name
360  $val = new ilNonEditableValueGUI($lng->txt("username"), 'ne_un');
361  $val->setValue($a_user->getLogin());
362  }
363  $a_form->addItem($val);
364  break;
365 
366  case "text":
368  {
369  $ti = new ilTextInputGUI($lng->txt($lv), "usr_".$f);
370  $ti->setValue($a_user->$m());
371  $ti->setMaxLength($p["maxlength"]);
372  $ti->setSize($p["size"]);
373  $ti->setDisabled($ilSetting->get("usr_settings_disable_".$f));
374  $ti->setRequired($ilSetting->get("require_".$f));
375  $a_form->addItem($ti);
376  }
377  break;
378 
379  case "birthday":
381  {
382  $bi = new ilBirthdayInputGUI($lng->txt($lv), "usr_".$f);
383  include_once "./Services/Calendar/classes/class.ilDateTime.php";
384  if (strlen($a_user->$m()))
385  {
386  $date = new ilDateTime($a_user->$m(), IL_CAL_DATE);
387  $bi->setDate($date);
388  }
389  $bi->setShowEmpty(true);
390  $bi->setStartYear(1900);
391  $bi->setDisabled($ilSetting->get("usr_settings_disable_".$f));
392  $bi->setRequired($ilSetting->get("require_".$f));
393  $a_form->addItem($bi);
394  }
395  break;
396 
397  case "radio":
399  {
400  $rg = new ilRadioGroupInputGUI($lng->txt($lv), "usr_".$f);
401  $rg->setValue($a_user->$m());
402  foreach ($p["values"] as $k => $v)
403  {
404  $op = new ilRadioOption($lng->txt($v), $k);
405  $rg->addOption($op);
406  }
407  $rg->setDisabled($ilSetting->get("usr_settings_disable_".$f));
408  $rg->setRequired($ilSetting->get("require_".$f));
409  $a_form->addItem($rg);
410  }
411  break;
412 
413  case "picture":
414  if (ilUserProfile::userSettingVisible("upload"))
415  {
416  $ii = new ilImageFileInputGUI($lng->txt("personal_picture"), "userfile");
417  $im = ilObjUser::_getPersonalPicturePath($a_user->getId(), "small", true,
418  true);
419  $ii->setDisabled($ilSetting->get("usr_settings_disable_upload"));
420  if ($im != "")
421  {
422  $ii->setImage($im);
423  $ii->setAlt($lng->txt("personal_picture"));
424  }
425 
426  // ilinc link as info
427  if (ilUserProfile::userSettingVisible("upload") and
428  $ilSetting->get("ilinc_active"))
429  {
430  include_once ('./Modules/ILinc/classes/class.ilObjiLincUser.php');
431  $ilinc_user = new ilObjiLincUser($a_user);
432 
433  if ($ilinc_user->id)
434  {
435  include_once ('./Modules/ILinc/classes/class.ilnetucateXMLAPI.php');
436  $ilincAPI = new ilnetucateXMLAPI();
437  $ilincAPI->uploadPicture($ilinc_user);
438  $response = $ilincAPI->sendRequest("uploadPicture");
439 
440  // return URL to user's personal page
441  $url = trim($response->data['url']['cdata']);
442  $desc =
443  $lng->txt("ilinc_upload_pic_text")." ".
444  '<a href="'.$url.'">'.$lng->txt("ilinc_upload_pic_linktext").'</a>';
445  $ii->setInfo($desc);
446  }
447  }
448 
449  $a_form->addItem($ii);
450  }
451  break;
452 
453  case "roles":
454  $global_roles = $rbacreview->getGlobalRoles();
455  foreach($global_roles as $role_id)
456  {
457  if (in_array($role_id,$rbacreview->assignedRoles($a_user->getId())))
458  {
459  $roleObj = $ilias->obj_factory->getInstanceByObjId($role_id);
460  $role_names .= $roleObj->getTitle().", ";
461  unset($roleObj);
462  }
463  }
464  $dr = new ilNonEditableValueGUI($lng->txt("default_roles"), "ne_dr");
465  $dr->setValue(substr($role_names,0,-2));
466  $a_form->addItem($dr);
467  break;
468 
469  case "email":
471  {
472  $em = new ilTextInputGUI($lng->txt($lv), "usr_".$f);
473  $em->setValue($a_user->$m());
474  $em->setMaxLength($p["maxlength"]);
475  $em->setSize($p["size"]);
476  $em->setDisabled($ilSetting->get("usr_settings_disable_".$f));
477  $em->setRequired($ilSetting->get("require_".$f));
478  $a_form->addItem($em);
479  }
480  break;
481 
482  case "textarea":
484  {
485  $ta = new ilTextAreaInputGUI($lng->txt($lv), "usr_".$f);
486  $ta->setValue($a_user->$m());
487  $ta->setRows($p["rows"]);
488  $ta->setCols($p["cols"]);
489  $ta->setDisabled($ilSetting->get("usr_settings_disable_".$f));
490  $ta->setRequired($ilSetting->get("require_".$f));
491  $a_form->addItem($ta);
492  }
493  break;
494 
495  case "messenger":
496  if (ilUserProfile::userSettingVisible("instant_messengers"))
497  {
498  $im_arr = $p["types"];
499  foreach ($im_arr as $im_name)
500  {
501  $im = new ilTextInputGUI($lng->txt("im_".$im_name), "usr_im_".$im_name);
502  $im->setValue($a_user->getInstantMessengerId($im_name));
503  $im->setMaxLength($p["maxlength"]);
504  $im->setSize($p["size"]);
505  $im->setDisabled($ilSetting->get("usr_settings_disable_"."instant_messengers"));
506  $im->setRequired($ilSetting->get("require_"."instant_messengers"));
507  $a_form->addItem($im);
508  }
509  }
510  break;
511 
512  case "password":
513  // todo
514  break;
515  }
516  }
517  }
518 
522  static function userSettingVisible($a_setting)
523  {
524  global $ilSetting;
525 
526  return ($ilSetting->get("usr_settings_hide_".$a_setting) != 1);
527  }
528 }
529 ?>