ILIAS  release_4-3 Revision
 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 "./Services/Object/classes/class.ilObject.php";
10 require_once './Services/User/exceptions/class.ilUserException.php';
11 
24 class ilObjUser extends ilObject
25 {
30  // personal data
31 
32  var $login; // username in system
33 
34  var $passwd; // password encoded in the format specified by $passwd_type
36  // specifies the password format.
37  // value: IL_PASSWD_PLAIN, IL_PASSWD_MD5 or IL_PASSWD_CRYPT.
38 
39  // Differences between password format in class ilObjUser and
40  // in table usr_data:
41  // Class ilObjUser supports three different password types
42  // (plain, MD5 and CRYPT) and it uses the variables $passwd
43  // and $passwd_type to store them.
44  // Table usr_data supports only two different password types
45  // (MD5 and CRYPT) and it uses the columns "passwd" and
46  // "il2passwd" to store them.
47  // The conversion between these two storage layouts is done
48  // in the methods that perform SQL statements. All other
49  // methods work exclusively with the $passwd and $passwd_type
50  // variables.
51 
52  var $gender; // 'm' or 'f'
53  var $utitle; // user title (keep in mind, that we derive $title from object also!)
55  var $lastname;
56  protected $birthday;
57  var $fullname; // title + firstname + lastname in one string
58  //var $archive_dir = "./image"; // point to image file (should be flexible)
59  // address data
62  var $street;
63  var $city;
64  var $zipcode;
65  var $country;
70  var $fax;
71  var $email;
72  var $hobby;
75  var $approve_date = null;
76  var $agree_date = null;
77  var $active;
78  //var $ilinc_id; // unique Id for netucate ilinc service
79  var $client_ip; // client ip to check before login
80  var $auth_mode; // authentication mode
81 
82  var $im_icq;
83  var $im_yahoo;
84  var $im_msn;
85  var $im_aim;
86  var $im_skype;
88  var $im_voip;
89 
91  var $latitude;
93  var $loc_zoom;
94 
97 
98  var $user_defined_data = array();
99 
105  var $prefs;
106 
112  var $skin;
113 
114 
121 
127  var $ilias;
128 
131 
135  protected static $personal_image_cache = array();
136 
142  protected $inactivation_date = null;
143 
148  private $is_self_registered = false;
149 
155  function ilObjUser($a_user_id = 0, $a_call_by_reference = false)
156  {
157  global $ilias,$ilDB;
158 
159  // init variables
160  $this->ilias =& $ilias;
161  $this->db =& $ilDB;
162 
163  $this->type = "usr";
164  $this->ilObject($a_user_id, $a_call_by_reference);
165  $this->auth_mode = "default";
166  $this->passwd_type = IL_PASSWD_PLAIN;
167 
168  // for gender selection. don't change this
169  /*$this->gender = array(
170  'm' => "salutation_m",
171  'f' => "salutation_f"
172  );*/
173  if ($a_user_id > 0)
174  {
175  $this->setId($a_user_id);
176  $this->read();
177  }
178  else
179  {
180  // TODO: all code in else-structure doesn't belongs in class user !!!
181  //load default data
182  $this->prefs = array();
183  //language
184  $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
185 
186  //skin and pda support
187  $this->skin = $this->ilias->ini->readVariable("layout","skin");
188 
189  $this->prefs["skin"] = $this->skin;
190  $this->prefs["show_users_online"] = "y";
191 
192  //style (css)
193  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
194  }
195  }
196 
201  function read()
202  {
203  global $ilErr, $ilDB;
204 
205  // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
206  // use (3.11.0 alpha)
207  /*$q = "SELECT * FROM usr_data ".
208  "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
209  "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
210  $r = $ilDB->queryF("SELECT * FROM usr_data ".
211  "WHERE usr_id= %s", array("integer"), array($this->id));
212 
213  if ($data = $ilDB->fetchAssoc($r))
214  {
215  // convert password storage layout used by table usr_data into
216  // storage layout used by class ilObjUser
217  if ($data["passwd"] == "" && $data["i2passwd"] != "")
218  {
219  $data["passwd_type"] = IL_PASSWD_CRYPT;
220  $data["passwd"] = $data["i2passwd"];
221  }
222  else
223  {
224  $data["passwd_type"] = IL_PASSWD_MD5;
225  //$data["passwd"] = $data["passwd"]; (implicit)
226  }
227  unset($data["i2passw"]);
228 
229  // this assign must not be set via $this->assignData($data)
230  // because this method will be called on profile updates and
231  // would set this values to 0, because they arent posted from form
232  $this->setLastPasswordChangeTS( $data['last_password_change'] );
233  $this->setLoginAttempts( $data['login_attempts'] );
234 
235 
236  // fill member vars in one shot
237  $this->assignData($data);
238 
239  //get userpreferences from usr_pref table
240  $this->readPrefs();
241 
242  //set language to default if not set
243  if ($this->prefs["language"] == "")
244  {
245  $this->prefs["language"] = $this->oldPrefs["language"];
246  }
247 
248  //check skin-setting
249  include_once("./Services/Style/classes/class.ilStyleDefinition.php");
250  if ($this->prefs["skin"] == "" ||
251  !ilStyleDefinition::skinExists($this->prefs["skin"]))
252  {
253  $this->prefs["skin"] = $this->oldPrefs["skin"];
254  }
255 
256  $this->skin = $this->prefs["skin"];
257 
258  //check style-setting (skins could have more than one stylesheet
259  if ($this->prefs["style"] == "" ||
260  !ilStyleDefinition::skinExists($this->skin, $this->prefs["style"]))
261  {
262  //load default (css)
263  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
264  }
265 
266  if (empty($this->prefs["hits_per_page"]))
267  {
268  $this->prefs["hits_per_page"] = 10;
269  }
270 
271  }
272  else
273  {
274  $ilErr->raiseError("<b>Error: There is no dataset with id ".
275  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
276  "<br />Line: ".__LINE__, $ilErr->FATAL);
277  }
278 
279  $this->readUserDefinedFields();
280 
281  parent::read();
282  }
283 
289  function assignData($a_data)
290  {
291  global $ilErr, $ilDB, $lng;
292 
293  // basic personal data
294  $this->setLogin($a_data["login"]);
295  if (! $a_data["passwd_type"])
296  {
297  $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
298  $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
299  .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
300  }
301  if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
302  {
303  $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
304  }
305 
306  $this->setGender($a_data["gender"]);
307  $this->setUTitle($a_data["title"]);
308  $this->setFirstname($a_data["firstname"]);
309  $this->setLastname($a_data["lastname"]);
310  $this->setFullname();
311  if (!is_array($a_data['birthday']))
312  {
313  $this->setBirthday($a_data['birthday']);
314  }
315  else
316  {
317  $this->setBirthday(null);
318  }
319 
320  // address data
321  $this->setInstitution($a_data["institution"]);
322  $this->setDepartment($a_data["department"]);
323  $this->setStreet($a_data["street"]);
324  $this->setCity($a_data["city"]);
325  $this->setZipcode($a_data["zipcode"]);
326  $this->setCountry($a_data["country"]);
327  $this->setSelectedCountry($a_data["sel_country"]);
328  $this->setPhoneOffice($a_data["phone_office"]);
329  $this->setPhoneHome($a_data["phone_home"]);
330  $this->setPhoneMobile($a_data["phone_mobile"]);
331  $this->setFax($a_data["fax"]);
332  $this->setMatriculation($a_data["matriculation"]);
333  $this->setEmail($a_data["email"]);
334  $this->setHobby($a_data["hobby"]);
335  $this->setClientIP($a_data["client_ip"]);
336 
337  // instant messenger data
338  $this->setInstantMessengerId('icq',$a_data["im_icq"]);
339  $this->setInstantMessengerId('yahoo',$a_data["im_yahoo"]);
340  $this->setInstantMessengerId('msn',$a_data["im_msn"]);
341  $this->setInstantMessengerId('aim',$a_data["im_aim"]);
342  $this->setInstantMessengerId('skype',$a_data["im_skype"]);
343  $this->setInstantMessengerId('jabber',$a_data["im_jabber"]);
344  $this->setInstantMessengerId('voip',$a_data["im_voip"]);
345 
346  // other data
347  $this->setDelicious($a_data["delicious"]);
348  $this->setLatitude($a_data["latitude"]);
349  $this->setLongitude($a_data["longitude"]);
350  $this->setLocationZoom($a_data["loc_zoom"]);
351 
352  // system data
353  $this->setLastLogin($a_data["last_login"]);
354  $this->setLastUpdate($a_data["last_update"]);
355  $this->create_date = $a_data["create_date"];
356  $this->setComment($a_data["referral_comment"]);
357  $this->approve_date = $a_data["approve_date"];
358  $this->active = $a_data["active"];
359  $this->agree_date = $a_data["agree_date"];
360 
361  $this->setInactivationDate($a_data["inactivation_date"]);
362 
363  // time limitation
364  $this->setTimeLimitOwner($a_data["time_limit_owner"]);
365  $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
366  $this->setTimeLimitFrom($a_data["time_limit_from"]);
367  $this->setTimeLimitUntil($a_data["time_limit_until"]);
368  $this->setTimeLimitMessage($a_data['time_limit_message']);
369 
370  // user profile incomplete?
371  $this->setProfileIncomplete($a_data["profile_incomplete"]);
372 
373  //iLinc
374  //$this->setiLincData($a_data['ilinc_id'],$a_data['ilinc_login'],$a_data['ilinc_passwd']);
375 
376  //authentication
377  $this->setAuthMode($a_data['auth_mode']);
378  $this->setExternalAccount($a_data['ext_account']);
379 
380  $this->setIsSelfRegistered((bool)$a_data['is_self_registered']);
381  }
382 
389  function saveAsNew($a_from_formular = true)
390  {
391  global $ilErr, $ilDB, $ilSetting, $ilUser;
392 
393  switch ($this->passwd_type)
394  {
395  case IL_PASSWD_PLAIN:
396  $pw_field = "passwd";
397  if(strlen($this->passwd))
398  {
399  $pw_value = md5($this->passwd);
400  }
401  else
402  {
403  $pw_value = $this->passwd;
404  }
405  break;
406 
407  case IL_PASSWD_MD5:
408  $pw_field = "passwd";
409  $pw_value = $this->passwd;
410  break;
411 
412  case IL_PASSWD_CRYPT:
413  $pw_field = "i2passwd";
414  $pw_value = $this->passwd;
415  break;
416 
417  default :
418  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
419  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
420  "<br />Line: ".__LINE__, $ilErr->FATAL);
421  }
422 
423  if( !$this->active )
424  {
425  $this->setInactivationDate( ilUtil::now() );
426  }
427  else
428  {
429  $this->setInactivationDate(null);
430  }
431 
432  $insert_array = array(
433  "usr_id" => array("integer", $this->id),
434  "login" => array("text", $this->login),
435  $pw_field => array("text", $pw_value),
436  "firstname" => array("text", $this->firstname),
437  "lastname" => array("text", $this->lastname),
438  "title" => array("text", $this->utitle),
439  "gender" => array("text", $this->gender),
440  "email" => array("text", trim($this->email)),
441  "hobby" => array("text", (string) $this->hobby),
442  "institution" => array("text", $this->institution),
443  "department" => array("text", $this->department),
444  "street" => array("text", $this->street),
445  "city" => array("text", $this->city),
446  "zipcode" => array("text", $this->zipcode),
447  "country" => array("text", $this->country),
448  "sel_country" => array("text", $this->sel_country),
449  "phone_office" => array("text", $this->phone_office),
450  "phone_home" => array("text", $this->phone_home),
451  "phone_mobile" => array("text", $this->phone_mobile),
452  "fax" => array("text", $this->fax),
453  "birthday" => array('date', $this->getBirthday()),
454  "last_login" => array("timestamp", null),
455  "last_update" => array("timestamp", ilUtil::now()),
456  "create_date" => array("timestamp", ilUtil::now()),
457  "referral_comment" => array("text", $this->referral_comment),
458  "matriculation" => array("text", $this->matriculation),
459  "client_ip" => array("text", $this->client_ip),
460  "approve_date" => array("timestamp", $this->approve_date),
461  "agree_date" => array("timestamp", $this->agree_date),
462  "active" => array("integer", (int) $this->active),
463  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
464  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
465  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
466  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
467  "auth_mode" => array("text", $this->getAuthMode()),
468  "ext_account" => array("text", $this->getExternalAccount()),
469  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
470  "im_icq" => array("text", $this->im_icq),
471  "im_yahoo" => array("text", $this->im_yahoo),
472  "im_msn" => array("text", $this->im_msn),
473  "im_aim" => array("text", $this->im_aim),
474  "im_skype" => array("text", $this->im_skype),
475  "delicious" => array("text", $this->delicious),
476  "latitude" => array("text", $this->latitude),
477  "longitude" => array("text", $this->longitude),
478  "loc_zoom" => array("integer", (int) $this->loc_zoom),
479  "last_password_change" => array("integer", (int) $this->last_password_change_ts),
480  "im_jabber" => array("text", $this->im_jabber),
481  "im_voip" => array("text", $this->im_voip),
482  'inactivation_date' => array('timestamp', $this->inactivation_date),
483  'is_self_registered' => array('integer', (int)$this->is_self_registered)
484  );
485  $ilDB->insert("usr_data", $insert_array);
486 
487  // add new entry in usr_defined_data
488  $this->addUserDefinedFieldEntry();
489  // ... and update
490  $this->updateUserDefinedFields();
491 
492  // CREATE ENTRIES FOR MAIL BOX
493  include_once ("Services/Mail/classes/class.ilMailbox.php");
494  $mbox = new ilMailbox($this->id);
495  $mbox->createDefaultFolder();
496 
497  include_once "Services/Mail/classes/class.ilMailOptions.php";
498  $mail_options = new ilMailOptions($this->id);
499  $mail_options->createMailOptionsEntry();
500 
501  // create personal bookmark folder tree
502  include_once "./Services/Bookmarks/classes/class.ilBookmarkFolder.php";
503  $bmf = new ilBookmarkFolder(0, $this->id);
504  $bmf->createNewBookmarkTree();
505  }
506 
511  function update()
512  {
513  global $ilErr, $ilDB, $ilAppEventHandler;
514 
515  $this->syncActive();
516 
517  if( $this->getStoredActive($this->id) && !$this->active )
518  {
519  $this->setInactivationDate( ilUtil::now() );
520  }
521  else if($this->active)
522  {
523  $this->setInactivationDate(null);
524  }
525 
526  $update_array = array(
527  "gender" => array("text", $this->gender),
528  "title" => array("text", $this->utitle),
529  "firstname" => array("text", $this->firstname),
530  "lastname" => array("text", $this->lastname),
531  "email" => array("text", trim($this->email)),
532  "birthday" => array('date', $this->getBirthday()),
533  "hobby" => array("text", $this->hobby),
534  "institution" => array("text", $this->institution),
535  "department" => array("text", $this->department),
536  "street" => array("text", $this->street),
537  "city" => array("text", $this->city),
538  "zipcode" => array("text", $this->zipcode),
539  "country" => array("text", $this->country),
540  "sel_country" => array("text", $this->sel_country),
541  "phone_office" => array("text", $this->phone_office),
542  "phone_home" => array("text", $this->phone_home),
543  "phone_mobile" => array("text", $this->phone_mobile),
544  "fax" => array("text", $this->fax),
545  "referral_comment" => array("text", $this->referral_comment),
546  "matriculation" => array("text", $this->matriculation),
547  "client_ip" => array("text", $this->client_ip),
548  "approve_date" => array("timestamp", $this->approve_date),
549  "active" => array("integer", $this->active),
550  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
551  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
552  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
553  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
554  "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
555  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
556  "auth_mode" => array("text", $this->getAuthMode()),
557  "ext_account" => array("text", $this->getExternalAccount()),
558  "im_icq" => array("text", $this->im_icq),
559  "im_yahoo" => array("text", $this->im_yahoo),
560  "im_msn" => array("text", $this->im_msn),
561  "im_aim" => array("text", $this->im_aim),
562  "im_skype" => array("text", $this->im_skype),
563  "delicious" => array("text", $this->delicious),
564  "latitude" => array("text", $this->latitude),
565  "longitude" => array("text", $this->longitude),
566  "loc_zoom" => array("integer", (int) $this->loc_zoom),
567  "last_password_change" => array("integer", $this->last_password_change_ts),
568  "im_jabber" => array("text", $this->im_jabber),
569  "im_voip" => array("text", $this->im_voip),
570  "last_update" => array("timestamp", ilUtil::now()),
571  'inactivation_date' => array('timestamp', $this->inactivation_date)
572  );
573 
574  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null))
575  {
576  $update_array["agree_date"] = array("timestamp", $this->agree_date);
577  }
578  switch ($this->passwd_type)
579  {
580  case IL_PASSWD_PLAIN:
581  if(strlen($this->passwd))
582  {
583  $update_array["i2passwd"] = array("text", (string) "");
584  $update_array["passwd"] = array("text", (string) md5($this->passwd));
585  }
586  else
587  {
588  $update_array["i2passwd"] = array("text", (string) "");
589  $update_array["passwd"] = array("text", (string) $this->passwd);
590  }
591  break;
592 
593  case IL_PASSWD_MD5:
594  $update_array["i2passwd"] = array("text", (string) "");
595  $update_array["passwd"] = array("text", (string) $this->passwd);
596  break;
597 
598  case IL_PASSWD_CRYPT:
599  $update_array["i2passwd"] = array("text", (string) $this->passwd);
600  $update_array["passwd"] = array("text", (string) "");
601  break;
602 
603  default :
604  $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
605  get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
606  }
607 
608  $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
609 
610  $this->writePrefs();
611 
612  // update user defined fields
613  $this->updateUserDefinedFields();
614 
615  parent::update();
617 
618  $this->read();
619 
620  $ilAppEventHandler->raise("Services/User", "afterUpdate",
621  array("user_obj" => $this));
622 
623  return true;
624  }
625 
629  function writeAccepted()
630  {
631  global $ilDB;
632 
633  $ilDB->manipulateF("UPDATE usr_data SET agree_date = ".$ilDB->now().
634  " WHERE usr_id = %s", array("integer"), array($this->getId()));
635  }
636 
640  private function _lookup($a_user_id, $a_field)
641  {
642  global $ilDB;
643 
644  $res = $ilDB->queryF("SELECT ".$a_field." FROM usr_data WHERE usr_id = %s",
645  array("integer"), array($a_user_id));
646 
647  while($set = $ilDB->fetchAssoc($res))
648  {
649  return $set[$a_field];
650  }
651  return false;
652  }
653 
657  function _lookupFullname($a_user_id)
658  {
659  global $ilDB;
660 
661  $set = $ilDB->queryF("SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
662  array("integer"), array($a_user_id));
663 
664  if ($rec = $ilDB->fetchAssoc($set))
665  {
666  if ($rec["title"])
667  {
668  $fullname = $rec["title"]." ";
669  }
670  if ($rec["firstname"])
671  {
672  $fullname .= $rec["firstname"]." ";
673  }
674  if ($rec["lastname"])
675  {
676  $fullname .= $rec["lastname"];
677  }
678  }
679  return $fullname;
680  }
681 
685  function _lookupIm($a_user_id, $a_type)
686  {
687  return ilObjUser::_lookup($a_user_id, "im_".$a_type);
688  }
689 
690 
694  function _lookupEmail($a_user_id)
695  {
696  return ilObjUser::_lookup($a_user_id, "email");
697  }
698 
702  public static function _lookupGender($a_user_id)
703  {
704  return ilObjUser::_lookup($a_user_id, "gender");
705  }
706 
713  function _lookupClientIP($a_user_id)
714  {
715  return ilObjUser::_lookup($a_user_id, "client_ip");
716  }
717 
718 
724  public static function _lookupName($a_user_id)
725  {
726  global $ilDB;
727 
728  $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
729  array("integer"), array($a_user_id));
730  $user_rec = $ilDB->fetchAssoc($res);
731  return array("user_id" => $a_user_id,
732  "firstname" => $user_rec["firstname"],
733  "lastname" => $user_rec["lastname"],
734  "title" => $user_rec["title"],
735  "login" => $user_rec["login"]);
736  }
737 
741  function _lookupFields($a_user_id)
742  {
743  global $ilDB;
744 
745  $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
746  array("integer"), array($a_user_id));
747  $user_rec = $ilDB->fetchAssoc($res);
748  return $user_rec;
749  }
750 
754  function _lookupLogin($a_user_id)
755  {
756  return ilObjUser::_lookup($a_user_id, "login");
757  }
758 
762  function _lookupExternalAccount($a_user_id)
763  {
764  return ilObjUser::_lookup($a_user_id, "ext_account");
765  }
766 
770  public static function _lookupId($a_user_str)
771  {
772  global $ilDB;
773 
774  $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
775  array("text"), array($a_user_str));
776  $user_rec = $ilDB->fetchAssoc($res);
777  return $user_rec["usr_id"];
778  }
779 
783  function _lookupLastLogin($a_user_id)
784  {
785  return ilObjUser::_lookup($a_user_id, "last_login");
786  }
787 
788 
794  function refreshLogin()
795  {
796  global $ilDB;
797 
798  $ilDB->manipulateF("UPDATE usr_data SET ".
799  "last_login = ".$ilDB->now().
800  " WHERE usr_id = %s",
801  array("integer"), array($this->id));
802  }
803 
810  function replacePassword($new_md5)
811  {
812  global $ilDB;
813 
814  $this->passwd_type = IL_PASSWD_MD5;
815  $this->passwd = $new_md5;
816 
817  $ilDB->manipulateF("UPDATE usr_data SET ".
818  "passwd = %s ".
819  "WHERE usr_id = %s",
820  array("text", "integer"), array($this->passwd, $this->id));
821 
822  return true;
823  }
824 
833  function updatePassword($a_old, $a_new1, $a_new2)
834  {
835  global $ilDB;
836 
837  if (func_num_args() != 3)
838  {
839  return false;
840  }
841 
842  if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
843  {
844  return false;
845  }
846 
847  if ($a_new1 != $a_new2)
848  {
849  return false;
850  }
851 
852  // is catched by isset() ???
853  if ($a_new1 == "" || $a_old == "")
854  {
855  return false;
856  }
857 
858  //check old password
859  switch ($this->passwd_type)
860  {
861  case IL_PASSWD_PLAIN:
862  if ($a_old != $this->passwd)
863  {
864  return false;
865  }
866  break;
867 
868  case IL_PASSWD_MD5:
869  if (md5($a_old) != $this->passwd)
870  {
871  return false;
872  }
873  break;
874 
875  case IL_PASSWD_CRYPT:
876  if (self::_makeIlias2Password($a_old) != $this->passwd)
877  {
878  return false;
879  }
880  break;
881  }
882 
883  //update password
884  $this->passwd = md5($a_new1);
885  $this->passwd_type = IL_PASSWD_MD5;
886 
887  $ilDB->manipulateF("UPDATE usr_data SET ".
888  "passwd = %s ".
889  "WHERE usr_id = %s",
890  array("text", "integer"), array($this->passwd, $this->id));
891 
892  return true;
893  }
894 
902  function resetPassword($a_new1, $a_new2)
903  {
904  global $ilDB;
905 
906  if (func_num_args() != 2)
907  {
908  return false;
909  }
910 
911  if (!isset($a_new1) or !isset($a_new2))
912  {
913  return false;
914  }
915 
916  if ($a_new1 != $a_new2)
917  {
918  return false;
919  }
920 
921  //update password
922  $this->passwd = md5($a_new1);
923  $this->passwd_type = IL_PASSWD_MD5;
924 
925  $ilDB->manipulateF("UPDATE usr_data SET ".
926  "passwd = %s ".
927  "WHERE usr_id = %s",
928  array("text", "integer"),
929  array($this->passwd, $this->id));
930 
931  return true;
932  }
933 
938  public static function _makeIlias2Password($a_passwd)
939  {
940  return (crypt($a_passwd,substr($a_passwd,0,2)));
941  }
942 
953  public static function _doesLoginnameExistInHistory($a_login)
954  {
955  global $ilDB;
956 
957  $res = $ilDB->queryF('
958  SELECT * FROM loginname_history
959  WHERE login = %s',
960  array('text'), array($a_login));
961 
962  return $ilDB->fetchAssoc($res) ? true : false;
963  }
964 
977  public static function _getLastHistoryDataByUserId($a_usr_id)
978  {
979  global $ilDB;
980 
981  $ilDB->setLimit(1, 0);
982  $res = $ilDB->queryF('
983  SELECT login, history_date FROM loginname_history
984  WHERE usr_id = %s ORDER BY history_date DESC',
985  array('integer'), array($a_usr_id));
986  $row = $ilDB->fetchAssoc($res);
987  if(!is_array($row) || !count($row)) throw new ilUserException('');
988 
989  return array(
990  $row['login'], $row['history_date']
991  );
992  }
993 
1001  function updateLogin($a_login)
1002  {
1003  global $ilDB, $ilSetting;
1004 
1005  if(func_num_args() != 1)
1006  {
1007  return false;
1008  }
1009 
1010  if(!isset($a_login))
1011  {
1012  return false;
1013  }
1014 
1015  // Update not necessary
1016  if(0 == strcmp($a_login, self::_lookupLogin($this->getId())))
1017  {
1018  return false;
1019  }
1020 
1021  try
1022  {
1023  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1024  }
1025  catch(ilUserException $e) { $last_history_entry = null; }
1026 
1027  // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1028  if((int)$ilSetting->get('allow_change_loginname') &&
1029  (int)$ilSetting->get('reuse_of_loginnames') == 0 &&
1031  {
1032  throw new ilUserException($this->lng->txt('loginname_already_exists'));
1033  }
1034  else if((int)$ilSetting->get('allow_change_loginname') &&
1035  (int)$ilSetting->get('loginname_change_blocking_time') &&
1036  is_array($last_history_entry) &&
1037  $last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time') > time())
1038  {
1039  include_once 'Services/Calendar/classes/class.ilDate.php';
1040  throw new ilUserException(
1041  sprintf(
1042  $this->lng->txt('changing_loginname_not_possible_info'),
1044  new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1046  new ilDateTime(($last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX))
1047  )
1048  );
1049  }
1050  else
1051  {
1052  // log old loginname in history
1053  if((int)$ilSetting->get('allow_change_loginname') &&
1054  (int)$ilSetting->get('create_history_loginname'))
1055  {
1056  ilObjUser::_writeHistory($this->getId(), self::_lookupLogin($this->getId()));
1057  }
1058 
1059  //update login
1060  $this->login = $a_login;
1061 
1062  $ilDB->manipulateF('
1063  UPDATE usr_data
1064  SET login = %s
1065  WHERE usr_id = %s',
1066  array('text', 'integer'), array($this->getLogin(), $this->getId()));
1067  }
1068 
1069  return true;
1070  }
1071 
1078  function writePref($a_keyword, $a_value)
1079  {
1080  self::_writePref($this->id, $a_keyword, $a_value);
1081  $this->setPref($a_keyword, $a_value);
1082  }
1083 
1084 
1090  function deletePref($a_keyword)
1091  {
1092  self::_deletePref($this->getId(), $a_keyword);
1093  }
1094 
1100  public static function _deletePref($a_user_id, $a_keyword)
1101  {
1105  global $ilDB;
1106 
1107  $ilDB->manipulateF(
1108  'DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s',
1109  array('integer', 'text'),
1110  array($a_user_id, $a_keyword)
1111  );
1112  }
1113 
1119  function _deleteAllPref($a_user_id)
1120  {
1121  global $ilDB;
1122 
1123  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1124  array("integer"), array($a_user_id));
1125  }
1126 
1133  public static function _writePref($a_usr_id, $a_keyword, $a_value)
1134  {
1138  global $ilDB;
1139 
1140  self::_deletePref($a_usr_id, $a_keyword);
1141  if(strlen($a_value))
1142  {
1143  $ilDB->manipulateF(
1144  'INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s, %s, %s)',
1145  array('integer', 'text', 'text'),
1146  array($a_usr_id, $a_keyword, $a_value)
1147  );
1148  }
1149  }
1150 
1155  function writePrefs()
1156  {
1157  global $ilDB;
1158 
1159  ilObjUser::_deleteAllPref($this->id);
1160  foreach ($this->prefs as $keyword => $value)
1161  {
1162  self::_writePref($this->id, $keyword, $value);
1163  }
1164  }
1165 
1172  public function getTimeZone()
1173  {
1174  if($tz = $this->getPref('user_tz'))
1175  {
1176  return $tz;
1177  }
1178  else
1179  {
1180  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1181  $settings = ilCalendarSettings::_getInstance();
1182  return $settings->getDefaultTimeZone();
1183  }
1184  }
1185 
1192  public function getTimeFormat()
1193  {
1194  if($format = $this->getPref('time_format'))
1195  {
1196  return $format;
1197  }
1198  else
1199  {
1200  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1201  $settings = ilCalendarSettings::_getInstance();
1202  return $settings->getDefaultTimeFormat();
1203  }
1204  }
1205 
1212  public function getDateFormat()
1213  {
1214  if($format = $this->getPref('date_format'))
1215  {
1216  return $format;
1217  }
1218  else
1219  {
1220  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1221  $settings = ilCalendarSettings::_getInstance();
1222  return $settings->getDefaultDateFormat();
1223  }
1224  }
1225 
1232  function setPref($a_keyword, $a_value)
1233  {
1234  if ($a_keyword != "")
1235  {
1236  $this->prefs[$a_keyword] = $a_value;
1237  }
1238  }
1239 
1245  function getPref($a_keyword)
1246  {
1247  if (array_key_exists($a_keyword, $this->prefs))
1248  {
1249  return $this->prefs[$a_keyword];
1250  }
1251  else
1252  {
1253  return FALSE;
1254  }
1255  }
1256 
1257  function _lookupPref($a_usr_id,$a_keyword)
1258  {
1259  global $ilDB;
1260 
1261  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1262  "AND keyword = ".$ilDB->quote($a_keyword, "text");
1263  $res = $ilDB->query($query);
1264 
1265  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1266  {
1267  return $row->value;
1268  }
1269  return false;
1270  }
1271 
1276  function readPrefs()
1277  {
1278  global $ilDB;
1279 
1280  if (is_array($this->prefs))
1281  {
1282  $this->oldPrefs = $this->prefs;
1283  }
1284 
1285  $this->prefs = ilObjUser::_getPreferences($this->id);
1286  }
1287 
1293  function delete()
1294  {
1295  global $rbacadmin, $ilDB;
1296 
1297  // deassign from ldap groups
1298  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1300  $mapping->deleteUser($this->getId());
1301 
1302  // remove mailbox / update sent mails
1303  include_once ("Services/Mail/classes/class.ilMailbox.php");
1304  $mailbox = new ilMailbox($this->getId());
1305  $mailbox->delete();
1306  $mailbox->updateMailsOfDeletedUser($this->getLogin());
1307 
1308  // delete feed blocks on personal desktop
1309  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1310  $costum_block = new ilCustomBlock();
1311  $costum_block->setContextObjId($this->getId());
1312  $costum_block->setContextObjType("user");
1313  $c_blocks = $costum_block->queryBlocksForContext();
1314  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1315  foreach($c_blocks as $c_block)
1316  {
1317  if ($c_block["type"] == "pdfeed")
1318  {
1319  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1320  $fb->delete();
1321  }
1322  }
1323 
1324 
1325  // delete block settings
1326  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1328 
1329  // delete user_account
1330  $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1331  array("integer"), array($this->getId()));
1332 
1333  // delete user_prefs
1334  ilObjUser::_deleteAllPref($this->getId());
1335 
1336  $this->removeUserPicture(false); // #8597
1337 
1338  // delete user_session
1339  include_once("./Services/Authentication/classes/class.ilSession.php");
1341 
1342  // remove user from rbac
1343  $rbacadmin->removeUser($this->getId());
1344 
1345  // remove bookmarks
1346  // TODO: move this to class.ilBookmarkFolder
1347  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1348  $ilDB->quote($this->getId(), "integer");
1349  $ilDB->manipulate($q);
1350 
1351  $q = "DELETE FROM bookmark_data WHERE user_id = ".
1352  $ilDB->quote($this->getId(), "integer");
1353  $ilDB->manipulate($q);
1354 
1355  // DELETE FORUM ENTRIES (not complete in the moment)
1356  include_once './Modules/Forum/classes/class.ilObjForum.php';
1357  ilObjForum::_deleteUser($this->getId());
1358 
1359  // Delete link check notify entries
1360  include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
1362 
1363  // Delete crs entries
1364  include_once './Modules/Course/classes/class.ilObjCourse.php';
1365  ilObjCourse::_deleteUser($this->getId());
1366 
1367  // Delete user tracking
1368  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1370 
1371  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1373 
1374  // Delete Tracking data SCORM 2004 RTE
1375  include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1377 
1378  // Delete Tracking data SCORM 1.2 RTE
1379  include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1381 
1382  // remove all notifications
1383  include_once "./Services/Notification/classes/class.ilNotification.php";
1385 
1386  // remove portfolios
1387  include_once "./Services/Portfolio/classes/class.ilObjPortfolio.php";
1389 
1390  // remove workspace
1391  include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1392  $tree = new ilWorkspaceTree($this->getId());
1393  $tree->cascadingDelete();
1394 
1395  // Delete user defined field entries
1397 
1398  // Delete clipboard entries
1399  $this->clipboardDeleteAll();
1400 
1401  // Reset owner
1402  $this->resetOwner();
1403 
1404 
1405  // Trigger deleteUser Event
1406  global $ilAppEventHandler;
1407  $ilAppEventHandler->raise(
1408  'Services/User', 'deleteUser', array('usr_id' => $this->getId())
1409  );
1410 
1411  // delete object data
1412  parent::delete();
1413  return true;
1414  }
1415 
1425  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1426  {
1427  $this->fullname = "";
1428 
1429  if ($a_title)
1430  {
1431  $fullname = $a_title." ";
1432  }
1433  elseif ($this->utitle)
1434  {
1435  $this->fullname = $this->utitle." ";
1436  }
1437 
1438  if ($a_firstname)
1439  {
1440  $fullname .= $a_firstname." ";
1441  }
1442  elseif ($this->firstname)
1443  {
1444  $this->fullname .= $this->firstname." ";
1445  }
1446 
1447  if ($a_lastname)
1448  {
1449  return $fullname.$a_lastname;
1450  }
1451 
1452  $this->fullname .= $this->lastname;
1453  }
1454 
1469  function getFullname($a_max_strlen = 0)
1470  {
1471  if (!$a_max_strlen)
1472  {
1473  return ilUtil::stripSlashes($this->fullname);
1474  }
1475 
1476  if (strlen($this->fullname) <= $a_max_strlen)
1477  {
1478  return ilUtil::stripSlashes($this->fullname);
1479  }
1480 
1481  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1482  {
1483  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1484  }
1485 
1486  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1487  {
1488  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1489  }
1490 
1491  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1492  {
1493  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1494  }
1495 
1496  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1497  }
1498 
1507  public static function _hasAcceptedAgreement($a_username)
1508  {
1509  global $ilDB;
1510 
1511  if($a_username == 'root')
1512  {
1513  return true;
1514  }
1515 
1516  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
1517  "WHERE login = %s AND NOT agree_date IS NULL",
1518  array("text"), array($a_username));
1519  return $ilDB->fetchAssoc($res) ? true : false;
1520  }
1521 
1522 
1527  {
1528  if ($this->agree_date != null || $this->login == "root")
1529  {
1530  return true;
1531  }
1532  return false;
1533  }
1534 
1540  function setLogin($a_str)
1541  {
1542  $this->login = $a_str;
1543  }
1544 
1549  function getLogin()
1550  {
1551  return $this->login;
1552  }
1553 
1559  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1560  {
1561  $this->passwd = $a_str;
1562  $this->passwd_type = $a_type;
1563  }
1564 
1572  function getPasswd()
1573  {
1574  return $this->passwd;
1575  }
1582  function getPasswdType()
1583  {
1584  return $this->passwd_type;
1585  }
1586 
1592  function setGender($a_str)
1593  {
1594  $this->gender = substr($a_str,-1);
1595  }
1596 
1601  function getGender()
1602  {
1603  return $this->gender;
1604  }
1605 
1613  function setUTitle($a_str)
1614  {
1615  $this->utitle = $a_str;
1616  }
1617 
1624  function getUTitle()
1625  {
1626  return $this->utitle;
1627  }
1628 
1634  function setFirstname($a_str)
1635  {
1636  $this->firstname = $a_str;
1637  }
1638 
1643  function getFirstname()
1644  {
1645  return $this->firstname;
1646  }
1647 
1653  function setLastname($a_str)
1654  {
1655  $this->lastname = $a_str;
1656  }
1657 
1662  function getLastname()
1663  {
1664  return $this->lastname;
1665  }
1666 
1672  function setInstitution($a_str)
1673  {
1674  $this->institution = $a_str;
1675  }
1676 
1681  function getInstitution()
1682  {
1683  return $this->institution;
1684  }
1685 
1691  function setDepartment($a_str)
1692  {
1693  $this->department = $a_str;
1694  }
1695 
1700  function getDepartment()
1701  {
1702  return $this->department;
1703  }
1704 
1710  function setStreet($a_str)
1711  {
1712  $this->street = $a_str;
1713  }
1714 
1719  function getStreet()
1720  {
1721  return $this->street;
1722  }
1723 
1729  function setCity($a_str)
1730  {
1731  $this->city = $a_str;
1732  }
1733 
1738  function getCity()
1739  {
1740  return $this->city;
1741  }
1742 
1748  function setZipcode($a_str)
1749  {
1750  $this->zipcode = $a_str;
1751  }
1752 
1757  function getZipcode()
1758  {
1759  return $this->zipcode;
1760  }
1761 
1768  function setCountry($a_str)
1769  {
1770  $this->country = $a_str;
1771  }
1772 
1778  function getCountry()
1779  {
1780  return $this->country;
1781  }
1782 
1788  function setSelectedCountry($a_val)
1789  {
1790  $this->sel_country = $a_val;
1791  }
1792 
1799  {
1800  return $this->sel_country;
1801  }
1802 
1808  function setPhoneOffice($a_str)
1809  {
1810  $this->phone_office = $a_str;
1811  }
1812 
1817  function getPhoneOffice()
1818  {
1819  return $this->phone_office;
1820  }
1821 
1827  function setPhoneHome($a_str)
1828  {
1829  $this->phone_home = $a_str;
1830  }
1831 
1836  function getPhoneHome()
1837  {
1838  return $this->phone_home;
1839  }
1840 
1846  function setPhoneMobile($a_str)
1847  {
1848  $this->phone_mobile = $a_str;
1849  }
1850 
1855  function getPhoneMobile()
1856  {
1857  return $this->phone_mobile;
1858  }
1859 
1865  function setFax($a_str)
1866  {
1867  $this->fax = $a_str;
1868  }
1869 
1874  function getFax()
1875  {
1876  return $this->fax;
1877  }
1878 
1884  function setClientIP($a_str)
1885  {
1886  $this->client_ip = $a_str;
1887  }
1888 
1893  function getClientIP()
1894  {
1895  return $this->client_ip;
1896  }
1897 
1903  function setMatriculation($a_str)
1904  {
1905  $this->matriculation = $a_str;
1906  }
1907 
1912  function getMatriculation()
1913  {
1914  return $this->matriculation;
1915  }
1916 
1923  public static function lookupMatriculation($a_usr_id)
1924  {
1925  global $ilDB;
1926 
1927  $query = "SELECT matriculation FROM usr_data ".
1928  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1929  $res = $ilDB->query($query);
1930  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1931  return $row->matriculation ? $row->matriculation : '';
1932  }
1933 
1939  function setEmail($a_str)
1940  {
1941  $this->email = $a_str;
1942  }
1943 
1948  function getEmail()
1949  {
1950  return $this->email;
1951  }
1952 
1958  function setHobby($a_str)
1959  {
1960  $this->hobby = $a_str;
1961  }
1962 
1967  function getHobby()
1968  {
1969  return $this->hobby;
1970  }
1971 
1977  function setLanguage($a_str)
1978  {
1979  $this->setPref("language",$a_str);
1980  unset($_SESSION['lang']);
1981  }
1982 
1988  function getLanguage()
1989  {
1990  return $this->prefs["language"];
1991  }
1992 
2001  function setDiskQuota($a_disk_quota)
2002  {
2003  $this->setPref("disk_quota",$a_disk_quota);
2004  }
2005 
2015  function getDiskQuota()
2016  {
2017  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
2018  }
2019 
2020  public function setLastPasswordChangeTS($a_last_password_change_ts)
2021  {
2022  $this->last_password_change_ts = $a_last_password_change_ts;
2023  }
2024 
2025  public function getLastPasswordChangeTS()
2026  {
2028  }
2029 
2030 
2031  public static function _lookupLanguage($a_usr_id)
2032  {
2033  global $ilDB;
2034 
2035  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
2036  $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
2037  $ilDB->quote('language', "text");
2038  $r = $ilDB->query($q);
2039 
2040  while($row = $ilDB->fetchAssoc($r))
2041  {
2042  return $row['value'];
2043  }
2044  return 'en';
2045  }
2046 
2047 
2048  function _checkPassword($a_usr_id, $a_pw)
2049  {
2050  global $ilDB;
2051 
2052  $pw = ilObjUser::_lookup($a_usr_id, "passwd");
2053  if ($pw == md5($a_pw))
2054  {
2055  return true;
2056  }
2057  return false;
2058  }
2059 
2060  function _writeExternalAccount($a_usr_id, $a_ext_id)
2061  {
2062  global $ilDB;
2063 
2064  $ilDB->manipulateF("UPDATE usr_data ".
2065  " SET ext_account = %s WHERE usr_id = %s",
2066  array("text", "integer"),
2067  array($a_ext_id, $a_usr_id));
2068  }
2069 
2070  function _writeAuthMode($a_usr_id, $a_auth_mode)
2071  {
2072  global $ilDB;
2073 
2074  $ilDB->manipulateF("UPDATE usr_data ".
2075  " SET auth_mode = %s WHERE usr_id = %s",
2076  array("text", "integer"),
2077  array($a_auth_mode, $a_usr_id));
2078  }
2079 
2085  {
2086  return $_SESSION['lang'];
2087  }
2088 
2094  function setLastLogin($a_str)
2095  {
2096  $this->last_login = $a_str;
2097  }
2098 
2104  function getLastLogin()
2105  {
2106  return $this->last_login;
2107  }
2108 
2114  function setLastUpdate($a_str)
2115  {
2116  $this->last_update = $a_str;
2117  }
2118  function getLastUpdate()
2119  {
2120  return $this->last_update;
2121  }
2122 
2128  function setComment($a_str)
2129  {
2130  $this->referral_comment = $a_str;
2131  }
2132 
2137  function getComment()
2138  {
2139  return $this->referral_comment;
2140  }
2141 
2148  function setApproveDate($a_str)
2149  {
2150  $this->approve_date = $a_str;
2151  }
2152 
2158  function getApproveDate()
2159  {
2160  return $this->approve_date;
2161  }
2162 
2163  // BEGIN DiskQuota: show when user accepted user agreement
2169  function getAgreeDate()
2170  {
2171  return $this->agree_date;
2172  }
2179  function setAgreeDate($a_str)
2180  {
2181  $this->agree_date = $a_str;
2182  }
2183  // END DiskQuota: show when user accepted user agreement
2184 
2191  function setActive($a_active, $a_owner = 0)
2192  {
2193  $this->setOwner($a_owner);
2194 
2195  if ($a_active)
2196  {
2197  $this->active = 1;
2198  $this->setApproveDate(date('Y-m-d H:i:s'));
2199  $this->setOwner($a_owner);
2200  }
2201  else
2202  {
2203  $this->active = 0;
2204  $this->setApproveDate(null);
2205  }
2206  }
2207 
2212  function getActive()
2213  {
2214  return $this->active;
2215  }
2216 
2220  public function _lookupActive($a_usr_id)
2221  {
2222  global $ilDB;
2223 
2224  $query = 'SELECT usr_id FROM usr_data '.
2225  'WHERE active = '.$ilDB->quote(1,'integer').' '.
2226  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
2227  $res = $ilDB->query($query);
2228  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2229  {
2230  return true;
2231  }
2232  return false;
2233  }
2234 
2240  function syncActive()
2241  {
2242  global $ilAuth;
2243 
2244  $storedActive = 0;
2245  if ($this->getStoredActive($this->id))
2246  {
2247  $storedActive = 1;
2248  }
2249 
2250  $currentActive = 0;
2251  if ($this->active)
2252  {
2253  $currentActive = 1;
2254  }
2255 
2256  if ((!empty($storedActive) && empty($currentActive)) ||
2257  (empty($storedActive) && !empty($currentActive)))
2258  {
2259  $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2260  }
2261  }
2262 
2269  function getStoredActive($a_id)
2270  {
2271  $active = ilObjUser::_lookup($a_id, "active");
2272  return $active ? true : false;
2273  }
2274 
2280  function setSkin($a_str)
2281  {
2282  // TODO: exception handling (dir exists)
2283  $this->skin = $a_str;
2284  }
2285 
2286  function setTimeLimitOwner($a_owner)
2287  {
2288  $this->time_limit_owner = $a_owner;
2289  }
2291  {
2292  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2293  }
2294  function setTimeLimitFrom($a_from)
2295  {
2296  $this->time_limit_from = $a_from;
2297  }
2298  function getTimeLimitFrom()
2299  {
2300  return $this->time_limit_from ? $this->time_limit_from : time();
2301  }
2302  function setTimeLimitUntil($a_until)
2303  {
2304  $this->time_limit_until = $a_until;
2305  }
2307  {
2308  return $this->time_limit_until ? $this->time_limit_until : time();
2309  }
2310  function setTimeLimitUnlimited($a_unlimited)
2311  {
2312  $this->time_limit_unlimited = $a_unlimited;
2313  }
2315  {
2316  return $this->time_limit_unlimited;
2317  }
2318  function setTimeLimitMessage($a_time_limit_message)
2319  {
2320  return $this->time_limit_message = $a_time_limit_message;
2321  }
2323  {
2324  return $this->time_limit_message;
2325  }
2326 
2327  public function setLoginAttempts($a_login_attempts)
2328  {
2329  $this->login_attempts = $a_login_attempts;
2330  }
2331 
2332  public function getLoginAttempts()
2333  {
2334  return $this->login_attempts;
2335  }
2336 
2337 
2338  function checkTimeLimit()
2339  {
2340  if($this->getTimeLimitUnlimited())
2341  {
2342  return true;
2343  }
2344  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2345  {
2346  return true;
2347  }
2348  return false;
2349  }
2350  function setProfileIncomplete($a_prof_inc)
2351  {
2352  $this->profile_incomplete = (boolean) $a_prof_inc;
2353  }
2355  {
2356  if($this->id == ANONYMOUS_USER_ID)
2357  {
2358  return false;
2359  }
2360  return $this->profile_incomplete;
2361  }
2362 
2363  public function isPasswordChangeDemanded()
2364  {
2365  //error_reporting(E_ALL);
2366  if( $this->id == ANONYMOUS_USER_ID || $this->id == SYSTEM_USER_ID )
2367  return false;
2368 
2369  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2370  $security = ilSecuritySettings::_getInstance();
2371 
2373  && $security->isPasswordChangeOnFirstLoginEnabled()
2374  && $this->getLastPasswordChangeTS() == 0
2375  && $this->is_self_registered == false
2376  ){
2377  return true;
2378  }
2379  else return false;
2380  }
2381 
2382  public function isPasswordExpired()
2383  {
2384  //error_reporting(E_ALL);
2385  if($this->id == ANONYMOUS_USER_ID) return false;
2386 
2387  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2388  $security = ilSecuritySettings::_getInstance();
2389  if( $security->getAccountSecurityMode() == ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED &&
2390  $this->getLastPasswordChangeTS() > 0 )
2391  {
2392  $max_pass_age = $security->getPasswordMaxAge();
2393  if( $max_pass_age > 0 )
2394  {
2395  $max_pass_age_ts = ( $max_pass_age * 86400 );
2396  $pass_change_ts = $this->getLastPasswordChangeTS();
2397  $current_ts = time();
2398 
2399  if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2400  return true;
2401  }
2402  }
2403  return false;
2404  }
2405 
2406  public function getPasswordAge()
2407  {
2408  $current_ts = time();
2409  $pass_change_ts = $this->getLastPasswordChangeTS();
2410  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2411  return $password_age;
2412  }
2413 
2414  public function setLastPasswordChangeToNow()
2415  {
2416  global $ilDB;
2417 
2418  $this->setLastPasswordChangeTS( time() );
2419 
2420  $query = "UPDATE usr_data SET last_password_change = %s " .
2421  "WHERE usr_id = %s";
2422  $affected = $ilDB->manipulateF($query,
2423  array('integer','integer'),
2424  array($this->getLastPasswordChangeTS(),$this->id));
2425  if($affected) return true;
2426  else return false;
2427  }
2428 
2429  public function resetLastPasswordChange()
2430  {
2431  global $ilDB;
2432 
2433  $query = "UPDATE usr_data SET last_password_change = 0 " .
2434  "WHERE usr_id = %s";
2435  $affected = $ilDB->manipulateF( $query, array('integer'),
2436  array($this->getId()) );
2437  if($affected) return true;
2438  else return false;
2439  }
2440 
2446  function setLatitude($a_latitude)
2447  {
2448  $this->latitude = $a_latitude;
2449  }
2450 
2456  function getLatitude()
2457  {
2458  return $this->latitude;
2459  }
2460 
2466  function setLongitude($a_longitude)
2467  {
2468  $this->longitude = $a_longitude;
2469  }
2470 
2476  function getLongitude()
2477  {
2478  return $this->longitude;
2479  }
2480 
2486  function setLocationZoom($a_locationzoom)
2487  {
2488  $this->loc_zoom = $a_locationzoom;
2489  }
2490 
2496  function getLocationZoom()
2497  {
2498  return $this->loc_zoom;
2499  }
2500 
2501  function &getAppliedUsers()
2502  {
2503  $this->applied_users = array();
2504  $this->__readAppliedUsers($this->getId());
2505 
2506  return $this->applied_users ? $this->applied_users : array();
2507  }
2508 
2509  function isChild($a_usr_id)
2510  {
2511  if($a_usr_id == $this->getId())
2512  {
2513  return true;
2514  }
2515 
2516  $this->applied_users = array();
2517  $this->__readAppliedUsers($this->getId());
2518 
2519  return in_array($a_usr_id,$this->applied_users);
2520  }
2521 
2522  function __readAppliedUsers($a_parent_id)
2523  {
2524  global $ilDB;
2525 
2526  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2527  "WHERE time_limit_owner = %s",
2528  array("integer"),
2529  array($a_parent_id));
2530  while ($row = $ilDB->fetchObject($res))
2531  {
2532  $this->applied_users[] = $row->usr_id;
2533 
2534  // recursion
2535  $this->__readAppliedUsers($row->usr_id);
2536  }
2537  return true;
2538  }
2539 
2545  static function hasActiveSession($a_user_id)
2546  {
2547  global $ilDB;
2548 
2549  $set = $ilDB->queryf('
2550  SELECT COUNT(*) session_count
2551  FROM usr_session WHERE user_id = %s AND expires > %s',
2552  array('integer', 'integer'),
2553  array($a_user_id, time()));
2554  $row = $ilDB->fetchAssoc($set);
2555  return (bool)$row['session_count'];
2556  }
2557 
2558  /*
2559  * check user id with login name
2560  * @access public
2561  */
2562  function checkUserId()
2563  {
2564  global $ilAuth, $ilSetting;
2565 
2568  if ($id > 0)
2569  {
2570  return $id;
2571  }
2572  return false;
2573  }
2574 
2578  private static function getLoginFromAuth() {
2579  global $ilAuth;
2580 
2581  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2582  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2584  {
2585  require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2586  require_once ('Services/Database/classes/class.ilAuthContainerMDB2.php');
2587  $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2588  }
2589  else
2590  {
2591  $login =$ilAuth->getUsername();
2592  }
2593 
2594  return $login;
2595  }
2596 
2597  /*
2598  * check to see if current user has been made active
2599  * @access public
2600  * @return true if active, otherwise false
2601  */
2603  {
2604  global $ilDB,$ilAuth;
2605 
2607  $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2608  array("text"),
2609  array($login));
2610  //query has got a result
2611  if ($rec = $ilDB->fetchAssoc($set))
2612  {
2613  if ($rec["active"])
2614  {
2615  return true;
2616  }
2617  }
2618 
2619  return false;
2620  }
2621 
2622  /*
2623  * STATIC METHOD
2624  * get the user_id of a login name
2625  * @param string login name
2626  * @return integer id of user
2627  * @static
2628  * @access public
2629  */
2630  function getUserIdByLogin($a_login)
2631  {
2632  return (int) ilObjUser::_lookupId($a_login);
2633  }
2634 
2643  function _getUserIdsByEmail($a_email)
2644  {
2645  global $ilias, $ilDB;
2646 
2647  $res = $ilDB->queryF("SELECT login FROM usr_data ".
2648  "WHERE email = %s and active = 1",
2649  array("text"),
2650  array($a_email));
2651  $ids = array ();
2652  while($row = $ilDB->fetchObject($res))
2653  {
2654  $ids[] = $row->login;
2655  }
2656 
2657  return $ids;
2658  }
2659 
2660 
2661 
2670  function getUserIdByEmail($a_email)
2671  {
2672  global $ilDB;
2673 
2674  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2675  "WHERE email = %s", array("text"), array($a_email));
2676 
2677  $row = $ilDB->fetchObject($res);
2678  return $row->usr_id ? $row->usr_id : 0;
2679  }
2680 
2681  /*
2682  * STATIC METHOD
2683  * get the login name of a user_id
2684  * @param integer id of user
2685  * @return string login name; false if not found
2686  * @static
2687  * @access public
2688  */
2689  function getLoginByUserId($a_userid)
2690  {
2691  $login = ilObjUser::_lookupLogin($a_userid);
2692  return $login ? $login : false;
2693  }
2694 
2705  static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2706  {
2707  global $ilias, $ilDB, $ilLog;
2708 
2709 
2710  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2711 
2712  $without_anonymous_users = true;
2713 
2714  // determine join filter
2715  $join_filter = " WHERE ";
2716  if ($filter_settings !== FALSE && strlen($filter_settings))
2717  {
2718  switch ($filter_settings)
2719  {
2720  case 3:
2721  // show only users without courses
2722  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.usr_id IS NULL AND ";
2723  break;
2724  case 5:
2725  // show only users with a certain course membership
2726  $ref_id = $_SESSION["user_filter_data"];
2727  if ($ref_id)
2728  {
2729  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.obj_id = ".
2730  "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2731  }
2732  break;
2733  case 6:
2734  global $rbacreview;
2735  $ref_id = $_SESSION["user_filter_data"];
2736  if ($ref_id)
2737  {
2738  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2739  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2740  if (is_array($local_roles) && count($local_roles))
2741  {
2742  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2743  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2744  }
2745  }
2746  break;
2747  case 7:
2748  global $rbacreview;
2749  $rol_id = $_SESSION["user_filter_data"];
2750  if ($rol_id)
2751  {
2752  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2753  $ilDB->quote($rol_id, "integer")." AND ";
2754  $without_anonymous_users = false;
2755  }
2756  break;
2757  }
2758  }
2759  // This is a temporary hack to search users by their role
2760  // See Mantis #338. This is a hack due to Mantis #337.
2761  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2762  {
2763  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2764  "FROM object_data,rbac_ua,usr_data ".
2765  "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2766  " AND object_data.type = 'role' ".
2767  "AND rbac_ua.rol_id = object_data.obj_id ".
2768  "AND usr_data.usr_id = rbac_ua.usr_id ".
2769  "AND rbac_ua.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2770  }
2771  else
2772  {
2773  $query.= $join_filter.
2774  "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2775  "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2776  "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2777  "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2778 
2779  if ($filter_settings !== FALSE && strlen($filter_settings))
2780  {
2781  switch ($filter_settings)
2782  {
2783  case 0:
2784  $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2785  break;
2786  case 1:
2787  $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2788  break;
2789  case 2:
2790  $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2791  break;
2792  case 4:
2793  $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"]));
2794  $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2795  break;
2796  }
2797  }
2798 
2799  if ($without_anonymous_users)
2800  {
2801  $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2802  }
2803 
2804  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2805  {
2806  $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2807  }
2808 
2809  }
2810  $ilLog->write($query);
2811  $res = $ilDB->query($query);
2812  while ($row = $ilDB->fetchObject($res))
2813  {
2814  $users[] = array(
2815  "usr_id" => $row->usr_id,
2816  "login" => $row->login,
2817  "firstname" => $row->firstname,
2818  "lastname" => $row->lastname,
2819  "email" => $row->email,
2820  "active" => $row->active);
2821  $ids[] = $row->usr_id;
2822  }
2823  if ($a_return_ids_only)
2824  return $ids ? $ids : array();
2825  else
2826  return $users ? $users : array();
2827  }
2828 
2838  {
2839  global $ilDB;
2840 
2841  $res = $ilDB->query("SELECT login FROM usr_data");
2842  while($row = $ilDB->fetchObject($res))
2843  {
2844  $logins[] = $row->login;
2845  }
2846  return $logins ? $logins : array();
2847  }
2848 
2857  public static function _readUsersProfileData($a_user_ids)
2858  {
2859  global $ilDB;
2860  $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2861  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2862  while ($row = $ilDB->fetchAssoc($res))
2863  {
2864  $user_data["$row[usr_id]"] = $row;
2865  }
2866  return $user_data ? $user_data : array();
2867  }
2868 
2877  function _getAllUserData($a_fields = NULL, $active =-1)
2878  {
2879  global $ilDB;
2880 
2881  $result_arr = array();
2882  $types = array();
2883  $values = array();
2884 
2885  if ($a_fields !== NULL and is_array($a_fields))
2886  {
2887  if (count($a_fields) == 0)
2888  {
2889  $select = "*";
2890  }
2891  else
2892  {
2893  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2894  unset($a_fields[$usr_id_field]);
2895 
2896  $select = implode(",",$a_fields).",usr_data.usr_id";
2897  // online time
2898  if(in_array('online_time',$a_fields))
2899  {
2900  $select .= ",ut_online.online_time ";
2901  }
2902  }
2903 
2904  $q = "SELECT ".$select." FROM usr_data ";
2905 
2906  // Add online_time if desired
2907  // Need left join here to show users that never logged in
2908  if(in_array('online_time',$a_fields))
2909  {
2910  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2911  }
2912 
2913  switch ($active)
2914  {
2915  case 0:
2916  case 1:
2917  $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2918  break;
2919  case 2:
2920  $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2921  break;
2922  case 3:
2923  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2924  $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2925  $r = $ilDB->query($qtemp);
2926  $course_users = array();
2927  while ($row = $ilDB->fetchAssoc($r))
2928  {
2929  array_push($course_users, $row["usr_id"]);
2930  }
2931  if (count($course_users))
2932  {
2933  $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2934  }
2935  else
2936  {
2937  return $result_arr;
2938  }
2939  break;
2940  case 4:
2941  $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"]));
2942  $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2943  break;
2944  case 5:
2945  $ref_id = $_SESSION["user_filter_data"];
2946  if ($ref_id)
2947  {
2948  $q .= " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id ".
2949  "WHERE obj_members.obj_id = (SELECT obj_id FROM object_reference ".
2950  "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2951  }
2952  break;
2953  case 6:
2954  global $rbacreview;
2955  $ref_id = $_SESSION["user_filter_data"];
2956  if ($ref_id)
2957  {
2958  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2959  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2960  if (is_array($local_roles) && count($local_roles))
2961  {
2962  $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2963  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2964  }
2965  }
2966  break;
2967  case 7:
2968  $rol_id = $_SESSION["user_filter_data"];
2969  if ($rol_id)
2970  {
2971  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2972  $ilDB->quote($rol_id, "integer");
2973  }
2974  break;
2975  }
2976  $r = $ilDB->query($q);
2977 
2978  while ($row = $ilDB->fetchAssoc($r))
2979  {
2980  $result_arr[] = $row;
2981  }
2982  }
2983 
2984  return $result_arr;
2985  }
2986 
2990  function _getNumberOfUsersForStyle($a_skin, $a_style)
2991  {
2992  global $ilDB;
2993 
2994  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
2995  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
2996  " AND up1.value= ".$ilDB->quote($a_style, "text").
2997  " AND up2.keyword= ".$ilDB->quote("skin", "text").
2998  " AND up2.value= ".$ilDB->quote($a_skin, "text").
2999  " AND up1.usr_id = up2.usr_id ";
3000 
3001  $cnt_set = $ilDB->query($q);
3002 
3003  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
3004 
3005  return $cnt_rec["cnt"];
3006  }
3007 
3012  {
3013  global $ilDB;
3014 
3015  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
3016  " WHERE up1.keyword = ".$ilDB->quote("style", "text").
3017  " AND up2.keyword = ".$ilDB->quote("skin", "text").
3018  " AND up1.usr_id = up2.usr_id";
3019 
3020  $sty_set = $ilDB->query($q);
3021 
3022  $styles = array();
3023  while($sty_rec = $ilDB->fetchAssoc($sty_set))
3024  {
3025  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
3026  }
3027 
3028  return $styles;
3029  }
3030 
3034  function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3035  {
3036  global $ilDB;
3037 
3038  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
3039  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3040  " AND up1.value= ".$ilDB->quote($a_from_style, "text").
3041  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3042  " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
3043  " AND up1.usr_id = up2.usr_id ";
3044 
3045  $usr_set = $ilDB->query($q);
3046 
3047  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3048  {
3049  self::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3050  self::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3051  }
3052  }
3053 
3054 
3064  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3065  {
3066  global $ilDB;
3067 
3068  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3069  "item_id = %s AND type = %s AND user_id = %s",
3070  array("integer", "text", "integer"),
3071  array($a_item_id, $a_type, $a_usr_id));
3072 
3073  // only insert if item is not already on desktop
3074  if (!$ilDB->fetchAssoc($item_set))
3075  {
3076  $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3077  " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3078  array($a_item_id,$a_type,$a_usr_id,$a_par));
3079  }
3080 
3081  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3083  }
3084 
3092  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3093  {
3094  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3095  }
3096 
3105  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3106  {
3107  global $ilDB;
3108 
3109  $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3110  " WHERE item_id = %s AND type = %s AND user_id = %s",
3111  array("text", "integer", "text", "integer"),
3112  array($a_par, $a_item_id, $a_type, $this->getId()));
3113  }
3114 
3115 
3125  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3126  {
3127  global $ilDB;
3128 
3129  $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3130  " item_id = %s AND type = %s AND user_id = %s",
3131  array("integer", "text", "integer"),
3132  array($a_item_id, $a_type, $a_usr_id));
3133 
3134  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3136  }
3137 
3145  function dropDesktopItem($a_item_id, $a_type)
3146  {
3147  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3148  }
3149 
3156  static function _removeItemFromDesktops($a_id)
3157  {
3158  global $ilDB;
3159 
3160  $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3161  array("integer"), array($a_id));
3162 
3163  $users = array();
3164 
3165  while ($row = $ilDB->fetchObject($r))
3166  {
3167  $users[] = $row->user_id;
3168  } // while
3169 
3170  if (count($users) > 0)
3171  {
3172  $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3173  array("integer"), array($a_id));
3174  }
3175 
3176  return $users;
3177  }
3178 
3188  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3189  {
3190  global $ilDB;
3191 
3192  if (self::$is_desktop_item_loaded[$a_usr_id.":".$a_item_id])
3193  {
3194  return self::$is_desktop_item_cache[$a_usr_id.":".$a_item_id.":".$a_type];
3195  }
3196  $item_set = $ilDB->queryF("SELECT item_id FROM desktop_item WHERE ".
3197  "item_id = %s AND type = %s AND user_id = %s",
3198  array("integer", "text", "integer"),
3199  array($a_item_id, $a_type, $a_usr_id));
3200 
3201  if ($ilDB->fetchAssoc($item_set))
3202  {
3203  return true;
3204  }
3205  else
3206  {
3207  return false;
3208  }
3209  }
3210 
3217  static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3218  {
3219  global $ilDB;
3220 
3221  if (!is_array($a_item_ids))
3222  {
3223  return;
3224  }
3225 
3226  $item_ids = array();
3227  foreach ($a_item_ids as $id)
3228  {
3229  if (!self::$is_desktop_item_loaded[$a_usr_id.":".$id])
3230  {
3231  $item_ids[] = $id;
3232  }
3233  self::$is_desktop_item_loaded[$a_usr_id.":".$id] = true;
3234  }
3235 
3236  if (count($item_ids) > 0)
3237  {
3238  $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE ".
3239  $ilDB->in("item_id", $item_ids, false, "integer").
3240  " AND user_id = ".$ilDB->quote($a_usr_id, "integer"));
3241  while ($r = $ilDB->fetchAssoc($item_set))
3242  {
3243  self::$is_desktop_item_cache[$a_usr_id.":".$r["item_id"].":".$r["type"]]
3244  = true;
3245  }
3246  }
3247  }
3248 
3256  function isDesktopItem($a_item_id, $a_type)
3257  {
3258  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3259  }
3260 
3261  function getDesktopItems($a_types = "")
3262  {
3263  return $this->_lookupDesktopItems($this->getId(), $a_types);
3264  }
3265 
3272  static function _lookupDesktopItems($user_id, $a_types = "")
3273  {
3274  global $ilUser, $rbacsystem, $tree, $ilDB;
3275 
3276  if ($a_types == "")
3277  {
3278  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3279  " FROM desktop_item it, object_reference oref ".
3280  ", object_data obj".
3281  " WHERE ".
3282  "it.item_id = oref.ref_id AND ".
3283  "oref.obj_id = obj.obj_id AND ".
3284  "it.user_id = %s", array("integer"), array($user_id));
3285  $items = array();
3286  while ($item_rec = $ilDB->fetchAssoc($item_set))
3287  {
3288  if ($tree->isInTree($item_rec["ref_id"])
3289  && $item_rec["type"] != "rolf"
3290  && $item_rec["type"] != "itgr") // due to bug 11508
3291  {
3292  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3293  $par_left = $tree->getLeftValue($parent_ref);
3294  $par_left = sprintf("%010d", $par_left);
3295 
3296 
3297  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3298  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3299  $items[$par_left.$title.$item_rec["ref_id"]] =
3300  array("ref_id" => $item_rec["ref_id"],
3301  "obj_id" => $item_rec["obj_id"],
3302  "type" => $item_rec["type"],
3303  "title" => $title,
3304  "description" => $desc,
3305  "parent_ref" => $parent_ref);
3306  }
3307  }
3308  ksort($items);
3309  }
3310  else
3311  {
3312  // due to bug 11508
3313  if (!is_array($a_types))
3314  {
3315  $a_types = array($a_types);
3316  }
3317  $items = array();
3318  $foundsurveys = array();
3319  foreach($a_types as $a_type)
3320  {
3321  if ($a_type == "itgr")
3322  {
3323  continue;
3324  }
3325  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3326  ", object_data obj WHERE ".
3327  "it.item_id = oref.ref_id AND ".
3328  "oref.obj_id = obj.obj_id AND ".
3329  "it.type = %s AND ".
3330  "it.user_id = %s ".
3331  "ORDER BY title",
3332  array("text", "integer"),
3333  array($a_type, $user_id));
3334 
3335  while ($item_rec = $ilDB->fetchAssoc($item_set))
3336  {
3337  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3338  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3339  $items[$title.$a_type.$item_rec["ref_id"]] =
3340  array("ref_id" => $item_rec["ref_id"],
3341  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3342  "title" => $title, "description" => $desc);
3343  }
3344 
3345  }
3346  ksort($items);
3347  }
3348 
3349  return $items;
3350  }
3351 
3357 
3365  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3366  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3367  {
3368  global $ilDB;
3369 
3370  if ($a_time == 0)
3371  {
3372  $a_time = date("Y-m-d H:i:s", time());
3373  }
3374 
3375  $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3376  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3377  array("integer", "integer", "text", "integer"),
3378  array(0, $a_item_id, $a_type, $this->getId()));
3379 
3380  // only insert if item is not already in clipboard
3381  if (!$d = $item_set->fetchRow())
3382  {
3383  $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3384  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3385  " (%s,%s,%s,%s,%s,%s,%s)",
3386  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3387  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3388  }
3389  else
3390  {
3391  $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3392  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3393  array("timestamp", "integer", "integer", "text"),
3394  array($a_time, $this->getId(), $a_item_id, $a_type));
3395  }
3396  }
3397 
3401  function addToPCClipboard($a_content, $a_time, $a_nr)
3402  {
3403  global $ilDB;
3404  if ($a_time == 0)
3405  {
3406  $a_time = date("Y-m-d H:i:s", time());
3407  }
3408  $ilDB->insert("personal_pc_clipboard", array(
3409  "user_id" => array("integer", $this->getId()),
3410  "content" => array("clob", $a_content),
3411  "insert_time" => array("timestamp", $a_time),
3412  "order_nr" => array("integer", $a_nr)
3413  ));
3414  }
3415 
3420  {
3421  global $ilDB;
3422 
3423  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3424  " WHERE user_id = %s", array("integer"), array($this->getId()));
3425  $row = $ilDB->fetchAssoc($set);
3426 
3427  $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3428  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3429  array("integer", "timestamp"),
3430  array($this->getId(), $row["mtime"]));
3431  $content = array();
3432  while ($row = $ilDB->fetchAssoc($set))
3433  {
3434  $content[] = $row["content"];
3435  }
3436 
3437  return $content;
3438  }
3439 
3443  function clipboardHasObjectsOfType($a_type)
3444  {
3445  global $ilDB;
3446 
3447  $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3448  "parent = %s AND type = %s AND user_id = %s",
3449  array("integer", "text", "integer"),
3450  array(0, $a_type, $this->getId()));
3451  if ($rec = $ilDB->fetchAssoc($set))
3452  {
3453  return true;
3454  }
3455 
3456  return false;
3457  }
3458 
3463  {
3464  global $ilDB;
3465 
3466  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3467  "type = %s AND user_id = %s",
3468  array("text", "integer"),
3469  array($a_type, $this->getId()));
3470  }
3471 
3476  {
3477  global $ilDB;
3478 
3479  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3480  "user_id = %s", array("integer"), array($this->getId()));
3481  }
3482 
3486  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3487  {
3488  global $ilDB;
3489 
3490  $par = "";
3491  if ($a_top_nodes_only)
3492  {
3493  $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3494  }
3495 
3496  $type_str = ($a_type != "")
3497  ? " AND type = ".$ilDB->quote($a_type, "text")." "
3498  : "";
3499  $q = "SELECT * FROM personal_clipboard WHERE ".
3500  "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3501  $type_str.$par.
3502  " ORDER BY order_nr";
3503  $objs = $ilDB->query($q);
3504  $objects = array();
3505  while ($obj = $ilDB->fetchAssoc($objs))
3506  {
3507  if ($obj["type"] == "mob")
3508  {
3509  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3510  }
3511  if ($obj["type"] == "incl")
3512  {
3513  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3514  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3515  }
3516  $objects[] = array ("id" => $obj["item_id"],
3517  "type" => $obj["type"], "title" => $obj["title"],
3518  "insert_time" => $obj["insert_time"]);
3519  }
3520  return $objects;
3521  }
3522 
3526  function getClipboardChilds($a_parent, $a_insert_time)
3527  {
3528  global $ilDB, $ilUser;
3529 
3530  $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3531  "user_id = %s AND parent = %s AND insert_time = %s ".
3532  " ORDER BY order_nr",
3533  array("integer", "integer", "timestamp"),
3534  array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3535  $objects = array();
3536  while ($obj = $ilDB->fetchAssoc($objs))
3537  {
3538  if ($obj["type"] == "mob")
3539  {
3540  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3541  }
3542  $objects[] = array ("id" => $obj["item_id"],
3543  "type" => $obj["type"], "title" => $obj["title"]);
3544  }
3545  return $objects;
3546  }
3547 
3556  function _getUsersForClipboadObject($a_type, $a_id)
3557  {
3558  global $ilDB;
3559 
3560  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3561  "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3562  "type = ".$ilDB->quote($a_type, "text");
3563  $user_set = $ilDB->query($q);
3564  $users = array();
3565  while ($user_rec = $ilDB->fetchAssoc($user_set))
3566  {
3567  $users[] = $user_rec["user_id"];
3568  }
3569 
3570  return $users;
3571  }
3572 
3580  function removeObjectFromClipboard($a_item_id, $a_type)
3581  {
3582  global $ilDB;
3583 
3584  $q = "DELETE FROM personal_clipboard WHERE ".
3585  "item_id = ".$ilDB->quote($a_item_id, "integer").
3586  " AND type = ".$ilDB->quote($a_type, "text")." ".
3587  " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3588  $ilDB->manipulate($q);
3589  }
3590 
3591  function _getImportedUserId($i2_id)
3592  {
3593  global $ilDB;
3594 
3595  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3596  $ilDB->quote($i2_id, "text");
3597 
3598  $res = $ilDB->query($query);
3599  while($row = $ilDB->fetchObject($res))
3600  {
3601  $id = $row->obj_id;
3602  }
3603  return $id ? $id : 0;
3604  }
3605 
3606 /*
3607 
3608  function setiLincData($a_id,$a_login,$a_passwd)
3609  {
3610  $this->ilinc_id = $a_id;
3611  $this->ilinc_login = $a_login;
3612  $this->ilinc_passwd = $a_passwd;
3613  }
3614 
3615 */
3616 
3617 /*
3618 
3619  function getiLincData()
3620  {
3621  return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
3622  }
3623 */
3628  function setAuthMode($a_str)
3629  {
3630  $this->auth_mode = $a_str;
3631  }
3632 
3637  function getAuthMode($a_auth_key = false)
3638  {
3639  if (!$a_auth_key)
3640  {
3641  return $this->auth_mode;
3642  }
3643 
3644  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3645  return ilAuthUtils::_getAuthMode($this->auth_mode);
3646  }
3647 
3655  function setExternalAccount($a_str)
3656  {
3657  $this->ext_account = $a_str;
3658  }
3659 
3668  {
3669  return $this->ext_account;
3670  }
3671 
3683  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3684  {
3685  global $ilDB,$ilSetting;
3686 
3687  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3688  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3689  "WHERE auth_mode = %s";
3690  $types[] = "text";
3691  $values[] = $a_auth_mode;
3692  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3693  {
3694  $q.= " OR auth_mode = %s ";
3695  $types[] = "text";
3696  $values[] = 'default';
3697  }
3698 
3699  $res = $ilDB->queryF($q, $types, $values);
3700  while ($row = $ilDB->fetchObject($res))
3701  {
3702  if($row->auth_mode == 'default')
3703  {
3704  $accounts[$row->usr_id] = $row->login;
3705  }
3706  else
3707  {
3708  $accounts[$row->usr_id] = $row->ext_account;
3709  }
3710  }
3711  return $accounts ? $accounts : array();
3712  }
3713 
3721  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3722  {
3723  global $ilDB;
3724 
3725  if(!is_array($a_usr_ids))
3726  {
3727  return false;
3728  }
3729 
3730 
3731  if( $a_status )
3732  {
3733  $q = "UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE ".
3734  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3735  $ilDB->manipulate($q);
3736  }
3737  else
3738  {
3739  $usrId_IN_usrIds = $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3740 
3741  $q = "UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds";
3742  $ilDB->manipulate($q);
3743 
3744  $queryString = "
3745  UPDATE usr_data
3746  SET inactivation_date = %s
3747  WHERE inactivation_date IS NULL
3748  AND $usrId_IN_usrIds
3749  ";
3750  $ilDB->manipulateF($queryString, array('timestamp'), array(ilUtil::now()));
3751  }
3752 
3753  return true;
3754  }
3755 
3756 
3765  public static function _lookupAuthMode($a_usr_id)
3766  {
3767  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3768  }
3769 
3776  public static function _checkExternalAuthAccount($a_auth, $a_account)
3777  {
3778  global $ilDB,$ilSetting;
3779 
3780  // Check directly with auth_mode
3781  $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3782  " ext_account = %s AND auth_mode = %s",
3783  array("text", "text"),
3784  array($a_account, $a_auth));
3785  if ($usr = $ilDB->fetchAssoc($r))
3786  {
3787  return $usr["login"];
3788  }
3789 
3790  // For compatibility, check for login (no ext_account entry given)
3791  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3792  "WHERE login = %s AND auth_mode = %s",
3793  array("text", "text"),
3794  array($a_account, $a_auth));
3795  if($usr = $ilDB->fetchAssoc($res))
3796  {
3797  return $usr['login'];
3798  }
3799 
3800  // If auth_default == $a_auth => check for login
3801  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3802  {
3803  $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3804  " ext_account = %s AND auth_mode = %s",
3805  array("text", "text"),
3806  array($a_account, "default"));
3807  if ($usr = $ilDB->fetchAssoc($res))
3808  {
3809  return $usr["login"];
3810  }
3811  // Search for login (no ext_account given)
3812  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3813  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3814  array("text", "text"),
3815  array($a_account, "default"));
3816  if($usr = $ilDB->fetchAssoc($res))
3817  {
3818  return $usr["login"];
3819  }
3820  }
3821  return false;
3822  }
3823 
3828  {
3829  global $ilDB;
3830 
3831  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3832  "GROUP BY auth_mode");
3833  $cnt_arr = array();
3834  while($cnt = $ilDB->fetchAssoc($r))
3835  {
3836  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3837  }
3838 
3839  return $cnt_arr;
3840  }
3841 
3847  function _getLocalAccountsForEmail($a_email)
3848  {
3849  global $ilDB, $ilSetting;
3850 
3851  // default set to local (1)?
3852 
3853  $q = "SELECT * FROM usr_data WHERE ".
3854  " email = %s AND (auth_mode = %s ";
3855  $types = array("text", "text");
3856  $values = array($a_email, "local");
3857 
3858  if ($ilSetting->get("auth_mode") == 1)
3859  {
3860  $q.=" OR auth_mode = %s";
3861  $types[] = "text";
3862  $values[] = "default";
3863  }
3864 
3865  $q.= ")";
3866 
3867  $users = array();
3868  $usr_set = $ilDB->queryF($q, $types, $values);
3869  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3870  {
3871  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3872  }
3873 
3874  return $users;
3875  }
3876 
3877 
3885  function _uploadPersonalPicture($tmp_file, $obj_id)
3886  {
3887  $webspace_dir = ilUtil::getWebspaceDir();
3888  $image_dir = $webspace_dir."/usr_images";
3889  $store_file = "usr_".$obj_id."."."jpg";
3890  $target_file = $image_dir."/$store_file";
3891 
3892  chmod($tmp_file, 0770);
3893 
3894  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3895  // taking only frame [0] to avoid problems with animated gifs
3896  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3897  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3898  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3899  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3900 
3901  ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
3902  ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
3903  ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
3904  ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
3905 
3906  // store filename
3907  self::_writePref($obj_id, "profile_image", $store_file);
3908 
3909  return TRUE;
3910  }
3911 
3912 
3921  public function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3922  {
3923  if(isset(self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic]))
3924  {
3925  return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3926  }
3927 
3928  self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic] = ilObjUser::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
3929 
3930  return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3931  }
3932 
3942  public static function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3943  $a_prevent_no_photo_image = false)
3944  {
3945  global $ilDB;
3946 
3947  // BEGIN DiskQuota: Fetch all user preferences in a single query
3948  $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3949  "keyword IN (%s,%s) ".
3950  "AND usr_id = %s",
3951  array("text", "text", "integer"),
3952  array('public_upload', 'public_profile', $a_usr_id));
3953  while ($row = $ilDB->fetchAssoc($res))
3954  {
3955  switch ($row['keyword'])
3956  {
3957  case 'public_upload' :
3958  $upload = $row['value'] == 'y';
3959  break;
3960  case 'public_profile' :
3961  $profile = ($row['value'] == 'y' ||
3962  $row['value'] == 'g');
3963  break;
3964  }
3965  }
3966 
3967  // END DiskQuota: Fetch all user preferences in a single query
3968  $webspace_dir = "";
3969  if(defined('ILIAS_MODULE'))
3970  {
3971  $webspace_dir = ('.'.$webspace_dir);
3972  }
3973  $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
3974 
3975  $image_dir = $webspace_dir."/usr_images";
3976  // BEGIN DiskQuota: Support 'big' user images
3977  if ($a_size == 'big')
3978  {
3979  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3980  }
3981  else
3982  {
3983  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3984  }
3985  // END DiskQuota: Support 'big' user images
3986 
3987  if((($upload && $profile) || $a_force_pic)
3988  && @is_file($thumb_file))
3989  {
3990  $file = $thumb_file."?t=".rand(1, 99999);
3991  }
3992  else
3993  {
3994  if (!$a_prevent_no_photo_image)
3995  {
3996  // we only have xsmall and xxsmall for this
3997  if($a_size == "small" || $a_size == "big")
3998  {
3999  $a_size = "xsmall";
4000  }
4001  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
4002  }
4003  }
4004 
4005  return $file;
4006  }
4007 
4014  static function copyProfilePicturesToDirectory($a_user_id, $a_dir)
4015  {
4016  $a_dir = trim(str_replace("..", "", $a_dir));
4017  if ($a_dir == "" || !is_dir($a_dir))
4018  {
4019  return;
4020  }
4021 
4022  $webspace_dir = ilUtil::getWebspaceDir();
4023  $image_dir = $webspace_dir."/usr_images";
4024  $images = array(
4025  "upload_".$a_user_id."pic",
4026  "usr_".$a_user_id."."."jpg",
4027  "usr_".$a_user_id."_small.jpg",
4028  "usr_".$a_user_id."_xsmall.jpg",
4029  "usr_".$a_user_id."_xxsmall.jpg",
4030  "upload_".$a_user_id);
4031  foreach ($images as $image)
4032  {
4033  if (is_file($image_dir."/".$image))
4034  {
4035  copy($image_dir."/".$image, $a_dir."/".$image);
4036  }
4037  }
4038  }
4039 
4040 
4044  function removeUserPicture($a_do_update = true)
4045  {
4046  $webspace_dir = ilUtil::getWebspaceDir();
4047  $image_dir = $webspace_dir."/usr_images";
4048  $file = $image_dir."/usr_".$this->getID()."."."jpg";
4049  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
4050  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
4051  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
4052  $upload_file = $image_dir."/upload_".$this->getID();
4053 
4054  if($a_do_update)
4055  {
4056  // remove user pref file name
4057  $this->setPref("profile_image", "");
4058  $this->update();
4059  }
4060 
4061  if (@is_file($file))
4062  {
4063  unlink($file);
4064  }
4065  if (@is_file($thumb_file))
4066  {
4067  unlink($thumb_file);
4068  }
4069  if (@is_file($xthumb_file))
4070  {
4071  unlink($xthumb_file);
4072  }
4073  if (@is_file($xxthumb_file))
4074  {
4075  unlink($xxthumb_file);
4076  }
4077  if (@is_file($upload_file))
4078  {
4079  unlink($upload_file);
4080  }
4081  }
4082 
4083 
4084  function setUserDefinedData($a_data)
4085  {
4086  if(!is_array($a_data))
4087  {
4088  return false;
4089  }
4090  foreach($a_data as $field => $data)
4091  {
4092  #$new_data[$field] = ilUtil::stripSlashes($data);
4093  // Assign it directly to avoid update problems of unchangable fields
4094  $this->user_defined_data['f_'.$field] = $data;
4095  }
4096  #$this->user_defined_data = $new_data;
4097 
4098  return true;
4099  }
4100 
4102  {
4103  return $this->user_defined_data ? $this->user_defined_data : array();
4104  }
4105 
4107  {
4108  global $ilDB;
4109 
4110  $fields = '';
4111 
4112  $field_def = array();
4113 
4114  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4115  $udata = new ilUserDefinedData($this->getId());
4116 
4117  foreach($this->user_defined_data as $field => $value)
4118  {
4119  if($field != 'usr_id')
4120  {
4121 // $field_def[$field] = array('text',$value);
4122  $udata->set($field, $value);
4123  }
4124  }
4125  $udata->update();
4126 
4127 /* if(!$field_def)
4128  {
4129  return true;
4130  }
4131 
4132  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4133  $res = $ilDB->query($query);
4134 
4135 
4136  if($res->numRows())
4137  {
4138  // Update
4139  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4140  }
4141  else
4142  {
4143  $field_def['usr_id'] = array('integer',$this->getId());
4144  $ilDB->insert('udf_data',$field_def);
4145  }
4146 */
4147  return true;
4148  }
4149 
4151  {
4152  global $ilDB;
4153 
4154  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4155  $udata = new ilUserDefinedData($this->getId());
4156 
4157 /* $query = "SELECT * FROM udf_data ".
4158  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4159 
4160  $res = $this->db->query($query);
4161  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
4162  {
4163  $this->user_defined_data = $row;
4164  }*/
4165 
4166  $this->user_defined_data = $udata->getAll();
4167 
4168  return true;
4169  }
4170 
4172  {
4173  global $ilDB;
4174 
4175 // not needed. no entry in udf_text/udf_clob means no value
4176 
4177 /* $query = "INSERT INTO udf_data (usr_id ) ".
4178  "VALUES( ".
4179  $ilDB->quote($this->getId(),'integer').
4180  ")";
4181  $res = $ilDB->manipulate($query);
4182 */
4183  return true;
4184  }
4185 
4187  {
4188  global $ilDB;
4189 
4190  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4192 
4193  // wrong place...
4194 /* $query = "DELETE FROM udf_data ".
4195  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4196  $res = $ilDB->manipulate($query);*/
4197 
4198  return true;
4199  }
4200 
4206  function getProfileAsString(&$a_language)
4207  {
4208  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4209  include_once './Services/Utilities/classes/class.ilFormat.php';
4210 
4211  global $lng,$rbacreview;
4212 
4213  $language =& $a_language;
4214  $language->loadLanguageModule('registration');
4215  $language->loadLanguageModule('crs');
4216 
4217  $body = '';
4218  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4219 
4220  if(strlen($this->getUTitle()))
4221  {
4222  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4223  }
4224  if(strlen($this->getGender()))
4225  {
4226  $gender = ($this->getGender() == 'm') ?
4227  $language->txt('gender_m') :
4228  $language->txt('gender_f');
4229  $body .= ($language->txt("gender").": ".$gender."\n");
4230  }
4231  if(strlen($this->getFirstname()))
4232  {
4233  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4234  }
4235  if(strlen($this->getLastname()))
4236  {
4237  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4238  }
4239  if(strlen($this->getInstitution()))
4240  {
4241  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4242  }
4243  if(strlen($this->getDepartment()))
4244  {
4245  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4246  }
4247  if(strlen($this->getStreet()))
4248  {
4249  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4250  }
4251  if(strlen($this->getCity()))
4252  {
4253  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4254  }
4255  if(strlen($this->getZipcode()))
4256  {
4257  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4258  }
4259  if(strlen($this->getCountry()))
4260  {
4261  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4262  }
4263  if(strlen($this->getSelectedCountry()))
4264  {
4265  $body .= ($language->txt("sel_country").": ".$this->getSelectedCountry()."\n");
4266  }
4267  if(strlen($this->getPhoneOffice()))
4268  {
4269  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4270  }
4271  if(strlen($this->getPhoneHome()))
4272  {
4273  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4274  }
4275  if(strlen($this->getPhoneMobile()))
4276  {
4277  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4278  }
4279  if(strlen($this->getFax()))
4280  {
4281  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4282  }
4283  if(strlen($this->getEmail()))
4284  {
4285  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4286  }
4287  if(strlen($this->getHobby()))
4288  {
4289  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4290  }
4291  if(strlen($this->getComment()))
4292  {
4293  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4294  }
4295  if(strlen($this->getMatriculation()))
4296  {
4297  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4298  }
4299  if(strlen($this->getCreateDate()))
4300  {
4305 
4306  $body .= ($language->txt("create_date").": ".$date."\n");
4307  }
4308 
4309  foreach($rbacreview->getGlobalRoles() as $role)
4310  {
4311  if($rbacreview->isAssigned($this->getId(),$role))
4312  {
4313  $gr[] = ilObjRole::_lookupTitle($role);
4314  }
4315  }
4316  if(count($gr))
4317  {
4318  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4319  }
4320 
4321  // Time limit
4322  if($this->getTimeLimitUnlimited())
4323  {
4324  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4325  }
4326  else
4327  {
4331  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4333 
4334  $start = new ilDateTime($this->getTimeLimitFrom(),IL_CAL_UNIX);
4335  $end = new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX);
4336 
4337  $body .= $language->txt('time_limit').': '.$start->get(IL_CAL_DATETIME);
4338  $body .= $language->txt('time_limit').': '.$end->get(IL_CAL_DATETIME);
4339 
4340 
4341  #$body .= $language->txt('time_limit').': '.$period;
4342  /*
4343  $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4344  ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4345  $language->txt('crs_to')." ".
4346  ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4347  */
4348  }
4349  return $body;
4350  }
4351 
4352  function setInstantMessengerId($a_im_type, $a_im_id)
4353  {
4354  $var = "im_".$a_im_type;
4355  $this->$var = $a_im_id;
4356  }
4357 
4358  function getInstantMessengerId($a_im_type)
4359  {
4360  $var = "im_".$a_im_type;
4361  return $this->$var;
4362  }
4363 
4364  function setDelicious($a_delicious)
4365  {
4366  $this->delicious = $a_delicious;
4367  }
4368 
4369  function getDelicious()
4370  {
4371  return $this->delicious;
4372  }
4373 
4377  function _lookupFeedHash($a_user_id, $a_create = false)
4378  {
4379  global $ilDB;
4380 
4381  if ($a_user_id > 0)
4382  {
4383  $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4384  array("integer"), array($a_user_id));
4385  if ($rec = $ilDB->fetchAssoc($set))
4386  {
4387  if (strlen($rec["feed_hash"]) == 32)
4388  {
4389  return $rec["feed_hash"];
4390  }
4391  else if($a_create)
4392  {
4393  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4394  $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4395  " WHERE usr_id = %s",
4396  array("text", "integer"),
4397  array($hash, $a_user_id));
4398  return $hash;
4399  }
4400  }
4401  }
4402 
4403  return false;
4404  }
4405 
4411  function _getFeedPass($a_user_id)
4412  {
4413  global $ilDB;
4414 
4415  if ($a_user_id > 0)
4416  {
4417  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4418  }
4419  return false;
4420  }
4421 
4427  function _setFeedPass($a_user_id, $a_password)
4428  {
4429  global $ilDB;
4430 
4431  self::_writePref($a_user_id, "priv_feed_pass",
4432  ($a_password=="") ? "" : md5($a_password));
4433  }
4434 
4444  public static function _loginExists($a_login,$a_user_id = 0)
4445  {
4446  global $ilDB;
4447 
4448  $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4449  "WHERE login = %s";
4450  $types[] = "text";
4451  $values[] = $a_login;
4452 
4453  if ($a_user_id != 0)
4454  {
4455  $q.= " AND usr_id != %s ";
4456  $types[] = "integer";
4457  $values[] = $a_user_id;
4458  }
4459 
4460  $r = $ilDB->queryF($q, $types, $values);
4461 
4462  if ($row = $ilDB->fetchAssoc($r))
4463  {
4464  return $row['usr_id'];
4465  }
4466  return false;
4467  }
4468 
4479  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4480  {
4481  global $ilDB;
4482 
4483  $res = $ilDB->queryF("SELECT * FROM usr_data ".
4484  "WHERE ext_account = %s AND auth_mode = %s",
4485  array("text", "text"),
4486  array($a_external_account, $a_auth_mode));
4487  return $ilDB->fetchAssoc($res) ? true :false;
4488  }
4489 
4497  public static function _getUsersForRole($role_id, $active = -1) {
4498  global $ilDB, $rbacreview;
4499  $data = array();
4500 
4501  $ids = $rbacreview->assignedUsers($role_id);
4502 
4503  if (count ($ids) == 0)
4504  {
4505  $ids = array (-1);
4506  }
4507 
4508  $query = "SELECT usr_data.*, usr_pref.value AS language
4509  FROM usr_data
4510  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4511  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4512  $values[] = "language";
4513  $types[] = "text";
4514 
4515 
4516  if (is_numeric($active) && $active > -1)
4517  {
4518  $query .= " AND usr_data.active = %s";
4519  $values[] = $active;
4520  $types[] = "integer";
4521  }
4522 
4523  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4524 
4525  $r = $ilDB->queryF($query, $types, $values);
4526  $data = array();
4527  while ($row = $ilDB->fetchAssoc($r))
4528  {
4529  $data[] = $row;
4530  }
4531  return $data;
4532  }
4533 
4534 
4540  public static function _getUsersForFolder ($ref_id, $active) {
4541  global $ilDB;
4542  $data = array();
4543  $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 ";
4544  $types[] = "text";
4545  $values[] = "language";
4546 
4547  if (is_numeric($active) && $active > -1)
4548  {
4549  $query .= " AND usr_data.active = %s";
4550  $values[] = $active;
4551  $types[] = "integer";
4552  }
4553 
4554  if ($ref_id != USER_FOLDER_ID)
4555  {
4556  $query.= " AND usr_data.time_limit_owner = %s";
4557  $values[] = $ref_id;
4558  $types[] = "integer";
4559  }
4560 
4561  $query .= " AND usr_data.usr_id != %s ";
4562  $values[] = ANONYMOUS_USER_ID;
4563  $types[] = "integer";
4564 
4565  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4566 
4567  $result = $ilDB->queryF($query, $types, $values);
4568  $data = array();
4569  while ($row = $ilDB->fetchAssoc($result))
4570  {
4571  array_push($data, $row);
4572  }
4573 
4574  return $data;
4575  }
4576 
4577 
4583  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4584  {
4585  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4586  }
4587 
4588 
4594  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4595  {
4596  global $rbacadmin, $rbacreview, $ilDB;
4597 
4598  // quote all ids
4599  $ids = array();
4600  foreach ($a_mem_ids as $mem_id) {
4601  $ids [] = $ilDB->quote($mem_id);
4602  }
4603 
4604  $query = "SELECT usr_data.*, usr_pref.value AS language
4605  FROM usr_data
4606  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4607  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer")."
4608  AND usr_data.usr_id != %s";
4609  $values[] = "language";
4610  $types[] = "text";
4611  $values[] = ANONYMOUS_USER_ID;
4612  $types[] = "integer";
4613 
4614  if (is_numeric($active) && $active > -1)
4615  {
4616  $query .= " AND active = %s";
4617  $values[] = $active;
4618  $types[] = "integer";
4619  }
4620 
4621  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4622  {
4623  $query.= " AND usr_data.time_limit_owner = %s";
4624  $values[] = $timelimitowner;
4625  $types[] = "integer";
4626 
4627  }
4628 
4629  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4630 
4631  $result = $ilDB->queryF($query, $types, $values);
4632  while ($row = $ilDB->fetchAssoc($result))
4633  {
4634  $mem_arr[] = $row;
4635  }
4636 
4637  return $mem_arr ? $mem_arr : array();
4638  }
4639 
4640 
4641 
4647  public static function _getUserData ($a_internalids) {
4648  global $ilDB;
4649 
4650  $ids = array();
4651  if (is_array($a_internalids)) {
4652  foreach ($a_internalids as $internalid) {
4653  if (is_numeric ($internalid))
4654  {
4655  $ids[] = $internalid;
4656  }
4657  else
4658  {
4659  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4660  if (is_numeric($parsedid) && $parsedid > 0)
4661  {
4662  $ids[] = $parsedid;
4663  }
4664  }
4665  }
4666  }
4667  if (count($ids) == 0)
4668  $ids [] = -1;
4669 
4670  $query = "SELECT usr_data.*, usr_pref.value AS language
4671  FROM usr_data
4672  LEFT JOIN usr_pref
4673  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4674  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4675  $values[] = "language";
4676  $types[] = "text";
4677 
4678  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4679 
4680  $data = array();
4681  $result = $ilDB->queryF($query, $types, $values);
4682  while ($row = $ilDB->fetchAssoc($result))
4683  {
4684  $data[] = $row;
4685  }
4686  return $data;
4687  }
4688 
4695  public static function _getPreferences ($user_id)
4696  {
4697  global $ilDB;
4698 
4699  $prefs = array();
4700 
4701  $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4702  array("integer"), array($user_id));
4703 
4704  while($row = $ilDB->fetchAssoc($r))
4705  {
4706  $prefs[$row["keyword"]] = $row["value"];
4707  }
4708 
4709  return $prefs;
4710  }
4711 
4712 
4713  public static function _resetLoginAttempts($a_usr_id)
4714  {
4715  global $ilDB;
4716 
4717  $query = "UPDATE usr_data SET login_attempts = 0 WHERE usr_id = %s";
4718  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4719 
4720  if($affected) return true;
4721  else return false;
4722  }
4723 
4724  public static function _getLoginAttempts($a_usr_id)
4725  {
4726  global $ilDB;
4727 
4728  $query = "SELECT login_attempts FROM usr_data WHERE usr_id = %s";
4729  $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4730  $record = $ilDB->fetchAssoc( $result );
4731  $login_attempts = $record['login_attempts'];
4732 
4733  return $login_attempts;
4734  }
4735 
4736  public static function _incrementLoginAttempts($a_usr_id)
4737  {
4738  global $ilDB;
4739 
4740  $query = "UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s";
4741  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4742 
4743  if($affected) return true;
4744  else return false;
4745  }
4746 
4747  public static function _setUserInactive($a_usr_id)
4748  {
4749  global $ilDB;
4750 
4751  $query = "UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s";
4752  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array(ilUtil::now(), $a_usr_id) );
4753 
4754  if($affected) return true;
4755  else return false;
4756  }
4757 
4763  public function hasPublicProfile() {
4764  return in_array($this->getPref("public_profile"), array("y", "g"));
4765  }
4766 
4772  public function getPublicName()
4773  {
4774  if ($this->hasPublicProfile())
4775  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4776  else
4777  return $this->getLogin();
4778 
4779  }
4780 
4781  public static function _writeHistory($a_usr_id, $a_login)
4782  {
4783  global $ilDB;
4784 
4785  $timestamp = time();
4786 
4787  $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4788  array('integer', 'text', 'integer'),
4789  array($a_usr_id, $a_login, $timestamp));
4790 
4791  if( $ilDB->numRows($res) == 0 )
4792  {
4793  $ilDB->manipulateF('
4794  INSERT INTO loginname_history
4795  (usr_id, login, history_date)
4796  VALUES (%s, %s, %s)',
4797  array('integer', 'text', 'integer'),
4798  array($a_usr_id, $a_login, $timestamp));
4799  }
4800 
4801  return true;
4802  }
4803 
4811  function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4812  {
4813  global $ilDB;
4814 
4815  $pd_set = new ilSetting("pd");
4816  $atime = $pd_set->get("user_activity_time") * 60;
4817  $ctime = time();
4818 
4819  if ($a_user_id == 0)
4820  {
4821  $where = "WHERE user_id != 0 AND NOT agree_date IS NULL ";
4822  $type_array = array("integer");
4823  $val_array = array(time());
4824  }
4825  else
4826  {
4827  $where = "WHERE user_id = %s ";
4828  $type_array = array("integer", "integer");
4829  $val_array = array($a_user_id, time());
4830  }
4831 
4832  $no_anonym = ($a_no_anonymous)
4833  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4834  : "";
4835 
4836  include_once './Services/User/classes/class.ilUserAccountSettings.php';
4837  if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
4838  {
4839  include_once './Services/User/classes/class.ilUserFilter.php';
4840  $user_filter = 'AND '.$ilDB->in('time_limit_owner',ilUserFilter::getInstance()->getFolderIds(),false,'integer').' ';
4841  }
4842  else
4843  {
4844  $user_filter = ' ';
4845  }
4846  $r = $ilDB->queryF($q = "SELECT count(user_id) as num,user_id,firstname,lastname,title,login,last_login,max(ctime) AS ctime ".
4847  "FROM usr_session ".
4848  "LEFT JOIN usr_data u ON user_id = u.usr_id ".
4849  "LEFT JOIN usr_pref p ON (p.usr_id = u.usr_id AND p.keyword = ".
4850  $ilDB->quote("hide_own_online_status", "text").") ".$where.
4851  "AND expires > %s ".
4852  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4853  $no_anonym.
4854  $user_filter.
4855  "GROUP BY user_id,firstname,lastname,title,login,last_login ".
4856  "ORDER BY lastname, firstname", $type_array, $val_array);
4857 
4858  while ($user = $ilDB->fetchAssoc($r))
4859  {
4860  if ($atime <= 0
4861  || $user["ctime"] + $atime > $ctime)
4862  {
4863  $users[$user["user_id"]] = $user;
4864  }
4865  }
4866 
4867  return $users ? $users : array();
4868  }
4869 
4878  function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4879  {
4880  global $ilias, $ilDB;
4881 
4882  $pd_set = new ilSetting("pd");
4883  $atime = $pd_set->get("user_activity_time") * 60;
4884  $ctime = time();
4885  $no_anonym = ($a_no_anonymous)
4886  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4887  : "";
4888 
4889  // Get a list of object id's of all courses and groups for which
4890  // the current user has local roles.
4891  // Note: we have to use DISTINCT here, because a user may assume
4892  // multiple roles in a group or a course.
4893  $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4894  "FROM rbac_ua ua ".
4895  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4896  "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4897  "JOIN tree ON tree.child = r1.ref_id ".
4898  "JOIN object_reference r2 ON r2.ref_id = tree.parent ".
4899  "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4900  "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4901  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4902  "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4903  $ilDB->quote("grp", "text").")";
4904  $r = $ilDB->query($q);
4905 
4906  while ($row = $ilDB->fetchAssoc($r))
4907  {
4908  $groups_and_courses_of_user[] = $row["obj_id"];
4909  }
4910  // If the user is not in a course or a group, he has no associated users.
4911  if (count($groups_and_courses_of_user) == 0)
4912  {
4913  $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4914  "FROM usr_session ".
4915  "JOIN usr_data ON user_id=usr_id ".
4916  "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4917  $no_anonym.
4918  " AND NOT agree_date IS NULL ".
4919  "AND expires > ".$ilDB->quote(time(), "integer")." ".
4920  "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4921  $r = $ilDB->query($q);
4922  }
4923  else
4924  {
4925  $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4926  "FROM usr_session s ".
4927  "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4928  "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
4929  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4930  "JOIN tree ON tree.child = fa.parent ".
4931  "JOIN object_reference or1 ON or1.ref_id = tree.parent ".
4932  "JOIN object_data od ON od.obj_id = or1.obj_id ".
4933  "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
4934  $ilDB->quote("hide_own_online_status", "text").") ".
4935  "WHERE s.user_id != 0 ".
4936  $no_anonym.
4937  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4938  "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
4939  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4940  " AND NOT ud.agree_date IS NULL ".
4941  "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
4942  "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4943  "ORDER BY ud.lastname, ud.firstname";
4944  $r = $ilDB->query($q);
4945  }
4946 
4947  while ($user = $ilDB->fetchAssoc($r))
4948  {
4949  if ($atime <= 0
4950  || $user["ctime"] + $atime > $ctime)
4951  {
4952  $users[$user["user_id"]] = $user;
4953  }
4954  }
4955 
4956  return $users ? $users : array();
4957  }
4958 
4965  public static function _generateRegistrationHash($a_usr_id)
4966  {
4967  global $ilDB;
4968 
4969  do
4970  {
4971  $continue = false;
4972 
4973  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
4974 
4975  $res = $ilDB->queryf('
4976  SELECT COUNT(usr_id) cnt FROM usr_data
4977  WHERE reg_hash = %s',
4978  array('text'),
4979  array($hashcode));
4980  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
4981  {
4982  if($row->cnt > 0) $continue = true;
4983  break;
4984  }
4985 
4986  if($continue) continue;
4987 
4988  $ilDB->manipulateF('
4989  UPDATE usr_data
4990  SET reg_hash = %s
4991  WHERE usr_id = %s',
4992  array('text', 'integer'),
4993  array($hashcode, (int)$a_usr_id)
4994  );
4995 
4996  break;
4997 
4998  } while(true);
4999 
5000  return $hashcode;
5001  }
5002 
5011  public static function _verifyRegistrationHash($a_hash)
5012  {
5013  global $ilDB;
5014 
5015  $res = $ilDB->queryf('
5016  SELECT usr_id, create_date FROM usr_data
5017  WHERE reg_hash = %s',
5018  array('text'),
5019  array($a_hash));
5020  while($row = $ilDB->fetchAssoc($res))
5021  {
5022  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
5023  $oRegSettigs = new ilRegistrationSettings();
5024 
5025  if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
5026  time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
5027  {
5028  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
5029  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
5030  }
5031 
5032  $ilDB->manipulateF('
5033  UPDATE usr_data
5034  SET reg_hash = %s
5035  WHERE usr_id = %s',
5036  array('text', 'integer'),
5037  array('', (int)$row['usr_id'])
5038  );
5039 
5040  return (int)$row['usr_id'];
5041  }
5042 
5043  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
5044  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
5045  }
5046 
5047  function setBirthday($a_birthday)
5048  {
5049  if (strlen($a_birthday))
5050  {
5051  $date = new ilDate($a_birthday, IL_CAL_DATE);
5052  $this->birthday = $date->get(IL_CAL_DATE);
5053  }
5054  else
5055  {
5056  $this->birthday = null;
5057  }
5058  }
5059 
5060  function getBirthday()
5061  {
5062  return $this->birthday;
5063  }
5064 
5073  public static function _getUserIdsByInactivityPeriod($period)
5074  {
5075  if( !(int)$period ) throw new ilException('no valid period given');
5076 
5077  global $ilDB;
5078 
5079  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5080 
5081  $query = "SELECT usr_id FROM usr_data WHERE last_login < %s";
5082 
5083  $res = $ilDB->queryF($query, array('timestamp'), array($date));
5084 
5085  $ids = array();
5086  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5087  {
5088  $ids[] = $row->usr_id;
5089  }
5090 
5091  return $ids;
5092  }
5093 
5102  public static function _getUserIdsByInactivationPeriod($period)
5103  {
5105  $field = 'inactivation_date';
5107 
5108  if( !(int)$period ) throw new ilException('no valid period given');
5109 
5110  global $ilDB;
5111 
5112  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5113 
5114  $query = "SELECT usr_id FROM usr_data WHERE $field < %s AND active = %s";
5115 
5116  $res = $ilDB->queryF($query, array('timestamp', 'integer'), array($date, 0));
5117 
5118  $ids = array();
5119  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5120  {
5121  $ids[] = $row->usr_id;
5122  }
5123 
5124  return $ids;
5125  }
5126 
5136  public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5137  {
5138  if($a_last_login !== null) $last_login = $a_last_login;
5139  else $last_login = date('Y-m-d H:i:s');
5140 
5141  global $ilDB;
5142 
5143  $query = "UPDATE usr_data SET last_login = %s WHERE usr_id = %s";
5144  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array($last_login, $a_usr_id) );
5145 
5146  if($affected) return $last_login;
5147  else return false;
5148  }
5149 
5150  public function resetOwner()
5151  {
5152  global $ilDB;
5153 
5154  $query = "UPDATE object_data SET owner = 0 ".
5155  "WHERE owner = ".$ilDB->quote($this->getId(),'integer');
5156  $ilDB->query($query);
5157 
5158  return true;
5159  }
5160 
5161 
5168  static function getFirstLettersOfLastnames()
5169  {
5170  global $ilDB;
5171 
5172  $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("lastname", 1, 1))." let".
5173  " FROM usr_data".
5174  " WHERE usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer").
5175  " ORDER BY let";
5176  $let_set = $ilDB->query($q);
5177 
5178  $lets = array();
5179  while ($let_rec = $ilDB->fetchAssoc($let_set))
5180  {
5181  $let[$let_rec["let"]] = $let_rec["let"];
5182  }
5183  return $let;
5184  }
5185 
5186  // begin-patch deleteProgress
5187  public static function userExists($a_usr_ids = array())
5188  {
5189  global $ilDB;
5190 
5191  $query = 'SELECT count(*) num FROM object_data od '.
5192  'JOIN usr_data ud ON obj_id = usr_id '.
5193  'WHERE '.$ilDB->in('obj_id',$a_usr_ids,false,'integer').' ';
5194  $res = $ilDB->query($query);
5195  $num_rows =$res->fetchRow(DB_FETCHMODE_OBJECT)->num;
5196  return $num_rows == count((array) $a_usr_ids);
5197  }
5198  // end-patch deleteProgress
5199 
5204  {
5205  return (boolean) $_SESSION["user_captcha_verified"];
5206  }
5207 
5213  function setCaptchaVerified($a_val)
5214  {
5215  $_SESSION["user_captcha_verified"] = $a_val;
5216  }
5217 
5225  {
5226  include_once("./Services/Export/classes/class.ilExport.php");
5227  $exp = new ilExport();
5228  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5229  ilUtil::delDir($dir, true);
5230  $title = $this->getLastname().", ".$this->getLastname()." [".$this->getLogin()."]";
5231  $exp->exportEntity("personal_data", $this->getId(), "4.3.0",
5232  "Services/User", $title, $dir);
5233  }
5234 
5242  {
5243  include_once("./Services/Export/classes/class.ilExport.php");
5244  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5245  if (!is_dir($dir))
5246  {
5247  return "";
5248  }
5249  foreach(ilUtil::getDir($dir) as $entry)
5250  {
5251  if (is_int(strpos($entry["entry"], ".zip")))
5252  {
5253  return $entry["entry"];
5254  }
5255  }
5256 
5257  return "";
5258  }
5259 
5267  {
5268  include_once("./Services/Export/classes/class.ilExport.php");
5269  $file = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data").
5270  "/".$this->getPersonalDataExportFile();
5271  if (is_file($file))
5272  {
5274  }
5275  }
5276 
5283  function importPersonalData($a_file, $a_profile_data, $a_settings,
5284  $a_bookmarks, $a_notes, $a_calendar)
5285  {
5286  include_once("./Services/Export/classes/class.ilImport.php");
5287  $imp = new ilImport();
5288  if (!$a_profile_data)
5289  {
5290  $imp->addSkipEntity("Services/User", "usr_profile");
5291  }
5292  if (!$a_settings)
5293  {
5294  $imp->addSkipEntity("Services/User", "usr_setting");
5295  }
5296  if (!$a_bookmarks)
5297  {
5298  $imp->addSkipEntity("Services/Bookmarks", "bookmarks");
5299  }
5300  if (!$a_notes)
5301  {
5302  $imp->addSkipEntity("Services/Notes", "user_notes");
5303  }
5304  if (!$a_calendar)
5305  {
5306  $imp->addSkipEntity("Services/Calendar", "calendar");
5307  }
5308  $imp->importEntity($a_file["tmp_name"], $a_file["name"], "personal_data",
5309  "Services/User");
5310  }
5311 
5317  private static function initInactivationDate($usrIds)
5318  {
5319  global $ilDB;
5320 
5321  $NOW = $ilDB->now();
5322 
5323  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5324 
5325  $queryString = "
5326  UPDATE usr_data
5327  SET inactivation_date = $NOW
5328  WHERE inactivation_date IS NULL
5329  AND $usrId_IN_usrIds
5330  ";
5331 
5332  $ilDB->manipulate($queryString);
5333  }
5334 
5340  private static function resetInactivationDate($usrIds)
5341  {
5342  global $ilDB;
5343 
5344  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5345 
5346  $queryString = "
5347  UPDATE usr_data
5348  SET inactivation_date = NULL
5349  WHERE $usrId_IN_usrIds
5350  ";
5351 
5352  $ilDB->manipulate($queryString);
5353  }
5354 
5361  {
5362  $this->inactivation_date = $inactivation_date;
5363  }
5364 
5370  public function getInactivationDate()
5371  {
5372  return $this->inactivation_date;
5373  }
5374 
5375 
5379  public function isAnonymous()
5380  {
5381  return $this->getId() == ANONYMOUS_USER_ID;
5382  }
5383 
5384  public function activateDeletionFlag()
5385  {
5386  $this->writePref("delete_flag", true);
5387  }
5388 
5389  public function removeDeletionFlag()
5390  {
5391  $this->writePref("delete_flag", false);
5392  }
5393 
5394  public function hasDeletionFlag()
5395  {
5396  return (bool)$this->getPref("delete_flag");
5397  }
5398 
5402  public function setIsSelfRegistered($status)
5403  {
5404  $this->is_self_registered = (bool) $status;
5405  }
5406 
5407  public function isSelfRegistered()
5408  {
5409  return (bool) $this->is_self_registered;
5410  }
5411 
5412 } // END class ilObjUser
5413 ?>