ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 require_once './Modules/OrgUnit/classes/class.ilObjOrgUnit.php';
11 require_once './Modules/OrgUnit/classes/class.ilObjOrgUnitTree.php';
12 
25 class ilObjUser extends ilObject
26 {
31  // personal data
32 
33  var $login; // username in system
34 
38  protected $passwd; // password encoded in the format specified by $passwd_type
39 
43  protected $passwd_type;
44  // specifies the password format.
45  // value: IL_PASSWD_PLAIN or IL_PASSWD_CRYPTED.
46 
47  // Differences between password format in class ilObjUser and
48  // in table usr_data:
49  // Class ilObjUser supports two different password types
50  // (plain and crypted) and it uses the variables $passwd
51  // and $passwd_type to store them.
52  // Table usr_data supports only two different password types
53  // (md5 and bcrypt) and it uses the columns "passwd" and "passwd_type" to store them.
54  // The conversion between these two storage layouts is done
55  // in the methods that perform SQL statements. All other
56  // methods work exclusively with the $passwd and $passwd_type
57  // variables.
58 
64 
69  protected $password_salt = null;
70 
71  var $gender; // 'm' or 'f'
72  var $utitle; // user title (keep in mind, that we derive $title from object also!)
74  var $lastname;
75  protected $birthday;
76  var $fullname; // title + firstname + lastname in one string
77  //var $archive_dir = "./image"; // point to image file (should be flexible)
78  // address data
81  var $street;
82  var $city;
83  var $zipcode;
84  var $country;
89  var $fax;
90  var $email;
91  var $hobby;
94  var $approve_date = null;
95  var $agree_date = null;
96  var $active;
97  var $client_ip; // client ip to check before login
98  var $auth_mode; // authentication mode
99 
103 
106 
108 
114  var $prefs;
115 
121  var $skin;
122 
123 
130 
136  var $ilias;
137 
140 
144  protected static $personal_image_cache = array();
145 
151  protected $inactivation_date = null;
152 
157  private $is_self_registered = false;
158 
163  protected $org_units;
164 
165  protected $interests_general; // [array]
166  protected $interests_help_offered; // [array]
167  protected $interests_help_looking; // [array]
168 
174  public function __construct($a_user_id = 0, $a_call_by_reference = false)
175  {
176  global $ilias,$ilDB;
177 
178  // init variables
179  $this->ilias =& $ilias;
180  $this->db =& $ilDB;
181 
182  $this->type = "usr";
183  parent::__construct($a_user_id, $a_call_by_reference);
184  $this->auth_mode = "default";
185  $this->passwd_type = IL_PASSWD_PLAIN;
186 
187  // for gender selection. don't change this
188  /*$this->gender = array(
189  'm' => "salutation_m",
190  'f' => "salutation_f"
191  );*/
192  if ($a_user_id > 0)
193  {
194  $this->setId($a_user_id);
195  $this->read();
196  }
197  else
198  {
199  // TODO: all code in else-structure doesn't belongs in class user !!!
200  //load default data
201  $this->prefs = array();
202  //language
203  $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
204 
205  //skin and pda support
206  $this->skin = $this->ilias->ini->readVariable("layout","skin");
207 
208  $this->prefs["skin"] = $this->skin;
209 // $this->prefs["show_users_online"] = "y";
210 
211  //style (css)
212  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
213  }
214  }
215 
220  function read()
221  {
222  global $ilErr, $ilDB;
223 
224  // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
225  // use (3.11.0 alpha)
226  /*$q = "SELECT * FROM usr_data ".
227  "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
228  "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
229  $r = $ilDB->queryF("SELECT * FROM usr_data ".
230  "WHERE usr_id= %s", array("integer"), array($this->id));
231 
232  if ($data = $ilDB->fetchAssoc($r))
233  {
234  // convert password storage layout used by table usr_data into
235  // storage layout used by class ilObjUser
236  $data["passwd_type"] = IL_PASSWD_CRYPTED;
237 
238  // this assign must not be set via $this->assignData($data)
239  // because this method will be called on profile updates and
240  // would set this values to 0, because they arent posted from form
241  $this->setLastPasswordChangeTS( $data['last_password_change'] );
242  $this->setLoginAttempts( $data['login_attempts'] );
243 
244 
245  // fill member vars in one shot
246  $this->assignData($data);
247 
248  //get userpreferences from usr_pref table
249  $this->readPrefs();
250 
251  //set language to default if not set
252  if ($this->prefs["language"] == "")
253  {
254  $this->prefs["language"] = $this->oldPrefs["language"];
255  }
256 
257  //check skin-setting
258  include_once("./Services/Style/System/classes/class.ilStyleDefinition.php");
259  if ($this->prefs["skin"] == "" ||
260  !ilStyleDefinition::skinExists($this->prefs["skin"]))
261  {
262  $this->prefs["skin"] = $this->oldPrefs["skin"];
263  }
264 
265  $this->skin = $this->prefs["skin"];
266 
267  //check style-setting (skins could have more than one stylesheet
268  if ($this->prefs["style"] == "" ||
269  (!ilStyleDefinition::skinExists($this->skin) && ilStyleDefinition::styleExistsForSkinId($this->skin,$this->prefs["style"])))
270  {
271  //load default (css)
272  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
273  }
274 
275  if (empty($this->prefs["hits_per_page"]))
276  {
277  $this->prefs["hits_per_page"] = 10;
278  }
279  }
280  else
281  {
282  $ilErr->raiseError("<b>Error: There is no dataset with id ".
283  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
284  "<br />Line: ".__LINE__, $ilErr->FATAL);
285  }
286 
287  $this->readMultiTextFields();
288  $this->readUserDefinedFields();
289 
290  parent::read();
291  }
292 
296  public function getPasswordEncodingType()
297  {
299  }
300 
304  public function setPasswordEncodingType($password_encryption_type)
305  {
306  $this->password_encoding_type = $password_encryption_type;
307  }
308 
312  public function getPasswordSalt()
313  {
314  return $this->password_salt;
315  }
316 
321  {
322  $this->password_salt = $password_salt;
323  }
324 
330  function assignData($a_data)
331  {
332  global $ilErr, $ilDB, $lng;
333 
334  // basic personal data
335  $this->setLogin($a_data["login"]);
336  if (! $a_data["passwd_type"])
337  {
338  $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
339  $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
340  .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
341  }
342  if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
343  {
344  $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
345  }
346 
347  $this->setGender($a_data["gender"]);
348  $this->setUTitle($a_data["title"]);
349  $this->setFirstname($a_data["firstname"]);
350  $this->setLastname($a_data["lastname"]);
351  $this->setFullname();
352  if (!is_array($a_data['birthday']))
353  {
354  $this->setBirthday($a_data['birthday']);
355  }
356  else
357  {
358  $this->setBirthday(null);
359  }
360 
361  // address data
362  $this->setInstitution($a_data["institution"]);
363  $this->setDepartment($a_data["department"]);
364  $this->setStreet($a_data["street"]);
365  $this->setCity($a_data["city"]);
366  $this->setZipcode($a_data["zipcode"]);
367  $this->setCountry($a_data["country"]);
368  $this->setSelectedCountry($a_data["sel_country"]);
369  $this->setPhoneOffice($a_data["phone_office"]);
370  $this->setPhoneHome($a_data["phone_home"]);
371  $this->setPhoneMobile($a_data["phone_mobile"]);
372  $this->setFax($a_data["fax"]);
373  $this->setMatriculation($a_data["matriculation"]);
374  $this->setEmail($a_data["email"]);
375  $this->setHobby($a_data["hobby"]);
376  $this->setClientIP($a_data["client_ip"]);
377  $this->setPasswordEncodingType($a_data['passwd_enc_type']);
378  $this->setPasswordSalt($a_data['passwd_salt']);
379 
380  // other data
381  $this->setLatitude($a_data["latitude"]);
382  $this->setLongitude($a_data["longitude"]);
383  $this->setLocationZoom($a_data["loc_zoom"]);
384 
385  // system data
386  $this->setLastLogin($a_data["last_login"]);
387  $this->setLastUpdate($a_data["last_update"]);
388  $this->create_date = $a_data["create_date"];
389  $this->setComment($a_data["referral_comment"]);
390  $this->approve_date = $a_data["approve_date"];
391  $this->active = $a_data["active"];
392  $this->agree_date = $a_data["agree_date"];
393 
394  $this->setInactivationDate($a_data["inactivation_date"]);
395 
396  // time limitation
397  $this->setTimeLimitOwner($a_data["time_limit_owner"]);
398  $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
399  $this->setTimeLimitFrom($a_data["time_limit_from"]);
400  $this->setTimeLimitUntil($a_data["time_limit_until"]);
401  $this->setTimeLimitMessage($a_data['time_limit_message']);
402 
403  // user profile incomplete?
404  $this->setProfileIncomplete($a_data["profile_incomplete"]);
405 
406  //authentication
407  $this->setAuthMode($a_data['auth_mode']);
408  $this->setExternalAccount($a_data['ext_account']);
409 
410  $this->setIsSelfRegistered((bool)$a_data['is_self_registered']);
411  }
412 
419  public function saveAsNew($a_from_formular = true)
420  {
421  global $ilAppEventHandler;
422 
427  global $ilErr, $ilDB;
428 
429  switch ($this->passwd_type)
430  {
431  case IL_PASSWD_PLAIN:
432  if(strlen($this->passwd))
433  {
434  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
435  ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
436  $pw_value = $this->getPasswd();
437  }
438  else
439  {
440  $pw_value = $this->passwd;
441  }
442  break;
443 
444  case IL_PASSWD_CRYPTED:
445  $pw_value = $this->passwd;
446  break;
447 
448  default :
449  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
450  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
451  "<br />Line: ".__LINE__, $ilErr->FATAL);
452  }
453 
454  if( !$this->active )
455  {
456  $this->setInactivationDate( ilUtil::now() );
457  }
458  else
459  {
460  $this->setInactivationDate(null);
461  }
462 
463  $insert_array = array(
464  "usr_id" => array("integer", $this->id),
465  "login" => array("text", $this->login),
466  "passwd" => array("text", $pw_value),
467  'passwd_enc_type' => array("text", $this->getPasswordEncodingType()),
468  'passwd_salt' => array("text", $this->getPasswordSalt()),
469  "firstname" => array("text", $this->firstname),
470  "lastname" => array("text", $this->lastname),
471  "title" => array("text", $this->utitle),
472  "gender" => array("text", $this->gender),
473  "email" => array("text", trim($this->email)),
474  "hobby" => array("text", (string) $this->hobby),
475  "institution" => array("text", $this->institution),
476  "department" => array("text", $this->department),
477  "street" => array("text", $this->street),
478  "city" => array("text", $this->city),
479  "zipcode" => array("text", $this->zipcode),
480  "country" => array("text", $this->country),
481  "sel_country" => array("text", $this->sel_country),
482  "phone_office" => array("text", $this->phone_office),
483  "phone_home" => array("text", $this->phone_home),
484  "phone_mobile" => array("text", $this->phone_mobile),
485  "fax" => array("text", $this->fax),
486  "birthday" => array('date', $this->getBirthday()),
487  "last_login" => array("timestamp", null),
488  "last_update" => array("timestamp", ilUtil::now()),
489  "create_date" => array("timestamp", ilUtil::now()),
490  "referral_comment" => array("text", $this->referral_comment),
491  "matriculation" => array("text", $this->matriculation),
492  "client_ip" => array("text", $this->client_ip),
493  "approve_date" => array("timestamp", $this->approve_date),
494  "agree_date" => array("timestamp", $this->agree_date),
495  "active" => array("integer", (int) $this->active),
496  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
497  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
498  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
499  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
500  "auth_mode" => array("text", $this->getAuthMode()),
501  "ext_account" => array("text", $this->getExternalAccount()),
502  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
503  "latitude" => array("text", $this->latitude),
504  "longitude" => array("text", $this->longitude),
505  "loc_zoom" => array("integer", (int) $this->loc_zoom),
506  "last_password_change" => array("integer", (int) $this->last_password_change_ts),
507  'inactivation_date' => array('timestamp', $this->inactivation_date),
508  'is_self_registered' => array('integer', (int)$this->is_self_registered),
509  );
510  $ilDB->insert("usr_data", $insert_array);
511 
512  $this->updateMultiTextFields(true);
513 
514  // add new entry in usr_defined_data
515  $this->addUserDefinedFieldEntry();
516  // ... and update
517  $this->updateUserDefinedFields();
518 
519  // CREATE ENTRIES FOR MAIL BOX
520  include_once ("Services/Mail/classes/class.ilMailbox.php");
521  $mbox = new ilMailbox($this->id);
522  $mbox->createDefaultFolder();
523 
524  include_once "Services/Mail/classes/class.ilMailOptions.php";
525  $mail_options = new ilMailOptions($this->id);
526  $mail_options->createMailOptionsEntry();
527 
528  // create personal bookmark folder tree
529  include_once "./Services/Bookmarks/classes/class.ilBookmarkFolder.php";
530  $bmf = new ilBookmarkFolder(0, $this->id);
531  $bmf->createNewBookmarkTree();
532 
533  $ilAppEventHandler->raise("Services/User", "afterCreate",
534  array("user_obj" => $this));
535 
536  }
537 
541  public function update()
542  {
548  global $ilErr, $ilDB, $ilAppEventHandler;
549 
550  $this->syncActive();
551 
552  if( $this->getStoredActive($this->id) && !$this->active )
553  {
554  $this->setInactivationDate( ilUtil::now() );
555  }
556  else if($this->active)
557  {
558  $this->setInactivationDate(null);
559  }
560 
561  $update_array = array(
562  "gender" => array("text", $this->gender),
563  "title" => array("text", $this->utitle),
564  "firstname" => array("text", $this->firstname),
565  "lastname" => array("text", $this->lastname),
566  "email" => array("text", trim($this->email)),
567  "birthday" => array('date', $this->getBirthday()),
568  "hobby" => array("text", $this->hobby),
569  "institution" => array("text", $this->institution),
570  "department" => array("text", $this->department),
571  "street" => array("text", $this->street),
572  "city" => array("text", $this->city),
573  "zipcode" => array("text", $this->zipcode),
574  "country" => array("text", $this->country),
575  "sel_country" => array("text", $this->sel_country),
576  "phone_office" => array("text", $this->phone_office),
577  "phone_home" => array("text", $this->phone_home),
578  "phone_mobile" => array("text", $this->phone_mobile),
579  "fax" => array("text", $this->fax),
580  "referral_comment" => array("text", $this->referral_comment),
581  "matriculation" => array("text", $this->matriculation),
582  "client_ip" => array("text", $this->client_ip),
583  "approve_date" => array("timestamp", $this->approve_date),
584  "active" => array("integer", $this->active),
585  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
586  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
587  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
588  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
589  "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
590  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
591  "auth_mode" => array("text", $this->getAuthMode()),
592  "ext_account" => array("text", $this->getExternalAccount()),
593  "latitude" => array("text", $this->latitude),
594  "longitude" => array("text", $this->longitude),
595  "loc_zoom" => array("integer", (int) $this->loc_zoom),
596  "last_password_change" => array("integer", $this->last_password_change_ts),
597  "last_update" => array("timestamp", ilUtil::now()),
598  'inactivation_date' => array('timestamp', $this->inactivation_date)
599  );
600 
601  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null))
602  {
603  $update_array["agree_date"] = array("timestamp", $this->agree_date);
604  }
605  switch ($this->passwd_type)
606  {
607  case IL_PASSWD_PLAIN:
608  if(strlen($this->passwd))
609  {
610  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
611  ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
612  $update_array['passwd'] = array('text', $this->getPasswd());
613  }
614  else
615  {
616  $update_array["passwd"] = array("text", (string) $this->passwd);
617  }
618  break;
619 
620  case IL_PASSWD_CRYPTED:
621  $update_array["passwd"] = array("text", (string) $this->passwd);
622  break;
623 
624  default :
625  $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
626  get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
627  }
628 
629  $update_array['passwd_enc_type'] = array('text', $this->getPasswordEncodingType());
630  $update_array['passwd_salt'] = array('text', $this->getPasswordSalt());
631 
632  $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
633 
634  $this->updateMultiTextFields();
635 
636  $this->writePrefs();
637 
638  // update user defined fields
639  $this->updateUserDefinedFields();
640 
641  parent::update();
642  parent::updateOwner();
643 
644  $this->read();
645 
646  $ilAppEventHandler->raise("Services/User", "afterUpdate",
647  array("user_obj" => $this));
648 
649  return true;
650  }
651 
655  function writeAccepted()
656  {
657  global $ilDB;
658 
659  $ilDB->manipulateF("UPDATE usr_data SET agree_date = ".$ilDB->now().
660  " WHERE usr_id = %s", array("integer"), array($this->getId()));
661  }
662 
666  private static function _lookup($a_user_id, $a_field)
667  {
668  global $ilDB;
669 
670  $res = $ilDB->queryF("SELECT ".$a_field." FROM usr_data WHERE usr_id = %s",
671  array("integer"), array($a_user_id));
672 
673  while($set = $ilDB->fetchAssoc($res))
674  {
675  return $set[$a_field];
676  }
677  return false;
678  }
679 
683  static function _lookupFullname($a_user_id)
684  {
685  global $ilDB;
686 
687  $set = $ilDB->queryF("SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
688  array("integer"), array($a_user_id));
689 
690  if ($rec = $ilDB->fetchAssoc($set))
691  {
692  if ($rec["title"])
693  {
694  $fullname = $rec["title"]." ";
695  }
696  if ($rec["firstname"])
697  {
698  $fullname .= $rec["firstname"]." ";
699  }
700  if ($rec["lastname"])
701  {
702  $fullname .= $rec["lastname"];
703  }
704  }
705  return $fullname;
706  }
707 
711  static function _lookupEmail($a_user_id)
712  {
713  return ilObjUser::_lookup($a_user_id, "email");
714  }
715 
719  public static function _lookupGender($a_user_id)
720  {
721  return ilObjUser::_lookup($a_user_id, "gender");
722  }
723 
730  static function _lookupClientIP($a_user_id)
731  {
732  return ilObjUser::_lookup($a_user_id, "client_ip");
733  }
734 
735 
741  public static function _lookupName($a_user_id)
742  {
743  global $ilDB;
744 
745  $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
746  array("integer"), array($a_user_id));
747  $user_rec = $ilDB->fetchAssoc($res);
748  return array("user_id" => $a_user_id,
749  "firstname" => $user_rec["firstname"],
750  "lastname" => $user_rec["lastname"],
751  "title" => $user_rec["title"],
752  "login" => $user_rec["login"]);
753  }
754 
758  static function _lookupFields($a_user_id)
759  {
760  global $ilDB;
761 
762  $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
763  array("integer"), array($a_user_id));
764  $user_rec = $ilDB->fetchAssoc($res);
765  return $user_rec;
766  }
767 
771  public static function _lookupLogin($a_user_id)
772  {
773  return ilObjUser::_lookup($a_user_id, "login");
774  }
775 
779  static function _lookupExternalAccount($a_user_id)
780  {
781  return ilObjUser::_lookup($a_user_id, "ext_account");
782  }
783 
787  public static function _lookupId($a_user_str)
788  {
789  global $ilDB;
790 
791  if (!is_array($a_user_str))
792  {
793  $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
794  array("text"), array($a_user_str));
795  $user_rec = $ilDB->fetchAssoc($res);
796  return $user_rec["usr_id"];
797  }
798  else
799  {
800  $set = $ilDB->query("SELECT usr_id FROM usr_data ".
801  " WHERE ".$ilDB->in("login", $a_user_str, false, "text")
802  );
803  $ids = array();
804  while ($rec = $ilDB->fetchAssoc($set))
805  {
806  $ids[] = $rec["usr_id"];
807  }
808  return $ids;
809  }
810  }
811 
815  static function _lookupLastLogin($a_user_id)
816  {
817  return ilObjUser::_lookup($a_user_id, "last_login");
818  }
819 
820 
826  function refreshLogin()
827  {
828  global $ilDB;
829 
830  $ilDB->manipulateF("UPDATE usr_data SET ".
831  "last_login = ".$ilDB->now().
832  " WHERE usr_id = %s",
833  array("integer"), array($this->id));
834  }
835 
836 
844  public function resetPassword($raw, $raw_retype)
845  {
849  global $ilDB;
850 
851  if(func_num_args() != 2)
852  {
853  return false;
854  }
855 
856  if(!isset($raw) || !isset($raw_retype))
857  {
858  return false;
859  }
860 
861  if($raw != $raw_retype)
862  {
863  return false;
864  }
865 
866  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
867  ilUserPasswordManager::getInstance()->encodePassword($this, $raw);
868 
869  $ilDB->manipulateF(
870  'UPDATE usr_data
871  SET passwd = %s, passwd_enc_type = %s, passwd_salt = %s
872  WHERE usr_id = %s',
873  array('text', 'text', 'text', 'integer'),
874  array($this->getPasswd(), $this->getPasswordEncodingType(), $this->getPasswordSalt(), $this->getId())
875  );
876 
877  return true;
878  }
879 
890  public static function _doesLoginnameExistInHistory($a_login)
891  {
892  global $ilDB;
893 
894  $res = $ilDB->queryF('
895  SELECT * FROM loginname_history
896  WHERE login = %s',
897  array('text'), array($a_login));
898 
899  return $ilDB->fetchAssoc($res) ? true : false;
900  }
901 
914  public static function _getLastHistoryDataByUserId($a_usr_id)
915  {
916  global $ilDB;
917 
918  $ilDB->setLimit(1, 0);
919  $res = $ilDB->queryF('
920  SELECT login, history_date FROM loginname_history
921  WHERE usr_id = %s ORDER BY history_date DESC',
922  array('integer'), array($a_usr_id));
923  $row = $ilDB->fetchAssoc($res);
924  if(!is_array($row) || !count($row)) throw new ilUserException('');
925 
926  return array(
927  $row['login'], $row['history_date']
928  );
929  }
930 
938  function updateLogin($a_login)
939  {
940  global $ilDB, $ilSetting;
941 
942  if(func_num_args() != 1)
943  {
944  return false;
945  }
946 
947  if(!isset($a_login))
948  {
949  return false;
950  }
951 
952  $former_login = self::_lookupLogin($this->getId());
953 
954  // Update not necessary
955  if(0 == strcmp($a_login, $former_login))
956  {
957  return false;
958  }
959 
960  try
961  {
962  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
963  }
964  catch(ilUserException $e) { $last_history_entry = null; }
965 
966  // throw exception if the desired loginame is already in history and it is not allowed to reuse it
967  if((int)$ilSetting->get('allow_change_loginname') &&
968  (int)$ilSetting->get('reuse_of_loginnames') == 0 &&
969  self::_doesLoginnameExistInHistory($a_login))
970  {
971  throw new ilUserException($this->lng->txt('loginname_already_exists'));
972  }
973  else if((int)$ilSetting->get('allow_change_loginname') &&
974  (int)$ilSetting->get('loginname_change_blocking_time') &&
975  is_array($last_history_entry) &&
976  $last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time') > time())
977  {
978  include_once 'Services/Calendar/classes/class.ilDate.php';
979  throw new ilUserException(
980  sprintf(
981  $this->lng->txt('changing_loginname_not_possible_info'),
983  new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
985  new ilDateTime(($last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX))
986  )
987  );
988  }
989  else
990  {
991  // log old loginname in history
992  if((int)$ilSetting->get('allow_change_loginname') &&
993  (int)$ilSetting->get('create_history_loginname'))
994  {
995  ilObjUser::_writeHistory($this->getId(), $former_login);
996  }
997 
998  //update login
999  $this->login = $a_login;
1000 
1001  $ilDB->manipulateF('
1002  UPDATE usr_data
1003  SET login = %s
1004  WHERE usr_id = %s',
1005  array('text', 'integer'), array($this->getLogin(), $this->getId()));
1006  }
1007 
1008  return true;
1009  }
1010 
1017  function writePref($a_keyword, $a_value)
1018  {
1019  self::_writePref($this->id, $a_keyword, $a_value);
1020  $this->setPref($a_keyword, $a_value);
1021  }
1022 
1023 
1029  function deletePref($a_keyword)
1030  {
1031  self::_deletePref($this->getId(), $a_keyword);
1032  }
1033 
1039  public static function _deletePref($a_user_id, $a_keyword)
1040  {
1044  global $ilDB;
1045 
1046  $ilDB->manipulateF(
1047  'DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s',
1048  array('integer', 'text'),
1049  array($a_user_id, $a_keyword)
1050  );
1051  }
1052 
1058  static function _deleteAllPref($a_user_id)
1059  {
1060  global $ilDB;
1061 
1062  $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1063  array("integer"), array($a_user_id));
1064  }
1065 
1072  public static function _writePref($a_usr_id, $a_keyword, $a_value)
1073  {
1074  global $ilDB;
1075  $ilDB->replace("usr_pref",
1076  array(
1077  "usr_id" => array("integer", $a_usr_id),
1078  "keyword" => array("text", $a_keyword),
1079  ),
1080  array(
1081  "value" => array("text",$a_value)
1082  )
1083  );
1084 
1085  /*
1086  self::_deletePref($a_usr_id, $a_keyword);
1087  if(strlen($a_value))
1088  {
1089  $ilDB->manipulateF(
1090  'INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s, %s, %s)',
1091  array('integer', 'text', 'text'),
1092  array($a_usr_id, $a_keyword, $a_value)
1093  );
1094  }*/
1095  }
1096 
1101  function writePrefs()
1102  {
1103  global $ilDB;
1104 
1105  ilObjUser::_deleteAllPref($this->id);
1106  foreach ($this->prefs as $keyword => $value)
1107  {
1108  self::_writePref($this->id, $keyword, $value);
1109  }
1110  }
1111 
1118  public function getTimeZone()
1119  {
1120  if($tz = $this->getPref('user_tz'))
1121  {
1122  return $tz;
1123  }
1124  else
1125  {
1126  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1127  $settings = ilCalendarSettings::_getInstance();
1128  return $settings->getDefaultTimeZone();
1129  }
1130  }
1131 
1138  public function getTimeFormat()
1139  {
1140  if($format = $this->getPref('time_format'))
1141  {
1142  return $format;
1143  }
1144  else
1145  {
1146  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1147  $settings = ilCalendarSettings::_getInstance();
1148  return $settings->getDefaultTimeFormat();
1149  }
1150  }
1151 
1158  public function getDateFormat()
1159  {
1160  if($format = $this->getPref('date_format'))
1161  {
1162  return $format;
1163  }
1164  else
1165  {
1166  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1167  $settings = ilCalendarSettings::_getInstance();
1168  return $settings->getDefaultDateFormat();
1169  }
1170  }
1171 
1178  function setPref($a_keyword, $a_value)
1179  {
1180  if ($a_keyword != "")
1181  {
1182  $this->prefs[$a_keyword] = $a_value;
1183  }
1184  }
1185 
1191  function getPref($a_keyword)
1192  {
1193  if (array_key_exists($a_keyword, $this->prefs))
1194  {
1195  return $this->prefs[$a_keyword];
1196  }
1197  else
1198  {
1199  return FALSE;
1200  }
1201  }
1202 
1203  static function _lookupPref($a_usr_id,$a_keyword)
1204  {
1205  global $ilDB;
1206 
1207  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1208  "AND keyword = ".$ilDB->quote($a_keyword, "text");
1209  $res = $ilDB->query($query);
1210 
1211  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
1212  {
1213  return $row->value;
1214  }
1215  return false;
1216  }
1217 
1222  function readPrefs()
1223  {
1224  global $ilDB;
1225 
1226  if (is_array($this->prefs))
1227  {
1228  $this->oldPrefs = $this->prefs;
1229  }
1230 
1231  $this->prefs = ilObjUser::_getPreferences($this->id);
1232  }
1233 
1239  function delete()
1240  {
1241  global $rbacadmin, $ilDB;
1242 
1243  // deassign from ldap groups
1244  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1246  $mapping->deleteUser($this->getId());
1247 
1248  // remove mailbox / update sent mails
1249  include_once ("Services/Mail/classes/class.ilMailbox.php");
1250  $mailbox = new ilMailbox($this->getId());
1251  $mailbox->delete();
1252  $mailbox->updateMailsOfDeletedUser($this->getLogin());
1253 
1254  // delete feed blocks on personal desktop
1255  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1256  $costum_block = new ilCustomBlock();
1257  $costum_block->setContextObjId($this->getId());
1258  $costum_block->setContextObjType("user");
1259  $c_blocks = $costum_block->queryBlocksForContext();
1260  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1261  foreach($c_blocks as $c_block)
1262  {
1263  if ($c_block["type"] == "pdfeed")
1264  {
1265  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1266  $fb->delete();
1267  }
1268  }
1269 
1270 
1271  // delete block settings
1272  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1274 
1275  // delete user_account
1276  $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1277  array("integer"), array($this->getId()));
1278 
1279  $this->deleteMultiTextFields();
1280 
1281  // delete user_prefs
1282  ilObjUser::_deleteAllPref($this->getId());
1283 
1284  $this->removeUserPicture(false); // #8597
1285 
1286  // delete user_session
1287  include_once("./Services/Authentication/classes/class.ilSession.php");
1289 
1290  // remove user from rbac
1291  $rbacadmin->removeUser($this->getId());
1292 
1293  // remove bookmarks
1294  // TODO: move this to class.ilBookmarkFolder
1295  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1296  $ilDB->quote($this->getId(), "integer");
1297  $ilDB->manipulate($q);
1298 
1299  $q = "DELETE FROM bookmark_data WHERE user_id = ".
1300  $ilDB->quote($this->getId(), "integer");
1301  $ilDB->manipulate($q);
1302 
1303  // DELETE FORUM ENTRIES (not complete in the moment)
1304  include_once './Modules/Forum/classes/class.ilObjForum.php';
1305  ilObjForum::_deleteUser($this->getId());
1306 
1307  // Delete link check notify entries
1308  include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
1310 
1311  // Delete crs entries
1312  include_once './Modules/Course/classes/class.ilObjCourse.php';
1313  ilObjCourse::_deleteUser($this->getId());
1314 
1315  // Delete user tracking
1316  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1318 
1319  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1321 
1322  // Delete Tracking data SCORM 2004 RTE
1323  include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1325 
1326  // Delete Tracking data SCORM 1.2 RTE
1327  include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1329 
1330  // remove all notifications
1331  include_once "./Services/Notification/classes/class.ilNotification.php";
1333 
1334  // remove portfolios
1335  include_once "./Modules/Portfolio/classes/class.ilObjPortfolio.php";
1337 
1338  // remove workspace
1339  include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1340  $tree = new ilWorkspaceTree($this->getId());
1341  $tree->cascadingDelete();
1342 
1343  // remove disk quota entries
1344  include_once "./Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1346 
1347  // remove reminder entries
1348  require_once 'Services/User/classes/class.ilCronDeleteInactiveUserReminderMail.php';
1350 
1351  // badges
1352  include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
1354 
1355  // Delete user defined field entries
1357 
1358  // Delete clipboard entries
1359  $this->clipboardDeleteAll();
1360 
1361  // Reset owner
1362  $this->resetOwner();
1363 
1364  // Trigger deleteUser Event
1365  global $ilAppEventHandler;
1366  $ilAppEventHandler->raise(
1367  'Services/User', 'deleteUser', array('usr_id' => $this->getId())
1368  );
1369 
1370  // delete object data
1371  parent::delete();
1372  return true;
1373  }
1374 
1384  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1385  {
1386  $this->fullname = "";
1387 
1388  if ($a_title)
1389  {
1390  $fullname = $a_title." ";
1391  }
1392  elseif ($this->utitle)
1393  {
1394  $this->fullname = $this->utitle." ";
1395  }
1396 
1397  if ($a_firstname)
1398  {
1399  $fullname .= $a_firstname." ";
1400  }
1401  elseif ($this->firstname)
1402  {
1403  $this->fullname .= $this->firstname." ";
1404  }
1405 
1406  if ($a_lastname)
1407  {
1408  return $fullname.$a_lastname;
1409  }
1410 
1411  $this->fullname .= $this->lastname;
1412  }
1413 
1428  function getFullname($a_max_strlen = 0)
1429  {
1430  if (!$a_max_strlen)
1431  {
1432  return ilUtil::stripSlashes($this->fullname);
1433  }
1434 
1435  if (strlen($this->fullname) <= $a_max_strlen)
1436  {
1437  return ilUtil::stripSlashes($this->fullname);
1438  }
1439 
1440  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1441  {
1442  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1443  }
1444 
1445  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1446  {
1447  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1448  }
1449 
1450  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1451  {
1452  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1453  }
1454 
1455  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1456  }
1457 
1463  function setLogin($a_str)
1464  {
1465  $this->login = $a_str;
1466  }
1467 
1472  function getLogin()
1473  {
1474  return $this->login;
1475  }
1476 
1482  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1483  {
1484  $this->passwd = $a_str;
1485  $this->passwd_type = $a_type;
1486  }
1487 
1495  function getPasswd()
1496  {
1497  return $this->passwd;
1498  }
1505  function getPasswdType()
1506  {
1507  return $this->passwd_type;
1508  }
1509 
1515  function setGender($a_str)
1516  {
1517  $this->gender = substr($a_str,-1);
1518  }
1519 
1524  function getGender()
1525  {
1526  return $this->gender;
1527  }
1528 
1536  function setUTitle($a_str)
1537  {
1538  $this->utitle = $a_str;
1539  }
1540 
1547  function getUTitle()
1548  {
1549  return $this->utitle;
1550  }
1551 
1557  function setFirstname($a_str)
1558  {
1559  $this->firstname = $a_str;
1560  }
1561 
1566  function getFirstname()
1567  {
1568  return $this->firstname;
1569  }
1570 
1576  function setLastname($a_str)
1577  {
1578  $this->lastname = $a_str;
1579  }
1580 
1585  function getLastname()
1586  {
1587  return $this->lastname;
1588  }
1589 
1595  function setInstitution($a_str)
1596  {
1597  $this->institution = $a_str;
1598  }
1599 
1604  function getInstitution()
1605  {
1606  return $this->institution;
1607  }
1608 
1614  function setDepartment($a_str)
1615  {
1616  $this->department = $a_str;
1617  }
1618 
1623  function getDepartment()
1624  {
1625  return $this->department;
1626  }
1627 
1633  function setStreet($a_str)
1634  {
1635  $this->street = $a_str;
1636  }
1637 
1642  function getStreet()
1643  {
1644  return $this->street;
1645  }
1646 
1652  function setCity($a_str)
1653  {
1654  $this->city = $a_str;
1655  }
1656 
1661  function getCity()
1662  {
1663  return $this->city;
1664  }
1665 
1671  function setZipcode($a_str)
1672  {
1673  $this->zipcode = $a_str;
1674  }
1675 
1680  function getZipcode()
1681  {
1682  return $this->zipcode;
1683  }
1684 
1691  function setCountry($a_str)
1692  {
1693  $this->country = $a_str;
1694  }
1695 
1701  function getCountry()
1702  {
1703  return $this->country;
1704  }
1705 
1711  function setSelectedCountry($a_val)
1712  {
1713  $this->sel_country = $a_val;
1714  }
1715 
1722  {
1723  return $this->sel_country;
1724  }
1725 
1731  function setPhoneOffice($a_str)
1732  {
1733  $this->phone_office = $a_str;
1734  }
1735 
1740  function getPhoneOffice()
1741  {
1742  return $this->phone_office;
1743  }
1744 
1750  function setPhoneHome($a_str)
1751  {
1752  $this->phone_home = $a_str;
1753  }
1754 
1759  function getPhoneHome()
1760  {
1761  return $this->phone_home;
1762  }
1763 
1769  function setPhoneMobile($a_str)
1770  {
1771  $this->phone_mobile = $a_str;
1772  }
1773 
1778  function getPhoneMobile()
1779  {
1780  return $this->phone_mobile;
1781  }
1782 
1788  function setFax($a_str)
1789  {
1790  $this->fax = $a_str;
1791  }
1792 
1797  function getFax()
1798  {
1799  return $this->fax;
1800  }
1801 
1807  function setClientIP($a_str)
1808  {
1809  $this->client_ip = $a_str;
1810  }
1811 
1816  function getClientIP()
1817  {
1818  return $this->client_ip;
1819  }
1820 
1826  function setMatriculation($a_str)
1827  {
1828  $this->matriculation = $a_str;
1829  }
1830 
1835  function getMatriculation()
1836  {
1837  return $this->matriculation;
1838  }
1839 
1846  public static function lookupMatriculation($a_usr_id)
1847  {
1848  global $ilDB;
1849 
1850  $query = "SELECT matriculation FROM usr_data ".
1851  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1852  $res = $ilDB->query($query);
1854  return $row->matriculation ? $row->matriculation : '';
1855  }
1856 
1862  function setEmail($a_str)
1863  {
1864  $this->email = $a_str;
1865  }
1866 
1871  function getEmail()
1872  {
1873  return $this->email;
1874  }
1875 
1881  function setHobby($a_str)
1882  {
1883  $this->hobby = $a_str;
1884  }
1885 
1890  function getHobby()
1891  {
1892  return $this->hobby;
1893  }
1894 
1900  function setLanguage($a_str)
1901  {
1902  $this->setPref("language",$a_str);
1903  unset($_SESSION['lang']);
1904  }
1905 
1911  function getLanguage()
1912  {
1913  return $this->prefs["language"];
1914  }
1915 
1924  function setDiskQuota($a_disk_quota)
1925  {
1926  $this->setPref("disk_quota",$a_disk_quota);
1927  }
1928 
1938  function getDiskQuota()
1939  {
1940  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
1941  }
1942 
1944  {
1945  return $this->prefs["wsp_disk_quota"] ? $this->prefs["wsp_disk_quota"] : 0;
1946  }
1947 
1948  public function setLastPasswordChangeTS($a_last_password_change_ts)
1949  {
1950  $this->last_password_change_ts = $a_last_password_change_ts;
1951  }
1952 
1953  public function getLastPasswordChangeTS()
1954  {
1956  }
1957 
1958 
1959  public static function _lookupLanguage($a_usr_id)
1960  {
1961  global $ilDB;
1962 
1963  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
1964  $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
1965  $ilDB->quote('language', "text");
1966  $r = $ilDB->query($q);
1967 
1968  while($row = $ilDB->fetchAssoc($r))
1969  {
1970  return $row['value'];
1971  }
1972  return 'en';
1973  }
1974 
1975  static function _writeExternalAccount($a_usr_id, $a_ext_id)
1976  {
1977  global $ilDB;
1978 
1979  $ilDB->manipulateF("UPDATE usr_data ".
1980  " SET ext_account = %s WHERE usr_id = %s",
1981  array("text", "integer"),
1982  array($a_ext_id, $a_usr_id));
1983  }
1984 
1985  static function _writeAuthMode($a_usr_id, $a_auth_mode)
1986  {
1987  global $ilDB;
1988 
1989  $ilDB->manipulateF("UPDATE usr_data ".
1990  " SET auth_mode = %s WHERE usr_id = %s",
1991  array("text", "integer"),
1992  array($a_auth_mode, $a_usr_id));
1993  }
1994 
2000  {
2001  return $_SESSION['lang'];
2002  }
2003 
2009  function setCurrentLanguage($a_val)
2010  {
2011  $_SESSION['lang'] = $a_val;
2012  }
2013 
2019  function setLastLogin($a_str)
2020  {
2021  $this->last_login = $a_str;
2022  }
2023 
2029  function getLastLogin()
2030  {
2031  return $this->last_login;
2032  }
2033 
2039  function setLastUpdate($a_str)
2040  {
2041  $this->last_update = $a_str;
2042  }
2043  function getLastUpdate()
2044  {
2045  return $this->last_update;
2046  }
2047 
2053  function setComment($a_str)
2054  {
2055  $this->referral_comment = $a_str;
2056  }
2057 
2062  function getComment()
2063  {
2064  return $this->referral_comment;
2065  }
2066 
2073  function setApproveDate($a_str)
2074  {
2075  $this->approve_date = $a_str;
2076  }
2077 
2083  function getApproveDate()
2084  {
2085  return $this->approve_date;
2086  }
2087 
2088  // BEGIN DiskQuota: show when user accepted user agreement
2094  function getAgreeDate()
2095  {
2096  return $this->agree_date;
2097  }
2104  function setAgreeDate($a_str)
2105  {
2106  $this->agree_date = $a_str;
2107  }
2108  // END DiskQuota: show when user accepted user agreement
2109 
2116  function setActive($a_active, $a_owner = 0)
2117  {
2118  $this->setOwner($a_owner);
2119 
2120  if ($a_active)
2121  {
2122  $this->active = 1;
2123  $this->setApproveDate(date('Y-m-d H:i:s'));
2124  $this->setOwner($a_owner);
2125  }
2126  else
2127  {
2128  $this->active = 0;
2129  $this->setApproveDate(null);
2130  }
2131  }
2132 
2137  function getActive()
2138  {
2139  return $this->active;
2140  }
2141 
2145  static public function _lookupActive($a_usr_id)
2146  {
2147  global $ilDB;
2148 
2149  $query = 'SELECT usr_id FROM usr_data '.
2150  'WHERE active = '.$ilDB->quote(1,'integer').' '.
2151  'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
2152  $res = $ilDB->query($query);
2153  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
2154  {
2155  return true;
2156  }
2157  return false;
2158  }
2159 
2165  function syncActive()
2166  {
2167  global $ilAuth;
2168 
2169  $storedActive = 0;
2170  if ($this->getStoredActive($this->id))
2171  {
2172  $storedActive = 1;
2173  }
2174 
2175  $currentActive = 0;
2176  if ($this->active)
2177  {
2178  $currentActive = 1;
2179  }
2180 
2181  if ((!empty($storedActive) && empty($currentActive)) ||
2182  (empty($storedActive) && !empty($currentActive)))
2183  {
2184  $this->setActive($currentActive, self::getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2185  }
2186  }
2187 
2194  function getStoredActive($a_id)
2195  {
2196  $active = ilObjUser::_lookup($a_id, "active");
2197  return $active ? true : false;
2198  }
2199 
2205  function setSkin($a_str)
2206  {
2207  // TODO: exception handling (dir exists)
2208  $this->skin = $a_str;
2209  }
2210 
2211  function setTimeLimitOwner($a_owner)
2212  {
2213  $this->time_limit_owner = $a_owner;
2214  }
2216  {
2217  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2218  }
2219  function setTimeLimitFrom($a_from)
2220  {
2221  $this->time_limit_from = $a_from;
2222  }
2223  function getTimeLimitFrom()
2224  {
2225  return $this->time_limit_from;
2226  }
2227  function setTimeLimitUntil($a_until)
2228  {
2229  $this->time_limit_until = $a_until;
2230  }
2232  {
2233  return $this->time_limit_until;
2234  }
2235  function setTimeLimitUnlimited($a_unlimited)
2236  {
2237  $this->time_limit_unlimited = $a_unlimited;
2238  }
2240  {
2241  return $this->time_limit_unlimited;
2242  }
2243  function setTimeLimitMessage($a_time_limit_message)
2244  {
2245  return $this->time_limit_message = $a_time_limit_message;
2246  }
2248  {
2249  return $this->time_limit_message;
2250  }
2251 
2252  public function setLoginAttempts($a_login_attempts)
2253  {
2254  $this->login_attempts = $a_login_attempts;
2255  }
2256 
2257  public function getLoginAttempts()
2258  {
2259  return $this->login_attempts;
2260  }
2261 
2262 
2263  function checkTimeLimit()
2264  {
2265  if($this->getTimeLimitUnlimited())
2266  {
2267  return true;
2268  }
2269  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2270  {
2271  return true;
2272  }
2273  return false;
2274  }
2275  function setProfileIncomplete($a_prof_inc)
2276  {
2277  $this->profile_incomplete = (boolean) $a_prof_inc;
2278  }
2280  {
2281  if($this->id == ANONYMOUS_USER_ID)
2282  {
2283  return false;
2284  }
2285  return $this->profile_incomplete;
2286  }
2287 
2291  public function isPasswordChangeDemanded()
2292  {
2293  if ($this->id == ANONYMOUS_USER_ID) {
2294  return false;
2295  }
2296 
2297  if ($this->id == SYSTEM_USER_ID) {
2298  require_once './Services/User/classes/class.ilUserPasswordManager.php';
2299  if (
2300  \ilUserPasswordManager::getInstance()->verifyPassword($this, base64_decode('aG9tZXI=')) &&
2302  ) {
2303  return true;
2304  } else {
2305  return false;
2306  }
2307  }
2308 
2309  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2310  $security = ilSecuritySettings::_getInstance();
2311 
2312  if (
2314  $security->isPasswordChangeOnFirstLoginEnabled() &&
2315  $this->getLastPasswordChangeTS() == 0 &&
2316  $this->is_self_registered == false
2317  ) {
2318  return true;
2319  }
2320 
2321  return false;
2322  }
2323 
2324  public function isPasswordExpired()
2325  {
2326  if ($this->id == ANONYMOUS_USER_ID) {
2327  return false;
2328  }
2329 
2330  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2331  $security = ilSecuritySettings::_getInstance();
2332  if ($this->getLastPasswordChangeTS() > 0) {
2333  $max_pass_age = $security->getPasswordMaxAge();
2334  if ($max_pass_age > 0) {
2335  $max_pass_age_ts = ($max_pass_age * 86400);
2336  $pass_change_ts = $this->getLastPasswordChangeTS();
2337  $current_ts = time();
2338 
2339  if (($current_ts - $pass_change_ts) > $max_pass_age_ts) {
2341  return true;
2342  }
2343  }
2344  }
2345  }
2346 
2347  return false;
2348  }
2349 
2350  public function getPasswordAge()
2351  {
2352  $current_ts = time();
2353  $pass_change_ts = $this->getLastPasswordChangeTS();
2354  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2355  return $password_age;
2356  }
2357 
2358  public function setLastPasswordChangeToNow()
2359  {
2360  global $ilDB;
2361 
2362  $this->setLastPasswordChangeTS( time() );
2363 
2364  $query = "UPDATE usr_data SET last_password_change = %s " .
2365  "WHERE usr_id = %s";
2366  $affected = $ilDB->manipulateF($query,
2367  array('integer','integer'),
2368  array($this->getLastPasswordChangeTS(),$this->id));
2369  if($affected) return true;
2370  else return false;
2371  }
2372 
2373  public function resetLastPasswordChange()
2374  {
2375  global $ilDB;
2376 
2377  $query = "UPDATE usr_data SET last_password_change = 0 " .
2378  "WHERE usr_id = %s";
2379  $affected = $ilDB->manipulateF( $query, array('integer'),
2380  array($this->getId()) );
2381  if($affected) return true;
2382  else return false;
2383  }
2384 
2390  function setLatitude($a_latitude)
2391  {
2392  $this->latitude = $a_latitude;
2393  }
2394 
2400  function getLatitude()
2401  {
2402  return $this->latitude;
2403  }
2404 
2410  function setLongitude($a_longitude)
2411  {
2412  $this->longitude = $a_longitude;
2413  }
2414 
2420  function getLongitude()
2421  {
2422  return $this->longitude;
2423  }
2424 
2430  function setLocationZoom($a_locationzoom)
2431  {
2432  $this->loc_zoom = $a_locationzoom;
2433  }
2434 
2440  function getLocationZoom()
2441  {
2442  return $this->loc_zoom;
2443  }
2444 
2445 
2451  static function hasActiveSession($a_user_id, $a_session_id)
2452  {
2453  global $ilDB;
2454 
2455  $set = $ilDB->queryf('
2456  SELECT COUNT(*) session_count
2457  FROM usr_session WHERE user_id = %s AND expires > %s AND session_id != %s ',
2458  array('integer', 'integer', 'text'),
2459  array($a_user_id, time(), $a_session_id));
2460  $row = $ilDB->fetchAssoc($set);
2461  return (bool)$row['session_count'];
2462  }
2463 
2464  /*
2465  * check user id with login name
2466  * @access public
2467  */
2468  function checkUserId()
2469  {
2470  global $ilAuth, $ilSetting;
2471 
2472  $login = ilObjUser::getLoginFromAuth();
2473  $id = ilObjUser::_lookupId($login);
2474  if ($id > 0)
2475  {
2476  return $id;
2477  }
2478  return false;
2479  }
2480 
2484  private static function getLoginFromAuth()
2485  {
2486  global $ilAuth;
2487 
2488  $uid = $GLOBALS['DIC']['ilAuthSession']->getUserId();
2489  $login = ilObjUser::_lookupLogin($uid);
2490 
2491  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2492  require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2494  {
2495  $login = self::toUsernameWithoutDomain($login);
2496  }
2497  return $login;
2498  }
2499 
2506  public static function toUsernameWithoutDomain($a_login)
2507  {
2508  // Remove all characters including the last slash or the last backslash
2509  // in the username
2510  $pos = strrpos($a_login, '/');
2511  $pos2 = strrpos($a_login, '\\');
2512  if ($pos === false || $pos < $pos2)
2513  {
2514  $pos = $pos2;
2515  }
2516  if ($pos !== false)
2517  {
2518  $a_login = substr($a_login, $pos + 1);
2519  }
2520  return $a_login;
2521  }
2522 
2523  /*
2524  * check to see if current user has been made active
2525  * @access public
2526  * @return true if active, otherwise false
2527  */
2529  {
2530  global $ilDB,$ilAuth;
2531 
2532  $login = ilObjUser::getLoginFromAuth();
2533  $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2534  array("text"),
2535  array($login));
2536  //query has got a result
2537  if ($rec = $ilDB->fetchAssoc($set))
2538  {
2539  if ($rec["active"])
2540  {
2541  return true;
2542  }
2543  }
2544 
2545  return false;
2546  }
2547 
2548  /*
2549  * STATIC METHOD
2550  * get the user_id of a login name
2551  * @param string login name
2552  * @return integer id of user
2553  * @static
2554  * @access public
2555  */
2556  public static function getUserIdByLogin($a_login)
2557  {
2558  return (int) ilObjUser::_lookupId($a_login);
2559  }
2560 
2569  static function _getUserIdsByEmail($a_email)
2570  {
2571  global $ilias, $ilDB;
2572 
2573  $res = $ilDB->queryF("SELECT login FROM usr_data ".
2574  "WHERE email = %s and active = 1",
2575  array("text"),
2576  array($a_email));
2577  $ids = array ();
2578  while($row = $ilDB->fetchObject($res))
2579  {
2580  $ids[] = $row->login;
2581  }
2582 
2583  return $ids;
2584  }
2585 
2586 
2587 
2596  function getUserIdByEmail($a_email)
2597  {
2598  global $ilDB;
2599 
2600  $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2601  "WHERE email = %s", array("text"), array($a_email));
2602 
2603  $row = $ilDB->fetchObject($res);
2604  return $row->usr_id ? $row->usr_id : 0;
2605  }
2606 
2607  /*
2608  * STATIC METHOD
2609  * get the login name of a user_id
2610  * @param integer id of user
2611  * @return string login name; false if not found
2612  * @static
2613  * @access public
2614  */
2615  function getLoginByUserId($a_userid)
2616  {
2617  $login = ilObjUser::_lookupLogin($a_userid);
2618  return $login ? $login : false;
2619  }
2620 
2631  static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2632  {
2633  global $ilias, $ilDB, $ilLog;
2634 
2635 
2636  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2637 
2638  $without_anonymous_users = true;
2639 
2640  // determine join filter
2641  $join_filter = " WHERE ";
2642  if ($filter_settings !== FALSE && strlen($filter_settings))
2643  {
2644  switch ($filter_settings)
2645  {
2646  case 3:
2647  // show only users without courses
2648  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.usr_id IS NULL AND ";
2649  break;
2650  case 5:
2651  // show only users with a certain course membership
2652  $ref_id = $_SESSION["user_filter_data"];
2653  if ($ref_id)
2654  {
2655  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.obj_id = ".
2656  "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2657  }
2658  break;
2659  case 6:
2660  global $rbacreview;
2661  $ref_id = $_SESSION["user_filter_data"];
2662  if ($ref_id)
2663  {
2664  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
2665  if (is_array($local_roles) && count($local_roles))
2666  {
2667  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2668  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2669  }
2670  }
2671  break;
2672  case 7:
2673  global $rbacreview;
2674  $rol_id = $_SESSION["user_filter_data"];
2675  if ($rol_id)
2676  {
2677  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2678  $ilDB->quote($rol_id, "integer")." AND ";
2679  $without_anonymous_users = false;
2680  }
2681  break;
2682  }
2683  }
2684  // This is a temporary hack to search users by their role
2685  // See Mantis #338. This is a hack due to Mantis #337.
2686  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2687  {
2688  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2689  "FROM object_data,rbac_ua,usr_data ".
2690  "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2691  " AND object_data.type = 'role' ".
2692  "AND rbac_ua.rol_id = object_data.obj_id ".
2693  "AND usr_data.usr_id = rbac_ua.usr_id ".
2694  "AND rbac_ua.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2695  }
2696  else
2697  {
2698  $query.= $join_filter.
2699  "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2700  "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2701  "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2702  "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2703 
2704  if ($filter_settings !== FALSE && strlen($filter_settings))
2705  {
2706  switch ($filter_settings)
2707  {
2708  case 0:
2709  $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2710  break;
2711  case 1:
2712  $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2713  break;
2714  case 2:
2715  $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2716  break;
2717  case 4:
2718  $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"]));
2719  $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2720  break;
2721  }
2722  }
2723 
2724  if ($without_anonymous_users)
2725  {
2726  $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2727  }
2728 
2729  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2730  {
2731  $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2732  }
2733 
2734  }
2735  $ilLog->write($query);
2736  $res = $ilDB->query($query);
2737  while ($row = $ilDB->fetchObject($res))
2738  {
2739  $users[] = array(
2740  "usr_id" => $row->usr_id,
2741  "login" => $row->login,
2742  "firstname" => $row->firstname,
2743  "lastname" => $row->lastname,
2744  "email" => $row->email,
2745  "active" => $row->active);
2746  $ids[] = $row->usr_id;
2747  }
2748  if ($a_return_ids_only)
2749  return $ids ? $ids : array();
2750  else
2751  return $users ? $users : array();
2752  }
2753 
2757  public static function getAllUserLogins()
2758  {
2762  global $ilDB;
2763 
2764  $logins = array();
2765 
2766  $res = $ilDB->query(
2767  "SELECT login FROM usr_data WHERE " . $ilDB->in('usr_id', array(ANONYMOUS_USER_ID), true, 'integer')
2768  );
2769  while($row = $ilDB->fetchAssoc($res))
2770  {
2771  $logins[] = $row['login'];
2772  }
2773 
2774  return $logins;
2775  }
2776 
2785  public static function _readUsersProfileData($a_user_ids)
2786  {
2787  global $ilDB;
2788  $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2789  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2790  while ($row = $ilDB->fetchAssoc($res))
2791  {
2792  $user_data["$row[usr_id]"] = $row;
2793  }
2794  return $user_data ? $user_data : array();
2795  }
2796 
2805  static function _getAllUserData($a_fields = NULL, $active =-1)
2806  {
2807  global $ilDB;
2808 
2809  $result_arr = array();
2810  $types = array();
2811  $values = array();
2812 
2813  if ($a_fields !== NULL and is_array($a_fields))
2814  {
2815  if (count($a_fields) == 0)
2816  {
2817  $select = "*";
2818  }
2819  else
2820  {
2821  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2822  unset($a_fields[$usr_id_field]);
2823 
2824  $select = implode(",",$a_fields).",usr_data.usr_id";
2825  // online time
2826  if(in_array('online_time',$a_fields))
2827  {
2828  $select .= ",ut_online.online_time ";
2829  }
2830  }
2831 
2832  $q = "SELECT ".$select." FROM usr_data ";
2833 
2834  // Add online_time if desired
2835  // Need left join here to show users that never logged in
2836  if(in_array('online_time',$a_fields))
2837  {
2838  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2839  }
2840 
2841  switch ($active)
2842  {
2843  case 0:
2844  case 1:
2845  $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2846  break;
2847  case 2:
2848  $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2849  break;
2850  case 3:
2851  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2852  $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2853  $r = $ilDB->query($qtemp);
2854  $course_users = array();
2855  while ($row = $ilDB->fetchAssoc($r))
2856  {
2857  array_push($course_users, $row["usr_id"]);
2858  }
2859  if (count($course_users))
2860  {
2861  $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2862  }
2863  else
2864  {
2865  return $result_arr;
2866  }
2867  break;
2868  case 4:
2869  $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"]));
2870  $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2871  break;
2872  case 5:
2873  $ref_id = $_SESSION["user_filter_data"];
2874  if ($ref_id)
2875  {
2876  $q .= " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id ".
2877  "WHERE obj_members.obj_id = (SELECT obj_id FROM object_reference ".
2878  "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2879  }
2880  break;
2881  case 6:
2882  global $rbacreview;
2883  $ref_id = $_SESSION["user_filter_data"];
2884  if ($ref_id)
2885  {
2886  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
2887  if (is_array($local_roles) && count($local_roles))
2888  {
2889  $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2890  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2891  }
2892  }
2893  break;
2894  case 7:
2895  $rol_id = $_SESSION["user_filter_data"];
2896  if ($rol_id)
2897  {
2898  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2899  $ilDB->quote($rol_id, "integer");
2900  }
2901  break;
2902  }
2903  $r = $ilDB->query($q);
2904 
2905  while ($row = $ilDB->fetchAssoc($r))
2906  {
2907  $result_arr[] = $row;
2908  }
2909  }
2910 
2911  return $result_arr;
2912  }
2913 
2917  static function _getNumberOfUsersForStyle($a_skin, $a_style)
2918  {
2919  global $ilDB;
2920 
2921  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
2922  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
2923  " AND up1.value= ".$ilDB->quote($a_style, "text").
2924  " AND up2.keyword= ".$ilDB->quote("skin", "text").
2925  " AND up2.value= ".$ilDB->quote($a_skin, "text").
2926  " AND up1.usr_id = up2.usr_id ";
2927 
2928  $cnt_set = $ilDB->query($q);
2929 
2930  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
2931 
2932  return $cnt_rec["cnt"];
2933  }
2934 
2938  static function _getAllUserAssignedStyles()
2939  {
2940  global $ilDB;
2941 
2942  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
2943  " WHERE up1.keyword = ".$ilDB->quote("style", "text").
2944  " AND up2.keyword = ".$ilDB->quote("skin", "text").
2945  " AND up1.usr_id = up2.usr_id";
2946 
2947  $sty_set = $ilDB->query($q);
2948 
2949  $styles = array();
2950  while($sty_rec = $ilDB->fetchAssoc($sty_set))
2951  {
2952  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
2953  }
2954 
2955  return $styles;
2956  }
2957 
2961  static function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
2962  {
2963  global $ilDB;
2964 
2965  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
2966  " WHERE up1.keyword= ".$ilDB->quote("style", "text").
2967  " AND up1.value= ".$ilDB->quote($a_from_style, "text").
2968  " AND up2.keyword= ".$ilDB->quote("skin", "text").
2969  " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
2970  " AND up1.usr_id = up2.usr_id ";
2971 
2972  $usr_set = $ilDB->query($q);
2973 
2974  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
2975  {
2976  self::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
2977  self::_writePref($usr_rec["usr_id"], "style", $a_to_style);
2978  }
2979  }
2980 
2981 
2991  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
2992  {
2993  global $ilDB;
2994 
2995  $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
2996  "item_id = %s AND type = %s AND user_id = %s",
2997  array("integer", "text", "integer"),
2998  array($a_item_id, $a_type, $a_usr_id));
2999 
3000  // only insert if item is not already on desktop
3001  if (!$ilDB->fetchAssoc($item_set))
3002  {
3003  $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3004  " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3005  array($a_item_id,$a_type,$a_usr_id,$a_par));
3006  }
3007 
3008  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3010  }
3011 
3019  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3020  {
3021  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3022  }
3023 
3032  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3033  {
3034  global $ilDB;
3035 
3036  $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3037  " WHERE item_id = %s AND type = %s AND user_id = %s",
3038  array("text", "integer", "text", "integer"),
3039  array($a_par, $a_item_id, $a_type, $this->getId()));
3040  }
3041 
3042 
3052  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3053  {
3054  global $ilDB;
3055 
3056  $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3057  " item_id = %s AND type = %s AND user_id = %s",
3058  array("integer", "text", "integer"),
3059  array($a_item_id, $a_type, $a_usr_id));
3060 
3061  include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3063  }
3064 
3072  function dropDesktopItem($a_item_id, $a_type)
3073  {
3074  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3075  }
3076 
3083  static function _removeItemFromDesktops($a_id)
3084  {
3085  global $ilDB;
3086 
3087  $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3088  array("integer"), array($a_id));
3089 
3090  $users = array();
3091 
3092  while ($row = $ilDB->fetchObject($r))
3093  {
3094  $users[] = $row->user_id;
3095  } // while
3096 
3097  if (count($users) > 0)
3098  {
3099  $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3100  array("integer"), array($a_id));
3101  }
3102 
3103  return $users;
3104  }
3105 
3115  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3116  {
3117  global $ilDB;
3118 
3119  if (self::$is_desktop_item_loaded[$a_usr_id.":".$a_item_id])
3120  {
3121  return self::$is_desktop_item_cache[$a_usr_id.":".$a_item_id.":".$a_type];
3122  }
3123  $item_set = $ilDB->queryF("SELECT item_id FROM desktop_item WHERE ".
3124  "item_id = %s AND type = %s AND user_id = %s",
3125  array("integer", "text", "integer"),
3126  array($a_item_id, $a_type, $a_usr_id));
3127 
3128  if ($ilDB->fetchAssoc($item_set))
3129  {
3130  return true;
3131  }
3132  else
3133  {
3134  return false;
3135  }
3136  }
3137 
3144  static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3145  {
3146  global $ilDB;
3147 
3148  if (!is_array($a_item_ids))
3149  {
3150  return;
3151  }
3152 
3153  $item_ids = array();
3154  foreach ($a_item_ids as $id)
3155  {
3156  if (!self::$is_desktop_item_loaded[$a_usr_id.":".$id])
3157  {
3158  $item_ids[] = $id;
3159  }
3160  self::$is_desktop_item_loaded[$a_usr_id.":".$id] = true;
3161  }
3162 
3163  if (count($item_ids) > 0)
3164  {
3165  $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE ".
3166  $ilDB->in("item_id", $item_ids, false, "integer").
3167  " AND user_id = ".$ilDB->quote($a_usr_id, "integer"));
3168  while ($r = $ilDB->fetchAssoc($item_set))
3169  {
3170  self::$is_desktop_item_cache[$a_usr_id.":".$r["item_id"].":".$r["type"]]
3171  = true;
3172  }
3173  }
3174  }
3175 
3183  function isDesktopItem($a_item_id, $a_type)
3184  {
3185  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3186  }
3187 
3188  function getDesktopItems($a_types = "")
3189  {
3190  return $this->_lookupDesktopItems($this->getId(), $a_types);
3191  }
3192 
3199  static function _lookupDesktopItems($user_id, $a_types = "")
3200  {
3201  global $ilUser, $rbacsystem, $tree, $ilDB;
3202 
3203  if ($a_types == "")
3204  {
3205  $is_nested_set = ($tree->getTreeImplementation() instanceof ilNestedSetTree);
3206 
3207  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3208  " FROM desktop_item it, object_reference oref ".
3209  ", object_data obj".
3210  " WHERE ".
3211  "it.item_id = oref.ref_id AND ".
3212  "oref.obj_id = obj.obj_id AND ".
3213  "it.user_id = %s", array("integer"), array($user_id));
3214  $items = $all_parent_path = array();
3215  while ($item_rec = $ilDB->fetchAssoc($item_set))
3216  {
3217  if ($tree->isInTree($item_rec["ref_id"])
3218  && $item_rec["type"] != "rolf"
3219  && $item_rec["type"] != "itgr") // due to bug 11508
3220  {
3221  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3222 
3223  if(!isset($all_parent_path[$parent_ref]))
3224  {
3225  // #15746
3226  //if($is_nested_set)
3227  //{
3228  // $par_left = $tree->getLeftValue($parent_ref);
3229  // $all_parent_path[$parent_ref] = sprintf("%010d", $par_left);
3230  //}
3231  //else
3232  //{
3233  $node = $tree->getNodeData($parent_ref);
3234  $all_parent_path[$parent_ref] = $node["title"];
3235  //}
3236  }
3237 
3238  $parent_path = $all_parent_path[$parent_ref];
3239 
3240  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3241  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3242  $items[$parent_path.$title.$item_rec["ref_id"]] =
3243  array("ref_id" => $item_rec["ref_id"],
3244  "obj_id" => $item_rec["obj_id"],
3245  "type" => $item_rec["type"],
3246  "title" => $title,
3247  "description" => $desc,
3248  "parent_ref" => $parent_ref);
3249  }
3250  }
3251  ksort($items);
3252  }
3253  else
3254  {
3255  // due to bug 11508
3256  if (!is_array($a_types))
3257  {
3258  $a_types = array($a_types);
3259  }
3260  $items = array();
3261  $foundsurveys = array();
3262  foreach($a_types as $a_type)
3263  {
3264  if ($a_type == "itgr")
3265  {
3266  continue;
3267  }
3268  $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3269  ", object_data obj WHERE ".
3270  "it.item_id = oref.ref_id AND ".
3271  "oref.obj_id = obj.obj_id AND ".
3272  "it.type = %s AND ".
3273  "it.user_id = %s ".
3274  "ORDER BY title",
3275  array("text", "integer"),
3276  array($a_type, $user_id));
3277 
3278  while ($item_rec = $ilDB->fetchAssoc($item_set))
3279  {
3280  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3281  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3282  $items[$title.$a_type.$item_rec["ref_id"]] =
3283  array("ref_id" => $item_rec["ref_id"],
3284  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3285  "title" => $title, "description" => $desc);
3286  }
3287 
3288  }
3289  ksort($items);
3290  }
3291 
3292  return $items;
3293  }
3294 
3300 
3308  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3309  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3310  {
3311  global $ilDB;
3312 
3313  if ($a_time == 0)
3314  {
3315  $a_time = date("Y-m-d H:i:s", time());
3316  }
3317 
3318  $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3319  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3320  array("integer", "integer", "text", "integer"),
3321  array(0, $a_item_id, $a_type, $this->getId()));
3322 
3323  // only insert if item is not already in clipboard
3324  if (!$d = $item_set->fetchRow())
3325  {
3326  $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3327  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3328  " (%s,%s,%s,%s,%s,%s,%s)",
3329  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3330  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3331  }
3332  else
3333  {
3334  $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3335  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3336  array("timestamp", "integer", "integer", "text"),
3337  array($a_time, $this->getId(), $a_item_id, $a_type));
3338  }
3339  }
3340 
3344  function addToPCClipboard($a_content, $a_time, $a_nr)
3345  {
3346  global $ilDB;
3347  if ($a_time == 0)
3348  {
3349  $a_time = date("Y-m-d H:i:s", time());
3350  }
3351  $ilDB->insert("personal_pc_clipboard", array(
3352  "user_id" => array("integer", $this->getId()),
3353  "content" => array("clob", $a_content),
3354  "insert_time" => array("timestamp", $a_time),
3355  "order_nr" => array("integer", $a_nr)
3356  ));
3357  }
3358 
3363  {
3364  global $ilDB;
3365 
3366  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3367  " WHERE user_id = %s", array("integer"), array($this->getId()));
3368  $row = $ilDB->fetchAssoc($set);
3369 
3370  $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3371  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3372  array("integer", "timestamp"),
3373  array($this->getId(), $row["mtime"]));
3374  $content = array();
3375  while ($row = $ilDB->fetchAssoc($set))
3376  {
3377  $content[] = $row["content"];
3378  }
3379 
3380  return $content;
3381  }
3382 
3387  {
3388  global $ilDB;
3389 
3390  $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3391  "parent = %s AND type = %s AND user_id = %s",
3392  array("integer", "text", "integer"),
3393  array(0, $a_type, $this->getId()));
3394  if ($rec = $ilDB->fetchAssoc($set))
3395  {
3396  return true;
3397  }
3398 
3399  return false;
3400  }
3401 
3406  {
3407  global $ilDB;
3408 
3409  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3410  "type = %s AND user_id = %s",
3411  array("text", "integer"),
3412  array($a_type, $this->getId()));
3413  }
3414 
3419  {
3420  global $ilDB;
3421 
3422  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3423  "user_id = %s", array("integer"), array($this->getId()));
3424  }
3425 
3429  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3430  {
3431  global $ilDB;
3432 
3433  $par = "";
3434  if ($a_top_nodes_only)
3435  {
3436  $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3437  }
3438 
3439  $type_str = ($a_type != "")
3440  ? " AND type = ".$ilDB->quote($a_type, "text")." "
3441  : "";
3442  $q = "SELECT * FROM personal_clipboard WHERE ".
3443  "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3444  $type_str.$par.
3445  " ORDER BY order_nr";
3446  $objs = $ilDB->query($q);
3447  $objects = array();
3448  while ($obj = $ilDB->fetchAssoc($objs))
3449  {
3450  if ($obj["type"] == "mob")
3451  {
3452  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3453  }
3454  if ($obj["type"] == "incl")
3455  {
3456  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3457  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3458  }
3459  $objects[] = array ("id" => $obj["item_id"],
3460  "type" => $obj["type"], "title" => $obj["title"],
3461  "insert_time" => $obj["insert_time"]);
3462  }
3463  return $objects;
3464  }
3465 
3469  function getClipboardChilds($a_parent, $a_insert_time)
3470  {
3471  global $ilDB, $ilUser;
3472 
3473  $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3474  "user_id = %s AND parent = %s AND insert_time = %s ".
3475  " ORDER BY order_nr",
3476  array("integer", "integer", "timestamp"),
3477  array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3478  $objects = array();
3479  while ($obj = $ilDB->fetchAssoc($objs))
3480  {
3481  if ($obj["type"] == "mob")
3482  {
3483  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3484  }
3485  $objects[] = array ("id" => $obj["item_id"],
3486  "type" => $obj["type"], "title" => $obj["title"], "insert_time" => $obj["insert_time"]);
3487  }
3488  return $objects;
3489  }
3490 
3499  static function _getUsersForClipboadObject($a_type, $a_id)
3500  {
3501  global $ilDB;
3502 
3503  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3504  "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3505  "type = ".$ilDB->quote($a_type, "text");
3506  $user_set = $ilDB->query($q);
3507  $users = array();
3508  while ($user_rec = $ilDB->fetchAssoc($user_set))
3509  {
3510  $users[] = $user_rec["user_id"];
3511  }
3512 
3513  return $users;
3514  }
3515 
3523  function removeObjectFromClipboard($a_item_id, $a_type)
3524  {
3525  global $ilDB;
3526 
3527  $q = "DELETE FROM personal_clipboard WHERE ".
3528  "item_id = ".$ilDB->quote($a_item_id, "integer").
3529  " AND type = ".$ilDB->quote($a_type, "text")." ".
3530  " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3531  $ilDB->manipulate($q);
3532  }
3533 
3534  static function _getImportedUserId($i2_id)
3535  {
3536  global $ilDB;
3537 
3538  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3539  $ilDB->quote($i2_id, "text");
3540 
3541  $res = $ilDB->query($query);
3542  while($row = $ilDB->fetchObject($res))
3543  {
3544  $id = $row->obj_id;
3545  }
3546  return $id ? $id : 0;
3547  }
3548 
3554  public static function lookupOrgUnitsRepresentation($a_usr_id)
3555  {
3556  require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
3557  return ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_usr_id);
3558  }
3559 
3560 
3564  public function getOrgUnitsRepresentation() {
3565  return self::lookupOrgUnitsRepresentation($this->getId());
3566  }
3567 
3568 
3573  function setAuthMode($a_str)
3574  {
3575  $this->auth_mode = $a_str;
3576  }
3577 
3582  function getAuthMode($a_auth_key = false)
3583  {
3584  if (!$a_auth_key)
3585  {
3586  return $this->auth_mode;
3587  }
3588 
3589  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3590  return ilAuthUtils::_getAuthMode($this->auth_mode);
3591  }
3592 
3600  function setExternalAccount($a_str)
3601  {
3602  $this->ext_account = $a_str;
3603  }
3604 
3613  {
3614  return $this->ext_account;
3615  }
3616 
3628  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3629  {
3630  global $ilDB,$ilSetting;
3631 
3632  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3633  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3634  "WHERE auth_mode = %s";
3635  $types[] = "text";
3636  $values[] = $a_auth_mode;
3637  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3638  {
3639  $q.= " OR auth_mode = %s ";
3640  $types[] = "text";
3641  $values[] = 'default';
3642  }
3643 
3644  $res = $ilDB->queryF($q, $types, $values);
3645  while ($row = $ilDB->fetchObject($res))
3646  {
3647  if($row->auth_mode == 'default')
3648  {
3649  $accounts[$row->usr_id] = $row->login;
3650  }
3651  else
3652  {
3653  $accounts[$row->usr_id] = $row->ext_account;
3654  }
3655  }
3656  return $accounts ? $accounts : array();
3657  }
3658 
3666  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3667  {
3668  global $ilDB;
3669 
3670  if(!is_array($a_usr_ids))
3671  {
3672  return false;
3673  }
3674 
3675 
3676  if( $a_status )
3677  {
3678  $q = "UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE ".
3679  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3680  $ilDB->manipulate($q);
3681  }
3682  else
3683  {
3684  $usrId_IN_usrIds = $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3685 
3686  $q = "UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds";
3687  $ilDB->manipulate($q);
3688 
3689  $queryString = "
3690  UPDATE usr_data
3691  SET inactivation_date = %s
3692  WHERE inactivation_date IS NULL
3693  AND $usrId_IN_usrIds
3694  ";
3695  $ilDB->manipulateF($queryString, array('timestamp'), array(ilUtil::now()));
3696  }
3697 
3698  return true;
3699  }
3700 
3701 
3710  public static function _lookupAuthMode($a_usr_id)
3711  {
3712  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3713  }
3714 
3721  public static function _checkExternalAuthAccount($a_auth, $a_account)
3722  {
3723  global $ilDB,$ilSetting;
3724 
3725  // Check directly with auth_mode
3726  $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3727  " ext_account = %s AND auth_mode = %s",
3728  array("text", "text"),
3729  array($a_account, $a_auth));
3730  if ($usr = $ilDB->fetchAssoc($r))
3731  {
3732  return $usr["login"];
3733  }
3734 
3735  // For compatibility, check for login (no ext_account entry given)
3736  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3737  "WHERE login = %s AND auth_mode = %s AND ext_account IS NULL ",
3738  array("text", "text"),
3739  array($a_account, $a_auth));
3740  if($usr = $ilDB->fetchAssoc($res))
3741  {
3742  return $usr['login'];
3743  }
3744 
3745  // If auth_default == $a_auth => check for login
3746  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3747  {
3748  $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3749  " ext_account = %s AND auth_mode = %s",
3750  array("text", "text"),
3751  array($a_account, "default"));
3752  if ($usr = $ilDB->fetchAssoc($res))
3753  {
3754  return $usr["login"];
3755  }
3756  // Search for login (no ext_account given)
3757  $res = $ilDB->queryF("SELECT login FROM usr_data ".
3758  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3759  array("text", "text"),
3760  array($a_account, "default"));
3761  if($usr = $ilDB->fetchAssoc($res))
3762  {
3763  return $usr["login"];
3764  }
3765  }
3766  return false;
3767  }
3768 
3773  {
3774  global $ilDB;
3775 
3776  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3777  "GROUP BY auth_mode");
3778  $cnt_arr = array();
3779  while($cnt = $ilDB->fetchAssoc($r))
3780  {
3781  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3782  }
3783 
3784  return $cnt_arr;
3785  }
3786 
3792  static function _getLocalAccountsForEmail($a_email)
3793  {
3794  global $ilDB, $ilSetting;
3795 
3796  // default set to local (1)?
3797 
3798  $q = "SELECT * FROM usr_data WHERE ".
3799  " email = %s AND (auth_mode = %s ";
3800  $types = array("text", "text");
3801  $values = array($a_email, "local");
3802 
3803  if ($ilSetting->get("auth_mode") == 1)
3804  {
3805  $q.=" OR auth_mode = %s";
3806  $types[] = "text";
3807  $values[] = "default";
3808  }
3809 
3810  $q.= ")";
3811 
3812  $users = array();
3813  $usr_set = $ilDB->queryF($q, $types, $values);
3814  while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3815  {
3816  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3817  }
3818 
3819  return $users;
3820  }
3821 
3822 
3830  static function _uploadPersonalPicture($tmp_file, $obj_id)
3831  {
3832  $webspace_dir = ilUtil::getWebspaceDir();
3833  $image_dir = $webspace_dir."/usr_images";
3834  $store_file = "usr_".$obj_id."."."jpg";
3835  $target_file = $image_dir."/$store_file";
3836 
3837  chmod($tmp_file, 0770);
3838 
3839  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3840  // taking only frame [0] to avoid problems with animated gifs
3841  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3842  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3843  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3844  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3845 
3846  ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
3847  ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
3848  ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
3849  ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
3850 
3851  // store filename
3852  self::_writePref($obj_id, "profile_image", $store_file);
3853 
3854  return TRUE;
3855  }
3856 
3857 
3866  public function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3867  {
3868  if(isset(self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic]))
3869  {
3870  return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3871  }
3872 
3873  self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic] = ilObjUser::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
3874 
3875  return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3876  }
3877 
3887  public static function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3888  $a_prevent_no_photo_image = false)
3889  {
3890  global $ilDB;
3891 
3892  // BEGIN DiskQuota: Fetch all user preferences in a single query
3893  $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3894  "keyword IN (%s,%s) ".
3895  "AND usr_id = %s",
3896  array("text", "text", "integer"),
3897  array('public_upload', 'public_profile', $a_usr_id));
3898  while ($row = $ilDB->fetchAssoc($res))
3899  {
3900  switch ($row['keyword'])
3901  {
3902  case 'public_upload' :
3903  $upload = $row['value'] == 'y';
3904  break;
3905  case 'public_profile' :
3906  $profile = ($row['value'] == 'y' ||
3907  $row['value'] == 'g');
3908  break;
3909  }
3910  }
3911 
3912  // END DiskQuota: Fetch all user preferences in a single query
3913  $webspace_dir = "";
3914  if(defined('ILIAS_MODULE'))
3915  {
3916  $webspace_dir = ('.'.$webspace_dir);
3917  }
3918  $webspace_dir .= ('./'.ltrim(ilUtil::getWebspaceDir(), "./"));
3919 
3920  $image_dir = $webspace_dir."/usr_images";
3921  // BEGIN DiskQuota: Support 'big' user images
3922  if ($a_size == 'big')
3923  {
3924  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3925  }
3926  else
3927  {
3928  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3929  }
3930  // END DiskQuota: Support 'big' user images
3931 
3932  if((($upload && $profile) || $a_force_pic)
3933  && @is_file($thumb_file))
3934  {
3935  $file = $thumb_file."?t=".rand(1, 99999);
3936  }
3937  else
3938  {
3939  if (!$a_prevent_no_photo_image)
3940  {
3941  // we only have xsmall and xxsmall for this
3942  if($a_size == "small" || $a_size == "big")
3943  {
3944  $a_size = "xsmall";
3945  }
3946  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
3947  }
3948  }
3949 
3950  require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
3952  }
3953 
3960  static function copyProfilePicturesToDirectory($a_user_id, $a_dir)
3961  {
3962  $a_dir = trim(str_replace("..", "", $a_dir));
3963  if ($a_dir == "" || !is_dir($a_dir))
3964  {
3965  return;
3966  }
3967 
3968  $webspace_dir = ilUtil::getWebspaceDir();
3969  $image_dir = $webspace_dir."/usr_images";
3970  $images = array(
3971  "upload_".$a_user_id."pic",
3972  "usr_".$a_user_id."."."jpg",
3973  "usr_".$a_user_id."_small.jpg",
3974  "usr_".$a_user_id."_xsmall.jpg",
3975  "usr_".$a_user_id."_xxsmall.jpg",
3976  "upload_".$a_user_id);
3977  foreach ($images as $image)
3978  {
3979  if (is_file($image_dir."/".$image))
3980  {
3981  copy($image_dir."/".$image, $a_dir."/".$image);
3982  }
3983  }
3984  }
3985 
3986 
3990  function removeUserPicture($a_do_update = true)
3991  {
3992  $webspace_dir = ilUtil::getWebspaceDir();
3993  $image_dir = $webspace_dir."/usr_images";
3994  $file = $image_dir."/usr_".$this->getID()."."."jpg";
3995  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
3996  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
3997  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
3998  $upload_file = $image_dir."/upload_".$this->getID();
3999 
4000  if($a_do_update)
4001  {
4002  // remove user pref file name
4003  $this->setPref("profile_image", "");
4004  $this->update();
4005  }
4006 
4007  if (@is_file($file))
4008  {
4009  unlink($file);
4010  }
4011  if (@is_file($thumb_file))
4012  {
4013  unlink($thumb_file);
4014  }
4015  if (@is_file($xthumb_file))
4016  {
4017  unlink($xthumb_file);
4018  }
4019  if (@is_file($xxthumb_file))
4020  {
4021  unlink($xxthumb_file);
4022  }
4023  if (@is_file($upload_file))
4024  {
4025  unlink($upload_file);
4026  }
4027  }
4028 
4029 
4030  function setUserDefinedData($a_data)
4031  {
4032  if(!is_array($a_data))
4033  {
4034  return false;
4035  }
4036  foreach($a_data as $field => $data)
4037  {
4038  #$new_data[$field] = ilUtil::stripSlashes($data);
4039  // Assign it directly to avoid update problems of unchangable fields
4040  $this->user_defined_data['f_'.$field] = $data;
4041  }
4042  #$this->user_defined_data = $new_data;
4043 
4044  return true;
4045  }
4046 
4048  {
4049  return $this->user_defined_data ? $this->user_defined_data : array();
4050  }
4051 
4053  {
4054  global $ilDB;
4055 
4056  $fields = '';
4057 
4058  $field_def = array();
4059 
4060  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4061  $udata = new ilUserDefinedData($this->getId());
4062 
4063  foreach($this->user_defined_data as $field => $value)
4064  {
4065  if($field != 'usr_id')
4066  {
4067 // $field_def[$field] = array('text',$value);
4068  $udata->set($field, $value);
4069  }
4070  }
4071  $udata->update();
4072 
4073 /* if(!$field_def)
4074  {
4075  return true;
4076  }
4077 
4078  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4079  $res = $ilDB->query($query);
4080 
4081 
4082  if($res->numRows())
4083  {
4084  // Update
4085  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4086  }
4087  else
4088  {
4089  $field_def['usr_id'] = array('integer',$this->getId());
4090  $ilDB->insert('udf_data',$field_def);
4091  }
4092 */
4093  return true;
4094  }
4095 
4097  {
4098  global $ilDB;
4099 
4100  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4101  $udata = new ilUserDefinedData($this->getId());
4102 
4103 /* $query = "SELECT * FROM udf_data ".
4104  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4105 
4106  $res = $this->db->query($query);
4107  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
4108  {
4109  $this->user_defined_data = $row;
4110  }*/
4111 
4112  $this->user_defined_data = $udata->getAll();
4113 
4114  return true;
4115  }
4116 
4118  {
4119  global $ilDB;
4120 
4121 // not needed. no entry in udf_text/udf_clob means no value
4122 
4123 /* $query = "INSERT INTO udf_data (usr_id ) ".
4124  "VALUES( ".
4125  $ilDB->quote($this->getId(),'integer').
4126  ")";
4127  $res = $ilDB->manipulate($query);
4128 */
4129  return true;
4130  }
4131 
4133  {
4134  global $ilDB;
4135 
4136  include_once("./Services/User/classes/class.ilUserDefinedData.php");
4138 
4139  // wrong place...
4140 /* $query = "DELETE FROM udf_data ".
4141  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4142  $res = $ilDB->manipulate($query);*/
4143 
4144  return true;
4145  }
4146 
4152  function getProfileAsString(&$a_language)
4153  {
4154  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4155 
4156  global $lng,$rbacreview;
4157 
4158  $language =& $a_language;
4159  $language->loadLanguageModule('registration');
4160  $language->loadLanguageModule('crs');
4161 
4162  $body = '';
4163  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4164 
4165  if(strlen($this->getUTitle()))
4166  {
4167  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4168  }
4169  if(strlen($this->getGender()))
4170  {
4171  $gender = ($this->getGender() == 'm') ?
4172  $language->txt('gender_m') :
4173  $language->txt('gender_f');
4174  $body .= ($language->txt("gender").": ".$gender."\n");
4175  }
4176  if(strlen($this->getFirstname()))
4177  {
4178  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4179  }
4180  if(strlen($this->getLastname()))
4181  {
4182  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4183  }
4184  if(strlen($this->getInstitution()))
4185  {
4186  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4187  }
4188  if(strlen($this->getDepartment()))
4189  {
4190  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4191  }
4192  if(strlen($this->getStreet()))
4193  {
4194  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4195  }
4196  if(strlen($this->getCity()))
4197  {
4198  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4199  }
4200  if(strlen($this->getZipcode()))
4201  {
4202  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4203  }
4204  if(strlen($this->getCountry()))
4205  {
4206  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4207  }
4208  if(strlen($this->getSelectedCountry()))
4209  {
4210  $body .= ($language->txt("sel_country").": ".$this->getSelectedCountry()."\n");
4211  }
4212  if(strlen($this->getPhoneOffice()))
4213  {
4214  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4215  }
4216  if(strlen($this->getPhoneHome()))
4217  {
4218  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4219  }
4220  if(strlen($this->getPhoneMobile()))
4221  {
4222  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4223  }
4224  if(strlen($this->getFax()))
4225  {
4226  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4227  }
4228  if(strlen($this->getEmail()))
4229  {
4230  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4231  }
4232  if(strlen($this->getHobby()))
4233  {
4234  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4235  }
4236  if(strlen($this->getComment()))
4237  {
4238  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4239  }
4240  if(strlen($this->getMatriculation()))
4241  {
4242  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4243  }
4244  if(strlen($this->getCreateDate()))
4245  {
4250 
4251  $body .= ($language->txt("create_date").": ".$date."\n");
4252  }
4253 
4254  foreach($rbacreview->getGlobalRoles() as $role)
4255  {
4256  if($rbacreview->isAssigned($this->getId(),$role))
4257  {
4258  $gr[] = ilObjRole::_lookupTitle($role);
4259  }
4260  }
4261  if(count($gr))
4262  {
4263  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4264  }
4265 
4266  // Time limit
4267  if($this->getTimeLimitUnlimited())
4268  {
4269  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4270  }
4271  else
4272  {
4276  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4278 
4280  $end = new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX);
4281 
4282  $body .= $language->txt('time_limit').': '.$start->get(IL_CAL_DATETIME);
4283  $body .= $language->txt('time_limit').': '.$end->get(IL_CAL_DATETIME);
4284  }
4285 
4286  include_once './Services/User/classes/class.ilUserDefinedFields.php';
4290  $user_defined_fields = ilUserDefinedFields::_getInstance();
4291  $user_defined_data = $this->getUserDefinedData();
4292 
4293  foreach($user_defined_fields->getDefinitions() as $field_id => $definition)
4294  {
4295  $data = $user_defined_data["f_".$field_id];
4296  if(strlen($data))
4297  {
4298  if($definition['field_type'] == UDF_TYPE_WYSIWYG)
4299  {
4300  $data = preg_replace('/<br(\s*)?\/?>/i', "\n", $data);
4301  $data = strip_tags($data);
4302  }
4303 
4304  $body .= $definition['field_name'].': '. $data . "\n";
4305  }
4306  }
4307 
4308  return $body;
4309  }
4310 
4314  static function _lookupFeedHash($a_user_id, $a_create = false)
4315  {
4316  global $ilDB;
4317 
4318  if ($a_user_id > 0)
4319  {
4320  $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4321  array("integer"), array($a_user_id));
4322  if ($rec = $ilDB->fetchAssoc($set))
4323  {
4324  if (strlen($rec["feed_hash"]) == 32)
4325  {
4326  return $rec["feed_hash"];
4327  }
4328  else if($a_create)
4329  {
4330  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4331  $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4332  " WHERE usr_id = %s",
4333  array("text", "integer"),
4334  array($hash, $a_user_id));
4335  return $hash;
4336  }
4337  }
4338  }
4339 
4340  return false;
4341  }
4342 
4348  static function _getFeedPass($a_user_id)
4349  {
4350  global $ilDB;
4351 
4352  if ($a_user_id > 0)
4353  {
4354  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4355  }
4356  return false;
4357  }
4358 
4364  static function _setFeedPass($a_user_id, $a_password)
4365  {
4366  global $ilDB;
4367 
4368  self::_writePref($a_user_id, "priv_feed_pass",
4369  ($a_password=="") ? "" : md5($a_password));
4370  }
4371 
4381  public static function _loginExists($a_login,$a_user_id = 0)
4382  {
4383  global $ilDB;
4384 
4385  $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4386  "WHERE login = %s";
4387  $types[] = "text";
4388  $values[] = $a_login;
4389 
4390  if ($a_user_id != 0)
4391  {
4392  $q.= " AND usr_id != %s ";
4393  $types[] = "integer";
4394  $values[] = $a_user_id;
4395  }
4396 
4397  $r = $ilDB->queryF($q, $types, $values);
4398 
4399  if ($row = $ilDB->fetchAssoc($r))
4400  {
4401  return $row['usr_id'];
4402  }
4403  return false;
4404  }
4405 
4416  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4417  {
4418  global $ilDB;
4419 
4420  $res = $ilDB->queryF("SELECT * FROM usr_data ".
4421  "WHERE ext_account = %s AND auth_mode = %s",
4422  array("text", "text"),
4423  array($a_external_account, $a_auth_mode));
4424  return $ilDB->fetchAssoc($res) ? true :false;
4425  }
4426 
4434  public static function _getUsersForRole($role_id, $active = -1) {
4435  global $ilDB, $rbacreview;
4436  $data = array();
4437 
4438  $ids = $rbacreview->assignedUsers($role_id);
4439 
4440  if (count ($ids) == 0)
4441  {
4442  $ids = array (-1);
4443  }
4444 
4445  $query = "SELECT usr_data.*, usr_pref.value AS language
4446  FROM usr_data
4447  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4448  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4449  $values[] = "language";
4450  $types[] = "text";
4451 
4452 
4453  if (is_numeric($active) && $active > -1)
4454  {
4455  $query .= " AND usr_data.active = %s";
4456  $values[] = $active;
4457  $types[] = "integer";
4458  }
4459 
4460  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4461 
4462  $r = $ilDB->queryF($query, $types, $values);
4463  $data = array();
4464  while ($row = $ilDB->fetchAssoc($r))
4465  {
4466  $data[] = $row;
4467  }
4468  return $data;
4469  }
4470 
4471 
4477  public static function _getUsersForFolder ($ref_id, $active) {
4478  global $ilDB;
4479  $data = array();
4480  $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 ";
4481  $types[] = "text";
4482  $values[] = "language";
4483 
4484  if (is_numeric($active) && $active > -1)
4485  {
4486  $query .= " AND usr_data.active = %s";
4487  $values[] = $active;
4488  $types[] = "integer";
4489  }
4490 
4491  if ($ref_id != USER_FOLDER_ID)
4492  {
4493  $query.= " AND usr_data.time_limit_owner = %s";
4494  $values[] = $ref_id;
4495  $types[] = "integer";
4496  }
4497 
4498  $query .= " AND usr_data.usr_id != %s ";
4499  $values[] = ANONYMOUS_USER_ID;
4500  $types[] = "integer";
4501 
4502  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4503 
4504  $result = $ilDB->queryF($query, $types, $values);
4505  $data = array();
4506  while ($row = $ilDB->fetchAssoc($result))
4507  {
4508  array_push($data, $row);
4509  }
4510 
4511  return $data;
4512  }
4513 
4514 
4520  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4521  {
4522  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4523  }
4524 
4525 
4531  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4532  {
4533  global $rbacadmin, $rbacreview, $ilDB;
4534 
4535  $query = "SELECT usr_data.*, usr_pref.value AS language
4536  FROM usr_data
4537  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4538  WHERE ".$ilDB->in("usr_data.usr_id", $a_mem_ids, false, "integer")."
4539  AND usr_data.usr_id != %s";
4540  $values[] = "language";
4541  $types[] = "text";
4542  $values[] = ANONYMOUS_USER_ID;
4543  $types[] = "integer";
4544 
4545  if (is_numeric($active) && $active > -1)
4546  {
4547  $query .= " AND active = %s";
4548  $values[] = $active;
4549  $types[] = "integer";
4550  }
4551 
4552  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4553  {
4554  $query.= " AND usr_data.time_limit_owner = %s";
4555  $values[] = $timelimitowner;
4556  $types[] = "integer";
4557 
4558  }
4559 
4560  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4561 
4562  $result = $ilDB->queryF($query, $types, $values);
4563  while ($row = $ilDB->fetchAssoc($result))
4564  {
4565  $mem_arr[] = $row;
4566  }
4567 
4568  return $mem_arr ? $mem_arr : array();
4569  }
4570 
4571 
4572 
4578  public static function _getUserData ($a_internalids) {
4579  global $ilDB;
4580 
4581  $ids = array();
4582  if (is_array($a_internalids)) {
4583  foreach ($a_internalids as $internalid) {
4584  if (is_numeric ($internalid))
4585  {
4586  $ids[] = $internalid;
4587  }
4588  else
4589  {
4590  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4591  if (is_numeric($parsedid) && $parsedid > 0)
4592  {
4593  $ids[] = $parsedid;
4594  }
4595  }
4596  }
4597  }
4598  if (count($ids) == 0)
4599  $ids [] = -1;
4600 
4601  $query = "SELECT usr_data.*, usr_pref.value AS language
4602  FROM usr_data
4603  LEFT JOIN usr_pref
4604  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4605  WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4606  $values[] = "language";
4607  $types[] = "text";
4608 
4609  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4610 
4611  $data = array();
4612  $result = $ilDB->queryF($query, $types, $values);
4613  while ($row = $ilDB->fetchAssoc($result))
4614  {
4615  $data[] = $row;
4616  }
4617  return $data;
4618  }
4619 
4626  public static function _getPreferences ($user_id)
4627  {
4628  global $ilDB;
4629 
4630  $prefs = array();
4631 
4632  $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4633  array("integer"), array($user_id));
4634 
4635  while($row = $ilDB->fetchAssoc($r))
4636  {
4637  $prefs[$row["keyword"]] = $row["value"];
4638  }
4639 
4640  return $prefs;
4641  }
4642 
4652  public static function getUserSubsetByPreferenceValue($a_user_ids, $a_keyword, $a_val)
4653  {
4654  global $ilDB;
4655 
4656  $users = array();
4657  $set = $ilDB->query("SELECT usr_id FROM usr_pref ".
4658  " WHERE keyword = ".$ilDB->quote($a_keyword, "text").
4659  " AND ".$ilDB->in("usr_id", $a_user_ids, false, "integer").
4660  " AND value = ".$ilDB->quote($a_val, "text")
4661  );
4662  while ($rec = $ilDB->fetchAssoc($set))
4663  {
4664  $users[] = $rec["usr_id"];
4665  }
4666  return $users;
4667  }
4668 
4669 
4670  public static function _resetLoginAttempts($a_usr_id)
4671  {
4672  global $ilDB;
4673 
4674  $query = "UPDATE usr_data SET login_attempts = 0 WHERE usr_id = %s";
4675  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4676 
4677  if($affected) return true;
4678  else return false;
4679  }
4680 
4681  public static function _getLoginAttempts($a_usr_id)
4682  {
4683  global $ilDB;
4684 
4685  $query = "SELECT login_attempts FROM usr_data WHERE usr_id = %s";
4686  $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4687  $record = $ilDB->fetchAssoc( $result );
4688  $login_attempts = $record['login_attempts'];
4689 
4690  return $login_attempts;
4691  }
4692 
4693  public static function _incrementLoginAttempts($a_usr_id)
4694  {
4695  global $ilDB;
4696 
4697  $query = "UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s";
4698  $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4699 
4700  if($affected) return true;
4701  else return false;
4702  }
4703 
4704  public static function _setUserInactive($a_usr_id)
4705  {
4706  global $ilDB;
4707 
4708  $query = "UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s";
4709  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array(ilUtil::now(), $a_usr_id) );
4710 
4711  if($affected) return true;
4712  else return false;
4713  }
4714 
4720  public function hasPublicProfile() {
4721  return in_array($this->getPref("public_profile"), array("y", "g"));
4722  }
4723 
4729  public function getPublicName()
4730  {
4731  if ($this->hasPublicProfile())
4732  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4733  else
4734  return $this->getLogin();
4735 
4736  }
4737 
4738  public static function _writeHistory($a_usr_id, $a_login)
4739  {
4740  global $ilDB;
4741 
4742  $timestamp = time();
4743 
4744  $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4745  array('integer', 'text', 'integer'),
4746  array($a_usr_id, $a_login, $timestamp));
4747 
4748  if( $ilDB->numRows($res) == 0 )
4749  {
4750  $ilDB->manipulateF('
4751  INSERT INTO loginname_history
4752  (usr_id, login, history_date)
4753  VALUES (%s, %s, %s)',
4754  array('integer', 'text', 'integer'),
4755  array($a_usr_id, $a_login, $timestamp));
4756  }
4757 
4758  return true;
4759  }
4760 
4768  public static function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4769  {
4773  global $DIC;
4774 
4775  $ilDB = $DIC->database();
4776  $rbacreview = $DIC->rbac()->review();
4777 
4778  $pd_set = new ilSetting('pd');
4779  $atime = $pd_set->get('user_activity_time') * 60;
4780  $ctime = time();
4781 
4782  $where = array();
4783 
4784  if($a_user_id == 0)
4785  {
4786  $where[] = 'user_id > 0';
4787  }
4788  else if (is_array($a_user_id))
4789  {
4790  $where[] = $ilDB->in("user_id", $a_user_id, false, "integer");
4791  }
4792  else
4793  {
4794  $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
4795  }
4796 
4797  if($a_no_anonymous)
4798  {
4799  $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
4800  }
4801 
4802  include_once 'Services/User/classes/class.ilUserAccountSettings.php';
4803  if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
4804  {
4805  include_once 'Services/User/classes/class.ilUserFilter.php';
4806  $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
4807  }
4808 
4809  $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
4810  $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
4811 
4812  $where = 'WHERE ' . implode(' AND ', $where);
4813 
4814  $r = $ilDB->queryF("
4815  SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime, agree_date
4816  FROM usr_session
4817  LEFT JOIN usr_data u
4818  ON user_id = u.usr_id
4819  LEFT JOIN usr_pref p
4820  ON (p.usr_id = u.usr_id AND p.keyword = %s)
4821  {$where}
4822  GROUP BY user_id, firstname, lastname, title, login, last_login, agree_date
4823  ORDER BY lastname, firstname
4824  ",
4825  array('text'),
4826  array('hide_own_online_status')
4827  );
4828 
4829  $users = array();
4830  while($user = $ilDB->fetchAssoc($r))
4831  {
4832  if($atime <= 0 || $user['ctime'] + $atime > $ctime)
4833  {
4834  $users[$user['user_id']] = $user;
4835  }
4836  }
4837 
4838  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4840  $users = array_filter($users, function($user) {
4841  if ($user['agree_date'] || $user['user_id'] == SYSTEM_USER_ID || 'root' === $user['login']) {
4842  return true;
4843  }
4844 
4845  return false;
4846  });
4847  }
4848 
4849  return $users;
4850  }
4851 
4861  public static function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4862  {
4863  global $ilias, $ilDB;
4864 
4865  $pd_set = new ilSetting("pd");
4866  $atime = $pd_set->get("user_activity_time") * 60;
4867  $ctime = time();
4868  $no_anonym = ($a_no_anonymous)
4869  ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4870  : "";
4871 
4872  // Get a list of object id's of all courses and groups for which
4873  // the current user has local roles.
4874  // Note: we have to use DISTINCT here, because a user may assume
4875  // multiple roles in a group or a course.
4876  $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4877  "FROM rbac_ua ua ".
4878  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4879  "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4880  "JOIN tree ON tree.child = r1.ref_id ".
4881  "JOIN object_reference r2 ON r2.ref_id = tree.child ". // #17674 - rolf is gone
4882  "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4883  "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4884  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4885  "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4886  $ilDB->quote("grp", "text").")";
4887  $r = $ilDB->query($q);
4888 
4889  while ($row = $ilDB->fetchAssoc($r))
4890  {
4891  $groups_and_courses_of_user[] = $row["obj_id"];
4892  }
4893 
4894  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4895  $tos_condition = '';
4897  {
4898  $tos_condition = " AND (agree_date IS NOT NULL OR ud.usr_id = " . $ilDB->quote(SYSTEM_USER_ID, 'integer') . ") ";
4899  }
4900 
4901  // If the user is not in a course or a group, he has no associated users.
4902  if (count($groups_and_courses_of_user) == 0)
4903  {
4904  $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4905  "FROM usr_session ".
4906  "JOIN usr_data ud ON user_id = ud.usr_id ".
4907  "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4908  $no_anonym.
4909  $tos_condition.
4910  "AND expires > ".$ilDB->quote(time(), "integer")." ".
4911  "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4912  $r = $ilDB->query($q);
4913  }
4914  else
4915  {
4916  $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4917  "FROM usr_session s ".
4918  "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4919  "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
4920  "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4921  "JOIN tree ON tree.child = fa.parent ".
4922  "JOIN object_reference or1 ON or1.ref_id = tree.child ". // #17674 - rolf is gone
4923  "JOIN object_data od ON od.obj_id = or1.obj_id ".
4924  "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
4925  $ilDB->quote("hide_own_online_status", "text").") ".
4926  "WHERE s.user_id != 0 ".
4927  $no_anonym.
4928  "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4929  "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
4930  "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4931  $tos_condition.
4932  "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
4933  "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4934  "ORDER BY ud.lastname, ud.firstname";
4935  $r = $ilDB->query($q);
4936  }
4937 
4938  while ($user = $ilDB->fetchAssoc($r))
4939  {
4940  if ($atime <= 0
4941  || $user["ctime"] + $atime > $ctime)
4942  {
4943  $users[$user["user_id"]] = $user;
4944  }
4945  }
4946 
4947  return $users ? $users : array();
4948  }
4949 
4956  public static function _generateRegistrationHash($a_usr_id)
4957  {
4958  global $ilDB;
4959 
4960  do
4961  {
4962  $continue = false;
4963 
4964  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
4965 
4966  $res = $ilDB->queryf('
4967  SELECT COUNT(usr_id) cnt FROM usr_data
4968  WHERE reg_hash = %s',
4969  array('text'),
4970  array($hashcode));
4971  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
4972  {
4973  if($row->cnt > 0) $continue = true;
4974  break;
4975  }
4976 
4977  if($continue) continue;
4978 
4979  $ilDB->manipulateF('
4980  UPDATE usr_data
4981  SET reg_hash = %s
4982  WHERE usr_id = %s',
4983  array('text', 'integer'),
4984  array($hashcode, (int)$a_usr_id)
4985  );
4986 
4987  break;
4988 
4989  } while(true);
4990 
4991  return $hashcode;
4992  }
4993 
5002  public static function _verifyRegistrationHash($a_hash)
5003  {
5004  global $ilDB;
5005 
5006  $res = $ilDB->queryf('
5007  SELECT usr_id, create_date FROM usr_data
5008  WHERE reg_hash = %s',
5009  array('text'),
5010  array($a_hash));
5011  while($row = $ilDB->fetchAssoc($res))
5012  {
5013  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
5014  $oRegSettigs = new ilRegistrationSettings();
5015 
5016  if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
5017  time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
5018  {
5019  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
5020  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
5021  }
5022 
5023  $ilDB->manipulateF('
5024  UPDATE usr_data
5025  SET reg_hash = %s
5026  WHERE usr_id = %s',
5027  array('text', 'integer'),
5028  array('', (int)$row['usr_id'])
5029  );
5030 
5031  return (int)$row['usr_id'];
5032  }
5033 
5034  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
5035  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
5036  }
5037 
5038  function setBirthday($a_birthday)
5039  {
5040  if (strlen($a_birthday))
5041  {
5042  $date = new ilDate($a_birthday, IL_CAL_DATE);
5043  $this->birthday = $date->get(IL_CAL_DATE);
5044  }
5045  else
5046  {
5047  $this->birthday = null;
5048  }
5049  }
5050 
5051  function getBirthday()
5052  {
5053  return $this->birthday;
5054  }
5055 
5064  public static function _getUserIdsByInactivityPeriod($period)
5065  {
5066  if( !(int)$period ) throw new ilException('no valid period given');
5067 
5068  global $ilDB;
5069 
5070  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5071 
5072  $query = "SELECT usr_id FROM usr_data WHERE last_login < %s OR (ISNULL(last_login) AND create_date < %s)";
5073 
5074  $res = $ilDB->queryF($query, array('timestamp', 'timestamp'), array($date, $date));
5075 
5076  $ids = array();
5077  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
5078  {
5079  $ids[] = $row->usr_id;
5080  }
5081 
5082  return $ids;
5083  }
5084 
5093  public static function _getUserIdsByInactivationPeriod($period)
5094  {
5096  $field = 'inactivation_date';
5098 
5099  if( !(int)$period ) throw new ilException('no valid period given');
5100 
5101  global $ilDB;
5102 
5103  $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5104 
5105  $query = "SELECT usr_id FROM usr_data WHERE $field < %s AND active = %s";
5106 
5107  $res = $ilDB->queryF($query, array('timestamp', 'integer'), array($date, 0));
5108 
5109  $ids = array();
5110  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
5111  {
5112  $ids[] = $row->usr_id;
5113  }
5114 
5115  return $ids;
5116  }
5117 
5127  public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5128  {
5129  if($a_last_login !== null) $last_login = $a_last_login;
5130  else $last_login = date('Y-m-d H:i:s');
5131 
5132  global $ilDB;
5133 
5134  $query = "UPDATE usr_data SET last_login = %s WHERE usr_id = %s";
5135  $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array($last_login, $a_usr_id) );
5136 
5137  if($affected) return $last_login;
5138  else return false;
5139  }
5140 
5141  public function resetOwner()
5142  {
5143  global $ilDB;
5144 
5145  $query = "UPDATE object_data SET owner = 0 ".
5146  "WHERE owner = ".$ilDB->quote($this->getId(),'integer');
5147  $ilDB->query($query);
5148 
5149  return true;
5150  }
5151 
5152 
5159  static function getFirstLettersOfLastnames()
5160  {
5161  global $ilDB;
5162 
5163  $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("lastname", 1, 1))." let".
5164  " FROM usr_data".
5165  " WHERE usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer").
5166  " ORDER BY let";
5167  $let_set = $ilDB->query($q);
5168 
5169  $lets = array();
5170  while ($let_rec = $ilDB->fetchAssoc($let_set))
5171  {
5172  $let[$let_rec["let"]] = $let_rec["let"];
5173  }
5174  return $let;
5175  }
5176 
5177  // begin-patch deleteProgress
5178  public static function userExists($a_usr_ids = array())
5179  {
5180  global $ilDB;
5181 
5182  $query = 'SELECT count(*) num FROM object_data od '.
5183  'JOIN usr_data ud ON obj_id = usr_id '.
5184  'WHERE '.$ilDB->in('obj_id',$a_usr_ids,false,'integer').' ';
5185  $res = $ilDB->query($query);
5186  $num_rows =$res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)->num;
5187  return $num_rows == count((array) $a_usr_ids);
5188  }
5189  // end-patch deleteProgress
5190 
5195  {
5196  return (boolean) $_SESSION["user_captcha_verified"];
5197  }
5198 
5204  function setCaptchaVerified($a_val)
5205  {
5206  $_SESSION["user_captcha_verified"] = $a_val;
5207  }
5208 
5216  {
5217  include_once("./Services/Export/classes/class.ilExport.php");
5218  $exp = new ilExport();
5219  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5220  ilUtil::delDir($dir, true);
5221  $title = $this->getLastname().", ".$this->getLastname()." [".$this->getLogin()."]";
5222  $exp->exportEntity("personal_data", $this->getId(), "",
5223  "Services/User", $title, $dir);
5224  }
5225 
5233  {
5234  include_once("./Services/Export/classes/class.ilExport.php");
5235  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5236  if (!is_dir($dir))
5237  {
5238  return "";
5239  }
5240  foreach(ilUtil::getDir($dir) as $entry)
5241  {
5242  if (is_int(strpos($entry["entry"], ".zip")))
5243  {
5244  return $entry["entry"];
5245  }
5246  }
5247 
5248  return "";
5249  }
5250 
5258  {
5259  include_once("./Services/Export/classes/class.ilExport.php");
5260  $file = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data").
5261  "/".$this->getPersonalDataExportFile();
5262  if (is_file($file))
5263  {
5265  }
5266  }
5267 
5274  function importPersonalData($a_file, $a_profile_data, $a_settings,
5275  $a_bookmarks, $a_notes, $a_calendar)
5276  {
5277  include_once("./Services/Export/classes/class.ilImport.php");
5278  $imp = new ilImport();
5279  if (!$a_profile_data)
5280  {
5281  $imp->addSkipEntity("Services/User", "usr_profile");
5282  }
5283  if (!$a_settings)
5284  {
5285  $imp->addSkipEntity("Services/User", "usr_setting");
5286  }
5287  if (!$a_bookmarks)
5288  {
5289  $imp->addSkipEntity("Services/Bookmarks", "bookmarks");
5290  }
5291  if (!$a_notes)
5292  {
5293  $imp->addSkipEntity("Services/Notes", "user_notes");
5294  }
5295  if (!$a_calendar)
5296  {
5297  $imp->addSkipEntity("Services/Calendar", "calendar");
5298  }
5299  $imp->importEntity($a_file["tmp_name"], $a_file["name"], "personal_data",
5300  "Services/User");
5301  }
5302 
5308  private static function initInactivationDate($usrIds)
5309  {
5310  global $ilDB;
5311 
5312  $NOW = $ilDB->now();
5313 
5314  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5315 
5316  $queryString = "
5317  UPDATE usr_data
5318  SET inactivation_date = $NOW
5319  WHERE inactivation_date IS NULL
5320  AND $usrId_IN_usrIds
5321  ";
5322 
5323  $ilDB->manipulate($queryString);
5324  }
5325 
5331  private static function resetInactivationDate($usrIds)
5332  {
5333  global $ilDB;
5334 
5335  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5336 
5337  $queryString = "
5338  UPDATE usr_data
5339  SET inactivation_date = NULL
5340  WHERE $usrId_IN_usrIds
5341  ";
5342 
5343  $ilDB->manipulate($queryString);
5344  }
5345 
5352  {
5353  $this->inactivation_date = $inactivation_date;
5354  }
5355 
5361  public function getInactivationDate()
5362  {
5363  return $this->inactivation_date;
5364  }
5365 
5369  public function hasToAcceptTermsOfService()
5370  {
5371  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5372 
5373  if(
5375  null == $this->agree_date &&
5376  'root' != $this->login &&
5377  !in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID))
5378  )
5379  {
5380  return true;
5381  }
5382 
5383  return false;
5384  }
5385 
5390  public static function hasUserToAcceptTermsOfService($a_username)
5391  {
5395  global $ilDB;
5396 
5397  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5398 
5400  {
5401  return false;
5402  }
5403 
5404  $in = $ilDB->in('usr_id', array(ANONYMOUS_USER_ID, SYSTEM_USER_ID), true, 'integer');
5405  $res = $ilDB->queryF(
5406  "SELECT usr_id FROM usr_data WHERE login = %s AND agree_date IS NULL $in",
5407  array("text"),
5408  array($a_username)
5409  );
5410  return $ilDB->fetchAssoc($res) ? true : false;
5411  }
5412 
5420  public static function getUsersAgreed($a_agreed = true, $a_users = null)
5421  {
5422  global $ilDB;
5423 
5424  $date_is = ($a_agreed)
5425  ? "IS NOT NULL"
5426  : "IS NULL";
5427 
5428  $users = (is_array($a_users))
5429  ? " AND ".$ilDB->in("usr_id", $a_users, false, "integer")
5430  : "";
5431 
5432  $set = $ilDB->query("SELECT usr_id FROM usr_data ".
5433  " WHERE agree_date ".$date_is.
5434  $users);
5435  $ret = array();
5436  while ($rec = $ilDB->fetchAssoc($set))
5437  {
5438  $ret[] = $rec["usr_id"];
5439  }
5440  return $ret;
5441  }
5442 
5443 
5448  public function hasToAcceptTermsOfServiceInSession($status = null)
5449  {
5450  if(null === $status)
5451  {
5452  return ilSession::get('has_to_accept_agr_in_session');
5453  }
5454 
5455  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5457  {
5458  ilSession::set('has_to_accept_agr_in_session', (int)$status);
5459  }
5460  }
5461 
5465  public function isAnonymous()
5466  {
5467  return self::_isAnonymous($this->getId());
5468  }
5469 
5474  public static function _isAnonymous($usr_id)
5475  {
5476  return $usr_id == ANONYMOUS_USER_ID;
5477  }
5478 
5479  public function activateDeletionFlag()
5480  {
5481  $this->writePref("delete_flag", true);
5482  }
5483 
5484  public function removeDeletionFlag()
5485  {
5486  $this->writePref("delete_flag", false);
5487  }
5488 
5489  public function hasDeletionFlag()
5490  {
5491  return (bool)$this->getPref("delete_flag");
5492  }
5493 
5497  public function setIsSelfRegistered($status)
5498  {
5499  $this->is_self_registered = (bool) $status;
5500  }
5501 
5502  public function isSelfRegistered()
5503  {
5504  return (bool) $this->is_self_registered;
5505  }
5506 
5507 
5508  //
5509  // MULTI-TEXT / INTERESTS
5510  //
5511 
5517  public function setGeneralInterests(array $value = null)
5518  {
5519  $this->interests_general = $value;
5520  }
5521 
5527  public function getGeneralInterests()
5528  {
5529  return $this->interests_general;
5530  }
5531 
5537  public function getGeneralInterestsAsText()
5538  {
5539  return $this->buildTextFromArray("interests_general");
5540  }
5541 
5547  public function setOfferingHelp(array $value = null)
5548  {
5549  $this->interests_help_offered = $value;
5550  }
5551 
5557  public function getOfferingHelp()
5558  {
5560  }
5561 
5567  public function getOfferingHelpAsText()
5568  {
5569  return $this->buildTextFromArray("interests_help_offered");
5570  }
5571 
5577  public function setLookingForHelp(array $value = null)
5578  {
5579  $this->interests_help_looking = $value;
5580  }
5581 
5587  public function getLookingForHelp()
5588  {
5590  }
5591 
5597  public function getLookingForHelpAsText()
5598  {
5599  return $this->buildTextFromArray("interests_help_looking");
5600  }
5601 
5608  protected function buildTextFromArray($a_attr)
5609  {
5610  $current = $this->$a_attr;
5611  if(is_array($current) && sizeof($current))
5612  {
5613  return implode(", ", $current);
5614  }
5615  }
5616 
5620  protected function readMultiTextFields()
5621  {
5622  global $ilDB;
5623 
5624  if(!$this->getId())
5625  {
5626  return;
5627  }
5628 
5629  $set = $ilDB->query("SELECT field_id,value".
5630  " FROM usr_data_multi".
5631  " WHERE usr_id = ".$ilDB->quote($this->getId(), "integer").
5632  " ORDER BY value");
5633  while($row = $ilDB->fetchAssoc($set))
5634  {
5635  $values[$row["field_id"]][] = $row["value"];
5636  }
5637 
5638  if(isset($values["interests_general"]))
5639  {
5640  $this->setGeneralInterests($values["interests_general"]);
5641  }
5642  else
5643  {
5644  $this->setGeneralInterests();
5645  }
5646  if(isset($values["interests_help_offered"]))
5647  {
5648  $this->setOfferingHelp($values["interests_help_offered"]);
5649  }
5650  else
5651  {
5652  $this->setOfferingHelp();
5653  }
5654  if(isset($values["interests_help_looking"]))
5655  {
5656  $this->setLookingForHelp($values["interests_help_looking"]);
5657  }
5658  else
5659  {
5660  $this->setLookingForHelp();
5661  }
5662  }
5663 
5669  public function updateMultiTextFields($a_create = false)
5670  {
5671  global $ilDB;
5672 
5673  if(!$this->getId())
5674  {
5675  return;
5676  }
5677 
5678  if(!$a_create)
5679  {
5680  $this->deleteMultiTextFields();
5681  }
5682 
5683  $map = array(
5684  "interests_general" => $this->getGeneralInterests(),
5685  "interests_help_offered" => $this->getOfferingHelp(),
5686  "interests_help_looking" => $this->getLookingForHelp()
5687  );
5688 
5689  foreach($map as $id => $values)
5690  {
5691  if(is_array($values) && sizeof($values))
5692  {
5693  foreach($values as $value)
5694  {
5695  $value = trim($value);
5696  if($value)
5697  {
5698  $uniq_id = $ilDB->nextId('usr_data_multi');
5699 
5700  $ilDB->manipulate("INSERT usr_data_multi".
5701  " (id,usr_id,field_id,value) VALUES".
5702  " (".$ilDB->quote($uniq_id, "integer").
5703  ",".$ilDB->quote($this->getId(), "integer").
5704  ",".$ilDB->quote($id, "text").
5705  ",".$ilDB->quote($value, "text").
5706  ")");
5707  }
5708  }
5709  }
5710  }
5711  }
5712 
5716  protected function deleteMultiTextFields()
5717  {
5718  global $ilDB;
5719 
5720  if(!$this->getId())
5721  {
5722  return;
5723  }
5724 
5725  $ilDB->manipulate("DELETE FROM usr_data_multi".
5726  " WHERE usr_id = ".$ilDB->quote($this->getId(), "integer"));
5727  }
5728 
5729  public static function findInterests($a_term, $a_user_id = null, $a_field_id = null)
5730  {
5731  global $ilDB;
5732 
5733  $res = array();
5734 
5735  $sql = "SELECT DISTINCT(value)".
5736  " FROM usr_data_multi".
5737  " WHERE ".$ilDB->like("value", "text", "%".$a_term."%");
5738  if($a_field_id)
5739  {
5740  $sql .= " AND field_id = ".$ilDB->quote($a_field_id, "text");
5741  }
5742  if($a_user_id)
5743  {
5744  $sql .= " AND usr_id <> ".$ilDB->quote($a_user_id, "integer");
5745  }
5746  $sql .= " ORDER BY value";
5747  $set = $ilDB->query($sql);
5748  while($row = $ilDB->fetchAssoc($set))
5749  {
5750  $res[] = $row["value"];
5751  }
5752 
5753  return $res;
5754  }
5755 } // END class ilObjUser
5756 ?>
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
static getUserIdByLogin($a_login)
static toUsernameWithoutDomain($a_login)
Static function removes Microsoft domain name from username webdav related.
global $ilErr
Definition: raiseError.php:16
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
static _lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
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
static _getNumberOfUsersForStyle($a_skin, $a_style)
skins and styles
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
static _deleteSettingsOfUser($a_user)
Delete block settings of user.
static hasActiveSession($a_user_id, $a_session_id)
Check for simultaneous login.
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
static _getFeedPass($a_user_id)
Lookup news feed password for user.
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="")
static _writePref($a_usr_id, $a_keyword, $a_value)
static _lookupFullname($a_user_id)
Lookup Full Name.
Class for user related exception handling in ILIAS.
setLastLogin($a_str)
set user&#39;s last login public
static _getAllUserData($a_fields=NULL, $active=-1)
STATIC METHOD get all user data.
static _getUsersForClipboadObject($a_type, $a_id)
get all users, that have a certain object within their clipboard
getInactivationDate()
getter for inactivation date
getFax()
get fax public
Class ilObject Basic functions for all objects.
setProfileIncomplete($a_prof_inc)
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)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$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)
static _lookupClientIP($a_user_id)
Lookup client ip.
setLastname($a_str)
set lastame public
getCreateDate()
get create date public
Base class for nested set path based trees.
getLongitude()
Get Longitude.
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)
static _getAuthMode($a_auth_mode, $a_db_handler='')
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.
for($col=0; $col< 50; $col++) $d
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
getOfferingHelpAsText()
Get help offering as plain text.
setTimeLimitUnlimited($a_unlimited)
static styleExistsForSkinId($skin_id, $style_id)
Tree handler for personal workspace.
setPref($a_keyword, $a_value)
set a user preference
static _verifyRegistrationHash($a_hash)
Verifies a registration hash.
static _getImportedUserId($i2_id)
setInactivationDate($inactivation_date)
setter for inactivation date
setZipcode($a_str)
set zipcode public
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...
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...
$a_type
Definition: workflow.php:93
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
static lookupOrgUnitsRepresentation($a_usr_id)
lokup org unit representation
getExternalAccount()
get external account
getCity()
get city public
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
setUserDefinedData($a_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.
static _getLocalAccountsForEmail($a_email)
check whether external account and authentication method matches with a user
$a_content
Definition: workflow.php:94
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 _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.
static _getNumberOfUsersPerAuthMode()
get number of users per auth mode
clipboardDeleteObjectsOfType($a_type)
Delete objects of type for user.
deletePref($a_keyword)
Deletes a userpref value of the user from the database public.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
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
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.
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
$ilUser
Definition: imgupload.php:18
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)
static $is_desktop_item_cache
static _setFeedPass($a_user_id, $a_password)
Set news feed password for user.
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
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static _uploadPersonalPicture($tmp_file, $obj_id)
Create a personal picture image file from a temporary image file.
writePrefs()
write all userprefs private
static _destroyByUserId($a_user_id)
Destroy session.
static skinExists($skin_id, ilSystemStyleConfig $system_style_config=null)
Check whether a skin exists.
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...
Create styles array
The data for the language used.
static deleteEntriesOfUser($a_user_id)
Delete data of user.
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
getPCClipboardContent()
Add a page content item to PC clipboard (should go to another class)
This is the super class of all custom blocks.
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
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)
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)
setFirstname($a_str)
set firstname public
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.
bookmark folder (note: this class handles personal bookmarks folders only)
global $ilSetting
Definition: privfeed.php:17
static resetInactivationDate($usrIds)
type $ilDB
static _lookupEmail($a_user_id)
Lookup email.
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
static getInstance()
Singelton get instance.
static _lookupPref($a_usr_id, $a_keyword)
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 _lookupFeedHash($a_user_id, $a_create=false)
Lookup news feed hash for user.
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
$ret
Definition: parser.php:6
getPhoneHome()
get home phone public
static _getUsersForIds($a_mem_ids, $active=-1, $timelimitowner=-1)
return user data for given user id
static _deleteUser($a_usr_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
const USER_FOLDER_ID
Class ilObjUserFolder.
setLastPasswordChangeToNow()
static findInterests($a_term, $a_user_id=null, $a_field_id=null)
static _getUserIdsByEmail($a_email)
STATIC METHOD get all user_ids of an email address.
setUTitle($a_str)
set user title (note: don&#39;t mix up this method with setTitle() that is derived from ilObject and sets...
global $DIC
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...
static _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
skins and styles
setPasswordEncodingType($password_encryption_type)
static _lookupActive($a_usr_id)
Check user account active.
getStoredActive($a_id)
get user active state
getClipboardChilds($a_parent, $a_insert_time)
Get childs of an item.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static _lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
static _writeAuthMode($a_usr_id, $a_auth_mode)
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
update()
update object in db
setPhoneMobile($a_str)
set mobile phone public
Class for user related exception handling in ILIAS.
static getUsersAgreed($a_agreed=true, $a_users=null)
Get users that have or have not agreed to the user agreement.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
getClientIP()
get client ip number public
static deleteByUserId($a_user_id)
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.
static _writeExternalAccount($a_usr_id, $a_ext_id)
hasPublicProfile()
returns true if public is profile, false otherwise
static _getAllUserAssignedStyles()
skins and styles
static _doesLoginnameExistInHistory($a_login)
Checks wether the passed loginname already exists in history.
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
static _deleteAllPref($a_user_id)
Deletes a userpref value of the user from the database public.
importPersonalData($a_file, $a_profile_data, $a_settings, $a_bookmarks, $a_notes, $a_calendar)
Import personal data.
static _deleteUser($a_usr_id)
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
readPrefs()
get all user preferences private
getPhoneMobile()
get mobile phone public
static _lookupLastLogin($a_user_id)
lookup last login