ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjUser.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 define ("IL_PASSWD_PLAIN", "plain");
5 define ("IL_PASSWD_MD5", "md5"); // ILIAS 3 Password
6 define ("IL_PASSWD_CRYPT", "crypt"); // ILIAS 2 Password
7 
8 
9 require_once "./Services/Object/classes/class.ilObject.php";
10 require_once './Services/User/exceptions/class.ilUserException.php';
11 
24 class ilObjUser extends ilObject
25 {
30  // personal data
31 
32  var $login; // username in system
33 
34  var $passwd; // password encoded in the format specified by $passwd_type
36  // specifies the password format.
37  // value: IL_PASSWD_PLAIN, IL_PASSWD_MD5 or IL_PASSWD_CRYPT.
38 
39  // Differences between password format in class ilObjUser and
40  // in table usr_data:
41  // Class ilObjUser supports three different password types
42  // (plain, MD5 and CRYPT) and it uses the variables $passwd
43  // and $passwd_type to store them.
44  // Table usr_data supports only two different password types
45  // (MD5 and CRYPT) and it uses the columns "passwd" and
46  // "il2passwd" to store them.
47  // The conversion between these two storage layouts is done
48  // in the methods that perform SQL statements. All other
49  // methods work exclusively with the $passwd and $passwd_type
50  // variables.
51 
52  var $gender; // 'm' or 'f'
53  var $utitle; // user title (keep in mind, that we derive $title from object also!)
55  var $lastname;
56  protected $birthday;
57  var $fullname; // title + firstname + lastname in one string
58  //var $archive_dir = "./image"; // point to image file (should be flexible)
59  // address data
62  var $street;
63  var $city;
64  var $zipcode;
65  var $country;
70  var $fax;
71  var $email;
72  var $hobby;
75  var $approve_date = null;
76  var $agree_date = null;
77  var $active;
78  //var $ilinc_id; // unique Id for netucate ilinc service
79  var $client_ip; // client ip to check before login
80  var $auth_mode; // authentication mode
81 
82  var $im_icq;
83  var $im_yahoo;
84  var $im_msn;
85  var $im_aim;
86  var $im_skype;
88  var $im_voip;
89 
91  var $latitude;
93  var $loc_zoom;
94 
97 
98  var $user_defined_data = array();
99 
105  var $prefs;
106 
112  var $skin;
113 
114 
121 
127  var $ilias;
128 
131 
135  protected static $personal_image_cache = array();
136 
142  protected $inactivation_date = null;
143 
148  private $is_self_registered = false;
149 
155  function ilObjUser($a_user_id = 0, $a_call_by_reference = false)
156  {
157  global $ilias,$ilDB;
158 
159  // init variables
160  $this->ilias =& $ilias;
161  $this->db =& $ilDB;
162 
163  $this->type = "usr";
164  $this->ilObject($a_user_id, $a_call_by_reference);
165  $this->auth_mode = "default";
166  $this->passwd_type = IL_PASSWD_PLAIN;
167 
168  // for gender selection. don't change this
169  /*$this->gender = array(
170  'm' => "salutation_m",
171  'f' => "salutation_f"
172  );*/
173  if ($a_user_id > 0)
174  {
175  $this->setId($a_user_id);
176  $this->read();
177  }
178  else
179  {
180  // TODO: all code in else-structure doesn't belongs in class user !!!
181  //load default data
182  $this->prefs = array();
183  //language
184  $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
185 
186  //skin and pda support
187  $this->skin = $this->ilias->ini->readVariable("layout","skin");
188 
189  $this->prefs["skin"] = $this->skin;
190  $this->prefs["show_users_online"] = "y";
191 
192  //style (css)
193  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
194  }
195  }
196 
201  function read()
202  {
203  global $ilErr, $ilDB;
204 
205  // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
206  // use (3.11.0 alpha)
207  /*$q = "SELECT * FROM usr_data ".
208  "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
209  "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
210  $r = $ilDB->queryF("SELECT * FROM usr_data ".
211  "WHERE usr_id= %s", array("integer"), array($this->id));
212 
213  if ($data = $ilDB->fetchAssoc($r))
214  {
215  // convert password storage layout used by table usr_data into
216  // storage layout used by class ilObjUser
217  if ($data["passwd"] == "" && $data["i2passwd"] != "")
218  {
219  $data["passwd_type"] = IL_PASSWD_CRYPT;
220  $data["passwd"] = $data["i2passwd"];
221  }
222  else
223  {
224  $data["passwd_type"] = IL_PASSWD_MD5;
225  //$data["passwd"] = $data["passwd"]; (implicit)
226  }
227  unset($data["i2passw"]);
228 
229  // this assign must not be set via $this->assignData($data)
230  // because this method will be called on profile updates and
231  // would set this values to 0, because they arent posted from form
232  $this->setLastPasswordChangeTS( $data['last_password_change'] );
233  $this->setLoginAttempts( $data['login_attempts'] );
234 
235 
236  // fill member vars in one shot
237  $this->assignData($data);
238 
239  //get userpreferences from usr_pref table
240  $this->readPrefs();
241 
242  //set language to default if not set
243  if ($this->prefs["language"] == "")
244  {
245  $this->prefs["language"] = $this->oldPrefs["language"];
246  }
247 
248  //check skin-setting
249  include_once("./Services/Style/classes/class.ilStyleDefinition.php");
250  if ($this->prefs["skin"] == "" ||
251  !ilStyleDefinition::skinExists($this->prefs["skin"]))
252  {
253  $this->prefs["skin"] = $this->oldPrefs["skin"];
254  }
255 
256  $this->skin = $this->prefs["skin"];
257 
258  //check style-setting (skins could have more than one stylesheet
259  if ($this->prefs["style"] == "" ||
260  !ilStyleDefinition::skinExists($this->skin, $this->prefs["style"]))
261  {
262  //load default (css)
263  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
264  }
265 
266  if (empty($this->prefs["hits_per_page"]))
267  {
268  $this->prefs["hits_per_page"] = 10;
269  }
270 
271  }
272  else
273  {
274  $ilErr->raiseError("<b>Error: There is no dataset with id ".
275  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
276  "<br />Line: ".__LINE__, $ilErr->FATAL);
277  }
278 
279  $this->readUserDefinedFields();
280 
281  parent::read();
282  }
283 
289  function assignData($a_data)
290  {
291  global $ilErr, $ilDB, $lng;
292 
293  // basic personal data
294  $this->setLogin($a_data["login"]);
295  if (! $a_data["passwd_type"])
296  {
297  $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
298  $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
299  .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
300  }
301  if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
302  {
303  $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
304  }
305 
306  $this->setGender($a_data["gender"]);
307  $this->setUTitle($a_data["title"]);
308  $this->setFirstname($a_data["firstname"]);
309  $this->setLastname($a_data["lastname"]);
310  $this->setFullname();
311  if (!is_array($a_data['birthday']))
312  {
313  $this->setBirthday($a_data['birthday']);
314  }
315  else
316  {
317  $this->setBirthday(null);
318  }
319 
320  // address data
321  $this->setInstitution($a_data["institution"]);
322  $this->setDepartment($a_data["department"]);
323  $this->setStreet($a_data["street"]);
324  $this->setCity($a_data["city"]);
325  $this->setZipcode($a_data["zipcode"]);
326  $this->setCountry($a_data["country"]);
327  $this->setSelectedCountry($a_data["sel_country"]);
328  $this->setPhoneOffice($a_data["phone_office"]);
329  $this->setPhoneHome($a_data["phone_home"]);
330  $this->setPhoneMobile($a_data["phone_mobile"]);
331  $this->setFax($a_data["fax"]);
332  $this->setMatriculation($a_data["matriculation"]);
333  $this->setEmail($a_data["email"]);
334  $this->setHobby($a_data["hobby"]);
335  $this->setClientIP($a_data["client_ip"]);
336 
337  // instant messenger data
338  $this->setInstantMessengerId('icq',$a_data["im_icq"]);
339  $this->setInstantMessengerId('yahoo',$a_data["im_yahoo"]);
340  $this->setInstantMessengerId('msn',$a_data["im_msn"]);
341  $this->setInstantMessengerId('aim',$a_data["im_aim"]);
342  $this->setInstantMessengerId('skype',$a_data["im_skype"]);
343  $this->setInstantMessengerId('jabber',$a_data["im_jabber"]);
344  $this->setInstantMessengerId('voip',$a_data["im_voip"]);
345 
346  // other data
347  $this->setDelicious($a_data["delicious"]);
348  $this->setLatitude($a_data["latitude"]);
349  $this->setLongitude($a_data["longitude"]);
350  $this->setLocationZoom($a_data["loc_zoom"]);
351 
352  // system data
353  $this->setLastLogin($a_data["last_login"]);
354  $this->setLastUpdate($a_data["last_update"]);
355  $this->create_date = $a_data["create_date"];
356  $this->setComment($a_data["referral_comment"]);
357  $this->approve_date = $a_data["approve_date"];
358  $this->active = $a_data["active"];
359  $this->agree_date = $a_data["agree_date"];
360 
361  $this->setInactivationDate($a_data["inactivation_date"]);
362 
363  // time limitation
364  $this->setTimeLimitOwner($a_data["time_limit_owner"]);
365  $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
366  $this->setTimeLimitFrom($a_data["time_limit_from"]);
367  $this->setTimeLimitUntil($a_data["time_limit_until"]);
368  $this->setTimeLimitMessage($a_data['time_limit_message']);
369 
370  // user profile incomplete?
371  $this->setProfileIncomplete($a_data["profile_incomplete"]);
372 
373  //iLinc
374  //$this->setiLincData($a_data['ilinc_id'],$a_data['ilinc_login'],$a_data['ilinc_passwd']);
375 
376  //authentication
377  $this->setAuthMode($a_data['auth_mode']);
378  $this->setExternalAccount($a_data['ext_account']);
379 
380  $this->setIsSelfRegistered((bool)$a_data['is_self_registered']);
381  }
382 
389  function saveAsNew($a_from_formular = true)
390  {
391  global $ilErr, $ilDB, $ilSetting, $ilUser;
392 
393  switch ($this->passwd_type)
394  {
395  case IL_PASSWD_PLAIN:
396  $pw_field = "passwd";
397  if(strlen($this->passwd))
398  {
399  $pw_value = md5($this->passwd);
400  }
401  else
402  {
403  $pw_value = $this->passwd;
404  }
405  break;
406 
407  case IL_PASSWD_MD5:
408  $pw_field = "passwd";
409  $pw_value = $this->passwd;
410  break;
411 
412  case IL_PASSWD_CRYPT:
413  $pw_field = "i2passwd";
414  $pw_value = $this->passwd;
415  break;
416 
417  default :
418  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
419  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
420  "<br />Line: ".__LINE__, $ilErr->FATAL);
421  }
422 
423  if( !$this->active )
424  {
425  $this->setInactivationDate( ilUtil::now() );
426  }
427  else
428  {
429  $this->setInactivationDate(null);
430  }
431 
432  $insert_array = array(
433  "usr_id" => array("integer", $this->id),
434  "login" => array("text", $this->login),
435  $pw_field => array("text", $pw_value),
436  "firstname" => array("text", $this->firstname),
437  "lastname" => array("text", $this->lastname),
438  "title" => array("text", $this->utitle),
439  "gender" => array("text", $this->gender),
440  "email" => array("text", trim($this->email)),
441  "hobby" => array("text", (string) $this->hobby),
442  "institution" => array("text", $this->institution),
443  "department" => array("text", $this->department),
444  "street" => array("text", $this->street),
445  "city" => array("text", $this->city),
446  "zipcode" => array("text", $this->zipcode),
447  "country" => array("text", $this->country),
448  "sel_country" => array("text", $this->sel_country),
449  "phone_office" => array("text", $this->phone_office),
450  "phone_home" => array("text", $this->phone_home),
451  "phone_mobile" => array("text", $this->phone_mobile),
452  "fax" => array("text", $this->fax),
453  "birthday" => array('date', $this->getBirthday()),
454  "last_login" => array("timestamp", null),
455  "last_update" => array("timestamp", ilUtil::now()),
456  "create_date" => array("timestamp", ilUtil::now()),
457  "referral_comment" => array("text", $this->referral_comment),
458  "matriculation" => array("text", $this->matriculation),
459  "client_ip" => array("text", $this->client_ip),
460  "approve_date" => array("timestamp", $this->approve_date),
461  "agree_date" => array("timestamp", $this->agree_date),
462  "active" => array("integer", (int) $this->active),
463  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
464  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
465  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
466  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
467  "auth_mode" => array("text", $this->getAuthMode()),
468  "ext_account" => array("text", $this->getExternalAccount()),
469  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
470  "im_icq" => array("text", $this->im_icq),
471  "im_yahoo" => array("text", $this->im_yahoo),
472  "im_msn" => array("text", $this->im_msn),
473  "im_aim" => array("text", $this->im_aim),
474  "im_skype" => array("text", $this->im_skype),
475  "delicious" => array("text", $this->delicious),
476  "latitude" => array("text", $this->latitude),
477  "longitude" => array("text", $this->longitude),
478  "loc_zoom" => array("integer", (int) $this->loc_zoom),
479  "last_password_change" => array("integer", (int) $this->last_password_change_ts),
480  "im_jabber" => array("text", $this->im_jabber),
481  "im_voip" => array("text", $this->im_voip),
482  'inactivation_date' => array('timestamp', $this->inactivation_date),
483  'is_self_registered' => array('integer', (int)$this->is_self_registered)
484  );
485  $ilDB->insert("usr_data", $insert_array);
486 
487  // add new entry in usr_defined_data
488  $this->addUserDefinedFieldEntry();
489  // ... and update
490  $this->updateUserDefinedFields();
491 
492  // CREATE ENTRIES FOR MAIL BOX
493  include_once ("Services/Mail/classes/class.ilMailbox.php");
494  $mbox = new ilMailbox($this->id);
495  $mbox->createDefaultFolder();
496 
497  include_once "Services/Mail/classes/class.ilMailOptions.php";
498  $mail_options = new ilMailOptions($this->id);
499  $mail_options->createMailOptionsEntry();
500 
501  // create personal bookmark folder tree
502  include_once "./Services/Bookmarks/classes/class.ilBookmarkFolder.php";
503  $bmf = new ilBookmarkFolder(0, $this->id);
504  $bmf->createNewBookmarkTree();
505  }
506 
511  function update()
512  {
513  global $ilErr, $ilDB, $ilAppEventHandler;
514 
515  $this->syncActive();
516 
517  if( $this->getStoredActive($this->id) && !$this->active )
518  {
519  $this->setInactivationDate( ilUtil::now() );
520  }
521  else if($this->active)
522  {
523  $this->setInactivationDate(null);
524  }
525 
526  $update_array = array(
527  "gender" => array("text", $this->gender),
528  "title" => array("text", $this->utitle),
529  "firstname" => array("text", $this->firstname),
530  "lastname" => array("text", $this->lastname),
531  "email" => array("text", trim($this->email)),
532  "birthday" => array('date', $this->getBirthday()),
533  "hobby" => array("text", $this->hobby),
534  "institution" => array("text", $this->institution),
535  "department" => array("text", $this->department),
536  "street" => array("text", $this->street),
537  "city" => array("text", $this->city),
538  "zipcode" => array("text", $this->zipcode),
539  "country" => array("text", $this->country),
540  "sel_country" => array("text", $this->sel_country),
541  "phone_office" => array("text", $this->phone_office),
542  "phone_home" => array("text", $this->phone_home),
543  "phone_mobile" => array("text", $this->phone_mobile),
544  "fax" => array("text", $this->fax),
545  "referral_comment" => array("text", $this->referral_comment),
546  "matriculation" => array("text", $this->matriculation),
547  "client_ip" => array("text", $this->client_ip),
548  "approve_date" => array("timestamp", $this->approve_date),
549  "active" => array("integer", $this->active),
550  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
551  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
552  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
553  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
554  "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
555  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
556  "auth_mode" => array("text", $this->getAuthMode()),
557  "ext_account" => array("text", $this->getExternalAccount()),
558  "im_icq" => array("text", $this->im_icq),
559  "im_yahoo" => array("text", $this->im_yahoo),
560  "im_msn" => array("text", $this->im_msn),
561  "im_aim" => array("text", $this->im_aim),
562  "im_skype" => array("text", $this->im_skype),
563  "delicious" => array("text", $this->delicious),
564  "latitude" => array("text", $this->latitude),
565  "longitude" => array("text", $this->longitude),
566  "loc_zoom" => array("integer", (int) $this->loc_zoom),
567  "last_password_change" => array("integer", $this->last_password_change_ts),
568  "im_jabber" => array("text", $this->im_jabber),
569  "im_voip" => array("text", $this->im_voip),
570  "last_update" => array("timestamp", ilUtil::now()),
571  'inactivation_date' => array('timestamp', $this->inactivation_date)
572  );
573 
574  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null))
575  {
576  $update_array["agree_date"] = array("timestamp", $this->agree_date);
577  }
578  switch ($this->passwd_type)
579  {
580  case IL_PASSWD_PLAIN:
581  if(strlen($this->passwd))
582  {
583  $update_array["i2passwd"] = array("text", (string) "");
584  $update_array["passwd"] = array("text", (string) md5($this->passwd));
585  }
586  else
587  {
588  $update_array["i2passwd"] = array("text", (string) "");
589  $update_array["passwd"] = array("text", (string) $this->passwd);
590  }
591  break;
592 
593  case IL_PASSWD_MD5:
594  $update_array["i2passwd"] = array("text", (string) "");
595  $update_array["passwd"] = array("text", (string) $this->passwd);
596  break;
597 
598  case IL_PASSWD_CRYPT:
599  $update_array["i2passwd"] = array("text", (string) $this->passwd);
600  $update_array["passwd"] = array("text", (string) "");
601  break;
602 
603  default :
604  $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
605  get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
606  }
607 
608  $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
609 
610  $this->writePrefs();
611 
612  // update user defined fields
613  $this->updateUserDefinedFields();
614 
615  parent::update();
616  parent::updateOwner();
617 
618  $this->read();
619 
620  $ilAppEventHandler->raise("Services/User", "afterUpdate",
621  array("user_obj" => $this));
622 
623  return true;
624  }
625 
629  function writeAccepted()
630  {
631  global $ilDB;
632 
633  $ilDB->manipulateF("UPDATE usr_data SET agree_date = ".$ilDB->now().
634  " WHERE usr_id = %s", array("integer"), array($this->getId()));
635  }
636 
640  private function _lookup($a_user_id, $a_field)
641  {
642  global $ilDB;
643 
644  $res = $ilDB->queryF("SELECT ".$a_field." FROM usr_data WHERE usr_id = %s",
645  array("integer"), array($a_user_id));
646 
647  while($set = $ilDB->fetchAssoc($res))
648  {
649  return $set[$a_field];
650  }
651  return false;
652  }
653 
657  function _lookupFullname($a_user_id)
658  {
659  global $ilDB;
660 
661  $set = $ilDB->queryF("SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
662  array("integer"), array($a_user_id));
663 
664  if ($rec = $ilDB->fetchAssoc($set))
665  {
666  if ($rec["title"])
667  {
668  $fullname = $rec["title"]." ";
669  }
670  if ($rec["firstname"])
671  {
672  $fullname .= $rec["firstname"]." ";
673  }
674  if ($rec["lastname"])
675  {
676  $fullname .= $rec["lastname"];
677  }
678  }
679  return $fullname;
680  }
681 
685  function _lookupIm($a_user_id, $a_type)
686  {
687  return ilObjUser::_lookup($a_user_id, "im_".$a_type);
688  }
689 
690 
694  function _lookupEmail($a_user_id)
695  {
696  return ilObjUser::_lookup($a_user_id, "email");
697  }
698 
702  public static function _lookupGender($a_user_id)
703  {
704  return ilObjUser::_lookup($a_user_id, "gender");
705  }
706 
713  function _lookupClientIP($a_user_id)
714  {
715  return ilObjUser::_lookup($a_user_id, "client_ip");
716  }
717 
718 
724  public static function _lookupName($a_user_id)
725  {
726  global $ilDB;
727 
728  $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
729  array("integer"), array($a_user_id));
730  $user_rec = $ilDB->fetchAssoc($res);
731  return array("user_id" => $a_user_id,
732  "firstname" => $user_rec["firstname"],
733  "lastname" => $user_rec["lastname"],
734  "title" => $user_rec["title"],
735  "login" => $user_rec["login"]);
736  }
737 
741  function _lookupFields($a_user_id)
742  {
743  global $ilDB;
744 
745  $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
746  array("integer"), array($a_user_id));
747  $user_rec = $ilDB->fetchAssoc($res);
748  return $user_rec;
749  }
750 
754  function _lookupLogin($a_user_id)
755  {
756  return ilObjUser::_lookup($a_user_id, "login");
757  }
758 
762  function _lookupExternalAccount($a_user_id)
763  {
764  return ilObjUser::_lookup($a_user_id, "ext_account");
765  }
766 
770  public static function _lookupId($a_user_str)
771  {
772  global $ilDB;
773 
774  $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
775  array("text"), array($a_user_str));
776  $user_rec = $ilDB->fetchAssoc($res);
777  return $user_rec["usr_id"];
778  }
779 
783  function _lookupLastLogin($a_user_id)
784  {
785  return ilObjUser::_lookup($a_user_id, "last_login");
786  }
787 
788 
794  function refreshLogin()
795  {
796  global $ilDB;
797 
798  $ilDB->manipulateF("UPDATE usr_data SET ".
799  "last_login = ".$ilDB->now().
800  " WHERE usr_id = %s",
801  array("integer"), array($this->id));
802  }
803 
810  function replacePassword($new_md5)
811  {
812  global $ilDB;
813 
814  $this->passwd_type = IL_PASSWD_MD5;
815  $this->passwd = $new_md5;
816 
817  $ilDB->manipulateF("UPDATE usr_data SET ".
818  "passwd = %s ".
819  "WHERE usr_id = %s",
820  array("text", "integer"), array($this->passwd, $this->id));
821 
822  return true;
823  }
824 
833  function updatePassword($a_old, $a_new1, $a_new2)
834  {
835  global $ilDB;
836 
837  if (func_num_args() != 3)
838  {
839  return false;
840  }
841 
842  if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
843  {
844  return false;
845  }
846 
847  if ($a_new1 != $a_new2)
848  {
849  return false;
850  }
851 
852  // is catched by isset() ???
853  if ($a_new1 == "" || $a_old == "")
854  {
855  return false;
856  }
857 
858  //check old password
859  switch ($this->passwd_type)
860  {
861  case IL_PASSWD_PLAIN:
862  if ($a_old != $this->passwd)
863  {
864  return false;
865  }
866  break;
867 
868  case IL_PASSWD_MD5:
869  if (md5($a_old) != $this->passwd)
870  {
871  return false;
872  }
873  break;
874 
875  case IL_PASSWD_CRYPT:
876  if (self::_makeIlias2Password($a_old) != $this->passwd)
877  {
878  return false;
879  }
880  break;
881  }
882 
883  //update password
884  $this->passwd = md5($a_new1);
885  $this->passwd_type = IL_PASSWD_MD5;
886 
887  $ilDB->manipulateF("UPDATE usr_data SET ".
888  "passwd = %s ".
889  "WHERE usr_id = %s",
890  array("text", "integer"), array($this->passwd, $this->id));
891 
892  return true;
893  }
894 
902  function resetPassword($a_new1, $a_new2)
903  {
904  global $ilDB;
905 
906  if (func_num_args() != 2)
907  {
908  return false;
909  }
910 
911  if (!isset($a_new1) or !isset($a_new2))
912  {
913  return false;
914  }
915 
916  if ($a_new1 != $a_new2)
917  {
918  return false;
919  }
920 
921  //update password
922  $this->passwd = md5($a_new1);
923  $this->passwd_type = IL_PASSWD_MD5;
924 
925  $ilDB->manipulateF("UPDATE usr_data SET ".
926  "passwd = %s ".
927  "WHERE usr_id = %s",
928  array("text", "integer"),
929  array($this->passwd, $this->id));
930 
931  return true;
932  }
933 
938  public static function _makeIlias2Password($a_passwd)
939  {
940  return (crypt($a_passwd,substr($a_passwd,0,2)));
941  }
942 
953  public static function _doesLoginnameExistInHistory($a_login)
954  {
955  global $ilDB;
956 
957  $res = $ilDB->queryF('
958  SELECT * FROM loginname_history
959  WHERE login = %s',
960  array('text'), array($a_login));
961 
962  return $ilDB->fetchAssoc($res) ? true : false;
963  }
964 
977  public static function _getLastHistoryDataByUserId($a_usr_id)
978  {
979  global $ilDB;
980 
981  $ilDB->setLimit(1, 0);
982  $res = $ilDB->queryF('
983  SELECT login, history_date FROM loginname_history
984  WHERE usr_id = %s ORDER BY history_date DESC',
985  array('integer'), array($a_usr_id));
986  $row = $ilDB->fetchAssoc($res);
987  if(!is_array($row) || !count($row)) throw new ilUserException('');
988 
989  return array(
990  $row['login'], $row['history_date']
991  );
992  }
993 
1001  function updateLogin($a_login)
1002  {
1003  global $ilDB, $ilSetting;
1004 
1005  if(func_num_args() != 1)
1006  {
1007  return false;
1008  }
1009 
1010  if(!isset($a_login))
1011  {
1012  return false;
1013  }
1014 
1015  $former_login = self::_lookupLogin($this->getId());
1016 
1017  // Update not necessary
1018  if(0 == strcmp($a_login, $former_login))
1019  {
1020  return false;
1021  }
1022 
1023  try
1024  {
1025  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1026  }
1027  catch(ilUserException $e) { $last_history_entry = null; }
1028 
1029  // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1030  if((int)$ilSetting->get('allow_change_loginname') &&
1031  (int)$ilSetting->get('reuse_of_loginnames') == 0 &&
1032  self::_doesLoginnameExistInHistory($a_login))
1033  {
1034  throw new ilUserException($this->lng->txt('loginname_already_exists'));
1035  }
1036  else if((int)$ilSetting->get('allow_change_loginname') &&
1037  (int)$ilSetting->get('loginname_change_blocking_time') &&
1038  is_array($last_history_entry) &&
1039  $last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time') > time())
1040  {
1041  include_once 'Services/Calendar/classes/class.ilDate.php';
1042  throw new ilUserException(
1043  sprintf(
1044  $this->lng->txt('changing_loginname_not_possible_info'),
1046  new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1048  new ilDateTime(($last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX))
1049  )
1050  );
1051  }
1052  else
1053  {
1054  // log old loginname in history
1055  if((int)$ilSetting->get('allow_change_loginname') &&
1056  (int)$ilSetting->get('create_history_loginname'))
1057  {
1058  ilObjUser::_writeHistory($this->getId(), $former_login);
1059  }
1060 
1061  //update login
1062  $this->login = $a_login;
1063 
1064  $ilDB->manipulateF('
1065  UPDATE usr_data
1066  SET login = %s
1067  WHERE usr_id = %s',
1068  array('text', 'integer'), array($this->getLogin(), $this->getId()));
1069 
1070  include_once 'Services/Contact/classes/class.ilAddressbook.php';
1071  ilAddressbook::onLoginNameChange($former_login, $this->getLogin());
1072  }
1073 
1074  return true;
1075  }
1076 
1083  function writePref($a_keyword, $a_value)
1084  {
1085  self::_writePref($this->id, $a_keyword, $a_value);
1086  $this->setPref($a_keyword, $a_value);
1087  }
1088 
1089 
1095  function deletePref($a_keyword)
1096  {
1097  self::_deletePref($this->getId(), $a_keyword);
1098  }
1099 
1105  public static function _deletePref($a_user_id, $a_keyword)
1106  {
1110  global $ilDB;
1111 
1112  $ilDB->manipulateF(
1113  'DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s',
1114  array('integer', 'text'),
1115  array($a_user_id, $a_keyword)
1116  );
1117  }
1118 
1124  function _deleteAllPref($a_user_id)
1125  {
1126  global $ilDB;
1127 
1128  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1129  array("integer"), array($a_user_id));
1130  }
1131 
1138  public static function _writePref($a_usr_id, $a_keyword, $a_value)
1139  {
1143  global $ilDB;
1144 
1145  self::_deletePref($a_usr_id, $a_keyword);
1146  if(strlen($a_value))
1147  {
1148  $ilDB->manipulateF(
1149  'INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s, %s, %s)',
1150  array('integer', 'text', 'text'),
1151  array($a_usr_id, $a_keyword, $a_value)
1152  );
1153  }
1154  }
1155 
1160  function writePrefs()
1161  {
1162  global $ilDB;
1163 
1164  ilObjUser::_deleteAllPref($this->id);
1165  foreach ($this->prefs as $keyword => $value)
1166  {
1167  self::_writePref($this->id, $keyword, $value);
1168  }
1169  }
1170 
1177  public function getTimeZone()
1178  {
1179  if($tz = $this->getPref('user_tz'))
1180  {
1181  return $tz;
1182  }
1183  else
1184  {
1185  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1186  $settings = ilCalendarSettings::_getInstance();
1187  return $settings->getDefaultTimeZone();
1188  }
1189  }
1190 
1197  public function getTimeFormat()
1198  {
1199  if($format = $this->getPref('time_format'))
1200  {
1201  return $format;
1202  }
1203  else
1204  {
1205  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1206  $settings = ilCalendarSettings::_getInstance();
1207  return $settings->getDefaultTimeFormat();
1208  }
1209  }
1210 
1217  public function getDateFormat()
1218  {
1219  if($format = $this->getPref('date_format'))
1220  {
1221  return $format;
1222  }
1223  else
1224  {
1225  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1226  $settings = ilCalendarSettings::_getInstance();
1227  return $settings->getDefaultDateFormat();
1228  }
1229  }
1230 
1237  function setPref($a_keyword, $a_value)
1238  {
1239  if ($a_keyword != "")
1240  {
1241  $this->prefs[$a_keyword] = $a_value;
1242  }
1243  }
1244 
1250  function getPref($a_keyword)
1251  {
1252  if (array_key_exists($a_keyword, $this->prefs))
1253  {
1254  return $this->prefs[$a_keyword];
1255  }
1256  else
1257  {
1258  return FALSE;
1259  }
1260  }
1261 
1262  function _lookupPref($a_usr_id,$a_keyword)
1263  {
1264  global $ilDB;
1265 
1266  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1267  "AND keyword = ".$ilDB->quote($a_keyword, "text");
1268  $res = $ilDB->query($query);
1269 
1270  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1271  {
1272  return $row->value;
1273  }
1274  return false;
1275  }
1276 
1281  function readPrefs()
1282  {
1283  global $ilDB;
1284 
1285  if (is_array($this->prefs))
1286  {
1287  $this->oldPrefs = $this->prefs;
1288  }
1289 
1290  $this->prefs = ilObjUser::_getPreferences($this->id);
1291  }
1292 
1298  function delete()
1299  {
1300  global $rbacadmin, $ilDB;
1301 
1302  // deassign from ldap groups
1303  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1305  $mapping->deleteUser($this->getId());
1306 
1307  // remove mailbox / update sent mails
1308  include_once ("Services/Mail/classes/class.ilMailbox.php");
1309  $mailbox = new ilMailbox($this->getId());
1310  $mailbox->delete();
1311  $mailbox->updateMailsOfDeletedUser($this->getLogin());
1312 
1313  // delete feed blocks on personal desktop
1314  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1315  $costum_block = new ilCustomBlock();
1316  $costum_block->setContextObjId($this->getId());
1317  $costum_block->setContextObjType("user");
1318  $c_blocks = $costum_block->queryBlocksForContext();
1319  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1320  foreach($c_blocks as $c_block)
1321  {
1322  if ($c_block["type"] == "pdfeed")
1323  {
1324  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1325  $fb->delete();
1326  }
1327  }
1328 
1329 
1330  // delete block settings
1331  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1333 
1334  // delete user_account
1335  $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1336  array("integer"), array($this->getId()));
1337 
1338  // delete user_prefs
1339  ilObjUser::_deleteAllPref($this->getId());
1340 
1341  $this->removeUserPicture(false); // #8597
1342 
1343  // delete user_session
1344  include_once("./Services/Authentication/classes/class.ilSession.php");
1346 
1347  // remove user from rbac
1348  $rbacadmin->removeUser($this->getId());
1349 
1350  // remove bookmarks
1351  // TODO: move this to class.ilBookmarkFolder
1352  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1353  $ilDB->quote($this->getId(), "integer");
1354  $ilDB->manipulate($q);
1355 
1356  $q = "DELETE FROM bookmark_data WHERE user_id = ".
1357  $ilDB->quote($this->getId(), "integer");
1358  $ilDB->manipulate($q);
1359 
1360  // DELETE FORUM ENTRIES (not complete in the moment)
1361  include_once './Modules/Forum/classes/class.ilObjForum.php';
1362  ilObjForum::_deleteUser($this->getId());
1363 
1364  // Delete link check notify entries
1365  include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
1367 
1368  // Delete crs entries
1369  include_once './Modules/Course/classes/class.ilObjCourse.php';
1370  ilObjCourse::_deleteUser($this->getId());
1371 
1372  // Delete user tracking
1373  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1375 
1376  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1378 
1379  // Delete Tracking data SCORM 2004 RTE
1380  include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1382 
1383  // Delete Tracking data SCORM 1.2 RTE
1384  include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1386 
1387  // remove all notifications
1388  include_once "./Services/Notification/classes/class.ilNotification.php";
1390 
1391  // remove portfolios
1392  include_once "./Modules/Portfolio/classes/class.ilObjPortfolio.php";
1394 
1395  // remove workspace
1396  include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1397  $tree = new ilWorkspaceTree($this->getId());
1398  $tree->cascadingDelete();
1399 
1400  // remove disk quota entries
1401  include_once "./Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1403 
1404  // Delete user defined field entries
1406 
1407  // Delete clipboard entries
1408  $this->clipboardDeleteAll();
1409 
1410  // Reset owner
1411  $this->resetOwner();
1412 
1413  include_once 'Services/Contact/classes/class.ilAddressbook.php';
1414  ilAddressbook::onUserDeletion($this);
1415 
1416  // Trigger deleteUser Event
1417  global $ilAppEventHandler;
1418  $ilAppEventHandler->raise(
1419  'Services/User', 'deleteUser', array('usr_id' => $this->getId())
1420  );
1421 
1422  // delete object data
1423  parent::delete();
1424  return true;
1425  }
1426 
1436  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1437  {
1438  $this->fullname = "";
1439 
1440  if ($a_title)
1441  {
1442  $fullname = $a_title." ";
1443  }
1444  elseif ($this->utitle)
1445  {
1446  $this->fullname = $this->utitle." ";
1447  }
1448 
1449  if ($a_firstname)
1450  {
1451  $fullname .= $a_firstname." ";
1452  }
1453  elseif ($this->firstname)
1454  {
1455  $this->fullname .= $this->firstname." ";
1456  }
1457 
1458  if ($a_lastname)
1459  {
1460  return $fullname.$a_lastname;
1461  }
1462 
1463  $this->fullname .= $this->lastname;
1464  }
1465 
1480  function getFullname($a_max_strlen = 0)
1481  {
1482  if (!$a_max_strlen)
1483  {
1484  return ilUtil::stripSlashes($this->fullname);
1485  }
1486 
1487  if (strlen($this->fullname) <= $a_max_strlen)
1488  {
1489  return ilUtil::stripSlashes($this->fullname);
1490  }
1491 
1492  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1493  {
1494  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1495  }
1496 
1497  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1498  {
1499  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1500  }
1501 
1502  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1503  {
1504  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1505  }
1506 
1507  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1508  }
1509 
1513  function hasAcceptedUserAgreement()
1514  {
1518  global $rbacreview;
1519 
1520  if(
1521  null != $this->agree_date ||
1522  'root' == $this->login ||
1523  in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID)) ||
1524  $rbacreview->isAssigned($this->getId(), SYSTEM_ROLE_ID)
1525  )
1526  {
1527  return true;
1528  }
1529  return false;
1530  }
1531 
1537  function setLogin($a_str)
1538  {
1539  $this->login = $a_str;
1540  }
1541 
1546  function getLogin()
1547  {
1548  return $this->login;
1549  }
1550 
1556  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1557  {
1558  $this->passwd = $a_str;
1559  $this->passwd_type = $a_type;
1560  }
1561 
1569  function getPasswd()
1570  {
1571  return $this->passwd;
1572  }
1579  function getPasswdType()
1580  {
1581  return $this->passwd_type;
1582  }
1583 
1589  function setGender($a_str)
1590  {
1591  $this->gender = substr($a_str,-1);
1592  }
1593 
1598  function getGender()
1599  {
1600  return $this->gender;
1601  }
1602 
1610  function setUTitle($a_str)
1611  {
1612  $this->utitle = $a_str;
1613  }
1614 
1621  function getUTitle()
1622  {
1623  return $this->utitle;
1624  }
1625 
1631  function setFirstname($a_str)
1632  {
1633  $this->firstname = $a_str;
1634  }
1635 
1640  function getFirstname()
1641  {
1642  return $this->firstname;
1643  }
1644 
1650  function setLastname($a_str)
1651  {
1652  $this->lastname = $a_str;
1653  }
1654 
1659  function getLastname()
1660  {
1661  return $this->lastname;
1662  }
1663 
1669  function setInstitution($a_str)
1670  {
1671  $this->institution = $a_str;
1672  }
1673 
1678  function getInstitution()
1679  {
1680  return $this->institution;
1681  }
1682 
1688  function setDepartment($a_str)
1689  {
1690  $this->department = $a_str;
1691  }
1692 
1697  function getDepartment()
1698  {
1699  return $this->department;
1700  }
1701 
1707  function setStreet($a_str)
1708  {
1709  $this->street = $a_str;
1710  }
1711 
1716  function getStreet()
1717  {
1718  return $this->street;
1719  }
1720 
1726  function setCity($a_str)
1727  {
1728  $this->city = $a_str;
1729  }
1730 
1735  function getCity()
1736  {
1737  return $this->city;
1738  }
1739 
1745  function setZipcode($a_str)
1746  {
1747  $this->zipcode = $a_str;
1748  }
1749 
1754  function getZipcode()
1755  {
1756  return $this->zipcode;
1757  }
1758 
1765  function setCountry($a_str)
1766  {
1767  $this->country = $a_str;
1768  }
1769 
1775  function getCountry()
1776  {
1777  return $this->country;
1778  }
1779 
1785  function setSelectedCountry($a_val)
1786  {
1787  $this->sel_country = $a_val;
1788  }
1789 
1796  {
1797  return $this->sel_country;
1798  }
1799 
1805  function setPhoneOffice($a_str)
1806  {
1807  $this->phone_office = $a_str;
1808  }
1809 
1814  function getPhoneOffice()
1815  {
1816  return $this->phone_office;
1817  }
1818 
1824  function setPhoneHome($a_str)
1825  {
1826  $this->phone_home = $a_str;
1827  }
1828 
1833  function getPhoneHome()
1834  {
1835  return $this->phone_home;
1836  }
1837 
1843  function setPhoneMobile($a_str)
1844  {
1845  $this->phone_mobile = $a_str;
1846  }
1847 
1852  function getPhoneMobile()
1853  {
1854  return $this->phone_mobile;
1855  }
1856 
1862  function setFax($a_str)
1863  {
1864  $this->fax = $a_str;
1865  }
1866 
1871  function getFax()
1872  {
1873  return $this->fax;
1874  }
1875 
1881  function setClientIP($a_str)
1882  {
1883  $this->client_ip = $a_str;
1884  }
1885 
1890  function getClientIP()
1891  {
1892  return $this->client_ip;
1893  }
1894 
1900  function setMatriculation($a_str)
1901  {
1902  $this->matriculation = $a_str;
1903  }
1904 
1909  function getMatriculation()
1910  {
1911  return $this->matriculation;
1912  }
1913 
1920  public static function lookupMatriculation($a_usr_id)
1921  {
1922  global $ilDB;
1923 
1924  $query = "SELECT matriculation FROM usr_data ".
1925  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1926  $res = $ilDB->query($query);
1927  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1928  return $row->matriculation ? $row->matriculation : '';
1929  }
1930 
1936  function setEmail($a_str)
1937  {
1938  $this->email = $a_str;
1939  }
1940 
1945  function getEmail()
1946  {
1947  return $this->email;
1948  }
1949 
1955  function setHobby($a_str)
1956  {
1957  $this->hobby = $a_str;
1958  }
1959 
1964  function getHobby()
1965  {
1966  return $this->hobby;
1967  }
1968 
1974  function setLanguage($a_str)
1975  {
1976  $this->setPref("language",$a_str);
1977  unset($_SESSION['lang']);
1978  }
1979 
1985  function getLanguage()
1986  {
1987  return $this->prefs["language"];
1988  }
1989 
1998  function setDiskQuota($a_disk_quota)
1999  {
2000  $this->setPref("disk_quota",$a_disk_quota);
2001  }
2002 
2012  function getDiskQuota()
2013  {
2014  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
2015  }
2016 
2018  {
2019  return $this->prefs["wsp_disk_quota"] ? $this->prefs["wsp_disk_quota"] : 0;
2020  }
2021 
2022  public function setLastPasswordChangeTS($a_last_password_change_ts)
2023  {
2024  $this->last_password_change_ts = $a_last_password_change_ts;
2025  }
2026 
2027  public function getLastPasswordChangeTS()
2028  {
2030  }
2031 
2032 
2033  public static function _lookupLanguage($a_usr_id)
2034  {
2035  global $ilDB;
2036 
2037  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
2038  $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
2039  $ilDB->quote('language', "text");
2040  $r = $ilDB->query($q);
2041 
2042  while($row = $ilDB->fetchAssoc($r))
2043  {
2044  return $row['value'];
2045  }
2046  return 'en';
2047  }
2048 
2049 
2050  function _checkPassword($a_usr_id, $a_pw)
2051  {
2052  global $ilDB;
2053 
2054  $pw = ilObjUser::_lookup($a_usr_id, "passwd");
2055  if ($pw == md5($a_pw))
2056  {
2057  return true;
2058  }
2059  return false;
2060  }
2061 
2062  function _writeExternalAccount($a_usr_id, $a_ext_id)
2063  {
2064  global $ilDB;
2065 
2066  $ilDB->manipulateF("UPDATE usr_data ".
2067  " SET ext_account = %s WHERE usr_id = %s",
2068  array("text", "integer"),
2069  array($a_ext_id, $a_usr_id));
2070  }
2071 
2072  function _writeAuthMode($a_usr_id, $a_auth_mode)
2073  {
2074  global $ilDB;
2075 
2076  $ilDB->manipulateF("UPDATE usr_data ".
2077  " SET auth_mode = %s WHERE usr_id = %s",
2078  array("text", "integer"),
2079  array($a_auth_mode, $a_usr_id));
2080  }
2081 
2087  {
2088  return $_SESSION['lang'];
2089  }
2090 
2096  function setCurrentLanguage($a_val)
2097  {
2098  $_SESSION['lang'] = $a_val;
2099  }
2100 
2106  function setLastLogin($a_str)
2107  {
2108  $this->last_login = $a_str;
2109  }
2110 
2116  function getLastLogin()
2117  {
2118  return $this->last_login;
2119  }
2120 
2126  function setLastUpdate($a_str)
2127  {
2128  $this->last_update = $a_str;
2129  }
2130  function getLastUpdate()
2131  {
2132  return $this->last_update;
2133  }
2134 
2140  function setComment($a_str)
2141  {
2142  $this->referral_comment = $a_str;
2143  }
2144 
2149  function getComment()
2150  {
2151  return $this->referral_comment;
2152  }
2153 
2160  function setApproveDate($a_str)
2161  {
2162  $this->approve_date = $a_str;
2163  }
2164 
2170  function getApproveDate()
2171  {
2172  return $this->approve_date;
2173  }
2174 
2175  // BEGIN DiskQuota: show when user accepted user agreement
2181  function getAgreeDate()
2182  {
2183  return $this->agree_date;
2184  }
2191  function setAgreeDate($a_str)
2192  {
2193  $this->agree_date = $a_str;
2194  }
2195  // END DiskQuota: show when user accepted user agreement
2196 
2203  function setActive($a_active, $a_owner = 0)
2204  {
2205  $this->setOwner($a_owner);
2206 
2207  if ($a_active)
2208  {
2209  $this->active = 1;
2210  $this->setApproveDate(date('Y-m-d H:i:s'));
2211  $this->setOwner($a_owner);
2212  }
2213  else
2214  {
2215  $this->active = 0;
2216  $this->setApproveDate(null);
2217  }
2218  }
2219 
2224  function getActive()
2225  {
2226  return $this->active;
2227  }
2228 
2232  public function _lookupActive($a_usr_id)
2233  {
2234  global $ilDB;
2235 
2236  $query = 'SELECT usr_id FROM usr_data '.
2237  'WHERE active = '.$ilDB->quote(1,'integer').' '.
2238  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
2239  $res = $ilDB->query($query);
2240  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2241  {
2242  return true;
2243  }
2244  return false;
2245  }
2246 
2252  function syncActive()
2253  {
2254  global $ilAuth;
2255 
2256  $storedActive = 0;
2257  if ($this->getStoredActive($this->id))
2258  {
2259  $storedActive = 1;
2260  }
2261 
2262  $currentActive = 0;
2263  if ($this->active)
2264  {
2265  $currentActive = 1;
2266  }
2267 
2268  if ((!empty($storedActive) && empty($currentActive)) ||
2269  (empty($storedActive) && !empty($currentActive)))
2270  {
2271  $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2272  }
2273  }
2274 
2281  function getStoredActive($a_id)
2282  {
2283  $active = ilObjUser::_lookup($a_id, "active");
2284  return $active ? true : false;
2285  }
2286 
2292  function setSkin($a_str)
2293  {
2294  // TODO: exception handling (dir exists)
2295  $this->skin = $a_str;
2296  }
2297 
2298  function setTimeLimitOwner($a_owner)
2299  {
2300  $this->time_limit_owner = $a_owner;
2301  }
2303  {
2304  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2305  }
2306  function setTimeLimitFrom($a_from)
2307  {
2308  $this->time_limit_from = $a_from;
2309  }
2310  function getTimeLimitFrom()
2311  {
2312  return $this->time_limit_from ? $this->time_limit_from : time();
2313  }
2314  function setTimeLimitUntil($a_until)
2315  {
2316  $this->time_limit_until = $a_until;
2317  }
2319  {
2320  return $this->time_limit_until ? $this->time_limit_until : time();
2321  }
2322  function setTimeLimitUnlimited($a_unlimited)
2323  {
2324  $this->time_limit_unlimited = $a_unlimited;
2325  }
2327  {
2328  return $this->time_limit_unlimited;
2329  }
2330  function setTimeLimitMessage($a_time_limit_message)
2331  {
2332  return $this->time_limit_message = $a_time_limit_message;
2333  }
2335  {
2336  return $this->time_limit_message;
2337  }
2338 
2339  public function setLoginAttempts($a_login_attempts)
2340  {
2341  $this->login_attempts = $a_login_attempts;
2342  }
2343 
2344  public function getLoginAttempts()
2345  {
2346  return $this->login_attempts;
2347  }
2348 
2349 
2350  function checkTimeLimit()
2351  {
2352  if($this->getTimeLimitUnlimited())
2353  {
2354  return true;
2355  }
2356  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2357  {
2358  return true;
2359  }
2360  return false;
2361  }
2362  function setProfileIncomplete($a_prof_inc)
2363  {
2364  $this->profile_incomplete = (boolean) $a_prof_inc;
2365  }
2367  {
2368  if($this->id == ANONYMOUS_USER_ID)
2369  {
2370  return false;
2371  }
2372  return $this->profile_incomplete;
2373  }
2374 
2375  public function isPasswordChangeDemanded()
2376  {
2377  //error_reporting(E_ALL);
2378  if( $this->id == ANONYMOUS_USER_ID || $this->id == SYSTEM_USER_ID )
2379  return false;
2380 
2381  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2382  $security = ilSecuritySettings::_getInstance();
2383 
2385  && $security->isPasswordChangeOnFirstLoginEnabled()
2386  && $this->getLastPasswordChangeTS() == 0
2387  && $this->is_self_registered == false
2388  ){
2389  return true;
2390  }
2391  else return false;
2392  }
2393 
2394  public function isPasswordExpired()
2395  {
2396  //error_reporting(E_ALL);
2397  if($this->id == ANONYMOUS_USER_ID) return false;
2398 
2399  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2400  $security = ilSecuritySettings::_getInstance();
2401  if( $this->getLastPasswordChangeTS() > 0 )
2402  {
2403  $max_pass_age = $security->getPasswordMaxAge();
2404  if( $max_pass_age > 0 )
2405  {
2406  $max_pass_age_ts = ( $max_pass_age * 86400 );
2407  $pass_change_ts = $this->getLastPasswordChangeTS();
2408  $current_ts = time();
2409 
2410  if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2411  return true;
2412  }
2413  }
2414  return false;
2415  }
2416 
2417  public function getPasswordAge()
2418  {
2419  $current_ts = time();
2420  $pass_change_ts = $this->getLastPasswordChangeTS();
2421  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2422  return $password_age;
2423  }
2424 
2425  public function setLastPasswordChangeToNow()
2426  {
2427  global $ilDB;
2428 
2429  $this->setLastPasswordChangeTS( time() );
2430 
2431  $query = "UPDATE usr_data SET last_password_change = %s " .
2432  "WHERE usr_id = %s";
2433  $affected = $ilDB->manipulateF($query,
2434  array('integer','integer'),
2435  array($this->getLastPasswordChangeTS(),$this->id));
2436  if($affected) return true;
2437  else return false;
2438  }
2439 
2440  public function resetLastPasswordChange()
2441  {
2442  global $ilDB;
2443 
2444  $query = "UPDATE usr_data SET last_password_change = 0 " .
2445  "WHERE usr_id = %s";
2446  $affected = $ilDB->manipulateF( $query, array('integer'),
2447  array($this->getId()) );
2448  if($affected) return true;
2449  else return false;
2450  }
2451 
2457  function setLatitude($a_latitude)
2458  {
2459  $this->latitude = $a_latitude;
2460  }
2461 
2467  function getLatitude()
2468  {
2469  return $this->latitude;
2470  }
2471 
2477  function setLongitude($a_longitude)
2478  {
2479  $this->longitude = $a_longitude;
2480  }
2481 
2487  function getLongitude()
2488  {
2489  return $this->longitude;
2490  }
2491 
2497  function setLocationZoom($a_locationzoom)
2498  {
2499  $this->loc_zoom = $a_locationzoom;
2500  }
2501 
2507  function getLocationZoom()
2508  {
2509  return $this->loc_zoom;
2510  }
2511 
2512  function &getAppliedUsers()
2513  {
2514  $this->applied_users = array();
2515  $this->__readAppliedUsers($this->getId());
2516 
2517  return $this->applied_users ? $this->applied_users : array();
2518  }
2519 
2520  function isChild($a_usr_id)
2521  {
2522  if($a_usr_id == $this->getId())
2523  {
2524  return true;
2525  }
2526 
2527  $this->applied_users = array();
2528  $this->__readAppliedUsers($this->getId());
2529 
2530  return in_array($a_usr_id,$this->applied_users);
2531  }
2532 
2533  function __readAppliedUsers($a_parent_id)
2534  {
2535  global $ilDB;
2536 
2537  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2538  "WHERE time_limit_owner = %s",
2539  array("integer"),
2540  array($a_parent_id));
2541  while ($row = $ilDB->fetchObject($res))
2542  {
2543  $this->applied_users[] = $row->usr_id;
2544 
2545  // recursion
2546  $this->__readAppliedUsers($row->usr_id);
2547  }
2548  return true;
2549  }
2550 
2556  static function hasActiveSession($a_user_id)
2557  {
2558  global $ilDB;
2559 
2560  $set = $ilDB->queryf('
2561  SELECT COUNT(*) session_count
2562  FROM usr_session WHERE user_id = %s AND expires > %s',
2563  array('integer', 'integer'),
2564  array($a_user_id, time()));
2565  $row = $ilDB->fetchAssoc($set);
2566  return (bool)$row['session_count'];
2567  }
2568 
2569  /*
2570  * check user id with login name
2571  * @access public
2572  */
2573  function checkUserId()
2574  {
2575  global $ilAuth, $ilSetting;
2576 
2577  $login = ilObjUser::getLoginFromAuth();
2578  $id = ilObjUser::_lookupId($login);
2579  if ($id > 0)
2580  {
2581  return $id;
2582  }
2583  return false;
2584  }
2585 
2589  private static function getLoginFromAuth() {
2590  global $ilAuth;
2591 
2592  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2593  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2595  {
2596  require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2597  require_once ('Services/Database/classes/class.ilAuthContainerMDB2.php');
2598  $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2599  }
2600  else
2601  {
2602  $login =$ilAuth->getUsername();
2603  }
2604 
2605  return $login;
2606  }
2607 
2608  /*
2609  * check to see if current user has been made active
2610  * @access public
2611  * @return true if active, otherwise false
2612  */
2614  {
2615  global $ilDB,$ilAuth;
2616 
2617  $login = ilObjUser::getLoginFromAuth();
2618  $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2619  array("text"),
2620  array($login));
2621  //query has got a result
2622  if ($rec = $ilDB->fetchAssoc($set))
2623  {
2624  if ($rec["active"])
2625  {
2626  return true;
2627  }
2628  }
2629 
2630  return false;
2631  }
2632 
2633  /*
2634  * STATIC METHOD
2635  * get the user_id of a login name
2636  * @param string login name
2637  * @return integer id of user
2638  * @static
2639  * @access public
2640  */
2641  function getUserIdByLogin($a_login)
2642  {
2643  return (int) ilObjUser::_lookupId($a_login);
2644  }
2645 
2654  function _getUserIdsByEmail($a_email)
2655  {
2656  global $ilias, $ilDB;
2657 
2658  $res = $ilDB->queryF("SELECT login FROM usr_data ".
2659  "WHERE email = %s and active = 1",
2660  array("text"),
2661  array($a_email));
2662  $ids = array ();
2663  while($row = $ilDB->fetchObject($res))
2664  {
2665  $ids[] = $row->login;
2666  }
2667 
2668  return $ids;
2669  }
2670 
2671 
2672 
2681  function getUserIdByEmail($a_email)
2682  {
2683  global $ilDB;
2684 
2685  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2686  "WHERE email = %s", array("text"), array($a_email));
2687 
2688  $row = $ilDB->fetchObject($res);
2689  return $row->usr_id ? $row->usr_id : 0;
2690  }
2691 
2692  /*
2693  * STATIC METHOD
2694  * get the login name of a user_id
2695  * @param integer id of user
2696  * @return string login name; false if not found
2697  * @static
2698  * @access public
2699  */
2700  function getLoginByUserId($a_userid)
2701  {
2702  $login = ilObjUser::_lookupLogin($a_userid);
2703  return $login ? $login : false;
2704  }
2705 
2716  static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2717  {
2718  global $ilias, $ilDB, $ilLog;
2719 
2720 
2721  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2722 
2723  $without_anonymous_users = true;
2724 
2725  // determine join filter
2726  $join_filter = " WHERE ";
2727  if ($filter_settings !== FALSE && strlen($filter_settings))
2728  {
2729  switch ($filter_settings)
2730  {
2731  case 3:
2732  // show only users without courses
2733  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.usr_id IS NULL AND ";
2734  break;
2735  case 5:
2736  // show only users with a certain course membership
2737  $ref_id = $_SESSION["user_filter_data"];
2738  if ($ref_id)
2739  {
2740  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.obj_id = ".
2741  "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2742  }
2743  break;
2744  case 6:
2745  global $rbacreview;
2746  $ref_id = $_SESSION["user_filter_data"];
2747  if ($ref_id)
2748  {
2749  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2750  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2751  if (is_array($local_roles) && count($local_roles))
2752  {
2753  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2754  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2755  }
2756  }
2757  break;
2758  case 7:
2759  global $rbacreview;
2760  $rol_id = $_SESSION["user_filter_data"];
2761  if ($rol_id)
2762  {
2763  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2764  $ilDB->quote($rol_id, "integer")." AND ";
2765  $without_anonymous_users = false;
2766  }
2767  break;
2768  }
2769  }
2770  // This is a temporary hack to search users by their role
2771  // See Mantis #338. This is a hack due to Mantis #337.
2772  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2773  {
2774  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2775  "FROM object_data,rbac_ua,usr_data ".
2776  "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2777  " AND object_data.type = 'role' ".
2778  "AND rbac_ua.rol_id = object_data.obj_id ".
2779  "AND usr_data.usr_id = rbac_ua.usr_id ".
2780  "AND rbac_ua.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2781  }
2782  else
2783  {
2784  $query.= $join_filter.
2785  "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2786  "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2787  "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2788  "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2789 
2790  if ($filter_settings !== FALSE && strlen($filter_settings))
2791  {
2792  switch ($filter_settings)
2793  {
2794  case 0:
2795  $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2796  break;
2797  case 1:
2798  $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2799  break;
2800  case 2:
2801  $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2802  break;
2803  case 4:
2804  $date = strftime("%Y-%m-%d %H:%I:%S", mktime(0, 0, 0, $_SESSION["user_filter_data"]["m"], $_SESSION["user_filter_data"]["d"], $_SESSION["user_filter_data"]["y"]));
2805  $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2806  break;
2807  }
2808  }
2809 
2810  if ($without_anonymous_users)
2811  {
2812  $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2813  }
2814 
2815  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2816  {
2817  $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2818  }
2819 
2820  }
2821  $ilLog->write($query);
2822  $res = $ilDB->query($query);
2823  while ($row = $ilDB->fetchObject($res))
2824  {
2825  $users[] = array(
2826  "usr_id" => $row->usr_id,
2827  "login" => $row->login,
2828  "firstname" => $row->firstname,
2829  "lastname" => $row->lastname,
2830  "email" => $row->email,
2831  "active" => $row->active);
2832  $ids[] = $row->usr_id;
2833  }
2834  if ($a_return_ids_only)
2835  return $ids ? $ids : array();
2836  else
2837  return $users ? $users : array();
2838  }
2839 
2848  function _getAllUserLogins(&$ilias)
2849  {
2850  global $ilDB;
2851 
2852  $res = $ilDB->query("SELECT login FROM usr_data");
2853  while($row = $ilDB->fetchObject($res))
2854  {
2855  $logins[] = $row->login;
2856  }
2857  return $logins ? $logins : array();
2858  }
2859 
2868  public static function _readUsersProfileData($a_user_ids)
2869  {
2870  global $ilDB;
2871  $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2872  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2873  while ($row = $ilDB->fetchAssoc($res))
2874  {
2875  $user_data["$row[usr_id]"] = $row;
2876  }
2877  return $user_data ? $user_data : array();
2878  }
2879 
2888  function _getAllUserData($a_fields = NULL, $active =-1)
2889  {
2890  global $ilDB;
2891 
2892  $result_arr = array();
2893  $types = array();
2894  $values = array();
2895 
2896  if ($a_fields !== NULL and is_array($a_fields))
2897  {
2898  if (count($a_fields) == 0)
2899  {
2900  $select = "*";
2901  }
2902  else
2903  {
2904  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2905  unset($a_fields[$usr_id_field]);
2906 
2907  $select = implode(",",$a_fields).",usr_data.usr_id";
2908  // online time
2909  if(in_array('online_time',$a_fields))
2910  {
2911  $select .= ",ut_online.online_time ";
2912  }
2913  }
2914 
2915  $q = "SELECT ".$select." FROM usr_data ";
2916 
2917  // Add online_time if desired
2918  // Need left join here to show users that never logged in
2919  if(in_array('online_time',$a_fields))
2920  {
2921  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2922  }
2923 
2924  switch ($active)
2925  {
2926  case 0:
2927  case 1:
2928  $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2929  break;
2930  case 2:
2931  $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2932  break;
2933  case 3:
2934  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2935  $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2936  $r = $ilDB->query($qtemp);
2937  $course_users = array();
2938  while ($row = $ilDB->fetchAssoc($r))
2939  {
2940  array_push($course_users, $row["usr_id"]);
2941  }
2942  if (count($course_users))
2943  {
2944  $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2945  }
2946  else
2947  {
2948  return $result_arr;
2949  }
2950  break;
2951  case 4:
2952  $date = strftime("%Y-%m-%d %H:%I:%S", mktime(0, 0, 0, $_SESSION["user_filter_data"]["m"], $_SESSION["user_filter_data"]["d"], $_SESSION["user_filter_data"]["y"]));
2953  $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2954  break;
2955  case 5:
2956  $ref_id = $_SESSION["user_filter_data"];
2957  if ($ref_id)
2958  {
2959  $q .= " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id ".
2960  "WHERE obj_members.obj_id = (SELECT obj_id FROM object_reference ".
2961  "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2962  }
2963  break;
2964  case 6:
2965  global $rbacreview;
2966  $ref_id = $_SESSION["user_filter_data"];
2967  if ($ref_id)
2968  {
2969  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2970  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2971  if (is_array($local_roles) && count($local_roles))
2972  {
2973  $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2974  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2975  }
2976  }
2977  break;
2978  case 7:
2979  $rol_id = $_SESSION["user_filter_data"];
2980  if ($rol_id)
2981  {
2982  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2983  $ilDB->quote($rol_id, "integer");
2984  }
2985  break;
2986  }
2987  $r = $ilDB->query($q);
2988 
2989  while ($row = $ilDB->fetchAssoc($r))
2990  {
2991  $result_arr[] = $row;
2992  }
2993  }
2994 
2995  return $result_arr;
2996  }
2997 
3001  function _getNumberOfUsersForStyle($a_skin, $a_style)
3002  {
3003  global $ilDB;
3004 
3005  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
3006  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3007  " AND up1.value= ".$ilDB->quote($a_style, "text").
3008  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3009  " AND up2.value= ".$ilDB->quote($a_skin, "text").
3010  " AND up1.usr_id = up2.usr_id ";
3011 
3012  $cnt_set = $ilDB->query($q);
3013 
3014  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
3015 
3016  return $cnt_rec["cnt"];
3017  }
3018 
3023  {
3024  global $ilDB;
3025 
3026  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
3027  " WHERE up1.keyword = ".$ilDB->quote("style", "text").
3028  " AND up2.keyword = ".$ilDB->quote("skin", "text").
3029  " AND up1.usr_id = up2.usr_id";
3030 
3031  $sty_set = $ilDB->query($q);
3032 
3033  $styles = array();
3034  while($sty_rec = $ilDB->fetchAssoc($sty_set))
3035  {
3036  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
3037  }
3038 
3039  return $styles;
3040  }
3041 
3045  function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3046  {
3047  global $ilDB;
3048 
3049  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
3050  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3051  " AND up1.value= ".$ilDB->quote($a_from_style, "text").
3052  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3053  " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
3054  " AND up1.usr_id = up2.usr_id ";
3055 
3056  $usr_set = $ilDB->query($q);
3057 
3058  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3059  {
3060  self::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3061  self::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3062  }
3063  }
3064 
3065 
3075  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3076  {
3077  global $ilDB;
3078 
3079  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3080  "item_id = %s AND type = %s AND user_id = %s",
3081  array("integer", "text", "integer"),
3082  array($a_item_id, $a_type, $a_usr_id));
3083 
3084  // only insert if item is not already on desktop
3085  if (!$ilDB->fetchAssoc($item_set))
3086  {
3087  $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3088  " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3089  array($a_item_id,$a_type,$a_usr_id,$a_par));
3090  }
3091 
3092  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3094  }
3095 
3103  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3104  {
3105  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3106  }
3107 
3116  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3117  {
3118  global $ilDB;
3119 
3120  $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3121  " WHERE item_id = %s AND type = %s AND user_id = %s",
3122  array("text", "integer", "text", "integer"),
3123  array($a_par, $a_item_id, $a_type, $this->getId()));
3124  }
3125 
3126 
3136  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3137  {
3138  global $ilDB;
3139 
3140  $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3141  " item_id = %s AND type = %s AND user_id = %s",
3142  array("integer", "text", "integer"),
3143  array($a_item_id, $a_type, $a_usr_id));
3144 
3145  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3147  }
3148 
3156  function dropDesktopItem($a_item_id, $a_type)
3157  {
3158  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3159  }
3160 
3167  static function _removeItemFromDesktops($a_id)
3168  {
3169  global $ilDB;
3170 
3171  $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3172  array("integer"), array($a_id));
3173 
3174  $users = array();
3175 
3176  while ($row = $ilDB->fetchObject($r))
3177  {
3178  $users[] = $row->user_id;
3179  } // while
3180 
3181  if (count($users) > 0)
3182  {
3183  $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3184  array("integer"), array($a_id));
3185  }
3186 
3187  return $users;
3188  }
3189 
3199  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3200  {
3201  global $ilDB;
3202 
3203  if (self::$is_desktop_item_loaded[$a_usr_id.":".$a_item_id])
3204  {
3205  return self::$is_desktop_item_cache[$a_usr_id.":".$a_item_id.":".$a_type];
3206  }
3207  $item_set = $ilDB->queryF("SELECT item_id FROM desktop_item WHERE ".
3208  "item_id = %s AND type = %s AND user_id = %s",
3209  array("integer", "text", "integer"),
3210  array($a_item_id, $a_type, $a_usr_id));
3211 
3212  if ($ilDB->fetchAssoc($item_set))
3213  {
3214  return true;
3215  }
3216  else
3217  {
3218  return false;
3219  }
3220  }
3221 
3228  static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3229  {
3230  global $ilDB;
3231 
3232  if (!is_array($a_item_ids))
3233  {
3234  return;
3235  }
3236 
3237  $item_ids = array();
3238  foreach ($a_item_ids as $id)
3239  {
3240  if (!self::$is_desktop_item_loaded[$a_usr_id.":".$id])
3241  {
3242  $item_ids[] = $id;
3243  }
3244  self::$is_desktop_item_loaded[$a_usr_id.":".$id] = true;
3245  }
3246 
3247  if (count($item_ids) > 0)
3248  {
3249  $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE ".
3250  $ilDB->in("item_id", $item_ids, false, "integer").
3251  " AND user_id = ".$ilDB->quote($a_usr_id, "integer"));
3252  while ($r = $ilDB->fetchAssoc($item_set))
3253  {
3254  self::$is_desktop_item_cache[$a_usr_id.":".$r["item_id"].":".$r["type"]]
3255  = true;
3256  }
3257  }
3258  }
3259 
3267  function isDesktopItem($a_item_id, $a_type)
3268  {
3269  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3270  }
3271 
3272  function getDesktopItems($a_types = "")
3273  {
3274  return $this->_lookupDesktopItems($this->getId(), $a_types);
3275  }
3276 
3283  static function _lookupDesktopItems($user_id, $a_types = "")
3284  {
3285  global $ilUser, $rbacsystem, $tree, $ilDB;
3286 
3287  if ($a_types == "")
3288  {
3289  $is_nested_set = ($tree->getTreeImplementation() instanceof ilNestedSetTree);
3290 
3291  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3292  " FROM desktop_item it, object_reference oref ".
3293  ", object_data obj".
3294  " WHERE ".
3295  "it.item_id = oref.ref_id AND ".
3296  "oref.obj_id = obj.obj_id AND ".
3297  "it.user_id = %s", array("integer"), array($user_id));
3298  $items = $all_parent_path = array();
3299  while ($item_rec = $ilDB->fetchAssoc($item_set))
3300  {
3301  if ($tree->isInTree($item_rec["ref_id"])
3302  && $item_rec["type"] != "rolf"
3303  && $item_rec["type"] != "itgr") // due to bug 11508
3304  {
3305  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3306 
3307  if(!isset($all_parent_path[$parent_ref]))
3308  {
3309  // #15746
3310  if($is_nested_set)
3311  {
3312  $par_left = $tree->getLeftValue($parent_ref);
3313  $all_parent_path[$parent_ref] = sprintf("%010d", $par_left);
3314  }
3315  else
3316  {
3317  $node = $tree->getNodeData($parent_ref);
3318  $all_parent_path[$parent_ref] = $node["path"];
3319  }
3320  }
3321 
3322  $parent_path = $all_parent_path[$parent_ref];
3323 
3324  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3325  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3326  $items[$parent_path.$title.$item_rec["ref_id"]] =
3327  array("ref_id" => $item_rec["ref_id"],
3328  "obj_id" => $item_rec["obj_id"],
3329  "type" => $item_rec["type"],
3330  "title" => $title,
3331  "description" => $desc,
3332  "parent_ref" => $parent_ref);
3333  }
3334  }
3335  ksort($items);
3336  }
3337  else
3338  {
3339  // due to bug 11508
3340  if (!is_array($a_types))
3341  {
3342  $a_types = array($a_types);
3343  }
3344  $items = array();
3345  $foundsurveys = array();
3346  foreach($a_types as $a_type)
3347  {
3348  if ($a_type == "itgr")
3349  {
3350  continue;
3351  }
3352  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3353  ", object_data obj WHERE ".
3354  "it.item_id = oref.ref_id AND ".
3355  "oref.obj_id = obj.obj_id AND ".
3356  "it.type = %s AND ".
3357  "it.user_id = %s ".
3358  "ORDER BY title",
3359  array("text", "integer"),
3360  array($a_type, $user_id));
3361 
3362  while ($item_rec = $ilDB->fetchAssoc($item_set))
3363  {
3364  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3365  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3366  $items[$title.$a_type.$item_rec["ref_id"]] =
3367  array("ref_id" => $item_rec["ref_id"],
3368  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3369  "title" => $title, "description" => $desc);
3370  }
3371 
3372  }
3373  ksort($items);
3374  }
3375 
3376  return $items;
3377  }
3378 
3384 
3392  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3393  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3394  {
3395  global $ilDB;
3396 
3397  if ($a_time == 0)
3398  {
3399  $a_time = date("Y-m-d H:i:s", time());
3400  }
3401 
3402  $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3403  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3404  array("integer", "integer", "text", "integer"),
3405  array(0, $a_item_id, $a_type, $this->getId()));
3406 
3407  // only insert if item is not already in clipboard
3408  if (!$d = $item_set->fetchRow())
3409  {
3410  $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3411  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3412  " (%s,%s,%s,%s,%s,%s,%s)",
3413  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3414  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3415  }
3416  else
3417  {
3418  $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3419  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3420  array("timestamp", "integer", "integer", "text"),
3421  array($a_time, $this->getId(), $a_item_id, $a_type));
3422  }
3423  }
3424 
3428  function addToPCClipboard($a_content, $a_time, $a_nr)
3429  {
3430  global $ilDB;
3431  if ($a_time == 0)
3432  {
3433  $a_time = date("Y-m-d H:i:s", time());
3434  }
3435  $ilDB->insert("personal_pc_clipboard", array(
3436  "user_id" => array("integer", $this->getId()),
3437  "content" => array("clob", $a_content),
3438  "insert_time" => array("timestamp", $a_time),
3439  "order_nr" => array("integer", $a_nr)
3440  ));
3441  }
3442 
3447  {
3448  global $ilDB;
3449 
3450  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3451  " WHERE user_id = %s", array("integer"), array($this->getId()));
3452  $row = $ilDB->fetchAssoc($set);
3453 
3454  $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3455  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3456  array("integer", "timestamp"),
3457  array($this->getId(), $row["mtime"]));
3458  $content = array();
3459  while ($row = $ilDB->fetchAssoc($set))
3460  {
3461  $content[] = $row["content"];
3462  }
3463 
3464  return $content;
3465  }
3466 
3470  function clipboardHasObjectsOfType($a_type)
3471  {
3472  global $ilDB;
3473 
3474  $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3475  "parent = %s AND type = %s AND user_id = %s",
3476  array("integer", "text", "integer"),
3477  array(0, $a_type, $this->getId()));
3478  if ($rec = $ilDB->fetchAssoc($set))
3479  {
3480  return true;
3481  }
3482 
3483  return false;
3484  }
3485 
3490  {
3491  global $ilDB;
3492 
3493  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3494  "type = %s AND user_id = %s",
3495  array("text", "integer"),
3496  array($a_type, $this->getId()));
3497  }
3498 
3503  {
3504  global $ilDB;
3505 
3506  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3507  "user_id = %s", array("integer"), array($this->getId()));
3508  }
3509 
3513  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3514  {
3515  global $ilDB;
3516 
3517  $par = "";
3518  if ($a_top_nodes_only)
3519  {
3520  $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3521  }
3522 
3523  $type_str = ($a_type != "")
3524  ? " AND type = ".$ilDB->quote($a_type, "text")." "
3525  : "";
3526  $q = "SELECT * FROM personal_clipboard WHERE ".
3527  "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3528  $type_str.$par.
3529  " ORDER BY order_nr";
3530  $objs = $ilDB->query($q);
3531  $objects = array();
3532  while ($obj = $ilDB->fetchAssoc($objs))
3533  {
3534  if ($obj["type"] == "mob")
3535  {
3536  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3537  }
3538  if ($obj["type"] == "incl")
3539  {
3540  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3541  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3542  }
3543  $objects[] = array ("id" => $obj["item_id"],
3544  "type" => $obj["type"], "title" => $obj["title"],
3545  "insert_time" => $obj["insert_time"]);
3546  }
3547  return $objects;
3548  }
3549 
3553  function getClipboardChilds($a_parent, $a_insert_time)
3554  {
3555  global $ilDB, $ilUser;
3556 
3557  $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3558  "user_id = %s AND parent = %s AND insert_time = %s ".
3559  " ORDER BY order_nr",
3560  array("integer", "integer", "timestamp"),
3561  array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3562  $objects = array();
3563  while ($obj = $ilDB->fetchAssoc($objs))
3564  {
3565  if ($obj["type"] == "mob")
3566  {
3567  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3568  }
3569  $objects[] = array ("id" => $obj["item_id"],
3570  "type" => $obj["type"], "title" => $obj["title"]);
3571  }
3572  return $objects;
3573  }
3574 
3583  function _getUsersForClipboadObject($a_type, $a_id)
3584  {
3585  global $ilDB;
3586 
3587  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3588  "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3589  "type = ".$ilDB->quote($a_type, "text");
3590  $user_set = $ilDB->query($q);
3591  $users = array();
3592  while ($user_rec = $ilDB->fetchAssoc($user_set))
3593  {
3594  $users[] = $user_rec["user_id"];
3595  }
3596 
3597  return $users;
3598  }
3599 
3607  function removeObjectFromClipboard($a_item_id, $a_type)
3608  {
3609  global $ilDB;
3610 
3611  $q = "DELETE FROM personal_clipboard WHERE ".
3612  "item_id = ".$ilDB->quote($a_item_id, "integer").
3613  " AND type = ".$ilDB->quote($a_type, "text")." ".
3614  " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3615  $ilDB->manipulate($q);
3616  }
3617 
3618  function _getImportedUserId($i2_id)
3619  {
3620  global $ilDB;
3621 
3622  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3623  $ilDB->quote($i2_id, "text");
3624 
3625  $res = $ilDB->query($query);
3626  while($row = $ilDB->fetchObject($res))
3627  {
3628  $id = $row->obj_id;
3629  }
3630  return $id ? $id : 0;
3631  }
3632 
3633 /*
3634 
3635  function setiLincData($a_id,$a_login,$a_passwd)
3636  {
3637  $this->ilinc_id = $a_id;
3638  $this->ilinc_login = $a_login;
3639  $this->ilinc_passwd = $a_passwd;
3640  }
3641 
3642 */
3643 
3644 /*
3645 
3646  function getiLincData()
3647  {
3648  return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
3649  }
3650 */
3655  function setAuthMode($a_str)
3656  {
3657  $this->auth_mode = $a_str;
3658  }
3659 
3664  function getAuthMode($a_auth_key = false)
3665  {
3666  if (!$a_auth_key)
3667  {
3668  return $this->auth_mode;
3669  }
3670 
3671  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3672  return ilAuthUtils::_getAuthMode($this->auth_mode);
3673  }
3674 
3682  function setExternalAccount($a_str)
3683  {
3684  $this->ext_account = $a_str;
3685  }
3686 
3695  {
3696  return $this->ext_account;
3697  }
3698 
3710  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3711  {
3712  global $ilDB,$ilSetting;
3713 
3714  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3715  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3716  "WHERE auth_mode = %s";
3717  $types[] = "text";
3718  $values[] = $a_auth_mode;
3719  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3720  {
3721  $q.= " OR auth_mode = %s ";
3722  $types[] = "text";
3723  $values[] = 'default';
3724  }
3725 
3726  $res = $ilDB->queryF($q, $types, $values);
3727  while ($row = $ilDB->fetchObject($res))
3728  {
3729  if($row->auth_mode == 'default')
3730  {
3731  $accounts[$row->usr_id] = $row->login;
3732  }
3733  else
3734  {
3735  $accounts[$row->usr_id] = $row->ext_account;
3736  }
3737  }
3738  return $accounts ? $accounts : array();
3739  }
3740 
3748  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3749  {
3750  global $ilDB;
3751 
3752  if(!is_array($a_usr_ids))
3753  {
3754  return false;
3755  }
3756 
3757 
3758  if( $a_status )
3759  {
3760  $q = "UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE ".
3761  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3762  $ilDB->manipulate($q);
3763  }
3764  else
3765  {
3766  $usrId_IN_usrIds = $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3767 
3768  $q = "UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds";
3769  $ilDB->manipulate($q);
3770 
3771  $queryString = "
3772  UPDATE usr_data
3773  SET inactivation_date = %s
3774  WHERE inactivation_date IS NULL
3775  AND $usrId_IN_usrIds
3776  ";
3777  $ilDB->manipulateF($queryString, array('timestamp'), array(ilUtil::now()));
3778  }
3779 
3780  return true;
3781  }
3782 
3783 
3792  public static function _lookupAuthMode($a_usr_id)
3793  {
3794  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3795  }
3796 
3803  public static function _checkExternalAuthAccount($a_auth, $a_account)
3804  {
3805  global $ilDB,$ilSetting;
3806 
3807  // Check directly with auth_mode
3808  $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3809  " ext_account = %s AND auth_mode = %s",
3810  array("text", "text"),
3811  array($a_account, $a_auth));
3812  if ($usr = $ilDB->fetchAssoc($r))
3813  {
3814  return $usr["login"];
3815  }
3816 
3817  // For compatibility, check for login (no ext_account entry given)
3818  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3819  "WHERE login = %s AND auth_mode = %s",
3820  array("text", "text"),
3821  array($a_account, $a_auth));
3822  if($usr = $ilDB->fetchAssoc($res))
3823  {
3824  return $usr['login'];
3825  }
3826 
3827  // If auth_default == $a_auth => check for login
3828  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3829  {
3830  $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3831  " ext_account = %s AND auth_mode = %s",
3832  array("text", "text"),
3833  array($a_account, "default"));
3834  if ($usr = $ilDB->fetchAssoc($res))
3835  {
3836  return $usr["login"];
3837  }
3838  // Search for login (no ext_account given)
3839  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3840  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3841  array("text", "text"),
3842  array($a_account, "default"));
3843  if($usr = $ilDB->fetchAssoc($res))
3844  {
3845  return $usr["login"];
3846  }
3847  }
3848  return false;
3849  }
3850 
3855  {
3856  global $ilDB;
3857 
3858  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3859  "GROUP BY auth_mode");
3860  $cnt_arr = array();
3861  while($cnt = $ilDB->fetchAssoc($r))
3862  {
3863  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3864  }
3865 
3866  return $cnt_arr;
3867  }
3868 
3874  function _getLocalAccountsForEmail($a_email)
3875  {
3876  global $ilDB, $ilSetting;
3877 
3878  // default set to local (1)?
3879 
3880  $q = "SELECT * FROM usr_data WHERE ".
3881  " email = %s AND (auth_mode = %s ";
3882  $types = array("text", "text");
3883  $values = array($a_email, "local");
3884 
3885  if ($ilSetting->get("auth_mode") == 1)
3886  {
3887  $q.=" OR auth_mode = %s";
3888  $types[] = "text";
3889  $values[] = "default";
3890  }
3891 
3892  $q.= ")";
3893 
3894  $users = array();
3895  $usr_set = $ilDB->queryF($q, $types, $values);
3896  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3897  {
3898  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3899  }
3900 
3901  return $users;
3902  }
3903 
3904 
3912  function _uploadPersonalPicture($tmp_file, $obj_id)
3913  {
3914  $webspace_dir = ilUtil::getWebspaceDir();
3915  $image_dir = $webspace_dir."/usr_images";
3916  $store_file = "usr_".$obj_id."."."jpg";
3917  $target_file = $image_dir."/$store_file";
3918 
3919  chmod($tmp_file, 0770);
3920 
3921  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3922  // taking only frame [0] to avoid problems with animated gifs
3923  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3924  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3925  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3926  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3927 
3928  ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
3929  ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
3930  ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
3931  ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
3932 
3933  // store filename
3934  self::_writePref($obj_id, "profile_image", $store_file);
3935 
3936  return TRUE;
3937  }
3938 
3939 
3948  public function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3949  {
3950  if(isset(self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic]))
3951  {
3952  return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3953  }
3954 
3955  self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic] = ilObjUser::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
3956 
3957  return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3958  }
3959 
3969  public static function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3970  $a_prevent_no_photo_image = false)
3971  {
3972  global $ilDB;
3973 
3974  // BEGIN DiskQuota: Fetch all user preferences in a single query
3975  $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3976  "keyword IN (%s,%s) ".
3977  "AND usr_id = %s",
3978  array("text", "text", "integer"),
3979  array('public_upload', 'public_profile', $a_usr_id));
3980  while ($row = $ilDB->fetchAssoc($res))
3981  {
3982  switch ($row['keyword'])
3983  {
3984  case 'public_upload' :
3985  $upload = $row['value'] == 'y';
3986  break;
3987  case 'public_profile' :
3988  $profile = ($row['value'] == 'y' ||
3989  $row['value'] == 'g');
3990  break;
3991  }
3992  }
3993 
3994  // END DiskQuota: Fetch all user preferences in a single query
3995  $webspace_dir = "";
3996  if(defined('ILIAS_MODULE'))
3997  {
3998  $webspace_dir = ('.'.$webspace_dir);
3999  }
4000  $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
4001 
4002  $image_dir = $webspace_dir."/usr_images";
4003  // BEGIN DiskQuota: Support 'big' user images
4004  if ($a_size == 'big')
4005  {
4006  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
4007  }
4008  else
4009  {
4010  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
4011  }
4012  // END DiskQuota: Support 'big' user images
4013 
4014  if((($upload && $profile) || $a_force_pic)
4015  && @is_file($thumb_file))
4016  {
4017  $file = $thumb_file."?t=".rand(1, 99999);
4018  }
4019  else
4020  {
4021  if (!$a_prevent_no_photo_image)
4022  {
4023  // we only have xsmall and xxsmall for this
4024  if($a_size == "small" || $a_size == "big")
4025  {
4026  $a_size = "xsmall";
4027  }
4028  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
4029  }
4030  }
4031 
4032  return $file;
4033  }
4034 
4041  static function copyProfilePicturesToDirectory($a_user_id, $a_dir)
4042  {
4043  $a_dir = trim(str_replace("..", "", $a_dir));
4044  if ($a_dir == "" || !is_dir($a_dir))
4045  {
4046  return;
4047  }
4048 
4049  $webspace_dir = ilUtil::getWebspaceDir();
4050  $image_dir = $webspace_dir."/usr_images";
4051  $images = array(
4052  "upload_".$a_user_id."pic",
4053  "usr_".$a_user_id."."."jpg",
4054  "usr_".$a_user_id."_small.jpg",
4055  "usr_".$a_user_id."_xsmall.jpg",
4056  "usr_".$a_user_id."_xxsmall.jpg",
4057  "upload_".$a_user_id);
4058  foreach ($images as $image)
4059  {
4060  if (is_file($image_dir."/".$image))
4061  {
4062  copy($image_dir."/".$image, $a_dir."/".$image);
4063  }
4064  }
4065  }
4066 
4067 
4071  function removeUserPicture($a_do_update = true)
4072  {
4073  $webspace_dir = ilUtil::getWebspaceDir();
4074  $image_dir = $webspace_dir."/usr_images";
4075  $file = $image_dir."/usr_".$this->getID()."."."jpg";
4076  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
4077  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
4078  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
4079  $upload_file = $image_dir."/upload_".$this->getID();
4080 
4081  if($a_do_update)
4082  {
4083  // remove user pref file name
4084  $this->setPref("profile_image", "");
4085  $this->update();
4086  }
4087 
4088  if (@is_file($file))
4089  {
4090  unlink($file);
4091  }
4092  if (@is_file($thumb_file))
4093  {
4094  unlink($thumb_file);
4095  }
4096  if (@is_file($xthumb_file))
4097  {
4098  unlink($xthumb_file);
4099  }
4100  if (@is_file($xxthumb_file))
4101  {
4102  unlink($xxthumb_file);
4103  }
4104  if (@is_file($upload_file))
4105  {
4106  unlink($upload_file);
4107  }
4108  }
4109 
4110 
4111  function setUserDefinedData($a_data)
4112  {
4113  if(!is_array($a_data))
4114  {
4115  return false;
4116  }
4117  foreach($a_data as $field => $data)
4118  {
4119  #$new_data[$field] = ilUtil::stripSlashes($data);
4120  // Assign it directly to avoid update problems of unchangable fields
4121  $this->user_defined_data['f_'.$field] = $data;
4122  }
4123  #$this->user_defined_data = $new_data;
4124 
4125  return true;
4126  }
4127 
4129  {
4130  return $this->user_defined_data ? $this->user_defined_data : array();
4131  }
4132 
4134  {
4135  global $ilDB;
4136 
4137  $fields = '';
4138 
4139  $field_def = array();
4140 
4141  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4142  $udata = new ilUserDefinedData($this->getId());
4143 
4144  foreach($this->user_defined_data as $field => $value)
4145  {
4146  if($field != 'usr_id')
4147  {
4148 // $field_def[$field] = array('text',$value);
4149  $udata->set($field, $value);
4150  }
4151  }
4152  $udata->update();
4153 
4154 /* if(!$field_def)
4155  {
4156  return true;
4157  }
4158 
4159  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4160  $res = $ilDB->query($query);
4161 
4162 
4163  if($res->numRows())
4164  {
4165  // Update
4166  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4167  }
4168  else
4169  {
4170  $field_def['usr_id'] = array('integer',$this->getId());
4171  $ilDB->insert('udf_data',$field_def);
4172  }
4173 */
4174  return true;
4175  }
4176 
4178  {
4179  global $ilDB;
4180 
4181  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4182  $udata = new ilUserDefinedData($this->getId());
4183 
4184 /* $query = "SELECT * FROM udf_data ".
4185  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4186 
4187  $res = $this->db->query($query);
4188  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
4189  {
4190  $this->user_defined_data = $row;
4191  }*/
4192 
4193  $this->user_defined_data = $udata->getAll();
4194 
4195  return true;
4196  }
4197 
4199  {
4200  global $ilDB;
4201 
4202 // not needed. no entry in udf_text/udf_clob means no value
4203 
4204 /* $query = "INSERT INTO udf_data (usr_id ) ".
4205  "VALUES( ".
4206  $ilDB->quote($this->getId(),'integer').
4207  ")";
4208  $res = $ilDB->manipulate($query);
4209 */
4210  return true;
4211  }
4212 
4214  {
4215  global $ilDB;
4216 
4217  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4219 
4220  // wrong place...
4221 /* $query = "DELETE FROM udf_data ".
4222  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4223  $res = $ilDB->manipulate($query);*/
4224 
4225  return true;
4226  }
4227 
4233  function getProfileAsString(&$a_language)
4234  {
4235  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4236  include_once './Services/Utilities/classes/class.ilFormat.php';
4237 
4238  global $lng,$rbacreview;
4239 
4240  $language =& $a_language;
4241  $language->loadLanguageModule('registration');
4242  $language->loadLanguageModule('crs');
4243 
4244  $body = '';
4245  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4246 
4247  if(strlen($this->getUTitle()))
4248  {
4249  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4250  }
4251  if(strlen($this->getGender()))
4252  {
4253  $gender = ($this->getGender() == 'm') ?
4254  $language->txt('gender_m') :
4255  $language->txt('gender_f');
4256  $body .= ($language->txt("gender").": ".$gender."\n");
4257  }
4258  if(strlen($this->getFirstname()))
4259  {
4260  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4261  }
4262  if(strlen($this->getLastname()))
4263  {
4264  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4265  }
4266  if(strlen($this->getInstitution()))
4267  {
4268  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4269  }
4270  if(strlen($this->getDepartment()))
4271  {
4272  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4273  }
4274  if(strlen($this->getStreet()))
4275  {
4276  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4277  }
4278  if(strlen($this->getCity()))
4279  {
4280  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4281  }
4282  if(strlen($this->getZipcode()))
4283  {
4284  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4285  }
4286  if(strlen($this->getCountry()))
4287  {
4288  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4289  }
4290  if(strlen($this->getSelectedCountry()))
4291  {
4292  $body .= ($language->txt("sel_country").": ".$this->getSelectedCountry()."\n");
4293  }
4294  if(strlen($this->getPhoneOffice()))
4295  {
4296  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4297  }
4298  if(strlen($this->getPhoneHome()))
4299  {
4300  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4301  }
4302  if(strlen($this->getPhoneMobile()))
4303  {
4304  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4305  }
4306  if(strlen($this->getFax()))
4307  {
4308  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4309  }
4310  if(strlen($this->getEmail()))
4311  {
4312  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4313  }
4314  if(strlen($this->getHobby()))
4315  {
4316  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4317  }
4318  if(strlen($this->getComment()))
4319  {
4320  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4321  }
4322  if(strlen($this->getMatriculation()))
4323  {
4324  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4325  }
4326  if(strlen($this->getCreateDate()))
4327  {
4332 
4333  $body .= ($language->txt("create_date").": ".$date."\n");
4334  }
4335 
4336  foreach($rbacreview->getGlobalRoles() as $role)
4337  {
4338  if($rbacreview->isAssigned($this->getId(),$role))
4339  {
4340  $gr[] = ilObjRole::_lookupTitle($role);
4341  }
4342  }
4343  if(count($gr))
4344  {
4345  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4346  }
4347 
4348  // Time limit
4349  if($this->getTimeLimitUnlimited())
4350  {
4351  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4352  }
4353  else
4354  {
4358  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4360 
4361  $start = new ilDateTime($this->getTimeLimitFrom(),IL_CAL_UNIX);
4362  $end = new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX);
4363 
4364  $body .= $language->txt('time_limit').': '.$start->get(IL_CAL_DATETIME);
4365  $body .= $language->txt('time_limit').': '.$end->get(IL_CAL_DATETIME);
4366 
4367 
4368  #$body .= $language->txt('time_limit').': '.$period;
4369  /*
4370  $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4371  ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4372  $language->txt('crs_to')." ".
4373  ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4374  */
4375  }
4376 
4377  include_once './Services/User/classes/class.ilUserDefinedFields.php';
4381  $user_defined_fields = ilUserDefinedFields::_getInstance();
4382  $user_defined_data = $this->getUserDefinedData();
4383 
4384  foreach($user_defined_fields->getDefinitions() as $field_id => $definition)
4385  {
4386  $data = $user_defined_data["f_".$field_id];
4387  if(strlen($data))
4388  {
4389  if($definition['field_type'] == UDF_TYPE_WYSIWYG)
4390  {
4391  $data = preg_replace('/<br(\s*)?\/?>/i', "\n", $data);
4392  $data = strip_tags($data);
4393  }
4394 
4395  $body .= $definition['field_name'].': '. $data . "\n";
4396  }
4397  }
4398 
4399  return $body;
4400  }
4401 
4402  function setInstantMessengerId($a_im_type, $a_im_id)
4403  {
4404  $var = "im_".$a_im_type;
4405  $this->$var = $a_im_id;
4406  }
4407 
4408  function getInstantMessengerId($a_im_type)
4409  {
4410  $var = "im_".$a_im_type;
4411  return $this->$var;
4412  }
4413 
4414  function setDelicious($a_delicious)
4415  {
4416  $this->delicious = $a_delicious;
4417  }
4418 
4419  function getDelicious()
4420  {
4421  return $this->delicious;
4422  }
4423 
4427  function _lookupFeedHash($a_user_id, $a_create = false)
4428  {
4429  global $ilDB;
4430 
4431  if ($a_user_id > 0)
4432  {
4433  $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4434  array("integer"), array($a_user_id));
4435  if ($rec = $ilDB->fetchAssoc($set))
4436  {
4437  if (strlen($rec["feed_hash"]) == 32)
4438  {
4439  return $rec["feed_hash"];
4440  }
4441  else if($a_create)
4442  {
4443  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4444  $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4445  " WHERE usr_id = %s",
4446  array("text", "integer"),
4447  array($hash, $a_user_id));
4448  return $hash;
4449  }
4450  }
4451  }
4452 
4453  return false;
4454  }
4455 
4461  function _getFeedPass($a_user_id)
4462  {
4463  global $ilDB;
4464 
4465  if ($a_user_id > 0)
4466  {
4467  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4468  }
4469  return false;
4470  }
4471 
4477  function _setFeedPass($a_user_id, $a_password)
4478  {
4479  global $ilDB;
4480 
4481  self::_writePref($a_user_id, "priv_feed_pass",
4482  ($a_password=="") ? "" : md5($a_password));
4483  }
4484 
4494  public static function _loginExists($a_login,$a_user_id = 0)
4495  {
4496  global $ilDB;
4497 
4498  $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4499  "WHERE login = %s";
4500  $types[] = "text";
4501  $values[] = $a_login;
4502 
4503  if ($a_user_id != 0)
4504  {
4505  $q.= " AND usr_id != %s ";
4506  $types[] = "integer";
4507  $values[] = $a_user_id;
4508  }
4509 
4510  $r = $ilDB->queryF($q, $types, $values);
4511 
4512  if ($row = $ilDB->fetchAssoc($r))
4513  {
4514  return $row['usr_id'];
4515  }
4516  return false;
4517  }
4518 
4529  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4530  {
4531  global $ilDB;
4532 
4533  $res = $ilDB->queryF("SELECT * FROM usr_data ".
4534  "WHERE ext_account = %s AND auth_mode = %s",
4535  array("text", "text"),
4536  array($a_external_account, $a_auth_mode));
4537  return $ilDB->fetchAssoc($res) ? true :false;
4538  }
4539 
4547  public static function _getUsersForRole($role_id, $active = -1) {
4548  global $ilDB, $rbacreview;
4549  $data = array();
4550 
4551  $ids = $rbacreview->assignedUsers($role_id);
4552 
4553  if (count ($ids) == 0)
4554  {
4555  $ids = array (-1);
4556  }
4557 
4558  $query = "SELECT usr_data.*, usr_pref.value AS language
4559  FROM usr_data
4560  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4561  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4562  $values[] = "language";
4563  $types[] = "text";
4564 
4565 
4566  if (is_numeric($active) && $active > -1)
4567  {
4568  $query .= " AND usr_data.active = %s";
4569  $values[] = $active;
4570  $types[] = "integer";
4571  }
4572 
4573  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4574 
4575  $r = $ilDB->queryF($query, $types, $values);
4576  $data = array();
4577  while ($row = $ilDB->fetchAssoc($r))
4578  {
4579  $data[] = $row;
4580  }
4581  return $data;
4582  }
4583 
4584 
4590  public static function _getUsersForFolder ($ref_id, $active) {
4591  global $ilDB;
4592  $data = array();
4593  $query = "SELECT usr_data.*, usr_pref.value AS language FROM usr_data LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id and usr_pref.keyword = %s WHERE 1 = 1 ";
4594  $types[] = "text";
4595  $values[] = "language";
4596 
4597  if (is_numeric($active) && $active > -1)
4598  {
4599  $query .= " AND usr_data.active = %s";
4600  $values[] = $active;
4601  $types[] = "integer";
4602  }
4603 
4604  if ($ref_id != USER_FOLDER_ID)
4605  {
4606  $query.= " AND usr_data.time_limit_owner = %s";
4607  $values[] = $ref_id;
4608  $types[] = "integer";
4609  }
4610 
4611  $query .= " AND usr_data.usr_id != %s ";
4612  $values[] = ANONYMOUS_USER_ID;
4613  $types[] = "integer";
4614 
4615  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4616 
4617  $result = $ilDB->queryF($query, $types, $values);
4618  $data = array();
4619  while ($row = $ilDB->fetchAssoc($result))
4620  {
4621  array_push($data, $row);
4622  }
4623 
4624  return $data;
4625  }
4626 
4627 
4633  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4634  {
4635  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4636  }
4637 
4638 
4644  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4645  {
4646  global $rbacadmin, $rbacreview, $ilDB;
4647 
4648  // quote all ids
4649  $ids = array();
4650  foreach ($a_mem_ids as $mem_id) {
4651  $ids [] = $ilDB->quote($mem_id);
4652  }
4653 
4654  $query = "SELECT usr_data.*, usr_pref.value AS language
4655  FROM usr_data
4656  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4657  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer")."
4658  AND usr_data.usr_id != %s";
4659  $values[] = "language";
4660  $types[] = "text";
4661  $values[] = ANONYMOUS_USER_ID;
4662  $types[] = "integer";
4663 
4664  if (is_numeric($active) && $active > -1)
4665  {
4666  $query .= " AND active = %s";
4667  $values[] = $active;
4668  $types[] = "integer";
4669  }
4670 
4671  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4672  {
4673  $query.= " AND usr_data.time_limit_owner = %s";
4674  $values[] = $timelimitowner;
4675  $types[] = "integer";
4676 
4677  }
4678 
4679  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4680 
4681  $result = $ilDB->queryF($query, $types, $values);
4682  while ($row = $ilDB->fetchAssoc($result))
4683  {
4684  $mem_arr[] = $row;
4685  }
4686 
4687  return $mem_arr ? $mem_arr : array();
4688  }
4689 
4690 
4691 
4697  public static function _getUserData ($a_internalids) {
4698  global $ilDB;
4699 
4700  $ids = array();
4701  if (is_array($a_internalids)) {
4702  foreach ($a_internalids as $internalid) {
4703  if (is_numeric ($internalid))
4704  {
4705  $ids[] = $internalid;
4706  }
4707  else
4708  {
4709  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4710  if (is_numeric($parsedid) && $parsedid > 0)
4711  {
4712  $ids[] = $parsedid;
4713  }
4714  }
4715  }
4716  }
4717  if (count($ids) == 0)
4718  $ids [] = -1;
4719 
4720  $query = "SELECT usr_data.*, usr_pref.value AS language
4721  FROM usr_data
4722  LEFT JOIN usr_pref
4723  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4724  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4725  $values[] = "language";
4726  $types[] = "text";
4727 
4728  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4729 
4730  $data = array();
4731  $result = $ilDB->queryF($query, $types, $values);
4732  while ($row = $ilDB->fetchAssoc($result))
4733  {
4734  $data[] = $row;
4735  }
4736  return $data;
4737  }
4738 
4745  public static function _getPreferences ($user_id)
4746  {
4747  global $ilDB;
4748 
4749  $prefs = array();
4750 
4751  $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4752  array("integer"), array($user_id));
4753 
4754  while($row = $ilDB->fetchAssoc($r))
4755  {
4756  $prefs[$row["keyword"]] = $row["value"];
4757  }
4758 
4759  return $prefs;
4760  }
4761 
4762 
4763  public static function _resetLoginAttempts($a_usr_id)
4764  {
4765  global $ilDB;
4766 
4767  $query = "UPDATE usr_data SET login_attempts = 0 WHERE usr_id = %s";
4768  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4769 
4770  if($affected) return true;
4771  else return false;
4772  }
4773 
4774  public static function _getLoginAttempts($a_usr_id)
4775  {
4776  global $ilDB;
4777 
4778  $query = "SELECT login_attempts FROM usr_data WHERE usr_id = %s";
4779  $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4780  $record = $ilDB->fetchAssoc( $result );
4781  $login_attempts = $record['login_attempts'];
4782 
4783  return $login_attempts;
4784  }
4785 
4786  public static function _incrementLoginAttempts($a_usr_id)
4787  {
4788  global $ilDB;
4789 
4790  $query = "UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s";
4791  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4792 
4793  if($affected) return true;
4794  else return false;
4795  }
4796 
4797  public static function _setUserInactive($a_usr_id)
4798  {
4799  global $ilDB;
4800 
4801  $query = "UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s";
4802  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array(ilUtil::now(), $a_usr_id) );
4803 
4804  if($affected) return true;
4805  else return false;
4806  }
4807 
4813  public function hasPublicProfile() {
4814  return in_array($this->getPref("public_profile"), array("y", "g"));
4815  }
4816 
4822  public function getPublicName()
4823  {
4824  if ($this->hasPublicProfile())
4825  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4826  else
4827  return $this->getLogin();
4828 
4829  }
4830 
4831  public static function _writeHistory($a_usr_id, $a_login)
4832  {
4833  global $ilDB;
4834 
4835  $timestamp = time();
4836 
4837  $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4838  array('integer', 'text', 'integer'),
4839  array($a_usr_id, $a_login, $timestamp));
4840 
4841  if( $ilDB->numRows($res) == 0 )
4842  {
4843  $ilDB->manipulateF('
4844  INSERT INTO loginname_history
4845  (usr_id, login, history_date)
4846  VALUES (%s, %s, %s)',
4847  array('integer', 'text', 'integer'),
4848  array($a_usr_id, $a_login, $timestamp));
4849  }
4850 
4851  return true;
4852  }
4853 
4861  public static function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4862  {
4866  global $ilDB;
4867 
4868  $pd_set = new ilSetting('pd');
4869  $atime = $pd_set->get('user_activity_time') * 60;
4870  $ctime = time();
4871 
4872  $where = array();
4873 
4874  if($a_user_id == 0)
4875  {
4876  $where[] = 'user_id > 0';
4877 
4878  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4879  if(ilTermsOfServiceHelper::isEnabled())
4880  {
4881  $where[] = '(agree_date IS NOT NULL OR user_id = ' . $ilDB->quote(SYSTEM_USER_ID, 'integer') . ')';
4882  }
4883  }
4884  else
4885  {
4886  $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
4887  }
4888 
4889  if($a_no_anonymous)
4890  {
4891  $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
4892  }
4893 
4894  include_once 'Services/User/classes/class.ilUserAccountSettings.php';
4895  if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
4896  {
4897  include_once 'Services/User/classes/class.ilUserFilter.php';
4898  $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
4899  }
4900 
4901  $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
4902  $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
4903 
4904  $where = 'WHERE ' . implode(' AND ', $where);
4905 
4906  $r = $ilDB->queryF("
4907  SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime
4908  FROM usr_session
4909  LEFT JOIN usr_data u
4910  ON user_id = u.usr_id
4911  LEFT JOIN usr_pref p
4912  ON (p.usr_id = u.usr_id AND p.keyword = %s)
4913  {$where}
4914  GROUP BY user_id, firstname, lastname, title, login, last_login
4915  ORDER BY lastname, firstname
4916  ",
4917  array('text'),
4918  array('hide_own_online_status')
4919  );
4920 
4921  $users = array();
4922  while($user = $ilDB->fetchAssoc($r))
4923  {
4924  if($atime <= 0 || $user['ctime'] + $atime > $ctime)
4925  {
4926  $users[$user['user_id']] = $user;
4927  }
4928  }
4929 
4930  return $users;
4931  }
4932 
4941  public static function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4942  {
4943  global $ilias, $ilDB;
4944 
4945  $pd_set = new ilSetting("pd");
4946  $atime = $pd_set->get("user_activity_time") * 60;
4947  $ctime = time();
4948  $no_anonym = ($a_no_anonymous)
4949  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4950  : "";
4951 
4952  // Get a list of object id's of all courses and groups for which
4953  // the current user has local roles.
4954  // Note: we have to use DISTINCT here, because a user may assume
4955  // multiple roles in a group or a course.
4956  $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4957  "FROM rbac_ua ua ".
4958  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4959  "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4960  "JOIN tree ON tree.child = r1.ref_id ".
4961  "JOIN object_reference r2 ON r2.ref_id = tree.parent ".
4962  "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4963  "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4964  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4965  "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4966  $ilDB->quote("grp", "text").")";
4967  $r = $ilDB->query($q);
4968 
4969  while ($row = $ilDB->fetchAssoc($r))
4970  {
4971  $groups_and_courses_of_user[] = $row["obj_id"];
4972  }
4973 
4974  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4975  $tos_condition = '';
4976  if(ilTermsOfServiceHelper::isEnabled())
4977  {
4978  $tos_condition = " AND (agree_date IS NOT NULL OR ud.usr_id = " . $ilDB->quote(SYSTEM_USER_ID, 'integer') . ") ";
4979  }
4980 
4981  // If the user is not in a course or a group, he has no associated users.
4982  if (count($groups_and_courses_of_user) == 0)
4983  {
4984  $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4985  "FROM usr_session ".
4986  "JOIN usr_data ud ON user_id = ud.usr_id ".
4987  "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4988  $no_anonym.
4989  $tos_condition.
4990  "AND expires > ".$ilDB->quote(time(), "integer")." ".
4991  "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4992  $r = $ilDB->query($q);
4993  }
4994  else
4995  {
4996  $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4997  "FROM usr_session s ".
4998  "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4999  "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
5000  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
5001  "JOIN tree ON tree.child = fa.parent ".
5002  "JOIN object_reference or1 ON or1.ref_id = tree.parent ".
5003  "JOIN object_data od ON od.obj_id = or1.obj_id ".
5004  "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
5005  $ilDB->quote("hide_own_online_status", "text").") ".
5006  "WHERE s.user_id != 0 ".
5007  $no_anonym.
5008  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
5009  "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
5010  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
5011  $tos_condition.
5012  "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
5013  "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
5014  "ORDER BY ud.lastname, ud.firstname";
5015  $r = $ilDB->query($q);
5016  }
5017 
5018  while ($user = $ilDB->fetchAssoc($r))
5019  {
5020  if ($atime <= 0
5021  || $user["ctime"] + $atime > $ctime)
5022  {
5023  $users[$user["user_id"]] = $user;
5024  }
5025  }
5026 
5027  return $users ? $users : array();
5028  }
5029 
5036  public static function _generateRegistrationHash($a_usr_id)
5037  {
5038  global $ilDB;
5039 
5040  do
5041  {
5042  $continue = false;
5043 
5044  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
5045 
5046  $res = $ilDB->queryf('
5047  SELECT COUNT(usr_id) cnt FROM usr_data
5048  WHERE reg_hash = %s',
5049  array('text'),
5050  array($hashcode));
5051  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5052  {
5053  if($row->cnt > 0) $continue = true;
5054  break;
5055  }
5056 
5057  if($continue) continue;
5058 
5059  $ilDB->manipulateF('
5060  UPDATE usr_data
5061  SET reg_hash = %s
5062  WHERE usr_id = %s',
5063  array('text', 'integer'),
5064  array($hashcode, (int)$a_usr_id)
5065  );
5066 
5067  break;
5068 
5069  } while(true);
5070 
5071  return $hashcode;
5072  }
5073 
5082  public static function _verifyRegistrationHash($a_hash)
5083  {
5084  global $ilDB;
5085 
5086  $res = $ilDB->queryf('
5087  SELECT usr_id, create_date FROM usr_data
5088  WHERE reg_hash = %s',
5089  array('text'),
5090  array($a_hash));
5091  while($row = $ilDB->fetchAssoc($res))
5092  {
5093  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
5094  $oRegSettigs = new ilRegistrationSettings();
5095 
5096  if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
5097  time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
5098  {
5099  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
5100  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
5101  }
5102 
5103  $ilDB->manipulateF('
5104  UPDATE usr_data
5105  SET reg_hash = %s
5106  WHERE usr_id = %s',
5107  array('text', 'integer'),
5108  array('', (int)$row['usr_id'])
5109  );
5110 
5111  return (int)$row['usr_id'];
5112  }
5113 
5114  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
5115  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
5116  }
5117 
5118  function setBirthday($a_birthday)
5119  {
5120  if (strlen($a_birthday))
5121  {
5122  $date = new ilDate($a_birthday, IL_CAL_DATE);
5123  $this->birthday = $date->get(IL_CAL_DATE);
5124  }
5125  else
5126  {
5127  $this->birthday = null;
5128  }
5129  }
5130 
5131  function getBirthday()
5132  {
5133  return $this->birthday;
5134  }
5135 
5144  public static function _getUserIdsByInactivityPeriod($period)
5145  {
5146  if( !(int)$period ) throw new ilException('no valid period given');
5147 
5148  global $ilDB;
5149 
5150  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5151 
5152  $query = "SELECT usr_id FROM usr_data WHERE last_login < %s";
5153 
5154  $res = $ilDB->queryF($query, array('timestamp'), array($date));
5155 
5156  $ids = array();
5157  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5158  {
5159  $ids[] = $row->usr_id;
5160  }
5161 
5162  return $ids;
5163  }
5164 
5173  public static function _getUserIdsByInactivationPeriod($period)
5174  {
5176  $field = 'inactivation_date';
5178 
5179  if( !(int)$period ) throw new ilException('no valid period given');
5180 
5181  global $ilDB;
5182 
5183  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5184 
5185  $query = "SELECT usr_id FROM usr_data WHERE $field < %s AND active = %s";
5186 
5187  $res = $ilDB->queryF($query, array('timestamp', 'integer'), array($date, 0));
5188 
5189  $ids = array();
5190  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5191  {
5192  $ids[] = $row->usr_id;
5193  }
5194 
5195  return $ids;
5196  }
5197 
5207  public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5208  {
5209  if($a_last_login !== null) $last_login = $a_last_login;
5210  else $last_login = date('Y-m-d H:i:s');
5211 
5212  global $ilDB;
5213 
5214  $query = "UPDATE usr_data SET last_login = %s WHERE usr_id = %s";
5215  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array($last_login, $a_usr_id) );
5216 
5217  if($affected) return $last_login;
5218  else return false;
5219  }
5220 
5221  public function resetOwner()
5222  {
5223  global $ilDB;
5224 
5225  $query = "UPDATE object_data SET owner = 0 ".
5226  "WHERE owner = ".$ilDB->quote($this->getId(),'integer');
5227  $ilDB->query($query);
5228 
5229  return true;
5230  }
5231 
5232 
5239  static function getFirstLettersOfLastnames()
5240  {
5241  global $ilDB;
5242 
5243  $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("lastname", 1, 1))." let".
5244  " FROM usr_data".
5245  " WHERE usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer").
5246  " ORDER BY let";
5247  $let_set = $ilDB->query($q);
5248 
5249  $lets = array();
5250  while ($let_rec = $ilDB->fetchAssoc($let_set))
5251  {
5252  $let[$let_rec["let"]] = $let_rec["let"];
5253  }
5254  return $let;
5255  }
5256 
5257  // begin-patch deleteProgress
5258  public static function userExists($a_usr_ids = array())
5259  {
5260  global $ilDB;
5261 
5262  $query = 'SELECT count(*) num FROM object_data od '.
5263  'JOIN usr_data ud ON obj_id = usr_id '.
5264  'WHERE '.$ilDB->in('obj_id',$a_usr_ids,false,'integer').' ';
5265  $res = $ilDB->query($query);
5266  $num_rows =$res->fetchRow(DB_FETCHMODE_OBJECT)->num;
5267  return $num_rows == count((array) $a_usr_ids);
5268  }
5269  // end-patch deleteProgress
5270 
5275  {
5276  return (boolean) $_SESSION["user_captcha_verified"];
5277  }
5278 
5284  function setCaptchaVerified($a_val)
5285  {
5286  $_SESSION["user_captcha_verified"] = $a_val;
5287  }
5288 
5296  {
5297  include_once("./Services/Export/classes/class.ilExport.php");
5298  $exp = new ilExport();
5299  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5300  ilUtil::delDir($dir, true);
5301  $title = $this->getLastname().", ".$this->getLastname()." [".$this->getLogin()."]";
5302  $exp->exportEntity("personal_data", $this->getId(), "4.3.0",
5303  "Services/User", $title, $dir);
5304  }
5305 
5313  {
5314  include_once("./Services/Export/classes/class.ilExport.php");
5315  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5316  if (!is_dir($dir))
5317  {
5318  return "";
5319  }
5320  foreach(ilUtil::getDir($dir) as $entry)
5321  {
5322  if (is_int(strpos($entry["entry"], ".zip")))
5323  {
5324  return $entry["entry"];
5325  }
5326  }
5327 
5328  return "";
5329  }
5330 
5338  {
5339  include_once("./Services/Export/classes/class.ilExport.php");
5340  $file = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data").
5341  "/".$this->getPersonalDataExportFile();
5342  if (is_file($file))
5343  {
5345  }
5346  }
5347 
5354  function importPersonalData($a_file, $a_profile_data, $a_settings,
5355  $a_bookmarks, $a_notes, $a_calendar)
5356  {
5357  include_once("./Services/Export/classes/class.ilImport.php");
5358  $imp = new ilImport();
5359  if (!$a_profile_data)
5360  {
5361  $imp->addSkipEntity("Services/User", "usr_profile");
5362  }
5363  if (!$a_settings)
5364  {
5365  $imp->addSkipEntity("Services/User", "usr_setting");
5366  }
5367  if (!$a_bookmarks)
5368  {
5369  $imp->addSkipEntity("Services/Bookmarks", "bookmarks");
5370  }
5371  if (!$a_notes)
5372  {
5373  $imp->addSkipEntity("Services/Notes", "user_notes");
5374  }
5375  if (!$a_calendar)
5376  {
5377  $imp->addSkipEntity("Services/Calendar", "calendar");
5378  }
5379  $imp->importEntity($a_file["tmp_name"], $a_file["name"], "personal_data",
5380  "Services/User");
5381  }
5382 
5388  private static function initInactivationDate($usrIds)
5389  {
5390  global $ilDB;
5391 
5392  $NOW = $ilDB->now();
5393 
5394  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5395 
5396  $queryString = "
5397  UPDATE usr_data
5398  SET inactivation_date = $NOW
5399  WHERE inactivation_date IS NULL
5400  AND $usrId_IN_usrIds
5401  ";
5402 
5403  $ilDB->manipulate($queryString);
5404  }
5405 
5411  private static function resetInactivationDate($usrIds)
5412  {
5413  global $ilDB;
5414 
5415  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5416 
5417  $queryString = "
5418  UPDATE usr_data
5419  SET inactivation_date = NULL
5420  WHERE $usrId_IN_usrIds
5421  ";
5422 
5423  $ilDB->manipulate($queryString);
5424  }
5425 
5432  {
5433  $this->inactivation_date = $inactivation_date;
5434  }
5435 
5441  public function getInactivationDate()
5442  {
5443  return $this->inactivation_date;
5444  }
5445 
5449  public function hasToAcceptTermsOfService()
5450  {
5454  global $rbacreview;
5455 
5456  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5457 
5458  if(
5459  ilTermsOfServiceHelper::isEnabled() &&
5460  null == $this->agree_date &&
5461  'root' != $this->agree_date &&
5462  !in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID)) &&
5463  !$rbacreview->isAssigned($this->getId(), SYSTEM_ROLE_ID)
5464  )
5465  {
5466  return true;
5467  }
5468 
5469  return false;
5470  }
5471 
5476  public static function hasUserToAcceptTermsOfService($a_username)
5477  {
5481  global $ilDB;
5482 
5483  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5484 
5485  if(!ilTermsOfServiceHelper::isEnabled())
5486  {
5487  return false;
5488  }
5489 
5490  $in = $ilDB->in('usr_id', array(ANONYMOUS_USER_ID, SYSTEM_USER_ID), true, 'integer');
5491  $res = $ilDB->queryF(
5492  "SELECT usr_id FROM usr_data WHERE login = %s AND agree_date IS NULL $in",
5493  array("text"),
5494  array($a_username)
5495  );
5496  return $ilDB->fetchAssoc($res) ? true : false;
5497  }
5498 
5503  public function hasToAcceptTermsOfServiceInSession($status = null)
5504  {
5505  if(null === $status)
5506  {
5507  return ilSession::get('has_to_accept_agr_in_session');
5508  }
5509 
5510  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5511  if(ilTermsOfServiceHelper::isEnabled())
5512  {
5513  ilSession::set('has_to_accept_agr_in_session', (int)$status);
5514  }
5515  }
5516 
5520  public function isAnonymous()
5521  {
5522  return $this->getId() == ANONYMOUS_USER_ID;
5523  }
5524 
5525  public function activateDeletionFlag()
5526  {
5527  $this->writePref("delete_flag", true);
5528  }
5529 
5530  public function removeDeletionFlag()
5531  {
5532  $this->writePref("delete_flag", false);
5533  }
5534 
5535  public function hasDeletionFlag()
5536  {
5537  return (bool)$this->getPref("delete_flag");
5538  }
5539 
5543  public function setIsSelfRegistered($status)
5544  {
5545  $this->is_self_registered = (bool) $status;
5546  }
5547 
5548  public function isSelfRegistered()
5549  {
5550  return (bool) $this->is_self_registered;
5551  }
5552 
5553 } // END class ilObjUser
5554 ?>
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
getCurrentLanguage()
returns the current language (may differ from user&#39;s pref setting!)
static _lookupName($a_user_id)
lookup user name
Class for user related exception handling in ILIAS.
static _getUserIdsByInactivationPeriod($period)
get ids of all users that have been inactivated since at least the given period
setActive($a_active, $a_owner=0)
set user active state and updates system fields appropriately public
ILIAS Setting Class.
Class UserMail this class handles user mails.
dropDesktopItem($a_item_id, $a_type)
drop an item from user&#39;s personal desktop
print $file
getClipboardObjects($a_type="", $a_top_nodes_only=false)
get all clipboard objects of user and specified type
static $is_desktop_item_loaded
static _getInstance()
get singleton instance
const IL_PASSWD_PLAIN
setInstitution($a_str)
set institution public
refreshLogin()
updates the login data of a "user" // TODO set date with now() should be enough public ...
static initInactivationDate($usrIds)
type $ilDB
Base class for ILIAS Exception handling.
getAuthMode($a_auth_key=false)
get auth mode public
setLatitude($a_latitude)
Set Latitude.
getLogin()
get login / username public
getActive()
get user active state public
const IL_CAL_DATETIME
static _getInstance()
Get instance.
static _deleteUser($a_usr_id)
clipboardDeleteAll()
Delete objects of type for user.
static preloadIsDesktopItem($a_usr_id, $a_item_ids)
Preload desktop item information.
static lookupMatriculation($a_usr_id)
Lookup matriculation.
Class ilUserDefinedData.
getTimeZone()
get timezone of user
setDepartment($a_str)
set department public
$result
_lookupLastLogin($a_user_id)
lookup last login
_getLocalAccountsForEmail($a_email)
check whether external account and authentication method matches with a user
static _deleteSettingsOfUser($a_user)
Delete block settings of user.
_lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
getFirstname()
get firstname public
setSelectedCountry($a_val)
Set selected country (selection drop down)
getLoginByUserId($a_userid)
setLoginAttempts($a_login_attempts)
setCaptchaVerified($a_val)
Set captcha verified.
getMatriculation()
get matriculation number public
setLanguage($a_str)
set user language public
removeUserPicture($a_do_update=true)
Remove user picture.
setFullname($a_title="", $a_firstname="", $a_lastname="")
builds a string with title + firstname + lastname method is used to build fullname in member variable...
getDesktopItems($a_types="")
_moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
skins and styles
Class for user related exception handling in ILIAS.
setLastLogin($a_str)
set user&#39;s last login public
updatePassword($a_old, $a_new1, $a_new2)
updates password
getInactivationDate()
getter for inactivation date
getFax()
get fax public
Class ilObject Basic functions for all objects.
setProfileIncomplete($a_prof_inc)
_lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
Custom block for external feeds on personal desktop.
getDepartment()
get department public
setAuthMode($a_str)
set auth mode public
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static deleteByOwner($a_owner_id)
Delete all entries for owner.
static _incrementLoginAttempts($a_usr_id)
replacePassword($new_md5)
replaces password with new md5 hash
$login
all user related data in single vars public
static get($a_var)
Get a value.
getLocationZoom()
Get Location Zoom.
setId($a_id)
set object id public
static _getExternalAccountsByAuthMode($a_auth_mode, $a_read_auth_default=false)
Get list of external account by authentication method Note: If login == ext_account for two user with...
setDesktopItemParameters($a_item_id, $a_type, $a_par)
set parameters of a desktop item entry
static set($a_var, $a_val)
Set a value.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static resetToDefaults()
reset to defaults
static _getUserIdsByInactivityPeriod($period)
get ids of all users that have been inactive for at least the given period
Import class.
static _getLastHistoryDataByUserId($a_usr_id)
Returns the last used loginname and the changedate of the passed user_id.
static _lookupId($a_user_str)
lookup id by login
getInstitution()
get institution public
setTimeLimitOwner($a_owner)
static setUseRelativeDates($a_status)
set use relative dates
assignData($a_data)
loads a record "user" from array public
static _lookupTitle($a_id)
lookup object title
const IL_PASSWD_CRYPT
static $personal_image_cache
setBirthday($a_birthday)
static _isActive()
Static getter.
static deletePDItemsCache($a_usr_id)
Delete cache (add remove desktop item)
setLastname($a_str)
set lastame public
getCreateDate()
get create date public
Base class for nested set path based trees.
getLongitude()
Get Longitude.
_lookupPref($a_usr_id, $a_keyword)
getPhoneOffice()
get office phone public
static _needsExternalAccountByAuthMode($a_auth_mode)
Check if chosen auth mode needs an external account entry.
const IL_CAL_UNIX
getStreet()
get street public
static userExists($a_usr_ids=array())
static getInstance()
Singelton get instance.
static _lookupGender($a_user_id)
Lookup gender.
setIsSelfRegistered($status)
saveAsNew($a_from_formular=true)
TODO: drop fields last_update & create_date.
getCountry()
Get country (free text)
static _resetLoginAttempts($a_usr_id)
getPref($a_keyword)
get a user preference
static _getAuthModeName($a_auth_key)
static now()
Return current timestamp in Y-m-d H:i:s format.
static _getLoginAttempts($a_usr_id)
static _toggleActiveStatusOfUsers($a_usr_ids, $a_status)
Toggle active status of users.
static lookupTitle($a_page_id)
Lookup title.
_getNumberOfUsersPerAuthMode()
get number of users per auth mode
read()
loads a record "user" from database private
getPublicName()
returns firstname lastname and login if profile is public, login otherwise
deleteUserDefinedFieldEntries()
setCountry($a_str)
Set country (free text)
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
ilObject($a_id=0, $a_reference=true)
Constructor public.
setPhoneHome($a_str)
set home phone public
setDelicious($a_delicious)
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
setTimeLimitUnlimited($a_unlimited)
resetPassword($a_new1, $a_new2)
reset password
Tree handler for personal workspace.
_getImportedUserId($i2_id)
setPref($a_keyword, $a_value)
set a user preference
static _verifyRegistrationHash($a_hash)
Verifies a registration hash.
_lookupFullname($a_user_id)
Lookup Full Name.
_uploadPersonalPicture($tmp_file, $obj_id)
Create a personal picture image file from a temporary image file.
setInactivationDate($inactivation_date)
setter for inactivation date
setZipcode($a_str)
set zipcode public
getUserIdByLogin($a_login)
_getNumberOfUsersForStyle($a_skin, $a_style)
skins and styles
setDiskQuota($a_disk_quota)
Sets the minimal disk quota imposed by this user account.
static _externalAccountExists($a_external_account, $a_auth_mode)
Check if an external account name already exists.
getDateFormat()
get date format
isDesktopItem($a_item_id, $a_type)
check wether an item is on the users desktop or not
addDesktopItem($a_item_id, $a_type, $a_par="")
add an item to user&#39;s personal desktop
setAgreeDate($a_str)
set date the user account was accepted by the user nullindicates that the user has not accepted his a...
_getFeedPass($a_user_id)
Lookup news feed password for user.
static setLanguage($a_lng)
set language
getUserIdByEmail($a_email)
STATIC METHOD get the user_id of an email address.
getAgreeDate()
get the date when the user accepted the user agreement public
static removeForUser($user_id)
Remove all notifications for given user.
static _getInstance()
Get singleton instance of this class.
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
ilObjUser($a_user_id=0, $a_call_by_reference=false)
Constructor public.
setEmail($a_str)
set email public
writeAccepted()
write accept date of user agreement to db
setPasswd($a_str, $a_type=IL_PASSWD_PLAIN)
set password public
static _removeItemFromDesktops($a_id)
removes object from all user&#39;s desktops public
fetchAssoc($a_set)
Fetch row as associative array from result set.
getExternalAccount()
get external account
getCity()
get city public
isChild($a_usr_id)
setTimeLimitUntil($a_until)
getPersonalWorkspaceDiskQuota()
setLogin($a_str)
set login / username public
getZipcode()
get zipcode public
getEmail()
get email address public
static toUsernameWithoutDomain($username)
Static function removes Microsoft domain name from username.
setUserDefinedData($a_data)
static copyProfilePicturesToDirectory($a_user_id, $a_dir)
Get profile picture direcotory.
getLastname()
get lastname public
_checkPassword($a_usr_id, $a_pw)
setOwner($a_owner)
set object owner
Class for single dates.
static execConvert($args)
execute convert command
setExternalAccount($a_str)
set external account
getId()
get object id public
exportPersonalData()
Export personal data.
static getLoginFromAuth()
Gets the username from $ilAuth, and converts it into an ILIAS login name.
setComment($a_str)
set referral comment public
getDiskQuota()
Returns the minimal disk quota imposed by this user account.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
update()
updates a record "user" and write it into database public
static hasActiveSession($a_user_id)
Check for simultaneous login.
static _lookupDescription($a_id)
lookup object description
Mail Box class Base class for creating and handling mail boxes.
static searchUsers($a_search_str, $active=1, $a_return_ids_only=false, $filter_settings=FALSE)
STATIC METHOD get the user_ids which correspond a search string.
clipboardDeleteObjectsOfType($a_type)
Delete objects of type for user.
deletePref($a_keyword)
Deletes a userpref value of the user from the database public.
syncActive()
synchronizes current and stored user active values for the owner value to be set correctly, this function should only be called when an admin is approving a user account public
setHobby($a_str)
set hobby public
setInstantMessengerId($a_im_type, $a_im_id)
setLocationZoom($a_locationzoom)
Set Location Zoom.
setMatriculation($a_str)
set matriculation number public
writePref($a_keyword, $a_value)
write userpref to user table private
setTimeLimitMessage($a_time_limit_message)
static _makeIlias2Password($a_passwd)
get encrypted Ilias 2 password (needed for imported ilias 2 users)
static formatDate(ilDateTime $date)
Format a date public.
_lookupIm($a_user_id, $a_type)
Lookup IM.
isCaptchaVerified()
Is user captcha verified?
getLastLogin()
returns last login date public
static _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user&#39;s personal desktop
clipboardHasObjectsOfType($a_type)
Check whether clipboard has objects of a certain type.
Date and time handling
addObjectToClipboard($a_item_id, $a_type, $a_title, $a_parent=0, $a_time=0, $a_order_nr=0)
add an item to user&#39;s personal clipboard
redirection script todo: (a better solution should control the processing via a xml file) ...
_lookupLogin($a_user_id)
lookup login
static _removeTrackingDataForUser($user_id)
_lookupEmail($a_user_id)
Lookup email.
_setFeedPass($a_user_id, $a_password)
Set news feed password for user.
_lookup($a_user_id, $a_field)
Private function for lookup methods.
static $is_desktop_item_cache
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
setGender($a_str)
set gender public
const AUTH_LOCAL
_getAuthMode($a_auth_mode, $a_db_handler='')
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
writePrefs()
write all userprefs private
static _destroyByUserId($a_user_id)
Destroy session.
sendPersonalDataFile()
Send personal data file.
getUTitle()
get user title (note: don&#39;t mix up this method with getTitle() that is derived from ilObject and gets...
getPersonalPicturePath($a_size="small", $a_force_pic=false)
Get path to personal picture.
const UDF_TYPE_WYSIWYG
static _getAssociatedUsersOnline($a_user_id, $a_no_anonymous=false)
reads all active sessions from db and returns users that are online and who have a local role in a gr...
static deleteEntriesOfUser($a_user_id)
Delete data of user.
_getAllUserData($a_fields=NULL, $active=-1)
STATIC METHOD get all user data.
setTimeLimitFrom($a_from)
static _getUsersForFolder($ref_id, $active)
get users for a category or from system folder
setCity($a_str)
set city public
_lookupActive($a_usr_id)
Check user account active.
getPCClipboardContent()
Add a page content item to PC clipboard (should go to another class)
This is the super class of all custom blocks.
setPhoneOffice($a_str)
set office phone public
setLastPasswordChangeTS($a_last_password_change_ts)
getLatitude()
Get Latitude.
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
getSelectedCountry()
Get selected country (selection drop down)
_writeExternalAccount($a_usr_id, $a_ext_id)
getComment()
get referral comment public
Class ilObjAuthSettingsGUI.
setClientIP($a_str)
set client ip number public
getPersonalDataExportFile()
Get personal data export file.
static _lookupAuthMode($a_usr_id)
lookup auth mode
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user&#39;s personal desktop
static _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
const IL_CAL_DATE
static _setUserInactive($a_usr_id)
getFullname($a_max_strlen=0)
get fullname public
const IL_PASSWD_MD5
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
static _lookupLanguage($a_usr_id)
_deleteAllPref($a_user_id)
Deletes a userpref value of the user from the database public.
setFirstname($a_str)
set firstname public
global $ilUser
Definition: imgupload.php:15
static skinExists($skin)
Check wheter a skin exists.
getPasswdType()
get password type
static _getUsersForGroup($a_mem_ids, $active=-1)
return user data for group members
removeObjectFromClipboard($a_item_id, $a_type)
remove object from user&#39;s personal clipboard
bookmark folder (note: this class handles personal bookmarks folders only)
_getAllUserLogins(&$ilias)
STATIC METHOD get all user logins.
_writeAuthMode($a_usr_id, $a_auth_mode)
global $ilSetting
Definition: privfeed.php:40
static resetInactivationDate($usrIds)
type $ilDB
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
static getInstance()
Singelton get instance.
getTimeFormat()
get time format
static _generateRegistrationHash($a_usr_id)
Generates a unique hashcode for activating a user profile after registration.
getPasswd()
get password
static _getPersonalPicturePath($a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
static getFirstLettersOfLastnames()
Get first letters of all lastnames.
setFax($a_str)
set fax public
getPhoneHome()
get home phone public
static _getUsersForIds($a_mem_ids, $active=-1, $timelimitowner=-1)
return user data for given user id
getHobby()
get hobby public
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static _updateLastLogin($a_usr_id, $a_last_login=null)
STATIC METHOD updates the last_login field of user with given id to given or current date...
getGender()
get gender public
getInstantMessengerId($a_im_type)
const USER_FOLDER_ID
Class ilObjUserFolder.
setLastPasswordChangeToNow()
setUTitle($a_str)
set user title (note: don&#39;t mix up this method with setTitle() that is derived from ilObject and sets...
setSkin($a_str)
set user skin (template set) public
setApproveDate($a_str)
set date the user account was activated null indicates that the user has not yet been activated publ...
getStoredActive($a_id)
get user active state
getClipboardChilds($a_parent, $a_insert_time)
Get childs of an item.
getApproveDate()
get the date when the user account was approved public
setStreet($a_str)
set street public
static _getUsersForRole($role_id, $active=-1)
return array of complete users which belong to a specific role
_getAllUserAssignedStyles()
skins and styles
setPhoneMobile($a_str)
set mobile phone public
Class for user related exception handling in ILIAS.
_getUsersForClipboadObject($a_type, $a_id)
get all users, that have a certain object within their clipboard
getClientIP()
get client ip number public
setLastUpdate($a_str)
set last update of user data set public
static _getPreferences($user_id)
get preferences for user
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getWebspaceDir($mode="filesystem")
get webspace directory
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
getLanguage()
returns a 2char-language-string public
static _getInstance()
Get instance of ilSecuritySettings.
static _getUserData($a_internalids)
return user data for given user ids
static deleteUserPortfolios($a_user_id)
Delete all portfolio data for user.
hasToAcceptTermsOfServiceInSession($status=null)
static _writeHistory($a_usr_id, $a_login)
setCurrentLanguage($a_val)
Set current language.
hasPublicProfile()
returns true if public is profile, false otherwise
static _doesLoginnameExistInHistory($a_login)
Checks wether the passed loginname already exists in history.
_lookupFeedHash($a_user_id, $a_create=false)
Lookup news feed hash for user.
addToPCClipboard($a_content, $a_time, $a_nr)
Add a page content item to PC clipboard (should go to another class)
updateLogin($a_login)
update login name
importPersonalData($a_file, $a_profile_data, $a_settings, $a_bookmarks, $a_notes, $a_calendar)
Import personal data.
_lookupClientIP($a_user_id)
Lookup client ip.
setLongitude($a_longitude)
Set Longitude.
static _isDesktopItem($a_usr_id, $a_item_id, $a_type)
check wether an item is on the users desktop or not
_getUserIdsByEmail($a_email)
STATIC METHOD get all user_ids of an email address.
__readAppliedUsers($a_parent_id)
_deleteUser($a_usr_id)
readPrefs()
get all user preferences private
getPhoneMobile()
get mobile phone public
$r