ILIAS  eassessment Revision 61809
 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  // TODO make this conditional!
373  $this->agree_date = "1970-01-01 00:00:00";
374  switch ($this->passwd_type)
375  {
376  case IL_PASSWD_PLAIN:
377  $pw_field = "passwd";
378  if(strlen($this->passwd))
379  {
380  $pw_value = md5($this->passwd);
381  }
382  else
383  {
384  $pw_value = $this->passwd;
385  }
386  break;
387 
388  case IL_PASSWD_MD5:
389  $pw_field = "passwd";
390  $pw_value = $this->passwd;
391  break;
392 
393  case IL_PASSWD_CRYPT:
394  $pw_field = "i2passwd";
395  $pw_value = $this->passwd;
396  break;
397 
398  default :
399  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
400  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
401  "<br />Line: ".__LINE__, $ilErr->FATAL);
402  }
403 
404  $insert_array = array(
405  "usr_id" => array("integer", $this->id),
406  "login" => array("text", $this->login),
407  $pw_field => array("text", $pw_value),
408  "firstname" => array("text", $this->firstname),
409  "lastname" => array("text", $this->lastname),
410  "title" => array("text", $this->utitle),
411  "gender" => array("text", $this->gender),
412  "email" => array("text", trim($this->email)),
413  "hobby" => array("text", (string) $this->hobby),
414  "institution" => array("text", $this->institution),
415  "department" => array("text", $this->department),
416  "street" => array("text", $this->street),
417  "city" => array("text", $this->city),
418  "zipcode" => array("text", $this->zipcode),
419  "country" => array("text", $this->country),
420  "sel_country" => array("text", $this->sel_country),
421  "phone_office" => array("text", $this->phone_office),
422  "phone_home" => array("text", $this->phone_home),
423  "phone_mobile" => array("text", $this->phone_mobile),
424  "fax" => array("text", $this->fax),
425  "birthday" => array('date', $this->getBirthday()),
426  "last_login" => array("timestamp", null),
427  "last_update" => array("timestamp", ilUtil::now()),
428  "create_date" => array("timestamp", ilUtil::now()),
429  "referral_comment" => array("text", $this->referral_comment),
430  "matriculation" => array("text", $this->matriculation),
431  "client_ip" => array("text", $this->client_ip),
432  "approve_date" => array("timestamp", $this->approve_date),
433  "agree_date" => array("timestamp", $this->agree_date),
434  "active" => array("integer", (int) $this->active),
435  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
436  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
437  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
438  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
439  "auth_mode" => array("text", $this->getAuthMode()),
440  "ext_account" => array("text", $this->getExternalAccount()),
441  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
442  "im_icq" => array("text", $this->im_icq),
443  "im_yahoo" => array("text", $this->im_yahoo),
444  "im_msn" => array("text", $this->im_msn),
445  "im_aim" => array("text", $this->im_aim),
446  "im_skype" => array("text", $this->im_skype),
447  "delicious" => array("text", $this->delicious),
448  "latitude" => array("text", $this->latitude),
449  "longitude" => array("text", $this->longitude),
450  "loc_zoom" => array("integer", (int) $this->loc_zoom),
451  "last_password_change" => array("integer", (int) $this->last_password_change_ts),
452  "im_jabber" => array("text", $this->im_jabber),
453  "im_voip" => array("text", $this->im_voip)
454  );
455  $ilDB->insert("usr_data", $insert_array);
456 
457  // add new entry in usr_defined_data
458  $this->addUserDefinedFieldEntry();
459  // ... and update
460  $this->updateUserDefinedFields();
461 
462  // CREATE ENTRIES FOR MAIL BOX
463  include_once ("Services/Mail/classes/class.ilMailbox.php");
464  $mbox = new ilMailbox($this->id);
465  $mbox->createDefaultFolder();
466 
467  include_once "Services/Mail/classes/class.ilMailOptions.php";
468  $mail_options = new ilMailOptions($this->id);
469  $mail_options->createMailOptionsEntry();
470 
471  // create personal bookmark folder tree
472  include_once "./Services/PersonalDesktop/classes/class.ilBookmarkFolder.php";
473  $bmf = new ilBookmarkFolder(0, $this->id);
474  $bmf->createNewBookmarkTree();
475 
476  }
477 
482  function update()
483  {
484  global $ilErr, $ilDB, $ilAppEventHandler;
485 
486  $this->syncActive();
487 
488  $update_array = array(
489  "gender" => array("text", $this->gender),
490  "title" => array("text", $this->utitle),
491  "firstname" => array("text", $this->firstname),
492  "lastname" => array("text", $this->lastname),
493  "email" => array("text", trim($this->email)),
494  "birthday" => array('date', $this->getBirthday()),
495  "hobby" => array("text", $this->hobby),
496  "institution" => array("text", $this->institution),
497  "department" => array("text", $this->department),
498  "street" => array("text", $this->street),
499  "city" => array("text", $this->city),
500  "zipcode" => array("text", $this->zipcode),
501  "country" => array("text", $this->country),
502  "sel_country" => array("text", $this->sel_country),
503  "phone_office" => array("text", $this->phone_office),
504  "phone_home" => array("text", $this->phone_home),
505  "phone_mobile" => array("text", $this->phone_mobile),
506  "fax" => array("text", $this->fax),
507  "referral_comment" => array("text", $this->referral_comment),
508  "matriculation" => array("text", $this->matriculation),
509  "client_ip" => array("text", $this->client_ip),
510  "approve_date" => array("timestamp", $this->approve_date),
511  "active" => array("integer", $this->active),
512  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
513  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
514  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
515  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
516  "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
517  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
518  "auth_mode" => array("text", $this->getAuthMode()),
519  "ext_account" => array("text", $this->getExternalAccount()),
520  "im_icq" => array("text", $this->im_icq),
521  "im_yahoo" => array("text", $this->im_yahoo),
522  "im_msn" => array("text", $this->im_msn),
523  "im_aim" => array("text", $this->im_aim),
524  "im_skype" => array("text", $this->im_skype),
525  "delicious" => array("text", $this->delicious),
526  "latitude" => array("text", $this->latitude),
527  "longitude" => array("text", $this->longitude),
528  "loc_zoom" => array("integer", (int) $this->loc_zoom),
529  "last_password_change" => array("integer", $this->last_password_change_ts),
530  "im_jabber" => array("text", $this->im_jabber),
531  "im_voip" => array("text", $this->im_voip),
532  "last_update" => array("timestamp", ilUtil::now())
533  );
534 
535  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null))
536  {
537  $update_array["agree_date"] = array("timestamp", $this->agree_date);
538  }
539  switch ($this->passwd_type)
540  {
541  case IL_PASSWD_PLAIN:
542  if(strlen($this->passwd))
543  {
544  $update_array["i2passwd"] = array("text", (string) "");
545  $update_array["passwd"] = array("text", (string) md5($this->passwd));
546  }
547  else
548  {
549  $update_array["i2passwd"] = array("text", (string) "");
550  $update_array["passwd"] = array("text", (string) $this->passwd);
551  }
552  break;
553 
554  case IL_PASSWD_MD5:
555  $update_array["i2passwd"] = array("text", (string) "");
556  $update_array["passwd"] = array("text", (string) $this->passwd);
557  break;
558 
559  case IL_PASSWD_CRYPT:
560  $update_array["i2passwd"] = array("text", (string) $this->passwd);
561  $update_array["passwd"] = array("text", (string) "");
562  break;
563 
564  default :
565  $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
566  get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
567  }
568 
569  $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
570 
571  $this->writePrefs();
572 
573  // update user defined fields
574  $this->updateUserDefinedFields();
575 
576  parent::update();
578 
579  $this->read();
580 
581  $ilAppEventHandler->raise("Services/User", "afterUpdate",
582  array("user_obj" => $this));
583 
584  return true;
585  }
586 
590  function writeAccepted()
591  {
592  global $ilDB;
593 
594  $ilDB->manipulateF("UPDATE usr_data SET agree_date = ".$ilDB->now().
595  " WHERE usr_id = %s", array("integer"), array($this->getId()));
596  }
597 
601  private function _lookup($a_user_id, $a_field)
602  {
603  global $ilDB;
604 
605  $res = $ilDB->queryF("SELECT ".$a_field." FROM usr_data WHERE usr_id = %s",
606  array("integer"), array($a_user_id));
607 
608  while($set = $ilDB->fetchAssoc($res))
609  {
610  return $set[$a_field];
611  }
612  return false;
613  }
614 
618  function _lookupFullname($a_user_id)
619  {
620  global $ilDB;
621 
622  $set = $ilDB->queryF("SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
623  array("integer"), array($a_user_id));
624 
625  if ($rec = $ilDB->fetchAssoc($set))
626  {
627  if ($rec["title"])
628  {
629  $fullname = $rec["title"]." ";
630  }
631  if ($rec["firstname"])
632  {
633  $fullname .= $rec["firstname"]." ";
634  }
635  if ($rec["lastname"])
636  {
637  $fullname .= $rec["lastname"];
638  }
639  }
640  return $fullname;
641  }
642 
646  function _lookupIm($a_user_id, $a_type)
647  {
648  return ilObjUser::_lookup($a_user_id, "im_".$a_type);
649  }
650 
651 
655  function _lookupEmail($a_user_id)
656  {
657  return ilObjUser::_lookup($a_user_id, "email");
658  }
659 
663  public static function _lookupGender($a_user_id)
664  {
665  return ilObjUser::_lookup($a_user_id, "gender");
666  }
667 
674  function _lookupClientIP($a_user_id)
675  {
676  return ilObjUser::_lookup($a_user_id, "client_ip");
677  }
678 
679 
683  public static function _lookupName($a_user_id)
684  {
685  global $ilDB;
686 
687  $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
688  array("integer"), array($a_user_id));
689  $user_rec = $ilDB->fetchAssoc($res);
690  return array("user_id" => $a_user_id,
691  "firstname" => $user_rec["firstname"],
692  "lastname" => $user_rec["lastname"],
693  "title" => $user_rec["title"],
694  "login" => $user_rec["login"]);
695  }
696 
700  function _lookupFields($a_user_id)
701  {
702  global $ilDB;
703 
704  $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
705  array("integer"), array($a_user_id));
706  $user_rec = $ilDB->fetchAssoc($res);
707  return $user_rec;
708  }
709 
713  function _lookupLogin($a_user_id)
714  {
715  return ilObjUser::_lookup($a_user_id, "login");
716  }
717 
721  function _lookupExternalAccount($a_user_id)
722  {
723  return ilObjUser::_lookup($a_user_id, "ext_account");
724  }
725 
729  public static function _lookupId($a_user_str)
730  {
731  global $ilDB;
732 
733  $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
734  array("text"), array($a_user_str));
735  $user_rec = $ilDB->fetchAssoc($res);
736  return $user_rec["usr_id"];
737  }
738 
742  function _lookupLastLogin($a_user_id)
743  {
744  return ilObjUser::_lookup($a_user_id, "last_login");
745  }
746 
747 
753  function refreshLogin()
754  {
755  global $ilDB;
756 
757  $ilDB->manipulateF("UPDATE usr_data SET ".
758  "last_login = ".$ilDB->now().
759  " WHERE usr_id = %s",
760  array("integer"), array($this->id));
761  }
762 
769  function replacePassword($new_md5)
770  {
771  global $ilDB;
772 
773  $this->passwd_type = IL_PASSWD_MD5;
774  $this->passwd = $new_md5;
775 
776  $ilDB->manipulateF("UPDATE usr_data SET ".
777  "passwd = %s ".
778  "WHERE usr_id = %s",
779  array("text", "integer"), array($this->passwd, $this->id));
780 
781  return true;
782  }
783 
792  function updatePassword($a_old, $a_new1, $a_new2)
793  {
794  global $ilDB;
795 
796  if (func_num_args() != 3)
797  {
798  return false;
799  }
800 
801  if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
802  {
803  return false;
804  }
805 
806  if ($a_new1 != $a_new2)
807  {
808  return false;
809  }
810 
811  // is catched by isset() ???
812  if ($a_new1 == "" || $a_old == "")
813  {
814  return false;
815  }
816 
817  //check old password
818  switch ($this->passwd_type)
819  {
820  case IL_PASSWD_PLAIN:
821  if ($a_old != $this->passwd)
822  {
823  return false;
824  }
825  break;
826 
827  case IL_PASSWD_MD5:
828  if (md5($a_old) != $this->passwd)
829  {
830  return false;
831  }
832  break;
833 
834  case IL_PASSWD_CRYPT:
835  if (_makeIlias2Password($a_old) != $this->passwd)
836  {
837  return false;
838  }
839  break;
840  }
841 
842  //update password
843  $this->passwd = md5($a_new1);
844  $this->passwd_type = IL_PASSWD_MD5;
845 
846  $ilDB->manipulateF("UPDATE usr_data SET ".
847  "passwd = %s ".
848  "WHERE usr_id = %s",
849  array("text", "integer"), array($this->passwd, $this->id));
850 
851  return true;
852  }
853 
861  function resetPassword($a_new1, $a_new2)
862  {
863  global $ilDB;
864 
865  if (func_num_args() != 2)
866  {
867  return false;
868  }
869 
870  if (!isset($a_new1) or !isset($a_new2))
871  {
872  return false;
873  }
874 
875  if ($a_new1 != $a_new2)
876  {
877  return false;
878  }
879 
880  //update password
881  $this->passwd = md5($a_new1);
882  $this->passwd_type = IL_PASSWD_MD5;
883 
884  $ilDB->manipulateF("UPDATE usr_data SET ".
885  "passwd = %s ".
886  "WHERE usr_id = %s",
887  array("text", "integer"),
888  array($this->passwd, $this->id));
889 
890  return true;
891  }
892 
896  function _makeIlias2Password($a_passwd)
897  {
898  return (crypt($a_passwd,substr($a_passwd,0,2)));
899  }
900 
904  function _lookupHasIlias2Password($a_user_login)
905  {
906  global $ilias, $ilDB;
907 
908  $user_set = $ilDB->queryF("SELECT i2passwd FROM usr_data ".
909  "WHERE login = %s", array("text"), array($a_user_login));
910  if ($user_rec = $ilDB->fetchAssoc($user_set))
911  {
912  if ($user_rec["i2passwd"] != "")
913  {
914  return true;
915  }
916  }
917 
918  return false;
919  }
920 
924  function _switchToIlias3Password($a_user, $a_pw)
925  {
926  global $ilias, $ilDB;
927 
928  $user_set = $ilDB->queryF("SELECT i2passwd FROM usr_data ".
929  "WHERE login = %s", array("text"), array($a_user_login));
930  if ($user_rec = $ilDB->fetchAssoc($user_set))
931  {
932  if ($user_rec["i2passwd"] == ilObjUser::_makeIlias2Password($a_pw))
933  {
934  $ilDB->manipulateF("UPDATE usr_data SET passwd = %s, i2passwd = %s".
935  "WHERE login = %s",
936  array("text", "text", "text"),
937  array(md5($a_pw), "", $a_user));
938  return true;
939  }
940  }
941 
942  return false;
943  }
944 
955  public static function _doesLoginnameExistInHistory($a_login)
956  {
957  global $ilDB;
958 
959  $res = $ilDB->queryF('
960  SELECT * FROM loginname_history
961  WHERE login = %s',
962  array('text'), array($a_login));
963 
964  return $ilDB->fetchAssoc($res) ? true : false;
965  }
966 
979  public static function _getLastHistoryDataByUserId($a_usr_id)
980  {
981  global $ilDB;
982 
983  $ilDB->setLimit(1, 0);
984  $res = $ilDB->queryF('
985  SELECT login, history_date FROM loginname_history
986  WHERE usr_id = %s ORDER BY history_date DESC',
987  array('integer'), array($a_usr_id));
988  $row = $ilDB->fetchAssoc($res);
989  if(!is_array($row) || !count($row)) throw new ilUserException('');
990 
991  return array(
992  $row['login'], $row['history_date']
993  );
994  }
995 
1003  function updateLogin($a_login)
1004  {
1005  global $ilDB, $ilSetting;
1006 
1007  if(func_num_args() != 1)
1008  {
1009  return false;
1010  }
1011 
1012  if(!isset($a_login))
1013  {
1014  return false;
1015  }
1016 
1017  // Update not necessary
1018  if($a_login == self::_lookupLogin($this->getId()))
1019  {
1020  return false;
1021  }
1022 
1023  try
1024  {
1025  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1026  }
1027  catch(ilUserException $e) { $last_history_entry = null; }
1028 
1029  // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1030  if((int)$ilSetting->get('allow_change_loginname') &&
1031  (int)$ilSetting->get('prevent_reuse_of_loginnames') &&
1033  {
1034  throw new ilUserException($this->lng->txt('loginname_already_exists'));
1035  }
1036  else if((int)$ilSetting->get('allow_change_loginname') &&
1037  (int)$ilSetting->get('loginname_change_blocking_time') &&
1038  is_array($last_history_entry) &&
1039  $last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time') > time())
1040  {
1041  include_once 'Services/Calendar/classes/class.ilDate.php';
1042  throw new ilUserException(
1043  sprintf(
1044  $this->lng->txt('changing_loginname_not_possible_info'),
1046  new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1048  new ilDateTime(($last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX))
1049  )
1050  );
1051  }
1052  else
1053  {
1054  // log old loginname in history
1055  if((int)$ilSetting->get('allow_change_loginname') &&
1056  (int)$ilSetting->get('create_history_loginname'))
1057  {
1058  ilObjUser::_writeHistory($this->getId(), self::_lookupLogin($this->getId()));
1059  }
1060 
1061  //update login
1062  $this->login = $a_login;
1063 
1064  $ilDB->manipulateF('
1065  UPDATE usr_data
1066  SET login = %s
1067  WHERE usr_id = %s',
1068  array('text', 'integer'), array($this->getLogin(), $this->getId()));
1069  }
1070 
1071  return true;
1072  }
1073 
1080  function writePref($a_keyword, $a_value)
1081  {
1082  ilObjUser::_writePref($this->id, $a_keyword, $a_value);
1083  $this->setPref($a_keyword, $a_value);
1084  }
1085 
1086 
1092  function deletePref($a_keyword)
1093  {
1094  ilObjUser::_deletePref($this->getId(), $a_keyword);
1095  }
1096 
1102  function _deletePref($a_user_id, $a_keyword)
1103  {
1104  global $ilDB;
1105 
1106  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s",
1107  array("integer", "text"), array($a_user_id, $a_keyword));
1108  }
1109 
1115  function _deleteAllPref($a_user_id)
1116  {
1117  global $ilDB;
1118 
1119  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1120  array("integer"), array($a_user_id));
1121  }
1122 
1126  function _writePref($a_usr_id, $a_keyword, $a_value)
1127  {
1128  global $ilDB;
1129 
1130  ilObjUser::_deletePref($a_usr_id, $a_keyword);
1131  if (strlen($a_value))
1132  {
1133  $ilDB->manipulateF("INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s,%s,%s)",
1134  array("integer", "text", "text"), array($a_usr_id, $a_keyword, $a_value));
1135  }
1136  }
1137 
1142  function writePrefs()
1143  {
1144  global $ilDB;
1145 
1146  ilObjUser::_deleteAllPref($this->id);
1147  foreach ($this->prefs as $keyword => $value)
1148  {
1149  ilObjUser::_writePref($this->id, $keyword, $value);
1150  }
1151  }
1152 
1159  public function getTimeZone()
1160  {
1161  if($tz = $this->getPref('user_tz'))
1162  {
1163  return $tz;
1164  }
1165  else
1166  {
1167  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1168  $settings = ilCalendarSettings::_getInstance();
1169  return $settings->getDefaultTimeZone();
1170  }
1171  }
1172 
1179  public function getTimeFormat()
1180  {
1181  if($format = $this->getPref('time_format'))
1182  {
1183  return $format;
1184  }
1185  else
1186  {
1187  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1188  $settings = ilCalendarSettings::_getInstance();
1189  return $settings->getDefaultTimeFormat();
1190  }
1191  }
1192 
1199  public function getDateFormat()
1200  {
1201  if($format = $this->getPref('date_format'))
1202  {
1203  return $format;
1204  }
1205  else
1206  {
1207  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1208  $settings = ilCalendarSettings::_getInstance();
1209  return $settings->getDefaultDateFormat();
1210  }
1211  }
1212 
1219  function setPref($a_keyword, $a_value)
1220  {
1221  if ($a_keyword != "")
1222  {
1223  $this->prefs[$a_keyword] = $a_value;
1224  }
1225  }
1226 
1232  function getPref($a_keyword)
1233  {
1234  if (array_key_exists($a_keyword, $this->prefs))
1235  {
1236  return $this->prefs[$a_keyword];
1237  }
1238  else
1239  {
1240  return FALSE;
1241  }
1242  }
1243 
1244  function _lookupPref($a_usr_id,$a_keyword)
1245  {
1246  global $ilDB;
1247 
1248  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1249  "AND keyword = ".$ilDB->quote($a_keyword, "text");
1250  $res = $ilDB->query($query);
1251 
1252  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1253  {
1254  return $row->value;
1255  }
1256  return false;
1257  }
1258 
1263  function readPrefs()
1264  {
1265  global $ilDB;
1266 
1267  if (is_array($this->prefs))
1268  {
1269  $this->oldPrefs = $this->prefs;
1270  }
1271 
1272  $this->prefs = ilObjUser::_getPreferences($this->id);
1273  }
1274 
1280  function delete()
1281  {
1282  global $rbacadmin, $ilDB;
1283 
1284  // deassign from ldap groups
1285  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1287  $mapping->deleteUser($this->getId());
1288 
1289  // remove mailbox / update sent mails
1290  include_once ("Services/Mail/classes/class.ilMailbox.php");
1291  $mailbox = new ilMailbox($this->getId());
1292  $mailbox->delete();
1293  $mailbox->updateMailsOfDeletedUser();
1294 
1295  // delete feed blocks on personal desktop
1296  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1297  $costum_block = new ilCustomBlock();
1298  $costum_block->setContextObjId($this->getId());
1299  $costum_block->setContextObjType("user");
1300  $c_blocks = $costum_block->queryBlocksForContext();
1301  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1302  foreach($c_blocks as $c_block)
1303  {
1304  if ($c_block["type"] == "pdfeed")
1305  {
1306  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1307  $fb->delete();
1308  }
1309  }
1310 
1311 
1312  // delete block settings
1313  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1315 
1316  // delete user_account
1317  $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1318  array("integer"), array($this->getId()));
1319 
1320  // delete user_prefs
1321  ilObjUser::_deleteAllPref($this->getId());
1322 
1323  // delete user_session
1324  include_once("./Services/Authentication/classes/class.ilSession.php");
1326 
1327  // remove user from rbac
1328  $rbacadmin->removeUser($this->getId());
1329 
1330  // remove bookmarks
1331  // TODO: move this to class.ilBookmarkFolder
1332  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1333  $ilDB->quote($this->getId(), "integer");
1334  $ilDB->manipulate($q);
1335 
1336  $q = "DELETE FROM bookmark_data WHERE user_id = ".
1337  $ilDB->quote($this->getId(), "integer");
1338  $ilDB->manipulate($q);
1339 
1340  // Delete link check notify entries
1341  include_once './classes/class.ilLinkCheckNotify.php';
1343 
1344  // Delete crs entries
1345  include_once './Modules/Course/classes/class.ilObjCourse.php';
1346  ilObjCourse::_deleteUser($this->getId());
1347 
1348  // Delete user tracking
1349  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1351 
1352  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1354 
1355  // Delete Tracking data SCORM 2004 RTE
1356  include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1358 
1359  // Delete Tracking data SCORM 1.2 RTE
1360  include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1362 
1363  // remove all notifications
1364  include_once "./Services/Notification/classes/class.ilNotification.php";
1366 
1367  // Delete user defined field entries
1369 
1370  // Delete clipboard entries
1371  $this->clipboardDeleteAll();
1372 
1373  // Reset owner
1374  $this->resetOwner();
1375 
1376 
1377  // Trigger deleteUser Event
1378  global $ilAppEventHandler;
1379  $ilAppEventHandler->raise(
1380  'Services/User', 'deleteUser', array('usr_id' => $this->getId())
1381  );
1382 
1383  // delete object data
1384  parent::delete();
1385  return true;
1386  }
1387 
1397  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1398  {
1399  $this->fullname = "";
1400 
1401  if ($a_title)
1402  {
1403  $fullname = $a_title." ";
1404  }
1405  elseif ($this->utitle)
1406  {
1407  $this->fullname = $this->utitle." ";
1408  }
1409 
1410  if ($a_firstname)
1411  {
1412  $fullname .= $a_firstname." ";
1413  }
1414  elseif ($this->firstname)
1415  {
1416  $this->fullname .= $this->firstname." ";
1417  }
1418 
1419  if ($a_lastname)
1420  {
1421  return $fullname.$a_lastname;
1422  }
1423 
1424  $this->fullname .= $this->lastname;
1425  }
1426 
1441  function getFullname($a_max_strlen = 0)
1442  {
1443  if (!$a_max_strlen)
1444  {
1445  return ilUtil::stripSlashes($this->fullname);
1446  }
1447 
1448  if (strlen($this->fullname) <= $a_max_strlen)
1449  {
1450  return ilUtil::stripSlashes($this->fullname);
1451  }
1452 
1453  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1454  {
1455  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1456  }
1457 
1458  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1459  {
1460  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1461  }
1462 
1463  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1464  {
1465  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1466  }
1467 
1468  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1469  }
1470 
1471 // ### AA 03.09.01 updated page access logger ###
1478  {
1479  global $ilDB;
1480 
1481  //query
1482  $q = "SELECT * FROM lo_access ".
1483  "WHERE usr_id= ".$ilDB->quote((int) $this->id, "integer")." ".
1484  "ORDER BY timestamp DESC";
1485  $rst = $ilDB->query($q);
1486 
1487  // fill array
1488  $result = array();
1489  while($record = $ilDB->fetchObject($rst))
1490  {
1491  $result[] = array(
1492  "timestamp" => $record->timestamp,
1493  "usr_id" => $record->usr_id,
1494  "lm_id" => $record->lm_id,
1495  "obj_id" => $record->obj_id,
1496  "lm_title" => $record->lm_title);
1497  }
1498  return $result;
1499  }
1500 
1501 // ### AA 03.09.01 updated page access logger ###
1507  function getLessons()
1508  {
1509  global $ilDB;
1510 
1511  //query
1512  $q = "SELECT * FROM lo_access ".
1513  "WHERE usr_id= ".$ilDB->quote((int) $this->id, "integer")." ";
1514  $rst = $ilDB->query($q);
1515 
1516  // fill array
1517  $result = array();
1518  while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
1519  {
1520  $result[] = array(
1521  "timestamp" => $record->timestamp,
1522  "usr_id" => $record->usr_id,
1523  "lm_id" => $record->lm_id,
1524  "obj_id" => $record->obj_id,
1525  "lm_title" => $record->lm_title);
1526  }
1527  return $result;
1528  }
1529 
1538  public static function _hasAcceptedAgreement($a_username)
1539  {
1540  global $ilDB;
1541 
1542  if($a_username == 'root')
1543  {
1544  return true;
1545  }
1546 
1547  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
1548  "WHERE login = %s AND NOT agree_date IS NULL",
1549  array("text"), array($a_username));
1550  return $ilDB->fetchAssoc($res) ? true : false;
1551  }
1552 
1553 
1558  {
1559  if ($this->agree_date != null || $this->login == "root")
1560  {
1561  return true;
1562  }
1563  return false;
1564  }
1565 
1571  function setLogin($a_str)
1572  {
1573  $this->login = $a_str;
1574  }
1575 
1580  function getLogin()
1581  {
1582  return $this->login;
1583  }
1584 
1590  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1591  {
1592  $this->passwd = $a_str;
1593  $this->passwd_type = $a_type;
1594  }
1595 
1603  function getPasswd()
1604  {
1605  return $this->passwd;
1606  }
1613  function getPasswdType()
1614  {
1615  return $this->passwd_type;
1616  }
1617 
1623  function setGender($a_str)
1624  {
1625  $this->gender = substr($a_str,-1);
1626  }
1627 
1632  function getGender()
1633  {
1634  return $this->gender;
1635  }
1636 
1644  function setUTitle($a_str)
1645  {
1646  $this->utitle = $a_str;
1647  }
1648 
1655  function getUTitle()
1656  {
1657  return $this->utitle;
1658  }
1659 
1665  function setFirstname($a_str)
1666  {
1667  $this->firstname = $a_str;
1668  }
1669 
1674  function getFirstname()
1675  {
1676  return $this->firstname;
1677  }
1678 
1684  function setLastname($a_str)
1685  {
1686  $this->lastname = $a_str;
1687  }
1688 
1693  function getLastname()
1694  {
1695  return $this->lastname;
1696  }
1697 
1703  function setInstitution($a_str)
1704  {
1705  $this->institution = $a_str;
1706  }
1707 
1712  function getInstitution()
1713  {
1714  return $this->institution;
1715  }
1716 
1722  function setDepartment($a_str)
1723  {
1724  $this->department = $a_str;
1725  }
1726 
1731  function getDepartment()
1732  {
1733  return $this->department;
1734  }
1735 
1741  function setStreet($a_str)
1742  {
1743  $this->street = $a_str;
1744  }
1745 
1750  function getStreet()
1751  {
1752  return $this->street;
1753  }
1754 
1760  function setCity($a_str)
1761  {
1762  $this->city = $a_str;
1763  }
1764 
1769  function getCity()
1770  {
1771  return $this->city;
1772  }
1773 
1779  function setZipcode($a_str)
1780  {
1781  $this->zipcode = $a_str;
1782  }
1783 
1788  function getZipcode()
1789  {
1790  return $this->zipcode;
1791  }
1792 
1799  function setCountry($a_str)
1800  {
1801  $this->country = $a_str;
1802  }
1803 
1809  function getCountry()
1810  {
1811  return $this->country;
1812  }
1813 
1819  function setSelectedCountry($a_val)
1820  {
1821  $this->sel_country = $a_val;
1822  }
1823 
1830  {
1831  return $this->sel_country;
1832  }
1833 
1839  function setPhoneOffice($a_str)
1840  {
1841  $this->phone_office = $a_str;
1842  }
1843 
1848  function getPhoneOffice()
1849  {
1850  return $this->phone_office;
1851  }
1852 
1858  function setPhoneHome($a_str)
1859  {
1860  $this->phone_home = $a_str;
1861  }
1862 
1867  function getPhoneHome()
1868  {
1869  return $this->phone_home;
1870  }
1871 
1877  function setPhoneMobile($a_str)
1878  {
1879  $this->phone_mobile = $a_str;
1880  }
1881 
1886  function getPhoneMobile()
1887  {
1888  return $this->phone_mobile;
1889  }
1890 
1896  function setFax($a_str)
1897  {
1898  $this->fax = $a_str;
1899  }
1900 
1905  function getFax()
1906  {
1907  return $this->fax;
1908  }
1909 
1915  function setClientIP($a_str)
1916  {
1917  $this->client_ip = $a_str;
1918  }
1919 
1924  function getClientIP()
1925  {
1926  return $this->client_ip;
1927  }
1928 
1934  function setMatriculation($a_str)
1935  {
1936  $this->matriculation = $a_str;
1937  }
1938 
1943  function getMatriculation()
1944  {
1945  return $this->matriculation;
1946  }
1947 
1954  public static function lookupMatriculation($a_usr_id)
1955  {
1956  global $ilDB;
1957 
1958  $query = "SELECT matriculation FROM usr_data ".
1959  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1960  $res = $ilDB->query($query);
1961  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1962  return $row->matriculation ? $row->matriculation : '';
1963  }
1964 
1970  function setEmail($a_str)
1971  {
1972  $this->email = $a_str;
1973  }
1974 
1979  function getEmail()
1980  {
1981  return $this->email;
1982  }
1983 
1989  function setHobby($a_str)
1990  {
1991  $this->hobby = $a_str;
1992  }
1993 
1998  function getHobby()
1999  {
2000  return $this->hobby;
2001  }
2002 
2008  function setLanguage($a_str)
2009  {
2010  $this->setPref("language",$a_str);
2011  unset($_SESSION['lang']);
2012  }
2013 
2019  function getLanguage()
2020  {
2021  return $this->prefs["language"];
2022  }
2023 
2032  function setDiskQuota($a_disk_quota)
2033  {
2034  $this->setPref("disk_quota",$a_disk_quota);
2035  }
2036 
2046  function getDiskQuota()
2047  {
2048  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
2049  }
2050 
2051  public function setLastPasswordChangeTS($a_last_password_change_ts)
2052  {
2053  $this->last_password_change_ts = $a_last_password_change_ts;
2054  }
2055 
2056  public function getLastPasswordChangeTS()
2057  {
2059  }
2060 
2061 
2062  public static function _lookupLanguage($a_usr_id)
2063  {
2064  global $ilDB;
2065 
2066  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
2067  $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
2068  $ilDB->quote('language', "text");
2069  $r = $ilDB->query($q);
2070 
2071  while($row = $ilDB->fetchAssoc($r))
2072  {
2073  return $row['value'];
2074  }
2075  return 'en';
2076  }
2077 
2078 
2079  function _checkPassword($a_usr_id, $a_pw)
2080  {
2081  global $ilDB;
2082 
2083  $pw = ilObjUser::_lookup($a_usr_id, "passwd");
2084  if ($pw == md5($a_pw))
2085  {
2086  return true;
2087  }
2088  return false;
2089  }
2090 
2091  function _writeExternalAccount($a_usr_id, $a_ext_id)
2092  {
2093  global $ilDB;
2094 
2095  $ilDB->manipulateF("UPDATE usr_data ".
2096  " SET ext_account = %s WHERE usr_id = %s",
2097  array("text", "integer"),
2098  array($a_ext_id, $a_usr_id));
2099  }
2100 
2101  function _writeAuthMode($a_usr_id, $a_auth_mode)
2102  {
2103  global $ilDB;
2104 
2105  $ilDB->manipulateF("UPDATE usr_data ".
2106  " SET auth_mode = %s WHERE usr_id = %s",
2107  array("text", "integer"),
2108  array($a_auth_mode, $a_usr_id));
2109  }
2110 
2116  {
2117  return $_SESSION['lang'];
2118  }
2119 
2125  function setLastLogin($a_str)
2126  {
2127  $this->last_login = $a_str;
2128  }
2129 
2135  function getLastLogin()
2136  {
2137  return $this->last_login;
2138  }
2139 
2145  function setLastUpdate($a_str)
2146  {
2147  $this->last_update = $a_str;
2148  }
2149  function getLastUpdate()
2150  {
2151  return $this->last_update;
2152  }
2153 
2159  function setComment($a_str)
2160  {
2161  $this->referral_comment = $a_str;
2162  }
2163 
2168  function getComment()
2169  {
2170  return $this->referral_comment;
2171  }
2172 
2179  function setApproveDate($a_str)
2180  {
2181  $this->approve_date = $a_str;
2182  }
2183 
2189  function getApproveDate()
2190  {
2191  return $this->approve_date;
2192  }
2193 
2194  // BEGIN DiskQuota: show when user accepted user agreement
2200  function getAgreeDate()
2201  {
2202  return $this->agree_date;
2203  }
2210  function setAgreeDate($a_str)
2211  {
2212  $this->agree_date = $a_str;
2213  }
2214  // END DiskQuota: show when user accepted user agreement
2215 
2222  function setActive($a_active, $a_owner = 0)
2223  {
2224  $this->setOwner($a_owner);
2225 
2226  if ($a_active)
2227  {
2228  $this->active = 1;
2229  $this->setApproveDate(date('Y-m-d H:i:s'));
2230  $this->setOwner($a_owner);
2231  }
2232  else
2233  {
2234  $this->active = 0;
2235  $this->setApproveDate(null);
2236  }
2237  }
2238 
2243  function getActive()
2244  {
2245  return $this->active;
2246  }
2247 
2251  public function _lookupActive($a_usr_id)
2252  {
2253  global $ilDB;
2254 
2255  $query = 'SELECT usr_id FROM usr_data '.
2256  'WHERE active = '.$ilDB->quote(1,'integer').' '.
2257  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
2258  $res = $ilDB->query($query);
2259  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2260  {
2261  return true;
2262  }
2263  return false;
2264  }
2265 
2271  function syncActive()
2272  {
2273  global $ilAuth;
2274 
2275  $storedActive = 0;
2276  if ($this->getStoredActive($this->id))
2277  {
2278  $storedActive = 1;
2279  }
2280 
2281  $currentActive = 0;
2282  if ($this->active)
2283  {
2284  $currentActive = 1;
2285  }
2286 
2287  if ((!empty($storedActive) && empty($currentActive)) ||
2288  (empty($storedActive) && !empty($currentActive)))
2289  {
2290  $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2291  }
2292  }
2293 
2300  function getStoredActive($a_id)
2301  {
2302  $active = ilObjUser::_lookup($a_id, "active");
2303  return $active ? true : false;
2304  }
2305 
2311  function setSkin($a_str)
2312  {
2313  // TODO: exception handling (dir exists)
2314  $this->skin = $a_str;
2315  }
2316 
2317  function setTimeLimitOwner($a_owner)
2318  {
2319  $this->time_limit_owner = $a_owner;
2320  }
2322  {
2323  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2324  }
2325  function setTimeLimitFrom($a_from)
2326  {
2327  $this->time_limit_from = $a_from;
2328  }
2329  function getTimeLimitFrom()
2330  {
2331  return $this->time_limit_from ? $this->time_limit_from : time();
2332  }
2333  function setTimeLimitUntil($a_until)
2334  {
2335  $this->time_limit_until = $a_until;
2336  }
2338  {
2339  return $this->time_limit_until ? $this->time_limit_until : time();
2340  }
2341  function setTimeLimitUnlimited($a_unlimited)
2342  {
2343  $this->time_limit_unlimited = $a_unlimited;
2344  }
2346  {
2347  return $this->time_limit_unlimited;
2348  }
2349  function setTimeLimitMessage($a_time_limit_message)
2350  {
2351  return $this->time_limit_message = $a_time_limit_message;
2352  }
2354  {
2355  return $this->time_limit_message;
2356  }
2357 
2358  public function setLoginAttempts($a_login_attempts)
2359  {
2360  $this->login_attempts = $a_login_attempts;
2361  }
2362 
2363  public function getLoginAttempts()
2364  {
2365  return $this->login_attempts;
2366  }
2367 
2368 
2369  function checkTimeLimit()
2370  {
2371  if($this->getTimeLimitUnlimited())
2372  {
2373  return true;
2374  }
2375  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2376  {
2377  return true;
2378  }
2379  return false;
2380  }
2381  function setProfileIncomplete($a_prof_inc)
2382  {
2383  $this->profile_incomplete = (boolean) $a_prof_inc;
2384  }
2386  {
2387  return $this->profile_incomplete;
2388  }
2389 
2390  public function isPasswordChangeDemanded()
2391  {
2392  //error_reporting(E_ALL);
2393  if( $this->id == ANONYMOUS_USER_ID || $this->id == SYSTEM_USER_ID )
2394  return false;
2395 
2396  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2397  $security = ilSecuritySettings::_getInstance();
2398 
2400  && $security->isPasswordChangeOnFirstLoginEnabled()
2401  && $this->getLastPasswordChangeTS() == 0
2402  ){
2403  return true;
2404  }
2405  else return false;
2406  }
2407 
2408  public function isPasswordExpired()
2409  {
2410  //error_reporting(E_ALL);
2411  if($this->id == ANONYMOUS_USER_ID) return false;
2412 
2413  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2414  $security = ilSecuritySettings::_getInstance();
2415  if( $security->getAccountSecurityMode() == ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED &&
2416  $this->getLastPasswordChangeTS() > 0 )
2417  {
2418  $max_pass_age = $security->getPasswordMaxAge();
2419  if( $max_pass_age > 0 )
2420  {
2421  $max_pass_age_ts = ( $max_pass_age * 86400 );
2422  $pass_change_ts = $this->getLastPasswordChangeTS();
2423  $current_ts = time();
2424 
2425  if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2426  return true;
2427  }
2428  }
2429  return false;
2430  }
2431 
2432  public function getPasswordAge()
2433  {
2434  $current_ts = time();
2435  $pass_change_ts = $this->getLastPasswordChangeTS();
2436  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2437  return $password_age;
2438  }
2439 
2440  public function setLastPasswordChangeToNow()
2441  {
2442  global $ilDB;
2443 
2444  $this->setLastPasswordChangeTS( time() );
2445 
2446  $query = "UPDATE usr_data SET usr_data.last_password_change = %s " .
2447  "WHERE usr_data.usr_id = %s";
2448  $affected = $ilDB->manipulateF($query,
2449  array('integer','integer'),
2450  array($this->getLastPasswordChangeTS(),$this->id));
2451  if($affected) return true;
2452  else return false;
2453  }
2454 
2455  public function resetLastPasswordChange()
2456  {
2457  global $ilDB;
2458 
2459  $query = "UPDATE usr_data SET usr_data.last_password_change = 0 " .
2460  "WHERE usr_data.usr_id = %s";
2461  $affected = $ilDB->manipulateF( $query, array('integer'),
2462  array($this->getId()) );
2463  if($affected) return true;
2464  else return false;
2465  }
2466 
2472  function setLatitude($a_latitude)
2473  {
2474  $this->latitude = $a_latitude;
2475  }
2476 
2482  function getLatitude()
2483  {
2484  return $this->latitude;
2485  }
2486 
2492  function setLongitude($a_longitude)
2493  {
2494  $this->longitude = $a_longitude;
2495  }
2496 
2502  function getLongitude()
2503  {
2504  return $this->longitude;
2505  }
2506 
2512  function setLocationZoom($a_locationzoom)
2513  {
2514  $this->loc_zoom = $a_locationzoom;
2515  }
2516 
2522  function getLocationZoom()
2523  {
2524  return $this->loc_zoom;
2525  }
2526 
2527  function &getAppliedUsers()
2528  {
2529  $this->applied_users = array();
2530  $this->__readAppliedUsers($this->getId());
2531 
2532  return $this->applied_users ? $this->applied_users : array();
2533  }
2534 
2535  function isChild($a_usr_id)
2536  {
2537  if($a_usr_id == $this->getId())
2538  {
2539  return true;
2540  }
2541 
2542  $this->applied_users = array();
2543  $this->__readAppliedUsers($this->getId());
2544 
2545  return in_array($a_usr_id,$this->applied_users);
2546  }
2547 
2548  function __readAppliedUsers($a_parent_id)
2549  {
2550  global $ilDB;
2551 
2552  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2553  "WHERE time_limit_owner = %s",
2554  array("integer"),
2555  array($a_parent_id));
2556  while ($row = $ilDB->fetchObject($res))
2557  {
2558  $this->applied_users[] = $row->usr_id;
2559 
2560  // recursion
2561  $this->__readAppliedUsers($row->usr_id);
2562  }
2563  return true;
2564  }
2565 
2566  /*
2567  * check user id with login name
2568  * @access public
2569  */
2570  function checkUserId()
2571  {
2572  global $ilDB,$ilAuth, $ilSetting;
2573 
2576  if ($id > 0)
2577  {
2578  // check for simultaneous logins, except the user is the anonymous one
2579  if( $id != ANONYMOUS_USER_ID && (int)$ilSetting->get('ps_prevent_simultaneous_logins') == 1 )
2580  {
2581  $res = $ilDB->queryf('
2582  SELECT * FROM usr_session WHERE user_id = %s AND expires > %s',
2583  array('integer', 'integer'),
2584  array($id, time()));
2585  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2586  {
2587  $ilAuth->logout();
2588  @session_destroy();
2589  ilUtil::redirect('login.php?simultaneous_login=true');
2590  exit();
2591  }
2592  }
2593 
2594  return $id;
2595  }
2596  return false;
2597  }
2598 
2602  private static function getLoginFromAuth() {
2603  global $ilAuth;
2604 
2605  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2606  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2608  {
2609  require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2610  require_once ('Services/Database/classes/class.ilAuthContainerMDB2.php');
2611  $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2612  }
2613  else
2614  {
2615  $login =$ilAuth->getUsername();
2616  }
2617 
2618  return $login;
2619  }
2620 
2621  /*
2622  * check to see if current user has been made active
2623  * @access public
2624  * @return true if active, otherwise false
2625  */
2627  {
2628  global $ilDB,$ilAuth;
2629 
2631  $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2632  array("text"),
2633  array($login));
2634  //query has got a result
2635  if ($rec = $ilDB->fetchAssoc($set))
2636  {
2637  if ($rec["active"])
2638  {
2639  return true;
2640  }
2641  }
2642 
2643  return false;
2644  }
2645 
2646  /*
2647  * STATIC METHOD
2648  * get the user_id of a login name
2649  * @param string login name
2650  * @return integer id of user
2651  * @static
2652  * @access public
2653  */
2654  function getUserIdByLogin($a_login)
2655  {
2656  return (int) ilObjUser::_lookupId($a_login);
2657  }
2658 
2667  function _getUserIdsByEmail($a_email)
2668  {
2669  global $ilias, $ilDB;
2670 
2671  $res = $ilDB->queryF("SELECT login FROM usr_data ".
2672  "WHERE email = %s and active = 1",
2673  array("text"),
2674  array($a_email));
2675  $ids = array ();
2676  while($row = $ilDB->fetchObject($res))
2677  {
2678  $ids[] = $row->login;
2679  }
2680 
2681  return $ids;
2682  }
2683 
2684 
2685 
2694  function getUserIdByEmail($a_email)
2695  {
2696  global $ilDB;
2697 
2698  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2699  "WHERE email = %s", array("text"), array($a_email));
2700 
2701  $row = $ilDB->fetchObject($res);
2702  return $row->usr_id ? $row->usr_id : 0;
2703  }
2704 
2705  /*
2706  * STATIC METHOD
2707  * get the login name of a user_id
2708  * @param integer id of user
2709  * @return string login name; false if not found
2710  * @static
2711  * @access public
2712  */
2713  function getLoginByUserId($a_userid)
2714  {
2715  $login = ilObjUser::_lookupLogin($a_userid);
2716  return $login ? $login : false;
2717  }
2718 
2729  static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2730  {
2731  global $ilias, $ilDB, $ilLog;
2732 
2733 
2734  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2735 
2736  $without_anonymous_users = true;
2737 
2738  // determine join filter
2739  $join_filter = " WHERE ";
2740  if ($filter_settings !== FALSE && strlen($filter_settings))
2741  {
2742  switch ($filter_settings)
2743  {
2744  case 3:
2745  // show only users without courses
2746  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.usr_id IS NULL AND ";
2747  break;
2748  case 5:
2749  // show only users with a certain course membership
2750  $ref_id = $_SESSION["user_filter_data"];
2751  if ($ref_id)
2752  {
2753  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.obj_id = ".
2754  "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2755  }
2756  break;
2757  case 6:
2758  global $rbacreview;
2759  $ref_id = $_SESSION["user_filter_data"];
2760  if ($ref_id)
2761  {
2762  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2763  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2764  if (is_array($local_roles) && count($local_roles))
2765  {
2766  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2767  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2768  }
2769  }
2770  break;
2771  case 7:
2772  global $rbacreview;
2773  $rol_id = $_SESSION["user_filter_data"];
2774  if ($rol_id)
2775  {
2776  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2777  $ilDB->quote($rol_id, "integer")." AND ";
2778  $without_anonymous_users = false;
2779  }
2780  break;
2781  }
2782  }
2783  // This is a temporary hack to search users by their role
2784  // See Mantis #338. This is a hack due to Mantis #337.
2785  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2786  {
2787  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2788  "FROM object_data,rbac_ua,usr_data ".
2789  "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2790  " AND object_data.type = 'role' ".
2791  "AND rbac_ua.rol_id = object_data.obj_id ".
2792  "AND usr_data.usr_id = rbac_ua.usr_id ".
2793  "AND rbac_ua.usr_id != ".$illDB->quote(ANONYMOUS_USER_ID, "integer");
2794  }
2795  else
2796  {
2797  $query.= $join_filter.
2798  "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2799  "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2800  "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2801  "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2802 
2803  if ($filter_settings !== FALSE && strlen($filter_settings))
2804  {
2805  switch ($filter_settings)
2806  {
2807  case 0:
2808  $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2809  break;
2810  case 1:
2811  $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2812  break;
2813  case 2:
2814  $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2815  break;
2816  case 4:
2817  $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"]));
2818  $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2819  break;
2820  }
2821  }
2822 
2823  if ($without_anonymous_users)
2824  {
2825  $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2826  }
2827 
2828  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2829  {
2830  $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2831  }
2832 
2833  }
2834  $ilLog->write($query);
2835  $res = $ilDB->query($query);
2836  while ($row = $ilDB->fetchObject($res))
2837  {
2838  $users[] = array(
2839  "usr_id" => $row->usr_id,
2840  "login" => $row->login,
2841  "firstname" => $row->firstname,
2842  "lastname" => $row->lastname,
2843  "email" => $row->email,
2844  "active" => $row->active);
2845  $ids[] = $row->usr_id;
2846  }
2847  if ($a_return_ids_only)
2848  return $ids ? $ids : array();
2849  else
2850  return $users ? $users : array();
2851  }
2852 
2862  {
2863  global $ilDB;
2864 
2865  $res = $ilDB->query("SELECT login FROM usr_data");
2866  while($row = $ilDB->fetchObject($res))
2867  {
2868  $logins[] = $row->login;
2869  }
2870  return $logins ? $logins : array();
2871  }
2872 
2881  public static function _readUsersProfileData($a_user_ids)
2882  {
2883  global $ilDB;
2884  $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2885  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2886  while ($row = $ilDB->fetchAssoc($res))
2887  {
2888  $user_data["$row[usr_id]"] = $row;
2889  }
2890  return $user_data ? $user_data : array();
2891  }
2892 
2901  function _getAllUserData($a_fields = NULL, $active =-1)
2902  {
2903  global $ilDB;
2904 
2905  $result_arr = array();
2906  $types = array();
2907  $values = array();
2908 
2909  if ($a_fields !== NULL and is_array($a_fields))
2910  {
2911  if (count($a_fields) == 0)
2912  {
2913  $select = "*";
2914  }
2915  else
2916  {
2917  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2918  unset($a_fields[$usr_id_field]);
2919 
2920  $select = implode(",",$a_fields).",usr_data.usr_id";
2921  // online time
2922  if(in_array('online_time',$a_fields))
2923  {
2924  $select .= ",ut_online.online_time ";
2925  }
2926  }
2927 
2928  $q = "SELECT ".$select." FROM usr_data ";
2929 
2930  // Add online_time if desired
2931  // Need left join here to show users that never logged in
2932  if(in_array('online_time',$a_fields))
2933  {
2934  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2935  }
2936 
2937  switch ($active)
2938  {
2939  case 0:
2940  case 1:
2941  $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2942  break;
2943  case 2:
2944  $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2945  break;
2946  case 3:
2947  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2948  $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2949  $r = $ilDB->query($qtemp);
2950  $course_users = array();
2951  while ($row = $ilDB->fetchAssoc($r))
2952  {
2953  array_push($course_users, $row["usr_id"]);
2954  }
2955  if (count($course_users))
2956  {
2957  $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2958  }
2959  else
2960  {
2961  return $result_arr;
2962  }
2963  break;
2964  case 4:
2965  $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"]));
2966  $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2967  break;
2968  case 5:
2969  $ref_id = $_SESSION["user_filter_data"];
2970  if ($ref_id)
2971  {
2972  $q .= " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id ".
2973  "WHERE crs_members.obj_id = (SELECT obj_id FROM object_reference ".
2974  "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2975  }
2976  break;
2977  case 6:
2978  global $rbacreview;
2979  $ref_id = $_SESSION["user_filter_data"];
2980  if ($ref_id)
2981  {
2982  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2983  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2984  if (is_array($local_roles) && count($local_roles))
2985  {
2986  $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2987  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2988  }
2989  }
2990  break;
2991  case 7:
2992  $rol_id = $_SESSION["user_filter_data"];
2993  if ($rol_id)
2994  {
2995  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2996  $ilDB->quote($rol_id, "integer");
2997  }
2998  break;
2999  }
3000  $r = $ilDB->query($q);
3001 
3002  while ($row = $ilDB->fetchAssoc($r))
3003  {
3004  $result_arr[] = $row;
3005  }
3006  }
3007 
3008  return $result_arr;
3009  }
3010 
3014  function _getNumberOfUsersForStyle($a_skin, $a_style)
3015  {
3016  global $ilDB;
3017 
3018  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
3019  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3020  " AND up1.value= ".$ilDB->quote($a_style, "text").
3021  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3022  " AND up2.value= ".$ilDB->quote($a_skin, "text").
3023  " AND up1.usr_id = up2.usr_id ";
3024 
3025  $cnt_set = $ilDB->query($q);
3026 
3027  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
3028 
3029  return $cnt_rec["cnt"];
3030  }
3031 
3036  {
3037  global $ilDB;
3038 
3039  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
3040  " WHERE up1.keyword = ".$ilDB->quote("style", "text").
3041  " AND up2.keyword = ".$ilDB->quote("skin", "text").
3042  " AND up1.usr_id = up2.usr_id";
3043 
3044  $sty_set = $ilDB->query($q);
3045 
3046  $styles = array();
3047  while($sty_rec = $ilDB->fetchAssoc($sty_set))
3048  {
3049  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
3050  }
3051 
3052  return $styles;
3053  }
3054 
3058  function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3059  {
3060  global $ilDB;
3061 
3062  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
3063  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3064  " AND up1.value= ".$ilDB->quote($a_from_style, "text").
3065  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3066  " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
3067  " AND up1.usr_id = up2.usr_id ";
3068 
3069  $usr_set = $ilDB->query($q);
3070 
3071  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3072  {
3073  ilObjUser::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3074  ilObjUser::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3075  }
3076  }
3077 
3078 
3088  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3089  {
3090  global $ilDB;
3091 
3092  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3093  "item_id = %s AND type = %s AND user_id = %s",
3094  array("integer", "text", "integer"),
3095  array($a_item_id, $a_type, $a_usr_id));
3096 
3097  // only insert if item is not already on desktop
3098  if (!$ilDB->fetchAssoc($item_set))
3099  {
3100  $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3101  " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3102  array($a_item_id,$a_type,$a_usr_id,$a_par));
3103  }
3104 
3105  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3107  }
3108 
3116  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3117  {
3118  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3119  }
3120 
3129  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3130  {
3131  global $ilDB;
3132 
3133  $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3134  " WHERE item_id = %s AND type = %s AND user_id = %s",
3135  array("text", "integer", "text", "integer"),
3136  array($a_par, $a_item_id, $a_type, $this->getId()));
3137  }
3138 
3139 
3149  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3150  {
3151  global $ilDB;
3152 
3153  $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3154  " item_id = %s AND type = %s AND user_id = %s",
3155  array("integer", "text", "integer"),
3156  array($a_item_id, $a_type, $a_usr_id));
3157 
3158  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3160  }
3161 
3169  function dropDesktopItem($a_item_id, $a_type)
3170  {
3171  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3172  }
3173 
3180  static function _removeItemFromDesktops($a_id)
3181  {
3182  global $ilDB;
3183 
3184  $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3185  array("integer"), array($a_id));
3186 
3187  $users = array();
3188 
3189  while ($row = $ilDB->fetchObject($r))
3190  {
3191  $users[] = $row->user_id;
3192  } // while
3193 
3194  if (count($users) > 0)
3195  {
3196  $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3197  array("integer"), array($a_id));
3198  }
3199 
3200  return $users;
3201  }
3202 
3212  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3213  {
3214  global $ilDB;
3215 
3216  if (self::$is_desktop_item_loaded[$a_usr_id.":".$a_item_id])
3217  {
3218  return self::$is_desktop_item_cache[$a_usr_id.":".$a_item_id.":".$a_type];
3219  }
3220  $item_set = $ilDB->queryF("SELECT item_id FROM desktop_item WHERE ".
3221  "item_id = %s AND type = %s AND user_id = %s",
3222  array("integer", "text", "integer"),
3223  array($a_item_id, $a_type, $a_usr_id));
3224 
3225  if ($ilDB->fetchAssoc($item_set))
3226  {
3227  return true;
3228  }
3229  else
3230  {
3231  return false;
3232  }
3233  }
3234 
3241  static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3242  {
3243  global $ilDB;
3244 
3245  if (!is_array($a_item_ids))
3246  {
3247  return;
3248  }
3249 
3250  $item_ids = array();
3251  foreach ($a_item_ids as $id)
3252  {
3253  if (!self::$is_desktop_item_loaded[$a_usr_id.":".$id])
3254  {
3255  $item_ids[] = $id;
3256  }
3257  self::$is_desktop_item_loaded[$a_usr_id.":".$id] = true;
3258  }
3259 
3260  if (count($item_ids) > 0)
3261  {
3262  $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE ".
3263  $ilDB->in("item_id", $item_ids, false, "integer").
3264  " AND user_id = ".$ilDB->quote($a_usr_id, "integer"));
3265  while ($r = $ilDB->fetchAssoc($item_set))
3266  {
3267  self::$is_desktop_item_cache[$a_usr_id.":".$r["item_id"].":".$r["type"]]
3268  = true;
3269  }
3270  }
3271  }
3272 
3280  function isDesktopItem($a_item_id, $a_type)
3281  {
3282  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3283  }
3284 
3285  function getDesktopItems($a_types = "")
3286  {
3287  return $this->_lookupDesktopItems($this->getId(), $a_types);
3288  }
3289 
3296  static function _lookupDesktopItems($user_id, $a_types = "")
3297  {
3298  global $ilUser, $rbacsystem, $tree, $ilDB;
3299 
3300  if ($a_types == "")
3301  {
3302  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3303  " FROM desktop_item it, object_reference oref ".
3304  ", object_data obj".
3305  " WHERE ".
3306  "it.item_id = oref.ref_id AND ".
3307  "oref.obj_id = obj.obj_id AND ".
3308  "it.user_id = %s", array("integer"), array($user_id));
3309  $items = array();
3310  while ($item_rec = $ilDB->fetchAssoc($item_set))
3311  {
3312  if ($tree->isInTree($item_rec["ref_id"])
3313  && $item_rec["type"] != "rolf")
3314  {
3315  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3316  $par_left = $tree->getLeftValue($parent_ref);
3317  $par_left = sprintf("%010d", $par_left);
3318 
3319 
3320  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3321  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3322  $items[$par_left.$title.$item_rec["ref_id"]] =
3323  array("ref_id" => $item_rec["ref_id"],
3324  "obj_id" => $item_rec["obj_id"],
3325  "type" => $item_rec["type"],
3326  "title" => $title,
3327  "description" => $desc,
3328  "parent_ref" => $parent_ref);
3329  }
3330  }
3331  ksort($items);
3332  }
3333  else
3334  {
3335  if (!is_array($a_types))
3336  {
3337  $a_types = array($a_types);
3338  }
3339  $items = array();
3340  $foundsurveys = array();
3341  foreach($a_types as $a_type)
3342  {
3343  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3344  ", object_data obj WHERE ".
3345  "it.item_id = oref.ref_id AND ".
3346  "oref.obj_id = obj.obj_id AND ".
3347  "it.type = %s AND ".
3348  "it.user_id = %s ".
3349  "ORDER BY title",
3350  array("text", "integer"),
3351  array($a_type, $user_id));
3352 
3353  while ($item_rec = $ilDB->fetchAssoc($item_set))
3354  {
3355  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3356  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3357  $items[$title.$a_type.$item_rec["ref_id"]] =
3358  array("ref_id" => $item_rec["ref_id"],
3359  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3360  "title" => $title, "description" => $desc);
3361  }
3362 
3363  }
3364  ksort($items);
3365  }
3366  return $items;
3367  }
3368 
3374 
3382  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3383  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3384  {
3385  global $ilDB;
3386 
3387  if ($a_time == 0)
3388  {
3389  $a_time = date("Y-m-d H:i:s", time());
3390  }
3391 
3392  $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3393  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3394  array("integer", "integer", "text", "integer"),
3395  array(0, $a_item_id, $a_type, $this->getId()));
3396 
3397  // only insert if item is not already in clipboard
3398  if (!$d = $item_set->fetchRow())
3399  {
3400  $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3401  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3402  " (%s,%s,%s,%s,%s,%s,%s)",
3403  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3404  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3405  }
3406  else
3407  {
3408  $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3409  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3410  array("timestamp", "integer", "integer", "text"),
3411  array($a_time, $this->getId(), $a_item_id, $a_type));
3412  }
3413  }
3414 
3418  function addToPCClipboard($a_content, $a_time, $a_nr)
3419  {
3420  global $ilDB;
3421  if ($a_time == 0)
3422  {
3423  $a_time = date("Y-m-d H:i:s", time());
3424  }
3425  $ilDB->insert("personal_pc_clipboard", array(
3426  "user_id" => array("integer", $this->getId()),
3427  "content" => array("clob", $a_content),
3428  "insert_time" => array("timestamp", $a_time),
3429  "order_nr" => array("integer", $a_nr)
3430  ));
3431  }
3432 
3437  {
3438  global $ilDB;
3439 
3440  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3441  " WHERE user_id = %s", array("integer"), array($this->getId()));
3442  $row = $ilDB->fetchAssoc($set);
3443 
3444  $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3445  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3446  array("integer", "timestamp"),
3447  array($this->getId(), $row["mtime"]));
3448  $content = array();
3449  while ($row = $ilDB->fetchAssoc($set))
3450  {
3451  $content[] = $row["content"];
3452  }
3453 
3454  return $content;
3455  }
3456 
3460  function clipboardHasObjectsOfType($a_type)
3461  {
3462  global $ilDB;
3463 
3464  $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3465  "parent = %s AND type = %s AND user_id = %s",
3466  array("integer", "text", "integer"),
3467  array(0, $a_type, $this->getId()));
3468  if ($rec = $ilDB->fetchAssoc($set))
3469  {
3470  return true;
3471  }
3472 
3473  return false;
3474  }
3475 
3480  {
3481  global $ilDB;
3482 
3483  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3484  "type = %s AND user_id = %s",
3485  array("text", "integer"),
3486  array($a_type, $this->getId()));
3487  }
3488 
3493  {
3494  global $ilDB;
3495 
3496  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3497  "user_id = %s", array("integer"), array($this->getId()));
3498  }
3499 
3503  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3504  {
3505  global $ilDB;
3506 
3507  $par = "";
3508  if ($a_top_nodes_only)
3509  {
3510  $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3511  }
3512 
3513  $type_str = ($a_type != "")
3514  ? " AND type = ".$ilDB->quote($a_type, "text")." "
3515  : "";
3516  $q = "SELECT * FROM personal_clipboard WHERE ".
3517  "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3518  $type_str.$par.
3519  " ORDER BY order_nr";
3520  $objs = $ilDB->query($q);
3521  $objects = array();
3522  while ($obj = $ilDB->fetchAssoc($objs))
3523  {
3524  if ($obj["type"] == "mob")
3525  {
3526  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3527  }
3528  if ($obj["type"] == "incl")
3529  {
3530  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3531  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3532  }
3533  $objects[] = array ("id" => $obj["item_id"],
3534  "type" => $obj["type"], "title" => $obj["title"],
3535  "insert_time" => $obj["insert_time"]);
3536  }
3537  return $objects;
3538  }
3539 
3543  function getClipboardChilds($a_parent, $a_insert_time)
3544  {
3545  global $ilDB, $ilUser;
3546 
3547  $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3548  "user_id = %s AND parent = %s AND insert_time = %s ".
3549  " ORDER BY order_nr",
3550  array("integer", "integer", "timestamp"),
3551  array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3552  $objects = array();
3553  while ($obj = $ilDB->fetchAssoc($objs))
3554  {
3555  if ($obj["type"] == "mob")
3556  {
3557  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3558  }
3559  $objects[] = array ("id" => $obj["item_id"],
3560  "type" => $obj["type"], "title" => $obj["title"]);
3561  }
3562  return $objects;
3563  }
3564 
3573  function _getUsersForClipboadObject($a_type, $a_id)
3574  {
3575  global $ilDB;
3576 
3577  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3578  "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3579  "type = ".$ilDB->quote($a_type, "text");
3580  $user_set = $ilDB->query($q);
3581  $users = array();
3582  while ($user_rec = $ilDB->fetchAssoc($user_set))
3583  {
3584  $users[] = $user_rec["user_id"];
3585  }
3586 
3587  return $users;
3588  }
3589 
3597  function removeObjectFromClipboard($a_item_id, $a_type)
3598  {
3599  global $ilDB;
3600 
3601  $q = "DELETE FROM personal_clipboard WHERE ".
3602  "item_id = ".$ilDB->quote($a_item_id, "integer").
3603  " AND type = ".$ilDB->quote($a_type, "text")." ".
3604  " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3605  $ilDB->manipulate($q);
3606  }
3607 
3608  function _getImportedUserId($i2_id)
3609  {
3610  global $ilDB;
3611 
3612  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3613  $ilDB->quote($i2_id, "text");
3614 
3615  $res = $ilDB->query($query);
3616  while($row = $ilDB->fetchObject($res))
3617  {
3618  $id = $row->obj_id;
3619  }
3620  return $id ? $id : 0;
3621  }
3622 
3623 /*
3624 
3625  function setiLincData($a_id,$a_login,$a_passwd)
3626  {
3627  $this->ilinc_id = $a_id;
3628  $this->ilinc_login = $a_login;
3629  $this->ilinc_passwd = $a_passwd;
3630  }
3631 
3632 */
3633 
3634 /*
3635 
3636  function getiLincData()
3637  {
3638  return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
3639  }
3640 */
3645  function setAuthMode($a_str)
3646  {
3647  $this->auth_mode = $a_str;
3648  }
3649 
3654  function getAuthMode($a_auth_key = false)
3655  {
3656  if (!$a_auth_key)
3657  {
3658  return $this->auth_mode;
3659  }
3660 
3661  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3662  return ilAuthUtils::_getAuthMode($this->auth_mode);
3663  }
3664 
3672  function setExternalAccount($a_str)
3673  {
3674  $this->ext_account = $a_str;
3675  }
3676 
3685  {
3686  return $this->ext_account;
3687  }
3688 
3700  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3701  {
3702  global $ilDB,$ilSetting;
3703 
3704  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3705  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3706  "WHERE auth_mode = %s";
3707  $types[] = "text";
3708  $values[] = $a_auth_mode;
3709  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3710  {
3711  $q.= " OR auth_mode = %s ";
3712  $types[] = "text";
3713  $values[] = 'default';
3714  }
3715 
3716  $res = $ilDB->queryF($q, $types, $values);
3717  while ($row = $ilDB->fetchObject($res))
3718  {
3719  if($row->auth_mode == 'default')
3720  {
3721  $accounts[$row->usr_id] = $row->login;
3722  }
3723  else
3724  {
3725  $accounts[$row->usr_id] = $row->ext_account;
3726  }
3727  }
3728  return $accounts ? $accounts : array();
3729  }
3730 
3738  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3739  {
3740  global $ilDB;
3741 
3742  if(!is_array($a_usr_ids))
3743  {
3744  return false;
3745  }
3746  $q = "UPDATE usr_data SET active = %s WHERE ".
3747  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3748  $ilDB->manipulateF($q, array("integer"), array(($a_status ? 1 : 0)));
3749 
3750  return true;
3751  }
3752 
3753 
3762  public static function _lookupAuthMode($a_usr_id)
3763  {
3764  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3765  }
3766 
3773  public static function _checkExternalAuthAccount($a_auth, $a_account)
3774  {
3775  global $ilDB,$ilSetting;
3776 
3777  // Check directly with auth_mode
3778  $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3779  " ext_account = %s AND auth_mode = %s",
3780  array("text", "text"),
3781  array($a_account, $a_auth));
3782  if ($usr = $ilDB->fetchAssoc($r))
3783  {
3784  return $usr["login"];
3785  }
3786 
3787  // For compatibility, check for login (no ext_account entry given)
3788  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3789  "WHERE login = %s AND auth_mode = %s",
3790  array("text", "text"),
3791  array($a_account, $a_auth));
3792  if($usr = $ilDB->fetchAssoc($res))
3793  {
3794  return $usr['login'];
3795  }
3796 
3797  // If auth_default == $a_auth => check for login
3798  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3799  {
3800  $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3801  " ext_account = %s AND auth_mode = %s",
3802  array("text", "text"),
3803  array($a_account, "default"));
3804  if ($usr = $ilDB->fetchAssoc($res))
3805  {
3806  return $usr["login"];
3807  }
3808  // Search for login (no ext_account given)
3809  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3810  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3811  array("text", "text"),
3812  array($a_account, "default"));
3813  if($usr = $ilDB->fetchAssoc($res))
3814  {
3815  return $usr["login"];
3816  }
3817  }
3818  return false;
3819  }
3820 
3825  {
3826  global $ilDB;
3827 
3828  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3829  "GROUP BY auth_mode");
3830  $cnt_arr = array();
3831  while($cnt = $ilDB->fetchAssoc($r))
3832  {
3833  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3834  }
3835 
3836  return $cnt_arr;
3837  }
3838 
3844  function _getLocalAccountsForEmail($a_email)
3845  {
3846  global $ilDB, $ilSetting;
3847 
3848  // default set to local (1)?
3849 
3850  $q = "SELECT * FROM usr_data WHERE ".
3851  " email = %s AND (auth_mode = %s ";
3852  $types = array("text", "text");
3853  $values = array($a_email, "local");
3854 
3855  if ($ilSetting->get("auth_mode") == 1)
3856  {
3857  $q.=" OR auth_mode = %s";
3858  $types[] = "text";
3859  $values[] = "default";
3860  }
3861 
3862  $q.= ")";
3863 
3864  $users = array();
3865  $usr_set = $ilDB->queryF($q, $types, $values);
3866  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3867  {
3868  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3869  }
3870 
3871  return $users;
3872  }
3873 
3874 
3882  function _uploadPersonalPicture($tmp_file, $obj_id)
3883  {
3884  $webspace_dir = ilUtil::getWebspaceDir();
3885  $image_dir = $webspace_dir."/usr_images";
3886  $store_file = "usr_".$obj_id."."."jpg";
3887  $target_file = $image_dir."/$store_file";
3888 
3889  chmod($tmp_file, 0770);
3890 
3891  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3892  // taking only frame [0] to avoid problems with animated gifs
3893  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3894  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3895  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3896  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3897 
3898  ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
3899  ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
3900  ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
3901  ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
3902 
3903  // store filename
3904  ilObjUser::_writePref($obj_id, "profile_image", $store_file);
3905 
3906  return TRUE;
3907  }
3908 
3914  function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3915  {
3916  return ilObjUser::_getPersonalPicturePath($this->getId(),$a_size,$a_force_pic);
3917  }
3918 
3925  function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3926  $a_prevent_no_photo_image = false)
3927  {
3928  global $ilDB;
3929 
3930  // BEGIN DiskQuota: Fetch all user preferences in a single query
3931  $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3932  "keyword IN (%s,%s) ".
3933  "AND usr_id = %s",
3934  array("text", "text", "integer"),
3935  array('public_upload', 'public_profile', $a_usr_id));
3936  while ($row = $ilDB->fetchAssoc($res))
3937  {
3938  switch ($row['keyword'])
3939  {
3940  case 'public_upload' :
3941  $upload = $row['value'] == 'y';
3942  break;
3943  case 'public_profile' :
3944  $profile = ($row['value'] == 'y' ||
3945  $row['value'] == 'g');
3946  break;
3947  }
3948  }
3949 
3950  // END DiskQuota: Fetch all user preferences in a single query
3951  $webspace_dir = "";
3952  if(defined('ILIAS_MODULE'))
3953  {
3954  $webspace_dir = ('.'.$webspace_dir);
3955  }
3956  $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
3957 
3958  $image_dir = $webspace_dir."/usr_images";
3959  // BEGIN DiskQuota: Support 'big' user images
3960  if ($a_size == 'big')
3961  {
3962  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3963  }
3964  else
3965  {
3966  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3967  }
3968  // END DiskQuota: Support 'big' user images
3969 
3970  if((($upload && $profile) || $a_force_pic)
3971  && @is_file($thumb_file))
3972  {
3973  $file = $thumb_file."?t=".rand(1, 99999);
3974  }
3975  else
3976  {
3977  if (!$a_prevent_no_photo_image)
3978  {
3979  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
3980  }
3981  }
3982 
3983  return $file;
3984  }
3985 
3990  {
3991  $webspace_dir = ilUtil::getWebspaceDir();
3992  $image_dir = $webspace_dir."/usr_images";
3993  $file = $image_dir."/usr_".$this->getID()."."."jpg";
3994  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
3995  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
3996  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
3997  $upload_file = $image_dir."/upload_".$this->getID();
3998 
3999  // remove user pref file name
4000  $this->setPref("profile_image", "");
4001  $this->update();
4002 
4003  if (@is_file($file))
4004  {
4005  unlink($file);
4006  }
4007  if (@is_file($thumb_file))
4008  {
4009  unlink($thumb_file);
4010  }
4011  if (@is_file($xthumb_file))
4012  {
4013  unlink($xthumb_file);
4014  }
4015  if (@is_file($xxthumb_file))
4016  {
4017  unlink($xxthumb_file);
4018  }
4019  if (@is_file($upload_file))
4020  {
4021  unlink($upload_file);
4022  }
4023  }
4024 
4025 
4026  function setUserDefinedData($a_data)
4027  {
4028  if(!is_array($a_data))
4029  {
4030  return false;
4031  }
4032  foreach($a_data as $field => $data)
4033  {
4034  #$new_data[$field] = ilUtil::stripSlashes($data);
4035  // Assign it directly to avoid update problems of unchangable fields
4036  $this->user_defined_data['f_'.$field] = $data;
4037  }
4038  #$this->user_defined_data = $new_data;
4039 
4040  return true;
4041  }
4042 
4044  {
4045  return $this->user_defined_data ? $this->user_defined_data : array();
4046  }
4047 
4049  {
4050  global $ilDB;
4051 
4052  $fields = '';
4053 
4054  $field_def = array();
4055 
4056  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4057  $udata = new ilUserDefinedData($this->getId());
4058 
4059  foreach($this->user_defined_data as $field => $value)
4060  {
4061  if($field != 'usr_id')
4062  {
4063 // $field_def[$field] = array('text',$value);
4064  $udata->set($field, $value);
4065  }
4066  }
4067  $udata->update();
4068 
4069 /* if(!$field_def)
4070  {
4071  return true;
4072  }
4073 
4074  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4075  $res = $ilDB->query($query);
4076 
4077 
4078  if($res->numRows())
4079  {
4080  // Update
4081  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4082  }
4083  else
4084  {
4085  $field_def['usr_id'] = array('integer',$this->getId());
4086  $ilDB->insert('udf_data',$field_def);
4087  }
4088 */
4089  return true;
4090  }
4091 
4093  {
4094  global $ilDB;
4095 
4096  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4097  $udata = new ilUserDefinedData($this->getId());
4098 
4099 /* $query = "SELECT * FROM udf_data ".
4100  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4101 
4102  $res = $this->db->query($query);
4103  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
4104  {
4105  $this->user_defined_data = $row;
4106  }*/
4107 
4108  $this->user_defined_data = $udata->getAll();
4109 
4110  return true;
4111  }
4112 
4114  {
4115  global $ilDB;
4116 
4117 // not needed. no entry in udf_text/udf_clob means no value
4118 
4119 /* $query = "INSERT INTO udf_data (usr_id ) ".
4120  "VALUES( ".
4121  $ilDB->quote($this->getId(),'integer').
4122  ")";
4123  $res = $ilDB->manipulate($query);
4124 */
4125  return true;
4126  }
4127 
4129  {
4130  global $ilDB;
4131 
4132  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4134 
4135  // wrong place...
4136 /* $query = "DELETE FROM udf_data ".
4137  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4138  $res = $ilDB->manipulate($query);*/
4139 
4140  return true;
4141  }
4142 
4148  function getProfileAsString(&$a_language)
4149  {
4150  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4151  include_once 'classes/class.ilFormat.php';
4152 
4153  global $lng,$rbacreview;
4154 
4155  $language =& $a_language;
4156  $language->loadLanguageModule('registration');
4157  $language->loadLanguageModule('crs');
4158 
4159  $body = '';
4160  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4161 
4162  if(strlen($this->getUTitle()))
4163  {
4164  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4165  }
4166  if(strlen($this->getGender()))
4167  {
4168  $gender = ($this->getGender() == 'm') ?
4169  $language->txt('gender_m') :
4170  $language->txt('gender_f');
4171  $body .= ($language->txt("gender").": ".$gender."\n");
4172  }
4173  if(strlen($this->getFirstname()))
4174  {
4175  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4176  }
4177  if(strlen($this->getLastname()))
4178  {
4179  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4180  }
4181  if(strlen($this->getInstitution()))
4182  {
4183  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4184  }
4185  if(strlen($this->getDepartment()))
4186  {
4187  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4188  }
4189  if(strlen($this->getStreet()))
4190  {
4191  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4192  }
4193  if(strlen($this->getCity()))
4194  {
4195  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4196  }
4197  if(strlen($this->getZipcode()))
4198  {
4199  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4200  }
4201  if(strlen($this->getCountry()))
4202  {
4203  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4204  }
4205  if(strlen($this->getSelectedCountry()))
4206  {
4207  $body .= ($language->txt("sel_country").": ".$this->getSelectedCountry()."\n");
4208  }
4209  if(strlen($this->getPhoneOffice()))
4210  {
4211  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4212  }
4213  if(strlen($this->getPhoneHome()))
4214  {
4215  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4216  }
4217  if(strlen($this->getPhoneMobile()))
4218  {
4219  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4220  }
4221  if(strlen($this->getFax()))
4222  {
4223  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4224  }
4225  if(strlen($this->getEmail()))
4226  {
4227  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4228  }
4229  if(strlen($this->getHobby()))
4230  {
4231  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4232  }
4233  if(strlen($this->getComment()))
4234  {
4235  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4236  }
4237  if(strlen($this->getMatriculation()))
4238  {
4239  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4240  }
4241  if(strlen($this->getCreateDate()))
4242  {
4247 
4248  $body .= ($language->txt("create_date").": ".$date."\n");
4249  }
4250 
4251  foreach($rbacreview->getGlobalRoles() as $role)
4252  {
4253  if($rbacreview->isAssigned($this->getId(),$role))
4254  {
4255  $gr[] = ilObjRole::_lookupTitle($role);
4256  }
4257  }
4258  if(count($gr))
4259  {
4260  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4261  }
4262 
4263  // Time limit
4264  if($this->getTimeLimitUnlimited())
4265  {
4266  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4267  }
4268  else
4269  {
4273  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4275 
4276  $start = new ilDateTime($this->getTimeLimitFrom(),IL_CAL_UNIX);
4277  $end = new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX);
4278 
4279  $body .= $language->txt('time_limit').': '.$start->get(IL_CAL_DATETIME);
4280  $body .= $language->txt('time_limit').': '.$end->get(IL_CAL_DATETIME);
4281 
4282 
4283  #$body .= $language->txt('time_limit').': '.$period;
4284  /*
4285  $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4286  ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4287  $language->txt('crs_to')." ".
4288  ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4289  */
4290  }
4291  return $body;
4292  }
4293 
4294  function setInstantMessengerId($a_im_type, $a_im_id)
4295  {
4296  $var = "im_".$a_im_type;
4297  $this->$var = $a_im_id;
4298  }
4299 
4300  function getInstantMessengerId($a_im_type)
4301  {
4302  $var = "im_".$a_im_type;
4303  return $this->$var;
4304  }
4305 
4306  function setDelicious($a_delicious)
4307  {
4308  $this->delicious = $a_delicious;
4309  }
4310 
4311  function getDelicious()
4312  {
4313  return $this->delicious;
4314  }
4315 
4319  function _lookupFeedHash($a_user_id, $a_create = false)
4320  {
4321  global $ilDB;
4322 
4323  if ($a_user_id > 0)
4324  {
4325  $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4326  array("integer"), array($a_user_id));
4327  if ($rec = $ilDB->fetchAssoc($set))
4328  {
4329  if (strlen($rec["feed_hash"]) == 32)
4330  {
4331  return $rec["feed_hash"];
4332  }
4333  else if($a_create)
4334  {
4335  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4336  $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4337  " WHERE usr_id = %s",
4338  array("text", "integer"),
4339  array($hash, $a_user_id));
4340  return $hash;
4341  }
4342  }
4343  }
4344 
4345  return false;
4346  }
4347 
4353  function _getFeedPass($a_user_id)
4354  {
4355  global $ilDB;
4356 
4357  if ($a_user_id > 0)
4358  {
4359  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4360  }
4361  return false;
4362  }
4363 
4369  function _setFeedPass($a_user_id, $a_password)
4370  {
4371  global $ilDB;
4372 
4373  ilObjUser::_writePref($a_user_id, "priv_feed_pass",
4374  ($a_password=="") ? "" : md5($a_password));
4375  }
4376 
4386  public static function _loginExists($a_login,$a_user_id = 0)
4387  {
4388  global $ilDB;
4389 
4390  $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4391  "WHERE login = %s";
4392  $types[] = "text";
4393  $values[] = $a_login;
4394 
4395  if ($a_user_id != 0)
4396  {
4397  $q.= " AND usr_id != %s ";
4398  $types[] = "integer";
4399  $values[] = $a_user_id;
4400  }
4401 
4402  $r = $ilDB->queryF($q, $types, $values);
4403 
4404  if ($row = $ilDB->fetchAssoc($r))
4405  {
4406  return $row['usr_id'];
4407  }
4408  return false;
4409  }
4410 
4421  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4422  {
4423  global $ilDB;
4424 
4425  $res = $ilDB->queryF("SELECT * FROM usr_data ".
4426  "WHERE ext_account = %s AND auth_mode = %s",
4427  array("text", "text"),
4428  array($a_external_account, $a_auth_mode));
4429  return $ilDB->fetchAssoc($res) ? true :false;
4430  }
4431 
4439  public static function _getUsersForRole($role_id, $active = -1) {
4440  global $ilDB, $rbacreview;
4441  $data = array();
4442 
4443  $ids = $rbacreview->assignedUsers($role_id);
4444 
4445  if (count ($ids) == 0)
4446  {
4447  $ids = array (-1);
4448  }
4449 
4450  $query = "SELECT usr_data.*, usr_pref.value AS language
4451  FROM usr_data
4452  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4453  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4454  $values[] = "language";
4455  $types[] = "text";
4456 
4457 
4458  if (is_numeric($active) && $active > -1)
4459  {
4460  $query .= " AND usr_data.active = %s";
4461  $values[] = $active;
4462  $types[] = "integer";
4463  }
4464 
4465  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4466 
4467  $r = $ilDB->queryF($query, $types, $values);
4468  $data = array();
4469  while ($row = $ilDB->fetchAssoc($r))
4470  {
4471  $data[] = $row;
4472  }
4473  return $data;
4474  }
4475 
4476 
4482  public static function _getUsersForFolder ($ref_id, $active) {
4483  global $ilDB;
4484  $data = array();
4485  $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 ";
4486  $types[] = "text";
4487  $values[] = "language";
4488 
4489  if (is_numeric($active) && $active > -1)
4490  {
4491  $query .= " AND usr_data.active = %s";
4492  $values[] = $active;
4493  $types[] = "integer";
4494  }
4495 
4496  if ($ref_id != USER_FOLDER_ID)
4497  {
4498  $query.= " AND usr_data.time_limit_owner = %s";
4499  $values[] = $ref_id;
4500  $types[] = "integer";
4501  }
4502 
4503  $query .= " AND usr_data.usr_id != %s ";
4504  $values[] = ANONYMOUS_USER_ID;
4505  $types[] = "integer";
4506 
4507  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4508 
4509  $result = $ilDB->queryF($query, $types, $values);
4510  $data = array();
4511  while ($row = $ilDB->fetchAssoc($result))
4512  {
4513  array_push($data, $row);
4514  }
4515 
4516  return $data;
4517  }
4518 
4519 
4525  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4526  {
4527  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4528  }
4529 
4530 
4536  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4537  {
4538  global $rbacadmin, $rbacreview, $ilDB;
4539 
4540  // quote all ids
4541  $ids = array();
4542  foreach ($a_mem_ids as $mem_id) {
4543  $ids [] = $ilDB->quote($mem_id);
4544  }
4545 
4546  $query = "SELECT usr_data.*, usr_pref.value AS language
4547  FROM usr_data
4548  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4549  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer")."
4550  AND usr_data.usr_id != %s";
4551  $values[] = "language";
4552  $types[] = "text";
4553  $values[] = ANONYMOUS_USER_ID;
4554  $types[] = "integer";
4555 
4556  if (is_numeric($active) && $active > -1)
4557  {
4558  $query .= " AND active = %s";
4559  $values[] = $active;
4560  $types[] = "integer";
4561  }
4562 
4563  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4564  {
4565  $query.= " AND usr_data.time_limit_owner = %s";
4566  $values[] = $timelimitowner;
4567  $types[] = "integer";
4568 
4569  }
4570 
4571  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4572 
4573  $result = $ilDB->queryF($query, $types, $values);
4574  while ($row = $ilDB->fetchAssoc($result))
4575  {
4576  $mem_arr[] = $row;
4577  }
4578 
4579  return $mem_arr ? $mem_arr : array();
4580  }
4581 
4582 
4583 
4589  public static function _getUserData ($a_internalids) {
4590  global $ilDB;
4591 
4592  $ids = array();
4593  if (is_array($a_internalids)) {
4594  foreach ($a_internalids as $internalid) {
4595  if (is_numeric ($internalid))
4596  {
4597  $ids[] = $internalid;
4598  }
4599  else
4600  {
4601  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4602  if (is_numeric($parsedid) && $parsedid > 0)
4603  {
4604  $ids[] = $parsedid;
4605  }
4606  }
4607  }
4608  }
4609  if (count($ids) == 0)
4610  $ids [] = -1;
4611 
4612  $query = "SELECT usr_data.*, usr_pref.value AS language
4613  FROM usr_data
4614  LEFT JOIN usr_pref
4615  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4616  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4617  $values[] = "language";
4618  $types[] = "text";
4619 
4620  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4621 
4622  $data = array();
4623  $result = $ilDB->queryF($query, $types, $values);
4624  while ($row = $ilDB->fetchAssoc($result))
4625  {
4626  $data[] = $row;
4627  }
4628  return $data;
4629  }
4630 
4637  public static function _getPreferences ($user_id)
4638  {
4639  global $ilDB;
4640 
4641  $prefs = array();
4642 
4643  $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4644  array("integer"), array($user_id));
4645 
4646  while($row = $ilDB->fetchAssoc($r))
4647  {
4648  $prefs[$row["keyword"]] = $row["value"];
4649  }
4650 
4651  return $prefs;
4652  }
4653 
4654 
4655  public static function _resetLoginAttempts($a_usr_id)
4656  {
4657  global $ilDB;
4658 
4659  $query = "UPDATE usr_data SET usr_data.login_attempts = 0 WHERE usr_data.usr_id = %s";
4660  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4661 
4662  if($affected) return true;
4663  else return false;
4664  }
4665 
4666  public static function _getLoginAttempts($a_usr_id)
4667  {
4668  global $ilDB;
4669 
4670  $query = "SELECT usr_data.login_attempts FROM usr_data WHERE usr_data.usr_id = %s";
4671  $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4672  $record = $ilDB->fetchAssoc( $result );
4673  $login_attempts = $record['login_attempts'];
4674 
4675  return $login_attempts;
4676  }
4677 
4678  public static function _incrementLoginAttempts($a_usr_id)
4679  {
4680  global $ilDB;
4681 
4682  $query = "UPDATE usr_data SET usr_data.login_attempts = (usr_data.login_attempts + 1) WHERE usr_data.usr_id = %s";
4683  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4684 
4685  if($affected) return true;
4686  else return false;
4687  }
4688 
4689  public static function _setUserInactive($a_usr_id)
4690  {
4691  global $ilDB;
4692 
4693  $query = "UPDATE usr_data SET usr_data.active = 0 WHERE usr_data.usr_id = %s";
4694  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4695 
4696  if($affected) return true;
4697  else return false;
4698  }
4699 
4705  public function hasPublicProfile() {
4706  return in_array($this->getPref("public_profile"), array("y", "g"));
4707  }
4708 
4714  public function getPublicName()
4715  {
4716  if ($this->hasPublicProfile())
4717  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4718  else
4719  return $this->getLogin();
4720 
4721  }
4722 
4723  public static function _writeHistory($a_usr_id, $a_login)
4724  {
4725  global $ilDB;
4726 
4727  $timestamp = time();
4728 
4729  $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4730  array('integer', 'text', 'integer'),
4731  array($a_usr_id, $a_login, $timestamp));
4732 
4733  if( $ilDB->numRows($res) == 0 )
4734  {
4735  $ilDB->manipulateF('
4736  INSERT INTO loginname_history
4737  (usr_id, login, history_date)
4738  VALUES (%s, %s, %s)',
4739  array('integer', 'text', 'integer'),
4740  array($a_usr_id, $a_login, $timestamp));
4741  }
4742 
4743  return true;
4744  }
4745 
4753  function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4754  {
4755  global $ilDB;
4756 
4757  $pd_set = new ilSetting("pd");
4758  $atime = $pd_set->get("user_activity_time") * 60;
4759  $ctime = time();
4760 
4761  if ($a_user_id == 0)
4762  {
4763  $where = "WHERE user_id != 0 AND NOT agree_date IS NULL ";
4764  $type_array = array("integer");
4765  $val_array = array(time());
4766  }
4767  else
4768  {
4769  $where = "WHERE user_id = %s ";
4770  $type_array = array("integer", "integer");
4771  $val_array = array($a_user_id, time());
4772  }
4773 
4774  $no_anonym = ($a_no_anonymous)
4775  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4776  : "";
4777 
4778  include_once './Services/User/classes/class.ilUserAccountSettings.php';
4779  if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
4780  {
4781  include_once './Services/User/classes/class.ilUserFilter.php';
4782  $user_filter = 'AND '.$ilDB->in('time_limit_owner',ilUserFilter::getInstance()->getFolderIds(),false,'integer').' ';
4783  }
4784  else
4785  {
4786  $user_filter = ' ';
4787  }
4788  $r = $ilDB->queryF($q = "SELECT count(user_id) as num,user_id,firstname,lastname,title,login,last_login,max(ctime) AS ctime ".
4789  "FROM usr_session ".
4790  "LEFT JOIN usr_data u ON user_id = u.usr_id ".
4791  "LEFT JOIN usr_pref p ON (p.usr_id = u.usr_id AND p.keyword = ".
4792  $ilDB->quote("hide_own_online_status", "text").") ".$where.
4793  "AND expires > %s ".
4794  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4795  $no_anonym.
4796  $user_filter.
4797  "GROUP BY user_id,firstname,lastname,title,login,last_login ".
4798  "ORDER BY lastname, firstname", $type_array, $val_array);
4799 
4800  while ($user = $ilDB->fetchAssoc($r))
4801  {
4802  if ($atime <= 0
4803  || $user["ctime"] + $atime > $ctime)
4804  {
4805  $users[$user["user_id"]] = $user;
4806  }
4807  }
4808 
4809  return $users ? $users : array();
4810  }
4811 
4820  function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4821  {
4822  global $ilias, $ilDB;
4823 
4824  $pd_set = new ilSetting("pd");
4825  $atime = $pd_set->get("user_activity_time") * 60;
4826  $ctime = time();
4827  $no_anonym = ($a_no_anonymous)
4828  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4829  : "";
4830 
4831  // Get a list of object id's of all courses and groups for which
4832  // the current user has local roles.
4833  // Note: we have to use DISTINCT here, because a user may assume
4834  // multiple roles in a group or a course.
4835  $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4836  "FROM rbac_ua ua ".
4837  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4838  "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4839  "JOIN tree ON tree.child = r1.ref_id ".
4840  "JOIN object_reference r2 ON r2.ref_id = tree.parent ".
4841  "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4842  "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4843  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4844  "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4845  $ilDB->quote("grp", "text").")";
4846  $r = $ilDB->query($q);
4847 
4848  while ($row = $ilDB->fetchAssoc($r))
4849  {
4850  $groups_and_courses_of_user[] = $row["obj_id"];
4851  }
4852  // If the user is not in a course or a group, he has no associated users.
4853  if (count($groups_and_courses_of_user) == 0)
4854  {
4855  $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4856  "FROM usr_session ".
4857  "JOIN usr_data ON user_id=usr_id ".
4858  "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4859  $no_anonym.
4860  " AND NOT agree_date IS NULL ".
4861  "AND expires > ".$ilDB->quote(time(), "integer")." ".
4862  "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4863  $r = $ilDB->query($q);
4864  }
4865  else
4866  {
4867  $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4868  "FROM usr_session s ".
4869  "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4870  "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
4871  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4872  "JOIN tree ON tree.child = fa.parent ".
4873  "JOIN object_reference or1 ON or1.ref_id = tree.parent ".
4874  "JOIN object_data od ON od.obj_id = or1.obj_id ".
4875  "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
4876  $ilDB->quote("hide_own_online_status", "text").") ".
4877  "WHERE s.user_id != 0 ".
4878  $no_anonym.
4879  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4880  "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
4881  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4882  " AND NOT ud.agree_date IS NULL ".
4883  "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
4884  "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4885  "ORDER BY ud.lastname, ud.firstname";
4886  $r = $ilDB->query($q);
4887  }
4888 
4889  while ($user = $ilDB->fetchAssoc($r))
4890  {
4891  if ($atime <= 0
4892  || $user["ctime"] + $atime > $ctime)
4893  {
4894  $users[$user["user_id"]] = $user;
4895  }
4896  }
4897 
4898  return $users ? $users : array();
4899  }
4900 
4907  public static function _generateRegistrationHash($a_usr_id)
4908  {
4909  global $ilDB;
4910 
4911  do
4912  {
4913  $continue = false;
4914 
4915  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
4916 
4917  $res = $ilDB->queryf('
4918  SELECT COUNT(usr_id) cnt FROM usr_data
4919  WHERE reg_hash = %s',
4920  array('text'),
4921  array($hashcode));
4922  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
4923  {
4924  if($row->cnt > 0) $continue = true;
4925  break;
4926  }
4927 
4928  if($continue) continue;
4929 
4930  $ilDB->manipulateF('
4931  UPDATE usr_data
4932  SET reg_hash = %s
4933  WHERE usr_id = %s',
4934  array('text', 'integer'),
4935  array($hashcode, (int)$a_usr_id)
4936  );
4937 
4938  break;
4939 
4940  } while(true);
4941 
4942  return $hashcode;
4943  }
4944 
4953  public static function _verifyRegistrationHash($a_hash)
4954  {
4955  global $ilDB;
4956 
4957  $res = $ilDB->queryf('
4958  SELECT usr_id, create_date FROM usr_data
4959  WHERE reg_hash = %s',
4960  array('text'),
4961  array($a_hash));
4962  while($row = $ilDB->fetchAssoc($res))
4963  {
4964  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
4965  $oRegSettigs = new ilRegistrationSettings();
4966 
4967  if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
4968  time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
4969  {
4970  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
4971  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
4972  }
4973 
4974  $ilDB->manipulateF('
4975  UPDATE usr_data
4976  SET reg_hash = %s
4977  WHERE usr_id = %s',
4978  array('text', 'integer'),
4979  array('', (int)$row['usr_id'])
4980  );
4981 
4982  return (int)$row['usr_id'];
4983  }
4984 
4985  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
4986  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
4987  }
4988 
4989  function setBirthday($a_birthday)
4990  {
4991  if (strlen($a_birthday))
4992  {
4993  $date = new ilDate($a_birthday, IL_CAL_DATE);
4994  $this->birthday = $date->get(IL_CAL_DATE);
4995  }
4996  else
4997  {
4998  $this->birthday = null;
4999  }
5000  }
5001 
5002  function getBirthday()
5003  {
5004  return $this->birthday;
5005  }
5006 
5015  public static function _getUserIdsByInactivityPeriod($period)
5016  {
5017  if( !(int)$period ) throw new ilException('no valid period given');
5018 
5019  global $ilDB;
5020 
5021  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5022 
5023  $query = "SELECT usr_id FROM usr_data WHERE last_login < %s";
5024 
5025  $res = $ilDB->queryF($query, array('timestamp'), array($date));
5026 
5027  $ids = array();
5028  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5029  {
5030  $ids[] = $row->usr_id;
5031  }
5032 
5033  return $ids;
5034  }
5035 
5045  public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5046  {
5047  if($a_last_login !== null) $last_login = $a_last_login;
5048  else $last_login = date('Y-m-d H:i:s');
5049 
5050  global $ilDB;
5051 
5052  $query = "UPDATE usr_data SET usr_data.last_login = %s WHERE usr_data.usr_id = %s";
5053  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array($last_login, $a_usr_id) );
5054 
5055  if($affected) return $last_login;
5056  else return false;
5057  }
5058 
5059  public function resetOwner()
5060  {
5061  global $ilDB;
5062 
5063  $query = "UPDATE object_data SET owner = 0 ".
5064  "WHERE owner = ".$ilDB->quote($this->getId(),'integer');
5065  $ilDB->query($query);
5066 
5067  return true;
5068  }
5069 
5070 
5077  static function getFirstLettersOfLastnames()
5078  {
5079  global $ilDB;
5080 
5081  $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("lastname", 1, 1))." let FROM usr_data ORDER BY let";
5082  $let_set = $ilDB->query($q);
5083 
5084  $lets = array();
5085  while ($let_rec = $ilDB->fetchAssoc($let_set))
5086  {
5087  $let[$let_rec["let"]] = $let_rec["let"];
5088  }
5089  return $let;
5090  }
5091 
5092 
5093 } // END class ilObjUser
5094 ?>