ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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_CRYPTED", "crypted");
6 
7 
8 require_once "./Services/Object/classes/class.ilObject.php";
9 require_once './Services/User/exceptions/class.ilUserException.php';
10 
23 class ilObjUser extends ilObject
24 {
29  // personal data
30 
31  var $login; // username in system
32 
36  protected $passwd; // password encoded in the format specified by $passwd_type
37 
41  protected $passwd_type;
42  // specifies the password format.
43  // value: IL_PASSWD_PLAIN or IL_PASSWD_CRYPTED.
44 
45  // Differences between password format in class ilObjUser and
46  // in table usr_data:
47  // Class ilObjUser supports two different password types
48  // (plain and crypted) and it uses the variables $passwd
49  // and $passwd_type to store them.
50  // Table usr_data supports only two different password types
51  // (md5 and bcrypt) and it uses the columns "passwd" and "passwd_type" to store them.
52  // The conversion between these two storage layouts is done
53  // in the methods that perform SQL statements. All other
54  // methods work exclusively with the $passwd and $passwd_type
55  // variables.
56 
62 
67  protected $password_salt = null;
68 
69  var $gender; // 'm' or 'f'
70  var $utitle; // user title (keep in mind, that we derive $title from object also!)
72  var $lastname;
73  protected $birthday;
74  var $fullname; // title + firstname + lastname in one string
75  //var $archive_dir = "./image"; // point to image file (should be flexible)
76  // address data
79  var $street;
80  var $city;
81  var $zipcode;
82  var $country;
87  var $fax;
88  var $email;
89  var $hobby;
92  var $approve_date = null;
93  var $agree_date = null;
94  var $active;
95  var $client_ip; // client ip to check before login
96  var $auth_mode; // authentication mode
97 
98  var $im_icq;
99  var $im_yahoo;
100  var $im_msn;
101  var $im_aim;
104  var $im_voip;
105 
110 
113 
114  var $user_defined_data = array();
115 
121  var $prefs;
122 
128  var $skin;
129 
130 
137 
143  var $ilias;
144 
147 
151  protected static $personal_image_cache = array();
152 
158  protected $inactivation_date = null;
159 
164  private $is_self_registered = false;
165 
166  protected $interests_general; // [array]
167  protected $interests_help_offered; // [array]
168  protected $interests_help_looking; // [array]
169 
175  public function __construct($a_user_id = 0, $a_call_by_reference = false)
176  {
177  global $ilias,$ilDB;
178 
179  // init variables
180  $this->ilias =& $ilias;
181  $this->db =& $ilDB;
182 
183  $this->type = "usr";
184  parent::__construct($a_user_id, $a_call_by_reference);
185  $this->auth_mode = "default";
186  $this->passwd_type = IL_PASSWD_PLAIN;
187 
188  // for gender selection. don't change this
189  /*$this->gender = array(
190  'm' => "salutation_m",
191  'f' => "salutation_f"
192  );*/
193  if ($a_user_id > 0)
194  {
195  $this->setId($a_user_id);
196  $this->read();
197  }
198  else
199  {
200  // TODO: all code in else-structure doesn't belongs in class user !!!
201  //load default data
202  $this->prefs = array();
203  //language
204  $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
205 
206  //skin and pda support
207  $this->skin = $this->ilias->ini->readVariable("layout","skin");
208 
209  $this->prefs["skin"] = $this->skin;
210 // $this->prefs["show_users_online"] = "y";
211 
212  //style (css)
213  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
214  }
215  }
216 
221  function read()
222  {
223  global $ilErr, $ilDB;
224 
225  // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
226  // use (3.11.0 alpha)
227  /*$q = "SELECT * FROM usr_data ".
228  "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
229  "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
230  $r = $ilDB->queryF("SELECT * FROM usr_data ".
231  "WHERE usr_id= %s", array("integer"), array($this->id));
232 
233  if ($data = $ilDB->fetchAssoc($r))
234  {
235  // convert password storage layout used by table usr_data into
236  // storage layout used by class ilObjUser
237  $data["passwd_type"] = IL_PASSWD_CRYPTED;
238 
239  // this assign must not be set via $this->assignData($data)
240  // because this method will be called on profile updates and
241  // would set this values to 0, because they arent posted from form
242  $this->setLastPasswordChangeTS( $data['last_password_change'] );
243  $this->setLoginAttempts( $data['login_attempts'] );
244 
245 
246  // fill member vars in one shot
247  $this->assignData($data);
248 
249  //get userpreferences from usr_pref table
250  $this->readPrefs();
251 
252  //set language to default if not set
253  if ($this->prefs["language"] == "")
254  {
255  $this->prefs["language"] = $this->oldPrefs["language"];
256  }
257 
258  //check skin-setting
259  include_once("./Services/Style/classes/class.ilStyleDefinition.php");
260  if ($this->prefs["skin"] == "" ||
261  !ilStyleDefinition::skinExists($this->prefs["skin"]))
262  {
263  $this->prefs["skin"] = $this->oldPrefs["skin"];
264  }
265 
266  $this->skin = $this->prefs["skin"];
267 
268  //check style-setting (skins could have more than one stylesheet
269  if ($this->prefs["style"] == "" ||
270  !ilStyleDefinition::skinExists($this->skin, $this->prefs["style"]))
271  {
272  //load default (css)
273  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
274  }
275 
276  if (empty($this->prefs["hits_per_page"]))
277  {
278  $this->prefs["hits_per_page"] = 10;
279  }
280 
281  }
282  else
283  {
284  $ilErr->raiseError("<b>Error: There is no dataset with id ".
285  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
286  "<br />Line: ".__LINE__, $ilErr->FATAL);
287  }
288 
289  $this->readMultiTextFields();
290  $this->readUserDefinedFields();
291 
292  parent::read();
293  }
294 
298  public function getPasswordEncodingType()
299  {
301  }
302 
306  public function setPasswordEncodingType($password_encryption_type)
307  {
308  $this->password_encoding_type = $password_encryption_type;
309  }
310 
314  public function getPasswordSalt()
315  {
316  return $this->password_salt;
317  }
318 
323  {
324  $this->password_salt = $password_salt;
325  }
326 
332  function assignData($a_data)
333  {
334  global $ilErr, $ilDB, $lng;
335 
336  // basic personal data
337  $this->setLogin($a_data["login"]);
338  if (! $a_data["passwd_type"])
339  {
340  $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
341  $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
342  .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
343  }
344  if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
345  {
346  $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
347  }
348 
349  $this->setGender($a_data["gender"]);
350  $this->setUTitle($a_data["title"]);
351  $this->setFirstname($a_data["firstname"]);
352  $this->setLastname($a_data["lastname"]);
353  $this->setFullname();
354  if (!is_array($a_data['birthday']))
355  {
356  $this->setBirthday($a_data['birthday']);
357  }
358  else
359  {
360  $this->setBirthday(null);
361  }
362 
363  // address data
364  $this->setInstitution($a_data["institution"]);
365  $this->setDepartment($a_data["department"]);
366  $this->setStreet($a_data["street"]);
367  $this->setCity($a_data["city"]);
368  $this->setZipcode($a_data["zipcode"]);
369  $this->setCountry($a_data["country"]);
370  $this->setSelectedCountry($a_data["sel_country"]);
371  $this->setPhoneOffice($a_data["phone_office"]);
372  $this->setPhoneHome($a_data["phone_home"]);
373  $this->setPhoneMobile($a_data["phone_mobile"]);
374  $this->setFax($a_data["fax"]);
375  $this->setMatriculation($a_data["matriculation"]);
376  $this->setEmail($a_data["email"]);
377  $this->setHobby($a_data["hobby"]);
378  $this->setClientIP($a_data["client_ip"]);
379  $this->setPasswordEncodingType($a_data['passwd_enc_type']);
380  $this->setPasswordSalt($a_data['passwd_salt']);
381 
382  // instant messenger data
383  $this->setInstantMessengerId('icq',$a_data["im_icq"]);
384  $this->setInstantMessengerId('yahoo',$a_data["im_yahoo"]);
385  $this->setInstantMessengerId('msn',$a_data["im_msn"]);
386  $this->setInstantMessengerId('aim',$a_data["im_aim"]);
387  $this->setInstantMessengerId('skype',$a_data["im_skype"]);
388  $this->setInstantMessengerId('jabber',$a_data["im_jabber"]);
389  $this->setInstantMessengerId('voip',$a_data["im_voip"]);
390 
391  // other data
392  $this->setDelicious($a_data["delicious"]);
393  $this->setLatitude($a_data["latitude"]);
394  $this->setLongitude($a_data["longitude"]);
395  $this->setLocationZoom($a_data["loc_zoom"]);
396 
397  // system data
398  $this->setLastLogin($a_data["last_login"]);
399  $this->setLastUpdate($a_data["last_update"]);
400  $this->create_date = $a_data["create_date"];
401  $this->setComment($a_data["referral_comment"]);
402  $this->approve_date = $a_data["approve_date"];
403  $this->active = $a_data["active"];
404  $this->agree_date = $a_data["agree_date"];
405 
406  $this->setInactivationDate($a_data["inactivation_date"]);
407 
408  // time limitation
409  $this->setTimeLimitOwner($a_data["time_limit_owner"]);
410  $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
411  $this->setTimeLimitFrom($a_data["time_limit_from"]);
412  $this->setTimeLimitUntil($a_data["time_limit_until"]);
413  $this->setTimeLimitMessage($a_data['time_limit_message']);
414 
415  // user profile incomplete?
416  $this->setProfileIncomplete($a_data["profile_incomplete"]);
417 
418  //authentication
419  $this->setAuthMode($a_data['auth_mode']);
420  $this->setExternalAccount($a_data['ext_account']);
421 
422  $this->setIsSelfRegistered((bool)$a_data['is_self_registered']);
423  }
424 
431  public function saveAsNew($a_from_formular = true)
432  {
433  global $ilAppEventHandler;
434 
439  global $ilErr, $ilDB;
440 
441  switch ($this->passwd_type)
442  {
443  case IL_PASSWD_PLAIN:
444  if(strlen($this->passwd))
445  {
446  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
447  ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
448  $pw_value = $this->getPasswd();
449  }
450  else
451  {
452  $pw_value = $this->passwd;
453  }
454  break;
455 
456  case IL_PASSWD_CRYPTED:
457  $pw_value = $this->passwd;
458  break;
459 
460  default :
461  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
462  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
463  "<br />Line: ".__LINE__, $ilErr->FATAL);
464  }
465 
466  if( !$this->active )
467  {
468  $this->setInactivationDate( ilUtil::now() );
469  }
470  else
471  {
472  $this->setInactivationDate(null);
473  }
474 
475  $insert_array = array(
476  "usr_id" => array("integer", $this->id),
477  "login" => array("text", $this->login),
478  "passwd" => array("text", $pw_value),
479  'passwd_enc_type' => array("text", $this->getPasswordEncodingType()),
480  'passwd_salt' => array("text", $this->getPasswordSalt()),
481  "firstname" => array("text", $this->firstname),
482  "lastname" => array("text", $this->lastname),
483  "title" => array("text", $this->utitle),
484  "gender" => array("text", $this->gender),
485  "email" => array("text", trim($this->email)),
486  "hobby" => array("text", (string) $this->hobby),
487  "institution" => array("text", $this->institution),
488  "department" => array("text", $this->department),
489  "street" => array("text", $this->street),
490  "city" => array("text", $this->city),
491  "zipcode" => array("text", $this->zipcode),
492  "country" => array("text", $this->country),
493  "sel_country" => array("text", $this->sel_country),
494  "phone_office" => array("text", $this->phone_office),
495  "phone_home" => array("text", $this->phone_home),
496  "phone_mobile" => array("text", $this->phone_mobile),
497  "fax" => array("text", $this->fax),
498  "birthday" => array('date', $this->getBirthday()),
499  "last_login" => array("timestamp", null),
500  "last_update" => array("timestamp", ilUtil::now()),
501  "create_date" => array("timestamp", ilUtil::now()),
502  "referral_comment" => array("text", $this->referral_comment),
503  "matriculation" => array("text", $this->matriculation),
504  "client_ip" => array("text", $this->client_ip),
505  "approve_date" => array("timestamp", $this->approve_date),
506  "agree_date" => array("timestamp", $this->agree_date),
507  "active" => array("integer", (int) $this->active),
508  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
509  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
510  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
511  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
512  "auth_mode" => array("text", $this->getAuthMode()),
513  "ext_account" => array("text", $this->getExternalAccount()),
514  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
515  "im_icq" => array("text", $this->im_icq),
516  "im_yahoo" => array("text", $this->im_yahoo),
517  "im_msn" => array("text", $this->im_msn),
518  "im_aim" => array("text", $this->im_aim),
519  "im_skype" => array("text", $this->im_skype),
520  "delicious" => array("text", $this->delicious),
521  "latitude" => array("text", $this->latitude),
522  "longitude" => array("text", $this->longitude),
523  "loc_zoom" => array("integer", (int) $this->loc_zoom),
524  "last_password_change" => array("integer", (int) $this->last_password_change_ts),
525  "im_jabber" => array("text", $this->im_jabber),
526  "im_voip" => array("text", $this->im_voip),
527  'inactivation_date' => array('timestamp', $this->inactivation_date),
528  'is_self_registered' => array('integer', (int)$this->is_self_registered)
529  );
530  $ilDB->insert("usr_data", $insert_array);
531 
532  $this->updateMultiTextFields(true);
533 
534  // add new entry in usr_defined_data
535  $this->addUserDefinedFieldEntry();
536  // ... and update
537  $this->updateUserDefinedFields();
538 
539  // CREATE ENTRIES FOR MAIL BOX
540  include_once ("Services/Mail/classes/class.ilMailbox.php");
541  $mbox = new ilMailbox($this->id);
542  $mbox->createDefaultFolder();
543 
544  include_once "Services/Mail/classes/class.ilMailOptions.php";
545  $mail_options = new ilMailOptions($this->id);
546  $mail_options->createMailOptionsEntry();
547 
548  // create personal bookmark folder tree
549  include_once "./Services/Bookmarks/classes/class.ilBookmarkFolder.php";
550  $bmf = new ilBookmarkFolder(0, $this->id);
551  $bmf->createNewBookmarkTree();
552 
553  $ilAppEventHandler->raise("Services/User", "afterCreate",
554  array("user_obj" => $this));
555 
556  }
557 
561  public function update()
562  {
568  global $ilErr, $ilDB, $ilAppEventHandler;
569 
570  $this->syncActive();
571 
572  if( $this->getStoredActive($this->id) && !$this->active )
573  {
574  $this->setInactivationDate( ilUtil::now() );
575  }
576  else if($this->active)
577  {
578  $this->setInactivationDate(null);
579  }
580 
581  $update_array = array(
582  "gender" => array("text", $this->gender),
583  "title" => array("text", $this->utitle),
584  "firstname" => array("text", $this->firstname),
585  "lastname" => array("text", $this->lastname),
586  "email" => array("text", trim($this->email)),
587  "birthday" => array('date', $this->getBirthday()),
588  "hobby" => array("text", $this->hobby),
589  "institution" => array("text", $this->institution),
590  "department" => array("text", $this->department),
591  "street" => array("text", $this->street),
592  "city" => array("text", $this->city),
593  "zipcode" => array("text", $this->zipcode),
594  "country" => array("text", $this->country),
595  "sel_country" => array("text", $this->sel_country),
596  "phone_office" => array("text", $this->phone_office),
597  "phone_home" => array("text", $this->phone_home),
598  "phone_mobile" => array("text", $this->phone_mobile),
599  "fax" => array("text", $this->fax),
600  "referral_comment" => array("text", $this->referral_comment),
601  "matriculation" => array("text", $this->matriculation),
602  "client_ip" => array("text", $this->client_ip),
603  "approve_date" => array("timestamp", $this->approve_date),
604  "active" => array("integer", $this->active),
605  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
606  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
607  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
608  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
609  "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
610  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
611  "auth_mode" => array("text", $this->getAuthMode()),
612  "ext_account" => array("text", $this->getExternalAccount()),
613  "im_icq" => array("text", $this->im_icq),
614  "im_yahoo" => array("text", $this->im_yahoo),
615  "im_msn" => array("text", $this->im_msn),
616  "im_aim" => array("text", $this->im_aim),
617  "im_skype" => array("text", $this->im_skype),
618  "delicious" => array("text", $this->delicious),
619  "latitude" => array("text", $this->latitude),
620  "longitude" => array("text", $this->longitude),
621  "loc_zoom" => array("integer", (int) $this->loc_zoom),
622  "last_password_change" => array("integer", $this->last_password_change_ts),
623  "im_jabber" => array("text", $this->im_jabber),
624  "im_voip" => array("text", $this->im_voip),
625  "last_update" => array("timestamp", ilUtil::now()),
626  'inactivation_date' => array('timestamp', $this->inactivation_date)
627  );
628 
629  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null))
630  {
631  $update_array["agree_date"] = array("timestamp", $this->agree_date);
632  }
633  switch ($this->passwd_type)
634  {
635  case IL_PASSWD_PLAIN:
636  if(strlen($this->passwd))
637  {
638  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
639  ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
640  $update_array['passwd'] = array('text', $this->getPasswd());
641  }
642  else
643  {
644  $update_array["passwd"] = array("text", (string) $this->passwd);
645  }
646  break;
647 
648  case IL_PASSWD_CRYPTED:
649  $update_array["passwd"] = array("text", (string) $this->passwd);
650  break;
651 
652  default :
653  $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
654  get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
655  }
656 
657  $update_array['passwd_enc_type'] = array('text', $this->getPasswordEncodingType());
658  $update_array['passwd_salt'] = array('text', $this->getPasswordSalt());
659 
660  $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
661 
662  $this->updateMultiTextFields();
663 
664  $this->writePrefs();
665 
666  // update user defined fields
667  $this->updateUserDefinedFields();
668 
669  parent::update();
670  parent::updateOwner();
671 
672  $this->read();
673 
674  $ilAppEventHandler->raise("Services/User", "afterUpdate",
675  array("user_obj" => $this));
676 
677  return true;
678  }
679 
683  function writeAccepted()
684  {
685  global $ilDB;
686 
687  $ilDB->manipulateF("UPDATE usr_data SET agree_date = ".$ilDB->now().
688  " WHERE usr_id = %s", array("integer"), array($this->getId()));
689  }
690 
694  private static function _lookup($a_user_id, $a_field)
695  {
696  global $ilDB;
697 
698  $res = $ilDB->queryF("SELECT ".$a_field." FROM usr_data WHERE usr_id = %s",
699  array("integer"), array($a_user_id));
700 
701  while($set = $ilDB->fetchAssoc($res))
702  {
703  return $set[$a_field];
704  }
705  return false;
706  }
707 
711  function _lookupFullname($a_user_id)
712  {
713  global $ilDB;
714 
715  $set = $ilDB->queryF("SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
716  array("integer"), array($a_user_id));
717 
718  if ($rec = $ilDB->fetchAssoc($set))
719  {
720  if ($rec["title"])
721  {
722  $fullname = $rec["title"]." ";
723  }
724  if ($rec["firstname"])
725  {
726  $fullname .= $rec["firstname"]." ";
727  }
728  if ($rec["lastname"])
729  {
730  $fullname .= $rec["lastname"];
731  }
732  }
733  return $fullname;
734  }
735 
739  function _lookupIm($a_user_id, $a_type)
740  {
741  return ilObjUser::_lookup($a_user_id, "im_".$a_type);
742  }
743 
744 
748  function _lookupEmail($a_user_id)
749  {
750  return ilObjUser::_lookup($a_user_id, "email");
751  }
752 
756  public static function _lookupGender($a_user_id)
757  {
758  return ilObjUser::_lookup($a_user_id, "gender");
759  }
760 
767  function _lookupClientIP($a_user_id)
768  {
769  return ilObjUser::_lookup($a_user_id, "client_ip");
770  }
771 
772 
778  public static function _lookupName($a_user_id)
779  {
780  global $ilDB;
781 
782  $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
783  array("integer"), array($a_user_id));
784  $user_rec = $ilDB->fetchAssoc($res);
785  return array("user_id" => $a_user_id,
786  "firstname" => $user_rec["firstname"],
787  "lastname" => $user_rec["lastname"],
788  "title" => $user_rec["title"],
789  "login" => $user_rec["login"]);
790  }
791 
795  function _lookupFields($a_user_id)
796  {
797  global $ilDB;
798 
799  $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
800  array("integer"), array($a_user_id));
801  $user_rec = $ilDB->fetchAssoc($res);
802  return $user_rec;
803  }
804 
808  public static function _lookupLogin($a_user_id)
809  {
810  return ilObjUser::_lookup($a_user_id, "login");
811  }
812 
816  function _lookupExternalAccount($a_user_id)
817  {
818  return ilObjUser::_lookup($a_user_id, "ext_account");
819  }
820 
824  public static function _lookupId($a_user_str)
825  {
826  global $ilDB;
827 
828  if (!is_array($a_user_str))
829  {
830  $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
831  array("text"), array($a_user_str));
832  $user_rec = $ilDB->fetchAssoc($res);
833  return $user_rec["usr_id"];
834  }
835  else
836  {
837  $set = $ilDB->query("SELECT usr_id FROM usr_data ".
838  " WHERE ".$ilDB->in("login", $a_user_str, false, "text")
839  );
840  $ids = array();
841  while ($rec = $ilDB->fetchAssoc($set))
842  {
843  $ids[] = $rec["usr_id"];
844  }
845  return $ids;
846  }
847  }
848 
852  function _lookupLastLogin($a_user_id)
853  {
854  return ilObjUser::_lookup($a_user_id, "last_login");
855  }
856 
857 
863  function refreshLogin()
864  {
865  global $ilDB;
866 
867  $ilDB->manipulateF("UPDATE usr_data SET ".
868  "last_login = ".$ilDB->now().
869  " WHERE usr_id = %s",
870  array("integer"), array($this->id));
871  }
872 
878  public function replacePassword($md5_encoded_password)
879  {
883  global $ilDB;
884 
885  $this->setPasswd($md5_encoded_password, IL_PASSWD_CRYPTED);
886  $this->setPasswordEncodingType('md5');
887 
888  $ilDB->manipulateF(
889  'UPDATE usr_data
890  SET passwd = %s, passwd_enc_type = %s
891  WHERE usr_id = %s',
892  array('text', 'text', 'integer'),
893  array($this->getPasswd(), $this->getPasswordEncodingType(), $this->getId())
894  );
895 
896  return true;
897  }
898 
906  public function resetPassword($raw, $raw_retype)
907  {
911  global $ilDB;
912 
913  if(func_num_args() != 2)
914  {
915  return false;
916  }
917 
918  if(!isset($raw) || !isset($raw_retype))
919  {
920  return false;
921  }
922 
923  if($raw != $raw_retype)
924  {
925  return false;
926  }
927 
928  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
929  ilUserPasswordManager::getInstance()->encodePassword($this, $raw);
930 
931  $ilDB->manipulateF(
932  'UPDATE usr_data
933  SET passwd = %s, passwd_enc_type = %s, passwd_salt = %s
934  WHERE usr_id = %s',
935  array('text', 'text', 'text', 'integer'),
936  array($this->getPasswd(), $this->getPasswordEncodingType(), $this->getPasswordSalt(), $this->getId())
937  );
938 
939  return true;
940  }
941 
952  public static function _doesLoginnameExistInHistory($a_login)
953  {
954  global $ilDB;
955 
956  $res = $ilDB->queryF('
957  SELECT * FROM loginname_history
958  WHERE login = %s',
959  array('text'), array($a_login));
960 
961  return $ilDB->fetchAssoc($res) ? true : false;
962  }
963 
976  public static function _getLastHistoryDataByUserId($a_usr_id)
977  {
978  global $ilDB;
979 
980  $ilDB->setLimit(1, 0);
981  $res = $ilDB->queryF('
982  SELECT login, history_date FROM loginname_history
983  WHERE usr_id = %s ORDER BY history_date DESC',
984  array('integer'), array($a_usr_id));
985  $row = $ilDB->fetchAssoc($res);
986  if(!is_array($row) || !count($row)) throw new ilUserException('');
987 
988  return array(
989  $row['login'], $row['history_date']
990  );
991  }
992 
1000  function updateLogin($a_login)
1001  {
1002  global $ilDB, $ilSetting;
1003 
1004  if(func_num_args() != 1)
1005  {
1006  return false;
1007  }
1008 
1009  if(!isset($a_login))
1010  {
1011  return false;
1012  }
1013 
1014  $former_login = self::_lookupLogin($this->getId());
1015 
1016  // Update not necessary
1017  if(0 == strcmp($a_login, $former_login))
1018  {
1019  return false;
1020  }
1021 
1022  try
1023  {
1024  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1025  }
1026  catch(ilUserException $e) { $last_history_entry = null; }
1027 
1028  // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1029  if((int)$ilSetting->get('allow_change_loginname') &&
1030  (int)$ilSetting->get('reuse_of_loginnames') == 0 &&
1031  self::_doesLoginnameExistInHistory($a_login))
1032  {
1033  throw new ilUserException($this->lng->txt('loginname_already_exists'));
1034  }
1035  else if((int)$ilSetting->get('allow_change_loginname') &&
1036  (int)$ilSetting->get('loginname_change_blocking_time') &&
1037  is_array($last_history_entry) &&
1038  $last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time') > time())
1039  {
1040  include_once 'Services/Calendar/classes/class.ilDate.php';
1041  throw new ilUserException(
1042  sprintf(
1043  $this->lng->txt('changing_loginname_not_possible_info'),
1045  new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1047  new ilDateTime(($last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX))
1048  )
1049  );
1050  }
1051  else
1052  {
1053  // log old loginname in history
1054  if((int)$ilSetting->get('allow_change_loginname') &&
1055  (int)$ilSetting->get('create_history_loginname'))
1056  {
1057  ilObjUser::_writeHistory($this->getId(), $former_login);
1058  }
1059 
1060  //update login
1061  $this->login = $a_login;
1062 
1063  $ilDB->manipulateF('
1064  UPDATE usr_data
1065  SET login = %s
1066  WHERE usr_id = %s',
1067  array('text', 'integer'), array($this->getLogin(), $this->getId()));
1068  }
1069 
1070  return true;
1071  }
1072 
1079  function writePref($a_keyword, $a_value)
1080  {
1081  self::_writePref($this->id, $a_keyword, $a_value);
1082  $this->setPref($a_keyword, $a_value);
1083  }
1084 
1085 
1091  function deletePref($a_keyword)
1092  {
1093  self::_deletePref($this->getId(), $a_keyword);
1094  }
1095 
1101  public static function _deletePref($a_user_id, $a_keyword)
1102  {
1106  global $ilDB;
1107 
1108  $ilDB->manipulateF(
1109  'DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s',
1110  array('integer', 'text'),
1111  array($a_user_id, $a_keyword)
1112  );
1113  }
1114 
1120  function _deleteAllPref($a_user_id)
1121  {
1122  global $ilDB;
1123 
1124  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1125  array("integer"), array($a_user_id));
1126  }
1127 
1134  public static function _writePref($a_usr_id, $a_keyword, $a_value)
1135  {
1136  global $ilDB;
1137  $ilDB->replace("usr_pref",
1138  array(
1139  "usr_id" => array("integer", $a_usr_id),
1140  "keyword" => array("text", $a_keyword),
1141  ),
1142  array(
1143  "value" => array("text",$a_value)
1144  )
1145  );
1146 
1147  /*
1148  self::_deletePref($a_usr_id, $a_keyword);
1149  if(strlen($a_value))
1150  {
1151  $ilDB->manipulateF(
1152  'INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s, %s, %s)',
1153  array('integer', 'text', 'text'),
1154  array($a_usr_id, $a_keyword, $a_value)
1155  );
1156  }*/
1157  }
1158 
1163  function writePrefs()
1164  {
1165  global $ilDB;
1166 
1167  ilObjUser::_deleteAllPref($this->id);
1168  foreach ($this->prefs as $keyword => $value)
1169  {
1170  self::_writePref($this->id, $keyword, $value);
1171  }
1172  }
1173 
1180  public function getTimeZone()
1181  {
1182  if($tz = $this->getPref('user_tz'))
1183  {
1184  return $tz;
1185  }
1186  else
1187  {
1188  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1189  $settings = ilCalendarSettings::_getInstance();
1190  return $settings->getDefaultTimeZone();
1191  }
1192  }
1193 
1200  public function getTimeFormat()
1201  {
1202  if($format = $this->getPref('time_format'))
1203  {
1204  return $format;
1205  }
1206  else
1207  {
1208  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1209  $settings = ilCalendarSettings::_getInstance();
1210  return $settings->getDefaultTimeFormat();
1211  }
1212  }
1213 
1220  public function getDateFormat()
1221  {
1222  if($format = $this->getPref('date_format'))
1223  {
1224  return $format;
1225  }
1226  else
1227  {
1228  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1229  $settings = ilCalendarSettings::_getInstance();
1230  return $settings->getDefaultDateFormat();
1231  }
1232  }
1233 
1240  function setPref($a_keyword, $a_value)
1241  {
1242  if ($a_keyword != "")
1243  {
1244  $this->prefs[$a_keyword] = $a_value;
1245  }
1246  }
1247 
1253  function getPref($a_keyword)
1254  {
1255  if (array_key_exists($a_keyword, $this->prefs))
1256  {
1257  return $this->prefs[$a_keyword];
1258  }
1259  else
1260  {
1261  return FALSE;
1262  }
1263  }
1264 
1265  function _lookupPref($a_usr_id,$a_keyword)
1266  {
1267  global $ilDB;
1268 
1269  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1270  "AND keyword = ".$ilDB->quote($a_keyword, "text");
1271  $res = $ilDB->query($query);
1272 
1273  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1274  {
1275  return $row->value;
1276  }
1277  return false;
1278  }
1279 
1284  function readPrefs()
1285  {
1286  global $ilDB;
1287 
1288  if (is_array($this->prefs))
1289  {
1290  $this->oldPrefs = $this->prefs;
1291  }
1292 
1293  $this->prefs = ilObjUser::_getPreferences($this->id);
1294  }
1295 
1301  function delete()
1302  {
1303  global $rbacadmin, $ilDB;
1304 
1305  // deassign from ldap groups
1306  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1308  $mapping->deleteUser($this->getId());
1309 
1310  // remove mailbox / update sent mails
1311  include_once ("Services/Mail/classes/class.ilMailbox.php");
1312  $mailbox = new ilMailbox($this->getId());
1313  $mailbox->delete();
1314  $mailbox->updateMailsOfDeletedUser($this->getLogin());
1315 
1316  // delete feed blocks on personal desktop
1317  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1318  $costum_block = new ilCustomBlock();
1319  $costum_block->setContextObjId($this->getId());
1320  $costum_block->setContextObjType("user");
1321  $c_blocks = $costum_block->queryBlocksForContext();
1322  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1323  foreach($c_blocks as $c_block)
1324  {
1325  if ($c_block["type"] == "pdfeed")
1326  {
1327  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1328  $fb->delete();
1329  }
1330  }
1331 
1332 
1333  // delete block settings
1334  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1336 
1337  // delete user_account
1338  $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1339  array("integer"), array($this->getId()));
1340 
1341  $this->deleteMultiTextFields();
1342 
1343  // delete user_prefs
1344  ilObjUser::_deleteAllPref($this->getId());
1345 
1346  $this->removeUserPicture(false); // #8597
1347 
1348  // delete user_session
1349  include_once("./Services/Authentication/classes/class.ilSession.php");
1351 
1352  // remove user from rbac
1353  $rbacadmin->removeUser($this->getId());
1354 
1355  // remove bookmarks
1356  // TODO: move this to class.ilBookmarkFolder
1357  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1358  $ilDB->quote($this->getId(), "integer");
1359  $ilDB->manipulate($q);
1360 
1361  $q = "DELETE FROM bookmark_data WHERE user_id = ".
1362  $ilDB->quote($this->getId(), "integer");
1363  $ilDB->manipulate($q);
1364 
1365  // DELETE FORUM ENTRIES (not complete in the moment)
1366  include_once './Modules/Forum/classes/class.ilObjForum.php';
1367  ilObjForum::_deleteUser($this->getId());
1368 
1369  // Delete link check notify entries
1370  include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
1372 
1373  // Delete crs entries
1374  include_once './Modules/Course/classes/class.ilObjCourse.php';
1375  ilObjCourse::_deleteUser($this->getId());
1376 
1377  // Delete user tracking
1378  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1380 
1381  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1383 
1384  // Delete Tracking data SCORM 2004 RTE
1385  include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1387 
1388  // Delete Tracking data SCORM 1.2 RTE
1389  include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1391 
1392  // remove all notifications
1393  include_once "./Services/Notification/classes/class.ilNotification.php";
1395 
1396  // remove portfolios
1397  include_once "./Modules/Portfolio/classes/class.ilObjPortfolio.php";
1399 
1400  // remove workspace
1401  include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1402  $tree = new ilWorkspaceTree($this->getId());
1403  $tree->cascadingDelete();
1404 
1405  // remove disk quota entries
1406  include_once "./Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1408 
1409  // remove reminder entries
1410  require_once 'Services/User/classes/class.ilCronDeleteInactiveUserReminderMail.php';
1412 
1413  // Delete user defined field entries
1415 
1416  // Delete clipboard entries
1417  $this->clipboardDeleteAll();
1418 
1419  // Reset owner
1420  $this->resetOwner();
1421 
1422  // Trigger deleteUser Event
1423  global $ilAppEventHandler;
1424  $ilAppEventHandler->raise(
1425  'Services/User', 'deleteUser', array('usr_id' => $this->getId())
1426  );
1427 
1428  // delete object data
1429  parent::delete();
1430  return true;
1431  }
1432 
1442  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1443  {
1444  $this->fullname = "";
1445 
1446  if ($a_title)
1447  {
1448  $fullname = $a_title." ";
1449  }
1450  elseif ($this->utitle)
1451  {
1452  $this->fullname = $this->utitle." ";
1453  }
1454 
1455  if ($a_firstname)
1456  {
1457  $fullname .= $a_firstname." ";
1458  }
1459  elseif ($this->firstname)
1460  {
1461  $this->fullname .= $this->firstname." ";
1462  }
1463 
1464  if ($a_lastname)
1465  {
1466  return $fullname.$a_lastname;
1467  }
1468 
1469  $this->fullname .= $this->lastname;
1470  }
1471 
1486  function getFullname($a_max_strlen = 0)
1487  {
1488  if (!$a_max_strlen)
1489  {
1490  return ilUtil::stripSlashes($this->fullname);
1491  }
1492 
1493  if (strlen($this->fullname) <= $a_max_strlen)
1494  {
1495  return ilUtil::stripSlashes($this->fullname);
1496  }
1497 
1498  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1499  {
1500  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1501  }
1502 
1503  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1504  {
1505  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1506  }
1507 
1508  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1509  {
1510  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1511  }
1512 
1513  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1514  }
1515 
1521  function setLogin($a_str)
1522  {
1523  $this->login = $a_str;
1524  }
1525 
1530  function getLogin()
1531  {
1532  return $this->login;
1533  }
1534 
1540  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1541  {
1542  $this->passwd = $a_str;
1543  $this->passwd_type = $a_type;
1544  }
1545 
1553  function getPasswd()
1554  {
1555  return $this->passwd;
1556  }
1563  function getPasswdType()
1564  {
1565  return $this->passwd_type;
1566  }
1567 
1573  function setGender($a_str)
1574  {
1575  $this->gender = substr($a_str,-1);
1576  }
1577 
1582  function getGender()
1583  {
1584  return $this->gender;
1585  }
1586 
1594  function setUTitle($a_str)
1595  {
1596  $this->utitle = $a_str;
1597  }
1598 
1605  function getUTitle()
1606  {
1607  return $this->utitle;
1608  }
1609 
1615  function setFirstname($a_str)
1616  {
1617  $this->firstname = $a_str;
1618  }
1619 
1624  function getFirstname()
1625  {
1626  return $this->firstname;
1627  }
1628 
1634  function setLastname($a_str)
1635  {
1636  $this->lastname = $a_str;
1637  }
1638 
1643  function getLastname()
1644  {
1645  return $this->lastname;
1646  }
1647 
1653  function setInstitution($a_str)
1654  {
1655  $this->institution = $a_str;
1656  }
1657 
1662  function getInstitution()
1663  {
1664  return $this->institution;
1665  }
1666 
1672  function setDepartment($a_str)
1673  {
1674  $this->department = $a_str;
1675  }
1676 
1681  function getDepartment()
1682  {
1683  return $this->department;
1684  }
1685 
1691  function setStreet($a_str)
1692  {
1693  $this->street = $a_str;
1694  }
1695 
1700  function getStreet()
1701  {
1702  return $this->street;
1703  }
1704 
1710  function setCity($a_str)
1711  {
1712  $this->city = $a_str;
1713  }
1714 
1719  function getCity()
1720  {
1721  return $this->city;
1722  }
1723 
1729  function setZipcode($a_str)
1730  {
1731  $this->zipcode = $a_str;
1732  }
1733 
1738  function getZipcode()
1739  {
1740  return $this->zipcode;
1741  }
1742 
1749  function setCountry($a_str)
1750  {
1751  $this->country = $a_str;
1752  }
1753 
1759  function getCountry()
1760  {
1761  return $this->country;
1762  }
1763 
1769  function setSelectedCountry($a_val)
1770  {
1771  $this->sel_country = $a_val;
1772  }
1773 
1780  {
1781  return $this->sel_country;
1782  }
1783 
1789  function setPhoneOffice($a_str)
1790  {
1791  $this->phone_office = $a_str;
1792  }
1793 
1798  function getPhoneOffice()
1799  {
1800  return $this->phone_office;
1801  }
1802 
1808  function setPhoneHome($a_str)
1809  {
1810  $this->phone_home = $a_str;
1811  }
1812 
1817  function getPhoneHome()
1818  {
1819  return $this->phone_home;
1820  }
1821 
1827  function setPhoneMobile($a_str)
1828  {
1829  $this->phone_mobile = $a_str;
1830  }
1831 
1836  function getPhoneMobile()
1837  {
1838  return $this->phone_mobile;
1839  }
1840 
1846  function setFax($a_str)
1847  {
1848  $this->fax = $a_str;
1849  }
1850 
1855  function getFax()
1856  {
1857  return $this->fax;
1858  }
1859 
1865  function setClientIP($a_str)
1866  {
1867  $this->client_ip = $a_str;
1868  }
1869 
1874  function getClientIP()
1875  {
1876  return $this->client_ip;
1877  }
1878 
1884  function setMatriculation($a_str)
1885  {
1886  $this->matriculation = $a_str;
1887  }
1888 
1893  function getMatriculation()
1894  {
1895  return $this->matriculation;
1896  }
1897 
1904  public static function lookupMatriculation($a_usr_id)
1905  {
1906  global $ilDB;
1907 
1908  $query = "SELECT matriculation FROM usr_data ".
1909  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1910  $res = $ilDB->query($query);
1911  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1912  return $row->matriculation ? $row->matriculation : '';
1913  }
1914 
1920  function setEmail($a_str)
1921  {
1922  $this->email = $a_str;
1923  }
1924 
1929  function getEmail()
1930  {
1931  return $this->email;
1932  }
1933 
1939  function setHobby($a_str)
1940  {
1941  $this->hobby = $a_str;
1942  }
1943 
1948  function getHobby()
1949  {
1950  return $this->hobby;
1951  }
1952 
1958  function setLanguage($a_str)
1959  {
1960  $this->setPref("language",$a_str);
1961  unset($_SESSION['lang']);
1962  }
1963 
1969  function getLanguage()
1970  {
1971  return $this->prefs["language"];
1972  }
1973 
1982  function setDiskQuota($a_disk_quota)
1983  {
1984  $this->setPref("disk_quota",$a_disk_quota);
1985  }
1986 
1996  function getDiskQuota()
1997  {
1998  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
1999  }
2000 
2002  {
2003  return $this->prefs["wsp_disk_quota"] ? $this->prefs["wsp_disk_quota"] : 0;
2004  }
2005 
2006  public function setLastPasswordChangeTS($a_last_password_change_ts)
2007  {
2008  $this->last_password_change_ts = $a_last_password_change_ts;
2009  }
2010 
2011  public function getLastPasswordChangeTS()
2012  {
2014  }
2015 
2016 
2017  public static function _lookupLanguage($a_usr_id)
2018  {
2019  global $ilDB;
2020 
2021  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
2022  $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
2023  $ilDB->quote('language', "text");
2024  $r = $ilDB->query($q);
2025 
2026  while($row = $ilDB->fetchAssoc($r))
2027  {
2028  return $row['value'];
2029  }
2030  return 'en';
2031  }
2032 
2033  function _writeExternalAccount($a_usr_id, $a_ext_id)
2034  {
2035  global $ilDB;
2036 
2037  $ilDB->manipulateF("UPDATE usr_data ".
2038  " SET ext_account = %s WHERE usr_id = %s",
2039  array("text", "integer"),
2040  array($a_ext_id, $a_usr_id));
2041  }
2042 
2043  function _writeAuthMode($a_usr_id, $a_auth_mode)
2044  {
2045  global $ilDB;
2046 
2047  $ilDB->manipulateF("UPDATE usr_data ".
2048  " SET auth_mode = %s WHERE usr_id = %s",
2049  array("text", "integer"),
2050  array($a_auth_mode, $a_usr_id));
2051  }
2052 
2058  {
2059  return $_SESSION['lang'];
2060  }
2061 
2067  function setCurrentLanguage($a_val)
2068  {
2069  $_SESSION['lang'] = $a_val;
2070  }
2071 
2077  function setLastLogin($a_str)
2078  {
2079  $this->last_login = $a_str;
2080  }
2081 
2087  function getLastLogin()
2088  {
2089  return $this->last_login;
2090  }
2091 
2097  function setLastUpdate($a_str)
2098  {
2099  $this->last_update = $a_str;
2100  }
2101  function getLastUpdate()
2102  {
2103  return $this->last_update;
2104  }
2105 
2111  function setComment($a_str)
2112  {
2113  $this->referral_comment = $a_str;
2114  }
2115 
2120  function getComment()
2121  {
2122  return $this->referral_comment;
2123  }
2124 
2131  function setApproveDate($a_str)
2132  {
2133  $this->approve_date = $a_str;
2134  }
2135 
2141  function getApproveDate()
2142  {
2143  return $this->approve_date;
2144  }
2145 
2146  // BEGIN DiskQuota: show when user accepted user agreement
2152  function getAgreeDate()
2153  {
2154  return $this->agree_date;
2155  }
2162  function setAgreeDate($a_str)
2163  {
2164  $this->agree_date = $a_str;
2165  }
2166  // END DiskQuota: show when user accepted user agreement
2167 
2174  function setActive($a_active, $a_owner = 0)
2175  {
2176  $this->setOwner($a_owner);
2177 
2178  if ($a_active)
2179  {
2180  $this->active = 1;
2181  $this->setApproveDate(date('Y-m-d H:i:s'));
2182  $this->setOwner($a_owner);
2183  }
2184  else
2185  {
2186  $this->active = 0;
2187  $this->setApproveDate(null);
2188  }
2189  }
2190 
2195  function getActive()
2196  {
2197  return $this->active;
2198  }
2199 
2203  public function _lookupActive($a_usr_id)
2204  {
2205  global $ilDB;
2206 
2207  $query = 'SELECT usr_id FROM usr_data '.
2208  'WHERE active = '.$ilDB->quote(1,'integer').' '.
2209  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
2210  $res = $ilDB->query($query);
2211  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2212  {
2213  return true;
2214  }
2215  return false;
2216  }
2217 
2223  function syncActive()
2224  {
2225  global $ilAuth;
2226 
2227  $storedActive = 0;
2228  if ($this->getStoredActive($this->id))
2229  {
2230  $storedActive = 1;
2231  }
2232 
2233  $currentActive = 0;
2234  if ($this->active)
2235  {
2236  $currentActive = 1;
2237  }
2238 
2239  if ((!empty($storedActive) && empty($currentActive)) ||
2240  (empty($storedActive) && !empty($currentActive)))
2241  {
2242  $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2243  }
2244  }
2245 
2252  function getStoredActive($a_id)
2253  {
2254  $active = ilObjUser::_lookup($a_id, "active");
2255  return $active ? true : false;
2256  }
2257 
2263  function setSkin($a_str)
2264  {
2265  // TODO: exception handling (dir exists)
2266  $this->skin = $a_str;
2267  }
2268 
2269  function setTimeLimitOwner($a_owner)
2270  {
2271  $this->time_limit_owner = $a_owner;
2272  }
2274  {
2275  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2276  }
2277  function setTimeLimitFrom($a_from)
2278  {
2279  $this->time_limit_from = $a_from;
2280  }
2281  function getTimeLimitFrom()
2282  {
2283  return $this->time_limit_from ? $this->time_limit_from : time();
2284  }
2285  function setTimeLimitUntil($a_until)
2286  {
2287  $this->time_limit_until = $a_until;
2288  }
2290  {
2291  return $this->time_limit_until ? $this->time_limit_until : time();
2292  }
2293  function setTimeLimitUnlimited($a_unlimited)
2294  {
2295  $this->time_limit_unlimited = $a_unlimited;
2296  }
2298  {
2299  return $this->time_limit_unlimited;
2300  }
2301  function setTimeLimitMessage($a_time_limit_message)
2302  {
2303  return $this->time_limit_message = $a_time_limit_message;
2304  }
2306  {
2307  return $this->time_limit_message;
2308  }
2309 
2310  public function setLoginAttempts($a_login_attempts)
2311  {
2312  $this->login_attempts = $a_login_attempts;
2313  }
2314 
2315  public function getLoginAttempts()
2316  {
2317  return $this->login_attempts;
2318  }
2319 
2320 
2321  function checkTimeLimit()
2322  {
2323  if($this->getTimeLimitUnlimited())
2324  {
2325  return true;
2326  }
2327  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2328  {
2329  return true;
2330  }
2331  return false;
2332  }
2333  function setProfileIncomplete($a_prof_inc)
2334  {
2335  $this->profile_incomplete = (boolean) $a_prof_inc;
2336  }
2338  {
2339  if($this->id == ANONYMOUS_USER_ID)
2340  {
2341  return false;
2342  }
2343  return $this->profile_incomplete;
2344  }
2345 
2346  public function isPasswordChangeDemanded()
2347  {
2348  //error_reporting(E_ALL);
2349  if( $this->id == ANONYMOUS_USER_ID )
2350  return false;
2351 
2352  if ($this->id == SYSTEM_USER_ID) {
2353  require_once './Services/User/classes/class.ilUserPasswordManager.php';
2354  if (
2355  \ilUserPasswordManager::getInstance()->verifyPassword($this, base64_decode('aG9tZXI=')) &&
2357  ) {
2358  return true;
2359  } else {
2360  return false;
2361  }
2362  }
2363 
2364  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2365  $security = ilSecuritySettings::_getInstance();
2366 
2368  && $security->isPasswordChangeOnFirstLoginEnabled()
2369  && $this->getLastPasswordChangeTS() == 0
2370  && $this->is_self_registered == false
2371  ){
2372  return true;
2373  }
2374  else return false;
2375  }
2376 
2377  public function isPasswordExpired()
2378  {
2379  //error_reporting(E_ALL);
2380  if($this->id == ANONYMOUS_USER_ID) return false;
2381 
2382  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2383  $security = ilSecuritySettings::_getInstance();
2384  if( $this->getLastPasswordChangeTS() > 0 )
2385  {
2386  $max_pass_age = $security->getPasswordMaxAge();
2387  if( $max_pass_age > 0 )
2388  {
2389  $max_pass_age_ts = ( $max_pass_age * 86400 );
2390  $pass_change_ts = $this->getLastPasswordChangeTS();
2391  $current_ts = time();
2392 
2393  if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2394  return true;
2395  }
2396  }
2397  return false;
2398  }
2399 
2400  public function getPasswordAge()
2401  {
2402  $current_ts = time();
2403  $pass_change_ts = $this->getLastPasswordChangeTS();
2404  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2405  return $password_age;
2406  }
2407 
2408  public function setLastPasswordChangeToNow()
2409  {
2410  global $ilDB;
2411 
2412  $this->setLastPasswordChangeTS( time() );
2413 
2414  $query = "UPDATE usr_data SET last_password_change = %s " .
2415  "WHERE usr_id = %s";
2416  $affected = $ilDB->manipulateF($query,
2417  array('integer','integer'),
2418  array($this->getLastPasswordChangeTS(),$this->id));
2419  if($affected) return true;
2420  else return false;
2421  }
2422 
2423  public function resetLastPasswordChange()
2424  {
2425  global $ilDB;
2426 
2427  $query = "UPDATE usr_data SET last_password_change = 0 " .
2428  "WHERE usr_id = %s";
2429  $affected = $ilDB->manipulateF( $query, array('integer'),
2430  array($this->getId()) );
2431  if($affected) return true;
2432  else return false;
2433  }
2434 
2440  function setLatitude($a_latitude)
2441  {
2442  $this->latitude = $a_latitude;
2443  }
2444 
2450  function getLatitude()
2451  {
2452  return $this->latitude;
2453  }
2454 
2460  function setLongitude($a_longitude)
2461  {
2462  $this->longitude = $a_longitude;
2463  }
2464 
2470  function getLongitude()
2471  {
2472  return $this->longitude;
2473  }
2474 
2480  function setLocationZoom($a_locationzoom)
2481  {
2482  $this->loc_zoom = $a_locationzoom;
2483  }
2484 
2490  function getLocationZoom()
2491  {
2492  return $this->loc_zoom;
2493  }
2494 
2495  function &getAppliedUsers()
2496  {
2497  $this->applied_users = array();
2498  $this->__readAppliedUsers($this->getId());
2499 
2500  return $this->applied_users ? $this->applied_users : array();
2501  }
2502 
2503  function isChild($a_usr_id)
2504  {
2505  if($a_usr_id == $this->getId())
2506  {
2507  return true;
2508  }
2509 
2510  $this->applied_users = array();
2511  $this->__readAppliedUsers($this->getId());
2512 
2513  return in_array($a_usr_id,$this->applied_users);
2514  }
2515 
2516  function __readAppliedUsers($a_parent_id)
2517  {
2518  global $ilDB;
2519 
2520  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2521  "WHERE time_limit_owner = %s",
2522  array("integer"),
2523  array($a_parent_id));
2524  while ($row = $ilDB->fetchObject($res))
2525  {
2526  $this->applied_users[] = $row->usr_id;
2527 
2528  // recursion
2529  $this->__readAppliedUsers($row->usr_id);
2530  }
2531  return true;
2532  }
2533 
2539  static function hasActiveSession($a_user_id)
2540  {
2541  global $ilDB;
2542 
2543  $set = $ilDB->queryf('
2544  SELECT COUNT(*) session_count
2545  FROM usr_session WHERE user_id = %s AND expires > %s',
2546  array('integer', 'integer'),
2547  array($a_user_id, time()));
2548  $row = $ilDB->fetchAssoc($set);
2549  return (bool)$row['session_count'];
2550  }
2551 
2552  /*
2553  * check user id with login name
2554  * @access public
2555  */
2556  function checkUserId()
2557  {
2558  global $ilAuth, $ilSetting;
2559 
2560  $login = ilObjUser::getLoginFromAuth();
2561  $id = ilObjUser::_lookupId($login);
2562  if ($id > 0)
2563  {
2564  return $id;
2565  }
2566  return false;
2567  }
2568 
2572  private static function getLoginFromAuth() {
2573  global $ilAuth;
2574 
2575  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2576  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2578  {
2579  require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2580  require_once ('Services/Database/classes/class.ilAuthContainerMDB2.php');
2581  $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2582  }
2583  else
2584  {
2585  $login =$ilAuth->getUsername();
2586  }
2587 
2588  return $login;
2589  }
2590 
2591  /*
2592  * check to see if current user has been made active
2593  * @access public
2594  * @return true if active, otherwise false
2595  */
2597  {
2598  global $ilDB,$ilAuth;
2599 
2600  $login = ilObjUser::getLoginFromAuth();
2601  $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2602  array("text"),
2603  array($login));
2604  //query has got a result
2605  if ($rec = $ilDB->fetchAssoc($set))
2606  {
2607  if ($rec["active"])
2608  {
2609  return true;
2610  }
2611  }
2612 
2613  return false;
2614  }
2615 
2616  /*
2617  * STATIC METHOD
2618  * get the user_id of a login name
2619  * @param string login name
2620  * @return integer id of user
2621  * @static
2622  * @access public
2623  */
2624  function getUserIdByLogin($a_login)
2625  {
2626  return (int) ilObjUser::_lookupId($a_login);
2627  }
2628 
2637  function _getUserIdsByEmail($a_email)
2638  {
2639  global $ilias, $ilDB;
2640 
2641  $res = $ilDB->queryF("SELECT login FROM usr_data ".
2642  "WHERE email = %s and active = 1",
2643  array("text"),
2644  array($a_email));
2645  $ids = array ();
2646  while($row = $ilDB->fetchObject($res))
2647  {
2648  $ids[] = $row->login;
2649  }
2650 
2651  return $ids;
2652  }
2653 
2654 
2655 
2664  function getUserIdByEmail($a_email)
2665  {
2666  global $ilDB;
2667 
2668  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2669  "WHERE email = %s", array("text"), array($a_email));
2670 
2671  $row = $ilDB->fetchObject($res);
2672  return $row->usr_id ? $row->usr_id : 0;
2673  }
2674 
2675  /*
2676  * STATIC METHOD
2677  * get the login name of a user_id
2678  * @param integer id of user
2679  * @return string login name; false if not found
2680  * @static
2681  * @access public
2682  */
2683  function getLoginByUserId($a_userid)
2684  {
2685  $login = ilObjUser::_lookupLogin($a_userid);
2686  return $login ? $login : false;
2687  }
2688 
2699  static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2700  {
2701  global $ilias, $ilDB, $ilLog;
2702 
2703 
2704  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2705 
2706  $without_anonymous_users = true;
2707 
2708  // determine join filter
2709  $join_filter = " WHERE ";
2710  if ($filter_settings !== FALSE && strlen($filter_settings))
2711  {
2712  switch ($filter_settings)
2713  {
2714  case 3:
2715  // show only users without courses
2716  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.usr_id IS NULL AND ";
2717  break;
2718  case 5:
2719  // show only users with a certain course membership
2720  $ref_id = $_SESSION["user_filter_data"];
2721  if ($ref_id)
2722  {
2723  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.obj_id = ".
2724  "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2725  }
2726  break;
2727  case 6:
2728  global $rbacreview;
2729  $ref_id = $_SESSION["user_filter_data"];
2730  if ($ref_id)
2731  {
2732  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
2733  if (is_array($local_roles) && count($local_roles))
2734  {
2735  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2736  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2737  }
2738  }
2739  break;
2740  case 7:
2741  global $rbacreview;
2742  $rol_id = $_SESSION["user_filter_data"];
2743  if ($rol_id)
2744  {
2745  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2746  $ilDB->quote($rol_id, "integer")." AND ";
2747  $without_anonymous_users = false;
2748  }
2749  break;
2750  }
2751  }
2752  // This is a temporary hack to search users by their role
2753  // See Mantis #338. This is a hack due to Mantis #337.
2754  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2755  {
2756  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2757  "FROM object_data,rbac_ua,usr_data ".
2758  "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2759  " AND object_data.type = 'role' ".
2760  "AND rbac_ua.rol_id = object_data.obj_id ".
2761  "AND usr_data.usr_id = rbac_ua.usr_id ".
2762  "AND rbac_ua.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2763  }
2764  else
2765  {
2766  $query.= $join_filter.
2767  "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2768  "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2769  "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2770  "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2771 
2772  if ($filter_settings !== FALSE && strlen($filter_settings))
2773  {
2774  switch ($filter_settings)
2775  {
2776  case 0:
2777  $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2778  break;
2779  case 1:
2780  $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2781  break;
2782  case 2:
2783  $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2784  break;
2785  case 4:
2786  $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"]));
2787  $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2788  break;
2789  }
2790  }
2791 
2792  if ($without_anonymous_users)
2793  {
2794  $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2795  }
2796 
2797  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2798  {
2799  $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2800  }
2801 
2802  }
2803  $ilLog->write($query);
2804  $res = $ilDB->query($query);
2805  while ($row = $ilDB->fetchObject($res))
2806  {
2807  $users[] = array(
2808  "usr_id" => $row->usr_id,
2809  "login" => $row->login,
2810  "firstname" => $row->firstname,
2811  "lastname" => $row->lastname,
2812  "email" => $row->email,
2813  "active" => $row->active);
2814  $ids[] = $row->usr_id;
2815  }
2816  if ($a_return_ids_only)
2817  return $ids ? $ids : array();
2818  else
2819  return $users ? $users : array();
2820  }
2821 
2830  function _getAllUserLogins(&$ilias)
2831  {
2832  global $ilDB;
2833 
2834  $res = $ilDB->query("SELECT login FROM usr_data");
2835  while($row = $ilDB->fetchObject($res))
2836  {
2837  $logins[] = $row->login;
2838  }
2839  return $logins ? $logins : array();
2840  }
2841 
2850  public static function _readUsersProfileData($a_user_ids)
2851  {
2852  global $ilDB;
2853  $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2854  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2855  while ($row = $ilDB->fetchAssoc($res))
2856  {
2857  $user_data["$row[usr_id]"] = $row;
2858  }
2859  return $user_data ? $user_data : array();
2860  }
2861 
2870  function _getAllUserData($a_fields = NULL, $active =-1)
2871  {
2872  global $ilDB;
2873 
2874  $result_arr = array();
2875  $types = array();
2876  $values = array();
2877 
2878  if ($a_fields !== NULL and is_array($a_fields))
2879  {
2880  if (count($a_fields) == 0)
2881  {
2882  $select = "*";
2883  }
2884  else
2885  {
2886  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2887  unset($a_fields[$usr_id_field]);
2888 
2889  $select = implode(",",$a_fields).",usr_data.usr_id";
2890  // online time
2891  if(in_array('online_time',$a_fields))
2892  {
2893  $select .= ",ut_online.online_time ";
2894  }
2895  }
2896 
2897  $q = "SELECT ".$select." FROM usr_data ";
2898 
2899  // Add online_time if desired
2900  // Need left join here to show users that never logged in
2901  if(in_array('online_time',$a_fields))
2902  {
2903  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2904  }
2905 
2906  switch ($active)
2907  {
2908  case 0:
2909  case 1:
2910  $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2911  break;
2912  case 2:
2913  $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2914  break;
2915  case 3:
2916  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2917  $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2918  $r = $ilDB->query($qtemp);
2919  $course_users = array();
2920  while ($row = $ilDB->fetchAssoc($r))
2921  {
2922  array_push($course_users, $row["usr_id"]);
2923  }
2924  if (count($course_users))
2925  {
2926  $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2927  }
2928  else
2929  {
2930  return $result_arr;
2931  }
2932  break;
2933  case 4:
2934  $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"]));
2935  $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2936  break;
2937  case 5:
2938  $ref_id = $_SESSION["user_filter_data"];
2939  if ($ref_id)
2940  {
2941  $q .= " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id ".
2942  "WHERE obj_members.obj_id = (SELECT obj_id FROM object_reference ".
2943  "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2944  }
2945  break;
2946  case 6:
2947  global $rbacreview;
2948  $ref_id = $_SESSION["user_filter_data"];
2949  if ($ref_id)
2950  {
2951  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
2952  if (is_array($local_roles) && count($local_roles))
2953  {
2954  $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2955  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2956  }
2957  }
2958  break;
2959  case 7:
2960  $rol_id = $_SESSION["user_filter_data"];
2961  if ($rol_id)
2962  {
2963  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2964  $ilDB->quote($rol_id, "integer");
2965  }
2966  break;
2967  }
2968  $r = $ilDB->query($q);
2969 
2970  while ($row = $ilDB->fetchAssoc($r))
2971  {
2972  $result_arr[] = $row;
2973  }
2974  }
2975 
2976  return $result_arr;
2977  }
2978 
2982  function _getNumberOfUsersForStyle($a_skin, $a_style)
2983  {
2984  global $ilDB;
2985 
2986  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
2987  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
2988  " AND up1.value= ".$ilDB->quote($a_style, "text").
2989  " AND up2.keyword= ".$ilDB->quote("skin", "text").
2990  " AND up2.value= ".$ilDB->quote($a_skin, "text").
2991  " AND up1.usr_id = up2.usr_id ";
2992 
2993  $cnt_set = $ilDB->query($q);
2994 
2995  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
2996 
2997  return $cnt_rec["cnt"];
2998  }
2999 
3004  {
3005  global $ilDB;
3006 
3007  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
3008  " WHERE up1.keyword = ".$ilDB->quote("style", "text").
3009  " AND up2.keyword = ".$ilDB->quote("skin", "text").
3010  " AND up1.usr_id = up2.usr_id";
3011 
3012  $sty_set = $ilDB->query($q);
3013 
3014  $styles = array();
3015  while($sty_rec = $ilDB->fetchAssoc($sty_set))
3016  {
3017  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
3018  }
3019 
3020  return $styles;
3021  }
3022 
3026  function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3027  {
3028  global $ilDB;
3029 
3030  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
3031  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3032  " AND up1.value= ".$ilDB->quote($a_from_style, "text").
3033  " AND up2.keyword= ".$ilDB->quote("skin", "text").
3034  " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
3035  " AND up1.usr_id = up2.usr_id ";
3036 
3037  $usr_set = $ilDB->query($q);
3038 
3039  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3040  {
3041  self::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3042  self::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3043  }
3044  }
3045 
3046 
3056  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3057  {
3058  global $ilDB;
3059 
3060  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3061  "item_id = %s AND type = %s AND user_id = %s",
3062  array("integer", "text", "integer"),
3063  array($a_item_id, $a_type, $a_usr_id));
3064 
3065  // only insert if item is not already on desktop
3066  if (!$ilDB->fetchAssoc($item_set))
3067  {
3068  $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3069  " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3070  array($a_item_id,$a_type,$a_usr_id,$a_par));
3071  }
3072 
3073  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3075  }
3076 
3084  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3085  {
3086  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3087  }
3088 
3097  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3098  {
3099  global $ilDB;
3100 
3101  $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3102  " WHERE item_id = %s AND type = %s AND user_id = %s",
3103  array("text", "integer", "text", "integer"),
3104  array($a_par, $a_item_id, $a_type, $this->getId()));
3105  }
3106 
3107 
3117  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3118  {
3119  global $ilDB;
3120 
3121  $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3122  " item_id = %s AND type = %s AND user_id = %s",
3123  array("integer", "text", "integer"),
3124  array($a_item_id, $a_type, $a_usr_id));
3125 
3126  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3128  }
3129 
3137  function dropDesktopItem($a_item_id, $a_type)
3138  {
3139  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3140  }
3141 
3148  static function _removeItemFromDesktops($a_id)
3149  {
3150  global $ilDB;
3151 
3152  $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3153  array("integer"), array($a_id));
3154 
3155  $users = array();
3156 
3157  while ($row = $ilDB->fetchObject($r))
3158  {
3159  $users[] = $row->user_id;
3160  } // while
3161 
3162  if (count($users) > 0)
3163  {
3164  $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3165  array("integer"), array($a_id));
3166  }
3167 
3168  return $users;
3169  }
3170 
3180  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3181  {
3182  global $ilDB;
3183 
3184  if (self::$is_desktop_item_loaded[$a_usr_id.":".$a_item_id])
3185  {
3186  return self::$is_desktop_item_cache[$a_usr_id.":".$a_item_id.":".$a_type];
3187  }
3188  $item_set = $ilDB->queryF("SELECT item_id FROM desktop_item WHERE ".
3189  "item_id = %s AND type = %s AND user_id = %s",
3190  array("integer", "text", "integer"),
3191  array($a_item_id, $a_type, $a_usr_id));
3192 
3193  if ($ilDB->fetchAssoc($item_set))
3194  {
3195  return true;
3196  }
3197  else
3198  {
3199  return false;
3200  }
3201  }
3202 
3209  static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3210  {
3211  global $ilDB;
3212 
3213  if (!is_array($a_item_ids))
3214  {
3215  return;
3216  }
3217 
3218  $item_ids = array();
3219  foreach ($a_item_ids as $id)
3220  {
3221  if (!self::$is_desktop_item_loaded[$a_usr_id.":".$id])
3222  {
3223  $item_ids[] = $id;
3224  }
3225  self::$is_desktop_item_loaded[$a_usr_id.":".$id] = true;
3226  }
3227 
3228  if (count($item_ids) > 0)
3229  {
3230  $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE ".
3231  $ilDB->in("item_id", $item_ids, false, "integer").
3232  " AND user_id = ".$ilDB->quote($a_usr_id, "integer"));
3233  while ($r = $ilDB->fetchAssoc($item_set))
3234  {
3235  self::$is_desktop_item_cache[$a_usr_id.":".$r["item_id"].":".$r["type"]]
3236  = true;
3237  }
3238  }
3239  }
3240 
3248  function isDesktopItem($a_item_id, $a_type)
3249  {
3250  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3251  }
3252 
3253  function getDesktopItems($a_types = "")
3254  {
3255  return $this->_lookupDesktopItems($this->getId(), $a_types);
3256  }
3257 
3264  static function _lookupDesktopItems($user_id, $a_types = "")
3265  {
3266  global $ilUser, $rbacsystem, $tree, $ilDB;
3267 
3268  if ($a_types == "")
3269  {
3270  $is_nested_set = ($tree->getTreeImplementation() instanceof ilNestedSetTree);
3271 
3272  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3273  " FROM desktop_item it, object_reference oref ".
3274  ", object_data obj".
3275  " WHERE ".
3276  "it.item_id = oref.ref_id AND ".
3277  "oref.obj_id = obj.obj_id AND ".
3278  "it.user_id = %s", array("integer"), array($user_id));
3279  $items = $all_parent_path = array();
3280  while ($item_rec = $ilDB->fetchAssoc($item_set))
3281  {
3282  if ($tree->isInTree($item_rec["ref_id"])
3283  && $item_rec["type"] != "rolf"
3284  && $item_rec["type"] != "itgr") // due to bug 11508
3285  {
3286  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3287 
3288  if(!isset($all_parent_path[$parent_ref]))
3289  {
3290  // #15746
3291  //if($is_nested_set)
3292  //{
3293  // $par_left = $tree->getLeftValue($parent_ref);
3294  // $all_parent_path[$parent_ref] = sprintf("%010d", $par_left);
3295  //}
3296  //else
3297  //{
3298  $node = $tree->getNodeData($parent_ref);
3299  $all_parent_path[$parent_ref] = $node["title"];
3300  //}
3301  }
3302 
3303  $parent_path = $all_parent_path[$parent_ref];
3304 
3305  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3306  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3307  $items[$parent_path.$title.$item_rec["ref_id"]] =
3308  array("ref_id" => $item_rec["ref_id"],
3309  "obj_id" => $item_rec["obj_id"],
3310  "type" => $item_rec["type"],
3311  "title" => $title,
3312  "description" => $desc,
3313  "parent_ref" => $parent_ref);
3314  }
3315  }
3316  ksort($items);
3317  }
3318  else
3319  {
3320  // due to bug 11508
3321  if (!is_array($a_types))
3322  {
3323  $a_types = array($a_types);
3324  }
3325  $items = array();
3326  $foundsurveys = array();
3327  foreach($a_types as $a_type)
3328  {
3329  if ($a_type == "itgr")
3330  {
3331  continue;
3332  }
3333  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3334  ", object_data obj WHERE ".
3335  "it.item_id = oref.ref_id AND ".
3336  "oref.obj_id = obj.obj_id AND ".
3337  "it.type = %s AND ".
3338  "it.user_id = %s ".
3339  "ORDER BY title",
3340  array("text", "integer"),
3341  array($a_type, $user_id));
3342 
3343  while ($item_rec = $ilDB->fetchAssoc($item_set))
3344  {
3345  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3346  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3347  $items[$title.$a_type.$item_rec["ref_id"]] =
3348  array("ref_id" => $item_rec["ref_id"],
3349  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3350  "title" => $title, "description" => $desc);
3351  }
3352 
3353  }
3354  ksort($items);
3355  }
3356 
3357  return $items;
3358  }
3359 
3365 
3373  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3374  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3375  {
3376  global $ilDB;
3377 
3378  if ($a_time == 0)
3379  {
3380  $a_time = date("Y-m-d H:i:s", time());
3381  }
3382 
3383  $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3384  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3385  array("integer", "integer", "text", "integer"),
3386  array(0, $a_item_id, $a_type, $this->getId()));
3387 
3388  // only insert if item is not already in clipboard
3389  if (!$d = $item_set->fetchRow())
3390  {
3391  $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3392  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3393  " (%s,%s,%s,%s,%s,%s,%s)",
3394  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3395  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3396  }
3397  else
3398  {
3399  $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3400  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3401  array("timestamp", "integer", "integer", "text"),
3402  array($a_time, $this->getId(), $a_item_id, $a_type));
3403  }
3404  }
3405 
3409  function addToPCClipboard($a_content, $a_time, $a_nr)
3410  {
3411  global $ilDB;
3412  if ($a_time == 0)
3413  {
3414  $a_time = date("Y-m-d H:i:s", time());
3415  }
3416  $ilDB->insert("personal_pc_clipboard", array(
3417  "user_id" => array("integer", $this->getId()),
3418  "content" => array("clob", $a_content),
3419  "insert_time" => array("timestamp", $a_time),
3420  "order_nr" => array("integer", $a_nr)
3421  ));
3422  }
3423 
3428  {
3429  global $ilDB;
3430 
3431  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3432  " WHERE user_id = %s", array("integer"), array($this->getId()));
3433  $row = $ilDB->fetchAssoc($set);
3434 
3435  $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3436  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3437  array("integer", "timestamp"),
3438  array($this->getId(), $row["mtime"]));
3439  $content = array();
3440  while ($row = $ilDB->fetchAssoc($set))
3441  {
3442  $content[] = $row["content"];
3443  }
3444 
3445  return $content;
3446  }
3447 
3451  function clipboardHasObjectsOfType($a_type)
3452  {
3453  global $ilDB;
3454 
3455  $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3456  "parent = %s AND type = %s AND user_id = %s",
3457  array("integer", "text", "integer"),
3458  array(0, $a_type, $this->getId()));
3459  if ($rec = $ilDB->fetchAssoc($set))
3460  {
3461  return true;
3462  }
3463 
3464  return false;
3465  }
3466 
3471  {
3472  global $ilDB;
3473 
3474  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3475  "type = %s AND user_id = %s",
3476  array("text", "integer"),
3477  array($a_type, $this->getId()));
3478  }
3479 
3484  {
3485  global $ilDB;
3486 
3487  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3488  "user_id = %s", array("integer"), array($this->getId()));
3489  }
3490 
3494  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3495  {
3496  global $ilDB;
3497 
3498  $par = "";
3499  if ($a_top_nodes_only)
3500  {
3501  $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3502  }
3503 
3504  $type_str = ($a_type != "")
3505  ? " AND type = ".$ilDB->quote($a_type, "text")." "
3506  : "";
3507  $q = "SELECT * FROM personal_clipboard WHERE ".
3508  "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3509  $type_str.$par.
3510  " ORDER BY order_nr";
3511  $objs = $ilDB->query($q);
3512  $objects = array();
3513  while ($obj = $ilDB->fetchAssoc($objs))
3514  {
3515  if ($obj["type"] == "mob")
3516  {
3517  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3518  }
3519  if ($obj["type"] == "incl")
3520  {
3521  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3522  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3523  }
3524  $objects[] = array ("id" => $obj["item_id"],
3525  "type" => $obj["type"], "title" => $obj["title"],
3526  "insert_time" => $obj["insert_time"]);
3527  }
3528  return $objects;
3529  }
3530 
3534  function getClipboardChilds($a_parent, $a_insert_time)
3535  {
3536  global $ilDB, $ilUser;
3537 
3538  $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3539  "user_id = %s AND parent = %s AND insert_time = %s ".
3540  " ORDER BY order_nr",
3541  array("integer", "integer", "timestamp"),
3542  array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3543  $objects = array();
3544  while ($obj = $ilDB->fetchAssoc($objs))
3545  {
3546  if ($obj["type"] == "mob")
3547  {
3548  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3549  }
3550  $objects[] = array ("id" => $obj["item_id"],
3551  "type" => $obj["type"], "title" => $obj["title"], "insert_time" => $obj["insert_time"]);
3552  }
3553  return $objects;
3554  }
3555 
3564  function _getUsersForClipboadObject($a_type, $a_id)
3565  {
3566  global $ilDB;
3567 
3568  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3569  "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3570  "type = ".$ilDB->quote($a_type, "text");
3571  $user_set = $ilDB->query($q);
3572  $users = array();
3573  while ($user_rec = $ilDB->fetchAssoc($user_set))
3574  {
3575  $users[] = $user_rec["user_id"];
3576  }
3577 
3578  return $users;
3579  }
3580 
3588  function removeObjectFromClipboard($a_item_id, $a_type)
3589  {
3590  global $ilDB;
3591 
3592  $q = "DELETE FROM personal_clipboard WHERE ".
3593  "item_id = ".$ilDB->quote($a_item_id, "integer").
3594  " AND type = ".$ilDB->quote($a_type, "text")." ".
3595  " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3596  $ilDB->manipulate($q);
3597  }
3598 
3599  function _getImportedUserId($i2_id)
3600  {
3601  global $ilDB;
3602 
3603  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3604  $ilDB->quote($i2_id, "text");
3605 
3606  $res = $ilDB->query($query);
3607  while($row = $ilDB->fetchObject($res))
3608  {
3609  $id = $row->obj_id;
3610  }
3611  return $id ? $id : 0;
3612  }
3613 
3618  function setAuthMode($a_str)
3619  {
3620  $this->auth_mode = $a_str;
3621  }
3622 
3627  function getAuthMode($a_auth_key = false)
3628  {
3629  if (!$a_auth_key)
3630  {
3631  return $this->auth_mode;
3632  }
3633 
3634  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3635  return ilAuthUtils::_getAuthMode($this->auth_mode);
3636  }
3637 
3645  function setExternalAccount($a_str)
3646  {
3647  $this->ext_account = $a_str;
3648  }
3649 
3658  {
3659  return $this->ext_account;
3660  }
3661 
3673  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3674  {
3675  global $ilDB,$ilSetting;
3676 
3677  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3678  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3679  "WHERE auth_mode = %s";
3680  $types[] = "text";
3681  $values[] = $a_auth_mode;
3682  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3683  {
3684  $q.= " OR auth_mode = %s ";
3685  $types[] = "text";
3686  $values[] = 'default';
3687  }
3688 
3689  $res = $ilDB->queryF($q, $types, $values);
3690  while ($row = $ilDB->fetchObject($res))
3691  {
3692  if($row->auth_mode == 'default')
3693  {
3694  $accounts[$row->usr_id] = $row->login;
3695  }
3696  else
3697  {
3698  $accounts[$row->usr_id] = $row->ext_account;
3699  }
3700  }
3701  return $accounts ? $accounts : array();
3702  }
3703 
3711  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3712  {
3713  global $ilDB;
3714 
3715  if(!is_array($a_usr_ids))
3716  {
3717  return false;
3718  }
3719 
3720 
3721  if( $a_status )
3722  {
3723  $q = "UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE ".
3724  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3725  $ilDB->manipulate($q);
3726  }
3727  else
3728  {
3729  $usrId_IN_usrIds = $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3730 
3731  $q = "UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds";
3732  $ilDB->manipulate($q);
3733 
3734  $queryString = "
3735  UPDATE usr_data
3736  SET inactivation_date = %s
3737  WHERE inactivation_date IS NULL
3738  AND $usrId_IN_usrIds
3739  ";
3740  $ilDB->manipulateF($queryString, array('timestamp'), array(ilUtil::now()));
3741  }
3742 
3743  return true;
3744  }
3745 
3746 
3755  public static function _lookupAuthMode($a_usr_id)
3756  {
3757  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3758  }
3759 
3766  public static function _checkExternalAuthAccount($a_auth, $a_account)
3767  {
3768  global $ilDB,$ilSetting;
3769 
3770  // Check directly with auth_mode
3771  $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3772  " ext_account = %s AND auth_mode = %s",
3773  array("text", "text"),
3774  array($a_account, $a_auth));
3775  if ($usr = $ilDB->fetchAssoc($r))
3776  {
3777  return $usr["login"];
3778  }
3779 
3780  // For compatibility, check for login (no ext_account entry given)
3781  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3782  "WHERE login = %s AND auth_mode = %s AND ext_account IS NULL ",
3783  array("text", "text"),
3784  array($a_account, $a_auth));
3785  if($usr = $ilDB->fetchAssoc($res))
3786  {
3787  return $usr['login'];
3788  }
3789 
3790  // If auth_default == $a_auth => check for login
3791  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3792  {
3793  $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3794  " ext_account = %s AND auth_mode = %s",
3795  array("text", "text"),
3796  array($a_account, "default"));
3797  if ($usr = $ilDB->fetchAssoc($res))
3798  {
3799  return $usr["login"];
3800  }
3801  // Search for login (no ext_account given)
3802  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3803  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3804  array("text", "text"),
3805  array($a_account, "default"));
3806  if($usr = $ilDB->fetchAssoc($res))
3807  {
3808  return $usr["login"];
3809  }
3810  }
3811  return false;
3812  }
3813 
3818  {
3819  global $ilDB;
3820 
3821  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3822  "GROUP BY auth_mode");
3823  $cnt_arr = array();
3824  while($cnt = $ilDB->fetchAssoc($r))
3825  {
3826  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3827  }
3828 
3829  return $cnt_arr;
3830  }
3831 
3837  function _getLocalAccountsForEmail($a_email)
3838  {
3839  global $ilDB, $ilSetting;
3840 
3841  // default set to local (1)?
3842 
3843  $q = "SELECT * FROM usr_data WHERE ".
3844  " email = %s AND (auth_mode = %s ";
3845  $types = array("text", "text");
3846  $values = array($a_email, "local");
3847 
3848  if ($ilSetting->get("auth_mode") == 1)
3849  {
3850  $q.=" OR auth_mode = %s";
3851  $types[] = "text";
3852  $values[] = "default";
3853  }
3854 
3855  $q.= ")";
3856 
3857  $users = array();
3858  $usr_set = $ilDB->queryF($q, $types, $values);
3859  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3860  {
3861  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3862  }
3863 
3864  return $users;
3865  }
3866 
3867 
3875  function _uploadPersonalPicture($tmp_file, $obj_id)
3876  {
3877  $webspace_dir = ilUtil::getWebspaceDir();
3878  $image_dir = $webspace_dir."/usr_images";
3879  $store_file = "usr_".$obj_id."."."jpg";
3880  $target_file = $image_dir."/$store_file";
3881 
3882  chmod($tmp_file, 0770);
3883 
3884  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3885  // taking only frame [0] to avoid problems with animated gifs
3886  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3887  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3888  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3889  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3890 
3891  ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
3892  ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
3893  ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
3894  ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
3895 
3896  // store filename
3897  self::_writePref($obj_id, "profile_image", $store_file);
3898 
3899  return TRUE;
3900  }
3901 
3902 
3911  public function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3912  {
3913  if(isset(self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic]))
3914  {
3915  return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3916  }
3917 
3918  self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic] = ilObjUser::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
3919 
3920  return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3921  }
3922 
3932  public static function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3933  $a_prevent_no_photo_image = false)
3934  {
3935  global $ilDB;
3936 
3937  // BEGIN DiskQuota: Fetch all user preferences in a single query
3938  $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3939  "keyword IN (%s,%s) ".
3940  "AND usr_id = %s",
3941  array("text", "text", "integer"),
3942  array('public_upload', 'public_profile', $a_usr_id));
3943  while ($row = $ilDB->fetchAssoc($res))
3944  {
3945  switch ($row['keyword'])
3946  {
3947  case 'public_upload' :
3948  $upload = $row['value'] == 'y';
3949  break;
3950  case 'public_profile' :
3951  $profile = ($row['value'] == 'y' ||
3952  $row['value'] == 'g');
3953  break;
3954  }
3955  }
3956 
3957  // END DiskQuota: Fetch all user preferences in a single query
3958  $webspace_dir = "";
3959  if(defined('ILIAS_MODULE'))
3960  {
3961  $webspace_dir = ('.'.$webspace_dir);
3962  }
3963  $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
3964 
3965  $image_dir = $webspace_dir."/usr_images";
3966  // BEGIN DiskQuota: Support 'big' user images
3967  if ($a_size == 'big')
3968  {
3969  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3970  }
3971  else
3972  {
3973  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3974  }
3975  // END DiskQuota: Support 'big' user images
3976 
3977  if((($upload && $profile) || $a_force_pic)
3978  && @is_file($thumb_file))
3979  {
3980  $file = $thumb_file."?t=".rand(1, 99999);
3981  }
3982  else
3983  {
3984  if (!$a_prevent_no_photo_image)
3985  {
3986  // we only have xsmall and xxsmall for this
3987  if($a_size == "small" || $a_size == "big")
3988  {
3989  $a_size = "xsmall";
3990  }
3991  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
3992  }
3993  }
3994 
3995  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
3997  }
3998 
4005  static function copyProfilePicturesToDirectory($a_user_id, $a_dir)
4006  {
4007  $a_dir = trim(str_replace("..", "", $a_dir));
4008  if ($a_dir == "" || !is_dir($a_dir))
4009  {
4010  return;
4011  }
4012 
4013  $webspace_dir = ilUtil::getWebspaceDir();
4014  $image_dir = $webspace_dir."/usr_images";
4015  $images = array(
4016  "upload_".$a_user_id."pic",
4017  "usr_".$a_user_id."."."jpg",
4018  "usr_".$a_user_id."_small.jpg",
4019  "usr_".$a_user_id."_xsmall.jpg",
4020  "usr_".$a_user_id."_xxsmall.jpg",
4021  "upload_".$a_user_id);
4022  foreach ($images as $image)
4023  {
4024  if (is_file($image_dir."/".$image))
4025  {
4026  copy($image_dir."/".$image, $a_dir."/".$image);
4027  }
4028  }
4029  }
4030 
4031 
4035  function removeUserPicture($a_do_update = true)
4036  {
4037  $webspace_dir = ilUtil::getWebspaceDir();
4038  $image_dir = $webspace_dir."/usr_images";
4039  $file = $image_dir."/usr_".$this->getID()."."."jpg";
4040  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
4041  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
4042  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
4043  $upload_file = $image_dir."/upload_".$this->getID();
4044 
4045  if($a_do_update)
4046  {
4047  // remove user pref file name
4048  $this->setPref("profile_image", "");
4049  $this->update();
4050  }
4051 
4052  if (@is_file($file))
4053  {
4054  unlink($file);
4055  }
4056  if (@is_file($thumb_file))
4057  {
4058  unlink($thumb_file);
4059  }
4060  if (@is_file($xthumb_file))
4061  {
4062  unlink($xthumb_file);
4063  }
4064  if (@is_file($xxthumb_file))
4065  {
4066  unlink($xxthumb_file);
4067  }
4068  if (@is_file($upload_file))
4069  {
4070  unlink($upload_file);
4071  }
4072  }
4073 
4074 
4075  function setUserDefinedData($a_data)
4076  {
4077  if(!is_array($a_data))
4078  {
4079  return false;
4080  }
4081  foreach($a_data as $field => $data)
4082  {
4083  #$new_data[$field] = ilUtil::stripSlashes($data);
4084  // Assign it directly to avoid update problems of unchangable fields
4085  $this->user_defined_data['f_'.$field] = $data;
4086  }
4087  #$this->user_defined_data = $new_data;
4088 
4089  return true;
4090  }
4091 
4093  {
4094  return $this->user_defined_data ? $this->user_defined_data : array();
4095  }
4096 
4098  {
4099  global $ilDB;
4100 
4101  $fields = '';
4102 
4103  $field_def = array();
4104 
4105  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4106  $udata = new ilUserDefinedData($this->getId());
4107 
4108  foreach($this->user_defined_data as $field => $value)
4109  {
4110  if($field != 'usr_id')
4111  {
4112 // $field_def[$field] = array('text',$value);
4113  $udata->set($field, $value);
4114  }
4115  }
4116  $udata->update();
4117 
4118 /* if(!$field_def)
4119  {
4120  return true;
4121  }
4122 
4123  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4124  $res = $ilDB->query($query);
4125 
4126 
4127  if($res->numRows())
4128  {
4129  // Update
4130  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4131  }
4132  else
4133  {
4134  $field_def['usr_id'] = array('integer',$this->getId());
4135  $ilDB->insert('udf_data',$field_def);
4136  }
4137 */
4138  return true;
4139  }
4140 
4142  {
4143  global $ilDB;
4144 
4145  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4146  $udata = new ilUserDefinedData($this->getId());
4147 
4148 /* $query = "SELECT * FROM udf_data ".
4149  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4150 
4151  $res = $this->db->query($query);
4152  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
4153  {
4154  $this->user_defined_data = $row;
4155  }*/
4156 
4157  $this->user_defined_data = $udata->getAll();
4158 
4159  return true;
4160  }
4161 
4163  {
4164  global $ilDB;
4165 
4166 // not needed. no entry in udf_text/udf_clob means no value
4167 
4168 /* $query = "INSERT INTO udf_data (usr_id ) ".
4169  "VALUES( ".
4170  $ilDB->quote($this->getId(),'integer').
4171  ")";
4172  $res = $ilDB->manipulate($query);
4173 */
4174  return true;
4175  }
4176 
4178  {
4179  global $ilDB;
4180 
4181  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4183 
4184  // wrong place...
4185 /* $query = "DELETE FROM udf_data ".
4186  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4187  $res = $ilDB->manipulate($query);*/
4188 
4189  return true;
4190  }
4191 
4197  function getProfileAsString(&$a_language)
4198  {
4199  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4200  include_once './Services/Utilities/classes/class.ilFormat.php';
4201 
4202  global $lng,$rbacreview;
4203 
4204  $language =& $a_language;
4205  $language->loadLanguageModule('registration');
4206  $language->loadLanguageModule('crs');
4207 
4208  $body = '';
4209  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4210 
4211  if(strlen($this->getUTitle()))
4212  {
4213  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4214  }
4215  if(strlen($this->getGender()))
4216  {
4217  $gender = ($this->getGender() == 'm') ?
4218  $language->txt('gender_m') :
4219  $language->txt('gender_f');
4220  $body .= ($language->txt("gender").": ".$gender."\n");
4221  }
4222  if(strlen($this->getFirstname()))
4223  {
4224  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4225  }
4226  if(strlen($this->getLastname()))
4227  {
4228  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4229  }
4230  if(strlen($this->getInstitution()))
4231  {
4232  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4233  }
4234  if(strlen($this->getDepartment()))
4235  {
4236  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4237  }
4238  if(strlen($this->getStreet()))
4239  {
4240  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4241  }
4242  if(strlen($this->getCity()))
4243  {
4244  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4245  }
4246  if(strlen($this->getZipcode()))
4247  {
4248  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4249  }
4250  if(strlen($this->getCountry()))
4251  {
4252  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4253  }
4254  if(strlen($this->getSelectedCountry()))
4255  {
4256  $body .= ($language->txt("sel_country").": ".$this->getSelectedCountry()."\n");
4257  }
4258  if(strlen($this->getPhoneOffice()))
4259  {
4260  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4261  }
4262  if(strlen($this->getPhoneHome()))
4263  {
4264  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4265  }
4266  if(strlen($this->getPhoneMobile()))
4267  {
4268  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4269  }
4270  if(strlen($this->getFax()))
4271  {
4272  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4273  }
4274  if(strlen($this->getEmail()))
4275  {
4276  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4277  }
4278  if(strlen($this->getHobby()))
4279  {
4280  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4281  }
4282  if(strlen($this->getComment()))
4283  {
4284  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4285  }
4286  if(strlen($this->getMatriculation()))
4287  {
4288  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4289  }
4290  if(strlen($this->getCreateDate()))
4291  {
4296 
4297  $body .= ($language->txt("create_date").": ".$date."\n");
4298  }
4299 
4300  foreach($rbacreview->getGlobalRoles() as $role)
4301  {
4302  if($rbacreview->isAssigned($this->getId(),$role))
4303  {
4304  $gr[] = ilObjRole::_lookupTitle($role);
4305  }
4306  }
4307  if(count($gr))
4308  {
4309  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4310  }
4311 
4312  // Time limit
4313  if($this->getTimeLimitUnlimited())
4314  {
4315  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4316  }
4317  else
4318  {
4322  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4324 
4325  $start = new ilDateTime($this->getTimeLimitFrom(),IL_CAL_UNIX);
4326  $end = new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX);
4327 
4328  $body .= $language->txt('time_limit').': '.$start->get(IL_CAL_DATETIME);
4329  $body .= $language->txt('time_limit').': '.$end->get(IL_CAL_DATETIME);
4330 
4331 
4332  #$body .= $language->txt('time_limit').': '.$period;
4333  /*
4334  $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4335  ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4336  $language->txt('crs_to')." ".
4337  ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4338  */
4339  }
4340 
4341  include_once './Services/User/classes/class.ilUserDefinedFields.php';
4345  $user_defined_fields = ilUserDefinedFields::_getInstance();
4346  $user_defined_data = $this->getUserDefinedData();
4347 
4348  foreach($user_defined_fields->getDefinitions() as $field_id => $definition)
4349  {
4350  $data = $user_defined_data["f_".$field_id];
4351  if(strlen($data))
4352  {
4353  if($definition['field_type'] == UDF_TYPE_WYSIWYG)
4354  {
4355  $data = preg_replace('/<br(\s*)?\/?>/i', "\n", $data);
4356  $data = strip_tags($data);
4357  }
4358 
4359  $body .= $definition['field_name'].': '. $data . "\n";
4360  }
4361  }
4362 
4363  return $body;
4364  }
4365 
4366  function setInstantMessengerId($a_im_type, $a_im_id)
4367  {
4368  $var = "im_".$a_im_type;
4369  $this->$var = $a_im_id;
4370  }
4371 
4372  function getInstantMessengerId($a_im_type)
4373  {
4374  $var = "im_".$a_im_type;
4375  return $this->$var;
4376  }
4377 
4378  function setDelicious($a_delicious)
4379  {
4380  $this->delicious = $a_delicious;
4381  }
4382 
4383  function getDelicious()
4384  {
4385  return $this->delicious;
4386  }
4387 
4391  function _lookupFeedHash($a_user_id, $a_create = false)
4392  {
4393  global $ilDB;
4394 
4395  if ($a_user_id > 0)
4396  {
4397  $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4398  array("integer"), array($a_user_id));
4399  if ($rec = $ilDB->fetchAssoc($set))
4400  {
4401  if (strlen($rec["feed_hash"]) == 32)
4402  {
4403  return $rec["feed_hash"];
4404  }
4405  else if($a_create)
4406  {
4407  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4408  $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4409  " WHERE usr_id = %s",
4410  array("text", "integer"),
4411  array($hash, $a_user_id));
4412  return $hash;
4413  }
4414  }
4415  }
4416 
4417  return false;
4418  }
4419 
4425  function _getFeedPass($a_user_id)
4426  {
4427  global $ilDB;
4428 
4429  if ($a_user_id > 0)
4430  {
4431  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4432  }
4433  return false;
4434  }
4435 
4441  function _setFeedPass($a_user_id, $a_password)
4442  {
4443  global $ilDB;
4444 
4445  self::_writePref($a_user_id, "priv_feed_pass",
4446  ($a_password=="") ? "" : md5($a_password));
4447  }
4448 
4458  public static function _loginExists($a_login,$a_user_id = 0)
4459  {
4460  global $ilDB;
4461 
4462  $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4463  "WHERE login = %s";
4464  $types[] = "text";
4465  $values[] = $a_login;
4466 
4467  if ($a_user_id != 0)
4468  {
4469  $q.= " AND usr_id != %s ";
4470  $types[] = "integer";
4471  $values[] = $a_user_id;
4472  }
4473 
4474  $r = $ilDB->queryF($q, $types, $values);
4475 
4476  if ($row = $ilDB->fetchAssoc($r))
4477  {
4478  return $row['usr_id'];
4479  }
4480  return false;
4481  }
4482 
4493  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4494  {
4495  global $ilDB;
4496 
4497  $res = $ilDB->queryF("SELECT * FROM usr_data ".
4498  "WHERE ext_account = %s AND auth_mode = %s",
4499  array("text", "text"),
4500  array($a_external_account, $a_auth_mode));
4501  return $ilDB->fetchAssoc($res) ? true :false;
4502  }
4503 
4511  public static function _getUsersForRole($role_id, $active = -1) {
4512  global $ilDB, $rbacreview;
4513  $data = array();
4514 
4515  $ids = $rbacreview->assignedUsers($role_id);
4516 
4517  if (count ($ids) == 0)
4518  {
4519  $ids = array (-1);
4520  }
4521 
4522  $query = "SELECT usr_data.*, usr_pref.value AS language
4523  FROM usr_data
4524  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4525  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4526  $values[] = "language";
4527  $types[] = "text";
4528 
4529 
4530  if (is_numeric($active) && $active > -1)
4531  {
4532  $query .= " AND usr_data.active = %s";
4533  $values[] = $active;
4534  $types[] = "integer";
4535  }
4536 
4537  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4538 
4539  $r = $ilDB->queryF($query, $types, $values);
4540  $data = array();
4541  while ($row = $ilDB->fetchAssoc($r))
4542  {
4543  $data[] = $row;
4544  }
4545  return $data;
4546  }
4547 
4548 
4554  public static function _getUsersForFolder ($ref_id, $active) {
4555  global $ilDB;
4556  $data = array();
4557  $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 ";
4558  $types[] = "text";
4559  $values[] = "language";
4560 
4561  if (is_numeric($active) && $active > -1)
4562  {
4563  $query .= " AND usr_data.active = %s";
4564  $values[] = $active;
4565  $types[] = "integer";
4566  }
4567 
4568  if ($ref_id != USER_FOLDER_ID)
4569  {
4570  $query.= " AND usr_data.time_limit_owner = %s";
4571  $values[] = $ref_id;
4572  $types[] = "integer";
4573  }
4574 
4575  $query .= " AND usr_data.usr_id != %s ";
4576  $values[] = ANONYMOUS_USER_ID;
4577  $types[] = "integer";
4578 
4579  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4580 
4581  $result = $ilDB->queryF($query, $types, $values);
4582  $data = array();
4583  while ($row = $ilDB->fetchAssoc($result))
4584  {
4585  array_push($data, $row);
4586  }
4587 
4588  return $data;
4589  }
4590 
4591 
4597  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4598  {
4599  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4600  }
4601 
4602 
4608  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4609  {
4610  global $rbacadmin, $rbacreview, $ilDB;
4611 
4612  // quote all ids
4613  $ids = array();
4614  foreach ($a_mem_ids as $mem_id) {
4615  $ids [] = $ilDB->quote($mem_id);
4616  }
4617 
4618  $query = "SELECT usr_data.*, usr_pref.value AS language
4619  FROM usr_data
4620  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4621  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer")."
4622  AND usr_data.usr_id != %s";
4623  $values[] = "language";
4624  $types[] = "text";
4625  $values[] = ANONYMOUS_USER_ID;
4626  $types[] = "integer";
4627 
4628  if (is_numeric($active) && $active > -1)
4629  {
4630  $query .= " AND active = %s";
4631  $values[] = $active;
4632  $types[] = "integer";
4633  }
4634 
4635  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4636  {
4637  $query.= " AND usr_data.time_limit_owner = %s";
4638  $values[] = $timelimitowner;
4639  $types[] = "integer";
4640 
4641  }
4642 
4643  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4644 
4645  $result = $ilDB->queryF($query, $types, $values);
4646  while ($row = $ilDB->fetchAssoc($result))
4647  {
4648  $mem_arr[] = $row;
4649  }
4650 
4651  return $mem_arr ? $mem_arr : array();
4652  }
4653 
4654 
4655 
4661  public static function _getUserData ($a_internalids) {
4662  global $ilDB;
4663 
4664  $ids = array();
4665  if (is_array($a_internalids)) {
4666  foreach ($a_internalids as $internalid) {
4667  if (is_numeric ($internalid))
4668  {
4669  $ids[] = $internalid;
4670  }
4671  else
4672  {
4673  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4674  if (is_numeric($parsedid) && $parsedid > 0)
4675  {
4676  $ids[] = $parsedid;
4677  }
4678  }
4679  }
4680  }
4681  if (count($ids) == 0)
4682  $ids [] = -1;
4683 
4684  $query = "SELECT usr_data.*, usr_pref.value AS language
4685  FROM usr_data
4686  LEFT JOIN usr_pref
4687  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4688  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4689  $values[] = "language";
4690  $types[] = "text";
4691 
4692  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4693 
4694  $data = array();
4695  $result = $ilDB->queryF($query, $types, $values);
4696  while ($row = $ilDB->fetchAssoc($result))
4697  {
4698  $data[] = $row;
4699  }
4700  return $data;
4701  }
4702 
4709  public static function _getPreferences ($user_id)
4710  {
4711  global $ilDB;
4712 
4713  $prefs = array();
4714 
4715  $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4716  array("integer"), array($user_id));
4717 
4718  while($row = $ilDB->fetchAssoc($r))
4719  {
4720  $prefs[$row["keyword"]] = $row["value"];
4721  }
4722 
4723  return $prefs;
4724  }
4725 
4735  public static function getUserSubsetByPreferenceValue($a_user_ids, $a_keyword, $a_val)
4736  {
4737  global $ilDB;
4738 
4739  $users = array();
4740  $set = $ilDB->query("SELECT usr_id FROM usr_pref ".
4741  " WHERE keyword = ".$ilDB->quote($a_keyword, "text").
4742  " AND ".$ilDB->in("usr_id", $a_user_ids, false, "integer").
4743  " AND value = ".$ilDB->quote($a_val, "text")
4744  );
4745  while ($rec = $ilDB->fetchAssoc($set))
4746  {
4747  $users[] = $rec["usr_id"];
4748  }
4749  return $users;
4750  }
4751 
4752 
4753  public static function _resetLoginAttempts($a_usr_id)
4754  {
4755  global $ilDB;
4756 
4757  $query = "UPDATE usr_data SET login_attempts = 0 WHERE usr_id = %s";
4758  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4759 
4760  if($affected) return true;
4761  else return false;
4762  }
4763 
4764  public static function _getLoginAttempts($a_usr_id)
4765  {
4766  global $ilDB;
4767 
4768  $query = "SELECT login_attempts FROM usr_data WHERE usr_id = %s";
4769  $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4770  $record = $ilDB->fetchAssoc( $result );
4771  $login_attempts = $record['login_attempts'];
4772 
4773  return $login_attempts;
4774  }
4775 
4776  public static function _incrementLoginAttempts($a_usr_id)
4777  {
4778  global $ilDB;
4779 
4780  $query = "UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s";
4781  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4782 
4783  if($affected) return true;
4784  else return false;
4785  }
4786 
4787  public static function _setUserInactive($a_usr_id)
4788  {
4789  global $ilDB;
4790 
4791  $query = "UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s";
4792  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array(ilUtil::now(), $a_usr_id) );
4793 
4794  if($affected) return true;
4795  else return false;
4796  }
4797 
4803  public function hasPublicProfile() {
4804  return in_array($this->getPref("public_profile"), array("y", "g"));
4805  }
4806 
4812  public function getPublicName()
4813  {
4814  if ($this->hasPublicProfile())
4815  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4816  else
4817  return $this->getLogin();
4818 
4819  }
4820 
4821  public static function _writeHistory($a_usr_id, $a_login)
4822  {
4823  global $ilDB;
4824 
4825  $timestamp = time();
4826 
4827  $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4828  array('integer', 'text', 'integer'),
4829  array($a_usr_id, $a_login, $timestamp));
4830 
4831  if( $ilDB->numRows($res) == 0 )
4832  {
4833  $ilDB->manipulateF('
4834  INSERT INTO loginname_history
4835  (usr_id, login, history_date)
4836  VALUES (%s, %s, %s)',
4837  array('integer', 'text', 'integer'),
4838  array($a_usr_id, $a_login, $timestamp));
4839  }
4840 
4841  return true;
4842  }
4843 
4851  public static function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4852  {
4856  global $ilDB, $rbacreview;
4857 
4858  $pd_set = new ilSetting('pd');
4859  $atime = $pd_set->get('user_activity_time') * 60;
4860  $ctime = time();
4861 
4862  $where = array();
4863 
4864  if($a_user_id == 0)
4865  {
4866  $where[] = 'user_id > 0';
4867  }
4868  else if (is_array($a_user_id))
4869  {
4870  $where[] = $ilDB->in("user_id", $a_user_id, false, "integer");
4871  }
4872  else
4873  {
4874  $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
4875  }
4876 
4877  if($a_no_anonymous)
4878  {
4879  $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
4880  }
4881 
4882  include_once 'Services/User/classes/class.ilUserAccountSettings.php';
4883  if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
4884  {
4885  include_once 'Services/User/classes/class.ilUserFilter.php';
4886  $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
4887  }
4888 
4889  $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
4890  $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
4891 
4892  $where = 'WHERE ' . implode(' AND ', $where);
4893 
4894  $r = $ilDB->queryF("
4895  SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime, agree_date
4896  FROM usr_session
4897  LEFT JOIN usr_data u
4898  ON user_id = u.usr_id
4899  LEFT JOIN usr_pref p
4900  ON (p.usr_id = u.usr_id AND p.keyword = %s)
4901  {$where}
4902  GROUP BY user_id, firstname, lastname, title, login, last_login, agree_date
4903  ORDER BY lastname, firstname
4904  ",
4905  array('text'),
4906  array('hide_own_online_status')
4907  );
4908 
4909  $users = array();
4910  while($user = $ilDB->fetchAssoc($r))
4911  {
4912  if($atime <= 0 || $user['ctime'] + $atime > $ctime)
4913  {
4914  $users[$user['user_id']] = $user;
4915  }
4916  }
4917 
4918  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4919  if (ilTermsOfServiceHelper::isEnabled()) {
4920  $users = array_filter($users, function($user) {
4921  if ($user['agree_date'] || $user['user_id'] == SYSTEM_USER_ID || 'root' === $user['login']) {
4922  return true;
4923  }
4924 
4925  return false;
4926  });
4927  }
4928 
4929  return $users;
4930  }
4931 
4941  public static function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4942  {
4943  global $ilias, $ilDB;
4944 
4945  $pd_set = new ilSetting("pd");
4946  $atime = $pd_set->get("user_activity_time") * 60;
4947  $ctime = time();
4948  $no_anonym = ($a_no_anonymous)
4949  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4950  : "";
4951 
4952  // Get a list of object id's of all courses and groups for which
4953  // the current user has local roles.
4954  // Note: we have to use DISTINCT here, because a user may assume
4955  // multiple roles in a group or a course.
4956  $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4957  "FROM rbac_ua ua ".
4958  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4959  "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4960  "JOIN tree ON tree.child = r1.ref_id ".
4961  "JOIN object_reference r2 ON r2.ref_id = tree.child ". // #17674 - rolf is gone
4962  "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4963  "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4964  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4965  "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4966  $ilDB->quote("grp", "text").")";
4967  $r = $ilDB->query($q);
4968 
4969  while ($row = $ilDB->fetchAssoc($r))
4970  {
4971  $groups_and_courses_of_user[] = $row["obj_id"];
4972  }
4973 
4974  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4975  $tos_condition = '';
4976  if(ilTermsOfServiceHelper::isEnabled())
4977  {
4978  $tos_condition = " AND (agree_date IS NOT NULL OR ud.usr_id = " . $ilDB->quote(SYSTEM_USER_ID, 'integer') . ") ";
4979  }
4980 
4981  // If the user is not in a course or a group, he has no associated users.
4982  if (count($groups_and_courses_of_user) == 0)
4983  {
4984  $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4985  "FROM usr_session ".
4986  "JOIN usr_data ud ON user_id = ud.usr_id ".
4987  "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4988  $no_anonym.
4989  $tos_condition.
4990  "AND expires > ".$ilDB->quote(time(), "integer")." ".
4991  "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4992  $r = $ilDB->query($q);
4993  }
4994  else
4995  {
4996  $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4997  "FROM usr_session s ".
4998  "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4999  "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
5000  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
5001  "JOIN tree ON tree.child = fa.parent ".
5002  "JOIN object_reference or1 ON or1.ref_id = tree.child ". // #17674 - rolf is gone
5003  "JOIN object_data od ON od.obj_id = or1.obj_id ".
5004  "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
5005  $ilDB->quote("hide_own_online_status", "text").") ".
5006  "WHERE s.user_id != 0 ".
5007  $no_anonym.
5008  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
5009  "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
5010  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
5011  $tos_condition.
5012  "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
5013  "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
5014  "ORDER BY ud.lastname, ud.firstname";
5015  $r = $ilDB->query($q);
5016  }
5017 
5018  while ($user = $ilDB->fetchAssoc($r))
5019  {
5020  if ($atime <= 0
5021  || $user["ctime"] + $atime > $ctime)
5022  {
5023  $users[$user["user_id"]] = $user;
5024  }
5025  }
5026 
5027  return $users ? $users : array();
5028  }
5029 
5036  public static function _generateRegistrationHash($a_usr_id)
5037  {
5038  global $ilDB;
5039 
5040  do
5041  {
5042  $continue = false;
5043 
5044  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
5045 
5046  $res = $ilDB->queryf('
5047  SELECT COUNT(usr_id) cnt FROM usr_data
5048  WHERE reg_hash = %s',
5049  array('text'),
5050  array($hashcode));
5051  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5052  {
5053  if($row->cnt > 0) $continue = true;
5054  break;
5055  }
5056 
5057  if($continue) continue;
5058 
5059  $ilDB->manipulateF('
5060  UPDATE usr_data
5061  SET reg_hash = %s
5062  WHERE usr_id = %s',
5063  array('text', 'integer'),
5064  array($hashcode, (int)$a_usr_id)
5065  );
5066 
5067  break;
5068 
5069  } while(true);
5070 
5071  return $hashcode;
5072  }
5073 
5082  public static function _verifyRegistrationHash($a_hash)
5083  {
5084  global $ilDB;
5085 
5086  $res = $ilDB->queryf('
5087  SELECT usr_id, create_date FROM usr_data
5088  WHERE reg_hash = %s',
5089  array('text'),
5090  array($a_hash));
5091  while($row = $ilDB->fetchAssoc($res))
5092  {
5093  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
5094  $oRegSettigs = new ilRegistrationSettings();
5095 
5096  if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
5097  time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
5098  {
5099  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
5100  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
5101  }
5102 
5103  $ilDB->manipulateF('
5104  UPDATE usr_data
5105  SET reg_hash = %s
5106  WHERE usr_id = %s',
5107  array('text', 'integer'),
5108  array('', (int)$row['usr_id'])
5109  );
5110 
5111  return (int)$row['usr_id'];
5112  }
5113 
5114  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
5115  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
5116  }
5117 
5118  function setBirthday($a_birthday)
5119  {
5120  if (strlen($a_birthday))
5121  {
5122  $date = new ilDate($a_birthday, IL_CAL_DATE);
5123  $this->birthday = $date->get(IL_CAL_DATE);
5124  }
5125  else
5126  {
5127  $this->birthday = null;
5128  }
5129  }
5130 
5131  function getBirthday()
5132  {
5133  return $this->birthday;
5134  }
5135 
5144  public static function _getUserIdsByInactivityPeriod($period)
5145  {
5146  if( !(int)$period ) throw new ilException('no valid period given');
5147 
5148  global $ilDB;
5149 
5150  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5151 
5152  $query = "SELECT usr_id FROM usr_data WHERE last_login < %s OR (ISNULL(last_login) AND create_date < %s)";
5153 
5154  $res = $ilDB->queryF($query, array('timestamp', 'timestamp'), array($date, $date));
5155 
5156  $ids = array();
5157  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5158  {
5159  $ids[] = $row->usr_id;
5160  }
5161 
5162  return $ids;
5163  }
5164 
5173  public static function _getUserIdsByInactivationPeriod($period)
5174  {
5176  $field = 'inactivation_date';
5178 
5179  if( !(int)$period ) throw new ilException('no valid period given');
5180 
5181  global $ilDB;
5182 
5183  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5184 
5185  $query = "SELECT usr_id FROM usr_data WHERE $field < %s AND active = %s";
5186 
5187  $res = $ilDB->queryF($query, array('timestamp', 'integer'), array($date, 0));
5188 
5189  $ids = array();
5190  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5191  {
5192  $ids[] = $row->usr_id;
5193  }
5194 
5195  return $ids;
5196  }
5197 
5207  public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5208  {
5209  if($a_last_login !== null) $last_login = $a_last_login;
5210  else $last_login = date('Y-m-d H:i:s');
5211 
5212  global $ilDB;
5213 
5214  $query = "UPDATE usr_data SET last_login = %s WHERE usr_id = %s";
5215  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array($last_login, $a_usr_id) );
5216 
5217  if($affected) return $last_login;
5218  else return false;
5219  }
5220 
5221  public function resetOwner()
5222  {
5223  global $ilDB;
5224 
5225  $query = "UPDATE object_data SET owner = 0 ".
5226  "WHERE owner = ".$ilDB->quote($this->getId(),'integer');
5227  $ilDB->query($query);
5228 
5229  return true;
5230  }
5231 
5232 
5239  static function getFirstLettersOfLastnames()
5240  {
5241  global $ilDB;
5242 
5243  $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("lastname", 1, 1))." let".
5244  " FROM usr_data".
5245  " WHERE usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer").
5246  " ORDER BY let";
5247  $let_set = $ilDB->query($q);
5248 
5249  $lets = array();
5250  while ($let_rec = $ilDB->fetchAssoc($let_set))
5251  {
5252  $let[$let_rec["let"]] = $let_rec["let"];
5253  }
5254  return $let;
5255  }
5256 
5257  // begin-patch deleteProgress
5258  public static function userExists($a_usr_ids = array())
5259  {
5260  global $ilDB;
5261 
5262  $query = 'SELECT count(*) num FROM object_data od '.
5263  'JOIN usr_data ud ON obj_id = usr_id '.
5264  'WHERE '.$ilDB->in('obj_id',$a_usr_ids,false,'integer').' ';
5265  $res = $ilDB->query($query);
5266  $num_rows =$res->fetchRow(DB_FETCHMODE_OBJECT)->num;
5267  return $num_rows == count((array) $a_usr_ids);
5268  }
5269  // end-patch deleteProgress
5270 
5275  {
5276  return (boolean) $_SESSION["user_captcha_verified"];
5277  }
5278 
5284  function setCaptchaVerified($a_val)
5285  {
5286  $_SESSION["user_captcha_verified"] = $a_val;
5287  }
5288 
5296  {
5297  include_once("./Services/Export/classes/class.ilExport.php");
5298  $exp = new ilExport();
5299  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5300  ilUtil::delDir($dir, true);
5301  $title = $this->getLastname().", ".$this->getLastname()." [".$this->getLogin()."]";
5302  $exp->exportEntity("personal_data", $this->getId(), "4.5.0",
5303  "Services/User", $title, $dir);
5304  }
5305 
5313  {
5314  include_once("./Services/Export/classes/class.ilExport.php");
5315  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5316  if (!is_dir($dir))
5317  {
5318  return "";
5319  }
5320  foreach(ilUtil::getDir($dir) as $entry)
5321  {
5322  if (is_int(strpos($entry["entry"], ".zip")))
5323  {
5324  return $entry["entry"];
5325  }
5326  }
5327 
5328  return "";
5329  }
5330 
5338  {
5339  include_once("./Services/Export/classes/class.ilExport.php");
5340  $file = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data").
5341  "/".$this->getPersonalDataExportFile();
5342  if (is_file($file))
5343  {
5345  }
5346  }
5347 
5354  function importPersonalData($a_file, $a_profile_data, $a_settings,
5355  $a_bookmarks, $a_notes, $a_calendar)
5356  {
5357  include_once("./Services/Export/classes/class.ilImport.php");
5358  $imp = new ilImport();
5359  if (!$a_profile_data)
5360  {
5361  $imp->addSkipEntity("Services/User", "usr_profile");
5362  }
5363  if (!$a_settings)
5364  {
5365  $imp->addSkipEntity("Services/User", "usr_setting");
5366  }
5367  if (!$a_bookmarks)
5368  {
5369  $imp->addSkipEntity("Services/Bookmarks", "bookmarks");
5370  }
5371  if (!$a_notes)
5372  {
5373  $imp->addSkipEntity("Services/Notes", "user_notes");
5374  }
5375  if (!$a_calendar)
5376  {
5377  $imp->addSkipEntity("Services/Calendar", "calendar");
5378  }
5379  $imp->importEntity($a_file["tmp_name"], $a_file["name"], "personal_data",
5380  "Services/User");
5381  }
5382 
5388  private static function initInactivationDate($usrIds)
5389  {
5390  global $ilDB;
5391 
5392  $NOW = $ilDB->now();
5393 
5394  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5395 
5396  $queryString = "
5397  UPDATE usr_data
5398  SET inactivation_date = $NOW
5399  WHERE inactivation_date IS NULL
5400  AND $usrId_IN_usrIds
5401  ";
5402 
5403  $ilDB->manipulate($queryString);
5404  }
5405 
5411  private static function resetInactivationDate($usrIds)
5412  {
5413  global $ilDB;
5414 
5415  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5416 
5417  $queryString = "
5418  UPDATE usr_data
5419  SET inactivation_date = NULL
5420  WHERE $usrId_IN_usrIds
5421  ";
5422 
5423  $ilDB->manipulate($queryString);
5424  }
5425 
5432  {
5433  $this->inactivation_date = $inactivation_date;
5434  }
5435 
5441  public function getInactivationDate()
5442  {
5443  return $this->inactivation_date;
5444  }
5445 
5449  public function hasToAcceptTermsOfService()
5450  {
5451  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5452 
5453  if(
5454  ilTermsOfServiceHelper::isEnabled() &&
5455  null == $this->agree_date &&
5456  'root' != $this->login &&
5457  !in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID))
5458  )
5459  {
5460  return true;
5461  }
5462 
5463  return false;
5464  }
5465 
5470  public static function hasUserToAcceptTermsOfService($a_username)
5471  {
5475  global $ilDB;
5476 
5477  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5478 
5479  if(!ilTermsOfServiceHelper::isEnabled())
5480  {
5481  return false;
5482  }
5483 
5484  $in = $ilDB->in('usr_id', array(ANONYMOUS_USER_ID, SYSTEM_USER_ID), true, 'integer');
5485  $res = $ilDB->queryF(
5486  "SELECT usr_id FROM usr_data WHERE login = %s AND agree_date IS NULL $in",
5487  array("text"),
5488  array($a_username)
5489  );
5490  return $ilDB->fetchAssoc($res) ? true : false;
5491  }
5492 
5500  public static function getUsersAgreed($a_agreed = true, $a_users = null)
5501  {
5502  global $ilDB;
5503 
5504  $date_is = ($a_agreed)
5505  ? "IS NOT NULL"
5506  : "IS NULL";
5507 
5508  $users = (is_array($a_users))
5509  ? " AND ".$ilDB->in("usr_id", $a_users, false, "integer")
5510  : "";
5511 
5512  $set = $ilDB->query("SELECT usr_id FROM usr_data ".
5513  " WHERE agree_date ".$date_is.
5514  $users);
5515  $ret = array();
5516  while ($rec = $ilDB->fetchAssoc($set))
5517  {
5518  $ret[] = $rec["usr_id"];
5519  }
5520  return $ret;
5521  }
5522 
5523 
5528  public function hasToAcceptTermsOfServiceInSession($status = null)
5529  {
5530  if(null === $status)
5531  {
5532  return ilSession::get('has_to_accept_agr_in_session');
5533  }
5534 
5535  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5536  if(ilTermsOfServiceHelper::isEnabled())
5537  {
5538  ilSession::set('has_to_accept_agr_in_session', (int)$status);
5539  }
5540  }
5541 
5545  public function isAnonymous()
5546  {
5547  return self::_isAnonymous($this->getId());
5548  }
5549 
5554  public static function _isAnonymous($usr_id)
5555  {
5556  return $usr_id == ANONYMOUS_USER_ID;
5557  }
5558 
5559  public function activateDeletionFlag()
5560  {
5561  $this->writePref("delete_flag", true);
5562  }
5563 
5564  public function removeDeletionFlag()
5565  {
5566  $this->writePref("delete_flag", false);
5567  }
5568 
5569  public function hasDeletionFlag()
5570  {
5571  return (bool)$this->getPref("delete_flag");
5572  }
5573 
5577  public function setIsSelfRegistered($status)
5578  {
5579  $this->is_self_registered = (bool) $status;
5580  }
5581 
5582  public function isSelfRegistered()
5583  {
5584  return (bool) $this->is_self_registered;
5585  }
5586 
5587 
5588  //
5589  // MULTI-TEXT / INTERESTS
5590  //
5591 
5597  public function setGeneralInterests(array $value = null)
5598  {
5599  $this->interests_general = $value;
5600  }
5601 
5607  public function getGeneralInterests()
5608  {
5609  return $this->interests_general;
5610  }
5611 
5617  public function getGeneralInterestsAsText()
5618  {
5619  return $this->buildTextFromArray("interests_general");
5620  }
5621 
5627  public function setOfferingHelp(array $value = null)
5628  {
5629  $this->interests_help_offered = $value;
5630  }
5631 
5637  public function getOfferingHelp()
5638  {
5640  }
5641 
5647  public function getOfferingHelpAsText()
5648  {
5649  return $this->buildTextFromArray("interests_help_offered");
5650  }
5651 
5657  public function setLookingForHelp(array $value = null)
5658  {
5659  $this->interests_help_looking = $value;
5660  }
5661 
5667  public function getLookingForHelp()
5668  {
5670  }
5671 
5677  public function getLookingForHelpAsText()
5678  {
5679  return $this->buildTextFromArray("interests_help_looking");
5680  }
5681 
5688  protected function buildTextFromArray($a_attr)
5689  {
5690  $current = $this->$a_attr;
5691  if(is_array($current) && sizeof($current))
5692  {
5693  return implode(", ", $current);
5694  }
5695  }
5696 
5700  protected function readMultiTextFields()
5701  {
5702  global $ilDB;
5703 
5704  if(!$this->getId())
5705  {
5706  return;
5707  }
5708 
5709  $set = $ilDB->query("SELECT field_id,value".
5710  " FROM usr_data_multi".
5711  " WHERE usr_id = ".$ilDB->quote($this->getId(), "integer").
5712  " ORDER BY value");
5713  while($row = $ilDB->fetchAssoc($set))
5714  {
5715  $values[$row["field_id"]][] = $row["value"];
5716  }
5717 
5718  if(isset($values["interests_general"]))
5719  {
5720  $this->setGeneralInterests($values["interests_general"]);
5721  }
5722  else
5723  {
5724  $this->setGeneralInterests();
5725  }
5726  if(isset($values["interests_help_offered"]))
5727  {
5728  $this->setOfferingHelp($values["interests_help_offered"]);
5729  }
5730  else
5731  {
5732  $this->setOfferingHelp();
5733  }
5734  if(isset($values["interests_help_looking"]))
5735  {
5736  $this->setLookingForHelp($values["interests_help_looking"]);
5737  }
5738  else
5739  {
5740  $this->setLookingForHelp();
5741  }
5742  }
5743 
5749  public function updateMultiTextFields($a_create = false)
5750  {
5751  global $ilDB;
5752 
5753  if(!$this->getId())
5754  {
5755  return;
5756  }
5757 
5758  if(!$a_create)
5759  {
5760  $this->deleteMultiTextFields();
5761  }
5762 
5763  $map = array(
5764  "interests_general" => $this->getGeneralInterests(),
5765  "interests_help_offered" => $this->getOfferingHelp(),
5766  "interests_help_looking" => $this->getLookingForHelp()
5767  );
5768 
5769  foreach($map as $id => $values)
5770  {
5771  if(is_array($values) && sizeof($values))
5772  {
5773  foreach($values as $value)
5774  {
5775  $value = trim($value);
5776  if($value)
5777  {
5778  $uniq_id = $ilDB->nextId('usr_data_multi');
5779 
5780  $ilDB->manipulate("INSERT usr_data_multi".
5781  " (id,usr_id,field_id,value) VALUES".
5782  " (".$ilDB->quote($uniq_id, "integer").
5783  ",".$ilDB->quote($this->getId(), "integer").
5784  ",".$ilDB->quote($id, "text").
5785  ",".$ilDB->quote($value, "text").
5786  ")");
5787  }
5788  }
5789  }
5790  }
5791  }
5792 
5796  protected function deleteMultiTextFields()
5797  {
5798  global $ilDB;
5799 
5800  if(!$this->getId())
5801  {
5802  return;
5803  }
5804 
5805  $ilDB->manipulate("DELETE FROM usr_data_multi".
5806  " WHERE usr_id = ".$ilDB->quote($this->getId(), "integer"));
5807  }
5808 
5809  public static function findInterests($a_term, $a_user_id = null, $a_field_id = null)
5810  {
5811  global $ilDB;
5812 
5813  $res = array();
5814 
5815  $sql = "SELECT DISTINCT(value)".
5816  " FROM usr_data_multi".
5817  " WHERE ".$ilDB->like("value", "text", "%".$a_term."%");
5818  if($a_field_id)
5819  {
5820  $sql .= " AND field_id = ".$ilDB->quote($a_field_id, "text");
5821  }
5822  if($a_user_id)
5823  {
5824  $sql .= " AND usr_id <> ".$ilDB->quote($a_user_id, "integer");
5825  }
5826  $sql .= " ORDER BY value";
5827  $set = $ilDB->query($sql);
5828  while($row = $ilDB->fetchAssoc($set))
5829  {
5830  $res[] = $row["value"];
5831  }
5832 
5833  return $res;
5834  }
5835 } // END class ilObjUser
5836 ?>
getCurrentLanguage()
returns the current language (may differ from user&#39;s pref setting!)
static _lookupLogin($a_user_id)
lookup login
static _lookupName($a_user_id)
lookup user name
Class for user related exception handling in ILIAS.
static _getUserIdsByInactivationPeriod($period)
get ids of all users that have been inactivated since at least the given period
setActive($a_active, $a_owner=0)
set user active state and updates system fields appropriately public
ILIAS Setting Class.
Class UserMail this class handles user mails.
dropDesktopItem($a_item_id, $a_type)
drop an item from user&#39;s personal desktop
print $file
getClipboardObjects($a_type="", $a_top_nodes_only=false)
get all clipboard objects of user and specified type
static $is_desktop_item_loaded
static _getInstance()
get singleton instance
const IL_PASSWD_PLAIN
setInstitution($a_str)
set institution public
refreshLogin()
updates the login data of a "user" // TODO set date with now() should be enough public ...
static initInactivationDate($usrIds)
type $ilDB
Base class for ILIAS Exception handling.
getAuthMode($a_auth_key=false)
get auth mode public
setLatitude($a_latitude)
Set Latitude.
getLogin()
get login / username public
setOfferingHelp(array $value=null)
Set help offering.
getActive()
get user active state public
const IL_CAL_DATETIME
static _getInstance()
Get instance.
static _deleteUser($a_usr_id)
clipboardDeleteAll()
Delete objects of type for user.
static preloadIsDesktopItem($a_usr_id, $a_item_ids)
Preload desktop item information.
static lookupMatriculation($a_usr_id)
Lookup matriculation.
Class ilUserDefinedData.
getTimeZone()
get timezone of user
$_SESSION["AccountId"]
setDepartment($a_str)
set department public
$result
_lookupLastLogin($a_user_id)
lookup last login
_getLocalAccountsForEmail($a_email)
check whether external account and authentication method matches with a user
static _deleteSettingsOfUser($a_user)
Delete block settings of user.
_lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
getFirstname()
get firstname public
setSelectedCountry($a_val)
Set selected country (selection drop down)
getLoginByUserId($a_userid)
setLoginAttempts($a_login_attempts)
setCaptchaVerified($a_val)
Set captcha verified.
getMatriculation()
get matriculation number public
getGeneralInterestsAsText()
Get general interests as plain text.
setLanguage($a_str)
set user language public
removeUserPicture($a_do_update=true)
Remove user picture.
setFullname($a_title="", $a_firstname="", $a_lastname="")
builds a string with title + firstname + lastname method is used to build fullname in member variable...
getDesktopItems($a_types="")
_moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
skins and styles
static _writePref($a_usr_id, $a_keyword, $a_value)
Class for user related exception handling in ILIAS.
setLastLogin($a_str)
set user&#39;s last login public
getInactivationDate()
getter for inactivation date
getFax()
get fax public
Class ilObject Basic functions for all objects.
setProfileIncomplete($a_prof_inc)
_lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
Custom block for external feeds on personal desktop.
getDepartment()
get department public
setAuthMode($a_str)
set auth mode public
const IL_PASSWD_CRYPTED
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static deleteByOwner($a_owner_id)
Delete all entries for owner.
static _incrementLoginAttempts($a_usr_id)
$login
all user related data in single vars public
static get($a_var)
Get a value.
getLocationZoom()
Get Location Zoom.
setId($a_id)
set object id public
static _getExternalAccountsByAuthMode($a_auth_mode, $a_read_auth_default=false)
Get list of external account by authentication method Note: If login == ext_account for two user with...
setDesktopItemParameters($a_item_id, $a_type, $a_par)
set parameters of a desktop item entry
static set($a_var, $a_val)
Set a value.
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static resetToDefaults()
reset to defaults
static _getUserIdsByInactivityPeriod($period)
get ids of all users that have been inactive for at least the given period
Import class.
static _getLastHistoryDataByUserId($a_usr_id)
Returns the last used loginname and the changedate of the passed user_id.
static _lookupId($a_user_str)
Lookup id by login.
getInstitution()
get institution public
setTimeLimitOwner($a_owner)
static setUseRelativeDates($a_status)
set use relative dates
assignData($a_data)
loads a record "user" from array public
static _lookupTitle($a_id)
lookup object title
static $personal_image_cache
setBirthday($a_birthday)
static _isActive()
Static getter.
static deletePDItemsCache($a_usr_id)
Delete cache (add remove desktop item)
setLastname($a_str)
set lastame public
getCreateDate()
get create date public
Base class for nested set path based trees.
getLongitude()
Get Longitude.
_lookupPref($a_usr_id, $a_keyword)
getPhoneOffice()
get office phone public
static _needsExternalAccountByAuthMode($a_auth_mode)
Check if chosen auth mode needs an external account entry.
const IL_CAL_UNIX
getStreet()
get street public
static userExists($a_usr_ids=array())
static getInstance()
Singelton get instance.
static _lookupGender($a_user_id)
Lookup gender.
setIsSelfRegistered($status)
getCountry()
Get country (free text)
static _resetLoginAttempts($a_usr_id)
getPref($a_keyword)
get a user preference
static _getAuthModeName($a_auth_key)
static now()
Return current timestamp in Y-m-d H:i:s format.
static _getLoginAttempts($a_usr_id)
static _toggleActiveStatusOfUsers($a_usr_ids, $a_status)
Toggle active status of users.
static lookupTitle($a_page_id)
Lookup title.
_getNumberOfUsersPerAuthMode()
get number of users per auth mode
read()
loads a record "user" from database private
getPublicName()
returns firstname lastname and login if profile is public, login otherwise
deleteUserDefinedFieldEntries()
setCountry($a_str)
Set country (free text)
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
getLookingForHelp()
Get help looking for.
setPhoneHome($a_str)
set home phone public
setDelicious($a_delicious)
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
getOfferingHelpAsText()
Get help offering as plain text.
setTimeLimitUnlimited($a_unlimited)
Tree handler for personal workspace.
_getImportedUserId($i2_id)
setPref($a_keyword, $a_value)
set a user preference
static _verifyRegistrationHash($a_hash)
Verifies a registration hash.
_lookupFullname($a_user_id)
Lookup Full Name.
_uploadPersonalPicture($tmp_file, $obj_id)
Create a personal picture image file from a temporary image file.
setInactivationDate($inactivation_date)
setter for inactivation date
setZipcode($a_str)
set zipcode public
getUserIdByLogin($a_login)
_getNumberOfUsersForStyle($a_skin, $a_style)
skins and styles
setDiskQuota($a_disk_quota)
Sets the minimal disk quota imposed by this user account.
static _externalAccountExists($a_external_account, $a_auth_mode)
Check if an external account name already exists.
getDateFormat()
get date format
isDesktopItem($a_item_id, $a_type)
check wether an item is on the users desktop or not
addDesktopItem($a_item_id, $a_type, $a_par="")
add an item to user&#39;s personal desktop
setAgreeDate($a_str)
set date the user account was accepted by the user nullindicates that the user has not accepted his a...
_getFeedPass($a_user_id)
Lookup news feed password for user.
static setLanguage($a_lng)
set language
getUserIdByEmail($a_email)
STATIC METHOD get the user_id of an email address.
getAgreeDate()
get the date when the user accepted the user agreement public
static removeForUser($user_id)
Remove all notifications for given user.
static _getInstance()
Get singleton instance of this class.
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
setEmail($a_str)
set email public
getGeneralInterests()
Get general interests.
writeAccepted()
write accept date of user agreement to db
setPasswd($a_str, $a_type=IL_PASSWD_PLAIN)
set password public
static _removeItemFromDesktops($a_id)
removes object from all user&#39;s desktops public
getExternalAccount()
get external account
getCity()
get city public
isChild($a_usr_id)
setTimeLimitUntil($a_until)
getPersonalWorkspaceDiskQuota()
setLogin($a_str)
set login / username public
$r
Definition: example_031.php:79
getZipcode()
get zipcode public
getEmail()
get email address public
static toUsernameWithoutDomain($username)
Static function removes Microsoft domain name from username.
setUserDefinedData($a_data)
$data
static copyProfilePicturesToDirectory($a_user_id, $a_dir)
Get profile picture direcotory.
getLastname()
get lastname public
setOwner($a_owner)
set object owner
Class for single dates.
static execConvert($args)
execute convert command
setExternalAccount($a_str)
set external account
getId()
get object id public
exportPersonalData()
Export personal data.
static getLoginFromAuth()
Gets the username from $ilAuth, and converts it into an ILIAS login name.
setComment($a_str)
set referral comment public
getDiskQuota()
Returns the minimal disk quota imposed by this user account.
static _lookup($a_user_id, $a_field)
Private function for lookup methods.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static hasActiveSession($a_user_id)
Check for simultaneous login.
static _lookupDescription($a_id)
lookup object description
Mail Box class Base class for creating and handling mail boxes.
static searchUsers($a_search_str, $active=1, $a_return_ids_only=false, $filter_settings=FALSE)
STATIC METHOD get the user_ids which correspond a search string.
clipboardDeleteObjectsOfType($a_type)
Delete objects of type for user.
deletePref($a_keyword)
Deletes a userpref value of the user from the database public.
syncActive()
synchronizes current and stored user active values for the owner value to be set correctly, this function should only be called when an admin is approving a user account public
setHobby($a_str)
set hobby public
setInstantMessengerId($a_im_type, $a_im_id)
setLocationZoom($a_locationzoom)
Set Location Zoom.
setMatriculation($a_str)
set matriculation number public
writePref($a_keyword, $a_value)
write userpref to user table private
setTimeLimitMessage($a_time_limit_message)
static formatDate(ilDateTime $date)
Format a date public.
_lookupIm($a_user_id, $a_type)
Lookup IM.
isCaptchaVerified()
Is user captcha verified?
getLastLogin()
returns last login date public
static _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user&#39;s personal desktop
clipboardHasObjectsOfType($a_type)
Check whether clipboard has objects of a certain type.
Date and time handling
getOfferingHelp()
Get help offering.
addObjectToClipboard($a_item_id, $a_type, $a_title, $a_parent=0, $a_time=0, $a_order_nr=0)
add an item to user&#39;s personal clipboard
redirection script todo: (a better solution should control the processing via a xml file) ...
getLookingForHelpAsText()
Get help looking for as plain text.
static _removeTrackingDataForUser($user_id)
_lookupEmail($a_user_id)
Lookup email.
_setFeedPass($a_user_id, $a_password)
Set news feed password for user.
static $is_desktop_item_cache
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
__construct($a_user_id=0, $a_call_by_reference=false)
Constructor public.
setGender($a_str)
set gender public
static signFile($path_to_file)
const AUTH_LOCAL
_getAuthMode($a_auth_mode, $a_db_handler='')
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
writePrefs()
write all userprefs private
static _destroyByUserId($a_user_id)
Destroy session.
sendPersonalDataFile()
Send personal data file.
getUTitle()
get user title (note: don&#39;t mix up this method with getTitle() that is derived from ilObject and gets...
getPersonalPicturePath($a_size="small", $a_force_pic=false)
Get path to personal picture.
const UDF_TYPE_WYSIWYG
static _getAssociatedUsersOnline($a_user_id, $a_no_anonymous=false)
reads all active sessions from db and returns users that are online and who have a local role in a gr...
static deleteEntriesOfUser($a_user_id)
Delete data of user.
_getAllUserData($a_fields=NULL, $active=-1)
STATIC METHOD get all user data.
updateMultiTextFields($a_create=false)
Write multi-text values to DB.
setTimeLimitFrom($a_from)
static _getUsersForFolder($ref_id, $active)
get users for a category or from system folder
setCity($a_str)
set city public
_lookupActive($a_usr_id)
Check user account active.
getPCClipboardContent()
Add a page content item to PC clipboard (should go to another class)
This is the super class of all custom blocks.
setPhoneOffice($a_str)
set office phone public
setLastPasswordChangeTS($a_last_password_change_ts)
getLatitude()
Get Latitude.
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
static getUserSubsetByPreferenceValue($a_user_ids, $a_keyword, $a_val)
For a given set of user IDs return a subset that has a given user preference set. ...
getSelectedCountry()
Get selected country (selection drop down)
_writeExternalAccount($a_usr_id, $a_ext_id)
getComment()
get referral comment public
buildTextFromArray($a_attr)
Convert multi-text values to plain text.
Class ilObjAuthSettingsGUI.
deleteMultiTextFields()
Remove multi-text values from DB.
setClientIP($a_str)
set client ip number public
getPersonalDataExportFile()
Get personal data export file.
static _lookupAuthMode($a_usr_id)
lookup auth mode
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user&#39;s personal desktop
static _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
const IL_CAL_DATE
static _setUserInactive($a_usr_id)
getFullname($a_max_strlen=0)
get fullname public
static _isAnonymous($usr_id)
static _lookupLanguage($a_usr_id)
_deleteAllPref($a_user_id)
Deletes a userpref value of the user from the database public.
setFirstname($a_str)
set firstname public
static skinExists($skin)
Check wheter a skin exists.
getPasswdType()
get password type
static _getUsersForGroup($a_mem_ids, $active=-1)
return user data for group members
removeObjectFromClipboard($a_item_id, $a_type)
remove object from user&#39;s personal clipboard
setGeneralInterests(array $value=null)
Set general interests.
global $ilUser
Definition: imgupload.php:15
bookmark folder (note: this class handles personal bookmarks folders only)
_getAllUserLogins(&$ilias)
STATIC METHOD get all user logins.
_writeAuthMode($a_usr_id, $a_auth_mode)
global $ilSetting
Definition: privfeed.php:40
static resetInactivationDate($usrIds)
type $ilDB
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
static getInstance()
Singelton get instance.
getTimeFormat()
get time format
static _generateRegistrationHash($a_usr_id)
Generates a unique hashcode for activating a user profile after registration.
setLookingForHelp(array $value=null)
Set help looking for.
getPasswd()
get password
static _getPersonalPicturePath($a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
static getFirstLettersOfLastnames()
Get first letters of all lastnames.
setFax($a_str)
set fax public
global $ilDB
getPhoneHome()
get home phone public
static _getUsersForIds($a_mem_ids, $active=-1, $timelimitowner=-1)
return user data for given user id
getHobby()
get hobby public
setPasswordSalt($password_salt)
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static _updateLastLogin($a_usr_id, $a_last_login=null)
STATIC METHOD updates the last_login field of user with given id to given or current date...
getGender()
get gender public
getInstantMessengerId($a_im_type)
const USER_FOLDER_ID
Class ilObjUserFolder.
setLastPasswordChangeToNow()
static findInterests($a_term, $a_user_id=null, $a_field_id=null)
setUTitle($a_str)
set user title (note: don&#39;t mix up this method with setTitle() that is derived from ilObject and sets...
setSkin($a_str)
set user skin (template set) public
setApproveDate($a_str)
set date the user account was activated null indicates that the user has not yet been activated publ...
setPasswordEncodingType($password_encryption_type)
getStoredActive($a_id)
get user active state
getClipboardChilds($a_parent, $a_insert_time)
Get childs of an item.
getApproveDate()
get the date when the user account was approved public
setStreet($a_str)
set street public
static _getUsersForRole($role_id, $active=-1)
return array of complete users which belong to a specific role
_getAllUserAssignedStyles()
skins and styles
update()
update object in db
setPhoneMobile($a_str)
set mobile phone public
Class for user related exception handling in ILIAS.
_getUsersForClipboadObject($a_type, $a_id)
get all users, that have a certain object within their clipboard
static getUsersAgreed($a_agreed=true, $a_users=null)
Get users that have or have not agreed to the user agreement.
getClientIP()
get client ip number public
setLastUpdate($a_str)
set last update of user data set public
static _getPreferences($user_id)
get preferences for user
readMultiTextFields()
Fetch multi-text values from DB.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getWebspaceDir($mode="filesystem")
get webspace directory
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
getLanguage()
returns a 2char-language-string public
static _getInstance()
Get instance of ilSecuritySettings.
static _getUserData($a_internalids)
return user data for given user ids
static deleteUserPortfolios($a_user_id)
Delete all portfolio data for user.
static getInstance()
Single method to reduce footprint (included files, created instances)
hasToAcceptTermsOfServiceInSession($status=null)
static _writeHistory($a_usr_id, $a_login)
setCurrentLanguage($a_val)
Set current language.
hasPublicProfile()
returns true if public is profile, false otherwise
static _doesLoginnameExistInHistory($a_login)
Checks wether the passed loginname already exists in history.
_lookupFeedHash($a_user_id, $a_create=false)
Lookup news feed hash for user.
addToPCClipboard($a_content, $a_time, $a_nr)
Add a page content item to PC clipboard (should go to another class)
updateLogin($a_login)
update login name
importPersonalData($a_file, $a_profile_data, $a_settings, $a_bookmarks, $a_notes, $a_calendar)
Import personal data.
_lookupClientIP($a_user_id)
Lookup client ip.
setLongitude($a_longitude)
Set Longitude.
static _isDesktopItem($a_usr_id, $a_item_id, $a_type)
check wether an item is on the users desktop or not
_getUserIdsByEmail($a_email)
STATIC METHOD get all user_ids of an email address.
__readAppliedUsers($a_parent_id)
_deleteUser($a_usr_id)
readPrefs()
get all user preferences private
getPhoneMobile()
get mobile phone public