ILIAS  Release_4_1_x_branch Revision 61804
 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 
681  public static function _lookupName($a_user_id)
682  {
683  global $ilDB;
684 
685  $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
686  array("integer"), array($a_user_id));
687  $user_rec = $ilDB->fetchAssoc($res);
688  return array("user_id" => $a_user_id,
689  "firstname" => $user_rec["firstname"],
690  "lastname" => $user_rec["lastname"],
691  "title" => $user_rec["title"],
692  "login" => $user_rec["login"]);
693  }
694 
698  function _lookupFields($a_user_id)
699  {
700  global $ilDB;
701 
702  $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
703  array("integer"), array($a_user_id));
704  $user_rec = $ilDB->fetchAssoc($res);
705  return $user_rec;
706  }
707 
711  function _lookupLogin($a_user_id)
712  {
713  return ilObjUser::_lookup($a_user_id, "login");
714  }
715 
719  function _lookupExternalAccount($a_user_id)
720  {
721  return ilObjUser::_lookup($a_user_id, "ext_account");
722  }
723 
727  public static function _lookupId($a_user_str)
728  {
729  global $ilDB;
730 
731  $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
732  array("text"), array($a_user_str));
733  $user_rec = $ilDB->fetchAssoc($res);
734  return $user_rec["usr_id"];
735  }
736 
740  function _lookupLastLogin($a_user_id)
741  {
742  return ilObjUser::_lookup($a_user_id, "last_login");
743  }
744 
745 
751  function refreshLogin()
752  {
753  global $ilDB;
754 
755  $ilDB->manipulateF("UPDATE usr_data SET ".
756  "last_login = ".$ilDB->now().
757  " WHERE usr_id = %s",
758  array("integer"), array($this->id));
759  }
760 
767  function replacePassword($new_md5)
768  {
769  global $ilDB;
770 
771  $this->passwd_type = IL_PASSWD_MD5;
772  $this->passwd = $new_md5;
773 
774  $ilDB->manipulateF("UPDATE usr_data SET ".
775  "passwd = %s ".
776  "WHERE usr_id = %s",
777  array("text", "integer"), array($this->passwd, $this->id));
778 
779  return true;
780  }
781 
790  function updatePassword($a_old, $a_new1, $a_new2)
791  {
792  global $ilDB;
793 
794  if (func_num_args() != 3)
795  {
796  return false;
797  }
798 
799  if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
800  {
801  return false;
802  }
803 
804  if ($a_new1 != $a_new2)
805  {
806  return false;
807  }
808 
809  // is catched by isset() ???
810  if ($a_new1 == "" || $a_old == "")
811  {
812  return false;
813  }
814 
815  //check old password
816  switch ($this->passwd_type)
817  {
818  case IL_PASSWD_PLAIN:
819  if ($a_old != $this->passwd)
820  {
821  return false;
822  }
823  break;
824 
825  case IL_PASSWD_MD5:
826  if (md5($a_old) != $this->passwd)
827  {
828  return false;
829  }
830  break;
831 
832  case IL_PASSWD_CRYPT:
833  if (_makeIlias2Password($a_old) != $this->passwd)
834  {
835  return false;
836  }
837  break;
838  }
839 
840  //update password
841  $this->passwd = md5($a_new1);
842  $this->passwd_type = IL_PASSWD_MD5;
843 
844  $ilDB->manipulateF("UPDATE usr_data SET ".
845  "passwd = %s ".
846  "WHERE usr_id = %s",
847  array("text", "integer"), array($this->passwd, $this->id));
848 
849  return true;
850  }
851 
859  function resetPassword($a_new1, $a_new2)
860  {
861  global $ilDB;
862 
863  if (func_num_args() != 2)
864  {
865  return false;
866  }
867 
868  if (!isset($a_new1) or !isset($a_new2))
869  {
870  return false;
871  }
872 
873  if ($a_new1 != $a_new2)
874  {
875  return false;
876  }
877 
878  //update password
879  $this->passwd = md5($a_new1);
880  $this->passwd_type = IL_PASSWD_MD5;
881 
882  $ilDB->manipulateF("UPDATE usr_data SET ".
883  "passwd = %s ".
884  "WHERE usr_id = %s",
885  array("text", "integer"),
886  array($this->passwd, $this->id));
887 
888  return true;
889  }
890 
894  function _makeIlias2Password($a_passwd)
895  {
896  return (crypt($a_passwd,substr($a_passwd,0,2)));
897  }
898 
902  function _lookupHasIlias2Password($a_user_login)
903  {
904  global $ilias, $ilDB;
905 
906  $user_set = $ilDB->queryF("SELECT i2passwd FROM usr_data ".
907  "WHERE login = %s", array("text"), array($a_user_login));
908  if ($user_rec = $ilDB->fetchAssoc($user_set))
909  {
910  if ($user_rec["i2passwd"] != "")
911  {
912  return true;
913  }
914  }
915 
916  return false;
917  }
918 
922  function _switchToIlias3Password($a_user, $a_pw)
923  {
924  global $ilias, $ilDB;
925 
926  $user_set = $ilDB->queryF("SELECT i2passwd FROM usr_data ".
927  "WHERE login = %s", array("text"), array($a_user_login));
928  if ($user_rec = $ilDB->fetchAssoc($user_set))
929  {
930  if ($user_rec["i2passwd"] == ilObjUser::_makeIlias2Password($a_pw))
931  {
932  $ilDB->manipulateF("UPDATE usr_data SET passwd = %s, i2passwd = %s".
933  "WHERE login = %s",
934  array("text", "text", "text"),
935  array(md5($a_pw), "", $a_user));
936  return true;
937  }
938  }
939 
940  return false;
941  }
942 
953  public static function _doesLoginnameExistInHistory($a_login)
954  {
955  global $ilDB;
956 
957  $res = $ilDB->queryF('
958  SELECT * FROM loginname_history
959  WHERE login = %s',
960  array('text'), array($a_login));
961 
962  return $ilDB->fetchAssoc($res) ? true : false;
963  }
964 
977  public static function _getLastHistoryDataByUserId($a_usr_id)
978  {
979  global $ilDB;
980 
981  $ilDB->setLimit(1, 0);
982  $res = $ilDB->queryF('
983  SELECT login, history_date FROM loginname_history
984  WHERE usr_id = %s ORDER BY history_date DESC',
985  array('integer'), array($a_usr_id));
986  $row = $ilDB->fetchAssoc($res);
987  if(!is_array($row) || !count($row)) throw new ilUserException('');
988 
989  return array(
990  $row['login'], $row['history_date']
991  );
992  }
993 
1001  function updateLogin($a_login)
1002  {
1003  global $ilDB, $ilSetting;
1004 
1005  if(func_num_args() != 1)
1006  {
1007  return false;
1008  }
1009 
1010  if(!isset($a_login))
1011  {
1012  return false;
1013  }
1014 
1015  // Update not necessary
1016  if($a_login == self::_lookupLogin($this->getId()))
1017  {
1018  return false;
1019  }
1020 
1021  try
1022  {
1023  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1024  }
1025  catch(ilUserException $e) { $last_history_entry = null; }
1026 
1027  // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1028  if((int)$ilSetting->get('allow_change_loginname') &&
1029  (int)$ilSetting->get('prevent_reuse_of_loginnames') &&
1031  {
1032  throw new ilUserException($this->lng->txt('loginname_already_exists'));
1033  }
1034  else if((int)$ilSetting->get('allow_change_loginname') &&
1035  (int)$ilSetting->get('loginname_change_blocking_time') &&
1036  is_array($last_history_entry) &&
1037  $last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time') > time())
1038  {
1039  include_once 'Services/Calendar/classes/class.ilDate.php';
1040  throw new ilUserException(
1041  sprintf(
1042  $this->lng->txt('changing_loginname_not_possible_info'),
1044  new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1046  new ilDateTime(($last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX))
1047  )
1048  );
1049  }
1050  else
1051  {
1052  // log old loginname in history
1053  if((int)$ilSetting->get('allow_change_loginname') &&
1054  (int)$ilSetting->get('create_history_loginname'))
1055  {
1056  ilObjUser::_writeHistory($this->getId(), self::_lookupLogin($this->getId()));
1057  }
1058 
1059  //update login
1060  $this->login = $a_login;
1061 
1062  $ilDB->manipulateF('
1063  UPDATE usr_data
1064  SET login = %s
1065  WHERE usr_id = %s',
1066  array('text', 'integer'), array($this->getLogin(), $this->getId()));
1067  }
1068 
1069  return true;
1070  }
1071 
1078  function writePref($a_keyword, $a_value)
1079  {
1080  ilObjUser::_writePref($this->id, $a_keyword, $a_value);
1081  $this->setPref($a_keyword, $a_value);
1082  }
1083 
1084 
1090  function deletePref($a_keyword)
1091  {
1092  ilObjUser::_deletePref($this->getId(), $a_keyword);
1093  }
1094 
1100  function _deletePref($a_user_id, $a_keyword)
1101  {
1102  global $ilDB;
1103 
1104  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s",
1105  array("integer", "text"), array($a_user_id, $a_keyword));
1106  }
1107 
1113  function _deleteAllPref($a_user_id)
1114  {
1115  global $ilDB;
1116 
1117  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1118  array("integer"), array($a_user_id));
1119  }
1120 
1124  function _writePref($a_usr_id, $a_keyword, $a_value)
1125  {
1126  global $ilDB;
1127 
1128  ilObjUser::_deletePref($a_usr_id, $a_keyword);
1129  if (strlen($a_value))
1130  {
1131  $ilDB->manipulateF("INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s,%s,%s)",
1132  array("integer", "text", "text"), array($a_usr_id, $a_keyword, $a_value));
1133  }
1134  }
1135 
1140  function writePrefs()
1141  {
1142  global $ilDB;
1143 
1144  ilObjUser::_deleteAllPref($this->id);
1145  foreach ($this->prefs as $keyword => $value)
1146  {
1147  ilObjUser::_writePref($this->id, $keyword, $value);
1148  }
1149  }
1150 
1157  public function getTimeZone()
1158  {
1159  if($tz = $this->getPref('user_tz'))
1160  {
1161  return $tz;
1162  }
1163  else
1164  {
1165  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1166  $settings = ilCalendarSettings::_getInstance();
1167  return $settings->getDefaultTimeZone();
1168  }
1169  }
1170 
1177  public function getTimeFormat()
1178  {
1179  if($format = $this->getPref('time_format'))
1180  {
1181  return $format;
1182  }
1183  else
1184  {
1185  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1186  $settings = ilCalendarSettings::_getInstance();
1187  return $settings->getDefaultTimeFormat();
1188  }
1189  }
1190 
1197  public function getDateFormat()
1198  {
1199  if($format = $this->getPref('date_format'))
1200  {
1201  return $format;
1202  }
1203  else
1204  {
1205  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1206  $settings = ilCalendarSettings::_getInstance();
1207  return $settings->getDefaultDateFormat();
1208  }
1209  }
1210 
1217  function setPref($a_keyword, $a_value)
1218  {
1219  if ($a_keyword != "")
1220  {
1221  $this->prefs[$a_keyword] = $a_value;
1222  }
1223  }
1224 
1230  function getPref($a_keyword)
1231  {
1232  if (array_key_exists($a_keyword, $this->prefs))
1233  {
1234  return $this->prefs[$a_keyword];
1235  }
1236  else
1237  {
1238  return FALSE;
1239  }
1240  }
1241 
1242  function _lookupPref($a_usr_id,$a_keyword)
1243  {
1244  global $ilDB;
1245 
1246  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1247  "AND keyword = ".$ilDB->quote($a_keyword, "text");
1248  $res = $ilDB->query($query);
1249 
1250  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1251  {
1252  return $row->value;
1253  }
1254  return false;
1255  }
1256 
1261  function readPrefs()
1262  {
1263  global $ilDB;
1264 
1265  if (is_array($this->prefs))
1266  {
1267  $this->oldPrefs = $this->prefs;
1268  }
1269 
1270  $this->prefs = ilObjUser::_getPreferences($this->id);
1271  }
1272 
1278  function delete()
1279  {
1280  global $rbacadmin, $ilDB;
1281 
1282  // deassign from ldap groups
1283  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1285  $mapping->deleteUser($this->getId());
1286 
1287  // remove mailbox / update sent mails
1288  include_once ("Services/Mail/classes/class.ilMailbox.php");
1289  $mailbox = new ilMailbox($this->getId());
1290  $mailbox->delete();
1291  $mailbox->updateMailsOfDeletedUser();
1292 
1293  // delete feed blocks on personal desktop
1294  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1295  $costum_block = new ilCustomBlock();
1296  $costum_block->setContextObjId($this->getId());
1297  $costum_block->setContextObjType("user");
1298  $c_blocks = $costum_block->queryBlocksForContext();
1299  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1300  foreach($c_blocks as $c_block)
1301  {
1302  if ($c_block["type"] == "pdfeed")
1303  {
1304  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1305  $fb->delete();
1306  }
1307  }
1308 
1309 
1310  // delete block settings
1311  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1313 
1314  // delete user_account
1315  $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1316  array("integer"), array($this->getId()));
1317 
1318  // delete user_prefs
1319  ilObjUser::_deleteAllPref($this->getId());
1320 
1321  // delete user_session
1322  include_once("./Services/Authentication/classes/class.ilSession.php");
1324 
1325  // remove user from rbac
1326  $rbacadmin->removeUser($this->getId());
1327 
1328  // remove bookmarks
1329  // TODO: move this to class.ilBookmarkFolder
1330  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1331  $ilDB->quote($this->getId(), "integer");
1332  $ilDB->manipulate($q);
1333 
1334  $q = "DELETE FROM bookmark_data WHERE user_id = ".
1335  $ilDB->quote($this->getId(), "integer");
1336  $ilDB->manipulate($q);
1337 
1338  // DELETE FORUM ENTRIES (not complete in the moment)
1339  include_once './Modules/Forum/classes/class.ilObjForum.php';
1340  ilObjForum::_deleteUser($this->getId());
1341 
1342  // Delete link check notify entries
1343  include_once './classes/class.ilLinkCheckNotify.php';
1345 
1346  // Delete crs entries
1347  include_once './Modules/Course/classes/class.ilObjCourse.php';
1348  ilObjCourse::_deleteUser($this->getId());
1349 
1350  // Delete user tracking
1351  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1353 
1354  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1356 
1357  // Delete Tracking data SCORM 2004 RTE
1358  include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1360 
1361  // Delete Tracking data SCORM 1.2 RTE
1362  include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1364 
1365  // remove all notifications
1366  include_once "./Services/Notification/classes/class.ilNotification.php";
1368 
1369  // Delete user defined field entries
1371 
1372  // Delete clipboard entries
1373  $this->clipboardDeleteAll();
1374 
1375  // Reset owner
1376  $this->resetOwner();
1377 
1378 
1379  // Trigger deleteUser Event
1380  global $ilAppEventHandler;
1381  $ilAppEventHandler->raise(
1382  'Services/User', 'deleteUser', array('usr_id' => $this->getId())
1383  );
1384 
1385  // delete object data
1386  parent::delete();
1387  return true;
1388  }
1389 
1399  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1400  {
1401  $this->fullname = "";
1402 
1403  if ($a_title)
1404  {
1405  $fullname = $a_title." ";
1406  }
1407  elseif ($this->utitle)
1408  {
1409  $this->fullname = $this->utitle." ";
1410  }
1411 
1412  if ($a_firstname)
1413  {
1414  $fullname .= $a_firstname." ";
1415  }
1416  elseif ($this->firstname)
1417  {
1418  $this->fullname .= $this->firstname." ";
1419  }
1420 
1421  if ($a_lastname)
1422  {
1423  return $fullname.$a_lastname;
1424  }
1425 
1426  $this->fullname .= $this->lastname;
1427  }
1428 
1443  function getFullname($a_max_strlen = 0)
1444  {
1445  if (!$a_max_strlen)
1446  {
1447  return ilUtil::stripSlashes($this->fullname);
1448  }
1449 
1450  if (strlen($this->fullname) <= $a_max_strlen)
1451  {
1452  return ilUtil::stripSlashes($this->fullname);
1453  }
1454 
1455  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1456  {
1457  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1458  }
1459 
1460  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1461  {
1462  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1463  }
1464 
1465  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1466  {
1467  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1468  }
1469 
1470  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1471  }
1472 
1473 // ### AA 03.09.01 updated page access logger ###
1480  {
1481  global $ilDB;
1482 
1483  //query
1484  $q = "SELECT * FROM lo_access ".
1485  "WHERE usr_id= ".$ilDB->quote((int) $this->id, "integer")." ".
1486  "ORDER BY timestamp DESC";
1487  $rst = $ilDB->query($q);
1488 
1489  // fill array
1490  $result = array();
1491  while($record = $ilDB->fetchObject($rst))
1492  {
1493  $result[] = array(
1494  "timestamp" => $record->timestamp,
1495  "usr_id" => $record->usr_id,
1496  "lm_id" => $record->lm_id,
1497  "obj_id" => $record->obj_id,
1498  "lm_title" => $record->lm_title);
1499  }
1500  return $result;
1501  }
1502 
1503 // ### AA 03.09.01 updated page access logger ###
1509  function getLessons()
1510  {
1511  global $ilDB;
1512 
1513  //query
1514  $q = "SELECT * FROM lo_access ".
1515  "WHERE usr_id= ".$ilDB->quote((int) $this->id, "integer")." ";
1516  $rst = $ilDB->query($q);
1517 
1518  // fill array
1519  $result = array();
1520  while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
1521  {
1522  $result[] = array(
1523  "timestamp" => $record->timestamp,
1524  "usr_id" => $record->usr_id,
1525  "lm_id" => $record->lm_id,
1526  "obj_id" => $record->obj_id,
1527  "lm_title" => $record->lm_title);
1528  }
1529  return $result;
1530  }
1531 
1540  public static function _hasAcceptedAgreement($a_username)
1541  {
1542  global $ilDB;
1543 
1544  if($a_username == 'root')
1545  {
1546  return true;
1547  }
1548 
1549  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
1550  "WHERE login = %s AND NOT agree_date IS NULL",
1551  array("text"), array($a_username));
1552  return $ilDB->fetchAssoc($res) ? true : false;
1553  }
1554 
1555 
1560  {
1561  if ($this->agree_date != null || $this->login == "root")
1562  {
1563  return true;
1564  }
1565  return false;
1566  }
1567 
1573  function setLogin($a_str)
1574  {
1575  $this->login = $a_str;
1576  }
1577 
1582  function getLogin()
1583  {
1584  return $this->login;
1585  }
1586 
1592  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1593  {
1594  $this->passwd = $a_str;
1595  $this->passwd_type = $a_type;
1596  }
1597 
1605  function getPasswd()
1606  {
1607  return $this->passwd;
1608  }
1615  function getPasswdType()
1616  {
1617  return $this->passwd_type;
1618  }
1619 
1625  function setGender($a_str)
1626  {
1627  $this->gender = substr($a_str,-1);
1628  }
1629 
1634  function getGender()
1635  {
1636  return $this->gender;
1637  }
1638 
1646  function setUTitle($a_str)
1647  {
1648  $this->utitle = $a_str;
1649  }
1650 
1657  function getUTitle()
1658  {
1659  return $this->utitle;
1660  }
1661 
1667  function setFirstname($a_str)
1668  {
1669  $this->firstname = $a_str;
1670  }
1671 
1676  function getFirstname()
1677  {
1678  return $this->firstname;
1679  }
1680 
1686  function setLastname($a_str)
1687  {
1688  $this->lastname = $a_str;
1689  }
1690 
1695  function getLastname()
1696  {
1697  return $this->lastname;
1698  }
1699 
1705  function setInstitution($a_str)
1706  {
1707  $this->institution = $a_str;
1708  }
1709 
1714  function getInstitution()
1715  {
1716  return $this->institution;
1717  }
1718 
1724  function setDepartment($a_str)
1725  {
1726  $this->department = $a_str;
1727  }
1728 
1733  function getDepartment()
1734  {
1735  return $this->department;
1736  }
1737 
1743  function setStreet($a_str)
1744  {
1745  $this->street = $a_str;
1746  }
1747 
1752  function getStreet()
1753  {
1754  return $this->street;
1755  }
1756 
1762  function setCity($a_str)
1763  {
1764  $this->city = $a_str;
1765  }
1766 
1771  function getCity()
1772  {
1773  return $this->city;
1774  }
1775 
1781  function setZipcode($a_str)
1782  {
1783  $this->zipcode = $a_str;
1784  }
1785 
1790  function getZipcode()
1791  {
1792  return $this->zipcode;
1793  }
1794 
1801  function setCountry($a_str)
1802  {
1803  $this->country = $a_str;
1804  }
1805 
1811  function getCountry()
1812  {
1813  return $this->country;
1814  }
1815 
1821  function setSelectedCountry($a_val)
1822  {
1823  $this->sel_country = $a_val;
1824  }
1825 
1832  {
1833  return $this->sel_country;
1834  }
1835 
1841  function setPhoneOffice($a_str)
1842  {
1843  $this->phone_office = $a_str;
1844  }
1845 
1850  function getPhoneOffice()
1851  {
1852  return $this->phone_office;
1853  }
1854 
1860  function setPhoneHome($a_str)
1861  {
1862  $this->phone_home = $a_str;
1863  }
1864 
1869  function getPhoneHome()
1870  {
1871  return $this->phone_home;
1872  }
1873 
1879  function setPhoneMobile($a_str)
1880  {
1881  $this->phone_mobile = $a_str;
1882  }
1883 
1888  function getPhoneMobile()
1889  {
1890  return $this->phone_mobile;
1891  }
1892 
1898  function setFax($a_str)
1899  {
1900  $this->fax = $a_str;
1901  }
1902 
1907  function getFax()
1908  {
1909  return $this->fax;
1910  }
1911 
1917  function setClientIP($a_str)
1918  {
1919  $this->client_ip = $a_str;
1920  }
1921 
1926  function getClientIP()
1927  {
1928  return $this->client_ip;
1929  }
1930 
1936  function setMatriculation($a_str)
1937  {
1938  $this->matriculation = $a_str;
1939  }
1940 
1945  function getMatriculation()
1946  {
1947  return $this->matriculation;
1948  }
1949 
1956  public static function lookupMatriculation($a_usr_id)
1957  {
1958  global $ilDB;
1959 
1960  $query = "SELECT matriculation FROM usr_data ".
1961  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1962  $res = $ilDB->query($query);
1963  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1964  return $row->matriculation ? $row->matriculation : '';
1965  }
1966 
1972  function setEmail($a_str)
1973  {
1974  $this->email = $a_str;
1975  }
1976 
1981  function getEmail()
1982  {
1983  return $this->email;
1984  }
1985 
1991  function setHobby($a_str)
1992  {
1993  $this->hobby = $a_str;
1994  }
1995 
2000  function getHobby()
2001  {
2002  return $this->hobby;
2003  }
2004 
2010  function setLanguage($a_str)
2011  {
2012  $this->setPref("language",$a_str);
2013  unset($_SESSION['lang']);
2014  }
2015 
2021  function getLanguage()
2022  {
2023  return $this->prefs["language"];
2024  }
2025 
2034  function setDiskQuota($a_disk_quota)
2035  {
2036  $this->setPref("disk_quota",$a_disk_quota);
2037  }
2038 
2048  function getDiskQuota()
2049  {
2050  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
2051  }
2052 
2053  public function setLastPasswordChangeTS($a_last_password_change_ts)
2054  {
2055  $this->last_password_change_ts = $a_last_password_change_ts;
2056  }
2057 
2058  public function getLastPasswordChangeTS()
2059  {
2061  }
2062 
2063 
2064  public static function _lookupLanguage($a_usr_id)
2065  {
2066  global $ilDB;
2067 
2068  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
2069  $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
2070  $ilDB->quote('language', "text");
2071  $r = $ilDB->query($q);
2072 
2073  while($row = $ilDB->fetchAssoc($r))
2074  {
2075  return $row['value'];
2076  }
2077  return 'en';
2078  }
2079 
2080 
2081  function _checkPassword($a_usr_id, $a_pw)
2082  {
2083  global $ilDB;
2084 
2085  $pw = ilObjUser::_lookup($a_usr_id, "passwd");
2086  if ($pw == md5($a_pw))
2087  {
2088  return true;
2089  }
2090  return false;
2091  }
2092 
2093  function _writeExternalAccount($a_usr_id, $a_ext_id)
2094  {
2095  global $ilDB;
2096 
2097  $ilDB->manipulateF("UPDATE usr_data ".
2098  " SET ext_account = %s WHERE usr_id = %s",
2099  array("text", "integer"),
2100  array($a_ext_id, $a_usr_id));
2101  }
2102 
2103  function _writeAuthMode($a_usr_id, $a_auth_mode)
2104  {
2105  global $ilDB;
2106 
2107  $ilDB->manipulateF("UPDATE usr_data ".
2108  " SET auth_mode = %s WHERE usr_id = %s",
2109  array("text", "integer"),
2110  array($a_auth_mode, $a_usr_id));
2111  }
2112 
2118  {
2119  return $_SESSION['lang'];
2120  }
2121 
2127  function setLastLogin($a_str)
2128  {
2129  $this->last_login = $a_str;
2130  }
2131 
2137  function getLastLogin()
2138  {
2139  return $this->last_login;
2140  }
2141 
2147  function setLastUpdate($a_str)
2148  {
2149  $this->last_update = $a_str;
2150  }
2151  function getLastUpdate()
2152  {
2153  return $this->last_update;
2154  }
2155 
2161  function setComment($a_str)
2162  {
2163  $this->referral_comment = $a_str;
2164  }
2165 
2170  function getComment()
2171  {
2172  return $this->referral_comment;
2173  }
2174 
2181  function setApproveDate($a_str)
2182  {
2183  $this->approve_date = $a_str;
2184  }
2185 
2191  function getApproveDate()
2192  {
2193  return $this->approve_date;
2194  }
2195 
2196  // BEGIN DiskQuota: show when user accepted user agreement
2202  function getAgreeDate()
2203  {
2204  return $this->agree_date;
2205  }
2212  function setAgreeDate($a_str)
2213  {
2214  $this->agree_date = $a_str;
2215  }
2216  // END DiskQuota: show when user accepted user agreement
2217 
2224  function setActive($a_active, $a_owner = 0)
2225  {
2226  $this->setOwner($a_owner);
2227 
2228  if ($a_active)
2229  {
2230  $this->active = 1;
2231  $this->setApproveDate(date('Y-m-d H:i:s'));
2232  $this->setOwner($a_owner);
2233  }
2234  else
2235  {
2236  $this->active = 0;
2237  $this->setApproveDate(null);
2238  }
2239  }
2240 
2245  function getActive()
2246  {
2247  return $this->active;
2248  }
2249 
2253  public function _lookupActive($a_usr_id)
2254  {
2255  global $ilDB;
2256 
2257  $query = 'SELECT usr_id FROM usr_data '.
2258  'WHERE active = '.$ilDB->quote(1,'integer').' '.
2259  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
2260  $res = $ilDB->query($query);
2261  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2262  {
2263  return true;
2264  }
2265  return false;
2266  }
2267 
2273  function syncActive()
2274  {
2275  global $ilAuth;
2276 
2277  $storedActive = 0;
2278  if ($this->getStoredActive($this->id))
2279  {
2280  $storedActive = 1;
2281  }
2282 
2283  $currentActive = 0;
2284  if ($this->active)
2285  {
2286  $currentActive = 1;
2287  }
2288 
2289  if ((!empty($storedActive) && empty($currentActive)) ||
2290  (empty($storedActive) && !empty($currentActive)))
2291  {
2292  $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2293  }
2294  }
2295 
2302  function getStoredActive($a_id)
2303  {
2304  $active = ilObjUser::_lookup($a_id, "active");
2305  return $active ? true : false;
2306  }
2307 
2313  function setSkin($a_str)
2314  {
2315  // TODO: exception handling (dir exists)
2316  $this->skin = $a_str;
2317  }
2318 
2319  function setTimeLimitOwner($a_owner)
2320  {
2321  $this->time_limit_owner = $a_owner;
2322  }
2324  {
2325  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2326  }
2327  function setTimeLimitFrom($a_from)
2328  {
2329  $this->time_limit_from = $a_from;
2330  }
2331  function getTimeLimitFrom()
2332  {
2333  return $this->time_limit_from ? $this->time_limit_from : time();
2334  }
2335  function setTimeLimitUntil($a_until)
2336  {
2337  $this->time_limit_until = $a_until;
2338  }
2340  {
2341  return $this->time_limit_until ? $this->time_limit_until : time();
2342  }
2343  function setTimeLimitUnlimited($a_unlimited)
2344  {
2345  $this->time_limit_unlimited = $a_unlimited;
2346  }
2348  {
2349  return $this->time_limit_unlimited;
2350  }
2351  function setTimeLimitMessage($a_time_limit_message)
2352  {
2353  return $this->time_limit_message = $a_time_limit_message;
2354  }
2356  {
2357  return $this->time_limit_message;
2358  }
2359 
2360  public function setLoginAttempts($a_login_attempts)
2361  {
2362  $this->login_attempts = $a_login_attempts;
2363  }
2364 
2365  public function getLoginAttempts()
2366  {
2367  return $this->login_attempts;
2368  }
2369 
2370 
2371  function checkTimeLimit()
2372  {
2373  if($this->getTimeLimitUnlimited())
2374  {
2375  return true;
2376  }
2377  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2378  {
2379  return true;
2380  }
2381  return false;
2382  }
2383  function setProfileIncomplete($a_prof_inc)
2384  {
2385  $this->profile_incomplete = (boolean) $a_prof_inc;
2386  }
2388  {
2389  return $this->profile_incomplete;
2390  }
2391 
2392  public function isPasswordChangeDemanded()
2393  {
2394  //error_reporting(E_ALL);
2395  if( $this->id == ANONYMOUS_USER_ID || $this->id == SYSTEM_USER_ID )
2396  return false;
2397 
2398  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2399  $security = ilSecuritySettings::_getInstance();
2400 
2402  && $security->isPasswordChangeOnFirstLoginEnabled()
2403  && $this->getLastPasswordChangeTS() == 0
2404  ){
2405  return true;
2406  }
2407  else return false;
2408  }
2409 
2410  public function isPasswordExpired()
2411  {
2412  //error_reporting(E_ALL);
2413  if($this->id == ANONYMOUS_USER_ID) return false;
2414 
2415  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2416  $security = ilSecuritySettings::_getInstance();
2417  if( $security->getAccountSecurityMode() == ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED &&
2418  $this->getLastPasswordChangeTS() > 0 )
2419  {
2420  $max_pass_age = $security->getPasswordMaxAge();
2421  if( $max_pass_age > 0 )
2422  {
2423  $max_pass_age_ts = ( $max_pass_age * 86400 );
2424  $pass_change_ts = $this->getLastPasswordChangeTS();
2425  $current_ts = time();
2426 
2427  if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2428  return true;
2429  }
2430  }
2431  return false;
2432  }
2433 
2434  public function getPasswordAge()
2435  {
2436  $current_ts = time();
2437  $pass_change_ts = $this->getLastPasswordChangeTS();
2438  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2439  return $password_age;
2440  }
2441 
2442  public function setLastPasswordChangeToNow()
2443  {
2444  global $ilDB;
2445 
2446  $this->setLastPasswordChangeTS( time() );
2447 
2448  $query = "UPDATE usr_data SET usr_data.last_password_change = %s " .
2449  "WHERE usr_data.usr_id = %s";
2450  $affected = $ilDB->manipulateF($query,
2451  array('integer','integer'),
2452  array($this->getLastPasswordChangeTS(),$this->id));
2453  if($affected) return true;
2454  else return false;
2455  }
2456 
2457  public function resetLastPasswordChange()
2458  {
2459  global $ilDB;
2460 
2461  $query = "UPDATE usr_data SET usr_data.last_password_change = 0 " .
2462  "WHERE usr_data.usr_id = %s";
2463  $affected = $ilDB->manipulateF( $query, array('integer'),
2464  array($this->getId()) );
2465  if($affected) return true;
2466  else return false;
2467  }
2468 
2474  function setLatitude($a_latitude)
2475  {
2476  $this->latitude = $a_latitude;
2477  }
2478 
2484  function getLatitude()
2485  {
2486  return $this->latitude;
2487  }
2488 
2494  function setLongitude($a_longitude)
2495  {
2496  $this->longitude = $a_longitude;
2497  }
2498 
2504  function getLongitude()
2505  {
2506  return $this->longitude;
2507  }
2508 
2514  function setLocationZoom($a_locationzoom)
2515  {
2516  $this->loc_zoom = $a_locationzoom;
2517  }
2518 
2524  function getLocationZoom()
2525  {
2526  return $this->loc_zoom;
2527  }
2528 
2529  function &getAppliedUsers()
2530  {
2531  $this->applied_users = array();
2532  $this->__readAppliedUsers($this->getId());
2533 
2534  return $this->applied_users ? $this->applied_users : array();
2535  }
2536 
2537  function isChild($a_usr_id)
2538  {
2539  if($a_usr_id == $this->getId())
2540  {
2541  return true;
2542  }
2543 
2544  $this->applied_users = array();
2545  $this->__readAppliedUsers($this->getId());
2546 
2547  return in_array($a_usr_id,$this->applied_users);
2548  }
2549 
2550  function __readAppliedUsers($a_parent_id)
2551  {
2552  global $ilDB;
2553 
2554  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2555  "WHERE time_limit_owner = %s",
2556  array("integer"),
2557  array($a_parent_id));
2558  while ($row = $ilDB->fetchObject($res))
2559  {
2560  $this->applied_users[] = $row->usr_id;
2561 
2562  // recursion
2563  $this->__readAppliedUsers($row->usr_id);
2564  }
2565  return true;
2566  }
2567 
2568  /*
2569  * check user id with login name
2570  * @access public
2571  */
2572  function checkUserId()
2573  {
2574  global $ilDB,$ilAuth, $ilSetting;
2575 
2578  if ($id > 0)
2579  {
2580  // check for simultaneous logins, except the user is the anonymous one
2581  if( $id != ANONYMOUS_USER_ID && (int)$ilSetting->get('ps_prevent_simultaneous_logins') == 1 )
2582  {
2583  $res = $ilDB->queryf('
2584  SELECT * FROM usr_session WHERE user_id = %s AND expires > %s',
2585  array('integer', 'integer'),
2586  array($id, time()));
2587  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2588  {
2589  $ilAuth->logout();
2590  @session_destroy();
2591  ilUtil::redirect('login.php?simultaneous_login=true');
2592  exit();
2593  }
2594  }
2595 
2596  return $id;
2597  }
2598  return false;
2599  }
2600 
2604  private static function getLoginFromAuth() {
2605  global $ilAuth;
2606 
2607  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2608  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2610  {
2611  require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2612  require_once ('Services/Database/classes/class.ilAuthContainerMDB2.php');
2613  $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2614  }
2615  else
2616  {
2617  $login =$ilAuth->getUsername();
2618  }
2619 
2620  return $login;
2621  }
2622 
2623  /*
2624  * check to see if current user has been made active
2625  * @access public
2626  * @return true if active, otherwise false
2627  */
2629  {
2630  global $ilDB,$ilAuth;
2631 
2633  $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2634  array("text"),
2635  array($login));
2636  //query has got a result
2637  if ($rec = $ilDB->fetchAssoc($set))
2638  {
2639  if ($rec["active"])
2640  {
2641  return true;
2642  }
2643  }
2644 
2645  return false;
2646  }
2647 
2648  /*
2649  * STATIC METHOD
2650  * get the user_id of a login name
2651  * @param string login name
2652  * @return integer id of user
2653  * @static
2654  * @access public
2655  */
2656  function getUserIdByLogin($a_login)
2657  {
2658  return (int) ilObjUser::_lookupId($a_login);
2659  }
2660 
2669  function _getUserIdsByEmail($a_email)
2670  {
2671  global $ilias, $ilDB;
2672 
2673  $res = $ilDB->queryF("SELECT login FROM usr_data ".
2674  "WHERE email = %s and active = 1",
2675  array("text"),
2676  array($a_email));
2677  $ids = array ();
2678  while($row = $ilDB->fetchObject($res))
2679  {
2680  $ids[] = $row->login;
2681  }
2682 
2683  return $ids;
2684  }
2685 
2686 
2687 
2696  function getUserIdByEmail($a_email)
2697  {
2698  global $ilDB;
2699 
2700  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2701  "WHERE email = %s", array("text"), array($a_email));
2702 
2703  $row = $ilDB->fetchObject($res);
2704  return $row->usr_id ? $row->usr_id : 0;
2705  }
2706 
2707  /*
2708  * STATIC METHOD
2709  * get the login name of a user_id
2710  * @param integer id of user
2711  * @return string login name; false if not found
2712  * @static
2713  * @access public
2714  */
2715  function getLoginByUserId($a_userid)
2716  {
2717  $login = ilObjUser::_lookupLogin($a_userid);
2718  return $login ? $login : false;
2719  }
2720 
2731  static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2732  {
2733  global $ilias, $ilDB, $ilLog;
2734 
2735 
2736  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2737 
2738  $without_anonymous_users = true;
2739 
2740  // determine join filter
2741  $join_filter = " WHERE ";
2742  if ($filter_settings !== FALSE && strlen($filter_settings))
2743  {
2744  switch ($filter_settings)
2745  {
2746  case 3:
2747  // show only users without courses
2748  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.usr_id IS NULL AND ";
2749  break;
2750  case 5:
2751  // show only users with a certain course membership
2752  $ref_id = $_SESSION["user_filter_data"];
2753  if ($ref_id)
2754  {
2755  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.obj_id = ".
2756  "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2757  }
2758  break;
2759  case 6:
2760  global $rbacreview;
2761  $ref_id = $_SESSION["user_filter_data"];
2762  if ($ref_id)
2763  {
2764  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2765  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2766  if (is_array($local_roles) && count($local_roles))
2767  {
2768  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2769  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2770  }
2771  }
2772  break;
2773  case 7:
2774  global $rbacreview;
2775  $rol_id = $_SESSION["user_filter_data"];
2776  if ($rol_id)
2777  {
2778  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2779  $ilDB->quote($rol_id, "integer")." AND ";
2780  $without_anonymous_users = false;
2781  }
2782  break;
2783  }
2784  }
2785  // This is a temporary hack to search users by their role
2786  // See Mantis #338. This is a hack due to Mantis #337.
2787  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2788  {
2789  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2790  "FROM object_data,rbac_ua,usr_data ".
2791  "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2792  " AND object_data.type = 'role' ".
2793  "AND rbac_ua.rol_id = object_data.obj_id ".
2794  "AND usr_data.usr_id = rbac_ua.usr_id ".
2795  "AND rbac_ua.usr_id != ".$illDB->quote(ANONYMOUS_USER_ID, "integer");
2796  }
2797  else
2798  {
2799  $query.= $join_filter.
2800  "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2801  "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2802  "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2803  "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2804 
2805  if ($filter_settings !== FALSE && strlen($filter_settings))
2806  {
2807  switch ($filter_settings)
2808  {
2809  case 0:
2810  $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2811  break;
2812  case 1:
2813  $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2814  break;
2815  case 2:
2816  $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2817  break;
2818  case 4:
2819  $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"]));
2820  $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2821  break;
2822  }
2823  }
2824 
2825  if ($without_anonymous_users)
2826  {
2827  $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2828  }
2829 
2830  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2831  {
2832  $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2833  }
2834 
2835  }
2836  $ilLog->write($query);
2837  $res = $ilDB->query($query);
2838  while ($row = $ilDB->fetchObject($res))
2839  {
2840  $users[] = array(
2841  "usr_id" => $row->usr_id,
2842  "login" => $row->login,
2843  "firstname" => $row->firstname,
2844  "lastname" => $row->lastname,
2845  "email" => $row->email,
2846  "active" => $row->active);
2847  $ids[] = $row->usr_id;
2848  }
2849  if ($a_return_ids_only)
2850  return $ids ? $ids : array();
2851  else
2852  return $users ? $users : array();
2853  }
2854 
2864  {
2865  global $ilDB;
2866 
2867  $res = $ilDB->query("SELECT login FROM usr_data");
2868  while($row = $ilDB->fetchObject($res))
2869  {
2870  $logins[] = $row->login;
2871  }
2872  return $logins ? $logins : array();
2873  }
2874 
2883  public static function _readUsersProfileData($a_user_ids)
2884  {
2885  global $ilDB;
2886  $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2887  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2888  while ($row = $ilDB->fetchAssoc($res))
2889  {
2890  $user_data["$row[usr_id]"] = $row;
2891  }
2892  return $user_data ? $user_data : array();
2893  }
2894 
2903  function _getAllUserData($a_fields = NULL, $active =-1)
2904  {
2905  global $ilDB;
2906 
2907  $result_arr = array();
2908  $types = array();
2909  $values = array();
2910 
2911  if ($a_fields !== NULL and is_array($a_fields))
2912  {
2913  if (count($a_fields) == 0)
2914  {
2915  $select = "*";
2916  }
2917  else
2918  {
2919  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2920  unset($a_fields[$usr_id_field]);
2921 
2922  $select = implode(",",$a_fields).",usr_data.usr_id";
2923  // online time
2924  if(in_array('online_time',$a_fields))
2925  {
2926  $select .= ",ut_online.online_time ";
2927  }
2928  }
2929 
2930  $q = "SELECT ".$select." FROM usr_data ";
2931 
2932  // Add online_time if desired
2933  // Need left join here to show users that never logged in
2934  if(in_array('online_time',$a_fields))
2935  {
2936  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2937  }
2938 
2939  switch ($active)
2940  {
2941  case 0:
2942  case 1:
2943  $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2944  break;
2945  case 2:
2946  $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2947  break;
2948  case 3:
2949  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2950  $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2951  $r = $ilDB->query($qtemp);
2952  $course_users = array();
2953  while ($row = $ilDB->fetchAssoc($r))
2954  {
2955  array_push($course_users, $row["usr_id"]);
2956  }
2957  if (count($course_users))
2958  {
2959  $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2960  }
2961  else
2962  {
2963  return $result_arr;
2964  }
2965  break;
2966  case 4:
2967  $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"]));
2968  $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2969  break;
2970  case 5:
2971  $ref_id = $_SESSION["user_filter_data"];
2972  if ($ref_id)
2973  {
2974  $q .= " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id ".
2975  "WHERE crs_members.obj_id = (SELECT obj_id FROM object_reference ".
2976  "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2977  }
2978  break;
2979  case 6:
2980  global $rbacreview;
2981  $ref_id = $_SESSION["user_filter_data"];
2982  if ($ref_id)
2983  {
2984  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2985  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2986  if (is_array($local_roles) && count($local_roles))
2987  {
2988  $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2989  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2990  }
2991  }
2992  break;
2993  case 7:
2994  $rol_id = $_SESSION["user_filter_data"];
2995  if ($rol_id)
2996  {
2997  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2998  $ilDB->quote($rol_id, "integer");
2999  }
3000  break;
3001  }
3002  $r = $ilDB->query($q);
3003 
3004  while ($row = $ilDB->fetchAssoc($r))
3005  {
3006  $result_arr[] = $row;
3007  }
3008  }
3009 
3010  return $result_arr;
3011  }
3012 
3016  function _getNumberOfUsersForStyle($a_skin, $a_style)
3017  {
3018  global $ilDB;
3019 
3020  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
3021  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3022  " AND up1.value= ".$ilDB->quote($a_style, "text").
3023  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3024  " AND up2.value= ".$ilDB->quote($a_skin, "text").
3025  " AND up1.usr_id = up2.usr_id ";
3026 
3027  $cnt_set = $ilDB->query($q);
3028 
3029  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
3030 
3031  return $cnt_rec["cnt"];
3032  }
3033 
3038  {
3039  global $ilDB;
3040 
3041  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
3042  " WHERE up1.keyword = ".$ilDB->quote("style", "text").
3043  " AND up2.keyword = ".$ilDB->quote("skin", "text").
3044  " AND up1.usr_id = up2.usr_id";
3045 
3046  $sty_set = $ilDB->query($q);
3047 
3048  $styles = array();
3049  while($sty_rec = $ilDB->fetchAssoc($sty_set))
3050  {
3051  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
3052  }
3053 
3054  return $styles;
3055  }
3056 
3060  function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3061  {
3062  global $ilDB;
3063 
3064  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
3065  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3066  " AND up1.value= ".$ilDB->quote($a_from_style, "text").
3067  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3068  " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
3069  " AND up1.usr_id = up2.usr_id ";
3070 
3071  $usr_set = $ilDB->query($q);
3072 
3073  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3074  {
3075  ilObjUser::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3076  ilObjUser::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3077  }
3078  }
3079 
3080 
3090  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3091  {
3092  global $ilDB;
3093 
3094  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3095  "item_id = %s AND type = %s AND user_id = %s",
3096  array("integer", "text", "integer"),
3097  array($a_item_id, $a_type, $a_usr_id));
3098 
3099  // only insert if item is not already on desktop
3100  if (!$ilDB->fetchAssoc($item_set))
3101  {
3102  $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3103  " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3104  array($a_item_id,$a_type,$a_usr_id,$a_par));
3105  }
3106 
3107  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3109  }
3110 
3118  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3119  {
3120  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3121  }
3122 
3131  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3132  {
3133  global $ilDB;
3134 
3135  $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3136  " WHERE item_id = %s AND type = %s AND user_id = %s",
3137  array("text", "integer", "text", "integer"),
3138  array($a_par, $a_item_id, $a_type, $this->getId()));
3139  }
3140 
3141 
3151  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3152  {
3153  global $ilDB;
3154 
3155  $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3156  " item_id = %s AND type = %s AND user_id = %s",
3157  array("integer", "text", "integer"),
3158  array($a_item_id, $a_type, $a_usr_id));
3159 
3160  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3162  }
3163 
3171  function dropDesktopItem($a_item_id, $a_type)
3172  {
3173  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3174  }
3175 
3182  static function _removeItemFromDesktops($a_id)
3183  {
3184  global $ilDB;
3185 
3186  $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3187  array("integer"), array($a_id));
3188 
3189  $users = array();
3190 
3191  while ($row = $ilDB->fetchObject($r))
3192  {
3193  $users[] = $row->user_id;
3194  } // while
3195 
3196  if (count($users) > 0)
3197  {
3198  $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3199  array("integer"), array($a_id));
3200  }
3201 
3202  return $users;
3203  }
3204 
3214  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3215  {
3216  global $ilDB;
3217 
3218  if (self::$is_desktop_item_loaded[$a_usr_id.":".$a_item_id])
3219  {
3220  return self::$is_desktop_item_cache[$a_usr_id.":".$a_item_id.":".$a_type];
3221  }
3222  $item_set = $ilDB->queryF("SELECT item_id FROM desktop_item WHERE ".
3223  "item_id = %s AND type = %s AND user_id = %s",
3224  array("integer", "text", "integer"),
3225  array($a_item_id, $a_type, $a_usr_id));
3226 
3227  if ($ilDB->fetchAssoc($item_set))
3228  {
3229  return true;
3230  }
3231  else
3232  {
3233  return false;
3234  }
3235  }
3236 
3243  static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3244  {
3245  global $ilDB;
3246 
3247  if (!is_array($a_item_ids))
3248  {
3249  return;
3250  }
3251 
3252  $item_ids = array();
3253  foreach ($a_item_ids as $id)
3254  {
3255  if (!self::$is_desktop_item_loaded[$a_usr_id.":".$id])
3256  {
3257  $item_ids[] = $id;
3258  }
3259  self::$is_desktop_item_loaded[$a_usr_id.":".$id] = true;
3260  }
3261 
3262  if (count($item_ids) > 0)
3263  {
3264  $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE ".
3265  $ilDB->in("item_id", $item_ids, false, "integer").
3266  " AND user_id = ".$ilDB->quote($a_usr_id, "integer"));
3267  while ($r = $ilDB->fetchAssoc($item_set))
3268  {
3269  self::$is_desktop_item_cache[$a_usr_id.":".$r["item_id"].":".$r["type"]]
3270  = true;
3271  }
3272  }
3273  }
3274 
3282  function isDesktopItem($a_item_id, $a_type)
3283  {
3284  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3285  }
3286 
3287  function getDesktopItems($a_types = "")
3288  {
3289  return $this->_lookupDesktopItems($this->getId(), $a_types);
3290  }
3291 
3298  static function _lookupDesktopItems($user_id, $a_types = "")
3299  {
3300  global $ilUser, $rbacsystem, $tree, $ilDB;
3301 
3302  if ($a_types == "")
3303  {
3304  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3305  " FROM desktop_item it, object_reference oref ".
3306  ", object_data obj".
3307  " WHERE ".
3308  "it.item_id = oref.ref_id AND ".
3309  "oref.obj_id = obj.obj_id AND ".
3310  "it.user_id = %s", array("integer"), array($user_id));
3311  $items = array();
3312  while ($item_rec = $ilDB->fetchAssoc($item_set))
3313  {
3314  if ($tree->isInTree($item_rec["ref_id"])
3315  && $item_rec["type"] != "rolf")
3316  {
3317  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3318  $par_left = $tree->getLeftValue($parent_ref);
3319  $par_left = sprintf("%010d", $par_left);
3320 
3321 
3322  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3323  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3324  $items[$par_left.$title.$item_rec["ref_id"]] =
3325  array("ref_id" => $item_rec["ref_id"],
3326  "obj_id" => $item_rec["obj_id"],
3327  "type" => $item_rec["type"],
3328  "title" => $title,
3329  "description" => $desc,
3330  "parent_ref" => $parent_ref);
3331  }
3332  }
3333  ksort($items);
3334  }
3335  else
3336  {
3337  if (!is_array($a_types))
3338  {
3339  $a_types = array($a_types);
3340  }
3341  $items = array();
3342  $foundsurveys = array();
3343  foreach($a_types as $a_type)
3344  {
3345  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3346  ", object_data obj WHERE ".
3347  "it.item_id = oref.ref_id AND ".
3348  "oref.obj_id = obj.obj_id AND ".
3349  "it.type = %s AND ".
3350  "it.user_id = %s ".
3351  "ORDER BY title",
3352  array("text", "integer"),
3353  array($a_type, $user_id));
3354 
3355  while ($item_rec = $ilDB->fetchAssoc($item_set))
3356  {
3357  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3358  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3359  $items[$title.$a_type.$item_rec["ref_id"]] =
3360  array("ref_id" => $item_rec["ref_id"],
3361  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3362  "title" => $title, "description" => $desc);
3363  }
3364 
3365  }
3366  ksort($items);
3367  }
3368  return $items;
3369  }
3370 
3376 
3384  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3385  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3386  {
3387  global $ilDB;
3388 
3389  if ($a_time == 0)
3390  {
3391  $a_time = date("Y-m-d H:i:s", time());
3392  }
3393 
3394  $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3395  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3396  array("integer", "integer", "text", "integer"),
3397  array(0, $a_item_id, $a_type, $this->getId()));
3398 
3399  // only insert if item is not already in clipboard
3400  if (!$d = $item_set->fetchRow())
3401  {
3402  $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3403  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3404  " (%s,%s,%s,%s,%s,%s,%s)",
3405  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3406  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3407  }
3408  else
3409  {
3410  $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3411  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3412  array("timestamp", "integer", "integer", "text"),
3413  array($a_time, $this->getId(), $a_item_id, $a_type));
3414  }
3415  }
3416 
3420  function addToPCClipboard($a_content, $a_time, $a_nr)
3421  {
3422  global $ilDB;
3423  if ($a_time == 0)
3424  {
3425  $a_time = date("Y-m-d H:i:s", time());
3426  }
3427  $ilDB->insert("personal_pc_clipboard", array(
3428  "user_id" => array("integer", $this->getId()),
3429  "content" => array("clob", $a_content),
3430  "insert_time" => array("timestamp", $a_time),
3431  "order_nr" => array("integer", $a_nr)
3432  ));
3433  }
3434 
3439  {
3440  global $ilDB;
3441 
3442  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3443  " WHERE user_id = %s", array("integer"), array($this->getId()));
3444  $row = $ilDB->fetchAssoc($set);
3445 
3446  $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3447  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3448  array("integer", "timestamp"),
3449  array($this->getId(), $row["mtime"]));
3450  $content = array();
3451  while ($row = $ilDB->fetchAssoc($set))
3452  {
3453  $content[] = $row["content"];
3454  }
3455 
3456  return $content;
3457  }
3458 
3462  function clipboardHasObjectsOfType($a_type)
3463  {
3464  global $ilDB;
3465 
3466  $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3467  "parent = %s AND type = %s AND user_id = %s",
3468  array("integer", "text", "integer"),
3469  array(0, $a_type, $this->getId()));
3470  if ($rec = $ilDB->fetchAssoc($set))
3471  {
3472  return true;
3473  }
3474 
3475  return false;
3476  }
3477 
3482  {
3483  global $ilDB;
3484 
3485  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3486  "type = %s AND user_id = %s",
3487  array("text", "integer"),
3488  array($a_type, $this->getId()));
3489  }
3490 
3495  {
3496  global $ilDB;
3497 
3498  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3499  "user_id = %s", array("integer"), array($this->getId()));
3500  }
3501 
3505  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3506  {
3507  global $ilDB;
3508 
3509  $par = "";
3510  if ($a_top_nodes_only)
3511  {
3512  $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3513  }
3514 
3515  $type_str = ($a_type != "")
3516  ? " AND type = ".$ilDB->quote($a_type, "text")." "
3517  : "";
3518  $q = "SELECT * FROM personal_clipboard WHERE ".
3519  "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3520  $type_str.$par.
3521  " ORDER BY order_nr";
3522  $objs = $ilDB->query($q);
3523  $objects = array();
3524  while ($obj = $ilDB->fetchAssoc($objs))
3525  {
3526  if ($obj["type"] == "mob")
3527  {
3528  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3529  }
3530  if ($obj["type"] == "incl")
3531  {
3532  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3533  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3534  }
3535  $objects[] = array ("id" => $obj["item_id"],
3536  "type" => $obj["type"], "title" => $obj["title"],
3537  "insert_time" => $obj["insert_time"]);
3538  }
3539  return $objects;
3540  }
3541 
3545  function getClipboardChilds($a_parent, $a_insert_time)
3546  {
3547  global $ilDB, $ilUser;
3548 
3549  $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3550  "user_id = %s AND parent = %s AND insert_time = %s ".
3551  " ORDER BY order_nr",
3552  array("integer", "integer", "timestamp"),
3553  array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3554  $objects = array();
3555  while ($obj = $ilDB->fetchAssoc($objs))
3556  {
3557  if ($obj["type"] == "mob")
3558  {
3559  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3560  }
3561  $objects[] = array ("id" => $obj["item_id"],
3562  "type" => $obj["type"], "title" => $obj["title"]);
3563  }
3564  return $objects;
3565  }
3566 
3575  function _getUsersForClipboadObject($a_type, $a_id)
3576  {
3577  global $ilDB;
3578 
3579  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3580  "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3581  "type = ".$ilDB->quote($a_type, "text");
3582  $user_set = $ilDB->query($q);
3583  $users = array();
3584  while ($user_rec = $ilDB->fetchAssoc($user_set))
3585  {
3586  $users[] = $user_rec["user_id"];
3587  }
3588 
3589  return $users;
3590  }
3591 
3599  function removeObjectFromClipboard($a_item_id, $a_type)
3600  {
3601  global $ilDB;
3602 
3603  $q = "DELETE FROM personal_clipboard WHERE ".
3604  "item_id = ".$ilDB->quote($a_item_id, "integer").
3605  " AND type = ".$ilDB->quote($a_type, "text")." ".
3606  " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3607  $ilDB->manipulate($q);
3608  }
3609 
3610  function _getImportedUserId($i2_id)
3611  {
3612  global $ilDB;
3613 
3614  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3615  $ilDB->quote($i2_id, "text");
3616 
3617  $res = $ilDB->query($query);
3618  while($row = $ilDB->fetchObject($res))
3619  {
3620  $id = $row->obj_id;
3621  }
3622  return $id ? $id : 0;
3623  }
3624 
3625 /*
3626 
3627  function setiLincData($a_id,$a_login,$a_passwd)
3628  {
3629  $this->ilinc_id = $a_id;
3630  $this->ilinc_login = $a_login;
3631  $this->ilinc_passwd = $a_passwd;
3632  }
3633 
3634 */
3635 
3636 /*
3637 
3638  function getiLincData()
3639  {
3640  return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
3641  }
3642 */
3647  function setAuthMode($a_str)
3648  {
3649  $this->auth_mode = $a_str;
3650  }
3651 
3656  function getAuthMode($a_auth_key = false)
3657  {
3658  if (!$a_auth_key)
3659  {
3660  return $this->auth_mode;
3661  }
3662 
3663  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3664  return ilAuthUtils::_getAuthMode($this->auth_mode);
3665  }
3666 
3674  function setExternalAccount($a_str)
3675  {
3676  $this->ext_account = $a_str;
3677  }
3678 
3687  {
3688  return $this->ext_account;
3689  }
3690 
3702  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3703  {
3704  global $ilDB,$ilSetting;
3705 
3706  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3707  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3708  "WHERE auth_mode = %s";
3709  $types[] = "text";
3710  $values[] = $a_auth_mode;
3711  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3712  {
3713  $q.= " OR auth_mode = %s ";
3714  $types[] = "text";
3715  $values[] = 'default';
3716  }
3717 
3718  $res = $ilDB->queryF($q, $types, $values);
3719  while ($row = $ilDB->fetchObject($res))
3720  {
3721  if($row->auth_mode == 'default')
3722  {
3723  $accounts[$row->usr_id] = $row->login;
3724  }
3725  else
3726  {
3727  $accounts[$row->usr_id] = $row->ext_account;
3728  }
3729  }
3730  return $accounts ? $accounts : array();
3731  }
3732 
3740  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3741  {
3742  global $ilDB;
3743 
3744  if(!is_array($a_usr_ids))
3745  {
3746  return false;
3747  }
3748  $q = "UPDATE usr_data SET active = %s WHERE ".
3749  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3750  $ilDB->manipulateF($q, array("integer"), array(($a_status ? 1 : 0)));
3751 
3752  return true;
3753  }
3754 
3755 
3764  public static function _lookupAuthMode($a_usr_id)
3765  {
3766  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3767  }
3768 
3775  public static function _checkExternalAuthAccount($a_auth, $a_account)
3776  {
3777  global $ilDB,$ilSetting;
3778 
3779  // Check directly with auth_mode
3780  $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3781  " ext_account = %s AND auth_mode = %s",
3782  array("text", "text"),
3783  array($a_account, $a_auth));
3784  if ($usr = $ilDB->fetchAssoc($r))
3785  {
3786  return $usr["login"];
3787  }
3788 
3789  // For compatibility, check for login (no ext_account entry given)
3790  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3791  "WHERE login = %s AND auth_mode = %s",
3792  array("text", "text"),
3793  array($a_account, $a_auth));
3794  if($usr = $ilDB->fetchAssoc($res))
3795  {
3796  return $usr['login'];
3797  }
3798 
3799  // If auth_default == $a_auth => check for login
3800  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3801  {
3802  $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3803  " ext_account = %s AND auth_mode = %s",
3804  array("text", "text"),
3805  array($a_account, "default"));
3806  if ($usr = $ilDB->fetchAssoc($res))
3807  {
3808  return $usr["login"];
3809  }
3810  // Search for login (no ext_account given)
3811  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3812  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3813  array("text", "text"),
3814  array($a_account, "default"));
3815  if($usr = $ilDB->fetchAssoc($res))
3816  {
3817  return $usr["login"];
3818  }
3819  }
3820  return false;
3821  }
3822 
3827  {
3828  global $ilDB;
3829 
3830  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3831  "GROUP BY auth_mode");
3832  $cnt_arr = array();
3833  while($cnt = $ilDB->fetchAssoc($r))
3834  {
3835  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3836  }
3837 
3838  return $cnt_arr;
3839  }
3840 
3846  function _getLocalAccountsForEmail($a_email)
3847  {
3848  global $ilDB, $ilSetting;
3849 
3850  // default set to local (1)?
3851 
3852  $q = "SELECT * FROM usr_data WHERE ".
3853  " email = %s AND (auth_mode = %s ";
3854  $types = array("text", "text");
3855  $values = array($a_email, "local");
3856 
3857  if ($ilSetting->get("auth_mode") == 1)
3858  {
3859  $q.=" OR auth_mode = %s";
3860  $types[] = "text";
3861  $values[] = "default";
3862  }
3863 
3864  $q.= ")";
3865 
3866  $users = array();
3867  $usr_set = $ilDB->queryF($q, $types, $values);
3868  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3869  {
3870  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3871  }
3872 
3873  return $users;
3874  }
3875 
3876 
3884  function _uploadPersonalPicture($tmp_file, $obj_id)
3885  {
3886  $webspace_dir = ilUtil::getWebspaceDir();
3887  $image_dir = $webspace_dir."/usr_images";
3888  $store_file = "usr_".$obj_id."."."jpg";
3889  $target_file = $image_dir."/$store_file";
3890 
3891  chmod($tmp_file, 0770);
3892 
3893  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3894  // taking only frame [0] to avoid problems with animated gifs
3895  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3896  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3897  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3898  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3899 
3900  ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
3901  ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
3902  ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
3903  ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
3904 
3905  // store filename
3906  ilObjUser::_writePref($obj_id, "profile_image", $store_file);
3907 
3908  return TRUE;
3909  }
3910 
3916  function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3917  {
3918  return ilObjUser::_getPersonalPicturePath($this->getId(),$a_size,$a_force_pic);
3919  }
3920 
3927  function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3928  $a_prevent_no_photo_image = false)
3929  {
3930  global $ilDB;
3931 
3932  // BEGIN DiskQuota: Fetch all user preferences in a single query
3933  $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3934  "keyword IN (%s,%s) ".
3935  "AND usr_id = %s",
3936  array("text", "text", "integer"),
3937  array('public_upload', 'public_profile', $a_usr_id));
3938  while ($row = $ilDB->fetchAssoc($res))
3939  {
3940  switch ($row['keyword'])
3941  {
3942  case 'public_upload' :
3943  $upload = $row['value'] == 'y';
3944  break;
3945  case 'public_profile' :
3946  $profile = ($row['value'] == 'y' ||
3947  $row['value'] == 'g');
3948  break;
3949  }
3950  }
3951 
3952  // END DiskQuota: Fetch all user preferences in a single query
3953  $webspace_dir = "";
3954  if(defined('ILIAS_MODULE'))
3955  {
3956  $webspace_dir = ('.'.$webspace_dir);
3957  }
3958  $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
3959 
3960  $image_dir = $webspace_dir."/usr_images";
3961  // BEGIN DiskQuota: Support 'big' user images
3962  if ($a_size == 'big')
3963  {
3964  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3965  }
3966  else
3967  {
3968  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3969  }
3970  // END DiskQuota: Support 'big' user images
3971 
3972  if((($upload && $profile) || $a_force_pic)
3973  && @is_file($thumb_file))
3974  {
3975  $file = $thumb_file."?t=".rand(1, 99999);
3976  }
3977  else
3978  {
3979  if (!$a_prevent_no_photo_image)
3980  {
3981  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
3982  }
3983  }
3984 
3985  return $file;
3986  }
3987 
3992  {
3993  $webspace_dir = ilUtil::getWebspaceDir();
3994  $image_dir = $webspace_dir."/usr_images";
3995  $file = $image_dir."/usr_".$this->getID()."."."jpg";
3996  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
3997  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
3998  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
3999  $upload_file = $image_dir."/upload_".$this->getID();
4000 
4001  // remove user pref file name
4002  $this->setPref("profile_image", "");
4003  $this->update();
4004 
4005  if (@is_file($file))
4006  {
4007  unlink($file);
4008  }
4009  if (@is_file($thumb_file))
4010  {
4011  unlink($thumb_file);
4012  }
4013  if (@is_file($xthumb_file))
4014  {
4015  unlink($xthumb_file);
4016  }
4017  if (@is_file($xxthumb_file))
4018  {
4019  unlink($xxthumb_file);
4020  }
4021  if (@is_file($upload_file))
4022  {
4023  unlink($upload_file);
4024  }
4025  }
4026 
4027 
4028  function setUserDefinedData($a_data)
4029  {
4030  if(!is_array($a_data))
4031  {
4032  return false;
4033  }
4034  foreach($a_data as $field => $data)
4035  {
4036  #$new_data[$field] = ilUtil::stripSlashes($data);
4037  // Assign it directly to avoid update problems of unchangable fields
4038  $this->user_defined_data['f_'.$field] = $data;
4039  }
4040  #$this->user_defined_data = $new_data;
4041 
4042  return true;
4043  }
4044 
4046  {
4047  return $this->user_defined_data ? $this->user_defined_data : array();
4048  }
4049 
4051  {
4052  global $ilDB;
4053 
4054  $fields = '';
4055 
4056  $field_def = array();
4057 
4058  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4059  $udata = new ilUserDefinedData($this->getId());
4060 
4061  foreach($this->user_defined_data as $field => $value)
4062  {
4063  if($field != 'usr_id')
4064  {
4065 // $field_def[$field] = array('text',$value);
4066  $udata->set($field, $value);
4067  }
4068  }
4069  $udata->update();
4070 
4071 /* if(!$field_def)
4072  {
4073  return true;
4074  }
4075 
4076  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4077  $res = $ilDB->query($query);
4078 
4079 
4080  if($res->numRows())
4081  {
4082  // Update
4083  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4084  }
4085  else
4086  {
4087  $field_def['usr_id'] = array('integer',$this->getId());
4088  $ilDB->insert('udf_data',$field_def);
4089  }
4090 */
4091  return true;
4092  }
4093 
4095  {
4096  global $ilDB;
4097 
4098  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4099  $udata = new ilUserDefinedData($this->getId());
4100 
4101 /* $query = "SELECT * FROM udf_data ".
4102  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4103 
4104  $res = $this->db->query($query);
4105  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
4106  {
4107  $this->user_defined_data = $row;
4108  }*/
4109 
4110  $this->user_defined_data = $udata->getAll();
4111 
4112  return true;
4113  }
4114 
4116  {
4117  global $ilDB;
4118 
4119 // not needed. no entry in udf_text/udf_clob means no value
4120 
4121 /* $query = "INSERT INTO udf_data (usr_id ) ".
4122  "VALUES( ".
4123  $ilDB->quote($this->getId(),'integer').
4124  ")";
4125  $res = $ilDB->manipulate($query);
4126 */
4127  return true;
4128  }
4129 
4131  {
4132  global $ilDB;
4133 
4134  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4136 
4137  // wrong place...
4138 /* $query = "DELETE FROM udf_data ".
4139  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4140  $res = $ilDB->manipulate($query);*/
4141 
4142  return true;
4143  }
4144 
4150  function getProfileAsString(&$a_language)
4151  {
4152  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4153  include_once 'classes/class.ilFormat.php';
4154 
4155  global $lng,$rbacreview;
4156 
4157  $language =& $a_language;
4158  $language->loadLanguageModule('registration');
4159  $language->loadLanguageModule('crs');
4160 
4161  $body = '';
4162  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4163 
4164  if(strlen($this->getUTitle()))
4165  {
4166  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4167  }
4168  if(strlen($this->getGender()))
4169  {
4170  $gender = ($this->getGender() == 'm') ?
4171  $language->txt('gender_m') :
4172  $language->txt('gender_f');
4173  $body .= ($language->txt("gender").": ".$gender."\n");
4174  }
4175  if(strlen($this->getFirstname()))
4176  {
4177  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4178  }
4179  if(strlen($this->getLastname()))
4180  {
4181  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4182  }
4183  if(strlen($this->getInstitution()))
4184  {
4185  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4186  }
4187  if(strlen($this->getDepartment()))
4188  {
4189  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4190  }
4191  if(strlen($this->getStreet()))
4192  {
4193  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4194  }
4195  if(strlen($this->getCity()))
4196  {
4197  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4198  }
4199  if(strlen($this->getZipcode()))
4200  {
4201  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4202  }
4203  if(strlen($this->getCountry()))
4204  {
4205  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4206  }
4207  if(strlen($this->getSelectedCountry()))
4208  {
4209  $body .= ($language->txt("sel_country").": ".$this->getSelectedCountry()."\n");
4210  }
4211  if(strlen($this->getPhoneOffice()))
4212  {
4213  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4214  }
4215  if(strlen($this->getPhoneHome()))
4216  {
4217  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4218  }
4219  if(strlen($this->getPhoneMobile()))
4220  {
4221  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4222  }
4223  if(strlen($this->getFax()))
4224  {
4225  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4226  }
4227  if(strlen($this->getEmail()))
4228  {
4229  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4230  }
4231  if(strlen($this->getHobby()))
4232  {
4233  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4234  }
4235  if(strlen($this->getComment()))
4236  {
4237  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4238  }
4239  if(strlen($this->getMatriculation()))
4240  {
4241  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4242  }
4243  if(strlen($this->getCreateDate()))
4244  {
4249 
4250  $body .= ($language->txt("create_date").": ".$date."\n");
4251  }
4252 
4253  foreach($rbacreview->getGlobalRoles() as $role)
4254  {
4255  if($rbacreview->isAssigned($this->getId(),$role))
4256  {
4257  $gr[] = ilObjRole::_lookupTitle($role);
4258  }
4259  }
4260  if(count($gr))
4261  {
4262  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4263  }
4264 
4265  // Time limit
4266  if($this->getTimeLimitUnlimited())
4267  {
4268  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4269  }
4270  else
4271  {
4275  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4277 
4278  $start = new ilDateTime($this->getTimeLimitFrom(),IL_CAL_UNIX);
4279  $end = new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX);
4280 
4281  $body .= $language->txt('time_limit').': '.$start->get(IL_CAL_DATETIME);
4282  $body .= $language->txt('time_limit').': '.$end->get(IL_CAL_DATETIME);
4283 
4284 
4285  #$body .= $language->txt('time_limit').': '.$period;
4286  /*
4287  $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4288  ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4289  $language->txt('crs_to')." ".
4290  ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4291  */
4292  }
4293  return $body;
4294  }
4295 
4296  function setInstantMessengerId($a_im_type, $a_im_id)
4297  {
4298  $var = "im_".$a_im_type;
4299  $this->$var = $a_im_id;
4300  }
4301 
4302  function getInstantMessengerId($a_im_type)
4303  {
4304  $var = "im_".$a_im_type;
4305  return $this->$var;
4306  }
4307 
4308  function setDelicious($a_delicious)
4309  {
4310  $this->delicious = $a_delicious;
4311  }
4312 
4313  function getDelicious()
4314  {
4315  return $this->delicious;
4316  }
4317 
4321  function _lookupFeedHash($a_user_id, $a_create = false)
4322  {
4323  global $ilDB;
4324 
4325  if ($a_user_id > 0)
4326  {
4327  $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4328  array("integer"), array($a_user_id));
4329  if ($rec = $ilDB->fetchAssoc($set))
4330  {
4331  if (strlen($rec["feed_hash"]) == 32)
4332  {
4333  return $rec["feed_hash"];
4334  }
4335  else if($a_create)
4336  {
4337  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4338  $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4339  " WHERE usr_id = %s",
4340  array("text", "integer"),
4341  array($hash, $a_user_id));
4342  return $hash;
4343  }
4344  }
4345  }
4346 
4347  return false;
4348  }
4349 
4355  function _getFeedPass($a_user_id)
4356  {
4357  global $ilDB;
4358 
4359  if ($a_user_id > 0)
4360  {
4361  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4362  }
4363  return false;
4364  }
4365 
4371  function _setFeedPass($a_user_id, $a_password)
4372  {
4373  global $ilDB;
4374 
4375  ilObjUser::_writePref($a_user_id, "priv_feed_pass",
4376  ($a_password=="") ? "" : md5($a_password));
4377  }
4378 
4388  public static function _loginExists($a_login,$a_user_id = 0)
4389  {
4390  global $ilDB;
4391 
4392  $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4393  "WHERE login = %s";
4394  $types[] = "text";
4395  $values[] = $a_login;
4396 
4397  if ($a_user_id != 0)
4398  {
4399  $q.= " AND usr_id != %s ";
4400  $types[] = "integer";
4401  $values[] = $a_user_id;
4402  }
4403 
4404  $r = $ilDB->queryF($q, $types, $values);
4405 
4406  if ($row = $ilDB->fetchAssoc($r))
4407  {
4408  return $row['usr_id'];
4409  }
4410  return false;
4411  }
4412 
4423  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4424  {
4425  global $ilDB;
4426 
4427  $res = $ilDB->queryF("SELECT * FROM usr_data ".
4428  "WHERE ext_account = %s AND auth_mode = %s",
4429  array("text", "text"),
4430  array($a_external_account, $a_auth_mode));
4431  return $ilDB->fetchAssoc($res) ? true :false;
4432  }
4433 
4441  public static function _getUsersForRole($role_id, $active = -1) {
4442  global $ilDB, $rbacreview;
4443  $data = array();
4444 
4445  $ids = $rbacreview->assignedUsers($role_id);
4446 
4447  if (count ($ids) == 0)
4448  {
4449  $ids = array (-1);
4450  }
4451 
4452  $query = "SELECT usr_data.*, usr_pref.value AS language
4453  FROM usr_data
4454  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4455  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4456  $values[] = "language";
4457  $types[] = "text";
4458 
4459 
4460  if (is_numeric($active) && $active > -1)
4461  {
4462  $query .= " AND usr_data.active = %s";
4463  $values[] = $active;
4464  $types[] = "integer";
4465  }
4466 
4467  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4468 
4469  $r = $ilDB->queryF($query, $types, $values);
4470  $data = array();
4471  while ($row = $ilDB->fetchAssoc($r))
4472  {
4473  $data[] = $row;
4474  }
4475  return $data;
4476  }
4477 
4478 
4484  public static function _getUsersForFolder ($ref_id, $active) {
4485  global $ilDB;
4486  $data = array();
4487  $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 ";
4488  $types[] = "text";
4489  $values[] = "language";
4490 
4491  if (is_numeric($active) && $active > -1)
4492  {
4493  $query .= " AND usr_data.active = %s";
4494  $values[] = $active;
4495  $types[] = "integer";
4496  }
4497 
4498  if ($ref_id != USER_FOLDER_ID)
4499  {
4500  $query.= " AND usr_data.time_limit_owner = %s";
4501  $values[] = $ref_id;
4502  $types[] = "integer";
4503  }
4504 
4505  $query .= " AND usr_data.usr_id != %s ";
4506  $values[] = ANONYMOUS_USER_ID;
4507  $types[] = "integer";
4508 
4509  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4510 
4511  $result = $ilDB->queryF($query, $types, $values);
4512  $data = array();
4513  while ($row = $ilDB->fetchAssoc($result))
4514  {
4515  array_push($data, $row);
4516  }
4517 
4518  return $data;
4519  }
4520 
4521 
4527  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4528  {
4529  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4530  }
4531 
4532 
4538  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4539  {
4540  global $rbacadmin, $rbacreview, $ilDB;
4541 
4542  // quote all ids
4543  $ids = array();
4544  foreach ($a_mem_ids as $mem_id) {
4545  $ids [] = $ilDB->quote($mem_id);
4546  }
4547 
4548  $query = "SELECT usr_data.*, usr_pref.value AS language
4549  FROM usr_data
4550  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4551  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer")."
4552  AND usr_data.usr_id != %s";
4553  $values[] = "language";
4554  $types[] = "text";
4555  $values[] = ANONYMOUS_USER_ID;
4556  $types[] = "integer";
4557 
4558  if (is_numeric($active) && $active > -1)
4559  {
4560  $query .= " AND active = %s";
4561  $values[] = $active;
4562  $types[] = "integer";
4563  }
4564 
4565  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4566  {
4567  $query.= " AND usr_data.time_limit_owner = %s";
4568  $values[] = $timelimitowner;
4569  $types[] = "integer";
4570 
4571  }
4572 
4573  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4574 
4575  $result = $ilDB->queryF($query, $types, $values);
4576  while ($row = $ilDB->fetchAssoc($result))
4577  {
4578  $mem_arr[] = $row;
4579  }
4580 
4581  return $mem_arr ? $mem_arr : array();
4582  }
4583 
4584 
4585 
4591  public static function _getUserData ($a_internalids) {
4592  global $ilDB;
4593 
4594  $ids = array();
4595  if (is_array($a_internalids)) {
4596  foreach ($a_internalids as $internalid) {
4597  if (is_numeric ($internalid))
4598  {
4599  $ids[] = $internalid;
4600  }
4601  else
4602  {
4603  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4604  if (is_numeric($parsedid) && $parsedid > 0)
4605  {
4606  $ids[] = $parsedid;
4607  }
4608  }
4609  }
4610  }
4611  if (count($ids) == 0)
4612  $ids [] = -1;
4613 
4614  $query = "SELECT usr_data.*, usr_pref.value AS language
4615  FROM usr_data
4616  LEFT JOIN usr_pref
4617  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4618  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4619  $values[] = "language";
4620  $types[] = "text";
4621 
4622  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4623 
4624  $data = array();
4625  $result = $ilDB->queryF($query, $types, $values);
4626  while ($row = $ilDB->fetchAssoc($result))
4627  {
4628  $data[] = $row;
4629  }
4630  return $data;
4631  }
4632 
4639  public static function _getPreferences ($user_id)
4640  {
4641  global $ilDB;
4642 
4643  $prefs = array();
4644 
4645  $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4646  array("integer"), array($user_id));
4647 
4648  while($row = $ilDB->fetchAssoc($r))
4649  {
4650  $prefs[$row["keyword"]] = $row["value"];
4651  }
4652 
4653  return $prefs;
4654  }
4655 
4656 
4657  public static function _resetLoginAttempts($a_usr_id)
4658  {
4659  global $ilDB;
4660 
4661  $query = "UPDATE usr_data SET usr_data.login_attempts = 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 
4668  public static function _getLoginAttempts($a_usr_id)
4669  {
4670  global $ilDB;
4671 
4672  $query = "SELECT usr_data.login_attempts FROM usr_data WHERE usr_data.usr_id = %s";
4673  $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4674  $record = $ilDB->fetchAssoc( $result );
4675  $login_attempts = $record['login_attempts'];
4676 
4677  return $login_attempts;
4678  }
4679 
4680  public static function _incrementLoginAttempts($a_usr_id)
4681  {
4682  global $ilDB;
4683 
4684  $query = "UPDATE usr_data SET usr_data.login_attempts = (usr_data.login_attempts + 1) WHERE usr_data.usr_id = %s";
4685  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4686 
4687  if($affected) return true;
4688  else return false;
4689  }
4690 
4691  public static function _setUserInactive($a_usr_id)
4692  {
4693  global $ilDB;
4694 
4695  $query = "UPDATE usr_data SET usr_data.active = 0 WHERE usr_data.usr_id = %s";
4696  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4697 
4698  if($affected) return true;
4699  else return false;
4700  }
4701 
4707  public function hasPublicProfile() {
4708  return in_array($this->getPref("public_profile"), array("y", "g"));
4709  }
4710 
4716  public function getPublicName()
4717  {
4718  if ($this->hasPublicProfile())
4719  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4720  else
4721  return $this->getLogin();
4722 
4723  }
4724 
4725  public static function _writeHistory($a_usr_id, $a_login)
4726  {
4727  global $ilDB;
4728 
4729  $timestamp = time();
4730 
4731  $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4732  array('integer', 'text', 'integer'),
4733  array($a_usr_id, $a_login, $timestamp));
4734 
4735  if( $ilDB->numRows($res) == 0 )
4736  {
4737  $ilDB->manipulateF('
4738  INSERT INTO loginname_history
4739  (usr_id, login, history_date)
4740  VALUES (%s, %s, %s)',
4741  array('integer', 'text', 'integer'),
4742  array($a_usr_id, $a_login, $timestamp));
4743  }
4744 
4745  return true;
4746  }
4747 
4755  function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4756  {
4757  global $ilDB;
4758 
4759  $pd_set = new ilSetting("pd");
4760  $atime = $pd_set->get("user_activity_time") * 60;
4761  $ctime = time();
4762 
4763  if ($a_user_id == 0)
4764  {
4765  $where = "WHERE user_id != 0 AND NOT agree_date IS NULL ";
4766  $type_array = array("integer");
4767  $val_array = array(time());
4768  }
4769  else
4770  {
4771  $where = "WHERE user_id = %s ";
4772  $type_array = array("integer", "integer");
4773  $val_array = array($a_user_id, time());
4774  }
4775 
4776  $no_anonym = ($a_no_anonymous)
4777  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4778  : "";
4779 
4780  include_once './Services/User/classes/class.ilUserAccountSettings.php';
4781  if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
4782  {
4783  include_once './Services/User/classes/class.ilUserFilter.php';
4784  $user_filter = 'AND '.$ilDB->in('time_limit_owner',ilUserFilter::getInstance()->getFolderIds(),false,'integer').' ';
4785  }
4786  else
4787  {
4788  $user_filter = ' ';
4789  }
4790  $r = $ilDB->queryF($q = "SELECT count(user_id) as num,user_id,firstname,lastname,title,login,last_login,max(ctime) AS ctime ".
4791  "FROM usr_session ".
4792  "LEFT JOIN usr_data u ON user_id = u.usr_id ".
4793  "LEFT JOIN usr_pref p ON (p.usr_id = u.usr_id AND p.keyword = ".
4794  $ilDB->quote("hide_own_online_status", "text").") ".$where.
4795  "AND expires > %s ".
4796  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4797  $no_anonym.
4798  $user_filter.
4799  "GROUP BY user_id,firstname,lastname,title,login,last_login ".
4800  "ORDER BY lastname, firstname", $type_array, $val_array);
4801 
4802  while ($user = $ilDB->fetchAssoc($r))
4803  {
4804  if ($atime <= 0
4805  || $user["ctime"] + $atime > $ctime)
4806  {
4807  $users[$user["user_id"]] = $user;
4808  }
4809  }
4810 
4811  return $users ? $users : array();
4812  }
4813 
4822  function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4823  {
4824  global $ilias, $ilDB;
4825 
4826  $pd_set = new ilSetting("pd");
4827  $atime = $pd_set->get("user_activity_time") * 60;
4828  $ctime = time();
4829  $no_anonym = ($a_no_anonymous)
4830  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4831  : "";
4832 
4833  // Get a list of object id's of all courses and groups for which
4834  // the current user has local roles.
4835  // Note: we have to use DISTINCT here, because a user may assume
4836  // multiple roles in a group or a course.
4837  $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4838  "FROM rbac_ua ua ".
4839  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4840  "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4841  "JOIN tree ON tree.child = r1.ref_id ".
4842  "JOIN object_reference r2 ON r2.ref_id = tree.parent ".
4843  "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4844  "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4845  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4846  "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4847  $ilDB->quote("grp", "text").")";
4848  $r = $ilDB->query($q);
4849 
4850  while ($row = $ilDB->fetchAssoc($r))
4851  {
4852  $groups_and_courses_of_user[] = $row["obj_id"];
4853  }
4854  // If the user is not in a course or a group, he has no associated users.
4855  if (count($groups_and_courses_of_user) == 0)
4856  {
4857  $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4858  "FROM usr_session ".
4859  "JOIN usr_data ON user_id=usr_id ".
4860  "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4861  $no_anonym.
4862  " AND NOT agree_date IS NULL ".
4863  "AND expires > ".$ilDB->quote(time(), "integer")." ".
4864  "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4865  $r = $ilDB->query($q);
4866  }
4867  else
4868  {
4869  $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4870  "FROM usr_session s ".
4871  "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4872  "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
4873  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4874  "JOIN tree ON tree.child = fa.parent ".
4875  "JOIN object_reference or1 ON or1.ref_id = tree.parent ".
4876  "JOIN object_data od ON od.obj_id = or1.obj_id ".
4877  "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
4878  $ilDB->quote("hide_own_online_status", "text").") ".
4879  "WHERE s.user_id != 0 ".
4880  $no_anonym.
4881  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4882  "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
4883  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4884  " AND NOT ud.agree_date IS NULL ".
4885  "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
4886  "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4887  "ORDER BY ud.lastname, ud.firstname";
4888  $r = $ilDB->query($q);
4889  }
4890 
4891  while ($user = $ilDB->fetchAssoc($r))
4892  {
4893  if ($atime <= 0
4894  || $user["ctime"] + $atime > $ctime)
4895  {
4896  $users[$user["user_id"]] = $user;
4897  }
4898  }
4899 
4900  return $users ? $users : array();
4901  }
4902 
4909  public static function _generateRegistrationHash($a_usr_id)
4910  {
4911  global $ilDB;
4912 
4913  do
4914  {
4915  $continue = false;
4916 
4917  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
4918 
4919  $res = $ilDB->queryf('
4920  SELECT COUNT(usr_id) cnt FROM usr_data
4921  WHERE reg_hash = %s',
4922  array('text'),
4923  array($hashcode));
4924  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
4925  {
4926  if($row->cnt > 0) $continue = true;
4927  break;
4928  }
4929 
4930  if($continue) continue;
4931 
4932  $ilDB->manipulateF('
4933  UPDATE usr_data
4934  SET reg_hash = %s
4935  WHERE usr_id = %s',
4936  array('text', 'integer'),
4937  array($hashcode, (int)$a_usr_id)
4938  );
4939 
4940  break;
4941 
4942  } while(true);
4943 
4944  return $hashcode;
4945  }
4946 
4955  public static function _verifyRegistrationHash($a_hash)
4956  {
4957  global $ilDB;
4958 
4959  $res = $ilDB->queryf('
4960  SELECT usr_id, create_date FROM usr_data
4961  WHERE reg_hash = %s',
4962  array('text'),
4963  array($a_hash));
4964  while($row = $ilDB->fetchAssoc($res))
4965  {
4966  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
4967  $oRegSettigs = new ilRegistrationSettings();
4968 
4969  if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
4970  time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
4971  {
4972  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
4973  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
4974  }
4975 
4976  $ilDB->manipulateF('
4977  UPDATE usr_data
4978  SET reg_hash = %s
4979  WHERE usr_id = %s',
4980  array('text', 'integer'),
4981  array('', (int)$row['usr_id'])
4982  );
4983 
4984  return (int)$row['usr_id'];
4985  }
4986 
4987  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
4988  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
4989  }
4990 
4991  function setBirthday($a_birthday)
4992  {
4993  if (strlen($a_birthday))
4994  {
4995  $date = new ilDate($a_birthday, IL_CAL_DATE);
4996  $this->birthday = $date->get(IL_CAL_DATE);
4997  }
4998  else
4999  {
5000  $this->birthday = null;
5001  }
5002  }
5003 
5004  function getBirthday()
5005  {
5006  return $this->birthday;
5007  }
5008 
5017  public static function _getUserIdsByInactivityPeriod($period)
5018  {
5019  if( !(int)$period ) throw new ilException('no valid period given');
5020 
5021  global $ilDB;
5022 
5023  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5024 
5025  $query = "SELECT usr_id FROM usr_data WHERE last_login < %s";
5026 
5027  $res = $ilDB->queryF($query, array('timestamp'), array($date));
5028 
5029  $ids = array();
5030  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5031  {
5032  $ids[] = $row->usr_id;
5033  }
5034 
5035  return $ids;
5036  }
5037 
5047  public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5048  {
5049  if($a_last_login !== null) $last_login = $a_last_login;
5050  else $last_login = date('Y-m-d H:i:s');
5051 
5052  global $ilDB;
5053 
5054  $query = "UPDATE usr_data SET usr_data.last_login = %s WHERE usr_data.usr_id = %s";
5055  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array($last_login, $a_usr_id) );
5056 
5057  if($affected) return $last_login;
5058  else return false;
5059  }
5060 
5061  public function resetOwner()
5062  {
5063  global $ilDB;
5064 
5065  $query = "UPDATE object_data SET owner = 0 ".
5066  "WHERE owner = ".$ilDB->quote($this->getId(),'integer');
5067  $ilDB->query($query);
5068 
5069  return true;
5070  }
5071 
5072 
5079  static function getFirstLettersOfLastnames()
5080  {
5081  global $ilDB;
5082 
5083  $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("lastname", 1, 1))." let FROM usr_data ORDER BY let";
5084  $let_set = $ilDB->query($q);
5085 
5086  $lets = array();
5087  while ($let_rec = $ilDB->fetchAssoc($let_set))
5088  {
5089  $let[$let_rec["let"]] = $let_rec["let"];
5090  }
5091  return $let;
5092  }
5093 
5094 
5095 } // END class ilObjUser
5096 ?>