ILIAS  Release_4_0_x_branch Revision 61816
 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;
69  var $fax;
70  var $email;
71  var $hobby;
74  var $approve_date = null;
75  var $agree_date = null;
76  var $active;
77  //var $ilinc_id; // unique Id for netucate ilinc service
78  var $client_ip; // client ip to check before login
79  var $auth_mode; // authentication mode
80 
81  var $im_icq;
82  var $im_yahoo;
83  var $im_msn;
84  var $im_aim;
85  var $im_skype;
87  var $im_voip;
88 
90  var $latitude;
92  var $loc_zoom;
93 
96 
97  var $user_defined_data = array();
98 
104  var $prefs;
105 
111  var $skin;
112 
113 
120 
126  var $ilias;
127 
128 
134  function ilObjUser($a_user_id = 0, $a_call_by_reference = false)
135  {
136  global $ilias,$ilDB;
137 
138  // init variables
139  $this->ilias =& $ilias;
140  $this->db =& $ilDB;
141 
142  $this->type = "usr";
143  $this->ilObject($a_user_id, $a_call_by_reference);
144  $this->auth_mode = "default";
145  $this->passwd_type = IL_PASSWD_PLAIN;
146 
147  // for gender selection. don't change this
148  /*$this->gender = array(
149  'm' => "salutation_m",
150  'f' => "salutation_f"
151  );*/
152  if ($a_user_id > 0)
153  {
154  $this->setId($a_user_id);
155  $this->read();
156  }
157  else
158  {
159  // TODO: all code in else-structure doesn't belongs in class user !!!
160  //load default data
161  $this->prefs = array();
162  //language
163  $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
164 
165  //skin and pda support
166  $this->skin = $this->ilias->ini->readVariable("layout","skin");
167 
168  $this->prefs["skin"] = $this->skin;
169  $this->prefs["show_users_online"] = "y";
170 
171  //style (css)
172  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
173  }
174  }
175 
180  function read()
181  {
182  global $ilErr, $ilDB;
183 
184  // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
185  // use (3.11.0 alpha)
186  /*$q = "SELECT * FROM usr_data ".
187  "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
188  "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
189  $r = $ilDB->queryF("SELECT * FROM usr_data ".
190  "WHERE usr_id= %s", array("integer"), array($this->id));
191 
192  if ($data = $ilDB->fetchAssoc($r))
193  {
194  // convert password storage layout used by table usr_data into
195  // storage layout used by class ilObjUser
196  if ($data["passwd"] == "" && $data["i2passwd"] != "")
197  {
198  $data["passwd_type"] = IL_PASSWD_CRYPT;
199  $data["passwd"] = $data["i2passwd"];
200  }
201  else
202  {
203  $data["passwd_type"] = IL_PASSWD_MD5;
204  //$data["passwd"] = $data["passwd"]; (implicit)
205  }
206  unset($data["i2passw"]);
207 
208  // this assign must not be set via $this->assignData($data)
209  // because this method will be called on profile updates and
210  // would set this values to 0, because they arent posted from form
211  $this->setLastPasswordChangeTS( $data['last_password_change'] );
212  $this->setLoginAttempts( $data['login_attempts'] );
213 
214 
215  // fill member vars in one shot
216  $this->assignData($data);
217 
218  //get userpreferences from usr_pref table
219  $this->readPrefs();
220 
221  //set language to default if not set
222  if ($this->prefs["language"] == "")
223  {
224  $this->prefs["language"] = $this->oldPrefs["language"];
225  }
226 
227  //check skin-setting
228  include_once("./Services/Style/classes/class.ilStyleDefinition.php");
229  if ($this->prefs["skin"] == "" ||
230  !ilStyleDefinition::skinExists($this->prefs["skin"]))
231  {
232  $this->prefs["skin"] = $this->oldPrefs["skin"];
233  }
234 
235  $this->skin = $this->prefs["skin"];
236 
237  //check style-setting (skins could have more than one stylesheet
238  if ($this->prefs["style"] == "" ||
239  !ilStyleDefinition::skinExists($this->skin, $this->prefs["style"]))
240  {
241  //load default (css)
242  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
243  }
244 
245  if (empty($this->prefs["hits_per_page"]))
246  {
247  $this->prefs["hits_per_page"] = 10;
248  }
249 
250  }
251  else
252  {
253  $ilErr->raiseError("<b>Error: There is no dataset with id ".
254  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
255  "<br />Line: ".__LINE__, $ilErr->FATAL);
256  }
257 
258  $this->readUserDefinedFields();
259 
260  parent::read();
261  }
262 
268  function assignData($a_data)
269  {
270  global $ilErr, $ilDB, $lng;
271 
272  // basic personal data
273  $this->setLogin($a_data["login"]);
274  if (! $a_data["passwd_type"])
275  {
276  $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
277  $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
278  .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
279  }
280  if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
281  {
282  $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
283  }
284 
285  $this->setGender($a_data["gender"]);
286  $this->setUTitle($a_data["title"]);
287  $this->setFirstname($a_data["firstname"]);
288  $this->setLastname($a_data["lastname"]);
289  $this->setFullname();
290  if (!is_array($a_data['birthday']))
291  {
292  $this->setBirthday($a_data['birthday']);
293  }
294  else
295  {
296  $this->setBirthday(null);
297  }
298 
299  // address data
300  $this->setInstitution($a_data["institution"]);
301  $this->setDepartment($a_data["department"]);
302  $this->setStreet($a_data["street"]);
303  $this->setCity($a_data["city"]);
304  $this->setZipcode($a_data["zipcode"]);
305  $this->setCountry($a_data["country"]);
306  $this->setPhoneOffice($a_data["phone_office"]);
307  $this->setPhoneHome($a_data["phone_home"]);
308  $this->setPhoneMobile($a_data["phone_mobile"]);
309  $this->setFax($a_data["fax"]);
310  $this->setMatriculation($a_data["matriculation"]);
311  $this->setEmail($a_data["email"]);
312  $this->setHobby($a_data["hobby"]);
313  $this->setClientIP($a_data["client_ip"]);
314 
315  // instant messenger data
316  $this->setInstantMessengerId('icq',$a_data["im_icq"]);
317  $this->setInstantMessengerId('yahoo',$a_data["im_yahoo"]);
318  $this->setInstantMessengerId('msn',$a_data["im_msn"]);
319  $this->setInstantMessengerId('aim',$a_data["im_aim"]);
320  $this->setInstantMessengerId('skype',$a_data["im_skype"]);
321  $this->setInstantMessengerId('jabber',$a_data["im_jabber"]);
322  $this->setInstantMessengerId('voip',$a_data["im_voip"]);
323 
324  // other data
325  $this->setDelicious($a_data["delicious"]);
326  $this->setLatitude($a_data["latitude"]);
327  $this->setLongitude($a_data["longitude"]);
328  $this->setLocationZoom($a_data["loc_zoom"]);
329 
330  // system data
331  $this->setLastLogin($a_data["last_login"]);
332  $this->setLastUpdate($a_data["last_update"]);
333  $this->create_date = $a_data["create_date"];
334  $this->setComment($a_data["referral_comment"]);
335  $this->approve_date = $a_data["approve_date"];
336  $this->active = $a_data["active"];
337  $this->agree_date = $a_data["agree_date"];
338 
339  // time limitation
340  $this->setTimeLimitOwner($a_data["time_limit_owner"]);
341  $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
342  $this->setTimeLimitFrom($a_data["time_limit_from"]);
343  $this->setTimeLimitUntil($a_data["time_limit_until"]);
344  $this->setTimeLimitMessage($a_data['time_limit_message']);
345 
346  // user profile incomplete?
347  $this->setProfileIncomplete($a_data["profile_incomplete"]);
348 
349  //iLinc
350  //$this->setiLincData($a_data['ilinc_id'],$a_data['ilinc_login'],$a_data['ilinc_passwd']);
351 
352  //authentication
353  $this->setAuthMode($a_data['auth_mode']);
354  $this->setExternalAccount($a_data['ext_account']);
355  }
356 
363  function saveAsNew($a_from_formular = true)
364  {
365  global $ilErr, $ilDB, $ilSetting, $ilUser;
366 
367  switch ($this->passwd_type)
368  {
369  case IL_PASSWD_PLAIN:
370  $pw_field = "passwd";
371  if(strlen($this->passwd))
372  {
373  $pw_value = md5($this->passwd);
374  }
375  else
376  {
377  $pw_value = $this->passwd;
378  }
379  break;
380 
381  case IL_PASSWD_MD5:
382  $pw_field = "passwd";
383  $pw_value = $this->passwd;
384  break;
385 
386  case IL_PASSWD_CRYPT:
387  $pw_field = "i2passwd";
388  $pw_value = $this->passwd;
389  break;
390 
391  default :
392  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
393  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
394  "<br />Line: ".__LINE__, $ilErr->FATAL);
395  }
396 
397  $insert_array = array(
398  "usr_id" => array("integer", $this->id),
399  "login" => array("text", $this->login),
400  $pw_field => array("text", $pw_value),
401  "firstname" => array("text", $this->firstname),
402  "lastname" => array("text", $this->lastname),
403  "title" => array("text", $this->utitle),
404  "gender" => array("text", $this->gender),
405  "email" => array("text", $this->email),
406  "hobby" => array("text", (string) $this->hobby),
407  "institution" => array("text", $this->institution),
408  "department" => array("text", $this->department),
409  "street" => array("text", $this->street),
410  "city" => array("text", $this->city),
411  "zipcode" => array("text", $this->zipcode),
412  "country" => array("text", $this->country),
413  "phone_office" => array("text", $this->phone_office),
414  "phone_home" => array("text", $this->phone_home),
415  "phone_mobile" => array("text", $this->phone_mobile),
416  "fax" => array("text", $this->fax),
417  "birthday" => array('date', $this->getBirthday()),
418  "last_login" => array("timestamp", null),
419  "last_update" => array("timestamp", ilUtil::now()),
420  "create_date" => array("timestamp", ilUtil::now()),
421  "referral_comment" => array("text", $this->referral_comment),
422  "matriculation" => array("text", $this->matriculation),
423  "client_ip" => array("text", $this->client_ip),
424  "approve_date" => array("timestamp", $this->approve_date),
425  "agree_date" => array("timestamp", $this->agree_date),
426  "active" => array("integer", (int) $this->active),
427  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
428  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
429  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
430  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
431  "auth_mode" => array("text", $this->getAuthMode()),
432  "ext_account" => array("text", $this->getExternalAccount()),
433  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
434  "im_icq" => array("text", $this->im_icq),
435  "im_yahoo" => array("text", $this->im_yahoo),
436  "im_msn" => array("text", $this->im_msn),
437  "im_aim" => array("text", $this->im_aim),
438  "im_skype" => array("text", $this->im_skype),
439  "delicious" => array("text", $this->delicious),
440  "latitude" => array("text", $this->latitude),
441  "longitude" => array("text", $this->longitude),
442  "loc_zoom" => array("integer", (int) $this->loc_zoom),
443  "last_password_change" => array("integer", (int) $this->last_password_change_ts),
444  "im_jabber" => array("text", $this->im_jabber),
445  "im_voip" => array("text", $this->im_voip)
446  );
447  $ilDB->insert("usr_data", $insert_array);
448 
449  // add new entry in usr_defined_data
450  $this->addUserDefinedFieldEntry();
451  // ... and update
452  $this->updateUserDefinedFields();
453 
454  // CREATE ENTRIES FOR MAIL BOX
455  include_once ("Services/Mail/classes/class.ilMailbox.php");
456  $mbox = new ilMailbox($this->id);
457  $mbox->createDefaultFolder();
458 
459  include_once "Services/Mail/classes/class.ilMailOptions.php";
460  $mail_options = new ilMailOptions($this->id);
461  $mail_options->createMailOptionsEntry();
462 
463  // create personal bookmark folder tree
464  include_once "./Services/PersonalDesktop/classes/class.ilBookmarkFolder.php";
465  $bmf = new ilBookmarkFolder(0, $this->id);
466  $bmf->createNewBookmarkTree();
467 
468  }
469 
474  function update()
475  {
476  global $ilErr, $ilDB, $ilAppEventHandler;
477 
478  $this->syncActive();
479 
480  $update_array = array(
481  "gender" => array("text", $this->gender),
482  "title" => array("text", $this->utitle),
483  "firstname" => array("text", $this->firstname),
484  "lastname" => array("text", $this->lastname),
485  "email" => array("text", $this->email),
486  "birthday" => array('date', $this->getBirthday()),
487  "hobby" => array("text", $this->hobby),
488  "institution" => array("text", $this->institution),
489  "department" => array("text", $this->department),
490  "street" => array("text", $this->street),
491  "city" => array("text", $this->city),
492  "zipcode" => array("text", $this->zipcode),
493  "country" => array("text", $this->country),
494  "phone_office" => array("text", $this->phone_office),
495  "phone_home" => array("text", $this->phone_home),
496  "phone_mobile" => array("text", $this->phone_mobile),
497  "fax" => array("text", $this->fax),
498  "referral_comment" => array("text", $this->referral_comment),
499  "matriculation" => array("text", $this->matriculation),
500  "client_ip" => array("text", $this->client_ip),
501  "approve_date" => array("timestamp", $this->approve_date),
502  "active" => array("integer", $this->active),
503  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
504  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
505  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
506  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
507  "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
508  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
509  "auth_mode" => array("text", $this->getAuthMode()),
510  "ext_account" => array("text", $this->getExternalAccount()),
511  "im_icq" => array("text", $this->im_icq),
512  "im_yahoo" => array("text", $this->im_yahoo),
513  "im_msn" => array("text", $this->im_msn),
514  "im_aim" => array("text", $this->im_aim),
515  "im_skype" => array("text", $this->im_skype),
516  "delicious" => array("text", $this->delicious),
517  "latitude" => array("text", $this->latitude),
518  "longitude" => array("text", $this->longitude),
519  "loc_zoom" => array("integer", (int) $this->loc_zoom),
520  "last_password_change" => array("integer", $this->last_password_change_ts),
521  "im_jabber" => array("text", $this->im_jabber),
522  "im_voip" => array("text", $this->im_voip),
523  "last_update" => array("timestamp", ilUtil::now())
524  );
525 
526  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null))
527  {
528  $update_array["agree_date"] = array("timestamp", $this->agree_date);
529  }
530  switch ($this->passwd_type)
531  {
532  case IL_PASSWD_PLAIN:
533  if(strlen($this->passwd))
534  {
535  $update_array["i2passwd"] = array("text", (string) "");
536  $update_array["passwd"] = array("text", (string) md5($this->passwd));
537  }
538  else
539  {
540  $update_array["i2passwd"] = array("text", (string) "");
541  $update_array["passwd"] = array("text", (string) $this->passwd);
542  }
543  break;
544 
545  case IL_PASSWD_MD5:
546  $update_array["i2passwd"] = array("text", (string) "");
547  $update_array["passwd"] = array("text", (string) $this->passwd);
548  break;
549 
550  case IL_PASSWD_CRYPT:
551  $update_array["i2passwd"] = array("text", (string) $this->passwd);
552  $update_array["passwd"] = array("text", (string) "");
553  break;
554 
555  default :
556  $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
557  get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
558  }
559 
560  $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
561 
562  $this->writePrefs();
563 
564  // update user defined fields
565  $this->updateUserDefinedFields();
566 
567  parent::update();
569 
570  $this->read();
571 
572  $ilAppEventHandler->raise("Services/User", "afterUpdate",
573  array("user_obj" => $this));
574 
575  return true;
576  }
577 
581  function writeAccepted()
582  {
583  global $ilDB;
584 
585  $ilDB->manipulateF("UPDATE usr_data SET agree_date = ".$ilDB->now().
586  " WHERE usr_id = %s", array("integer"), array($this->getId()));
587  }
588 
592  private function _lookup($a_user_id, $a_field)
593  {
594  global $ilDB;
595 
596  $res = $ilDB->queryF("SELECT ".$a_field." FROM usr_data WHERE usr_id = %s",
597  array("integer"), array($a_user_id));
598 
599  while($set = $ilDB->fetchAssoc($res))
600  {
601  return $set[$a_field];
602  }
603  return false;
604  }
605 
609  function _lookupFullname($a_user_id)
610  {
611  global $ilDB;
612 
613  $set = $ilDB->queryF("SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
614  array("integer"), array($a_user_id));
615 
616  if ($rec = $ilDB->fetchAssoc($set))
617  {
618  if ($rec["title"])
619  {
620  $fullname = $rec["title"]." ";
621  }
622  if ($rec["firstname"])
623  {
624  $fullname .= $rec["firstname"]." ";
625  }
626  if ($rec["lastname"])
627  {
628  $fullname .= $rec["lastname"];
629  }
630  }
631  return $fullname;
632  }
633 
637  function _lookupIm($a_user_id, $a_type)
638  {
639  return ilObjUser::_lookup($a_user_id, "im_".$a_type);
640  }
641 
642 
646  function _lookupEmail($a_user_id)
647  {
648  return ilObjUser::_lookup($a_user_id, "email");
649  }
650 
654  public static function _lookupGender($a_user_id)
655  {
656  return ilObjUser::_lookup($a_user_id, "gender");
657  }
658 
665  function _lookupClientIP($a_user_id)
666  {
667  return ilObjUser::_lookup($a_user_id, "client_ip");
668  }
669 
670 
674  public static function _lookupName($a_user_id)
675  {
676  global $ilDB;
677 
678  $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
679  array("integer"), array($a_user_id));
680  $user_rec = $ilDB->fetchAssoc($res);
681  return array("user_id" => $a_user_id,
682  "firstname" => $user_rec["firstname"],
683  "lastname" => $user_rec["lastname"],
684  "title" => $user_rec["title"],
685  "login" => $user_rec["login"]);
686  }
687 
691  function _lookupFields($a_user_id)
692  {
693  global $ilDB;
694 
695  $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
696  array("integer"), array($a_user_id));
697  $user_rec = $ilDB->fetchAssoc($res);
698  return $user_rec;
699  }
700 
704  function _lookupLogin($a_user_id)
705  {
706  return ilObjUser::_lookup($a_user_id, "login");
707  }
708 
712  function _lookupExternalAccount($a_user_id)
713  {
714  return ilObjUser::_lookup($a_user_id, "ext_account");
715  }
716 
720  public static function _lookupId($a_user_str)
721  {
722  global $ilDB;
723 
724  $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
725  array("text"), array($a_user_str));
726  $user_rec = $ilDB->fetchAssoc($res);
727  return $user_rec["usr_id"];
728  }
729 
733  function _lookupLastLogin($a_user_id)
734  {
735  return ilObjUser::_lookup($a_user_id, "last_login");
736  }
737 
738 
744  function refreshLogin()
745  {
746  global $ilDB;
747 
748  $ilDB->manipulateF("UPDATE usr_data SET ".
749  "last_login = ".$ilDB->now().
750  " WHERE usr_id = %s",
751  array("integer"), array($this->id));
752  }
753 
760  function replacePassword($new_md5)
761  {
762  global $ilDB;
763 
764  $this->passwd_type = IL_PASSWD_MD5;
765  $this->passwd = $new_md5;
766 
767  $ilDB->manipulateF("UPDATE usr_data SET ".
768  "passwd = %s ".
769  "WHERE usr_id = %s",
770  array("text", "integer"), array($this->passwd, $this->id));
771 
772  return true;
773  }
774 
783  function updatePassword($a_old, $a_new1, $a_new2)
784  {
785  global $ilDB;
786 
787  if (func_num_args() != 3)
788  {
789  return false;
790  }
791 
792  if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
793  {
794  return false;
795  }
796 
797  if ($a_new1 != $a_new2)
798  {
799  return false;
800  }
801 
802  // is catched by isset() ???
803  if ($a_new1 == "" || $a_old == "")
804  {
805  return false;
806  }
807 
808  //check old password
809  switch ($this->passwd_type)
810  {
811  case IL_PASSWD_PLAIN:
812  if ($a_old != $this->passwd)
813  {
814  return false;
815  }
816  break;
817 
818  case IL_PASSWD_MD5:
819  if (md5($a_old) != $this->passwd)
820  {
821  return false;
822  }
823  break;
824 
825  case IL_PASSWD_CRYPT:
826  if (_makeIlias2Password($a_old) != $this->passwd)
827  {
828  return false;
829  }
830  break;
831  }
832 
833  //update password
834  $this->passwd = md5($a_new1);
835  $this->passwd_type = IL_PASSWD_MD5;
836 
837  $ilDB->manipulateF("UPDATE usr_data SET ".
838  "passwd = %s ".
839  "WHERE usr_id = %s",
840  array("text", "integer"), array($this->passwd, $this->id));
841 
842  return true;
843  }
844 
852  function resetPassword($a_new1, $a_new2)
853  {
854  global $ilDB;
855 
856  if (func_num_args() != 2)
857  {
858  return false;
859  }
860 
861  if (!isset($a_new1) or !isset($a_new2))
862  {
863  return false;
864  }
865 
866  if ($a_new1 != $a_new2)
867  {
868  return false;
869  }
870 
871  //update password
872  $this->passwd = md5($a_new1);
873  $this->passwd_type = IL_PASSWD_MD5;
874 
875  $ilDB->manipulateF("UPDATE usr_data SET ".
876  "passwd = %s ".
877  "WHERE usr_id = %s",
878  array("text", "integer"),
879  array($this->passwd, $this->id));
880 
881  return true;
882  }
883 
887  function _makeIlias2Password($a_passwd)
888  {
889  return (crypt($a_passwd,substr($a_passwd,0,2)));
890  }
891 
895  function _lookupHasIlias2Password($a_user_login)
896  {
897  global $ilias, $ilDB;
898 
899  $user_set = $ilDB->queryF("SELECT i2passwd FROM usr_data ".
900  "WHERE login = %s", array("text"), array($a_user_login));
901  if ($user_rec = $ilDB->fetchAssoc($user_set))
902  {
903  if ($user_rec["i2passwd"] != "")
904  {
905  return true;
906  }
907  }
908 
909  return false;
910  }
911 
915  function _switchToIlias3Password($a_user, $a_pw)
916  {
917  global $ilias, $ilDB;
918 
919  $user_set = $ilDB->queryF("SELECT i2passwd FROM usr_data ".
920  "WHERE login = %s", array("text"), array($a_user_login));
921  if ($user_rec = $ilDB->fetchAssoc($user_set))
922  {
923  if ($user_rec["i2passwd"] == ilObjUser::_makeIlias2Password($a_pw))
924  {
925  $ilDB->manipulateF("UPDATE usr_data SET passwd = %s, i2passwd = %s".
926  "WHERE login = %s",
927  array("text", "text", "text"),
928  array(md5($a_pw), "", $a_user));
929  return true;
930  }
931  }
932 
933  return false;
934  }
935 
946  public static function _doesLoginnameExistInHistory($a_login)
947  {
948  global $ilDB;
949 
950  $res = $ilDB->queryF('
951  SELECT * FROM loginname_history
952  WHERE login = %s',
953  array('text'), array($a_login));
954 
955  return $ilDB->fetchAssoc($res) ? true : false;
956  }
957 
970  public static function _getLastHistoryDataByUserId($a_usr_id)
971  {
972  global $ilDB;
973 
974  $ilDB->setLimit(1, 0);
975  $res = $ilDB->queryF('
976  SELECT login, history_date FROM loginname_history
977  WHERE usr_id = %s ORDER BY history_date DESC',
978  array('integer'), array($a_usr_id));
979  $row = $ilDB->fetchAssoc($res);
980  if(!is_array($row) || !count($row)) throw new ilUserException('');
981 
982  return array(
983  $row['login'], $row['history_date']
984  );
985  }
986 
994  function updateLogin($a_login)
995  {
996  global $ilDB, $ilSetting;
997 
998  if(func_num_args() != 1)
999  {
1000  return false;
1001  }
1002 
1003  if(!isset($a_login))
1004  {
1005  return false;
1006  }
1007 
1008  // Update not necessary
1009  if($a_login == self::_lookupLogin($this->getId()))
1010  {
1011  return false;
1012  }
1013 
1014  try
1015  {
1016  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1017  }
1018  catch(ilUserException $e) { $last_history_entry = null; }
1019 
1020  // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1021  if((int)$ilSetting->get('allow_change_loginname') &&
1022  (int)$ilSetting->get('prevent_reuse_of_loginnames') &&
1024  {
1025  throw new ilUserException($this->lng->txt('loginname_already_exists'));
1026  }
1027  else if((int)$ilSetting->get('allow_change_loginname') &&
1028  (int)$ilSetting->get('loginname_change_blocking_time') &&
1029  is_array($last_history_entry) &&
1030  $last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time') > time())
1031  {
1032  include_once 'Services/Calendar/classes/class.ilDate.php';
1033  throw new ilUserException(
1034  sprintf(
1035  $this->lng->txt('changing_loginname_not_possible_info'),
1037  new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1039  new ilDateTime(($last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX))
1040  )
1041  );
1042  }
1043  else
1044  {
1045  // log old loginname in history
1046  if((int)$ilSetting->get('allow_change_loginname') &&
1047  (int)$ilSetting->get('create_history_loginname'))
1048  {
1049  ilObjUser::_writeHistory($this->getId(), self::_lookupLogin($this->getId()));
1050  }
1051 
1052  //update login
1053  $this->login = $a_login;
1054 
1055  $ilDB->manipulateF('
1056  UPDATE usr_data
1057  SET login = %s
1058  WHERE usr_id = %s',
1059  array('text', 'integer'), array($this->getLogin(), $this->getId()));
1060  }
1061 
1062  return true;
1063  }
1064 
1071  function writePref($a_keyword, $a_value)
1072  {
1073  ilObjUser::_writePref($this->id, $a_keyword, $a_value);
1074  $this->setPref($a_keyword, $a_value);
1075  }
1076 
1077 
1083  function deletePref($a_keyword)
1084  {
1085  ilObjUser::_deletePref($this->getId(), $a_keyword);
1086  }
1087 
1093  function _deletePref($a_user_id, $a_keyword)
1094  {
1095  global $ilDB;
1096 
1097  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s",
1098  array("integer", "text"), array($a_user_id, $a_keyword));
1099  }
1100 
1106  function _deleteAllPref($a_user_id)
1107  {
1108  global $ilDB;
1109 
1110  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1111  array("integer"), array($a_user_id));
1112  }
1113 
1117  function _writePref($a_usr_id, $a_keyword, $a_value)
1118  {
1119  global $ilDB;
1120 
1121  ilObjUser::_deletePref($a_usr_id, $a_keyword);
1122  if (strlen($a_value))
1123  {
1124  $ilDB->manipulateF("INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s,%s,%s)",
1125  array("integer", "text", "text"), array($a_usr_id, $a_keyword, $a_value));
1126  }
1127  }
1128 
1133  function writePrefs()
1134  {
1135  global $ilDB;
1136 
1137  ilObjUser::_deleteAllPref($this->id);
1138  foreach ($this->prefs as $keyword => $value)
1139  {
1140  ilObjUser::_writePref($this->id, $keyword, $value);
1141  }
1142  }
1143 
1150  public function getTimeZone()
1151  {
1152  if($tz = $this->getPref('user_tz'))
1153  {
1154  return $tz;
1155  }
1156  else
1157  {
1158  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1159  $settings = ilCalendarSettings::_getInstance();
1160  return $settings->getDefaultTimeZone();
1161  }
1162  }
1163 
1170  public function getTimeFormat()
1171  {
1172  if($format = $this->getPref('time_format'))
1173  {
1174  return $format;
1175  }
1176  else
1177  {
1178  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1179  $settings = ilCalendarSettings::_getInstance();
1180  return $settings->getDefaultTimeFormat();
1181  }
1182  }
1183 
1190  function setPref($a_keyword, $a_value)
1191  {
1192  if ($a_keyword != "")
1193  {
1194  $this->prefs[$a_keyword] = $a_value;
1195  }
1196  }
1197 
1203  function getPref($a_keyword)
1204  {
1205  if (array_key_exists($a_keyword, $this->prefs))
1206  {
1207  return $this->prefs[$a_keyword];
1208  }
1209  else
1210  {
1211  return FALSE;
1212  }
1213  }
1214 
1215  function _lookupPref($a_usr_id,$a_keyword)
1216  {
1217  global $ilDB;
1218 
1219  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1220  "AND keyword = ".$ilDB->quote($a_keyword, "text");
1221  $res = $ilDB->query($query);
1222 
1223  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1224  {
1225  return $row->value;
1226  }
1227  return false;
1228  }
1229 
1235  function readPrefs()
1236  {
1237  global $ilDB;
1238 
1239  if (is_array($this->prefs))
1240  {
1241  $this->oldPrefs = $this->prefs;
1242  }
1243 
1244  $this->prefs = ilObjUser::_getPreferences($this->id);
1245  return count($prefs);
1246  }
1247 
1253  function delete()
1254  {
1255  global $rbacadmin, $ilDB;
1256 
1257  // deassign from ldap groups
1258  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1260  $mapping->deleteUser($this->getId());
1261 
1262  // remove mailbox / update sent mails
1263  include_once ("Services/Mail/classes/class.ilMailbox.php");
1264  $mailbox = new ilMailbox($this->getId());
1265  $mailbox->delete();
1266  $mailbox->updateMailsOfDeletedUser();
1267 
1268  // delete feed blocks on personal desktop
1269  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1270  $costum_block = new ilCustomBlock();
1271  $costum_block->setContextObjId($this->getId());
1272  $costum_block->setContextObjType("user");
1273  $c_blocks = $costum_block->queryBlocksForContext();
1274  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1275  foreach($c_blocks as $c_block)
1276  {
1277  if ($c_block["type"] == "pdfeed")
1278  {
1279  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1280  $fb->delete();
1281  }
1282  }
1283 
1284 
1285  // delete block settings
1286  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1288 
1289  // delete user_account
1290  $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1291  array("integer"), array($this->getId()));
1292 
1293  // delete user_prefs
1294  ilObjUser::_deleteAllPref($this->getId());
1295 
1296  // delete user_session
1297  include_once("./Services/Authentication/classes/class.ilSession.php");
1299 
1300  // remove user from rbac
1301  $rbacadmin->removeUser($this->getId());
1302 
1303  // remove bookmarks
1304  // TODO: move this to class.ilBookmarkFolder
1305  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1306  $ilDB->quote($this->getId(), "integer");
1307  $ilDB->manipulate($q);
1308 
1309  $q = "DELETE FROM bookmark_data WHERE user_id = ".
1310  $ilDB->quote($this->getId(), "integer");
1311  $ilDB->manipulate($q);
1312 
1313  // DELETE FORUM ENTRIES (not complete in the moment)
1314  include_once './Modules/Forum/classes/class.ilObjForum.php';
1315  ilObjForum::_deleteUser($this->getId());
1316 
1317  // Delete link check notify entries
1318  include_once './classes/class.ilLinkCheckNotify.php';
1320 
1321  // Delete crs entries
1322  include_once './Modules/Course/classes/class.ilObjCourse.php';
1323  ilObjCourse::_deleteUser($this->getId());
1324 
1325  // Delete user tracking
1326  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1328 
1329  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1331 
1332  // Delete user defined field entries
1334 
1335  // Delete clipboard entries
1336  $this->clipboardDeleteAll();
1337 
1338  // delete object data
1339  parent::delete();
1340  return true;
1341  }
1342 
1352  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1353  {
1354  $this->fullname = "";
1355 
1356  if ($a_title)
1357  {
1358  $fullname = $a_title." ";
1359  }
1360  elseif ($this->utitle)
1361  {
1362  $this->fullname = $this->utitle." ";
1363  }
1364 
1365  if ($a_firstname)
1366  {
1367  $fullname .= $a_firstname." ";
1368  }
1369  elseif ($this->firstname)
1370  {
1371  $this->fullname .= $this->firstname." ";
1372  }
1373 
1374  if ($a_lastname)
1375  {
1376  return $fullname.$a_lastname;
1377  }
1378 
1379  $this->fullname .= $this->lastname;
1380  }
1381 
1396  function getFullname($a_max_strlen = 0)
1397  {
1398  if (!$a_max_strlen)
1399  {
1400  return ilUtil::stripSlashes($this->fullname);
1401  }
1402 
1403  if (strlen($this->fullname) <= $a_max_strlen)
1404  {
1405  return ilUtil::stripSlashes($this->fullname);
1406  }
1407 
1408  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1409  {
1410  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1411  }
1412 
1413  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1414  {
1415  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1416  }
1417 
1418  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1419  {
1420  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1421  }
1422 
1423  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1424  }
1425 
1426 // ### AA 03.09.01 updated page access logger ###
1433  {
1434  global $ilDB;
1435 
1436  //query
1437  $q = "SELECT * FROM lo_access ".
1438  "WHERE usr_id= ".$ilDB->quote((int) $this->id, "integer")." ".
1439  "ORDER BY timestamp DESC";
1440  $rst = $ilDB->query($q);
1441 
1442  // fill array
1443  $result = array();
1444  while($record = $ilDB->fetchObject($rst))
1445  {
1446  $result[] = array(
1447  "timestamp" => $record->timestamp,
1448  "usr_id" => $record->usr_id,
1449  "lm_id" => $record->lm_id,
1450  "obj_id" => $record->obj_id,
1451  "lm_title" => $record->lm_title);
1452  }
1453  return $result;
1454  }
1455 
1456 // ### AA 03.09.01 updated page access logger ###
1462  function getLessons()
1463  {
1464  global $ilDB;
1465 
1466  //query
1467  $q = "SELECT * FROM lo_access ".
1468  "WHERE usr_id= ".$ilDB->quote((int) $this->id, "integer")." ";
1469  $rst = $ilDB->query($q);
1470 
1471  // fill array
1472  $result = array();
1473  while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
1474  {
1475  $result[] = array(
1476  "timestamp" => $record->timestamp,
1477  "usr_id" => $record->usr_id,
1478  "lm_id" => $record->lm_id,
1479  "obj_id" => $record->obj_id,
1480  "lm_title" => $record->lm_title);
1481  }
1482  return $result;
1483  }
1484 
1493  public static function _hasAcceptedAgreement($a_username)
1494  {
1495  global $ilDB;
1496 
1497  if($a_username == 'root')
1498  {
1499  return true;
1500  }
1501 
1502  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
1503  "WHERE login = %s AND NOT agree_date IS NULL",
1504  array("text"), array($a_username));
1505  return $ilDB->fetchAssoc($res) ? true : false;
1506  }
1507 
1508 
1513  {
1514  if ($this->agree_date != null || $this->login == "root")
1515  {
1516  return true;
1517  }
1518  return false;
1519  }
1520 
1526  function setLogin($a_str)
1527  {
1528  $this->login = $a_str;
1529  }
1530 
1535  function getLogin()
1536  {
1537  return $this->login;
1538  }
1539 
1545  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1546  {
1547  $this->passwd = $a_str;
1548  $this->passwd_type = $a_type;
1549  }
1550 
1558  function getPasswd()
1559  {
1560  return $this->passwd;
1561  }
1568  function getPasswdType()
1569  {
1570  return $this->passwd_type;
1571  }
1572 
1578  function setGender($a_str)
1579  {
1580  $this->gender = substr($a_str,-1);
1581  }
1582 
1587  function getGender()
1588  {
1589  return $this->gender;
1590  }
1591 
1599  function setUTitle($a_str)
1600  {
1601  $this->utitle = $a_str;
1602  }
1603 
1610  function getUTitle()
1611  {
1612  return $this->utitle;
1613  }
1614 
1620  function setFirstname($a_str)
1621  {
1622  $this->firstname = $a_str;
1623  }
1624 
1629  function getFirstname()
1630  {
1631  return $this->firstname;
1632  }
1633 
1639  function setLastname($a_str)
1640  {
1641  $this->lastname = $a_str;
1642  }
1643 
1648  function getLastname()
1649  {
1650  return $this->lastname;
1651  }
1652 
1658  function setInstitution($a_str)
1659  {
1660  $this->institution = $a_str;
1661  }
1662 
1667  function getInstitution()
1668  {
1669  return $this->institution;
1670  }
1671 
1677  function setDepartment($a_str)
1678  {
1679  $this->department = $a_str;
1680  }
1681 
1686  function getDepartment()
1687  {
1688  return $this->department;
1689  }
1690 
1696  function setStreet($a_str)
1697  {
1698  $this->street = $a_str;
1699  }
1700 
1705  function getStreet()
1706  {
1707  return $this->street;
1708  }
1709 
1715  function setCity($a_str)
1716  {
1717  $this->city = $a_str;
1718  }
1719 
1724  function getCity()
1725  {
1726  return $this->city;
1727  }
1728 
1734  function setZipcode($a_str)
1735  {
1736  $this->zipcode = $a_str;
1737  }
1738 
1743  function getZipcode()
1744  {
1745  return $this->zipcode;
1746  }
1747 
1753  function setCountry($a_str)
1754  {
1755  $this->country = $a_str;
1756  }
1757 
1762  function getCountry()
1763  {
1764  return $this->country;
1765  }
1766 
1772  function setPhoneOffice($a_str)
1773  {
1774  $this->phone_office = $a_str;
1775  }
1776 
1781  function getPhoneOffice()
1782  {
1783  return $this->phone_office;
1784  }
1785 
1791  function setPhoneHome($a_str)
1792  {
1793  $this->phone_home = $a_str;
1794  }
1795 
1800  function getPhoneHome()
1801  {
1802  return $this->phone_home;
1803  }
1804 
1810  function setPhoneMobile($a_str)
1811  {
1812  $this->phone_mobile = $a_str;
1813  }
1814 
1819  function getPhoneMobile()
1820  {
1821  return $this->phone_mobile;
1822  }
1823 
1829  function setFax($a_str)
1830  {
1831  $this->fax = $a_str;
1832  }
1833 
1838  function getFax()
1839  {
1840  return $this->fax;
1841  }
1842 
1848  function setClientIP($a_str)
1849  {
1850  $this->client_ip = $a_str;
1851  }
1852 
1857  function getClientIP()
1858  {
1859  return $this->client_ip;
1860  }
1861 
1867  function setMatriculation($a_str)
1868  {
1869  $this->matriculation = $a_str;
1870  }
1871 
1876  function getMatriculation()
1877  {
1878  return $this->matriculation;
1879  }
1880 
1887  public static function lookupMatriculation($a_usr_id)
1888  {
1889  global $ilDB;
1890 
1891  $query = "SELECT matriculation FROM usr_data ".
1892  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1893  $res = $ilDB->query($query);
1894  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1895  return $row->matriculation ? $row->matriculation : '';
1896  }
1897 
1903  function setEmail($a_str)
1904  {
1905  $this->email = $a_str;
1906  }
1907 
1912  function getEmail()
1913  {
1914  return $this->email;
1915  }
1916 
1922  function setHobby($a_str)
1923  {
1924  $this->hobby = $a_str;
1925  }
1926 
1931  function getHobby()
1932  {
1933  return $this->hobby;
1934  }
1935 
1941  function setLanguage($a_str)
1942  {
1943  $this->setPref("language",$a_str);
1944  unset($_SESSION['lang']);
1945  }
1946 
1952  function getLanguage()
1953  {
1954  return $this->prefs["language"];
1955  }
1956 
1965  function setDiskQuota($a_disk_quota)
1966  {
1967  $this->setPref("disk_quota",$a_disk_quota);
1968  }
1969 
1979  function getDiskQuota()
1980  {
1981  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
1982  }
1983 
1984  public function setLastPasswordChangeTS($a_last_password_change_ts)
1985  {
1986  $this->last_password_change_ts = $a_last_password_change_ts;
1987  }
1988 
1989  public function getLastPasswordChangeTS()
1990  {
1992  }
1993 
1994 
1995  public static function _lookupLanguage($a_usr_id)
1996  {
1997  global $ilDB;
1998 
1999  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
2000  $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
2001  $ilDB->quote('language', "text");
2002  $r = $ilDB->query($q);
2003 
2004  while($row = $ilDB->fetchAssoc($r))
2005  {
2006  return $row['value'];
2007  }
2008  return 'en';
2009  }
2010 
2011 
2012  function _checkPassword($a_usr_id, $a_pw)
2013  {
2014  global $ilDB;
2015 
2016  $pw = ilObjUser::_lookup($a_usr_id, "passwd");
2017  if ($pw == md5($a_pw))
2018  {
2019  return true;
2020  }
2021  return false;
2022  }
2023 
2024  function _writeExternalAccount($a_usr_id, $a_ext_id)
2025  {
2026  global $ilDB;
2027 
2028  $ilDB->manipulateF("UPDATE usr_data ".
2029  " SET ext_account = %s WHERE usr_id = %s",
2030  array("text", "integer"),
2031  array($a_ext_id, $a_usr_id));
2032  }
2033 
2034  function _writeAuthMode($a_usr_id, $a_auth_mode)
2035  {
2036  global $ilDB;
2037 
2038  $ilDB->manipulateF("UPDATE usr_data ".
2039  " SET auth_mode = %s WHERE usr_id = %s",
2040  array("text", "integer"),
2041  array($a_auth_mode, $a_usr_id));
2042  }
2043 
2049  {
2050  return $_SESSION['lang'];
2051  }
2052 
2058  function setLastLogin($a_str)
2059  {
2060  $this->last_login = $a_str;
2061  }
2062 
2068  function getLastLogin()
2069  {
2070  return $this->last_login;
2071  }
2072 
2078  function setLastUpdate($a_str)
2079  {
2080  $this->last_update = $a_str;
2081  }
2082  function getLastUpdate()
2083  {
2084  return $this->last_update;
2085  }
2086 
2092  function setComment($a_str)
2093  {
2094  $this->referral_comment = $a_str;
2095  }
2096 
2101  function getComment()
2102  {
2103  return $this->referral_comment;
2104  }
2105 
2112  function setApproveDate($a_str)
2113  {
2114  $this->approve_date = $a_str;
2115  }
2116 
2122  function getApproveDate()
2123  {
2124  return $this->approve_date;
2125  }
2126 
2127  // BEGIN DiskQuota: show when user accepted user agreement
2133  function getAgreeDate()
2134  {
2135  return $this->agree_date;
2136  }
2143  function setAgreeDate($a_str)
2144  {
2145  $this->agree_date = $a_str;
2146  }
2147  // END DiskQuota: show when user accepted user agreement
2148 
2155  function setActive($a_active, $a_owner = 6)
2156  {
2157  if (empty($a_owner))
2158  {
2159  $a_owner = 0;
2160  }
2161 
2162  if ($a_active)
2163  {
2164  $this->active = 1;
2165  $this->setApproveDate(date('Y-m-d H:i:s'));
2166  $this->setOwner($a_owner);
2167  }
2168  else
2169  {
2170  $this->active = 0;
2171  $this->setApproveDate(null);
2172  $this->setOwner(0);
2173  }
2174  }
2175 
2180  function getActive()
2181  {
2182  return $this->active;
2183  }
2184 
2190  function syncActive()
2191  {
2192  global $ilAuth;
2193 
2194  $storedActive = 0;
2195  if ($this->getStoredActive($this->id))
2196  {
2197  $storedActive = 1;
2198  }
2199 
2200  $currentActive = 0;
2201  if ($this->active)
2202  {
2203  $currentActive = 1;
2204  }
2205 
2206  if ((!empty($storedActive) && empty($currentActive)) ||
2207  (empty($storedActive) && !empty($currentActive)))
2208  {
2209  $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2210  }
2211  }
2212 
2219  function getStoredActive($a_id)
2220  {
2221  $active = ilObjUser::_lookup($a_id, "active");
2222  return $active ? true : false;
2223  }
2224 
2230  function setSkin($a_str)
2231  {
2232  // TODO: exception handling (dir exists)
2233  $this->skin = $a_str;
2234  }
2235 
2236  function setTimeLimitOwner($a_owner)
2237  {
2238  $this->time_limit_owner = $a_owner;
2239  }
2241  {
2242  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2243  }
2244  function setTimeLimitFrom($a_from)
2245  {
2246  $this->time_limit_from = $a_from;
2247  }
2248  function getTimeLimitFrom()
2249  {
2250  return $this->time_limit_from ? $this->time_limit_from : time();
2251  }
2252  function setTimeLimitUntil($a_until)
2253  {
2254  $this->time_limit_until = $a_until;
2255  }
2257  {
2258  return $this->time_limit_until ? $this->time_limit_until : time();
2259  }
2260  function setTimeLimitUnlimited($a_unlimited)
2261  {
2262  $this->time_limit_unlimited = $a_unlimited;
2263  }
2265  {
2266  return $this->time_limit_unlimited;
2267  }
2268  function setTimeLimitMessage($a_time_limit_message)
2269  {
2270  return $this->time_limit_message = $a_time_limit_message;
2271  }
2273  {
2274  return $this->time_limit_message;
2275  }
2276 
2277  public function setLoginAttempts($a_login_attempts)
2278  {
2279  $this->login_attempts = $a_login_attempts;
2280  }
2281 
2282  public function getLoginAttempts()
2283  {
2284  return $this->login_attempts;
2285  }
2286 
2287 
2288  function checkTimeLimit()
2289  {
2290  if($this->getTimeLimitUnlimited())
2291  {
2292  return true;
2293  }
2294  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2295  {
2296  return true;
2297  }
2298  return false;
2299  }
2300  function setProfileIncomplete($a_prof_inc)
2301  {
2302  $this->profile_incomplete = (boolean) $a_prof_inc;
2303  }
2305  {
2306  return $this->profile_incomplete;
2307  }
2308 
2309  public function isPasswordChangeDemanded()
2310  {
2311  //error_reporting(E_ALL);
2312  if( $this->id == ANONYMOUS_USER_ID || $this->id == SYSTEM_USER_ID )
2313  return false;
2314 
2315  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2316  $security = ilSecuritySettings::_getInstance();
2317 
2319  && $security->isPasswordChangeOnFirstLoginEnabled()
2320  && $this->getLastPasswordChangeTS() == 0
2321  ){
2322  return true;
2323  }
2324  else return false;
2325  }
2326 
2327  public function isPasswordExpired()
2328  {
2329  //error_reporting(E_ALL);
2330  if($this->id == ANONYMOUS_USER_ID) return false;
2331 
2332  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2333  $security = ilSecuritySettings::_getInstance();
2334  if( $security->getAccountSecurityMode() == ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED &&
2335  $this->getLastPasswordChangeTS() > 0 )
2336  {
2337  $max_pass_age = $security->getPasswordMaxAge();
2338  if( $max_pass_age > 0 )
2339  {
2340  $max_pass_age_ts = ( $max_pass_age * 86400 );
2341  $pass_change_ts = $this->getLastPasswordChangeTS();
2342  $current_ts = time();
2343 
2344  if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2345  return true;
2346  }
2347  }
2348  return false;
2349  }
2350 
2351  public function getPasswordAge()
2352  {
2353  $current_ts = time();
2354  $pass_change_ts = $this->getLastPasswordChangeTS();
2355  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2356  return $password_age;
2357  }
2358 
2359  public function setLastPasswordChangeToNow()
2360  {
2361  global $ilDB;
2362 
2363  $this->setLastPasswordChangeTS( time() );
2364 
2365  $query = "UPDATE usr_data SET usr_data.last_password_change = %s " .
2366  "WHERE usr_data.usr_id = %s";
2367  $affected = $ilDB->manipulateF($query,
2368  array('integer','integer'),
2369  array($this->getLastPasswordChangeTS(),$this->id));
2370  if($affected) return true;
2371  else return false;
2372  }
2373 
2374  public function resetLastPasswordChange()
2375  {
2376  global $ilDB;
2377 
2378  $query = "UPDATE usr_data SET usr_data.last_password_change = 0 " .
2379  "WHERE usr_data.usr_id = %s";
2380  $affected = $ilDB->manipulateF( $query, array('integer'),
2381  array($this->getId()) );
2382  if($affected) return true;
2383  else return false;
2384  }
2385 
2391  function setLatitude($a_latitude)
2392  {
2393  $this->latitude = $a_latitude;
2394  }
2395 
2401  function getLatitude()
2402  {
2403  return $this->latitude;
2404  }
2405 
2411  function setLongitude($a_longitude)
2412  {
2413  $this->longitude = $a_longitude;
2414  }
2415 
2421  function getLongitude()
2422  {
2423  return $this->longitude;
2424  }
2425 
2431  function setLocationZoom($a_locationzoom)
2432  {
2433  $this->loc_zoom = $a_locationzoom;
2434  }
2435 
2441  function getLocationZoom()
2442  {
2443  return $this->loc_zoom;
2444  }
2445 
2446  function &getAppliedUsers()
2447  {
2448  $this->applied_users = array();
2449  $this->__readAppliedUsers($this->getId());
2450 
2451  return $this->applied_users ? $this->applied_users : array();
2452  }
2453 
2454  function isChild($a_usr_id)
2455  {
2456  if($a_usr_id == $this->getId())
2457  {
2458  return true;
2459  }
2460 
2461  $this->applied_users = array();
2462  $this->__readAppliedUsers($this->getId());
2463 
2464  return in_array($a_usr_id,$this->applied_users);
2465  }
2466 
2467  function __readAppliedUsers($a_parent_id)
2468  {
2469  global $ilDB;
2470 
2471  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2472  "WHERE time_limit_owner = %s",
2473  array("integer"),
2474  array($a_parent_id));
2475  while ($row = $ilDB->fetchObject($res))
2476  {
2477  $this->applied_users[] = $row->usr_id;
2478 
2479  // recursion
2480  $this->__readAppliedUsers($row->usr_id);
2481  }
2482  return true;
2483  }
2484 
2485  /*
2486  * check user id with login name
2487  * @access public
2488  */
2489  function checkUserId()
2490  {
2491  global $ilDB,$ilAuth, $ilSetting;
2492 
2495  if ($id > 0)
2496  {
2497  // check for simultaneous logins, except the user is the anonymous one
2498  if( $id != ANONYMOUS_USER_ID && (int)$ilSetting->get('ps_prevent_simultaneous_logins') == 1 )
2499  {
2500  $res = $ilDB->queryf('
2501  SELECT * FROM usr_session WHERE user_id = %s AND expires > %s',
2502  array('integer', 'integer'),
2503  array($id, time()));
2504  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2505  {
2506  $ilAuth->logout();
2507  @session_destroy();
2508  ilUtil::redirect('login.php?simultaneous_login=true');
2509  exit();
2510  }
2511  }
2512 
2513  return $id;
2514  }
2515  return false;
2516  }
2517 
2521  private static function getLoginFromAuth() {
2522  global $ilAuth;
2523 
2524  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2525  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2527  {
2528  require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2529  require_once ('Services/Database/classes/class.ilAuthContainerMDB2.php');
2530  $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2531  }
2532  else
2533  {
2534  $login =$ilAuth->getUsername();
2535  }
2536 
2537  return $login;
2538  }
2539 
2540  /*
2541  * check to see if current user has been made active
2542  * @access public
2543  * @return true if active, otherwise false
2544  */
2546  {
2547  global $ilDB,$ilAuth;
2548 
2550  $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2551  array("text"),
2552  array($login));
2553  //query has got a result
2554  if ($rec = $ilDB->fetchAssoc($set))
2555  {
2556  if ($rec["active"])
2557  {
2558  return true;
2559  }
2560  }
2561 
2562  return false;
2563  }
2564 
2565  /*
2566  * STATIC METHOD
2567  * get the user_id of a login name
2568  * @param string login name
2569  * @return integer id of user
2570  * @static
2571  * @access public
2572  */
2573  function getUserIdByLogin($a_login)
2574  {
2575  return (int) ilObjUser::_lookupId($a_login);
2576  }
2577 
2586  function _getUserIdsByEmail($a_email)
2587  {
2588  global $ilias, $ilDB;
2589 
2590  $res = $ilDB->queryF("SELECT login FROM usr_data ".
2591  "WHERE email = %s and active = 1",
2592  array("text"),
2593  array($a_email));
2594  $ids = array ();
2595  while($row = $ilDB->fetchObject($res))
2596  {
2597  $ids[] = $row->login;
2598  }
2599 
2600  return $ids;
2601  }
2602 
2603 
2604 
2613  function getUserIdByEmail($a_email)
2614  {
2615  global $ilDB;
2616 
2617  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2618  "WHERE email = %s", array("text"), array($a_email));
2619 
2620  $row = $ilDB->fetchObject($res);
2621  return $row->usr_id ? $row->usr_id : 0;
2622  }
2623 
2624  /*
2625  * STATIC METHOD
2626  * get the login name of a user_id
2627  * @param integer id of user
2628  * @return string login name; false if not found
2629  * @static
2630  * @access public
2631  */
2632  function getLoginByUserId($a_userid)
2633  {
2634  $login = ilObjUser::_lookupLogin($a_userid);
2635  return $login ? $login : false;
2636  }
2637 
2648  static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2649  {
2650  global $ilias, $ilDB, $ilLog;
2651 
2652 
2653  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2654 
2655  $without_anonymous_users = true;
2656 
2657  // determine join filter
2658  $join_filter = " WHERE ";
2659  if ($filter_settings !== FALSE && strlen($filter_settings))
2660  {
2661  switch ($filter_settings)
2662  {
2663  case 3:
2664  // show only users without courses
2665  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.usr_id IS NULL AND ";
2666  break;
2667  case 5:
2668  // show only users with a certain course membership
2669  $ref_id = $_SESSION["user_filter_data"];
2670  if ($ref_id)
2671  {
2672  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.obj_id = ".
2673  "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2674  }
2675  break;
2676  case 6:
2677  global $rbacreview;
2678  $ref_id = $_SESSION["user_filter_data"];
2679  if ($ref_id)
2680  {
2681  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2682  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2683  if (is_array($local_roles) && count($local_roles))
2684  {
2685  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2686  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2687  }
2688  }
2689  break;
2690  case 7:
2691  global $rbacreview;
2692  $rol_id = $_SESSION["user_filter_data"];
2693  if ($rol_id)
2694  {
2695  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2696  $ilDB->quote($rol_id, "integer")." AND ";
2697  $without_anonymous_users = false;
2698  }
2699  break;
2700  }
2701  }
2702  // This is a temporary hack to search users by their role
2703  // See Mantis #338. This is a hack due to Mantis #337.
2704  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2705  {
2706  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2707  "FROM object_data,rbac_ua,usr_data ".
2708  "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2709  " AND object_data.type = 'role' ".
2710  "AND rbac_ua.rol_id = object_data.obj_id ".
2711  "AND usr_data.usr_id = rbac_ua.usr_id ".
2712  "AND rbac_ua.usr_id != ".$illDB->quote(ANONYMOUS_USER_ID, "integer");
2713  }
2714  else
2715  {
2716  $query.= $join_filter.
2717  "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2718  "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2719  "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2720  "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2721 
2722  if ($filter_settings !== FALSE && strlen($filter_settings))
2723  {
2724  switch ($filter_settings)
2725  {
2726  case 0:
2727  $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2728  break;
2729  case 1:
2730  $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2731  break;
2732  case 2:
2733  $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2734  break;
2735  case 4:
2736  $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"]));
2737  $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2738  break;
2739  }
2740  }
2741 
2742  if ($without_anonymous_users)
2743  {
2744  $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2745  }
2746 
2747  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2748  {
2749  $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2750  }
2751 
2752  }
2753  $ilLog->write($query);
2754  $res = $ilDB->query($query);
2755  while ($row = $ilDB->fetchObject($res))
2756  {
2757  $users[] = array(
2758  "usr_id" => $row->usr_id,
2759  "login" => $row->login,
2760  "firstname" => $row->firstname,
2761  "lastname" => $row->lastname,
2762  "email" => $row->email,
2763  "active" => $row->active);
2764  $ids[] = $row->usr_id;
2765  }
2766  if ($a_return_ids_only)
2767  return $ids ? $ids : array();
2768  else
2769  return $users ? $users : array();
2770  }
2771 
2781  {
2782  global $ilDB;
2783 
2784  $res = $ilDB->query("SELECT login FROM usr_data");
2785  while($row = $ilDB->fetchObject($res))
2786  {
2787  $logins[] = $row->login;
2788  }
2789  return $logins ? $logins : array();
2790  }
2791 
2800  public static function _readUsersProfileData($a_user_ids)
2801  {
2802  global $ilDB;
2803  $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2804  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2805  while ($row = $ilDB->fetchAssoc($res))
2806  {
2807  $user_data["$row[usr_id]"] = $row;
2808  }
2809  return $user_data ? $user_data : array();
2810  }
2811 
2820  function _getAllUserData($a_fields = NULL, $active =-1)
2821  {
2822  global $ilDB;
2823 
2824  $result_arr = array();
2825  $types = array();
2826  $values = array();
2827 
2828  if ($a_fields !== NULL and is_array($a_fields))
2829  {
2830  if (count($a_fields) == 0)
2831  {
2832  $select = "*";
2833  }
2834  else
2835  {
2836  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2837  unset($a_fields[$usr_id_field]);
2838 
2839  $select = implode(",",$a_fields).",usr_data.usr_id";
2840  // online time
2841  if(in_array('online_time',$a_fields))
2842  {
2843  $select .= ",ut_online.online_time ";
2844  }
2845  }
2846 
2847  $q = "SELECT ".$select." FROM usr_data ";
2848 
2849  // Add online_time if desired
2850  // Need left join here to show users that never logged in
2851  if(in_array('online_time',$a_fields))
2852  {
2853  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2854  }
2855 
2856  switch ($active)
2857  {
2858  case 0:
2859  case 1:
2860  $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2861  break;
2862  case 2:
2863  $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2864  break;
2865  case 3:
2866  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2867  $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2868  $r = $ilDB->query($qtemp);
2869  $course_users = array();
2870  while ($row = $ilDB->fetchAssoc($r))
2871  {
2872  array_push($course_users, $row["usr_id"]);
2873  }
2874  if (count($course_users))
2875  {
2876  $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2877  }
2878  else
2879  {
2880  return $result_arr;
2881  }
2882  break;
2883  case 4:
2884  $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"]));
2885  $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2886  break;
2887  case 5:
2888  $ref_id = $_SESSION["user_filter_data"];
2889  if ($ref_id)
2890  {
2891  $q .= " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id ".
2892  "WHERE crs_members.obj_id = (SELECT obj_id FROM object_reference ".
2893  "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2894  }
2895  break;
2896  case 6:
2897  global $rbacreview;
2898  $ref_id = $_SESSION["user_filter_data"];
2899  if ($ref_id)
2900  {
2901  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2902  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2903  if (is_array($local_roles) && count($local_roles))
2904  {
2905  $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2906  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2907  }
2908  }
2909  break;
2910  case 7:
2911  $rol_id = $_SESSION["user_filter_data"];
2912  if ($rol_id)
2913  {
2914  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2915  $ilDB->quote($rol_id, "integer");
2916  }
2917  break;
2918  }
2919 
2920  $r = $ilDB->query($q);
2921 
2922  while ($row = $ilDB->fetchAssoc($r))
2923  {
2924  $result_arr[] = $row;
2925  }
2926  }
2927 
2928  return $result_arr;
2929  }
2930 
2934  function _getNumberOfUsersForStyle($a_skin, $a_style)
2935  {
2936  global $ilDB;
2937 
2938  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
2939  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
2940  " AND up1.value= ".$ilDB->quote($a_style, "text").
2941  " AND up2.keyword= ".$ilDB->quote("skin", "text").
2942  " AND up2.value= ".$ilDB->quote($a_skin, "text").
2943  " AND up1.usr_id = up2.usr_id ";
2944 
2945  $cnt_set = $ilDB->query($q);
2946 
2947  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
2948 
2949  return $cnt_rec["cnt"];
2950  }
2951 
2956  {
2957  global $ilDB;
2958 
2959  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
2960  " WHERE up1.keyword = ".$ilDB->quote("style", "text").
2961  " AND up2.keyword = ".$ilDB->quote("skin", "text").
2962  " AND up1.usr_id = up2.usr_id";
2963 
2964  $sty_set = $ilDB->query($q);
2965 
2966  $styles = array();
2967  while($sty_rec = $ilDB->fetchAssoc($sty_set))
2968  {
2969  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
2970  }
2971 
2972  return $styles;
2973  }
2974 
2978  function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
2979  {
2980  global $ilDB;
2981 
2982  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
2983  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
2984  " AND up1.value= ".$ilDB->quote($a_from_style, "text").
2985  " AND up2.keyword= ".$ilDB->quote("skin", "text").
2986  " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
2987  " AND up1.usr_id = up2.usr_id ";
2988 
2989  $usr_set = $ilDB->query($q);
2990 
2991  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
2992  {
2993  ilObjUser::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
2994  ilObjUser::_writePref($usr_rec["usr_id"], "style", $a_to_style);
2995  }
2996  }
2997 
2998 
3008  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3009  {
3010  global $ilDB;
3011 
3012  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3013  "item_id = %s AND type = %s AND user_id = %s",
3014  array("integer", "text", "integer"),
3015  array($a_item_id, $a_type, $a_usr_id));
3016 
3017  // only insert if item is not already on desktop
3018  if (!$ilDB->fetchAssoc($item_set))
3019  {
3020  $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3021  " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3022  array($a_item_id,$a_type,$a_usr_id,$a_par));
3023  }
3024 
3025  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3027  }
3028 
3036  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3037  {
3038  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3039  }
3040 
3049  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3050  {
3051  global $ilDB;
3052 
3053  $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3054  " WHERE item_id = %s AND type = %s AND user_id = %s",
3055  array("text", "integer", "text", "integer"),
3056  array($a_par, $a_item_id, $a_type, $this->getId()));
3057  }
3058 
3059 
3069  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3070  {
3071  global $ilDB;
3072 
3073  $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3074  " item_id = %s AND type = %s AND user_id = %s",
3075  array("integer", "text", "integer"),
3076  array($a_item_id, $a_type, $a_usr_id));
3077 
3078  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3080  }
3081 
3089  function dropDesktopItem($a_item_id, $a_type)
3090  {
3091  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3092  }
3093 
3100  static function _removeItemFromDesktops($a_id)
3101  {
3102  global $ilDB;
3103 
3104  $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3105  array("integer"), array($a_id));
3106 
3107  $users = array();
3108 
3109  while ($row = $ilDB->fetchObject($r))
3110  {
3111  $users[] = $row->user_id;
3112  } // while
3113 
3114  if (count($users) > 0)
3115  {
3116  $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3117  array("integer"), array($a_id));
3118  }
3119 
3120  return $users;
3121  }
3122 
3132  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3133  {
3134  global $ilDB;
3135 
3136  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3137  "item_id = %s AND type = %s AND user_id = %s",
3138  array("integer", "text", "integer"),
3139  array($a_item_id, $a_type, $a_usr_id));
3140 
3141  if ($ilDB->fetchAssoc($item_set))
3142  {
3143  return true;
3144  }
3145  else
3146  {
3147  return false;
3148  }
3149  }
3150 
3158  function isDesktopItem($a_item_id, $a_type)
3159  {
3160  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3161  }
3162 
3163  function getDesktopItems($a_types = "")
3164  {
3165  return $this->_lookupDesktopItems($this->getId(), $a_types);
3166  }
3167 
3174  static function _lookupDesktopItems($user_id, $a_types = "")
3175  {
3176  global $ilUser, $rbacsystem, $tree, $ilDB;
3177 
3178  if ($a_types == "")
3179  {
3180  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3181  " FROM desktop_item it, object_reference oref ".
3182  ", object_data obj".
3183  " WHERE ".
3184  "it.item_id = oref.ref_id AND ".
3185  "oref.obj_id = obj.obj_id AND ".
3186  "it.user_id = %s", array("integer"), array($user_id));
3187  $items = array();
3188  while ($item_rec = $ilDB->fetchAssoc($item_set))
3189  {
3190  if ($tree->isInTree($item_rec["ref_id"])
3191  && $item_rec["type"] != "rolf")
3192  {
3193  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3194  $par_left = $tree->getLeftValue($parent_ref);
3195  $par_left = sprintf("%010d", $par_left);
3196 
3197 
3198  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3199  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3200  $items[$par_left.$title.$item_rec["ref_id"]] =
3201  array("ref_id" => $item_rec["ref_id"],
3202  "obj_id" => $item_rec["obj_id"],
3203  "type" => $item_rec["type"],
3204  "title" => $title,
3205  "description" => $desc,
3206  "parent_ref" => $parent_ref);
3207  }
3208  }
3209  ksort($items);
3210  }
3211  else
3212  {
3213  if (!is_array($a_types))
3214  {
3215  $a_types = array($a_types);
3216  }
3217  $items = array();
3218  $foundsurveys = array();
3219  foreach($a_types as $a_type)
3220  {
3221  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3222  ", object_data obj WHERE ".
3223  "it.item_id = oref.ref_id AND ".
3224  "oref.obj_id = obj.obj_id AND ".
3225  "it.type = %s AND ".
3226  "it.user_id = %s ".
3227  "ORDER BY title",
3228  array("text", "integer"),
3229  array($a_type, $user_id));
3230 
3231  while ($item_rec = $ilDB->fetchAssoc($item_set))
3232  {
3233  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3234  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3235  $items[$title.$a_type.$item_rec["ref_id"]] =
3236  array("ref_id" => $item_rec["ref_id"],
3237  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3238  "title" => $title, "description" => $desc);
3239  }
3240 
3241  }
3242  ksort($items);
3243  }
3244  return $items;
3245  }
3246 
3252 
3260  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3261  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3262  {
3263  global $ilDB;
3264 
3265  if ($a_time == 0)
3266  {
3267  $a_time = date("Y-m-d H:i:s", time());
3268  }
3269 
3270  $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3271  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3272  array("integer", "integer", "text", "integer"),
3273  array(0, $a_item_id, $a_type, $this->getId()));
3274 
3275  // only insert if item is not already in clipboard
3276  if (!$d = $item_set->fetchRow())
3277  {
3278  $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3279  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3280  " (%s,%s,%s,%s,%s,%s,%s)",
3281  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3282  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3283  }
3284  else
3285  {
3286  $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3287  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3288  array("timestamp", "integer", "integer", "text"),
3289  array($a_time, $this->getId(), $a_item_id, $a_type));
3290  }
3291  }
3292 
3296  function addToPCClipboard($a_content, $a_time, $a_nr)
3297  {
3298  global $ilDB;
3299  if ($a_time == 0)
3300  {
3301  $a_time = date("Y-m-d H:i:s", time());
3302  }
3303  $ilDB->insert("personal_pc_clipboard", array(
3304  "user_id" => array("integer", $this->getId()),
3305  "content" => array("clob", $a_content),
3306  "insert_time" => array("timestamp", $a_time),
3307  "order_nr" => array("integer", $a_nr)
3308  ));
3309  }
3310 
3315  {
3316  global $ilDB;
3317 
3318  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3319  " WHERE user_id = %s", array("integer"), array($this->getId()));
3320  $row = $ilDB->fetchAssoc($set);
3321 
3322  $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3323  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3324  array("integer", "timestamp"),
3325  array($this->getId(), $row["mtime"]));
3326  $content = array();
3327  while ($row = $ilDB->fetchAssoc($set))
3328  {
3329  $content[] = $row["content"];
3330  }
3331 
3332  return $content;
3333  }
3334 
3338  function clipboardHasObjectsOfType($a_type)
3339  {
3340  global $ilDB;
3341 
3342  $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3343  "parent = %s AND type = %s AND user_id = %s",
3344  array("integer", "text", "integer"),
3345  array(0, $a_type, $this->getId()));
3346  if ($rec = $ilDB->fetchAssoc($set))
3347  {
3348  return true;
3349  }
3350 
3351  return false;
3352  }
3353 
3358  {
3359  global $ilDB;
3360 
3361  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3362  "type = %s AND user_id = %s",
3363  array("text", "integer"),
3364  array($a_type, $this->getId()));
3365  }
3366 
3371  {
3372  global $ilDB;
3373 
3374  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3375  "user_id = %s", array("integer"), array($this->getId()));
3376  }
3377 
3381  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3382  {
3383  global $ilDB;
3384 
3385  $par = "";
3386  if ($a_top_nodes_only)
3387  {
3388  $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3389  }
3390 
3391  $type_str = ($a_type != "")
3392  ? " AND type = ".$ilDB->quote($a_type, "text")." "
3393  : "";
3394  $q = "SELECT * FROM personal_clipboard WHERE ".
3395  "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3396  $type_str.$par.
3397  " ORDER BY order_nr";
3398  $objs = $ilDB->query($q);
3399  $objects = array();
3400  while ($obj = $ilDB->fetchAssoc($objs))
3401  {
3402  if ($obj["type"] == "mob")
3403  {
3404  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3405  }
3406  if ($obj["type"] == "incl")
3407  {
3408  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3409  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3410  }
3411  $objects[] = array ("id" => $obj["item_id"],
3412  "type" => $obj["type"], "title" => $obj["title"],
3413  "insert_time" => $obj["insert_time"]);
3414  }
3415  return $objects;
3416  }
3417 
3421  function getClipboardChilds($a_parent, $a_insert_time)
3422  {
3423  global $ilDB, $ilUser;
3424 
3425  $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3426  "user_id = %s AND parent = %s AND insert_time = %s ".
3427  " ORDER BY order_nr",
3428  array("integer", "integer", "timestamp"),
3429  array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3430  $objects = array();
3431  while ($obj = $ilDB->fetchAssoc($objs))
3432  {
3433  if ($obj["type"] == "mob")
3434  {
3435  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3436  }
3437  $objects[] = array ("id" => $obj["item_id"],
3438  "type" => $obj["type"], "title" => $obj["title"]);
3439  }
3440  return $objects;
3441  }
3442 
3451  function _getUsersForClipboadObject($a_type, $a_id)
3452  {
3453  global $ilDB;
3454 
3455  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3456  "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3457  "type = ".$ilDB->quote($a_type, "text");
3458  $user_set = $ilDB->query($q);
3459  $users = array();
3460  while ($user_rec = $ilDB->fetchAssoc($user_set))
3461  {
3462  $users[] = $user_rec["user_id"];
3463  }
3464 
3465  return $users;
3466  }
3467 
3475  function removeObjectFromClipboard($a_item_id, $a_type)
3476  {
3477  global $ilDB;
3478 
3479  $q = "DELETE FROM personal_clipboard WHERE ".
3480  "item_id = ".$ilDB->quote($a_item_id, "integer").
3481  " AND type = ".$ilDB->quote($a_type, "text")." ".
3482  " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3483  $ilDB->manipulate($q);
3484  }
3485 
3486  function _getImportedUserId($i2_id)
3487  {
3488  global $ilDB;
3489 
3490  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3491  $ilDB->quote($i2_id, "text");
3492 
3493  $res = $ilDB->query($query);
3494  while($row = $ilDB->fetchObject($res))
3495  {
3496  $id = $row->obj_id;
3497  }
3498  return $id ? $id : 0;
3499  }
3500 
3501 /*
3502 
3503  function setiLincData($a_id,$a_login,$a_passwd)
3504  {
3505  $this->ilinc_id = $a_id;
3506  $this->ilinc_login = $a_login;
3507  $this->ilinc_passwd = $a_passwd;
3508  }
3509 
3510 */
3511 
3512 /*
3513 
3514  function getiLincData()
3515  {
3516  return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
3517  }
3518 */
3523  function setAuthMode($a_str)
3524  {
3525  $this->auth_mode = $a_str;
3526  }
3527 
3532  function getAuthMode($a_auth_key = false)
3533  {
3534  if (!$a_auth_key)
3535  {
3536  return $this->auth_mode;
3537  }
3538 
3539  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3540  return ilAuthUtils::_getAuthMode($this->auth_mode);
3541  }
3542 
3550  function setExternalAccount($a_str)
3551  {
3552  $this->ext_account = $a_str;
3553  }
3554 
3563  {
3564  return $this->ext_account;
3565  }
3566 
3578  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3579  {
3580  global $ilDB,$ilSetting;
3581 
3582  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3583  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3584  "WHERE auth_mode = %s";
3585  $types[] = "text";
3586  $values[] = $a_auth_mode;
3587  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3588  {
3589  $q.= " OR auth_mode = %s ";
3590  $types[] = "text";
3591  $values[] = 'default';
3592  }
3593 
3594  $res = $ilDB->queryF($q, $types, $values);
3595  while ($row = $ilDB->fetchObject($res))
3596  {
3597  if($row->auth_mode == 'default')
3598  {
3599  $accounts[$row->usr_id] = $row->login;
3600  }
3601  else
3602  {
3603  $accounts[$row->usr_id] = $row->ext_account;
3604  }
3605  }
3606  return $accounts ? $accounts : array();
3607  }
3608 
3616  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3617  {
3618  global $ilDB;
3619 
3620  if(!is_array($a_usr_ids))
3621  {
3622  return false;
3623  }
3624  $q = "UPDATE usr_data SET active = %s WHERE ".
3625  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3626  $ilDB->manipulateF($q, array("integer"), array(($a_status ? 1 : 0)));
3627 
3628  return true;
3629  }
3630 
3631 
3640  public static function _lookupAuthMode($a_usr_id)
3641  {
3642  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3643  }
3644 
3651  public static function _checkExternalAuthAccount($a_auth, $a_account)
3652  {
3653  global $ilDB,$ilSetting;
3654 
3655  // Check directly with auth_mode
3656  $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3657  " ext_account = %s AND auth_mode = %s",
3658  array("text", "text"),
3659  array($a_account, $a_auth));
3660  if ($usr = $ilDB->fetchAssoc($r))
3661  {
3662  return $usr["login"];
3663  }
3664 
3665  // For compatibility, check for login (no ext_account entry given)
3666  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3667  "WHERE login = %s AND auth_mode = %s",
3668  array("text", "text"),
3669  array($a_account, $a_auth));
3670  if($usr = $ilDB->fetchAssoc($res))
3671  {
3672  return $usr['login'];
3673  }
3674 
3675  // If auth_default == $a_auth => check for login
3676  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3677  {
3678  $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3679  " ext_account = %s AND auth_mode = %s",
3680  array("text", "text"),
3681  array($a_account, "default"));
3682  if ($usr = $ilDB->fetchAssoc($res))
3683  {
3684  return $usr["login"];
3685  }
3686  // Search for login (no ext_account given)
3687  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3688  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3689  array("text", "text"),
3690  array($a_account, "default"));
3691  if($usr = $ilDB->fetchAssoc($res))
3692  {
3693  return $usr["login"];
3694  }
3695  }
3696  return false;
3697  }
3698 
3703  {
3704  global $ilDB;
3705 
3706  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3707  "GROUP BY auth_mode");
3708  $cnt_arr = array();
3709  while($cnt = $ilDB->fetchAssoc($r))
3710  {
3711  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3712  }
3713 
3714  return $cnt_arr;
3715  }
3716 
3722  function _getLocalAccountsForEmail($a_email)
3723  {
3724  global $ilDB, $ilSetting;
3725 
3726  // default set to local (1)?
3727 
3728  $q = "SELECT * FROM usr_data WHERE ".
3729  " email = %s AND (auth_mode = %s ";
3730  $types = array("text", "text");
3731  $values = array($a_email, "local");
3732 
3733  if ($ilSetting->get("auth_mode") == 1)
3734  {
3735  $q.=" OR auth_mode = %s";
3736  $types[] = "text";
3737  $values[] = "default";
3738  }
3739 
3740  $q.= ")";
3741 
3742  $users = array();
3743  $usr_set = $ilDB->queryF($q, $types, $values);
3744  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3745  {
3746  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3747  }
3748 
3749  return $users;
3750  }
3751 
3752 
3760  function _uploadPersonalPicture($tmp_file, $obj_id)
3761  {
3762  $webspace_dir = ilUtil::getWebspaceDir();
3763  $image_dir = $webspace_dir."/usr_images";
3764  $store_file = "usr_".$obj_id."."."jpg";
3765  $target_file = $image_dir."/$store_file";
3766 
3767  chmod($tmp_file, 0770);
3768 
3769  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3770  // taking only frame [0] to avoid problems with animated gifs
3771  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3772  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3773  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3774  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3775 
3776  system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 200x200 -quality 100 JPEG:$show_file");
3777  system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 100x100 -quality 100 JPEG:$thumb_file");
3778  system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 75x75 -quality 100 JPEG:$xthumb_file");
3779  system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 30x30 -quality 100 JPEG:$xxthumb_file");
3780 
3781  // store filename
3782  ilObjUser::_writePref($obj_id, "profile_image", $store_file);
3783 
3784  return TRUE;
3785  }
3786 
3792  function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3793  {
3794  return ilObjUser::_getPersonalPicturePath($this->getId(),$a_size,$a_force_pic);
3795  }
3796 
3803  function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3804  $a_prevent_no_photo_image = false)
3805  {
3806  global $ilDB;
3807 
3808  // BEGIN DiskQuota: Fetch all user preferences in a single query
3809  $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3810  "keyword IN (%s,%s) ".
3811  "AND usr_id = %s",
3812  array("text", "text", "integer"),
3813  array('public_upload', 'public_profile', $a_usr_id));
3814  while ($row = $ilDB->fetchAssoc($res))
3815  {
3816  switch ($row['keyword'])
3817  {
3818  case 'public_upload' :
3819  $upload = $row['value'] == 'y';
3820  break;
3821  case 'public_profile' :
3822  $profile = ($row['value'] == 'y' ||
3823  $row['value'] == 'g');
3824  break;
3825  }
3826  }
3827 
3828  // END DiskQuota: Fetch all user preferences in a single query
3829 
3830  if(defined('ILIAS_MODULE'))
3831  {
3832  $webspace_dir = ('.'.$webspace_dir);
3833  }
3834  $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
3835 
3836  $image_dir = $webspace_dir."/usr_images";
3837  // BEGIN DiskQuota: Support 'big' user images
3838  if ($a_size == 'big')
3839  {
3840  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3841  }
3842  else
3843  {
3844  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3845  }
3846  // END DiskQuota: Support 'big' user images
3847 
3848  if((($upload && $profile) || $a_force_pic)
3849  && @is_file($thumb_file))
3850  {
3851  $file = $thumb_file."?t=".rand(1, 99999);
3852  }
3853  else
3854  {
3855  if (!$a_prevent_no_photo_image)
3856  {
3857  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
3858  }
3859  }
3860 
3861  return $file;
3862  }
3863 
3868  {
3869  $webspace_dir = ilUtil::getWebspaceDir();
3870  $image_dir = $webspace_dir."/usr_images";
3871  $file = $image_dir."/usr_".$this->getID()."."."jpg";
3872  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
3873  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
3874  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
3875  $upload_file = $image_dir."/upload_".$this->getID();
3876 
3877  // remove user pref file name
3878  $this->setPref("profile_image", "");
3879  $this->update();
3880 
3881  if (@is_file($file))
3882  {
3883  unlink($file);
3884  }
3885  if (@is_file($thumb_file))
3886  {
3887  unlink($thumb_file);
3888  }
3889  if (@is_file($xthumb_file))
3890  {
3891  unlink($xthumb_file);
3892  }
3893  if (@is_file($xxthumb_file))
3894  {
3895  unlink($xxthumb_file);
3896  }
3897  if (@is_file($upload_file))
3898  {
3899  unlink($upload_file);
3900  }
3901  }
3902 
3903 
3904  function setUserDefinedData($a_data)
3905  {
3906  if(!is_array($a_data))
3907  {
3908  return false;
3909  }
3910  foreach($a_data as $field => $data)
3911  {
3912  #$new_data[$field] = ilUtil::stripSlashes($data);
3913  // Assign it directly to avoid update problems of unchangable fields
3914  $this->user_defined_data['f_'.$field] = $data;
3915  }
3916  #$this->user_defined_data = $new_data;
3917 
3918  return true;
3919  }
3920 
3922  {
3923  return $this->user_defined_data ? $this->user_defined_data : array();
3924  }
3925 
3927  {
3928  global $ilDB;
3929 
3930  $fields = '';
3931 
3932  $field_def = array();
3933 
3934  include_once("./Services/User/classes/class.ilUserDefinedData.php");
3935  $udata = new ilUserDefinedData($this->getId());
3936 
3937  foreach($this->user_defined_data as $field => $value)
3938  {
3939  if($field != 'usr_id')
3940  {
3941 // $field_def[$field] = array('text',$value);
3942  $udata->set($field, $value);
3943  }
3944  }
3945  $udata->update();
3946 
3947 /* if(!$field_def)
3948  {
3949  return true;
3950  }
3951 
3952  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
3953  $res = $ilDB->query($query);
3954 
3955 
3956  if($res->numRows())
3957  {
3958  // Update
3959  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
3960  }
3961  else
3962  {
3963  $field_def['usr_id'] = array('integer',$this->getId());
3964  $ilDB->insert('udf_data',$field_def);
3965  }
3966 */
3967  return true;
3968  }
3969 
3971  {
3972  global $ilDB;
3973 
3974  include_once("./Services/User/classes/class.ilUserDefinedData.php");
3975  $udata = new ilUserDefinedData($this->getId());
3976 
3977 /* $query = "SELECT * FROM udf_data ".
3978  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
3979 
3980  $res = $this->db->query($query);
3981  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
3982  {
3983  $this->user_defined_data = $row;
3984  }*/
3985 
3986  $this->user_defined_data = $udata->getAll();
3987 
3988  return true;
3989  }
3990 
3992  {
3993  global $ilDB;
3994 
3995 // not needed. no entry in udf_text/udf_clob means no value
3996 
3997 /* $query = "INSERT INTO udf_data (usr_id ) ".
3998  "VALUES( ".
3999  $ilDB->quote($this->getId(),'integer').
4000  ")";
4001  $res = $ilDB->manipulate($query);
4002 */
4003  return true;
4004  }
4005 
4007  {
4008  global $ilDB;
4009 
4010  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4012 
4013  // wrong place...
4014 /* $query = "DELETE FROM udf_data ".
4015  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4016  $res = $ilDB->manipulate($query);*/
4017 
4018  return true;
4019  }
4020 
4026  function getProfileAsString(&$a_language)
4027  {
4028  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4029  include_once 'classes/class.ilFormat.php';
4030 
4031  global $lng,$rbacreview;
4032 
4033  $language =& $a_language;
4034  $language->loadLanguageModule('registration');
4035  $language->loadLanguageModule('crs');
4036 
4037  $body = '';
4038  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4039 
4040  if(strlen($this->getUTitle()))
4041  {
4042  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4043  }
4044  if(strlen($this->getGender()))
4045  {
4046  $gender = ($this->getGender() == 'm') ?
4047  $language->txt('gender_m') :
4048  $language->txt('gender_f');
4049  $body .= ($language->txt("gender").": ".$gender."\n");
4050  }
4051  if(strlen($this->getFirstname()))
4052  {
4053  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4054  }
4055  if(strlen($this->getLastname()))
4056  {
4057  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4058  }
4059  if(strlen($this->getInstitution()))
4060  {
4061  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4062  }
4063  if(strlen($this->getDepartment()))
4064  {
4065  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4066  }
4067  if(strlen($this->getStreet()))
4068  {
4069  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4070  }
4071  if(strlen($this->getCity()))
4072  {
4073  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4074  }
4075  if(strlen($this->getZipcode()))
4076  {
4077  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4078  }
4079  if(strlen($this->getCountry()))
4080  {
4081  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4082  }
4083  if(strlen($this->getPhoneOffice()))
4084  {
4085  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4086  }
4087  if(strlen($this->getPhoneHome()))
4088  {
4089  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4090  }
4091  if(strlen($this->getPhoneMobile()))
4092  {
4093  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4094  }
4095  if(strlen($this->getFax()))
4096  {
4097  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4098  }
4099  if(strlen($this->getEmail()))
4100  {
4101  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4102  }
4103  if(strlen($this->getHobby()))
4104  {
4105  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4106  }
4107  if(strlen($this->getComment()))
4108  {
4109  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4110  }
4111  if(strlen($this->getMatriculation()))
4112  {
4113  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4114  }
4115  if(strlen($this->getCreateDate()))
4116  {
4121 
4122  $body .= ($language->txt("create_date").": ".$date."\n");
4123  }
4124 
4125  foreach($rbacreview->getGlobalRoles() as $role)
4126  {
4127  if($rbacreview->isAssigned($this->getId(),$role))
4128  {
4129  $gr[] = ilObjRole::_lookupTitle($role);
4130  }
4131  }
4132  if(count($gr))
4133  {
4134  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4135  }
4136 
4137  // Time limit
4138  if($this->getTimeLimitUnlimited())
4139  {
4140  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4141  }
4142  else
4143  {
4147  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4149 
4150  $body .= $language->txt('time_limit').': '.$period;
4151  /*
4152  $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4153  ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4154  $language->txt('crs_to')." ".
4155  ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4156  */
4157  }
4158  return $body;
4159  }
4160 
4161  function setInstantMessengerId($a_im_type, $a_im_id)
4162  {
4163  $var = "im_".$a_im_type;
4164  $this->$var = $a_im_id;
4165  }
4166 
4167  function getInstantMessengerId($a_im_type)
4168  {
4169  $var = "im_".$a_im_type;
4170  return $this->$var;
4171  }
4172 
4173  function setDelicious($a_delicious)
4174  {
4175  $this->delicious = $a_delicious;
4176  }
4177 
4178  function getDelicious()
4179  {
4180  return $this->delicious;
4181  }
4182 
4186  function _lookupFeedHash($a_user_id, $a_create = false)
4187  {
4188  global $ilDB;
4189 
4190  if ($a_user_id > 0)
4191  {
4192  $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4193  array("integer"), array($a_user_id));
4194  if ($rec = $ilDB->fetchAssoc($set))
4195  {
4196  if (strlen($rec["feed_hash"]) == 32)
4197  {
4198  return $rec["feed_hash"];
4199  }
4200  else if($a_create)
4201  {
4202  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4203  $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4204  " WHERE usr_id = %s",
4205  array("text", "integer"),
4206  array($hash, $a_user_id));
4207  return $hash;
4208  }
4209  }
4210  }
4211 
4212  return false;
4213  }
4214 
4220  function _getFeedPass($a_user_id)
4221  {
4222  global $ilDB;
4223 
4224  if ($a_user_id > 0)
4225  {
4226  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4227  }
4228  return false;
4229  }
4230 
4236  function _setFeedPass($a_user_id, $a_password)
4237  {
4238  global $ilDB;
4239 
4240  ilObjUser::_writePref($a_user_id, "priv_feed_pass",
4241  ($a_password=="") ? "" : md5($a_password));
4242  }
4243 
4253  public static function _loginExists($a_login,$a_user_id = 0)
4254  {
4255  global $ilDB;
4256 
4257  $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4258  "WHERE login = %s";
4259  $types[] = "text";
4260  $values[] = $a_login;
4261 
4262  if ($a_user_id != 0)
4263  {
4264  $q.= " AND usr_id != %s ";
4265  $types[] = "integer";
4266  $values[] = $a_user_id;
4267  }
4268 
4269  $r = $ilDB->queryF($q, $types, $values);
4270 
4271  if ($row = $ilDB->fetchAssoc($r))
4272  {
4273  return $row['usr_id'];
4274  }
4275  return false;
4276  }
4277 
4288  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4289  {
4290  global $ilDB;
4291 
4292  $res = $ilDB->queryF("SELECT * FROM usr_data ".
4293  "WHERE ext_account = %s AND auth_mode = %s",
4294  array("text", "text"),
4295  array($a_external_account, $a_auth_mode));
4296  return $ilDB->fetchAssoc($res) ? true :false;
4297  }
4298 
4306  public static function _getUsersForRole($role_id, $active = -1) {
4307  global $ilDB, $rbacreview;
4308  $data = array();
4309 
4310  $ids = $rbacreview->assignedUsers($role_id);
4311 
4312  if (count ($ids) == 0)
4313  {
4314  $ids = array (-1);
4315  }
4316 
4317  $query = "SELECT usr_data.*, usr_pref.value AS language
4318  FROM usr_data
4319  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4320  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4321  $values[] = "language";
4322  $types[] = "text";
4323 
4324 
4325  if (is_numeric($active) && $active > -1)
4326  {
4327  $query .= " AND usr_data.active = %s";
4328  $values[] = $active;
4329  $types[] = "integer";
4330  }
4331 
4332  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4333 
4334  $r = $ilDB->queryF($query, $types, $values);
4335  $data = array();
4336  while ($row = $ilDB->fetchAssoc($r))
4337  {
4338  $data[] = $row;
4339  }
4340  return $data;
4341  }
4342 
4343 
4349  public static function _getUsersForFolder ($ref_id, $active) {
4350  global $ilDB;
4351  $data = array();
4352  $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 ";
4353  $types[] = "text";
4354  $values[] = "language";
4355 
4356  if (is_numeric($active) && $active > -1)
4357  {
4358  $query .= " AND usr_data.active = %s";
4359  $values[] = $active;
4360  $types[] = "integer";
4361  }
4362 
4363  if ($ref_id != USER_FOLDER_ID)
4364  {
4365  $query.= " AND usr_data.time_limit_owner = %s";
4366  $values[] = $ref_id;
4367  $types[] = "integer";
4368  }
4369 
4370  $query .= " AND usr_data.usr_id != %s ";
4371  $values[] = ANONYMOUS_USER_ID;
4372  $types[] = "integer";
4373 
4374  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4375 
4376  $result = $ilDB->queryF($query, $types, $values);
4377  $data = array();
4378  while ($row = $ilDB->fetchAssoc($result))
4379  {
4380  array_push($data, $row);
4381  }
4382 
4383  return $data;
4384  }
4385 
4386 
4392  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4393  {
4394  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4395  }
4396 
4397 
4403  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4404  {
4405  global $rbacadmin, $rbacreview, $ilDB;
4406 
4407  // quote all ids
4408  $ids = array();
4409  foreach ($a_mem_ids as $mem_id) {
4410  $ids [] = $ilDB->quote($mem_id);
4411  }
4412 
4413  $query = "SELECT usr_data.*, usr_pref.value AS language
4414  FROM usr_data
4415  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4416  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer")."
4417  AND usr_data.usr_id != %s";
4418  $values[] = "language";
4419  $types[] = "text";
4420  $values[] = ANONYMOUS_USER_ID;
4421  $types[] = "integer";
4422 
4423  if (is_numeric($active) && $active > -1)
4424  {
4425  $query .= " AND active = %s";
4426  $values[] = $active;
4427  $types[] = "integer";
4428  }
4429 
4430  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4431  {
4432  $query.= " AND usr_data.time_limit_owner = %s";
4433  $values[] = $timelimitowner;
4434  $types[] = "integer";
4435 
4436  }
4437 
4438  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4439 
4440  $result = $ilDB->queryF($query, $types, $values);
4441  while ($row = $ilDB->fetchAssoc($result))
4442  {
4443  $mem_arr[] = $row;
4444  }
4445 
4446  return $mem_arr ? $mem_arr : array();
4447  }
4448 
4449 
4450 
4456  public static function _getUserData ($a_internalids) {
4457  global $ilDB;
4458 
4459  $ids = array();
4460  if (is_array($a_internalids)) {
4461  foreach ($a_internalids as $internalid) {
4462  if (is_numeric ($internalid))
4463  {
4464  $ids[] = $internalid;
4465  }
4466  else
4467  {
4468  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4469  if (is_numeric($parsedid) && $parsedid > 0)
4470  {
4471  $ids[] = $parsedid;
4472  }
4473  }
4474  }
4475  }
4476  if (count($ids) == 0)
4477  $ids [] = -1;
4478 
4479  $query = "SELECT usr_data.*, usr_pref.value AS language
4480  FROM usr_data
4481  LEFT JOIN usr_pref
4482  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4483  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4484  $values[] = "language";
4485  $types[] = "text";
4486 
4487  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4488 
4489  $data = array();
4490  $result = $ilDB->queryF($query, $types, $values);
4491  while ($row = $ilDB->fetchAssoc($result))
4492  {
4493  $data[] = $row;
4494  }
4495  return $data;
4496  }
4497 
4504  public static function _getPreferences ($user_id)
4505  {
4506  global $ilDB;
4507 
4508  $prefs = array();
4509 
4510  $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4511  array("integer"), array($user_id));
4512 
4513  while($row = $ilDB->fetchAssoc($r))
4514  {
4515  $prefs[$row["keyword"]] = $row["value"];
4516  }
4517 
4518  return $prefs;
4519  }
4520 
4521 
4522  public static function _resetLoginAttempts($a_usr_id)
4523  {
4524  global $ilDB;
4525 
4526  $query = "UPDATE usr_data SET usr_data.login_attempts = 0 WHERE usr_data.usr_id = %s";
4527  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4528 
4529  if($affected) return true;
4530  else return false;
4531  }
4532 
4533  public static function _getLoginAttempts($a_usr_id)
4534  {
4535  global $ilDB;
4536 
4537  $query = "SELECT usr_data.login_attempts FROM usr_data WHERE usr_data.usr_id = %s";
4538  $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4539  $record = $ilDB->fetchAssoc( $result );
4540  $login_attempts = $record['login_attempts'];
4541 
4542  return $login_attempts;
4543  }
4544 
4545  public static function _incrementLoginAttempts($a_usr_id)
4546  {
4547  global $ilDB;
4548 
4549  $query = "UPDATE usr_data SET usr_data.login_attempts = (usr_data.login_attempts + 1) WHERE usr_data.usr_id = %s";
4550  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4551 
4552  if($affected) return true;
4553  else return false;
4554  }
4555 
4556  public static function _setUserInactive($a_usr_id)
4557  {
4558  global $ilDB;
4559 
4560  $query = "UPDATE usr_data SET usr_data.active = 0 WHERE usr_data.usr_id = %s";
4561  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4562 
4563  if($affected) return true;
4564  else return false;
4565  }
4566 
4572  public function hasPublicProfile() {
4573  return in_array($this->getPref("public_profile"), array("y", "g"));
4574  }
4575 
4581  public function getPublicName()
4582  {
4583  if ($this->hasPublicProfile())
4584  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4585  else
4586  return $this->getLogin();
4587 
4588  }
4589 
4590  public static function _writeHistory($a_usr_id, $a_login)
4591  {
4592  global $ilDB;
4593 
4594  $timestamp = time();
4595 
4596  $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4597  array('integer', 'text', 'integer'),
4598  array($a_usr_id, $a_login, $timestamp));
4599 
4600  if( $ilDB->numRows($res) == 0 )
4601  {
4602  $ilDB->manipulateF('
4603  INSERT INTO loginname_history
4604  (usr_id, login, history_date)
4605  VALUES (%s, %s, %s)',
4606  array('integer', 'text', 'integer'),
4607  array($a_usr_id, $a_login, $timestamp));
4608  }
4609 
4610  return true;
4611  }
4612 
4620  function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4621  {
4622  global $ilDB;
4623 
4624  $pd_set = new ilSetting("pd");
4625  $atime = $pd_set->get("user_activity_time") * 60;
4626  $ctime = time();
4627 
4628  if ($a_user_id == 0)
4629  {
4630  $where = "WHERE user_id != 0 AND NOT agree_date IS NULL ";
4631  $type_array = array("integer");
4632  $val_array = array(time());
4633  }
4634  else
4635  {
4636  $where = "WHERE user_id = %s ";
4637  $type_array = array("integer", "integer");
4638  $val_array = array($a_user_id, time());
4639  }
4640 
4641  $no_anonym = ($a_no_anonymous)
4642  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4643  : "";
4644 
4645  $r = $ilDB->queryF("SELECT count(user_id) as num,user_id,firstname,lastname,title,login,last_login,max(ctime) AS ctime ".
4646  "FROM usr_session ".
4647  "LEFT JOIN usr_data u ON user_id = u.usr_id ".
4648  "LEFT JOIN usr_pref p ON (p.usr_id = u.usr_id AND p.keyword = ".
4649  $ilDB->quote("hide_own_online_status", "text").") ".$where.
4650  "AND expires > %s ".
4651  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4652  $no_anonym.
4653  "GROUP BY user_id,firstname,lastname,title,login,last_login ".
4654  "ORDER BY lastname, firstname", $type_array, $val_array);
4655 
4656  while ($user = $ilDB->fetchAssoc($r))
4657  {
4658  if ($atime <= 0
4659  || $user["ctime"] + $atime > $ctime)
4660  {
4661  $users[$user["user_id"]] = $user;
4662  }
4663  }
4664 
4665  return $users ? $users : array();
4666  }
4667 
4676  function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4677  {
4678  global $ilias, $ilDB;
4679 
4680  $pd_set = new ilSetting("pd");
4681  $atime = $pd_set->get("user_activity_time") * 60;
4682  $ctime = time();
4683  $no_anonym = ($a_no_anonymous)
4684  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4685  : "";
4686 
4687  // Get a list of object id's of all courses and groups for which
4688  // the current user has local roles.
4689  // Note: we have to use DISTINCT here, because a user may assume
4690  // multiple roles in a group or a course.
4691  $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4692  "FROM rbac_ua ua ".
4693  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4694  "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4695  "JOIN tree ON tree.child = r1.ref_id ".
4696  "JOIN object_reference r2 ON r2.ref_id = tree.parent ".
4697  "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4698  "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4699  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4700  "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4701  $ilDB->quote("grp", "text").")";
4702  $r = $ilDB->query($q);
4703 
4704  while ($row = $ilDB->fetchAssoc($r))
4705  {
4706  $groups_and_courses_of_user[] = $row["obj_id"];
4707  }
4708  // If the user is not in a course or a group, he has no associated users.
4709  if (count($groups_and_courses_of_user) == 0)
4710  {
4711  $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4712  "FROM usr_session ".
4713  "JOIN usr_data ON user_id=usr_id ".
4714  "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4715  $no_anonym.
4716  " AND NOT agree_date IS NULL ".
4717  "AND expires > ".$ilDB->quote(time(), "integer")." ".
4718  "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4719  $r = $ilDB->query($q);
4720  }
4721  else
4722  {
4723  $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4724  "FROM usr_session s ".
4725  "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4726  "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
4727  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4728  "JOIN tree ON tree.child = fa.parent ".
4729  "JOIN object_reference or1 ON or1.ref_id = tree.parent ".
4730  "JOIN object_data od ON od.obj_id = or1.obj_id ".
4731  "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
4732  $ilDB->quote("hide_own_online_status", "text").") ".
4733  "WHERE s.user_id != 0 ".
4734  $no_anonym.
4735  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4736  "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
4737  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4738  " AND NOT ud.agree_date IS NULL ".
4739  "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
4740  "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4741  "ORDER BY ud.lastname, ud.firstname";
4742  $r = $ilDB->query($q);
4743  }
4744 
4745  while ($user = $ilDB->fetchAssoc($r))
4746  {
4747  if ($atime <= 0
4748  || $user["ctime"] + $atime > $ctime)
4749  {
4750  $users[$user["user_id"]] = $user;
4751  }
4752  }
4753 
4754  return $users ? $users : array();
4755  }
4756 
4763  public static function _generateRegistrationHash($a_usr_id)
4764  {
4765  global $ilDB;
4766 
4767  do
4768  {
4769  $continue = false;
4770 
4771  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
4772 
4773  $res = $ilDB->queryf('
4774  SELECT COUNT(usr_id) cnt FROM usr_data
4775  WHERE reg_hash = %s',
4776  array('text'),
4777  array($hashcode));
4778  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
4779  {
4780  if($row->cnt > 0) $continue = true;
4781  break;
4782  }
4783 
4784  if($continue) continue;
4785 
4786  $ilDB->manipulateF('
4787  UPDATE usr_data
4788  SET reg_hash = %s
4789  WHERE usr_id = %s',
4790  array('text', 'integer'),
4791  array($hashcode, (int)$a_usr_id)
4792  );
4793 
4794  break;
4795 
4796  } while(true);
4797 
4798  return $hashcode;
4799  }
4800 
4809  public static function _verifyRegistrationHash($a_hash)
4810  {
4811  global $ilDB;
4812 
4813  $res = $ilDB->queryf('
4814  SELECT usr_id, create_date FROM usr_data
4815  WHERE reg_hash = %s',
4816  array('text'),
4817  array($a_hash));
4818  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
4819  {
4820  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
4821  $oRegSettigs = new ilRegistrationSettings();
4822 
4823  if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
4824  time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row->create_date))
4825  {
4826  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
4827  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired');
4828  }
4829 
4830  $ilDB->manipulateF('
4831  UPDATE usr_data
4832  SET reg_hash = %s
4833  WHERE usr_id = %s',
4834  array('text', 'integer'),
4835  array('', (int)$row->usr_id)
4836  );
4837 
4838  return $row->usr_id;
4839  }
4840 
4841  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
4842  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
4843  }
4844 
4845  function setBirthday($a_birthday)
4846  {
4847  if (strlen($a_birthday))
4848  {
4849  $date = new ilDate($a_birthday, IL_CAL_DATE);
4850  $this->birthday = $date->get(IL_CAL_DATE);
4851  }
4852  else
4853  {
4854  $this->birthday = null;
4855  }
4856  }
4857 
4858  function getBirthday()
4859  {
4860  return $this->birthday;
4861  }
4862 } // END class ilObjUser
4863 ?>