ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups 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 "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 
132 
138  function ilObjUser($a_user_id = 0, $a_call_by_reference = false)
139  {
140  global $ilias,$ilDB;
141 
142  // init variables
143  $this->ilias =& $ilias;
144  $this->db =& $ilDB;
145 
146  $this->type = "usr";
147  $this->ilObject($a_user_id, $a_call_by_reference);
148  $this->auth_mode = "default";
149  $this->passwd_type = IL_PASSWD_PLAIN;
150 
151  // for gender selection. don't change this
152  /*$this->gender = array(
153  'm' => "salutation_m",
154  'f' => "salutation_f"
155  );*/
156  if ($a_user_id > 0)
157  {
158  $this->setId($a_user_id);
159  $this->read();
160  }
161  else
162  {
163  // TODO: all code in else-structure doesn't belongs in class user !!!
164  //load default data
165  $this->prefs = array();
166  //language
167  $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
168 
169  //skin and pda support
170  $this->skin = $this->ilias->ini->readVariable("layout","skin");
171 
172  $this->prefs["skin"] = $this->skin;
173  $this->prefs["show_users_online"] = "y";
174 
175  //style (css)
176  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
177  }
178  }
179 
184  function read()
185  {
186  global $ilErr, $ilDB;
187 
188  // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
189  // use (3.11.0 alpha)
190  /*$q = "SELECT * FROM usr_data ".
191  "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
192  "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
193  $r = $ilDB->queryF("SELECT * FROM usr_data ".
194  "WHERE usr_id= %s", array("integer"), array($this->id));
195 
196  if ($data = $ilDB->fetchAssoc($r))
197  {
198  // convert password storage layout used by table usr_data into
199  // storage layout used by class ilObjUser
200  if ($data["passwd"] == "" && $data["i2passwd"] != "")
201  {
202  $data["passwd_type"] = IL_PASSWD_CRYPT;
203  $data["passwd"] = $data["i2passwd"];
204  }
205  else
206  {
207  $data["passwd_type"] = IL_PASSWD_MD5;
208  //$data["passwd"] = $data["passwd"]; (implicit)
209  }
210  unset($data["i2passw"]);
211 
212  // this assign must not be set via $this->assignData($data)
213  // because this method will be called on profile updates and
214  // would set this values to 0, because they arent posted from form
215  $this->setLastPasswordChangeTS( $data['last_password_change'] );
216  $this->setLoginAttempts( $data['login_attempts'] );
217 
218 
219  // fill member vars in one shot
220  $this->assignData($data);
221 
222  //get userpreferences from usr_pref table
223  $this->readPrefs();
224 
225  //set language to default if not set
226  if ($this->prefs["language"] == "")
227  {
228  $this->prefs["language"] = $this->oldPrefs["language"];
229  }
230 
231  //check skin-setting
232  include_once("./Services/Style/classes/class.ilStyleDefinition.php");
233  if ($this->prefs["skin"] == "" ||
234  !ilStyleDefinition::skinExists($this->prefs["skin"]))
235  {
236  $this->prefs["skin"] = $this->oldPrefs["skin"];
237  }
238 
239  $this->skin = $this->prefs["skin"];
240 
241  //check style-setting (skins could have more than one stylesheet
242  if ($this->prefs["style"] == "" ||
243  !ilStyleDefinition::skinExists($this->skin, $this->prefs["style"]))
244  {
245  //load default (css)
246  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
247  }
248 
249  if (empty($this->prefs["hits_per_page"]))
250  {
251  $this->prefs["hits_per_page"] = 10;
252  }
253 
254  }
255  else
256  {
257  $ilErr->raiseError("<b>Error: There is no dataset with id ".
258  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
259  "<br />Line: ".__LINE__, $ilErr->FATAL);
260  }
261 
262  $this->readUserDefinedFields();
263 
264  parent::read();
265  }
266 
272  function assignData($a_data)
273  {
274  global $ilErr, $ilDB, $lng;
275 
276  // basic personal data
277  $this->setLogin($a_data["login"]);
278  if (! $a_data["passwd_type"])
279  {
280  $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
281  $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
282  .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
283  }
284  if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
285  {
286  $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
287  }
288 
289  $this->setGender($a_data["gender"]);
290  $this->setUTitle($a_data["title"]);
291  $this->setFirstname($a_data["firstname"]);
292  $this->setLastname($a_data["lastname"]);
293  $this->setFullname();
294  if (!is_array($a_data['birthday']))
295  {
296  $this->setBirthday($a_data['birthday']);
297  }
298  else
299  {
300  $this->setBirthday(null);
301  }
302 
303  // address data
304  $this->setInstitution($a_data["institution"]);
305  $this->setDepartment($a_data["department"]);
306  $this->setStreet($a_data["street"]);
307  $this->setCity($a_data["city"]);
308  $this->setZipcode($a_data["zipcode"]);
309  $this->setCountry($a_data["country"]);
310  $this->setSelectedCountry($a_data["sel_country"]);
311  $this->setPhoneOffice($a_data["phone_office"]);
312  $this->setPhoneHome($a_data["phone_home"]);
313  $this->setPhoneMobile($a_data["phone_mobile"]);
314  $this->setFax($a_data["fax"]);
315  $this->setMatriculation($a_data["matriculation"]);
316  $this->setEmail($a_data["email"]);
317  $this->setHobby($a_data["hobby"]);
318  $this->setClientIP($a_data["client_ip"]);
319 
320  // instant messenger data
321  $this->setInstantMessengerId('icq',$a_data["im_icq"]);
322  $this->setInstantMessengerId('yahoo',$a_data["im_yahoo"]);
323  $this->setInstantMessengerId('msn',$a_data["im_msn"]);
324  $this->setInstantMessengerId('aim',$a_data["im_aim"]);
325  $this->setInstantMessengerId('skype',$a_data["im_skype"]);
326  $this->setInstantMessengerId('jabber',$a_data["im_jabber"]);
327  $this->setInstantMessengerId('voip',$a_data["im_voip"]);
328 
329  // other data
330  $this->setDelicious($a_data["delicious"]);
331  $this->setLatitude($a_data["latitude"]);
332  $this->setLongitude($a_data["longitude"]);
333  $this->setLocationZoom($a_data["loc_zoom"]);
334 
335  // system data
336  $this->setLastLogin($a_data["last_login"]);
337  $this->setLastUpdate($a_data["last_update"]);
338  $this->create_date = $a_data["create_date"];
339  $this->setComment($a_data["referral_comment"]);
340  $this->approve_date = $a_data["approve_date"];
341  $this->active = $a_data["active"];
342  $this->agree_date = $a_data["agree_date"];
343 
344  // time limitation
345  $this->setTimeLimitOwner($a_data["time_limit_owner"]);
346  $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
347  $this->setTimeLimitFrom($a_data["time_limit_from"]);
348  $this->setTimeLimitUntil($a_data["time_limit_until"]);
349  $this->setTimeLimitMessage($a_data['time_limit_message']);
350 
351  // user profile incomplete?
352  $this->setProfileIncomplete($a_data["profile_incomplete"]);
353 
354  //iLinc
355  //$this->setiLincData($a_data['ilinc_id'],$a_data['ilinc_login'],$a_data['ilinc_passwd']);
356 
357  //authentication
358  $this->setAuthMode($a_data['auth_mode']);
359  $this->setExternalAccount($a_data['ext_account']);
360  }
361 
368  function saveAsNew($a_from_formular = true)
369  {
370  global $ilErr, $ilDB, $ilSetting, $ilUser;
371 
372  switch ($this->passwd_type)
373  {
374  case IL_PASSWD_PLAIN:
375  $pw_field = "passwd";
376  if(strlen($this->passwd))
377  {
378  $pw_value = md5($this->passwd);
379  }
380  else
381  {
382  $pw_value = $this->passwd;
383  }
384  break;
385 
386  case IL_PASSWD_MD5:
387  $pw_field = "passwd";
388  $pw_value = $this->passwd;
389  break;
390 
391  case IL_PASSWD_CRYPT:
392  $pw_field = "i2passwd";
393  $pw_value = $this->passwd;
394  break;
395 
396  default :
397  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
398  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
399  "<br />Line: ".__LINE__, $ilErr->FATAL);
400  }
401 
402  $insert_array = array(
403  "usr_id" => array("integer", $this->id),
404  "login" => array("text", $this->login),
405  $pw_field => array("text", $pw_value),
406  "firstname" => array("text", $this->firstname),
407  "lastname" => array("text", $this->lastname),
408  "title" => array("text", $this->utitle),
409  "gender" => array("text", $this->gender),
410  "email" => array("text", trim($this->email)),
411  "hobby" => array("text", (string) $this->hobby),
412  "institution" => array("text", $this->institution),
413  "department" => array("text", $this->department),
414  "street" => array("text", $this->street),
415  "city" => array("text", $this->city),
416  "zipcode" => array("text", $this->zipcode),
417  "country" => array("text", $this->country),
418  "sel_country" => array("text", $this->sel_country),
419  "phone_office" => array("text", $this->phone_office),
420  "phone_home" => array("text", $this->phone_home),
421  "phone_mobile" => array("text", $this->phone_mobile),
422  "fax" => array("text", $this->fax),
423  "birthday" => array('date', $this->getBirthday()),
424  "last_login" => array("timestamp", null),
425  "last_update" => array("timestamp", ilUtil::now()),
426  "create_date" => array("timestamp", ilUtil::now()),
427  "referral_comment" => array("text", $this->referral_comment),
428  "matriculation" => array("text", $this->matriculation),
429  "client_ip" => array("text", $this->client_ip),
430  "approve_date" => array("timestamp", $this->approve_date),
431  "agree_date" => array("timestamp", $this->agree_date),
432  "active" => array("integer", (int) $this->active),
433  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
434  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
435  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
436  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
437  "auth_mode" => array("text", $this->getAuthMode()),
438  "ext_account" => array("text", $this->getExternalAccount()),
439  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
440  "im_icq" => array("text", $this->im_icq),
441  "im_yahoo" => array("text", $this->im_yahoo),
442  "im_msn" => array("text", $this->im_msn),
443  "im_aim" => array("text", $this->im_aim),
444  "im_skype" => array("text", $this->im_skype),
445  "delicious" => array("text", $this->delicious),
446  "latitude" => array("text", $this->latitude),
447  "longitude" => array("text", $this->longitude),
448  "loc_zoom" => array("integer", (int) $this->loc_zoom),
449  "last_password_change" => array("integer", (int) $this->last_password_change_ts),
450  "im_jabber" => array("text", $this->im_jabber),
451  "im_voip" => array("text", $this->im_voip)
452  );
453  $ilDB->insert("usr_data", $insert_array);
454 
455  // add new entry in usr_defined_data
456  $this->addUserDefinedFieldEntry();
457  // ... and update
458  $this->updateUserDefinedFields();
459 
460  // CREATE ENTRIES FOR MAIL BOX
461  include_once ("Services/Mail/classes/class.ilMailbox.php");
462  $mbox = new ilMailbox($this->id);
463  $mbox->createDefaultFolder();
464 
465  include_once "Services/Mail/classes/class.ilMailOptions.php";
466  $mail_options = new ilMailOptions($this->id);
467  $mail_options->createMailOptionsEntry();
468 
469  // create personal bookmark folder tree
470  include_once "./Services/PersonalDesktop/classes/class.ilBookmarkFolder.php";
471  $bmf = new ilBookmarkFolder(0, $this->id);
472  $bmf->createNewBookmarkTree();
473 
474  }
475 
480  function update()
481  {
482  global $ilErr, $ilDB, $ilAppEventHandler;
483 
484  $this->syncActive();
485 
486  $update_array = array(
487  "gender" => array("text", $this->gender),
488  "title" => array("text", $this->utitle),
489  "firstname" => array("text", $this->firstname),
490  "lastname" => array("text", $this->lastname),
491  "email" => array("text", trim($this->email)),
492  "birthday" => array('date', $this->getBirthday()),
493  "hobby" => array("text", $this->hobby),
494  "institution" => array("text", $this->institution),
495  "department" => array("text", $this->department),
496  "street" => array("text", $this->street),
497  "city" => array("text", $this->city),
498  "zipcode" => array("text", $this->zipcode),
499  "country" => array("text", $this->country),
500  "sel_country" => array("text", $this->sel_country),
501  "phone_office" => array("text", $this->phone_office),
502  "phone_home" => array("text", $this->phone_home),
503  "phone_mobile" => array("text", $this->phone_mobile),
504  "fax" => array("text", $this->fax),
505  "referral_comment" => array("text", $this->referral_comment),
506  "matriculation" => array("text", $this->matriculation),
507  "client_ip" => array("text", $this->client_ip),
508  "approve_date" => array("timestamp", $this->approve_date),
509  "active" => array("integer", $this->active),
510  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
511  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
512  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
513  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
514  "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
515  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
516  "auth_mode" => array("text", $this->getAuthMode()),
517  "ext_account" => array("text", $this->getExternalAccount()),
518  "im_icq" => array("text", $this->im_icq),
519  "im_yahoo" => array("text", $this->im_yahoo),
520  "im_msn" => array("text", $this->im_msn),
521  "im_aim" => array("text", $this->im_aim),
522  "im_skype" => array("text", $this->im_skype),
523  "delicious" => array("text", $this->delicious),
524  "latitude" => array("text", $this->latitude),
525  "longitude" => array("text", $this->longitude),
526  "loc_zoom" => array("integer", (int) $this->loc_zoom),
527  "last_password_change" => array("integer", $this->last_password_change_ts),
528  "im_jabber" => array("text", $this->im_jabber),
529  "im_voip" => array("text", $this->im_voip),
530  "last_update" => array("timestamp", ilUtil::now())
531  );
532 
533  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null))
534  {
535  $update_array["agree_date"] = array("timestamp", $this->agree_date);
536  }
537  switch ($this->passwd_type)
538  {
539  case IL_PASSWD_PLAIN:
540  if(strlen($this->passwd))
541  {
542  $update_array["i2passwd"] = array("text", (string) "");
543  $update_array["passwd"] = array("text", (string) md5($this->passwd));
544  }
545  else
546  {
547  $update_array["i2passwd"] = array("text", (string) "");
548  $update_array["passwd"] = array("text", (string) $this->passwd);
549  }
550  break;
551 
552  case IL_PASSWD_MD5:
553  $update_array["i2passwd"] = array("text", (string) "");
554  $update_array["passwd"] = array("text", (string) $this->passwd);
555  break;
556 
557  case IL_PASSWD_CRYPT:
558  $update_array["i2passwd"] = array("text", (string) $this->passwd);
559  $update_array["passwd"] = array("text", (string) "");
560  break;
561 
562  default :
563  $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
564  get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
565  }
566 
567  $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
568 
569  $this->writePrefs();
570 
571  // update user defined fields
572  $this->updateUserDefinedFields();
573 
574  parent::update();
576 
577  $this->read();
578 
579  $ilAppEventHandler->raise("Services/User", "afterUpdate",
580  array("user_obj" => $this));
581 
582  return true;
583  }
584 
588  function writeAccepted()
589  {
590  global $ilDB;
591 
592  $ilDB->manipulateF("UPDATE usr_data SET agree_date = ".$ilDB->now().
593  " WHERE usr_id = %s", array("integer"), array($this->getId()));
594  }
595 
599  private function _lookup($a_user_id, $a_field)
600  {
601  global $ilDB;
602 
603  $res = $ilDB->queryF("SELECT ".$a_field." FROM usr_data WHERE usr_id = %s",
604  array("integer"), array($a_user_id));
605 
606  while($set = $ilDB->fetchAssoc($res))
607  {
608  return $set[$a_field];
609  }
610  return false;
611  }
612 
616  function _lookupFullname($a_user_id)
617  {
618  global $ilDB;
619 
620  $set = $ilDB->queryF("SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
621  array("integer"), array($a_user_id));
622 
623  if ($rec = $ilDB->fetchAssoc($set))
624  {
625  if ($rec["title"])
626  {
627  $fullname = $rec["title"]." ";
628  }
629  if ($rec["firstname"])
630  {
631  $fullname .= $rec["firstname"]." ";
632  }
633  if ($rec["lastname"])
634  {
635  $fullname .= $rec["lastname"];
636  }
637  }
638  return $fullname;
639  }
640 
644  function _lookupIm($a_user_id, $a_type)
645  {
646  return ilObjUser::_lookup($a_user_id, "im_".$a_type);
647  }
648 
649 
653  function _lookupEmail($a_user_id)
654  {
655  return ilObjUser::_lookup($a_user_id, "email");
656  }
657 
661  public static function _lookupGender($a_user_id)
662  {
663  return ilObjUser::_lookup($a_user_id, "gender");
664  }
665 
672  function _lookupClientIP($a_user_id)
673  {
674  return ilObjUser::_lookup($a_user_id, "client_ip");
675  }
676 
677 
683  public static function _lookupName($a_user_id)
684  {
685  global $ilDB;
686 
687  $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
688  array("integer"), array($a_user_id));
689  $user_rec = $ilDB->fetchAssoc($res);
690  return array("user_id" => $a_user_id,
691  "firstname" => $user_rec["firstname"],
692  "lastname" => $user_rec["lastname"],
693  "title" => $user_rec["title"],
694  "login" => $user_rec["login"]);
695  }
696 
700  function _lookupFields($a_user_id)
701  {
702  global $ilDB;
703 
704  $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
705  array("integer"), array($a_user_id));
706  $user_rec = $ilDB->fetchAssoc($res);
707  return $user_rec;
708  }
709 
713  function _lookupLogin($a_user_id)
714  {
715  return ilObjUser::_lookup($a_user_id, "login");
716  }
717 
721  function _lookupExternalAccount($a_user_id)
722  {
723  return ilObjUser::_lookup($a_user_id, "ext_account");
724  }
725 
729  public static function _lookupId($a_user_str)
730  {
731  global $ilDB;
732 
733  $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
734  array("text"), array($a_user_str));
735  $user_rec = $ilDB->fetchAssoc($res);
736  return $user_rec["usr_id"];
737  }
738 
742  function _lookupLastLogin($a_user_id)
743  {
744  return ilObjUser::_lookup($a_user_id, "last_login");
745  }
746 
747 
753  function refreshLogin()
754  {
755  global $ilDB;
756 
757  $ilDB->manipulateF("UPDATE usr_data SET ".
758  "last_login = ".$ilDB->now().
759  " WHERE usr_id = %s",
760  array("integer"), array($this->id));
761  }
762 
769  function replacePassword($new_md5)
770  {
771  global $ilDB;
772 
773  $this->passwd_type = IL_PASSWD_MD5;
774  $this->passwd = $new_md5;
775 
776  $ilDB->manipulateF("UPDATE usr_data SET ".
777  "passwd = %s ".
778  "WHERE usr_id = %s",
779  array("text", "integer"), array($this->passwd, $this->id));
780 
781  return true;
782  }
783 
792  function updatePassword($a_old, $a_new1, $a_new2)
793  {
794  global $ilDB;
795 
796  if (func_num_args() != 3)
797  {
798  return false;
799  }
800 
801  if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
802  {
803  return false;
804  }
805 
806  if ($a_new1 != $a_new2)
807  {
808  return false;
809  }
810 
811  // is catched by isset() ???
812  if ($a_new1 == "" || $a_old == "")
813  {
814  return false;
815  }
816 
817  //check old password
818  switch ($this->passwd_type)
819  {
820  case IL_PASSWD_PLAIN:
821  if ($a_old != $this->passwd)
822  {
823  return false;
824  }
825  break;
826 
827  case IL_PASSWD_MD5:
828  if (md5($a_old) != $this->passwd)
829  {
830  return false;
831  }
832  break;
833 
834  case IL_PASSWD_CRYPT:
835  if (_makeIlias2Password($a_old) != $this->passwd)
836  {
837  return false;
838  }
839  break;
840  }
841 
842  //update password
843  $this->passwd = md5($a_new1);
844  $this->passwd_type = IL_PASSWD_MD5;
845 
846  $ilDB->manipulateF("UPDATE usr_data SET ".
847  "passwd = %s ".
848  "WHERE usr_id = %s",
849  array("text", "integer"), array($this->passwd, $this->id));
850 
851  return true;
852  }
853 
861  function resetPassword($a_new1, $a_new2)
862  {
863  global $ilDB;
864 
865  if (func_num_args() != 2)
866  {
867  return false;
868  }
869 
870  if (!isset($a_new1) or !isset($a_new2))
871  {
872  return false;
873  }
874 
875  if ($a_new1 != $a_new2)
876  {
877  return false;
878  }
879 
880  //update password
881  $this->passwd = md5($a_new1);
882  $this->passwd_type = IL_PASSWD_MD5;
883 
884  $ilDB->manipulateF("UPDATE usr_data SET ".
885  "passwd = %s ".
886  "WHERE usr_id = %s",
887  array("text", "integer"),
888  array($this->passwd, $this->id));
889 
890  return true;
891  }
892 
896  function _makeIlias2Password($a_passwd)
897  {
898  return (crypt($a_passwd,substr($a_passwd,0,2)));
899  }
900 
904  function _lookupHasIlias2Password($a_user_login)
905  {
906  global $ilias, $ilDB;
907 
908  $user_set = $ilDB->queryF("SELECT i2passwd FROM usr_data ".
909  "WHERE login = %s", array("text"), array($a_user_login));
910  if ($user_rec = $ilDB->fetchAssoc($user_set))
911  {
912  if ($user_rec["i2passwd"] != "")
913  {
914  return true;
915  }
916  }
917 
918  return false;
919  }
920 
924  function _switchToIlias3Password($a_user, $a_pw)
925  {
926  global $ilias, $ilDB;
927 
928  $user_set = $ilDB->queryF("SELECT i2passwd FROM usr_data ".
929  "WHERE login = %s", array("text"), array($a_user_login));
930  if ($user_rec = $ilDB->fetchAssoc($user_set))
931  {
932  if ($user_rec["i2passwd"] == ilObjUser::_makeIlias2Password($a_pw))
933  {
934  $ilDB->manipulateF("UPDATE usr_data SET passwd = %s, i2passwd = %s".
935  "WHERE login = %s",
936  array("text", "text", "text"),
937  array(md5($a_pw), "", $a_user));
938  return true;
939  }
940  }
941 
942  return false;
943  }
944 
955  public static function _doesLoginnameExistInHistory($a_login)
956  {
957  global $ilDB;
958 
959  $res = $ilDB->queryF('
960  SELECT * FROM loginname_history
961  WHERE login = %s',
962  array('text'), array($a_login));
963 
964  return $ilDB->fetchAssoc($res) ? true : false;
965  }
966 
979  public static function _getLastHistoryDataByUserId($a_usr_id)
980  {
981  global $ilDB;
982 
983  $ilDB->setLimit(1, 0);
984  $res = $ilDB->queryF('
985  SELECT login, history_date FROM loginname_history
986  WHERE usr_id = %s ORDER BY history_date DESC',
987  array('integer'), array($a_usr_id));
988  $row = $ilDB->fetchAssoc($res);
989  if(!is_array($row) || !count($row)) throw new ilUserException('');
990 
991  return array(
992  $row['login'], $row['history_date']
993  );
994  }
995 
1003  function updateLogin($a_login)
1004  {
1005  global $ilDB, $ilSetting;
1006 
1007  if(func_num_args() != 1)
1008  {
1009  return false;
1010  }
1011 
1012  if(!isset($a_login))
1013  {
1014  return false;
1015  }
1016 
1017  // Update not necessary
1018  if($a_login == self::_lookupLogin($this->getId()))
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('prevent_reuse_of_loginnames') &&
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(), self::_lookupLogin($this->getId()));
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 
1071  return true;
1072  }
1073 
1080  function writePref($a_keyword, $a_value)
1081  {
1082  ilObjUser::_writePref($this->id, $a_keyword, $a_value);
1083  $this->setPref($a_keyword, $a_value);
1084  }
1085 
1086 
1092  function deletePref($a_keyword)
1093  {
1094  ilObjUser::_deletePref($this->getId(), $a_keyword);
1095  }
1096 
1102  function _deletePref($a_user_id, $a_keyword)
1103  {
1104  global $ilDB;
1105 
1106  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s",
1107  array("integer", "text"), array($a_user_id, $a_keyword));
1108  }
1109 
1115  function _deleteAllPref($a_user_id)
1116  {
1117  global $ilDB;
1118 
1119  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1120  array("integer"), array($a_user_id));
1121  }
1122 
1126  function _writePref($a_usr_id, $a_keyword, $a_value)
1127  {
1128  global $ilDB;
1129 
1130  ilObjUser::_deletePref($a_usr_id, $a_keyword);
1131  if (strlen($a_value))
1132  {
1133  $ilDB->manipulateF("INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s,%s,%s)",
1134  array("integer", "text", "text"), array($a_usr_id, $a_keyword, $a_value));
1135  }
1136  }
1137 
1142  function writePrefs()
1143  {
1144  global $ilDB;
1145 
1146  ilObjUser::_deleteAllPref($this->id);
1147  foreach ($this->prefs as $keyword => $value)
1148  {
1149  ilObjUser::_writePref($this->id, $keyword, $value);
1150  }
1151  }
1152 
1159  public function getTimeZone()
1160  {
1161  if($tz = $this->getPref('user_tz'))
1162  {
1163  return $tz;
1164  }
1165  else
1166  {
1167  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1168  $settings = ilCalendarSettings::_getInstance();
1169  return $settings->getDefaultTimeZone();
1170  }
1171  }
1172 
1179  public function getTimeFormat()
1180  {
1181  if($format = $this->getPref('time_format'))
1182  {
1183  return $format;
1184  }
1185  else
1186  {
1187  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1188  $settings = ilCalendarSettings::_getInstance();
1189  return $settings->getDefaultTimeFormat();
1190  }
1191  }
1192 
1199  public function getDateFormat()
1200  {
1201  if($format = $this->getPref('date_format'))
1202  {
1203  return $format;
1204  }
1205  else
1206  {
1207  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1208  $settings = ilCalendarSettings::_getInstance();
1209  return $settings->getDefaultDateFormat();
1210  }
1211  }
1212 
1219  function setPref($a_keyword, $a_value)
1220  {
1221  if ($a_keyword != "")
1222  {
1223  $this->prefs[$a_keyword] = $a_value;
1224  }
1225  }
1226 
1232  function getPref($a_keyword)
1233  {
1234  if (array_key_exists($a_keyword, $this->prefs))
1235  {
1236  return $this->prefs[$a_keyword];
1237  }
1238  else
1239  {
1240  return FALSE;
1241  }
1242  }
1243 
1244  function _lookupPref($a_usr_id,$a_keyword)
1245  {
1246  global $ilDB;
1247 
1248  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1249  "AND keyword = ".$ilDB->quote($a_keyword, "text");
1250  $res = $ilDB->query($query);
1251 
1252  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1253  {
1254  return $row->value;
1255  }
1256  return false;
1257  }
1258 
1263  function readPrefs()
1264  {
1265  global $ilDB;
1266 
1267  if (is_array($this->prefs))
1268  {
1269  $this->oldPrefs = $this->prefs;
1270  }
1271 
1272  $this->prefs = ilObjUser::_getPreferences($this->id);
1273  }
1274 
1280  function delete()
1281  {
1282  global $rbacadmin, $ilDB;
1283 
1284  // deassign from ldap groups
1285  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1287  $mapping->deleteUser($this->getId());
1288 
1289  // remove mailbox / update sent mails
1290  include_once ("Services/Mail/classes/class.ilMailbox.php");
1291  $mailbox = new ilMailbox($this->getId());
1292  $mailbox->delete();
1293  $mailbox->updateMailsOfDeletedUser($this->getLogin());
1294 
1295  // delete feed blocks on personal desktop
1296  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1297  $costum_block = new ilCustomBlock();
1298  $costum_block->setContextObjId($this->getId());
1299  $costum_block->setContextObjType("user");
1300  $c_blocks = $costum_block->queryBlocksForContext();
1301  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1302  foreach($c_blocks as $c_block)
1303  {
1304  if ($c_block["type"] == "pdfeed")
1305  {
1306  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1307  $fb->delete();
1308  }
1309  }
1310 
1311 
1312  // delete block settings
1313  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1315 
1316  // delete user_account
1317  $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1318  array("integer"), array($this->getId()));
1319 
1320  // delete user_prefs
1321  ilObjUser::_deleteAllPref($this->getId());
1322 
1323  $this->removeUserPicture(false); // #8597
1324 
1325  // delete user_session
1326  include_once("./Services/Authentication/classes/class.ilSession.php");
1328 
1329  // remove user from rbac
1330  $rbacadmin->removeUser($this->getId());
1331 
1332  // remove bookmarks
1333  // TODO: move this to class.ilBookmarkFolder
1334  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1335  $ilDB->quote($this->getId(), "integer");
1336  $ilDB->manipulate($q);
1337 
1338  $q = "DELETE FROM bookmark_data WHERE user_id = ".
1339  $ilDB->quote($this->getId(), "integer");
1340  $ilDB->manipulate($q);
1341 
1342  // DELETE FORUM ENTRIES (not complete in the moment)
1343  include_once './Modules/Forum/classes/class.ilObjForum.php';
1344  ilObjForum::_deleteUser($this->getId());
1345 
1346  // Delete link check notify entries
1347  include_once './classes/class.ilLinkCheckNotify.php';
1349 
1350  // Delete crs entries
1351  include_once './Modules/Course/classes/class.ilObjCourse.php';
1352  ilObjCourse::_deleteUser($this->getId());
1353 
1354  // Delete user tracking
1355  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1357 
1358  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1360 
1361  // Delete Tracking data SCORM 2004 RTE
1362  include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1364 
1365  // Delete Tracking data SCORM 1.2 RTE
1366  include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1368 
1369  // remove all notifications
1370  include_once "./Services/Notification/classes/class.ilNotification.php";
1372 
1373  // remove portfolios
1374  include_once "./Services/Portfolio/classes/class.ilObjPortfolio.php";
1376 
1377  // remove workspace
1378  include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1379  $tree = new ilWorkspaceTree($this->getId());
1380  $tree->cascadingDelete();
1381 
1382  // Delete user defined field entries
1384 
1385  // Delete clipboard entries
1386  $this->clipboardDeleteAll();
1387 
1388  // Reset owner
1389  $this->resetOwner();
1390 
1391 
1392  // Trigger deleteUser Event
1393  global $ilAppEventHandler;
1394  $ilAppEventHandler->raise(
1395  'Services/User', 'deleteUser', array('usr_id' => $this->getId())
1396  );
1397 
1398  // delete object data
1399  parent::delete();
1400  return true;
1401  }
1402 
1412  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1413  {
1414  $this->fullname = "";
1415 
1416  if ($a_title)
1417  {
1418  $fullname = $a_title." ";
1419  }
1420  elseif ($this->utitle)
1421  {
1422  $this->fullname = $this->utitle." ";
1423  }
1424 
1425  if ($a_firstname)
1426  {
1427  $fullname .= $a_firstname." ";
1428  }
1429  elseif ($this->firstname)
1430  {
1431  $this->fullname .= $this->firstname." ";
1432  }
1433 
1434  if ($a_lastname)
1435  {
1436  return $fullname.$a_lastname;
1437  }
1438 
1439  $this->fullname .= $this->lastname;
1440  }
1441 
1456  function getFullname($a_max_strlen = 0)
1457  {
1458  if (!$a_max_strlen)
1459  {
1460  return ilUtil::stripSlashes($this->fullname);
1461  }
1462 
1463  if (strlen($this->fullname) <= $a_max_strlen)
1464  {
1465  return ilUtil::stripSlashes($this->fullname);
1466  }
1467 
1468  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1469  {
1470  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1471  }
1472 
1473  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1474  {
1475  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1476  }
1477 
1478  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1479  {
1480  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1481  }
1482 
1483  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1484  }
1485 
1494  public static function _hasAcceptedAgreement($a_username)
1495  {
1496  global $ilDB;
1497 
1498  if($a_username == 'root')
1499  {
1500  return true;
1501  }
1502 
1503  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
1504  "WHERE login = %s AND NOT agree_date IS NULL",
1505  array("text"), array($a_username));
1506  return $ilDB->fetchAssoc($res) ? true : false;
1507  }
1508 
1509 
1514  {
1515  if ($this->agree_date != null || $this->login == "root")
1516  {
1517  return true;
1518  }
1519  return false;
1520  }
1521 
1527  function setLogin($a_str)
1528  {
1529  $this->login = $a_str;
1530  }
1531 
1536  function getLogin()
1537  {
1538  return $this->login;
1539  }
1540 
1546  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1547  {
1548  $this->passwd = $a_str;
1549  $this->passwd_type = $a_type;
1550  }
1551 
1559  function getPasswd()
1560  {
1561  return $this->passwd;
1562  }
1569  function getPasswdType()
1570  {
1571  return $this->passwd_type;
1572  }
1573 
1579  function setGender($a_str)
1580  {
1581  $this->gender = substr($a_str,-1);
1582  }
1583 
1588  function getGender()
1589  {
1590  return $this->gender;
1591  }
1592 
1600  function setUTitle($a_str)
1601  {
1602  $this->utitle = $a_str;
1603  }
1604 
1611  function getUTitle()
1612  {
1613  return $this->utitle;
1614  }
1615 
1621  function setFirstname($a_str)
1622  {
1623  $this->firstname = $a_str;
1624  }
1625 
1630  function getFirstname()
1631  {
1632  return $this->firstname;
1633  }
1634 
1640  function setLastname($a_str)
1641  {
1642  $this->lastname = $a_str;
1643  }
1644 
1649  function getLastname()
1650  {
1651  return $this->lastname;
1652  }
1653 
1659  function setInstitution($a_str)
1660  {
1661  $this->institution = $a_str;
1662  }
1663 
1668  function getInstitution()
1669  {
1670  return $this->institution;
1671  }
1672 
1678  function setDepartment($a_str)
1679  {
1680  $this->department = $a_str;
1681  }
1682 
1687  function getDepartment()
1688  {
1689  return $this->department;
1690  }
1691 
1697  function setStreet($a_str)
1698  {
1699  $this->street = $a_str;
1700  }
1701 
1706  function getStreet()
1707  {
1708  return $this->street;
1709  }
1710 
1716  function setCity($a_str)
1717  {
1718  $this->city = $a_str;
1719  }
1720 
1725  function getCity()
1726  {
1727  return $this->city;
1728  }
1729 
1735  function setZipcode($a_str)
1736  {
1737  $this->zipcode = $a_str;
1738  }
1739 
1744  function getZipcode()
1745  {
1746  return $this->zipcode;
1747  }
1748 
1755  function setCountry($a_str)
1756  {
1757  $this->country = $a_str;
1758  }
1759 
1765  function getCountry()
1766  {
1767  return $this->country;
1768  }
1769 
1775  function setSelectedCountry($a_val)
1776  {
1777  $this->sel_country = $a_val;
1778  }
1779 
1786  {
1787  return $this->sel_country;
1788  }
1789 
1795  function setPhoneOffice($a_str)
1796  {
1797  $this->phone_office = $a_str;
1798  }
1799 
1804  function getPhoneOffice()
1805  {
1806  return $this->phone_office;
1807  }
1808 
1814  function setPhoneHome($a_str)
1815  {
1816  $this->phone_home = $a_str;
1817  }
1818 
1823  function getPhoneHome()
1824  {
1825  return $this->phone_home;
1826  }
1827 
1833  function setPhoneMobile($a_str)
1834  {
1835  $this->phone_mobile = $a_str;
1836  }
1837 
1842  function getPhoneMobile()
1843  {
1844  return $this->phone_mobile;
1845  }
1846 
1852  function setFax($a_str)
1853  {
1854  $this->fax = $a_str;
1855  }
1856 
1861  function getFax()
1862  {
1863  return $this->fax;
1864  }
1865 
1871  function setClientIP($a_str)
1872  {
1873  $this->client_ip = $a_str;
1874  }
1875 
1880  function getClientIP()
1881  {
1882  return $this->client_ip;
1883  }
1884 
1890  function setMatriculation($a_str)
1891  {
1892  $this->matriculation = $a_str;
1893  }
1894 
1899  function getMatriculation()
1900  {
1901  return $this->matriculation;
1902  }
1903 
1910  public static function lookupMatriculation($a_usr_id)
1911  {
1912  global $ilDB;
1913 
1914  $query = "SELECT matriculation FROM usr_data ".
1915  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1916  $res = $ilDB->query($query);
1917  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1918  return $row->matriculation ? $row->matriculation : '';
1919  }
1920 
1926  function setEmail($a_str)
1927  {
1928  $this->email = $a_str;
1929  }
1930 
1935  function getEmail()
1936  {
1937  return $this->email;
1938  }
1939 
1945  function setHobby($a_str)
1946  {
1947  $this->hobby = $a_str;
1948  }
1949 
1954  function getHobby()
1955  {
1956  return $this->hobby;
1957  }
1958 
1964  function setLanguage($a_str)
1965  {
1966  $this->setPref("language",$a_str);
1967  unset($_SESSION['lang']);
1968  }
1969 
1975  function getLanguage()
1976  {
1977  return $this->prefs["language"];
1978  }
1979 
1988  function setDiskQuota($a_disk_quota)
1989  {
1990  $this->setPref("disk_quota",$a_disk_quota);
1991  }
1992 
2002  function getDiskQuota()
2003  {
2004  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
2005  }
2006 
2007  public function setLastPasswordChangeTS($a_last_password_change_ts)
2008  {
2009  $this->last_password_change_ts = $a_last_password_change_ts;
2010  }
2011 
2012  public function getLastPasswordChangeTS()
2013  {
2015  }
2016 
2017 
2018  public static function _lookupLanguage($a_usr_id)
2019  {
2020  global $ilDB;
2021 
2022  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
2023  $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
2024  $ilDB->quote('language', "text");
2025  $r = $ilDB->query($q);
2026 
2027  while($row = $ilDB->fetchAssoc($r))
2028  {
2029  return $row['value'];
2030  }
2031  return 'en';
2032  }
2033 
2034 
2035  function _checkPassword($a_usr_id, $a_pw)
2036  {
2037  global $ilDB;
2038 
2039  $pw = ilObjUser::_lookup($a_usr_id, "passwd");
2040  if ($pw == md5($a_pw))
2041  {
2042  return true;
2043  }
2044  return false;
2045  }
2046 
2047  function _writeExternalAccount($a_usr_id, $a_ext_id)
2048  {
2049  global $ilDB;
2050 
2051  $ilDB->manipulateF("UPDATE usr_data ".
2052  " SET ext_account = %s WHERE usr_id = %s",
2053  array("text", "integer"),
2054  array($a_ext_id, $a_usr_id));
2055  }
2056 
2057  function _writeAuthMode($a_usr_id, $a_auth_mode)
2058  {
2059  global $ilDB;
2060 
2061  $ilDB->manipulateF("UPDATE usr_data ".
2062  " SET auth_mode = %s WHERE usr_id = %s",
2063  array("text", "integer"),
2064  array($a_auth_mode, $a_usr_id));
2065  }
2066 
2072  {
2073  return $_SESSION['lang'];
2074  }
2075 
2081  function setLastLogin($a_str)
2082  {
2083  $this->last_login = $a_str;
2084  }
2085 
2091  function getLastLogin()
2092  {
2093  return $this->last_login;
2094  }
2095 
2101  function setLastUpdate($a_str)
2102  {
2103  $this->last_update = $a_str;
2104  }
2105  function getLastUpdate()
2106  {
2107  return $this->last_update;
2108  }
2109 
2115  function setComment($a_str)
2116  {
2117  $this->referral_comment = $a_str;
2118  }
2119 
2124  function getComment()
2125  {
2126  return $this->referral_comment;
2127  }
2128 
2135  function setApproveDate($a_str)
2136  {
2137  $this->approve_date = $a_str;
2138  }
2139 
2145  function getApproveDate()
2146  {
2147  return $this->approve_date;
2148  }
2149 
2150  // BEGIN DiskQuota: show when user accepted user agreement
2156  function getAgreeDate()
2157  {
2158  return $this->agree_date;
2159  }
2166  function setAgreeDate($a_str)
2167  {
2168  $this->agree_date = $a_str;
2169  }
2170  // END DiskQuota: show when user accepted user agreement
2171 
2178  function setActive($a_active, $a_owner = 0)
2179  {
2180  $this->setOwner($a_owner);
2181 
2182  if ($a_active)
2183  {
2184  $this->active = 1;
2185  $this->setApproveDate(date('Y-m-d H:i:s'));
2186  $this->setOwner($a_owner);
2187  }
2188  else
2189  {
2190  $this->active = 0;
2191  $this->setApproveDate(null);
2192  }
2193  }
2194 
2199  function getActive()
2200  {
2201  return $this->active;
2202  }
2203 
2207  public function _lookupActive($a_usr_id)
2208  {
2209  global $ilDB;
2210 
2211  $query = 'SELECT usr_id FROM usr_data '.
2212  'WHERE active = '.$ilDB->quote(1,'integer').' '.
2213  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
2214  $res = $ilDB->query($query);
2215  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2216  {
2217  return true;
2218  }
2219  return false;
2220  }
2221 
2227  function syncActive()
2228  {
2229  global $ilAuth;
2230 
2231  $storedActive = 0;
2232  if ($this->getStoredActive($this->id))
2233  {
2234  $storedActive = 1;
2235  }
2236 
2237  $currentActive = 0;
2238  if ($this->active)
2239  {
2240  $currentActive = 1;
2241  }
2242 
2243  if ((!empty($storedActive) && empty($currentActive)) ||
2244  (empty($storedActive) && !empty($currentActive)))
2245  {
2246  $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2247  }
2248  }
2249 
2256  function getStoredActive($a_id)
2257  {
2258  $active = ilObjUser::_lookup($a_id, "active");
2259  return $active ? true : false;
2260  }
2261 
2267  function setSkin($a_str)
2268  {
2269  // TODO: exception handling (dir exists)
2270  $this->skin = $a_str;
2271  }
2272 
2273  function setTimeLimitOwner($a_owner)
2274  {
2275  $this->time_limit_owner = $a_owner;
2276  }
2278  {
2279  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2280  }
2281  function setTimeLimitFrom($a_from)
2282  {
2283  $this->time_limit_from = $a_from;
2284  }
2285  function getTimeLimitFrom()
2286  {
2287  return $this->time_limit_from ? $this->time_limit_from : time();
2288  }
2289  function setTimeLimitUntil($a_until)
2290  {
2291  $this->time_limit_until = $a_until;
2292  }
2294  {
2295  return $this->time_limit_until ? $this->time_limit_until : time();
2296  }
2297  function setTimeLimitUnlimited($a_unlimited)
2298  {
2299  $this->time_limit_unlimited = $a_unlimited;
2300  }
2302  {
2303  return $this->time_limit_unlimited;
2304  }
2305  function setTimeLimitMessage($a_time_limit_message)
2306  {
2307  return $this->time_limit_message = $a_time_limit_message;
2308  }
2310  {
2311  return $this->time_limit_message;
2312  }
2313 
2314  public function setLoginAttempts($a_login_attempts)
2315  {
2316  $this->login_attempts = $a_login_attempts;
2317  }
2318 
2319  public function getLoginAttempts()
2320  {
2321  return $this->login_attempts;
2322  }
2323 
2324 
2325  function checkTimeLimit()
2326  {
2327  if($this->getTimeLimitUnlimited())
2328  {
2329  return true;
2330  }
2331  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2332  {
2333  return true;
2334  }
2335  return false;
2336  }
2337  function setProfileIncomplete($a_prof_inc)
2338  {
2339  $this->profile_incomplete = (boolean) $a_prof_inc;
2340  }
2342  {
2343  if($this->id == ANONYMOUS_USER_ID)
2344  {
2345  return false;
2346  }
2347  return $this->profile_incomplete;
2348  }
2349 
2350  public function isPasswordChangeDemanded()
2351  {
2352  //error_reporting(E_ALL);
2353  if( $this->id == ANONYMOUS_USER_ID || $this->id == SYSTEM_USER_ID )
2354  return false;
2355 
2356  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2357  $security = ilSecuritySettings::_getInstance();
2358 
2360  && $security->isPasswordChangeOnFirstLoginEnabled()
2361  && $this->getLastPasswordChangeTS() == 0
2362  ){
2363  return true;
2364  }
2365  else return false;
2366  }
2367 
2368  public function isPasswordExpired()
2369  {
2370  //error_reporting(E_ALL);
2371  if($this->id == ANONYMOUS_USER_ID) return false;
2372 
2373  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2374  $security = ilSecuritySettings::_getInstance();
2375  if( $security->getAccountSecurityMode() == ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED &&
2376  $this->getLastPasswordChangeTS() > 0 )
2377  {
2378  $max_pass_age = $security->getPasswordMaxAge();
2379  if( $max_pass_age > 0 )
2380  {
2381  $max_pass_age_ts = ( $max_pass_age * 86400 );
2382  $pass_change_ts = $this->getLastPasswordChangeTS();
2383  $current_ts = time();
2384 
2385  if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2386  return true;
2387  }
2388  }
2389  return false;
2390  }
2391 
2392  public function getPasswordAge()
2393  {
2394  $current_ts = time();
2395  $pass_change_ts = $this->getLastPasswordChangeTS();
2396  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2397  return $password_age;
2398  }
2399 
2400  public function setLastPasswordChangeToNow()
2401  {
2402  global $ilDB;
2403 
2404  $this->setLastPasswordChangeTS( time() );
2405 
2406  $query = "UPDATE usr_data SET usr_data.last_password_change = %s " .
2407  "WHERE usr_data.usr_id = %s";
2408  $affected = $ilDB->manipulateF($query,
2409  array('integer','integer'),
2410  array($this->getLastPasswordChangeTS(),$this->id));
2411  if($affected) return true;
2412  else return false;
2413  }
2414 
2415  public function resetLastPasswordChange()
2416  {
2417  global $ilDB;
2418 
2419  $query = "UPDATE usr_data SET usr_data.last_password_change = 0 " .
2420  "WHERE usr_data.usr_id = %s";
2421  $affected = $ilDB->manipulateF( $query, array('integer'),
2422  array($this->getId()) );
2423  if($affected) return true;
2424  else return false;
2425  }
2426 
2432  function setLatitude($a_latitude)
2433  {
2434  $this->latitude = $a_latitude;
2435  }
2436 
2442  function getLatitude()
2443  {
2444  return $this->latitude;
2445  }
2446 
2452  function setLongitude($a_longitude)
2453  {
2454  $this->longitude = $a_longitude;
2455  }
2456 
2462  function getLongitude()
2463  {
2464  return $this->longitude;
2465  }
2466 
2472  function setLocationZoom($a_locationzoom)
2473  {
2474  $this->loc_zoom = $a_locationzoom;
2475  }
2476 
2482  function getLocationZoom()
2483  {
2484  return $this->loc_zoom;
2485  }
2486 
2487  function &getAppliedUsers()
2488  {
2489  $this->applied_users = array();
2490  $this->__readAppliedUsers($this->getId());
2491 
2492  return $this->applied_users ? $this->applied_users : array();
2493  }
2494 
2495  function isChild($a_usr_id)
2496  {
2497  if($a_usr_id == $this->getId())
2498  {
2499  return true;
2500  }
2501 
2502  $this->applied_users = array();
2503  $this->__readAppliedUsers($this->getId());
2504 
2505  return in_array($a_usr_id,$this->applied_users);
2506  }
2507 
2508  function __readAppliedUsers($a_parent_id)
2509  {
2510  global $ilDB;
2511 
2512  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2513  "WHERE time_limit_owner = %s",
2514  array("integer"),
2515  array($a_parent_id));
2516  while ($row = $ilDB->fetchObject($res))
2517  {
2518  $this->applied_users[] = $row->usr_id;
2519 
2520  // recursion
2521  $this->__readAppliedUsers($row->usr_id);
2522  }
2523  return true;
2524  }
2525 
2526  /*
2527  * check user id with login name
2528  * @access public
2529  */
2530  function checkUserId()
2531  {
2532  global $ilDB,$ilAuth, $ilSetting;
2533 
2536  if ($id > 0)
2537  {
2538  // check for simultaneous logins, except the user is the anonymous one
2539  if( $id != ANONYMOUS_USER_ID && (int)$ilSetting->get('ps_prevent_simultaneous_logins') == 1 )
2540  {
2541  $res = $ilDB->queryf('
2542  SELECT * FROM usr_session WHERE user_id = %s AND expires > %s',
2543  array('integer', 'integer'),
2544  array($id, time()));
2545  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2546  {
2547  $ilAuth->logout();
2548  @session_destroy();
2549  ilUtil::redirect('login.php?simultaneous_login=true');
2550  exit();
2551  }
2552  }
2553 
2554  return $id;
2555  }
2556  return false;
2557  }
2558 
2562  private static function getLoginFromAuth() {
2563  global $ilAuth;
2564 
2565  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2566  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2568  {
2569  require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2570  require_once ('Services/Database/classes/class.ilAuthContainerMDB2.php');
2571  $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2572  }
2573  else
2574  {
2575  $login =$ilAuth->getUsername();
2576  }
2577 
2578  return $login;
2579  }
2580 
2581  /*
2582  * check to see if current user has been made active
2583  * @access public
2584  * @return true if active, otherwise false
2585  */
2587  {
2588  global $ilDB,$ilAuth;
2589 
2591  $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2592  array("text"),
2593  array($login));
2594  //query has got a result
2595  if ($rec = $ilDB->fetchAssoc($set))
2596  {
2597  if ($rec["active"])
2598  {
2599  return true;
2600  }
2601  }
2602 
2603  return false;
2604  }
2605 
2606  /*
2607  * STATIC METHOD
2608  * get the user_id of a login name
2609  * @param string login name
2610  * @return integer id of user
2611  * @static
2612  * @access public
2613  */
2614  function getUserIdByLogin($a_login)
2615  {
2616  return (int) ilObjUser::_lookupId($a_login);
2617  }
2618 
2627  function _getUserIdsByEmail($a_email)
2628  {
2629  global $ilias, $ilDB;
2630 
2631  $res = $ilDB->queryF("SELECT login FROM usr_data ".
2632  "WHERE email = %s and active = 1",
2633  array("text"),
2634  array($a_email));
2635  $ids = array ();
2636  while($row = $ilDB->fetchObject($res))
2637  {
2638  $ids[] = $row->login;
2639  }
2640 
2641  return $ids;
2642  }
2643 
2644 
2645 
2654  function getUserIdByEmail($a_email)
2655  {
2656  global $ilDB;
2657 
2658  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2659  "WHERE email = %s", array("text"), array($a_email));
2660 
2661  $row = $ilDB->fetchObject($res);
2662  return $row->usr_id ? $row->usr_id : 0;
2663  }
2664 
2665  /*
2666  * STATIC METHOD
2667  * get the login name of a user_id
2668  * @param integer id of user
2669  * @return string login name; false if not found
2670  * @static
2671  * @access public
2672  */
2673  function getLoginByUserId($a_userid)
2674  {
2675  $login = ilObjUser::_lookupLogin($a_userid);
2676  return $login ? $login : false;
2677  }
2678 
2689  static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2690  {
2691  global $ilias, $ilDB, $ilLog;
2692 
2693 
2694  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2695 
2696  $without_anonymous_users = true;
2697 
2698  // determine join filter
2699  $join_filter = " WHERE ";
2700  if ($filter_settings !== FALSE && strlen($filter_settings))
2701  {
2702  switch ($filter_settings)
2703  {
2704  case 3:
2705  // show only users without courses
2706  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.usr_id IS NULL AND ";
2707  break;
2708  case 5:
2709  // show only users with a certain course membership
2710  $ref_id = $_SESSION["user_filter_data"];
2711  if ($ref_id)
2712  {
2713  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.obj_id = ".
2714  "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2715  }
2716  break;
2717  case 6:
2718  global $rbacreview;
2719  $ref_id = $_SESSION["user_filter_data"];
2720  if ($ref_id)
2721  {
2722  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2723  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2724  if (is_array($local_roles) && count($local_roles))
2725  {
2726  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2727  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2728  }
2729  }
2730  break;
2731  case 7:
2732  global $rbacreview;
2733  $rol_id = $_SESSION["user_filter_data"];
2734  if ($rol_id)
2735  {
2736  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2737  $ilDB->quote($rol_id, "integer")." AND ";
2738  $without_anonymous_users = false;
2739  }
2740  break;
2741  }
2742  }
2743  // This is a temporary hack to search users by their role
2744  // See Mantis #338. This is a hack due to Mantis #337.
2745  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2746  {
2747  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2748  "FROM object_data,rbac_ua,usr_data ".
2749  "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2750  " AND object_data.type = 'role' ".
2751  "AND rbac_ua.rol_id = object_data.obj_id ".
2752  "AND usr_data.usr_id = rbac_ua.usr_id ".
2753  "AND rbac_ua.usr_id != ".$illDB->quote(ANONYMOUS_USER_ID, "integer");
2754  }
2755  else
2756  {
2757  $query.= $join_filter.
2758  "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2759  "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2760  "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2761  "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2762 
2763  if ($filter_settings !== FALSE && strlen($filter_settings))
2764  {
2765  switch ($filter_settings)
2766  {
2767  case 0:
2768  $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2769  break;
2770  case 1:
2771  $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2772  break;
2773  case 2:
2774  $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2775  break;
2776  case 4:
2777  $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"]));
2778  $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2779  break;
2780  }
2781  }
2782 
2783  if ($without_anonymous_users)
2784  {
2785  $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2786  }
2787 
2788  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2789  {
2790  $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2791  }
2792 
2793  }
2794  $ilLog->write($query);
2795  $res = $ilDB->query($query);
2796  while ($row = $ilDB->fetchObject($res))
2797  {
2798  $users[] = array(
2799  "usr_id" => $row->usr_id,
2800  "login" => $row->login,
2801  "firstname" => $row->firstname,
2802  "lastname" => $row->lastname,
2803  "email" => $row->email,
2804  "active" => $row->active);
2805  $ids[] = $row->usr_id;
2806  }
2807  if ($a_return_ids_only)
2808  return $ids ? $ids : array();
2809  else
2810  return $users ? $users : array();
2811  }
2812 
2822  {
2823  global $ilDB;
2824 
2825  $res = $ilDB->query("SELECT login FROM usr_data");
2826  while($row = $ilDB->fetchObject($res))
2827  {
2828  $logins[] = $row->login;
2829  }
2830  return $logins ? $logins : array();
2831  }
2832 
2841  public static function _readUsersProfileData($a_user_ids)
2842  {
2843  global $ilDB;
2844  $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2845  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2846  while ($row = $ilDB->fetchAssoc($res))
2847  {
2848  $user_data["$row[usr_id]"] = $row;
2849  }
2850  return $user_data ? $user_data : array();
2851  }
2852 
2861  function _getAllUserData($a_fields = NULL, $active =-1)
2862  {
2863  global $ilDB;
2864 
2865  $result_arr = array();
2866  $types = array();
2867  $values = array();
2868 
2869  if ($a_fields !== NULL and is_array($a_fields))
2870  {
2871  if (count($a_fields) == 0)
2872  {
2873  $select = "*";
2874  }
2875  else
2876  {
2877  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2878  unset($a_fields[$usr_id_field]);
2879 
2880  $select = implode(",",$a_fields).",usr_data.usr_id";
2881  // online time
2882  if(in_array('online_time',$a_fields))
2883  {
2884  $select .= ",ut_online.online_time ";
2885  }
2886  }
2887 
2888  $q = "SELECT ".$select." FROM usr_data ";
2889 
2890  // Add online_time if desired
2891  // Need left join here to show users that never logged in
2892  if(in_array('online_time',$a_fields))
2893  {
2894  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2895  }
2896 
2897  switch ($active)
2898  {
2899  case 0:
2900  case 1:
2901  $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2902  break;
2903  case 2:
2904  $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2905  break;
2906  case 3:
2907  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2908  $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2909  $r = $ilDB->query($qtemp);
2910  $course_users = array();
2911  while ($row = $ilDB->fetchAssoc($r))
2912  {
2913  array_push($course_users, $row["usr_id"]);
2914  }
2915  if (count($course_users))
2916  {
2917  $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2918  }
2919  else
2920  {
2921  return $result_arr;
2922  }
2923  break;
2924  case 4:
2925  $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"]));
2926  $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2927  break;
2928  case 5:
2929  $ref_id = $_SESSION["user_filter_data"];
2930  if ($ref_id)
2931  {
2932  $q .= " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id ".
2933  "WHERE crs_members.obj_id = (SELECT obj_id FROM object_reference ".
2934  "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2935  }
2936  break;
2937  case 6:
2938  global $rbacreview;
2939  $ref_id = $_SESSION["user_filter_data"];
2940  if ($ref_id)
2941  {
2942  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2943  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2944  if (is_array($local_roles) && count($local_roles))
2945  {
2946  $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2947  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2948  }
2949  }
2950  break;
2951  case 7:
2952  $rol_id = $_SESSION["user_filter_data"];
2953  if ($rol_id)
2954  {
2955  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2956  $ilDB->quote($rol_id, "integer");
2957  }
2958  break;
2959  }
2960  $r = $ilDB->query($q);
2961 
2962  while ($row = $ilDB->fetchAssoc($r))
2963  {
2964  $result_arr[] = $row;
2965  }
2966  }
2967 
2968  return $result_arr;
2969  }
2970 
2974  function _getNumberOfUsersForStyle($a_skin, $a_style)
2975  {
2976  global $ilDB;
2977 
2978  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
2979  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
2980  " AND up1.value= ".$ilDB->quote($a_style, "text").
2981  " AND up2.keyword= ".$ilDB->quote("skin", "text").
2982  " AND up2.value= ".$ilDB->quote($a_skin, "text").
2983  " AND up1.usr_id = up2.usr_id ";
2984 
2985  $cnt_set = $ilDB->query($q);
2986 
2987  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
2988 
2989  return $cnt_rec["cnt"];
2990  }
2991 
2996  {
2997  global $ilDB;
2998 
2999  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
3000  " WHERE up1.keyword = ".$ilDB->quote("style", "text").
3001  " AND up2.keyword = ".$ilDB->quote("skin", "text").
3002  " AND up1.usr_id = up2.usr_id";
3003 
3004  $sty_set = $ilDB->query($q);
3005 
3006  $styles = array();
3007  while($sty_rec = $ilDB->fetchAssoc($sty_set))
3008  {
3009  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
3010  }
3011 
3012  return $styles;
3013  }
3014 
3018  function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3019  {
3020  global $ilDB;
3021 
3022  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
3023  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3024  " AND up1.value= ".$ilDB->quote($a_from_style, "text").
3025  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3026  " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
3027  " AND up1.usr_id = up2.usr_id ";
3028 
3029  $usr_set = $ilDB->query($q);
3030 
3031  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3032  {
3033  ilObjUser::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3034  ilObjUser::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3035  }
3036  }
3037 
3038 
3048  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3049  {
3050  global $ilDB;
3051 
3052  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3053  "item_id = %s AND type = %s AND user_id = %s",
3054  array("integer", "text", "integer"),
3055  array($a_item_id, $a_type, $a_usr_id));
3056 
3057  // only insert if item is not already on desktop
3058  if (!$ilDB->fetchAssoc($item_set))
3059  {
3060  $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3061  " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3062  array($a_item_id,$a_type,$a_usr_id,$a_par));
3063  }
3064 
3065  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3067  }
3068 
3076  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3077  {
3078  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3079  }
3080 
3089  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3090  {
3091  global $ilDB;
3092 
3093  $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3094  " WHERE item_id = %s AND type = %s AND user_id = %s",
3095  array("text", "integer", "text", "integer"),
3096  array($a_par, $a_item_id, $a_type, $this->getId()));
3097  }
3098 
3099 
3109  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3110  {
3111  global $ilDB;
3112 
3113  $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3114  " item_id = %s AND type = %s AND user_id = %s",
3115  array("integer", "text", "integer"),
3116  array($a_item_id, $a_type, $a_usr_id));
3117 
3118  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3120  }
3121 
3129  function dropDesktopItem($a_item_id, $a_type)
3130  {
3131  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3132  }
3133 
3140  static function _removeItemFromDesktops($a_id)
3141  {
3142  global $ilDB;
3143 
3144  $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3145  array("integer"), array($a_id));
3146 
3147  $users = array();
3148 
3149  while ($row = $ilDB->fetchObject($r))
3150  {
3151  $users[] = $row->user_id;
3152  } // while
3153 
3154  if (count($users) > 0)
3155  {
3156  $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3157  array("integer"), array($a_id));
3158  }
3159 
3160  return $users;
3161  }
3162 
3172  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3173  {
3174  global $ilDB;
3175 
3176  if (self::$is_desktop_item_loaded[$a_usr_id.":".$a_item_id])
3177  {
3178  return self::$is_desktop_item_cache[$a_usr_id.":".$a_item_id.":".$a_type];
3179  }
3180  $item_set = $ilDB->queryF("SELECT item_id FROM desktop_item WHERE ".
3181  "item_id = %s AND type = %s AND user_id = %s",
3182  array("integer", "text", "integer"),
3183  array($a_item_id, $a_type, $a_usr_id));
3184 
3185  if ($ilDB->fetchAssoc($item_set))
3186  {
3187  return true;
3188  }
3189  else
3190  {
3191  return false;
3192  }
3193  }
3194 
3201  static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3202  {
3203  global $ilDB;
3204 
3205  if (!is_array($a_item_ids))
3206  {
3207  return;
3208  }
3209 
3210  $item_ids = array();
3211  foreach ($a_item_ids as $id)
3212  {
3213  if (!self::$is_desktop_item_loaded[$a_usr_id.":".$id])
3214  {
3215  $item_ids[] = $id;
3216  }
3217  self::$is_desktop_item_loaded[$a_usr_id.":".$id] = true;
3218  }
3219 
3220  if (count($item_ids) > 0)
3221  {
3222  $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE ".
3223  $ilDB->in("item_id", $item_ids, false, "integer").
3224  " AND user_id = ".$ilDB->quote($a_usr_id, "integer"));
3225  while ($r = $ilDB->fetchAssoc($item_set))
3226  {
3227  self::$is_desktop_item_cache[$a_usr_id.":".$r["item_id"].":".$r["type"]]
3228  = true;
3229  }
3230  }
3231  }
3232 
3240  function isDesktopItem($a_item_id, $a_type)
3241  {
3242  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3243  }
3244 
3245  function getDesktopItems($a_types = "")
3246  {
3247  return $this->_lookupDesktopItems($this->getId(), $a_types);
3248  }
3249 
3256  static function _lookupDesktopItems($user_id, $a_types = "")
3257  {
3258  global $ilUser, $rbacsystem, $tree, $ilDB;
3259 
3260  if ($a_types == "")
3261  {
3262  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3263  " FROM desktop_item it, object_reference oref ".
3264  ", object_data obj".
3265  " WHERE ".
3266  "it.item_id = oref.ref_id AND ".
3267  "oref.obj_id = obj.obj_id AND ".
3268  "it.user_id = %s", array("integer"), array($user_id));
3269  $items = array();
3270  while ($item_rec = $ilDB->fetchAssoc($item_set))
3271  {
3272  if ($tree->isInTree($item_rec["ref_id"])
3273  && $item_rec["type"] != "rolf")
3274  {
3275  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3276  $par_left = $tree->getLeftValue($parent_ref);
3277  $par_left = sprintf("%010d", $par_left);
3278 
3279 
3280  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3281  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3282  $items[$par_left.$title.$item_rec["ref_id"]] =
3283  array("ref_id" => $item_rec["ref_id"],
3284  "obj_id" => $item_rec["obj_id"],
3285  "type" => $item_rec["type"],
3286  "title" => $title,
3287  "description" => $desc,
3288  "parent_ref" => $parent_ref);
3289  }
3290  }
3291  ksort($items);
3292  }
3293  else
3294  {
3295  if (!is_array($a_types))
3296  {
3297  $a_types = array($a_types);
3298  }
3299  $items = array();
3300  $foundsurveys = array();
3301  foreach($a_types as $a_type)
3302  {
3303  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3304  ", object_data obj WHERE ".
3305  "it.item_id = oref.ref_id AND ".
3306  "oref.obj_id = obj.obj_id AND ".
3307  "it.type = %s AND ".
3308  "it.user_id = %s ".
3309  "ORDER BY title",
3310  array("text", "integer"),
3311  array($a_type, $user_id));
3312 
3313  while ($item_rec = $ilDB->fetchAssoc($item_set))
3314  {
3315  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3316  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3317  $items[$title.$a_type.$item_rec["ref_id"]] =
3318  array("ref_id" => $item_rec["ref_id"],
3319  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3320  "title" => $title, "description" => $desc);
3321  }
3322 
3323  }
3324  ksort($items);
3325  }
3326  return $items;
3327  }
3328 
3334 
3342  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3343  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3344  {
3345  global $ilDB;
3346 
3347  if ($a_time == 0)
3348  {
3349  $a_time = date("Y-m-d H:i:s", time());
3350  }
3351 
3352  $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3353  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3354  array("integer", "integer", "text", "integer"),
3355  array(0, $a_item_id, $a_type, $this->getId()));
3356 
3357  // only insert if item is not already in clipboard
3358  if (!$d = $item_set->fetchRow())
3359  {
3360  $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3361  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3362  " (%s,%s,%s,%s,%s,%s,%s)",
3363  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3364  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3365  }
3366  else
3367  {
3368  $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3369  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3370  array("timestamp", "integer", "integer", "text"),
3371  array($a_time, $this->getId(), $a_item_id, $a_type));
3372  }
3373  }
3374 
3378  function addToPCClipboard($a_content, $a_time, $a_nr)
3379  {
3380  global $ilDB;
3381  if ($a_time == 0)
3382  {
3383  $a_time = date("Y-m-d H:i:s", time());
3384  }
3385  $ilDB->insert("personal_pc_clipboard", array(
3386  "user_id" => array("integer", $this->getId()),
3387  "content" => array("clob", $a_content),
3388  "insert_time" => array("timestamp", $a_time),
3389  "order_nr" => array("integer", $a_nr)
3390  ));
3391  }
3392 
3397  {
3398  global $ilDB;
3399 
3400  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3401  " WHERE user_id = %s", array("integer"), array($this->getId()));
3402  $row = $ilDB->fetchAssoc($set);
3403 
3404  $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3405  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3406  array("integer", "timestamp"),
3407  array($this->getId(), $row["mtime"]));
3408  $content = array();
3409  while ($row = $ilDB->fetchAssoc($set))
3410  {
3411  $content[] = $row["content"];
3412  }
3413 
3414  return $content;
3415  }
3416 
3420  function clipboardHasObjectsOfType($a_type)
3421  {
3422  global $ilDB;
3423 
3424  $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3425  "parent = %s AND type = %s AND user_id = %s",
3426  array("integer", "text", "integer"),
3427  array(0, $a_type, $this->getId()));
3428  if ($rec = $ilDB->fetchAssoc($set))
3429  {
3430  return true;
3431  }
3432 
3433  return false;
3434  }
3435 
3440  {
3441  global $ilDB;
3442 
3443  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3444  "type = %s AND user_id = %s",
3445  array("text", "integer"),
3446  array($a_type, $this->getId()));
3447  }
3448 
3453  {
3454  global $ilDB;
3455 
3456  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3457  "user_id = %s", array("integer"), array($this->getId()));
3458  }
3459 
3463  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3464  {
3465  global $ilDB;
3466 
3467  $par = "";
3468  if ($a_top_nodes_only)
3469  {
3470  $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3471  }
3472 
3473  $type_str = ($a_type != "")
3474  ? " AND type = ".$ilDB->quote($a_type, "text")." "
3475  : "";
3476  $q = "SELECT * FROM personal_clipboard WHERE ".
3477  "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3478  $type_str.$par.
3479  " ORDER BY order_nr";
3480  $objs = $ilDB->query($q);
3481  $objects = array();
3482  while ($obj = $ilDB->fetchAssoc($objs))
3483  {
3484  if ($obj["type"] == "mob")
3485  {
3486  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3487  }
3488  if ($obj["type"] == "incl")
3489  {
3490  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3491  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3492  }
3493  $objects[] = array ("id" => $obj["item_id"],
3494  "type" => $obj["type"], "title" => $obj["title"],
3495  "insert_time" => $obj["insert_time"]);
3496  }
3497  return $objects;
3498  }
3499 
3503  function getClipboardChilds($a_parent, $a_insert_time)
3504  {
3505  global $ilDB, $ilUser;
3506 
3507  $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3508  "user_id = %s AND parent = %s AND insert_time = %s ".
3509  " ORDER BY order_nr",
3510  array("integer", "integer", "timestamp"),
3511  array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3512  $objects = array();
3513  while ($obj = $ilDB->fetchAssoc($objs))
3514  {
3515  if ($obj["type"] == "mob")
3516  {
3517  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3518  }
3519  $objects[] = array ("id" => $obj["item_id"],
3520  "type" => $obj["type"], "title" => $obj["title"]);
3521  }
3522  return $objects;
3523  }
3524 
3533  function _getUsersForClipboadObject($a_type, $a_id)
3534  {
3535  global $ilDB;
3536 
3537  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3538  "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3539  "type = ".$ilDB->quote($a_type, "text");
3540  $user_set = $ilDB->query($q);
3541  $users = array();
3542  while ($user_rec = $ilDB->fetchAssoc($user_set))
3543  {
3544  $users[] = $user_rec["user_id"];
3545  }
3546 
3547  return $users;
3548  }
3549 
3557  function removeObjectFromClipboard($a_item_id, $a_type)
3558  {
3559  global $ilDB;
3560 
3561  $q = "DELETE FROM personal_clipboard WHERE ".
3562  "item_id = ".$ilDB->quote($a_item_id, "integer").
3563  " AND type = ".$ilDB->quote($a_type, "text")." ".
3564  " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3565  $ilDB->manipulate($q);
3566  }
3567 
3568  function _getImportedUserId($i2_id)
3569  {
3570  global $ilDB;
3571 
3572  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3573  $ilDB->quote($i2_id, "text");
3574 
3575  $res = $ilDB->query($query);
3576  while($row = $ilDB->fetchObject($res))
3577  {
3578  $id = $row->obj_id;
3579  }
3580  return $id ? $id : 0;
3581  }
3582 
3583 /*
3584 
3585  function setiLincData($a_id,$a_login,$a_passwd)
3586  {
3587  $this->ilinc_id = $a_id;
3588  $this->ilinc_login = $a_login;
3589  $this->ilinc_passwd = $a_passwd;
3590  }
3591 
3592 */
3593 
3594 /*
3595 
3596  function getiLincData()
3597  {
3598  return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
3599  }
3600 */
3605  function setAuthMode($a_str)
3606  {
3607  $this->auth_mode = $a_str;
3608  }
3609 
3614  function getAuthMode($a_auth_key = false)
3615  {
3616  if (!$a_auth_key)
3617  {
3618  return $this->auth_mode;
3619  }
3620 
3621  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3622  return ilAuthUtils::_getAuthMode($this->auth_mode);
3623  }
3624 
3632  function setExternalAccount($a_str)
3633  {
3634  $this->ext_account = $a_str;
3635  }
3636 
3645  {
3646  return $this->ext_account;
3647  }
3648 
3660  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3661  {
3662  global $ilDB,$ilSetting;
3663 
3664  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3665  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3666  "WHERE auth_mode = %s";
3667  $types[] = "text";
3668  $values[] = $a_auth_mode;
3669  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3670  {
3671  $q.= " OR auth_mode = %s ";
3672  $types[] = "text";
3673  $values[] = 'default';
3674  }
3675 
3676  $res = $ilDB->queryF($q, $types, $values);
3677  while ($row = $ilDB->fetchObject($res))
3678  {
3679  if($row->auth_mode == 'default')
3680  {
3681  $accounts[$row->usr_id] = $row->login;
3682  }
3683  else
3684  {
3685  $accounts[$row->usr_id] = $row->ext_account;
3686  }
3687  }
3688  return $accounts ? $accounts : array();
3689  }
3690 
3698  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3699  {
3700  global $ilDB;
3701 
3702  if(!is_array($a_usr_ids))
3703  {
3704  return false;
3705  }
3706  $q = "UPDATE usr_data SET active = %s WHERE ".
3707  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3708  $ilDB->manipulateF($q, array("integer"), array(($a_status ? 1 : 0)));
3709 
3710  return true;
3711  }
3712 
3713 
3722  public static function _lookupAuthMode($a_usr_id)
3723  {
3724  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3725  }
3726 
3733  public static function _checkExternalAuthAccount($a_auth, $a_account)
3734  {
3735  global $ilDB,$ilSetting;
3736 
3737  // Check directly with auth_mode
3738  $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3739  " ext_account = %s AND auth_mode = %s",
3740  array("text", "text"),
3741  array($a_account, $a_auth));
3742  if ($usr = $ilDB->fetchAssoc($r))
3743  {
3744  return $usr["login"];
3745  }
3746 
3747  // For compatibility, check for login (no ext_account entry given)
3748  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3749  "WHERE login = %s AND auth_mode = %s",
3750  array("text", "text"),
3751  array($a_account, $a_auth));
3752  if($usr = $ilDB->fetchAssoc($res))
3753  {
3754  return $usr['login'];
3755  }
3756 
3757  // If auth_default == $a_auth => check for login
3758  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3759  {
3760  $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3761  " ext_account = %s AND auth_mode = %s",
3762  array("text", "text"),
3763  array($a_account, "default"));
3764  if ($usr = $ilDB->fetchAssoc($res))
3765  {
3766  return $usr["login"];
3767  }
3768  // Search for login (no ext_account given)
3769  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3770  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3771  array("text", "text"),
3772  array($a_account, "default"));
3773  if($usr = $ilDB->fetchAssoc($res))
3774  {
3775  return $usr["login"];
3776  }
3777  }
3778  return false;
3779  }
3780 
3785  {
3786  global $ilDB;
3787 
3788  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3789  "GROUP BY auth_mode");
3790  $cnt_arr = array();
3791  while($cnt = $ilDB->fetchAssoc($r))
3792  {
3793  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3794  }
3795 
3796  return $cnt_arr;
3797  }
3798 
3804  function _getLocalAccountsForEmail($a_email)
3805  {
3806  global $ilDB, $ilSetting;
3807 
3808  // default set to local (1)?
3809 
3810  $q = "SELECT * FROM usr_data WHERE ".
3811  " email = %s AND (auth_mode = %s ";
3812  $types = array("text", "text");
3813  $values = array($a_email, "local");
3814 
3815  if ($ilSetting->get("auth_mode") == 1)
3816  {
3817  $q.=" OR auth_mode = %s";
3818  $types[] = "text";
3819  $values[] = "default";
3820  }
3821 
3822  $q.= ")";
3823 
3824  $users = array();
3825  $usr_set = $ilDB->queryF($q, $types, $values);
3826  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3827  {
3828  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3829  }
3830 
3831  return $users;
3832  }
3833 
3834 
3842  function _uploadPersonalPicture($tmp_file, $obj_id)
3843  {
3844  $webspace_dir = ilUtil::getWebspaceDir();
3845  $image_dir = $webspace_dir."/usr_images";
3846  $store_file = "usr_".$obj_id."."."jpg";
3847  $target_file = $image_dir."/$store_file";
3848 
3849  chmod($tmp_file, 0770);
3850 
3851  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3852  // taking only frame [0] to avoid problems with animated gifs
3853  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3854  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3855  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3856  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3857 
3858  ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
3859  ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
3860  ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
3861  ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
3862 
3863  // store filename
3864  ilObjUser::_writePref($obj_id, "profile_image", $store_file);
3865 
3866  return TRUE;
3867  }
3868 
3874  function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3875  {
3876  return ilObjUser::_getPersonalPicturePath($this->getId(),$a_size,$a_force_pic);
3877  }
3878 
3885  function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3886  $a_prevent_no_photo_image = false)
3887  {
3888  global $ilDB;
3889 
3890  // BEGIN DiskQuota: Fetch all user preferences in a single query
3891  $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3892  "keyword IN (%s,%s) ".
3893  "AND usr_id = %s",
3894  array("text", "text", "integer"),
3895  array('public_upload', 'public_profile', $a_usr_id));
3896  while ($row = $ilDB->fetchAssoc($res))
3897  {
3898  switch ($row['keyword'])
3899  {
3900  case 'public_upload' :
3901  $upload = $row['value'] == 'y';
3902  break;
3903  case 'public_profile' :
3904  $profile = ($row['value'] == 'y' ||
3905  $row['value'] == 'g');
3906  break;
3907  }
3908  }
3909 
3910  // END DiskQuota: Fetch all user preferences in a single query
3911  $webspace_dir = "";
3912  if(defined('ILIAS_MODULE'))
3913  {
3914  $webspace_dir = ('.'.$webspace_dir);
3915  }
3916  $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
3917 
3918  $image_dir = $webspace_dir."/usr_images";
3919  // BEGIN DiskQuota: Support 'big' user images
3920  if ($a_size == 'big')
3921  {
3922  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3923  }
3924  else
3925  {
3926  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3927  }
3928  // END DiskQuota: Support 'big' user images
3929 
3930  if((($upload && $profile) || $a_force_pic)
3931  && @is_file($thumb_file))
3932  {
3933  $file = $thumb_file."?t=".rand(1, 99999);
3934  }
3935  else
3936  {
3937  if (!$a_prevent_no_photo_image)
3938  {
3939  // we only have xsmall and xxsmall for this
3940  if($a_size == "small" || $a_size == "big")
3941  {
3942  $a_size = "xsmall";
3943  }
3944  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
3945  }
3946  }
3947 
3948  return $file;
3949  }
3950 
3954  function removeUserPicture($a_do_update = true)
3955  {
3956  $webspace_dir = ilUtil::getWebspaceDir();
3957  $image_dir = $webspace_dir."/usr_images";
3958  $file = $image_dir."/usr_".$this->getID()."."."jpg";
3959  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
3960  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
3961  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
3962  $upload_file = $image_dir."/upload_".$this->getID();
3963 
3964  if($a_do_update)
3965  {
3966  // remove user pref file name
3967  $this->setPref("profile_image", "");
3968  $this->update();
3969  }
3970 
3971  if (@is_file($file))
3972  {
3973  unlink($file);
3974  }
3975  if (@is_file($thumb_file))
3976  {
3977  unlink($thumb_file);
3978  }
3979  if (@is_file($xthumb_file))
3980  {
3981  unlink($xthumb_file);
3982  }
3983  if (@is_file($xxthumb_file))
3984  {
3985  unlink($xxthumb_file);
3986  }
3987  if (@is_file($upload_file))
3988  {
3989  unlink($upload_file);
3990  }
3991  }
3992 
3993 
3994  function setUserDefinedData($a_data)
3995  {
3996  if(!is_array($a_data))
3997  {
3998  return false;
3999  }
4000  foreach($a_data as $field => $data)
4001  {
4002  #$new_data[$field] = ilUtil::stripSlashes($data);
4003  // Assign it directly to avoid update problems of unchangable fields
4004  $this->user_defined_data['f_'.$field] = $data;
4005  }
4006  #$this->user_defined_data = $new_data;
4007 
4008  return true;
4009  }
4010 
4012  {
4013  return $this->user_defined_data ? $this->user_defined_data : array();
4014  }
4015 
4017  {
4018  global $ilDB;
4019 
4020  $fields = '';
4021 
4022  $field_def = array();
4023 
4024  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4025  $udata = new ilUserDefinedData($this->getId());
4026 
4027  foreach($this->user_defined_data as $field => $value)
4028  {
4029  if($field != 'usr_id')
4030  {
4031 // $field_def[$field] = array('text',$value);
4032  $udata->set($field, $value);
4033  }
4034  }
4035  $udata->update();
4036 
4037 /* if(!$field_def)
4038  {
4039  return true;
4040  }
4041 
4042  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4043  $res = $ilDB->query($query);
4044 
4045 
4046  if($res->numRows())
4047  {
4048  // Update
4049  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4050  }
4051  else
4052  {
4053  $field_def['usr_id'] = array('integer',$this->getId());
4054  $ilDB->insert('udf_data',$field_def);
4055  }
4056 */
4057  return true;
4058  }
4059 
4061  {
4062  global $ilDB;
4063 
4064  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4065  $udata = new ilUserDefinedData($this->getId());
4066 
4067 /* $query = "SELECT * FROM udf_data ".
4068  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4069 
4070  $res = $this->db->query($query);
4071  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
4072  {
4073  $this->user_defined_data = $row;
4074  }*/
4075 
4076  $this->user_defined_data = $udata->getAll();
4077 
4078  return true;
4079  }
4080 
4082  {
4083  global $ilDB;
4084 
4085 // not needed. no entry in udf_text/udf_clob means no value
4086 
4087 /* $query = "INSERT INTO udf_data (usr_id ) ".
4088  "VALUES( ".
4089  $ilDB->quote($this->getId(),'integer').
4090  ")";
4091  $res = $ilDB->manipulate($query);
4092 */
4093  return true;
4094  }
4095 
4097  {
4098  global $ilDB;
4099 
4100  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4102 
4103  // wrong place...
4104 /* $query = "DELETE FROM udf_data ".
4105  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4106  $res = $ilDB->manipulate($query);*/
4107 
4108  return true;
4109  }
4110 
4116  function getProfileAsString(&$a_language)
4117  {
4118  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4119  include_once 'classes/class.ilFormat.php';
4120 
4121  global $lng,$rbacreview;
4122 
4123  $language =& $a_language;
4124  $language->loadLanguageModule('registration');
4125  $language->loadLanguageModule('crs');
4126 
4127  $body = '';
4128  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4129 
4130  if(strlen($this->getUTitle()))
4131  {
4132  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4133  }
4134  if(strlen($this->getGender()))
4135  {
4136  $gender = ($this->getGender() == 'm') ?
4137  $language->txt('gender_m') :
4138  $language->txt('gender_f');
4139  $body .= ($language->txt("gender").": ".$gender."\n");
4140  }
4141  if(strlen($this->getFirstname()))
4142  {
4143  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4144  }
4145  if(strlen($this->getLastname()))
4146  {
4147  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4148  }
4149  if(strlen($this->getInstitution()))
4150  {
4151  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4152  }
4153  if(strlen($this->getDepartment()))
4154  {
4155  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4156  }
4157  if(strlen($this->getStreet()))
4158  {
4159  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4160  }
4161  if(strlen($this->getCity()))
4162  {
4163  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4164  }
4165  if(strlen($this->getZipcode()))
4166  {
4167  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4168  }
4169  if(strlen($this->getCountry()))
4170  {
4171  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4172  }
4173  if(strlen($this->getSelectedCountry()))
4174  {
4175  $body .= ($language->txt("sel_country").": ".$this->getSelectedCountry()."\n");
4176  }
4177  if(strlen($this->getPhoneOffice()))
4178  {
4179  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4180  }
4181  if(strlen($this->getPhoneHome()))
4182  {
4183  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4184  }
4185  if(strlen($this->getPhoneMobile()))
4186  {
4187  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4188  }
4189  if(strlen($this->getFax()))
4190  {
4191  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4192  }
4193  if(strlen($this->getEmail()))
4194  {
4195  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4196  }
4197  if(strlen($this->getHobby()))
4198  {
4199  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4200  }
4201  if(strlen($this->getComment()))
4202  {
4203  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4204  }
4205  if(strlen($this->getMatriculation()))
4206  {
4207  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4208  }
4209  if(strlen($this->getCreateDate()))
4210  {
4215 
4216  $body .= ($language->txt("create_date").": ".$date."\n");
4217  }
4218 
4219  foreach($rbacreview->getGlobalRoles() as $role)
4220  {
4221  if($rbacreview->isAssigned($this->getId(),$role))
4222  {
4223  $gr[] = ilObjRole::_lookupTitle($role);
4224  }
4225  }
4226  if(count($gr))
4227  {
4228  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4229  }
4230 
4231  // Time limit
4232  if($this->getTimeLimitUnlimited())
4233  {
4234  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4235  }
4236  else
4237  {
4241  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4243 
4244  $start = new ilDateTime($this->getTimeLimitFrom(),IL_CAL_UNIX);
4245  $end = new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX);
4246 
4247  $body .= $language->txt('time_limit').': '.$start->get(IL_CAL_DATETIME);
4248  $body .= $language->txt('time_limit').': '.$end->get(IL_CAL_DATETIME);
4249 
4250 
4251  #$body .= $language->txt('time_limit').': '.$period;
4252  /*
4253  $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4254  ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4255  $language->txt('crs_to')." ".
4256  ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4257  */
4258  }
4259  return $body;
4260  }
4261 
4262  function setInstantMessengerId($a_im_type, $a_im_id)
4263  {
4264  $var = "im_".$a_im_type;
4265  $this->$var = $a_im_id;
4266  }
4267 
4268  function getInstantMessengerId($a_im_type)
4269  {
4270  $var = "im_".$a_im_type;
4271  return $this->$var;
4272  }
4273 
4274  function setDelicious($a_delicious)
4275  {
4276  $this->delicious = $a_delicious;
4277  }
4278 
4279  function getDelicious()
4280  {
4281  return $this->delicious;
4282  }
4283 
4287  function _lookupFeedHash($a_user_id, $a_create = false)
4288  {
4289  global $ilDB;
4290 
4291  if ($a_user_id > 0)
4292  {
4293  $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4294  array("integer"), array($a_user_id));
4295  if ($rec = $ilDB->fetchAssoc($set))
4296  {
4297  if (strlen($rec["feed_hash"]) == 32)
4298  {
4299  return $rec["feed_hash"];
4300  }
4301  else if($a_create)
4302  {
4303  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4304  $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4305  " WHERE usr_id = %s",
4306  array("text", "integer"),
4307  array($hash, $a_user_id));
4308  return $hash;
4309  }
4310  }
4311  }
4312 
4313  return false;
4314  }
4315 
4321  function _getFeedPass($a_user_id)
4322  {
4323  global $ilDB;
4324 
4325  if ($a_user_id > 0)
4326  {
4327  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4328  }
4329  return false;
4330  }
4331 
4337  function _setFeedPass($a_user_id, $a_password)
4338  {
4339  global $ilDB;
4340 
4341  ilObjUser::_writePref($a_user_id, "priv_feed_pass",
4342  ($a_password=="") ? "" : md5($a_password));
4343  }
4344 
4354  public static function _loginExists($a_login,$a_user_id = 0)
4355  {
4356  global $ilDB;
4357 
4358  $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4359  "WHERE login = %s";
4360  $types[] = "text";
4361  $values[] = $a_login;
4362 
4363  if ($a_user_id != 0)
4364  {
4365  $q.= " AND usr_id != %s ";
4366  $types[] = "integer";
4367  $values[] = $a_user_id;
4368  }
4369 
4370  $r = $ilDB->queryF($q, $types, $values);
4371 
4372  if ($row = $ilDB->fetchAssoc($r))
4373  {
4374  return $row['usr_id'];
4375  }
4376  return false;
4377  }
4378 
4389  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4390  {
4391  global $ilDB;
4392 
4393  $res = $ilDB->queryF("SELECT * FROM usr_data ".
4394  "WHERE ext_account = %s AND auth_mode = %s",
4395  array("text", "text"),
4396  array($a_external_account, $a_auth_mode));
4397  return $ilDB->fetchAssoc($res) ? true :false;
4398  }
4399 
4407  public static function _getUsersForRole($role_id, $active = -1) {
4408  global $ilDB, $rbacreview;
4409  $data = array();
4410 
4411  $ids = $rbacreview->assignedUsers($role_id);
4412 
4413  if (count ($ids) == 0)
4414  {
4415  $ids = array (-1);
4416  }
4417 
4418  $query = "SELECT usr_data.*, usr_pref.value AS language
4419  FROM usr_data
4420  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4421  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4422  $values[] = "language";
4423  $types[] = "text";
4424 
4425 
4426  if (is_numeric($active) && $active > -1)
4427  {
4428  $query .= " AND usr_data.active = %s";
4429  $values[] = $active;
4430  $types[] = "integer";
4431  }
4432 
4433  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4434 
4435  $r = $ilDB->queryF($query, $types, $values);
4436  $data = array();
4437  while ($row = $ilDB->fetchAssoc($r))
4438  {
4439  $data[] = $row;
4440  }
4441  return $data;
4442  }
4443 
4444 
4450  public static function _getUsersForFolder ($ref_id, $active) {
4451  global $ilDB;
4452  $data = array();
4453  $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 ";
4454  $types[] = "text";
4455  $values[] = "language";
4456 
4457  if (is_numeric($active) && $active > -1)
4458  {
4459  $query .= " AND usr_data.active = %s";
4460  $values[] = $active;
4461  $types[] = "integer";
4462  }
4463 
4464  if ($ref_id != USER_FOLDER_ID)
4465  {
4466  $query.= " AND usr_data.time_limit_owner = %s";
4467  $values[] = $ref_id;
4468  $types[] = "integer";
4469  }
4470 
4471  $query .= " AND usr_data.usr_id != %s ";
4472  $values[] = ANONYMOUS_USER_ID;
4473  $types[] = "integer";
4474 
4475  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4476 
4477  $result = $ilDB->queryF($query, $types, $values);
4478  $data = array();
4479  while ($row = $ilDB->fetchAssoc($result))
4480  {
4481  array_push($data, $row);
4482  }
4483 
4484  return $data;
4485  }
4486 
4487 
4493  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4494  {
4495  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4496  }
4497 
4498 
4504  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4505  {
4506  global $rbacadmin, $rbacreview, $ilDB;
4507 
4508  // quote all ids
4509  $ids = array();
4510  foreach ($a_mem_ids as $mem_id) {
4511  $ids [] = $ilDB->quote($mem_id);
4512  }
4513 
4514  $query = "SELECT usr_data.*, usr_pref.value AS language
4515  FROM usr_data
4516  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4517  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer")."
4518  AND usr_data.usr_id != %s";
4519  $values[] = "language";
4520  $types[] = "text";
4521  $values[] = ANONYMOUS_USER_ID;
4522  $types[] = "integer";
4523 
4524  if (is_numeric($active) && $active > -1)
4525  {
4526  $query .= " AND active = %s";
4527  $values[] = $active;
4528  $types[] = "integer";
4529  }
4530 
4531  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4532  {
4533  $query.= " AND usr_data.time_limit_owner = %s";
4534  $values[] = $timelimitowner;
4535  $types[] = "integer";
4536 
4537  }
4538 
4539  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4540 
4541  $result = $ilDB->queryF($query, $types, $values);
4542  while ($row = $ilDB->fetchAssoc($result))
4543  {
4544  $mem_arr[] = $row;
4545  }
4546 
4547  return $mem_arr ? $mem_arr : array();
4548  }
4549 
4550 
4551 
4557  public static function _getUserData ($a_internalids) {
4558  global $ilDB;
4559 
4560  $ids = array();
4561  if (is_array($a_internalids)) {
4562  foreach ($a_internalids as $internalid) {
4563  if (is_numeric ($internalid))
4564  {
4565  $ids[] = $internalid;
4566  }
4567  else
4568  {
4569  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4570  if (is_numeric($parsedid) && $parsedid > 0)
4571  {
4572  $ids[] = $parsedid;
4573  }
4574  }
4575  }
4576  }
4577  if (count($ids) == 0)
4578  $ids [] = -1;
4579 
4580  $query = "SELECT usr_data.*, usr_pref.value AS language
4581  FROM usr_data
4582  LEFT JOIN usr_pref
4583  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4584  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4585  $values[] = "language";
4586  $types[] = "text";
4587 
4588  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4589 
4590  $data = array();
4591  $result = $ilDB->queryF($query, $types, $values);
4592  while ($row = $ilDB->fetchAssoc($result))
4593  {
4594  $data[] = $row;
4595  }
4596  return $data;
4597  }
4598 
4605  public static function _getPreferences ($user_id)
4606  {
4607  global $ilDB;
4608 
4609  $prefs = array();
4610 
4611  $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4612  array("integer"), array($user_id));
4613 
4614  while($row = $ilDB->fetchAssoc($r))
4615  {
4616  $prefs[$row["keyword"]] = $row["value"];
4617  }
4618 
4619  return $prefs;
4620  }
4621 
4622 
4623  public static function _resetLoginAttempts($a_usr_id)
4624  {
4625  global $ilDB;
4626 
4627  $query = "UPDATE usr_data SET usr_data.login_attempts = 0 WHERE usr_data.usr_id = %s";
4628  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4629 
4630  if($affected) return true;
4631  else return false;
4632  }
4633 
4634  public static function _getLoginAttempts($a_usr_id)
4635  {
4636  global $ilDB;
4637 
4638  $query = "SELECT usr_data.login_attempts FROM usr_data WHERE usr_data.usr_id = %s";
4639  $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4640  $record = $ilDB->fetchAssoc( $result );
4641  $login_attempts = $record['login_attempts'];
4642 
4643  return $login_attempts;
4644  }
4645 
4646  public static function _incrementLoginAttempts($a_usr_id)
4647  {
4648  global $ilDB;
4649 
4650  $query = "UPDATE usr_data SET usr_data.login_attempts = (usr_data.login_attempts + 1) WHERE usr_data.usr_id = %s";
4651  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4652 
4653  if($affected) return true;
4654  else return false;
4655  }
4656 
4657  public static function _setUserInactive($a_usr_id)
4658  {
4659  global $ilDB;
4660 
4661  $query = "UPDATE usr_data SET usr_data.active = 0 WHERE usr_data.usr_id = %s";
4662  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4663 
4664  if($affected) return true;
4665  else return false;
4666  }
4667 
4673  public function hasPublicProfile() {
4674  return in_array($this->getPref("public_profile"), array("y", "g"));
4675  }
4676 
4682  public function getPublicName()
4683  {
4684  if ($this->hasPublicProfile())
4685  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4686  else
4687  return $this->getLogin();
4688 
4689  }
4690 
4691  public static function _writeHistory($a_usr_id, $a_login)
4692  {
4693  global $ilDB;
4694 
4695  $timestamp = time();
4696 
4697  $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4698  array('integer', 'text', 'integer'),
4699  array($a_usr_id, $a_login, $timestamp));
4700 
4701  if( $ilDB->numRows($res) == 0 )
4702  {
4703  $ilDB->manipulateF('
4704  INSERT INTO loginname_history
4705  (usr_id, login, history_date)
4706  VALUES (%s, %s, %s)',
4707  array('integer', 'text', 'integer'),
4708  array($a_usr_id, $a_login, $timestamp));
4709  }
4710 
4711  return true;
4712  }
4713 
4721  function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4722  {
4723  global $ilDB;
4724 
4725  $pd_set = new ilSetting("pd");
4726  $atime = $pd_set->get("user_activity_time") * 60;
4727  $ctime = time();
4728 
4729  if ($a_user_id == 0)
4730  {
4731  $where = "WHERE user_id != 0 AND NOT agree_date IS NULL ";
4732  $type_array = array("integer");
4733  $val_array = array(time());
4734  }
4735  else
4736  {
4737  $where = "WHERE user_id = %s ";
4738  $type_array = array("integer", "integer");
4739  $val_array = array($a_user_id, time());
4740  }
4741 
4742  $no_anonym = ($a_no_anonymous)
4743  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4744  : "";
4745 
4746  include_once './Services/User/classes/class.ilUserAccountSettings.php';
4747  if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
4748  {
4749  include_once './Services/User/classes/class.ilUserFilter.php';
4750  $user_filter = 'AND '.$ilDB->in('time_limit_owner',ilUserFilter::getInstance()->getFolderIds(),false,'integer').' ';
4751  }
4752  else
4753  {
4754  $user_filter = ' ';
4755  }
4756  $r = $ilDB->queryF($q = "SELECT count(user_id) as num,user_id,firstname,lastname,title,login,last_login,max(ctime) AS ctime ".
4757  "FROM usr_session ".
4758  "LEFT JOIN usr_data u ON user_id = u.usr_id ".
4759  "LEFT JOIN usr_pref p ON (p.usr_id = u.usr_id AND p.keyword = ".
4760  $ilDB->quote("hide_own_online_status", "text").") ".$where.
4761  "AND expires > %s ".
4762  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4763  $no_anonym.
4764  $user_filter.
4765  "GROUP BY user_id,firstname,lastname,title,login,last_login ".
4766  "ORDER BY lastname, firstname", $type_array, $val_array);
4767 
4768  while ($user = $ilDB->fetchAssoc($r))
4769  {
4770  if ($atime <= 0
4771  || $user["ctime"] + $atime > $ctime)
4772  {
4773  $users[$user["user_id"]] = $user;
4774  }
4775  }
4776 
4777  return $users ? $users : array();
4778  }
4779 
4788  function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4789  {
4790  global $ilias, $ilDB;
4791 
4792  $pd_set = new ilSetting("pd");
4793  $atime = $pd_set->get("user_activity_time") * 60;
4794  $ctime = time();
4795  $no_anonym = ($a_no_anonymous)
4796  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4797  : "";
4798 
4799  // Get a list of object id's of all courses and groups for which
4800  // the current user has local roles.
4801  // Note: we have to use DISTINCT here, because a user may assume
4802  // multiple roles in a group or a course.
4803  $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4804  "FROM rbac_ua ua ".
4805  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4806  "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4807  "JOIN tree ON tree.child = r1.ref_id ".
4808  "JOIN object_reference r2 ON r2.ref_id = tree.parent ".
4809  "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4810  "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4811  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4812  "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4813  $ilDB->quote("grp", "text").")";
4814  $r = $ilDB->query($q);
4815 
4816  while ($row = $ilDB->fetchAssoc($r))
4817  {
4818  $groups_and_courses_of_user[] = $row["obj_id"];
4819  }
4820  // If the user is not in a course or a group, he has no associated users.
4821  if (count($groups_and_courses_of_user) == 0)
4822  {
4823  $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4824  "FROM usr_session ".
4825  "JOIN usr_data ON user_id=usr_id ".
4826  "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4827  $no_anonym.
4828  " AND NOT agree_date IS NULL ".
4829  "AND expires > ".$ilDB->quote(time(), "integer")." ".
4830  "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4831  $r = $ilDB->query($q);
4832  }
4833  else
4834  {
4835  $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4836  "FROM usr_session s ".
4837  "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4838  "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
4839  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4840  "JOIN tree ON tree.child = fa.parent ".
4841  "JOIN object_reference or1 ON or1.ref_id = tree.parent ".
4842  "JOIN object_data od ON od.obj_id = or1.obj_id ".
4843  "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
4844  $ilDB->quote("hide_own_online_status", "text").") ".
4845  "WHERE s.user_id != 0 ".
4846  $no_anonym.
4847  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4848  "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
4849  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4850  " AND NOT ud.agree_date IS NULL ".
4851  "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
4852  "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4853  "ORDER BY ud.lastname, ud.firstname";
4854  $r = $ilDB->query($q);
4855  }
4856 
4857  while ($user = $ilDB->fetchAssoc($r))
4858  {
4859  if ($atime <= 0
4860  || $user["ctime"] + $atime > $ctime)
4861  {
4862  $users[$user["user_id"]] = $user;
4863  }
4864  }
4865 
4866  return $users ? $users : array();
4867  }
4868 
4875  public static function _generateRegistrationHash($a_usr_id)
4876  {
4877  global $ilDB;
4878 
4879  do
4880  {
4881  $continue = false;
4882 
4883  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
4884 
4885  $res = $ilDB->queryf('
4886  SELECT COUNT(usr_id) cnt FROM usr_data
4887  WHERE reg_hash = %s',
4888  array('text'),
4889  array($hashcode));
4890  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
4891  {
4892  if($row->cnt > 0) $continue = true;
4893  break;
4894  }
4895 
4896  if($continue) continue;
4897 
4898  $ilDB->manipulateF('
4899  UPDATE usr_data
4900  SET reg_hash = %s
4901  WHERE usr_id = %s',
4902  array('text', 'integer'),
4903  array($hashcode, (int)$a_usr_id)
4904  );
4905 
4906  break;
4907 
4908  } while(true);
4909 
4910  return $hashcode;
4911  }
4912 
4921  public static function _verifyRegistrationHash($a_hash)
4922  {
4923  global $ilDB;
4924 
4925  $res = $ilDB->queryf('
4926  SELECT usr_id, create_date FROM usr_data
4927  WHERE reg_hash = %s',
4928  array('text'),
4929  array($a_hash));
4930  while($row = $ilDB->fetchAssoc($res))
4931  {
4932  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
4933  $oRegSettigs = new ilRegistrationSettings();
4934 
4935  if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
4936  time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
4937  {
4938  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
4939  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
4940  }
4941 
4942  $ilDB->manipulateF('
4943  UPDATE usr_data
4944  SET reg_hash = %s
4945  WHERE usr_id = %s',
4946  array('text', 'integer'),
4947  array('', (int)$row['usr_id'])
4948  );
4949 
4950  return (int)$row['usr_id'];
4951  }
4952 
4953  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
4954  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
4955  }
4956 
4957  function setBirthday($a_birthday)
4958  {
4959  if (strlen($a_birthday))
4960  {
4961  $date = new ilDate($a_birthday, IL_CAL_DATE);
4962  $this->birthday = $date->get(IL_CAL_DATE);
4963  }
4964  else
4965  {
4966  $this->birthday = null;
4967  }
4968  }
4969 
4970  function getBirthday()
4971  {
4972  return $this->birthday;
4973  }
4974 
4983  public static function _getUserIdsByInactivityPeriod($period)
4984  {
4985  if( !(int)$period ) throw new ilException('no valid period given');
4986 
4987  global $ilDB;
4988 
4989  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
4990 
4991  $query = "SELECT usr_id FROM usr_data WHERE last_login < %s";
4992 
4993  $res = $ilDB->queryF($query, array('timestamp'), array($date));
4994 
4995  $ids = array();
4996  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
4997  {
4998  $ids[] = $row->usr_id;
4999  }
5000 
5001  return $ids;
5002  }
5003 
5013  public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5014  {
5015  if($a_last_login !== null) $last_login = $a_last_login;
5016  else $last_login = date('Y-m-d H:i:s');
5017 
5018  global $ilDB;
5019 
5020  $query = "UPDATE usr_data SET usr_data.last_login = %s WHERE usr_data.usr_id = %s";
5021  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array($last_login, $a_usr_id) );
5022 
5023  if($affected) return $last_login;
5024  else return false;
5025  }
5026 
5027  public function resetOwner()
5028  {
5029  global $ilDB;
5030 
5031  $query = "UPDATE object_data SET owner = 0 ".
5032  "WHERE owner = ".$ilDB->quote($this->getId(),'integer');
5033  $ilDB->query($query);
5034 
5035  return true;
5036  }
5037 
5038 
5045  static function getFirstLettersOfLastnames()
5046  {
5047  global $ilDB;
5048 
5049  $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("lastname", 1, 1))." let FROM usr_data ORDER BY let";
5050  $let_set = $ilDB->query($q);
5051 
5052  $lets = array();
5053  while ($let_rec = $ilDB->fetchAssoc($let_set))
5054  {
5055  $let[$let_rec["let"]] = $let_rec["let"];
5056  }
5057  return $let;
5058  }
5059 
5060 
5061 
5065  public function isAnonymous()
5066  {
5067  return $this->getId() == ANONYMOUS_USER_ID;
5068  }
5069 } // END class ilObjUser
5070 ?>