ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjUser.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
5 
6 define("IL_PASSWD_PLAIN", "plain");
7 define("IL_PASSWD_CRYPTED", "crypted");
8 
9 
10 require_once "./Services/Object/classes/class.ilObject.php";
11 require_once './Services/User/exceptions/class.ilUserException.php';
12 require_once './Modules/OrgUnit/classes/class.ilObjOrgUnit.php';
13 require_once './Modules/OrgUnit/classes/class.ilObjOrgUnitTree.php';
14 
27 class ilObjUser extends ilObject
28 {
33  // personal data
34 
35  public $login; // username in system
36 
40  protected $passwd; // password encoded in the format specified by $passwd_type
41 
45  protected $passwd_type;
46  // specifies the password format.
47  // value: IL_PASSWD_PLAIN or IL_PASSWD_CRYPTED.
48 
49  // Differences between password format in class ilObjUser and
50  // in table usr_data:
51  // Class ilObjUser supports two different password types
52  // (plain and crypted) and it uses the variables $passwd
53  // and $passwd_type to store them.
54  // Table usr_data supports only two different password types
55  // (md5 and bcrypt) and it uses the columns "passwd" and "passwd_type" to store them.
56  // The conversion between these two storage layouts is done
57  // in the methods that perform SQL statements. All other
58  // methods work exclusively with the $passwd and $passwd_type
59  // variables.
60 
66 
71  protected $password_salt = null;
72 
73  public $gender; // 'm' or 'f'
74  public $utitle; // user title (keep in mind, that we derive $title from object also!)
75  public $firstname;
76  public $lastname;
77  protected $birthday;
78  public $fullname; // title + firstname + lastname in one string
79  //var $archive_dir = "./image"; // point to image file (should be flexible)
80  // address data
81  public $institution;
82  public $department;
83  public $street;
84  public $city;
85  public $zipcode;
86  public $country;
87  public $sel_country;
88  public $phone_office;
89  public $phone_home;
90  public $phone_mobile;
91  public $fax;
92  public $email;
93  protected $second_email = null;
94  public $hobby;
97  public $approve_date = null;
98  public $agree_date = null;
99  public $active;
100  public $client_ip; // client ip to check before login
101  public $auth_mode; // authentication mode
102 
103  public $latitude;
104  public $longitude;
105  public $loc_zoom;
106 
108  protected $passwd_policy_reset = false;
110 
111  public $user_defined_data = array();
112 
118  public $prefs;
119 
125  public $skin;
126 
127 
134 
140  public $ilias;
141 
142  public static $is_desktop_item_loaded;
143  public static $is_desktop_item_cache;
144 
148  protected static $personal_image_cache = array();
149 
155  protected $inactivation_date = null;
156 
161  private $is_self_registered = false;
162 
167  protected $org_units;
168 
169  protected $interests_general; // [array]
170  protected $interests_help_offered; // [array]
171  protected $interests_help_looking; // [array]
172 
176  protected $last_profile_prompt; // timestamp
177 
181  protected $first_login; // timestamp
182 
183 
189  public function __construct($a_user_id = 0, $a_call_by_reference = false)
190  {
191  global $DIC;
192 
193  $ilias = $DIC['ilias'];
194  $ilDB = $DIC['ilDB'];
195 
196  // init variables
197  $this->ilias = &$ilias;
198  $this->db = &$ilDB;
199 
200  $this->type = "usr";
201  parent::__construct($a_user_id, $a_call_by_reference);
202  $this->auth_mode = "default";
203  $this->passwd_type = IL_PASSWD_PLAIN;
204 
205  // for gender selection. don't change this
206  /*$this->gender = array(
207  'n' => "salutation_n",
208  'm' => "salutation_m",
209  'f' => "salutation_f"
210  );*/
211  if ($a_user_id > 0) {
212  $this->setId($a_user_id);
213  $this->read();
214  } else {
215  // TODO: all code in else-structure doesn't belongs in class user !!!
216  //load default data
217  $this->prefs = array();
218  //language
219  $this->prefs["language"] = $this->ilias->ini->readVariable("language", "default");
220 
221  //skin and pda support
222  $this->skin = $this->ilias->ini->readVariable("layout", "skin");
223 
224  $this->prefs["skin"] = $this->skin;
225  // $this->prefs["show_users_online"] = "y";
226 
227  //style (css)
228  $this->prefs["style"] = $this->ilias->ini->readVariable("layout", "style");
229  }
230  }
231 
236  public function read()
237  {
238  global $DIC;
239 
240  $ilErr = $DIC['ilErr'];
241  $ilDB = $DIC['ilDB'];
242 
243  // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
244  // use (3.11.0 alpha)
245  /*$q = "SELECT * FROM usr_data ".
246  "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
247  "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
248  $r = $ilDB->queryF("SELECT * FROM usr_data " .
249  "WHERE usr_id= %s", array("integer"), array($this->id));
250 
251  if ($data = $ilDB->fetchAssoc($r)) {
252  // convert password storage layout used by table usr_data into
253  // storage layout used by class ilObjUser
254  $data["passwd_type"] = IL_PASSWD_CRYPTED;
255 
256  // this assign must not be set via $this->assignData($data)
257  // because this method will be called on profile updates and
258  // would set this values to 0, because they arent posted from form
259  $this->setLastPasswordChangeTS($data['last_password_change']);
260  $this->setLoginAttempts($data['login_attempts']);
261  $this->setPasswordPolicyResetStatus((bool) $data['passwd_policy_reset']);
262 
263 
264  // fill member vars in one shot
265  $this->assignData($data);
266 
267  //get userpreferences from usr_pref table
268  $this->readPrefs();
269 
270  //set language to default if not set
271  if ($this->prefs["language"] == "") {
272  $this->prefs["language"] = $this->oldPrefs["language"];
273  }
274 
275  //check skin-setting
276  include_once("./Services/Style/System/classes/class.ilStyleDefinition.php");
277  if ($this->prefs["skin"] == "" ||
278  !ilStyleDefinition::skinExists($this->prefs["skin"])) {
279  $this->prefs["skin"] = $this->oldPrefs["skin"];
280  }
281 
282  $this->skin = $this->prefs["skin"];
283 
284  //check style-setting (skins could have more than one stylesheet
285  if ($this->prefs["style"] == "" ||
286  (!ilStyleDefinition::skinExists($this->skin) && ilStyleDefinition::styleExistsForSkinId($this->skin, $this->prefs["style"])) ||
287  !ilStyleDefinition::styleExists($this->prefs["style"])) {
288  //load default (css)
289  $this->prefs["style"] = $this->ilias->ini->readVariable("layout", "style");
290  }
291 
292  if (empty($this->prefs["hits_per_page"])) {
293  $this->prefs["hits_per_page"] = 10;
294  }
295  } else {
296  $ilErr->raiseError("<b>Error: There is no dataset with id " .
297  $this->id . "!</b><br />class: " . get_class($this) . "<br />Script: " . __FILE__ .
298  "<br />Line: " . __LINE__, $ilErr->FATAL);
299  }
300 
301  $this->readMultiTextFields();
302  $this->readUserDefinedFields();
303 
304  parent::read();
305  }
306 
310  public function getPasswordEncodingType()
311  {
313  }
314 
318  public function setPasswordEncodingType($password_encryption_type)
319  {
320  $this->password_encoding_type = $password_encryption_type;
321  }
322 
326  public function getPasswordSalt()
327  {
328  return $this->password_salt;
329  }
330 
335  {
336  $this->password_salt = $password_salt;
337  }
338 
344  public function assignData($a_data)
345  {
346  global $DIC;
347 
348  $ilErr = $DIC['ilErr'];
349  $ilDB = $DIC['ilDB'];
350  $lng = $DIC['lng'];
351 
352  // basic personal data
353  $this->setLogin($a_data["login"]);
354  if (!$a_data["passwd_type"]) {
355  $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). " .
356  $this->id . "!</b><br />class: " . get_class($this) . "<br />Script: "
357  . __FILE__ . "<br />Line: " . __LINE__, $ilErr->FATAL);
358  }
359  if ($a_data["passwd"] != "********" and strlen($a_data['passwd'])) {
360  $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
361  }
362 
363  $this->setGender($a_data["gender"]);
364  $this->setUTitle($a_data["title"]);
365  $this->setFirstname($a_data["firstname"]);
366  $this->setLastname($a_data["lastname"]);
367  $this->setFullname();
368  if (!is_array($a_data['birthday'])) {
369  $this->setBirthday($a_data['birthday']);
370  } else {
371  $this->setBirthday(null);
372  }
373 
374  // address data
375  $this->setInstitution($a_data["institution"]);
376  $this->setDepartment($a_data["department"]);
377  $this->setStreet($a_data["street"]);
378  $this->setCity($a_data["city"]);
379  $this->setZipcode($a_data["zipcode"]);
380  $this->setCountry($a_data["country"]);
381  $this->setSelectedCountry($a_data["sel_country"]);
382  $this->setPhoneOffice($a_data["phone_office"]);
383  $this->setPhoneHome($a_data["phone_home"]);
384  $this->setPhoneMobile($a_data["phone_mobile"]);
385  $this->setFax($a_data["fax"]);
386  $this->setMatriculation($a_data["matriculation"]);
387  $this->setEmail($a_data["email"]);
388  $this->setSecondEmail($a_data["second_email"]);
389  $this->setHobby($a_data["hobby"]);
390  $this->setClientIP($a_data["client_ip"]);
391  $this->setPasswordEncodingType($a_data['passwd_enc_type']);
392  $this->setPasswordSalt($a_data['passwd_salt']);
393 
394  // other data
395  $this->setLatitude($a_data["latitude"]);
396  $this->setLongitude($a_data["longitude"]);
397  $this->setLocationZoom($a_data["loc_zoom"]);
398 
399  // system data
400  $this->setLastLogin($a_data["last_login"]);
401  $this->setFirstLogin($a_data["first_login"]);
402  $this->setLastProfilePrompt($a_data["last_profile_prompt"]);
403  $this->setLastUpdate($a_data["last_update"]);
404  $this->create_date = $a_data["create_date"];
405  $this->setComment($a_data["referral_comment"]);
406  $this->approve_date = $a_data["approve_date"];
407  $this->active = $a_data["active"];
408  $this->agree_date = $a_data["agree_date"];
409 
410  $this->setInactivationDate($a_data["inactivation_date"]);
411 
412  // time limitation
413  $this->setTimeLimitOwner($a_data["time_limit_owner"]);
414  $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
415  $this->setTimeLimitFrom($a_data["time_limit_from"]);
416  $this->setTimeLimitUntil($a_data["time_limit_until"]);
417  $this->setTimeLimitMessage($a_data['time_limit_message']);
418 
419  // user profile incomplete?
420  $this->setProfileIncomplete($a_data["profile_incomplete"]);
421 
422  //authentication
423  $this->setAuthMode($a_data['auth_mode']);
424  $this->setExternalAccount($a_data['ext_account']);
425 
426  $this->setIsSelfRegistered((bool) $a_data['is_self_registered']);
427  }
428 
435  public function saveAsNew($a_from_formular = true)
436  {
437  global $DIC;
438 
439  $ilAppEventHandler = $DIC['ilAppEventHandler'];
440 
445  global $DIC;
446 
447  $ilErr = $DIC['ilErr'];
448  $ilDB = $DIC['ilDB'];
449 
450  switch ($this->passwd_type) {
451  case IL_PASSWD_PLAIN:
452  if (strlen($this->passwd)) {
453  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
454  ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
455  $pw_value = $this->getPasswd();
456  } else {
457  $pw_value = $this->passwd;
458  }
459  break;
460 
461  case IL_PASSWD_CRYPTED:
462  $pw_value = $this->passwd;
463  break;
464 
465  default:
466  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. " .
467  $this->id . "!</b><br />class: " . get_class($this) . "<br />Script: " . __FILE__ .
468  "<br />Line: " . __LINE__, $ilErr->FATAL);
469  }
470 
471  if (!$this->active) {
473  } else {
474  $this->setInactivationDate(null);
475  }
476 
477  $insert_array = array(
478  "usr_id" => array("integer", $this->id),
479  "login" => array("text", $this->login),
480  "passwd" => array("text", $pw_value),
481  'passwd_enc_type' => array("text", $this->getPasswordEncodingType()),
482  'passwd_salt' => array("text", $this->getPasswordSalt()),
483  "firstname" => array("text", $this->firstname),
484  "lastname" => array("text", $this->lastname),
485  "title" => array("text", $this->utitle),
486  "gender" => array("text", $this->gender),
487  "email" => array("text", trim($this->email)),
488  "second_email" => array("text", trim($this->second_email)),
489  "hobby" => array("text", (string) $this->hobby),
490  "institution" => array("text", $this->institution),
491  "department" => array("text", $this->department),
492  "street" => array("text", $this->street),
493  "city" => array("text", $this->city),
494  "zipcode" => array("text", $this->zipcode),
495  "country" => array("text", $this->country),
496  "sel_country" => array("text", $this->sel_country),
497  "phone_office" => array("text", $this->phone_office),
498  "phone_home" => array("text", $this->phone_home),
499  "phone_mobile" => array("text", $this->phone_mobile),
500  "fax" => array("text", $this->fax),
501  "birthday" => array('date', $this->getBirthday()),
502  "last_login" => array("timestamp", null),
503  "first_login" => array("timestamp", null),
504  "last_profile_prompt" => array("timestamp", null),
505  "last_update" => array("timestamp", ilUtil::now()),
506  "create_date" => array("timestamp", ilUtil::now()),
507  "referral_comment" => array("text", $this->referral_comment),
508  "matriculation" => array("text", $this->matriculation),
509  "client_ip" => array("text", $this->client_ip),
510  "approve_date" => array("timestamp", $this->approve_date),
511  "agree_date" => array("timestamp", $this->agree_date),
512  "active" => array("integer", (int) $this->active),
513  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
514  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
515  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
516  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
517  "auth_mode" => array("text", $this->getAuthMode()),
518  "ext_account" => array("text", $this->getExternalAccount()),
519  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
520  "latitude" => array("text", $this->latitude),
521  "longitude" => array("text", $this->longitude),
522  "loc_zoom" => array("integer", (int) $this->loc_zoom),
523  "last_password_change" => array("integer", (int) $this->last_password_change_ts),
524  "passwd_policy_reset" => array("integer", (int) $this->passwd_policy_reset),
525  'inactivation_date' => array('timestamp', $this->inactivation_date),
526  'is_self_registered' => array('integer', (int) $this->is_self_registered),
527  );
528  $ilDB->insert("usr_data", $insert_array);
529 
530  $this->updateMultiTextFields(true);
531 
532  // add new entry in usr_defined_data
533  $this->addUserDefinedFieldEntry();
534  // ... and update
535  $this->updateUserDefinedFields();
536 
537  // CREATE ENTRIES FOR MAIL BOX
538  include_once("Services/Mail/classes/class.ilMailbox.php");
539  $mbox = new ilMailbox($this->id);
540  $mbox->createDefaultFolder();
541 
542  include_once "Services/Mail/classes/class.ilMailOptions.php";
543  $mail_options = new ilMailOptions($this->id);
544  $mail_options->createMailOptionsEntry();
545 
546 
547  $ilAppEventHandler->raise(
548  "Services/User",
549  "afterCreate",
550  array("user_obj" => $this)
551  );
552  }
553 
557  public function update()
558  {
564  global $DIC;
565 
566  $ilErr = $DIC['ilErr'];
567  $ilDB = $DIC['ilDB'];
568  $ilAppEventHandler = $DIC['ilAppEventHandler'];
569 
570  $this->syncActive();
571 
572  if ($this->getStoredActive($this->id) && !$this->active) {
574  } elseif ($this->active) {
575  $this->setInactivationDate(null);
576  }
577 
578  $update_array = array(
579  "gender" => array("text", $this->gender),
580  "title" => array("text", $this->utitle),
581  "firstname" => array("text", $this->firstname),
582  "lastname" => array("text", $this->lastname),
583  "email" => array("text", trim($this->email)),
584  "second_email" => array("text", trim($this->second_email)),
585  "birthday" => array('date', $this->getBirthday()),
586  "hobby" => array("text", $this->hobby),
587  "institution" => array("text", $this->institution),
588  "department" => array("text", $this->department),
589  "street" => array("text", $this->street),
590  "city" => array("text", $this->city),
591  "zipcode" => array("text", $this->zipcode),
592  "country" => array("text", $this->country),
593  "sel_country" => array("text", $this->sel_country),
594  "phone_office" => array("text", $this->phone_office),
595  "phone_home" => array("text", $this->phone_home),
596  "phone_mobile" => array("text", $this->phone_mobile),
597  "fax" => array("text", $this->fax),
598  "referral_comment" => array("text", $this->referral_comment),
599  "matriculation" => array("text", $this->matriculation),
600  "client_ip" => array("text", $this->client_ip),
601  "approve_date" => array("timestamp", $this->approve_date),
602  "active" => array("integer", $this->active),
603  "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
604  "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
605  "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
606  "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
607  "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
608  "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
609  "auth_mode" => array("text", $this->getAuthMode()),
610  "ext_account" => array("text", $this->getExternalAccount()),
611  "latitude" => array("text", $this->latitude),
612  "longitude" => array("text", $this->longitude),
613  "loc_zoom" => array("integer", (int) $this->loc_zoom),
614  "last_password_change" => array("integer", $this->last_password_change_ts),
615  "passwd_policy_reset" => array("integer", $this->passwd_policy_reset),
616  "last_update" => array("timestamp", ilUtil::now()),
617  'inactivation_date' => array('timestamp', $this->inactivation_date)
618  );
619 
620  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null)) {
621  $update_array["agree_date"] = array("timestamp", $this->agree_date);
622  }
623  switch ($this->passwd_type) {
624  case IL_PASSWD_PLAIN:
625  if (strlen($this->passwd)) {
626  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
627  ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
628  $update_array['passwd'] = array('text', $this->getPasswd());
629  } else {
630  $update_array["passwd"] = array("text", (string) $this->passwd);
631  }
632  break;
633 
634  case IL_PASSWD_CRYPTED:
635  $update_array["passwd"] = array("text", (string) $this->passwd);
636  break;
637 
638  default:
639  $ilErr->raiseError("<b>Error: passwd_type missing in function update()" . $this->id . "!</b><br />class: " .
640  get_class($this) . "<br />Script: " . __FILE__ . "<br />Line: " . __LINE__, $ilErr->FATAL);
641  }
642 
643  $update_array['passwd_enc_type'] = array('text', $this->getPasswordEncodingType());
644  $update_array['passwd_salt'] = array('text', $this->getPasswordSalt());
645 
646  $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
647 
648  $this->updateMultiTextFields();
649 
650  $this->writePrefs();
651 
652  // update user defined fields
653  $this->updateUserDefinedFields();
654 
655  parent::update();
656  parent::updateOwner();
657 
658  $this->read();
659 
660  $ilAppEventHandler->raise(
661  "Services/User",
662  "afterUpdate",
663  array("user_obj" => $this)
664  );
665 
666  return true;
667  }
668 
672  public function writeAccepted()
673  {
674  global $DIC;
675 
676  $ilDB = $DIC['ilDB'];
677 
678  $ilDB->manipulateF("UPDATE usr_data SET agree_date = " . $ilDB->now() .
679  " WHERE usr_id = %s", array("integer"), array($this->getId()));
680  }
681 
685  private static function _lookup($a_user_id, $a_field)
686  {
687  global $DIC;
688 
689  $ilDB = $DIC['ilDB'];
690 
691  $res = $ilDB->queryF(
692  "SELECT " . $a_field . " FROM usr_data WHERE usr_id = %s",
693  array("integer"),
694  array($a_user_id)
695  );
696 
697  while ($set = $ilDB->fetchAssoc($res)) {
698  return $set[$a_field];
699  }
700  return false;
701  }
702 
706  public static function _lookupFullname($a_user_id)
707  {
708  global $DIC;
709 
710  $ilDB = $DIC['ilDB'];
711 
712  $set = $ilDB->queryF(
713  "SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
714  array("integer"),
715  array($a_user_id)
716  );
717 
718  if ($rec = $ilDB->fetchAssoc($set)) {
719  if ($rec["title"]) {
720  $fullname = $rec["title"] . " ";
721  }
722  if ($rec["firstname"]) {
723  $fullname .= $rec["firstname"] . " ";
724  }
725  if ($rec["lastname"]) {
726  $fullname .= $rec["lastname"];
727  }
728  }
729  return $fullname;
730  }
731 
735  public static function _lookupEmail($a_user_id)
736  {
737  return ilObjUser::_lookup($a_user_id, "email");
738  }
739 
745  public static function _lookupSecondEmail($a_user_id)
746  {
747  return ilObjUser::_lookup($a_user_id, "second_email");
748  }
749 
753  public static function _lookupGender($a_user_id)
754  {
755  return ilObjUser::_lookup($a_user_id, "gender");
756  }
757 
764  public static function _lookupClientIP($a_user_id)
765  {
766  return ilObjUser::_lookup($a_user_id, "client_ip");
767  }
768 
769 
775  public static function _lookupName($a_user_id)
776  {
777  global $DIC;
778 
779  $ilDB = $DIC['ilDB'];
780 
781  $res = $ilDB->queryF(
782  "SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
783  array("integer"),
784  array($a_user_id)
785  );
786  $user_rec = $ilDB->fetchAssoc($res);
787  return array("user_id" => $a_user_id,
788  "firstname" => $user_rec["firstname"],
789  "lastname" => $user_rec["lastname"],
790  "title" => $user_rec["title"],
791  "login" => $user_rec["login"]);
792  }
793 
797  public static function _lookupFields($a_user_id)
798  {
799  global $DIC;
800 
801  $ilDB = $DIC['ilDB'];
802 
803  $res = $ilDB->queryF(
804  "SELECT * FROM usr_data WHERE usr_id = %s",
805  array("integer"),
806  array($a_user_id)
807  );
808  $user_rec = $ilDB->fetchAssoc($res);
809  return $user_rec;
810  }
811 
815  public static function _lookupLogin($a_user_id)
816  {
817  return ilObjUser::_lookup($a_user_id, "login");
818  }
819 
823  public static function _lookupExternalAccount($a_user_id)
824  {
825  return ilObjUser::_lookup($a_user_id, "ext_account");
826  }
827 
831  public static function _lookupId($a_user_str)
832  {
833  global $DIC;
834 
835  $ilDB = $DIC['ilDB'];
836 
837  if (!is_array($a_user_str)) {
838  $res = $ilDB->queryF(
839  "SELECT usr_id FROM usr_data WHERE login = %s",
840  array("text"),
841  array($a_user_str)
842  );
843  $user_rec = $ilDB->fetchAssoc($res);
844  return $user_rec["usr_id"];
845  } else {
846  $set = $ilDB->query(
847  "SELECT usr_id FROM usr_data " .
848  " WHERE " . $ilDB->in("login", $a_user_str, false, "text")
849  );
850  $ids = array();
851  while ($rec = $ilDB->fetchAssoc($set)) {
852  $ids[] = $rec["usr_id"];
853  }
854  return $ids;
855  }
856  }
857 
861  public static function _lookupLastLogin($a_user_id)
862  {
863  return ilObjUser::_lookup($a_user_id, "last_login");
864  }
865 
869  public static function _lookupFirstLogin($a_user_id)
870  {
871  return ilObjUser::_lookup($a_user_id, "first_login");
872  }
873 
874 
880  public function refreshLogin()
881  {
882  global $DIC;
883 
884  $ilDB = $DIC['ilDB'];
885 
886  $ilDB->manipulateF(
887  "UPDATE usr_data SET " .
888  "last_login = " . $ilDB->now() .
889  " WHERE usr_id = %s",
890  array("integer"),
891  array($this->id)
892  );
893 
894  if ($this->getFirstLogin() == "") {
895  $ilDB->manipulateF(
896  "UPDATE usr_data SET " .
897  "first_login = " . $ilDB->now() .
898  " WHERE usr_id = %s",
899  array("integer"),
900  array($this->id)
901  );
902  }
903  }
904 
905 
913  public function resetPassword($raw, $raw_retype)
914  {
918  global $DIC;
919 
920  $ilDB = $DIC['ilDB'];
921 
922  if (func_num_args() != 2) {
923  return false;
924  }
925 
926  if (!isset($raw) || !isset($raw_retype)) {
927  return false;
928  }
929 
930  if ($raw != $raw_retype) {
931  return false;
932  }
933 
934  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
935  ilUserPasswordManager::getInstance()->encodePassword($this, $raw);
936 
937  $ilDB->manipulateF(
938  'UPDATE usr_data
939  SET passwd = %s, passwd_enc_type = %s, passwd_salt = %s
940  WHERE usr_id = %s',
941  array('text', 'text', 'text', 'integer'),
942  array($this->getPasswd(), $this->getPasswordEncodingType(), $this->getPasswordSalt(), $this->getId())
943  );
944 
945  return true;
946  }
947 
958  public static function _doesLoginnameExistInHistory($a_login)
959  {
960  global $DIC;
961 
962  $ilDB = $DIC['ilDB'];
963 
964  $res = $ilDB->queryF(
965  '
966  SELECT * FROM loginname_history
967  WHERE login = %s',
968  array('text'),
969  array($a_login)
970  );
971 
972  return $ilDB->fetchAssoc($res) ? true : false;
973  }
974 
987  public static function _getLastHistoryDataByUserId($a_usr_id)
988  {
989  global $DIC;
990 
991  $ilDB = $DIC['ilDB'];
992 
993  $ilDB->setLimit(1, 0);
994  $res = $ilDB->queryF(
995  '
996  SELECT login, history_date FROM loginname_history
997  WHERE usr_id = %s ORDER BY history_date DESC',
998  array('integer'),
999  array($a_usr_id)
1000  );
1001  $row = $ilDB->fetchAssoc($res);
1002  if (!is_array($row) || !count($row)) {
1003  throw new ilUserException('');
1004  }
1005 
1006  return array(
1007  $row['login'], $row['history_date']
1008  );
1009  }
1010 
1018  public function updateLogin($a_login)
1019  {
1020  global $DIC;
1021 
1022  $ilDB = $DIC['ilDB'];
1023  $ilSetting = $DIC['ilSetting'];
1024 
1025  if (func_num_args() != 1) {
1026  return false;
1027  }
1028 
1029  if (!isset($a_login)) {
1030  return false;
1031  }
1032 
1033  $former_login = self::_lookupLogin($this->getId());
1034 
1035  // Update not necessary
1036  if (0 == strcmp($a_login, $former_login)) {
1037  return false;
1038  }
1039 
1040  try {
1041  $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1042  } catch (ilUserException $e) {
1043  $last_history_entry = null;
1044  }
1045 
1046  // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1047  if ((int) $ilSetting->get('allow_change_loginname') &&
1048  (int) $ilSetting->get('reuse_of_loginnames') == 0 &&
1049  self::_doesLoginnameExistInHistory($a_login)) {
1050  throw new ilUserException($this->lng->txt('loginname_already_exists'));
1051  } elseif ((int) $ilSetting->get('allow_change_loginname') &&
1052  (int) $ilSetting->get('loginname_change_blocking_time') &&
1053  is_array($last_history_entry) &&
1054  $last_history_entry[1] + (int) $ilSetting->get('loginname_change_blocking_time') > time()) {
1055  include_once 'Services/Calendar/classes/class.ilDate.php';
1056  throw new ilUserException(
1057  sprintf(
1058  $this->lng->txt('changing_loginname_not_possible_info'),
1060  new ilDateTime($last_history_entry[1], IL_CAL_UNIX)
1061  ),
1063  new ilDateTime(($last_history_entry[1] + (int) $ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX)
1064  )
1065  )
1066  );
1067  } else {
1068  // log old loginname in history
1069  if ((int) $ilSetting->get('allow_change_loginname') &&
1070  (int) $ilSetting->get('create_history_loginname')) {
1071  ilObjUser::_writeHistory($this->getId(), $former_login);
1072  }
1073 
1074  //update login
1075  $this->login = $a_login;
1076 
1077  $ilDB->manipulateF(
1078  '
1079  UPDATE usr_data
1080  SET login = %s
1081  WHERE usr_id = %s',
1082  array('text', 'integer'),
1083  array($this->getLogin(), $this->getId())
1084  );
1085  }
1086 
1087  return true;
1088  }
1089 
1096  public function writePref($a_keyword, $a_value)
1097  {
1098  self::_writePref($this->id, $a_keyword, $a_value);
1099  $this->setPref($a_keyword, $a_value);
1100  }
1101 
1102 
1108  public function deletePref($a_keyword)
1109  {
1110  self::_deletePref($this->getId(), $a_keyword);
1111  }
1112 
1118  public static function _deletePref($a_user_id, $a_keyword)
1119  {
1123  global $DIC;
1124 
1125  $ilDB = $DIC['ilDB'];
1126 
1127  $ilDB->manipulateF(
1128  'DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s',
1129  array('integer', 'text'),
1130  array($a_user_id, $a_keyword)
1131  );
1132  }
1133 
1139  public static function _deleteAllPref($a_user_id)
1140  {
1141  global $DIC;
1142 
1143  $ilDB = $DIC['ilDB'];
1144 
1145  $ilDB->manipulateF(
1146  "DELETE FROM usr_pref WHERE usr_id = %s",
1147  array("integer"),
1148  array($a_user_id)
1149  );
1150  }
1151 
1158  public static function _writePref($a_usr_id, $a_keyword, $a_value)
1159  {
1160  global $DIC;
1161 
1162  $ilDB = $DIC['ilDB'];
1163  $ilDB->replace(
1164  "usr_pref",
1165  array(
1166  "usr_id" => array("integer", $a_usr_id),
1167  "keyword" => array("text", $a_keyword),
1168  ),
1169  array(
1170  "value" => array("text",$a_value)
1171  )
1172  );
1173 
1174  /*
1175  self::_deletePref($a_usr_id, $a_keyword);
1176  if(strlen($a_value))
1177  {
1178  $ilDB->manipulateF(
1179  'INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s, %s, %s)',
1180  array('integer', 'text', 'text'),
1181  array($a_usr_id, $a_keyword, $a_value)
1182  );
1183  }*/
1184  }
1185 
1190  public function writePrefs()
1191  {
1192  global $DIC;
1193 
1194  $ilDB = $DIC['ilDB'];
1195 
1196  ilObjUser::_deleteAllPref($this->id);
1197  foreach ($this->prefs as $keyword => $value) {
1198  self::_writePref($this->id, $keyword, $value);
1199  }
1200  }
1201 
1208  public function getTimeZone()
1209  {
1210  if ($tz = $this->getPref('user_tz')) {
1211  return $tz;
1212  } else {
1213  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1214  $settings = ilCalendarSettings::_getInstance();
1215  return $settings->getDefaultTimeZone();
1216  }
1217  }
1218 
1225  public function getTimeFormat()
1226  {
1227  if ($format = $this->getPref('time_format')) {
1228  return $format;
1229  } else {
1230  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1231  $settings = ilCalendarSettings::_getInstance();
1232  return $settings->getDefaultTimeFormat();
1233  }
1234  }
1235 
1242  public function getDateFormat()
1243  {
1244  if ($format = $this->getPref('date_format')) {
1245  return $format;
1246  } else {
1247  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1248  $settings = ilCalendarSettings::_getInstance();
1249  return $settings->getDefaultDateFormat();
1250  }
1251  }
1252 
1259  public function setPref($a_keyword, $a_value)
1260  {
1261  if ($a_keyword != "") {
1262  $this->prefs[$a_keyword] = $a_value;
1263  }
1264  }
1265 
1271  public function getPref($a_keyword)
1272  {
1273  if (array_key_exists($a_keyword, $this->prefs)) {
1274  return $this->prefs[$a_keyword];
1275  } else {
1276  return false;
1277  }
1278  }
1279 
1280  public static function _lookupPref($a_usr_id, $a_keyword)
1281  {
1282  global $DIC;
1283 
1284  $ilDB = $DIC['ilDB'];
1285 
1286  $query = "SELECT * FROM usr_pref WHERE usr_id = " . $ilDB->quote($a_usr_id, "integer") . " " .
1287  "AND keyword = " . $ilDB->quote($a_keyword, "text");
1288  $res = $ilDB->query($query);
1289 
1290  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1291  return $row->value;
1292  }
1293  return false;
1294  }
1295 
1300  public function readPrefs()
1301  {
1302  global $DIC;
1303 
1304  $ilDB = $DIC['ilDB'];
1305 
1306  if (is_array($this->prefs)) {
1307  $this->oldPrefs = $this->prefs;
1308  }
1309 
1310  $this->prefs = ilObjUser::_getPreferences($this->id);
1311  }
1312 
1318  public function delete()
1319  {
1320  global $DIC;
1321 
1322  $rbacadmin = $DIC->rbac()->admin();
1323  $ilDB = $DIC['ilDB'];
1324 
1325  // deassign from ldap groups
1326  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1328  $mapping->deleteUser($this->getId());
1329 
1330  // remove mailbox / update sent mails
1331  include_once("Services/Mail/classes/class.ilMailbox.php");
1332  $mailbox = new ilMailbox($this->getId());
1333  $mailbox->delete();
1334  $mailbox->updateMailsOfDeletedUser($this->getLogin());
1335 
1336  // delete feed blocks on personal desktop
1337  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1338  $costum_block = new ilCustomBlock();
1339  $costum_block->setContextObjId($this->getId());
1340  $costum_block->setContextObjType("user");
1341  $c_blocks = $costum_block->queryBlocksForContext();
1342  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1343  foreach ($c_blocks as $c_block) {
1344  if ($c_block["type"] == "pdfeed") {
1345  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1346  $fb->delete();
1347  }
1348  }
1349 
1350 
1351  // delete block settings
1352  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1354 
1355  // delete user_account
1356  $ilDB->manipulateF(
1357  "DELETE FROM usr_data WHERE usr_id = %s",
1358  array("integer"),
1359  array($this->getId())
1360  );
1361 
1362  $this->deleteMultiTextFields();
1363 
1364  // delete user_prefs
1365  ilObjUser::_deleteAllPref($this->getId());
1366 
1367  $this->removeUserPicture(false); // #8597
1368 
1369  // delete user_session
1370  include_once("./Services/Authentication/classes/class.ilSession.php");
1372 
1373  // remove user from rbac
1374  $rbacadmin->removeUser($this->getId());
1375 
1376  // remove bookmarks
1377  // TODO: move this to class.ilBookmarkFolder
1378  $q = "DELETE FROM bookmark_tree WHERE tree = " .
1379  $ilDB->quote($this->getId(), "integer");
1380  $ilDB->manipulate($q);
1381 
1382  $q = "DELETE FROM bookmark_data WHERE user_id = " .
1383  $ilDB->quote($this->getId(), "integer");
1384  $ilDB->manipulate($q);
1385 
1386  // DELETE FORUM ENTRIES (not complete in the moment)
1387  include_once './Modules/Forum/classes/class.ilObjForum.php';
1388  ilObjForum::_deleteUser($this->getId());
1389 
1390  // Delete link check notify entries
1391  include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
1393 
1394  // Delete crs entries
1395  include_once './Modules/Course/classes/class.ilObjCourse.php';
1396  ilObjCourse::_deleteUser($this->getId());
1397 
1398  // Delete user tracking
1399  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1401 
1402  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1404 
1405  // Delete Tracking data SCORM 2004 RTE
1406  include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1408 
1409  // Delete Tracking data SCORM 1.2 RTE
1410  include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1412 
1413  // remove all notifications
1414  include_once "./Services/Notification/classes/class.ilNotification.php";
1416 
1417  // remove portfolios
1418  include_once "./Modules/Portfolio/classes/class.ilObjPortfolio.php";
1420 
1421  // remove workspace
1422  include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1423  $tree = new ilWorkspaceTree($this->getId());
1424  $tree->cascadingDelete();
1425 
1426  // remove disk quota entries
1427  include_once "./Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1429 
1430  // remove reminder entries
1431  require_once 'Services/User/classes/class.ilCronDeleteInactiveUserReminderMail.php';
1433 
1434  // badges
1435  include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
1437 
1438  // remove org unit assignments
1439  $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
1440  $ilOrgUnitUserAssignmentQueries->deleteAllAssignmentsOfUser($this->getId());
1441 
1442  // Delete user defined field entries
1444 
1445  // Delete clipboard entries
1446  $this->clipboardDeleteAll();
1447 
1448  // Reset owner
1449  $this->resetOwner();
1450 
1451  // Trigger deleteUser Event
1452  global $DIC;
1453 
1454  $ilAppEventHandler = $DIC['ilAppEventHandler'];
1455  $ilAppEventHandler->raise(
1456  'Services/User',
1457  'deleteUser',
1458  array('usr_id' => $this->getId())
1459  );
1460 
1461  // delete object data
1462  parent::delete();
1463  return true;
1464  }
1465 
1475  public function setFullname($a_title = "", $a_firstname = "", $a_lastname = "")
1476  {
1477  $this->fullname = "";
1478 
1479  if ($a_title) {
1480  $fullname = $a_title . " ";
1481  } elseif ($this->utitle) {
1482  $this->fullname = $this->utitle . " ";
1483  }
1484 
1485  if ($a_firstname) {
1486  $fullname .= $a_firstname . " ";
1487  } elseif ($this->firstname) {
1488  $this->fullname .= $this->firstname . " ";
1489  }
1490 
1491  if ($a_lastname) {
1492  return $fullname . $a_lastname;
1493  }
1494 
1495  $this->fullname .= $this->lastname;
1496  }
1497 
1512  public function getFullname($a_max_strlen = 0)
1513  {
1514  if (!$a_max_strlen) {
1515  return ilUtil::stripSlashes($this->fullname);
1516  }
1517 
1518  if (strlen($this->fullname) <= $a_max_strlen) {
1519  return ilUtil::stripSlashes($this->fullname);
1520  }
1521 
1522  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen) {
1523  return ilUtil::stripSlashes($this->utitle . " " . substr($this->firstname, 0, 1) . ". " . $this->lastname);
1524  }
1525 
1526  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen) {
1527  return ilUtil::stripSlashes($this->firstname . " " . $this->lastname);
1528  }
1529 
1530  if ((strlen($this->lastname) + 3) <= $a_max_strlen) {
1531  return ilUtil::stripSlashes(substr($this->firstname, 0, 1) . ". " . $this->lastname);
1532  }
1533 
1534  return ilUtil::stripSlashes(substr($this->lastname, 0, $a_max_strlen));
1535  }
1536 
1542  public function setLogin($a_str)
1543  {
1544  $this->login = $a_str;
1545  }
1546 
1551  public function getLogin()
1552  {
1553  return $this->login;
1554  }
1555 
1561  public function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1562  {
1563  $this->passwd = $a_str;
1564  $this->passwd_type = $a_type;
1565  }
1566 
1574  public function getPasswd()
1575  {
1576  return $this->passwd;
1577  }
1584  public function getPasswdType()
1585  {
1586  return $this->passwd_type;
1587  }
1588 
1594  public function setGender($a_str)
1595  {
1596  $this->gender = substr($a_str, -1);
1597  }
1598 
1603  public function getGender()
1604  {
1605  return $this->gender;
1606  }
1607 
1615  public function setUTitle($a_str)
1616  {
1617  $this->utitle = $a_str;
1618  }
1619 
1626  public function getUTitle()
1627  {
1628  return $this->utitle;
1629  }
1630 
1636  public function setFirstname($a_str)
1637  {
1638  $this->firstname = $a_str;
1639  }
1640 
1645  public function getFirstname()
1646  {
1647  return $this->firstname;
1648  }
1649 
1655  public function setLastname($a_str)
1656  {
1657  $this->lastname = $a_str;
1658  }
1659 
1664  public function getLastname()
1665  {
1666  return $this->lastname;
1667  }
1668 
1674  public function setInstitution($a_str)
1675  {
1676  $this->institution = $a_str;
1677  }
1678 
1683  public function getInstitution()
1684  {
1685  return $this->institution;
1686  }
1687 
1693  public function setDepartment($a_str)
1694  {
1695  $this->department = $a_str;
1696  }
1697 
1702  public function getDepartment()
1703  {
1704  return $this->department;
1705  }
1706 
1712  public function setStreet($a_str)
1713  {
1714  $this->street = $a_str;
1715  }
1716 
1721  public function getStreet()
1722  {
1723  return $this->street;
1724  }
1725 
1731  public function setCity($a_str)
1732  {
1733  $this->city = $a_str;
1734  }
1735 
1740  public function getCity()
1741  {
1742  return $this->city;
1743  }
1744 
1750  public function setZipcode($a_str)
1751  {
1752  $this->zipcode = $a_str;
1753  }
1754 
1759  public function getZipcode()
1760  {
1761  return $this->zipcode;
1762  }
1763 
1770  public function setCountry($a_str)
1771  {
1772  $this->country = $a_str;
1773  }
1774 
1780  public function getCountry()
1781  {
1782  return $this->country;
1783  }
1784 
1790  public function setSelectedCountry($a_val)
1791  {
1792  $this->sel_country = $a_val;
1793  }
1794 
1800  public function getSelectedCountry()
1801  {
1802  return $this->sel_country;
1803  }
1804 
1810  public function setPhoneOffice($a_str)
1811  {
1812  $this->phone_office = $a_str;
1813  }
1814 
1819  public function getPhoneOffice()
1820  {
1821  return $this->phone_office;
1822  }
1823 
1829  public function setPhoneHome($a_str)
1830  {
1831  $this->phone_home = $a_str;
1832  }
1833 
1838  public function getPhoneHome()
1839  {
1840  return $this->phone_home;
1841  }
1842 
1848  public function setPhoneMobile($a_str)
1849  {
1850  $this->phone_mobile = $a_str;
1851  }
1852 
1857  public function getPhoneMobile()
1858  {
1859  return $this->phone_mobile;
1860  }
1861 
1867  public function setFax($a_str)
1868  {
1869  $this->fax = $a_str;
1870  }
1871 
1876  public function getFax()
1877  {
1878  return $this->fax;
1879  }
1880 
1886  public function setClientIP($a_str)
1887  {
1888  $this->client_ip = $a_str;
1889  }
1890 
1895  public function getClientIP()
1896  {
1897  return $this->client_ip;
1898  }
1899 
1905  public function setMatriculation($a_str)
1906  {
1907  $this->matriculation = $a_str;
1908  }
1909 
1914  public function getMatriculation()
1915  {
1916  return $this->matriculation;
1917  }
1918 
1925  public static function lookupMatriculation($a_usr_id)
1926  {
1927  global $DIC;
1928 
1929  $ilDB = $DIC['ilDB'];
1930 
1931  $query = "SELECT matriculation FROM usr_data " .
1932  "WHERE usr_id = " . $ilDB->quote($a_usr_id);
1933  $res = $ilDB->query($query);
1934  $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
1935  return $row->matriculation ? $row->matriculation : '';
1936  }
1937 
1943  public function setEmail($a_str)
1944  {
1945  $this->email = $a_str;
1946  }
1947 
1952  public function getEmail()
1953  {
1954  return $this->email;
1955  }
1956 
1960  public function getSecondEmail()
1961  {
1962  return $this->second_email;
1963  }
1964 
1969  {
1970  $this->second_email = $second_email;
1971  }
1972 
1978  public function setHobby($a_str)
1979  {
1980  $this->hobby = $a_str;
1981  }
1982 
1987  public function getHobby()
1988  {
1989  return $this->hobby;
1990  }
1991 
1997  public function setLanguage($a_str)
1998  {
1999  $this->setPref("language", $a_str);
2000  unset($_SESSION['lang']);
2001  }
2002 
2008  public function getLanguage()
2009  {
2010  return $this->prefs["language"];
2011  }
2012 
2021  public function setDiskQuota($a_disk_quota)
2022  {
2023  $this->setPref("disk_quota", $a_disk_quota);
2024  }
2025 
2035  public function getDiskQuota()
2036  {
2037  return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
2038  }
2039 
2041  {
2042  return $this->prefs["wsp_disk_quota"] ? $this->prefs["wsp_disk_quota"] : 0;
2043  }
2044 
2045  public function setLastPasswordChangeTS($a_last_password_change_ts)
2046  {
2047  $this->last_password_change_ts = $a_last_password_change_ts;
2048  }
2049 
2050  public function getLastPasswordChangeTS()
2051  {
2053  }
2054 
2058  public function getPasswordPolicyResetStatus() : bool
2059  {
2060  return (bool) $this->passwd_policy_reset;
2061  }
2062 
2066  public function setPasswordPolicyResetStatus(bool $status)
2067  {
2068  $this->passwd_policy_reset = $status;
2069  }
2070 
2071  public static function _lookupLanguage($a_usr_id)
2072  {
2073  global $DIC;
2074 
2075  $ilDB = $DIC->database();
2076  $lng = $DIC->language();
2077 
2078  $q = "SELECT value FROM usr_pref WHERE usr_id= " .
2079  $ilDB->quote($a_usr_id, "integer") . " AND keyword = " .
2080  $ilDB->quote('language', "text");
2081  $r = $ilDB->query($q);
2082 
2083  while ($row = $ilDB->fetchAssoc($r)) {
2084  return $row['value'];
2085  }
2086  if (is_object($lng)) {
2087  return $lng->getDefaultLanguage();
2088  }
2089  return 'en';
2090  }
2091 
2092  public static function _writeExternalAccount($a_usr_id, $a_ext_id)
2093  {
2094  global $DIC;
2095 
2096  $ilDB = $DIC['ilDB'];
2097 
2098  $ilDB->manipulateF(
2099  "UPDATE usr_data " .
2100  " SET ext_account = %s WHERE usr_id = %s",
2101  array("text", "integer"),
2102  array($a_ext_id, $a_usr_id)
2103  );
2104  }
2105 
2106  public static function _writeAuthMode($a_usr_id, $a_auth_mode)
2107  {
2108  global $DIC;
2109 
2110  $ilDB = $DIC['ilDB'];
2111 
2112  $ilDB->manipulateF(
2113  "UPDATE usr_data " .
2114  " SET auth_mode = %s WHERE usr_id = %s",
2115  array("text", "integer"),
2116  array($a_auth_mode, $a_usr_id)
2117  );
2118  }
2119 
2124  public function getCurrentLanguage()
2125  {
2126  return $_SESSION['lang'];
2127  }
2128 
2134  public function setCurrentLanguage($a_val)
2135  {
2136  $_SESSION['lang'] = $a_val;
2137  }
2138 
2144  public function setLastLogin($a_str)
2145  {
2146  $this->last_login = $a_str;
2147  }
2148 
2154  public function getLastLogin()
2155  {
2156  return $this->last_login;
2157  }
2158 
2163  public function setFirstLogin($a_str)
2164  {
2165  $this->first_login = $a_str;
2166  }
2167 
2172  public function getFirstLogin()
2173  {
2174  return $this->first_login;
2175  }
2176 
2181  public function setLastProfilePrompt($a_str)
2182  {
2183  $this->last_profile_prompt = $a_str;
2184  }
2185 
2190  public function getLastProfilePrompt()
2191  {
2193  }
2194 
2200  public function setLastUpdate($a_str)
2201  {
2202  $this->last_update = $a_str;
2203  }
2204  public function getLastUpdate()
2205  {
2206  return $this->last_update;
2207  }
2208 
2214  public function setComment($a_str)
2215  {
2216  $this->referral_comment = $a_str;
2217  }
2218 
2223  public function getComment()
2224  {
2225  return $this->referral_comment;
2226  }
2227 
2234  public function setApproveDate($a_str)
2235  {
2236  $this->approve_date = $a_str;
2237  }
2238 
2244  public function getApproveDate()
2245  {
2246  return $this->approve_date;
2247  }
2248 
2249  // BEGIN DiskQuota: show when user accepted user agreement
2255  public function getAgreeDate()
2256  {
2257  return $this->agree_date;
2258  }
2265  public function setAgreeDate($a_str)
2266  {
2267  $this->agree_date = $a_str;
2268  }
2269  // END DiskQuota: show when user accepted user agreement
2270 
2277  public function setActive($a_active, $a_owner = 0)
2278  {
2279  $this->setOwner($a_owner);
2280 
2281  if ($a_active) {
2282  $this->active = 1;
2283  $this->setApproveDate(date('Y-m-d H:i:s'));
2284  $this->setOwner($a_owner);
2285  } else {
2286  $this->active = 0;
2287  $this->setApproveDate(null);
2288  }
2289  }
2290 
2295  public function getActive()
2296  {
2297  return $this->active;
2298  }
2299 
2303  public static function _lookupActive($a_usr_id)
2304  {
2305  global $DIC;
2306 
2307  $ilDB = $DIC['ilDB'];
2308 
2309  $query = 'SELECT usr_id FROM usr_data ' .
2310  'WHERE active = ' . $ilDB->quote(1, 'integer') . ' ' .
2311  'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
2312  $res = $ilDB->query($query);
2313  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2314  return true;
2315  }
2316  return false;
2317  }
2318 
2324  public function syncActive()
2325  {
2326  $storedActive = 0;
2327  if ($this->getStoredActive($this->id)) {
2328  $storedActive = 1;
2329  }
2330 
2331  $currentActive = 0;
2332  if ($this->active) {
2333  $currentActive = 1;
2334  }
2335 
2336  if ((!empty($storedActive) && empty($currentActive)) ||
2337  (empty($storedActive) && !empty($currentActive))) {
2338  $this->setActive($currentActive, self::getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2339  }
2340  }
2341 
2348  public function getStoredActive($a_id)
2349  {
2350  $active = ilObjUser::_lookup($a_id, "active");
2351  return $active ? true : false;
2352  }
2353 
2359  public function setSkin($a_str)
2360  {
2361  // TODO: exception handling (dir exists)
2362  $this->skin = $a_str;
2363  }
2364 
2365  public function setTimeLimitOwner($a_owner)
2366  {
2367  $this->time_limit_owner = $a_owner;
2368  }
2369  public function getTimeLimitOwner()
2370  {
2371  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2372  }
2373  public function setTimeLimitFrom($a_from)
2374  {
2375  $this->time_limit_from = $a_from;
2376  }
2377  public function getTimeLimitFrom()
2378  {
2379  return $this->time_limit_from;
2380  }
2381  public function setTimeLimitUntil($a_until)
2382  {
2383  $this->time_limit_until = $a_until;
2384  }
2385  public function getTimeLimitUntil()
2386  {
2387  return $this->time_limit_until;
2388  }
2389  public function setTimeLimitUnlimited($a_unlimited)
2390  {
2391  $this->time_limit_unlimited = $a_unlimited;
2392  }
2393  public function getTimeLimitUnlimited()
2394  {
2395  return $this->time_limit_unlimited;
2396  }
2397  public function setTimeLimitMessage($a_time_limit_message)
2398  {
2399  return $this->time_limit_message = $a_time_limit_message;
2400  }
2401  public function getTimeLimitMessage()
2402  {
2403  return $this->time_limit_message;
2404  }
2405 
2406  public function setLoginAttempts($a_login_attempts)
2407  {
2408  $this->login_attempts = $a_login_attempts;
2409  }
2410 
2411  public function getLoginAttempts()
2412  {
2413  return $this->login_attempts;
2414  }
2415 
2416 
2417  public function checkTimeLimit()
2418  {
2419  if ($this->getTimeLimitUnlimited()) {
2420  return true;
2421  }
2422  if ($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time()) {
2423  return true;
2424  }
2425  return false;
2426  }
2427  public function setProfileIncomplete($a_prof_inc)
2428  {
2429  $this->profile_incomplete = (boolean) $a_prof_inc;
2430  }
2431  public function getProfileIncomplete()
2432  {
2433  if ($this->id == ANONYMOUS_USER_ID) {
2434  return false;
2435  }
2436  return $this->profile_incomplete;
2437  }
2438 
2442  public function isPasswordChangeDemanded()
2443  {
2444  if ($this->id == ANONYMOUS_USER_ID) {
2445  return false;
2446  }
2447 
2448  if ($this->id == SYSTEM_USER_ID) {
2449  if (
2450  \ilUserPasswordManager::getInstance()->verifyPassword($this, base64_decode('aG9tZXI=')) &&
2452  ) {
2453  return true;
2454  } else {
2455  return false;
2456  }
2457  }
2458 
2459  $security = ilSecuritySettings::_getInstance();
2460 
2461  $authModeAllowsPasswordChange = !ilAuthUtils::_needsExternalAccountByAuthMode($this->getAuthMode(true));
2462  $passwordResetOnFirstLogin = (
2463  $security->isPasswordChangeOnFirstLoginEnabled() &&
2464  $this->getLastPasswordChangeTS() == 0 && $this->is_self_registered == false
2465  );
2466  $passwordResetOnChangedPolicy = $this->getPasswordPolicyResetStatus();
2467 
2468  return ($authModeAllowsPasswordChange && ($passwordResetOnFirstLogin || $passwordResetOnChangedPolicy));
2469  }
2470 
2471  public function isPasswordExpired()
2472  {
2473  if ($this->id == ANONYMOUS_USER_ID) {
2474  return false;
2475  }
2476 
2477  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2478  $security = ilSecuritySettings::_getInstance();
2479  if ($this->getLastPasswordChangeTS() > 0) {
2480  $max_pass_age = $security->getPasswordMaxAge();
2481  if ($max_pass_age > 0) {
2482  $max_pass_age_ts = ($max_pass_age * 86400);
2483  $pass_change_ts = $this->getLastPasswordChangeTS();
2484  $current_ts = time();
2485 
2486  if (($current_ts - $pass_change_ts) > $max_pass_age_ts) {
2488  return true;
2489  }
2490  }
2491  }
2492  }
2493 
2494  return false;
2495  }
2496 
2497  public function getPasswordAge()
2498  {
2499  $current_ts = time();
2500  $pass_change_ts = $this->getLastPasswordChangeTS();
2501  $password_age = (int) (($current_ts - $pass_change_ts) / 86400);
2502  return $password_age;
2503  }
2504 
2505  public function setLastPasswordChangeToNow()
2506  {
2507  global $DIC;
2508 
2509  $ilDB = $DIC['ilDB'];
2510 
2511  $this->setLastPasswordChangeTS(time());
2512 
2513  $query = "UPDATE usr_data SET last_password_change = %s " .
2514  "WHERE usr_id = %s";
2515  $affected = $ilDB->manipulateF(
2516  $query,
2517  array('integer','integer'),
2518  array($this->getLastPasswordChangeTS(),$this->id)
2519  );
2520  if ($affected) {
2521  return true;
2522  } else {
2523  return false;
2524  }
2525  }
2526 
2527  public function resetLastPasswordChange()
2528  {
2529  global $DIC;
2530 
2531  $ilDB = $DIC['ilDB'];
2532 
2533  $query = "UPDATE usr_data SET last_password_change = 0 " .
2534  "WHERE usr_id = %s";
2535  $affected = $ilDB->manipulateF(
2536  $query,
2537  array('integer'),
2538  array($this->getId())
2539  );
2540  if ($affected) {
2541  return true;
2542  } else {
2543  return false;
2544  }
2545  }
2546 
2552  public function setLatitude($a_latitude)
2553  {
2554  $this->latitude = $a_latitude;
2555  }
2556 
2562  public function getLatitude()
2563  {
2564  return $this->latitude;
2565  }
2566 
2572  public function setLongitude($a_longitude)
2573  {
2574  $this->longitude = $a_longitude;
2575  }
2576 
2582  public function getLongitude()
2583  {
2584  return $this->longitude;
2585  }
2586 
2592  public function setLocationZoom($a_locationzoom)
2593  {
2594  $this->loc_zoom = $a_locationzoom;
2595  }
2596 
2602  public function getLocationZoom()
2603  {
2604  return $this->loc_zoom;
2605  }
2606 
2607 
2613  public static function hasActiveSession($a_user_id, $a_session_id)
2614  {
2615  global $DIC;
2616 
2617  $ilDB = $DIC['ilDB'];
2618 
2619  $set = $ilDB->queryf(
2620  '
2621  SELECT COUNT(*) session_count
2622  FROM usr_session WHERE user_id = %s AND expires > %s AND session_id != %s ',
2623  array('integer', 'integer', 'text'),
2624  array($a_user_id, time(), $a_session_id)
2625  );
2626  $row = $ilDB->fetchAssoc($set);
2627  return (bool) $row['session_count'];
2628  }
2629 
2630  /*
2631  * check user id with login name
2632  * @access public
2633  */
2634  public function checkUserId()
2635  {
2636  global $DIC;
2637 
2638  $ilSetting = $DIC['ilSetting'];
2639 
2642  if ($id > 0) {
2643  return $id;
2644  }
2645  return false;
2646  }
2647 
2651  private static function getLoginFromAuth()
2652  {
2653  $uid = $GLOBALS['DIC']['ilAuthSession']->getUserId();
2655 
2656  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2657  require_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2659  $login = self::toUsernameWithoutDomain($login);
2660  }
2661  return $login;
2662  }
2663 
2670  public static function toUsernameWithoutDomain($a_login)
2671  {
2672  // Remove all characters including the last slash or the last backslash
2673  // in the username
2674  $pos = strrpos($a_login, '/');
2675  $pos2 = strrpos($a_login, '\\');
2676  if ($pos === false || $pos < $pos2) {
2677  $pos = $pos2;
2678  }
2679  if ($pos !== false) {
2680  $a_login = substr($a_login, $pos + 1);
2681  }
2682  return $a_login;
2683  }
2684 
2685  /*
2686  * check to see if current user has been made active
2687  * @access public
2688  * @return true if active, otherwise false
2689  */
2690  public function isCurrentUserActive()
2691  {
2692  global $DIC;
2693 
2694  $ilDB = $DIC['ilDB'];
2695 
2697  $set = $ilDB->queryF(
2698  "SELECT active FROM usr_data WHERE login= %s",
2699  array("text"),
2700  array($login)
2701  );
2702  //query has got a result
2703  if ($rec = $ilDB->fetchAssoc($set)) {
2704  if ($rec["active"]) {
2705  return true;
2706  }
2707  }
2708 
2709  return false;
2710  }
2711 
2712  /*
2713  * STATIC METHOD
2714  * get the user_id of a login name
2715  * @param string login name
2716  * @return integer id of user
2717  * @static
2718  * @access public
2719  */
2720  public static function getUserIdByLogin($a_login)
2721  {
2722  return (int) ilObjUser::_lookupId($a_login);
2723  }
2724 
2733  public static function getUserIdsByEmail($a_email) : array
2734  {
2735  global $DIC;
2736 
2737  $ilias = $DIC['ilias'];
2738  $ilDB = $DIC['ilDB'];
2739 
2740  $res = $ilDB->queryF(
2741  "SELECT usr_id FROM usr_data " .
2742  "WHERE email = %s and active = 1",
2743  array("text"),
2744  array($a_email)
2745  );
2746  $ids = array();
2747  while ($row = $ilDB->fetchObject($res)) {
2748  $ids[] = $row->usr_id;
2749  }
2750 
2751  return $ids;
2752  }
2753 
2754 
2761  public static function getUserLoginsByEmail($a_email) : array
2762  {
2763  global $DIC;
2764 
2765  $ilDB = $DIC->database();
2766 
2767  $res = $ilDB->queryF(
2768  "SELECT login FROM usr_data " .
2769  "WHERE email = %s and active = 1",
2770  array("text"),
2771  array($a_email)
2772  );
2773  $ids = array();
2774  while ($row = $ilDB->fetchObject($res)) {
2775  $ids[] = $row->login;
2776  }
2777 
2778  return $ids;
2779  }
2780 
2781  /*
2782  * STATIC METHOD
2783  * get the login name of a user_id
2784  * @param integer id of user
2785  * @return string login name; false if not found
2786  * @static
2787  * @access public
2788  */
2789  public function getLoginByUserId($a_userid)
2790  {
2791  $login = ilObjUser::_lookupLogin($a_userid);
2792  return $login ? $login : false;
2793  }
2794 
2805  public static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = false)
2806  {
2807  global $DIC;
2808 
2809  $ilias = $DIC['ilias'];
2810  $ilDB = $DIC['ilDB'];
2811  $ilLog = $DIC['ilLog'];
2812 
2813 
2814  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2815 
2816  $without_anonymous_users = true;
2817 
2818  // determine join filter
2819  $join_filter = " WHERE ";
2820  if ($filter_settings !== false && strlen($filter_settings)) {
2821  switch ($filter_settings) {
2822  case 3:
2823  // show only users without courses
2824  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.usr_id IS NULL AND ";
2825  break;
2826  case 5:
2827  // show only users with a certain course membership
2828  $ref_id = $_SESSION["user_filter_data"];
2829  if ($ref_id) {
2830  $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.obj_id = " .
2831  "(SELECT obj_id FROM object_reference WHERE ref_id = " . $ilDB->quote($ref_id, "integer") . ") AND ";
2832  }
2833  break;
2834  case 6:
2835  global $DIC;
2836 
2837  $rbacreview = $DIC['rbacreview'];
2838  $ref_id = $_SESSION["user_filter_data"];
2839  if ($ref_id) {
2840  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
2841  if (is_array($local_roles) && count($local_roles)) {
2842  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE " .
2843  $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles) . " AND ";
2844  }
2845  }
2846  break;
2847  case 7:
2848  global $DIC;
2849 
2850  $rbacreview = $DIC['rbacreview'];
2851  $rol_id = $_SESSION["user_filter_data"];
2852  if ($rol_id) {
2853  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = " .
2854  $ilDB->quote($rol_id, "integer") . " AND ";
2855  $without_anonymous_users = false;
2856  }
2857  break;
2858  }
2859  }
2860  // This is a temporary hack to search users by their role
2861  // See Mantis #338. This is a hack due to Mantis #337.
2862  if (strtolower(substr($a_search_str, 0, 5)) == "role:") {
2863  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email " .
2864  "FROM object_data,rbac_ua,usr_data " .
2865  "WHERE " . $ilDB->like("object_data.title", "text", "%" . substr($a_search_str, 5) . "%") .
2866  " AND object_data.type = 'role' " .
2867  "AND rbac_ua.rol_id = object_data.obj_id " .
2868  "AND usr_data.usr_id = rbac_ua.usr_id " .
2869  "AND rbac_ua.usr_id != " . $ilDB->quote(ANONYMOUS_USER_ID, "integer");
2870  } else {
2871  $query .= $join_filter .
2872  "(" . $ilDB->like("usr_data.login", "text", "%" . $a_search_str . "%") . " " .
2873  "OR " . $ilDB->like("usr_data.firstname", "text", "%" . $a_search_str . "%") . " " .
2874  "OR " . $ilDB->like("usr_data.lastname", "text", "%" . $a_search_str . "%") . " " .
2875  "OR " . $ilDB->like("usr_data.email", "text", "%" . $a_search_str . "%") . ") ";
2876 
2877  if ($filter_settings !== false && strlen($filter_settings)) {
2878  switch ($filter_settings) {
2879  case 0:
2880  $query .= " AND usr_data.active = " . $ilDB->quote(0, "integer") . " ";
2881  break;
2882  case 1:
2883  $query .= " AND usr_data.active = " . $ilDB->quote(1, "integer") . " ";
2884  break;
2885  case 2:
2886  $query .= " AND usr_data.time_limit_unlimited = " . $ilDB->quote(0, "integer") . " ";
2887  break;
2888  case 4:
2889  $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"]));
2890  $query .= " AND last_login < " . $ilDB->quote($date, "timestamp") . " ";
2891  break;
2892  }
2893  }
2894 
2895  if ($without_anonymous_users) {
2896  $query .= "AND usr_data.usr_id != " . $ilDB->quote(ANONYMOUS_USER_ID, "integer");
2897  }
2898 
2899  if (is_numeric($active) && $active > -1 && $filter_settings === false) {
2900  $query .= " AND active = " . $ilDB->quote($active, "integer") . " ";
2901  }
2902  }
2903  $ilLog->write($query);
2904  $res = $ilDB->query($query);
2905  while ($row = $ilDB->fetchObject($res)) {
2906  $users[] = array(
2907  "usr_id" => $row->usr_id,
2908  "login" => $row->login,
2909  "firstname" => $row->firstname,
2910  "lastname" => $row->lastname,
2911  "email" => $row->email,
2912  "active" => $row->active);
2913  $ids[] = $row->usr_id;
2914  }
2915  if ($a_return_ids_only) {
2916  return $ids ? $ids : array();
2917  } else {
2918  return $users ? $users : array();
2919  }
2920  }
2921 
2925  public static function getAllUserLogins()
2926  {
2930  global $DIC;
2931 
2932  $ilDB = $DIC['ilDB'];
2933 
2934  $logins = array();
2935 
2936  $res = $ilDB->query(
2937  "SELECT login FROM usr_data WHERE " . $ilDB->in('usr_id', array(ANONYMOUS_USER_ID), true, 'integer')
2938  );
2939  while ($row = $ilDB->fetchAssoc($res)) {
2940  $logins[] = $row['login'];
2941  }
2942 
2943  return $logins;
2944  }
2945 
2954  public static function _readUsersProfileData($a_user_ids)
2955  {
2956  global $DIC;
2957 
2958  $ilDB = $DIC['ilDB'];
2959  $res = $ilDB->query("SELECT * FROM usr_data WHERE " .
2960  $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2961  while ($row = $ilDB->fetchAssoc($res)) {
2962  $user_data["$row[usr_id]"] = $row;
2963  }
2964  return $user_data ? $user_data : array();
2965  }
2966 
2975  public static function _getAllUserData($a_fields = null, $active = -1)
2976  {
2977  global $DIC;
2978 
2979  $ilDB = $DIC['ilDB'];
2980 
2981  $result_arr = array();
2982  $types = array();
2983  $values = array();
2984 
2985  if ($a_fields !== null and is_array($a_fields)) {
2986  if (count($a_fields) == 0) {
2987  $select = "*";
2988  } else {
2989  if (($usr_id_field = array_search("usr_id", $a_fields)) !== false) {
2990  unset($a_fields[$usr_id_field]);
2991  }
2992 
2993  $select = implode(",", $a_fields) . ",usr_data.usr_id";
2994  // online time
2995  if (in_array('online_time', $a_fields)) {
2996  $select .= ",ut_online.online_time ";
2997  }
2998  }
2999 
3000  $q = "SELECT " . $select . " FROM usr_data ";
3001 
3002  // Add online_time if desired
3003  // Need left join here to show users that never logged in
3004  if (in_array('online_time', $a_fields)) {
3005  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
3006  }
3007 
3008  switch ($active) {
3009  case 0:
3010  case 1:
3011  $q .= "WHERE active = " . $ilDB->quote($active, "integer");
3012  break;
3013  case 2:
3014  $q .= "WHERE time_limit_unlimited= " . $ilDB->quote(0, "integer");;
3015  break;
3016  case 3:
3017  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND " .
3018  $ilDB->like("object_data.title", "text", "%crs%") . " AND usr_data.usr_id = rbac_ua.usr_id";
3019  $r = $ilDB->query($qtemp);
3020  $course_users = array();
3021  while ($row = $ilDB->fetchAssoc($r)) {
3022  array_push($course_users, $row["usr_id"]);
3023  }
3024  if (count($course_users)) {
3025  $q .= " WHERE " . $ilDB->in("usr_data.usr_id", $course_users, true, "integer") . " ";
3026  } else {
3027  return $result_arr;
3028  }
3029  break;
3030  case 4:
3031  $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"]));
3032  $q .= " AND last_login < " . $ilDB->quote($date, "timestamp");
3033  break;
3034  case 5:
3035  $ref_id = $_SESSION["user_filter_data"];
3036  if ($ref_id) {
3037  $q .= " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id " .
3038  "WHERE obj_members.obj_id = (SELECT obj_id FROM object_reference " .
3039  "WHERE ref_id = " . $ilDB->quote($ref_id, "integer") . ") ";
3040  }
3041  break;
3042  case 6:
3043  global $DIC;
3044 
3045  $rbacreview = $DIC['rbacreview'];
3046  $ref_id = $_SESSION["user_filter_data"];
3047  if ($ref_id) {
3048  $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
3049  if (is_array($local_roles) && count($local_roles)) {
3050  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE " .
3051  $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer") . " ";
3052  }
3053  }
3054  break;
3055  case 7:
3056  $rol_id = $_SESSION["user_filter_data"];
3057  if ($rol_id) {
3058  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = " .
3059  $ilDB->quote($rol_id, "integer");
3060  }
3061  break;
3062  }
3063  $r = $ilDB->query($q);
3064 
3065  while ($row = $ilDB->fetchAssoc($r)) {
3066  $result_arr[] = $row;
3067  }
3068  }
3069 
3070  return $result_arr;
3071  }
3072 
3076  public static function _getNumberOfUsersForStyle($a_skin, $a_style)
3077  {
3078  global $DIC;
3079 
3080  $ilDB = $DIC['ilDB'];
3081 
3082  $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 " .
3083  " WHERE up1.keyword= " . $ilDB->quote("style", "text") .
3084  " AND up1.value= " . $ilDB->quote($a_style, "text") .
3085  " AND up2.keyword= " . $ilDB->quote("skin", "text") .
3086  " AND up2.value= " . $ilDB->quote($a_skin, "text") .
3087  " AND up1.usr_id = up2.usr_id ";
3088 
3089  $cnt_set = $ilDB->query($q);
3090 
3091  $cnt_rec = $ilDB->fetchAssoc($cnt_set);
3092 
3093  return $cnt_rec["cnt"];
3094  }
3095 
3099  public static function _getAllUserAssignedStyles()
3100  {
3101  global $DIC;
3102 
3103  $ilDB = $DIC['ilDB'];
3104 
3105  $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 " .
3106  " WHERE up1.keyword = " . $ilDB->quote("style", "text") .
3107  " AND up2.keyword = " . $ilDB->quote("skin", "text") .
3108  " AND up1.usr_id = up2.usr_id";
3109 
3110  $sty_set = $ilDB->query($q);
3111 
3112  $styles = array();
3113  while ($sty_rec = $ilDB->fetchAssoc($sty_set)) {
3114  $styles[] = $sty_rec["skin"] . ":" . $sty_rec["style"];
3115  }
3116 
3117  return $styles;
3118  }
3119 
3123  public static function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3124  {
3125  global $DIC;
3126 
3127  $ilDB = $DIC['ilDB'];
3128 
3129  $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 " .
3130  " WHERE up1.keyword= " . $ilDB->quote("style", "text") .
3131  " AND up1.value= " . $ilDB->quote($a_from_style, "text") .
3132  " AND up2.keyword= " . $ilDB->quote("skin", "text") .
3133  " AND up2.value= " . $ilDB->quote($a_from_skin, "text") .
3134  " AND up1.usr_id = up2.usr_id ";
3135 
3136  $usr_set = $ilDB->query($q);
3137 
3138  while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
3139  self::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3140  self::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3141  }
3142  }
3143 
3144 
3150 
3158  public function addObjectToClipboard(
3159  $a_item_id,
3160  $a_type,
3161  $a_title,
3162  $a_parent = 0,
3163  $a_time = 0,
3164  $a_order_nr = 0
3165  ) {
3166  global $DIC;
3167 
3168  $ilDB = $DIC['ilDB'];
3169 
3170  if ($a_time == 0) {
3171  $a_time = date("Y-m-d H:i:s", time());
3172  }
3173 
3174  $item_set = $ilDB->queryF(
3175  "SELECT * FROM personal_clipboard WHERE " .
3176  "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3177  array("integer", "integer", "text", "integer"),
3178  array(0, $a_item_id, $a_type, $this->getId())
3179  );
3180 
3181  // only insert if item is not already in clipboard
3182  if (!$d = $item_set->fetchRow()) {
3183  $ilDB->manipulateF(
3184  "INSERT INTO personal_clipboard " .
3185  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES " .
3186  " (%s,%s,%s,%s,%s,%s,%s)",
3187  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3188  array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr)
3189  );
3190  } else {
3191  $ilDB->manipulateF(
3192  "UPDATE personal_clipboard SET insert_time = %s " .
3193  "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3194  array("timestamp", "integer", "integer", "text"),
3195  array($a_time, $this->getId(), $a_item_id, $a_type)
3196  );
3197  }
3198  }
3199 
3203  public function addToPCClipboard($a_content, $a_time, $a_nr)
3204  {
3205  global $DIC;
3206 
3207  $ilDB = $DIC['ilDB'];
3208  if ($a_time == 0) {
3209  $a_time = date("Y-m-d H:i:s", time());
3210  }
3211  $ilDB->insert("personal_pc_clipboard", array(
3212  "user_id" => array("integer", $this->getId()),
3213  "content" => array("clob", $a_content),
3214  "insert_time" => array("timestamp", $a_time),
3215  "order_nr" => array("integer", $a_nr)
3216  ));
3217  }
3218 
3222  public function getPCClipboardContent()
3223  {
3224  global $DIC;
3225 
3226  $ilDB = $DIC['ilDB'];
3227 
3228  $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard " .
3229  " WHERE user_id = %s", array("integer"), array($this->getId()));
3230  $row = $ilDB->fetchAssoc($set);
3231 
3232  $set = $ilDB->queryF(
3233  "SELECT * FROM personal_pc_clipboard " .
3234  " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3235  array("integer", "timestamp"),
3236  array($this->getId(), $row["mtime"])
3237  );
3238  $content = array();
3239  while ($row = $ilDB->fetchAssoc($set)) {
3240  $content[] = $row["content"];
3241  }
3242 
3243  return $content;
3244  }
3245 
3250  {
3251  global $DIC;
3252 
3253  $ilDB = $DIC['ilDB'];
3254 
3255  $set = $ilDB->queryF(
3256  "SELECT * FROM personal_clipboard WHERE " .
3257  "parent = %s AND type = %s AND user_id = %s",
3258  array("integer", "text", "integer"),
3259  array(0, $a_type, $this->getId())
3260  );
3261  if ($rec = $ilDB->fetchAssoc($set)) {
3262  return true;
3263  }
3264 
3265  return false;
3266  }
3267 
3272  {
3273  global $DIC;
3274 
3275  $ilDB = $DIC['ilDB'];
3276 
3277  $ilDB->manipulateF(
3278  "DELETE FROM personal_clipboard WHERE " .
3279  "type = %s AND user_id = %s",
3280  array("text", "integer"),
3281  array($a_type, $this->getId())
3282  );
3283  }
3284 
3288  public function clipboardDeleteAll()
3289  {
3290  global $DIC;
3291 
3292  $ilDB = $DIC['ilDB'];
3293 
3294  $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE " .
3295  "user_id = %s", array("integer"), array($this->getId()));
3296  }
3297 
3301  public function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3302  {
3303  global $DIC;
3304 
3305  $ilDB = $DIC['ilDB'];
3306 
3307  $par = "";
3308  if ($a_top_nodes_only) {
3309  $par = " AND parent = " . $ilDB->quote(0, "integer") . " ";
3310  }
3311 
3312  $type_str = ($a_type != "")
3313  ? " AND type = " . $ilDB->quote($a_type, "text") . " "
3314  : "";
3315  $q = "SELECT * FROM personal_clipboard WHERE " .
3316  "user_id = " . $ilDB->quote($this->getId(), "integer") . " " .
3317  $type_str . $par .
3318  " ORDER BY order_nr";
3319  $objs = $ilDB->query($q);
3320  $objects = array();
3321  while ($obj = $ilDB->fetchAssoc($objs)) {
3322  if ($obj["type"] == "mob") {
3323  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3324  if (ilObject::_lookupType((int) $obj["item_id"]) !== "mob") {
3325  continue;
3326  }
3327  }
3328  if ($obj["type"] == "incl") {
3329  include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3330  $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3331  if (!ilPageObject::_exists("mep", (int) $obj["item_id"], "-")) {
3332  continue;
3333  }
3334  }
3335  $objects[] = array("id" => $obj["item_id"],
3336  "type" => $obj["type"], "title" => $obj["title"],
3337  "insert_time" => $obj["insert_time"]);
3338  }
3339  return $objects;
3340  }
3341 
3345  public function getClipboardChilds($a_parent, $a_insert_time)
3346  {
3347  global $DIC;
3348 
3349  $ilDB = $DIC['ilDB'];
3350  $ilUser = $DIC['ilUser'];
3351 
3352  $objs = $ilDB->queryF(
3353  "SELECT * FROM personal_clipboard WHERE " .
3354  "user_id = %s AND parent = %s AND insert_time = %s " .
3355  " ORDER BY order_nr",
3356  array("integer", "integer", "timestamp"),
3357  array($ilUser->getId(), (int) $a_parent, $a_insert_time)
3358  );
3359  $objects = array();
3360  while ($obj = $ilDB->fetchAssoc($objs)) {
3361  if ($obj["type"] == "mob") {
3362  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3363  }
3364  $objects[] = array("id" => $obj["item_id"],
3365  "type" => $obj["type"], "title" => $obj["title"], "insert_time" => $obj["insert_time"]);
3366  }
3367  return $objects;
3368  }
3369 
3378  public static function _getUsersForClipboadObject($a_type, $a_id)
3379  {
3380  global $DIC;
3381 
3382  $ilDB = $DIC['ilDB'];
3383 
3384  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE " .
3385  "item_id = " . $ilDB->quote($a_id, "integer") . " AND " .
3386  "type = " . $ilDB->quote($a_type, "text");
3387  $user_set = $ilDB->query($q);
3388  $users = array();
3389  while ($user_rec = $ilDB->fetchAssoc($user_set)) {
3390  $users[] = $user_rec["user_id"];
3391  }
3392 
3393  return $users;
3394  }
3395 
3403  public function removeObjectFromClipboard($a_item_id, $a_type)
3404  {
3405  global $DIC;
3406 
3407  $ilDB = $DIC['ilDB'];
3408 
3409  $q = "DELETE FROM personal_clipboard WHERE " .
3410  "item_id = " . $ilDB->quote($a_item_id, "integer") .
3411  " AND type = " . $ilDB->quote($a_type, "text") . " " .
3412  " AND user_id = " . $ilDB->quote($this->getId(), "integer");
3413  $ilDB->manipulate($q);
3414  }
3415 
3416  public static function _getImportedUserId($i2_id)
3417  {
3418  global $DIC;
3419 
3420  $ilDB = $DIC['ilDB'];
3421 
3422  $query = "SELECT obj_id FROM object_data WHERE import_id = " .
3423  $ilDB->quote($i2_id, "text");
3424 
3425  $res = $ilDB->query($query);
3426  while ($row = $ilDB->fetchObject($res)) {
3427  $id = $row->obj_id;
3428  }
3429  return $id ? $id : 0;
3430  }
3431 
3437  public static function lookupOrgUnitsRepresentation($a_usr_id)
3438  {
3439  require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
3440  return ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_usr_id);
3441  }
3442 
3443 
3447  public function getOrgUnitsRepresentation()
3448  {
3449  return self::lookupOrgUnitsRepresentation($this->getId());
3450  }
3451 
3452 
3457  public function setAuthMode($a_str)
3458  {
3459  $this->auth_mode = $a_str;
3460  }
3461 
3466  public function getAuthMode($a_auth_key = false)
3467  {
3468  if (!$a_auth_key) {
3469  return $this->auth_mode;
3470  }
3471 
3472  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3473  return ilAuthUtils::_getAuthMode($this->auth_mode);
3474  }
3475 
3483  public function setExternalAccount($a_str)
3484  {
3485  $this->ext_account = $a_str;
3486  }
3487 
3495  public function getExternalAccount()
3496  {
3497  return $this->ext_account;
3498  }
3499 
3511  public static function _getExternalAccountsByAuthMode($a_auth_mode, $a_read_auth_default = false)
3512  {
3513  global $DIC;
3514 
3515  $ilDB = $DIC['ilDB'];
3516  $ilSetting = $DIC['ilSetting'];
3517 
3518  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3519  $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data " .
3520  "WHERE auth_mode = %s";
3521  $types[] = "text";
3522  $values[] = $a_auth_mode;
3523  if ($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode', AUTH_LOCAL)) == $a_auth_mode) {
3524  $q .= " OR auth_mode = %s ";
3525  $types[] = "text";
3526  $values[] = 'default';
3527  }
3528 
3529  $res = $ilDB->queryF($q, $types, $values);
3530  while ($row = $ilDB->fetchObject($res)) {
3531  if ($row->auth_mode == 'default') {
3532  $accounts[$row->usr_id] = $row->login;
3533  } else {
3534  $accounts[$row->usr_id] = $row->ext_account;
3535  }
3536  }
3537  return $accounts ? $accounts : array();
3538  }
3539 
3547  public static function _toggleActiveStatusOfUsers($a_usr_ids, $a_status)
3548  {
3549  global $DIC;
3550 
3551  $ilDB = $DIC['ilDB'];
3552 
3553  if (!is_array($a_usr_ids)) {
3554  return false;
3555  }
3556 
3557 
3558  if ($a_status) {
3559  $q = "UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE " .
3560  $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3561  $ilDB->manipulate($q);
3562  } else {
3563  $usrId_IN_usrIds = $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3564 
3565  $q = "UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds";
3566  $ilDB->manipulate($q);
3567 
3568  $queryString = "
3569  UPDATE usr_data
3570  SET inactivation_date = %s
3571  WHERE inactivation_date IS NULL
3572  AND $usrId_IN_usrIds
3573  ";
3574  $ilDB->manipulateF($queryString, array('timestamp'), array(ilUtil::now()));
3575  }
3576 
3577  return true;
3578  }
3579 
3580 
3589  public static function _lookupAuthMode($a_usr_id)
3590  {
3591  return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3592  }
3593 
3600  public static function _checkExternalAuthAccount($a_auth, $a_account, $tryFallback = true)
3601  {
3602  $db = $GLOBALS['DIC']->database();
3603  $settings = $GLOBALS['DIC']->settings();
3604 
3605  // Check directly with auth_mode
3606  $r = $db->queryF(
3607  "SELECT * FROM usr_data WHERE " .
3608  " ext_account = %s AND auth_mode = %s",
3609  array("text", "text"),
3610  array($a_account, $a_auth)
3611  );
3612  if ($usr = $db->fetchAssoc($r)) {
3613  return $usr["login"];
3614  }
3615 
3616  if (!$tryFallback) {
3617  return false;
3618  }
3619 
3620  // For compatibility, check for login (no ext_account entry given)
3621  $res = $db->queryF(
3622  "SELECT login FROM usr_data " .
3623  "WHERE login = %s AND auth_mode = %s AND (ext_account IS NULL OR ext_account = '') ",
3624  array("text", "text"),
3625  array($a_account, $a_auth)
3626  );
3627  if ($usr = $db->fetchAssoc($res)) {
3628  return $usr['login'];
3629  }
3630 
3631  // If auth_default == $a_auth => check for login
3632  if (ilAuthUtils::_getAuthModeName($settings->get('auth_mode')) == $a_auth) {
3633  $res = $db->queryF(
3634  "SELECT login FROM usr_data WHERE " .
3635  " ext_account = %s AND auth_mode = %s",
3636  array("text", "text"),
3637  array($a_account, "default")
3638  );
3639  if ($usr = $db->fetchAssoc($res)) {
3640  return $usr["login"];
3641  }
3642  // Search for login (no ext_account given)
3643  $res = $db->queryF(
3644  "SELECT login FROM usr_data " .
3645  "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3646  array("text", "text"),
3647  array($a_account, "default")
3648  );
3649  if ($usr = $db->fetchAssoc($res)) {
3650  return $usr["login"];
3651  }
3652  }
3653  return false;
3654  }
3655 
3659  public static function _getNumberOfUsersPerAuthMode()
3660  {
3661  global $DIC;
3662 
3663  $ilDB = $DIC['ilDB'];
3664 
3665  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data " .
3666  "GROUP BY auth_mode");
3667  $cnt_arr = array();
3668  while ($cnt = $ilDB->fetchAssoc($r)) {
3669  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3670  }
3671 
3672  return $cnt_arr;
3673  }
3674 
3680  public static function _getLocalAccountsForEmail($a_email)
3681  {
3682  global $DIC;
3683 
3684  $ilDB = $DIC['ilDB'];
3685  $ilSetting = $DIC['ilSetting'];
3686 
3687  // default set to local (1)?
3688 
3689  $q = "SELECT * FROM usr_data WHERE " .
3690  " email = %s AND (auth_mode = %s ";
3691  $types = array("text", "text");
3692  $values = array($a_email, "local");
3693 
3694  if ($ilSetting->get("auth_mode") == 1) {
3695  $q .= " OR auth_mode = %s";
3696  $types[] = "text";
3697  $values[] = "default";
3698  }
3699 
3700  $q .= ")";
3701 
3702  $users = array();
3703  $usr_set = $ilDB->queryF($q, $types, $values);
3704  while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
3705  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3706  }
3707 
3708  return $users;
3709  }
3710 
3711 
3719  public static function _uploadPersonalPicture($tmp_file, $obj_id)
3720  {
3721  $webspace_dir = ilUtil::getWebspaceDir();
3722  $image_dir = $webspace_dir . "/usr_images";
3723  $store_file = "usr_" . $obj_id . "." . "jpg";
3724  $target_file = $image_dir . "/$store_file";
3725 
3726  chmod($tmp_file, 0770);
3727 
3728  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3729  // taking only frame [0] to avoid problems with animated gifs
3730  $show_file = "$image_dir/usr_" . $obj_id . ".jpg";
3731  $thumb_file = "$image_dir/usr_" . $obj_id . "_small.jpg";
3732  $xthumb_file = "$image_dir/usr_" . $obj_id . "_xsmall.jpg";
3733  $xxthumb_file = "$image_dir/usr_" . $obj_id . "_xxsmall.jpg";
3734 
3735  ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
3736  ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
3737  ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
3738  ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
3739 
3740  // store filename
3741  self::_writePref($obj_id, "profile_image", $store_file);
3742 
3743  return true;
3744  }
3745 
3746 
3755  public function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3756  {
3757  if (isset(self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic])) {
3758  return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
3759  }
3760 
3761  self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic] = ilObjUser::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
3762 
3763  return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
3764  }
3765 
3766  public function getAvatar() : Avatar
3767  {
3768  return self::_getAvatar($this->getId());
3769  }
3770 
3771  public static function _getAvatar($a_usr_id) : Avatar
3772  {
3773  $define = new ilUserAvatarResolver((int) $a_usr_id);
3774 
3775  return $define->getAvatar();
3776  }
3777 
3789  public static function _getPersonalPicturePath(
3790  $a_usr_id,
3791  $a_size = "small",
3792  $a_force_pic = false,
3793  $a_prevent_no_photo_image = false
3794  ) {
3795  $define = new ilUserAvatarResolver((int) $a_usr_id);
3796  $define->setForcePicture($a_force_pic);
3797  $define->setSize($a_size);
3798 
3799  return ilWACSignedPath::signFile($define->getLegacyPictureURL());
3800  }
3801 
3808  public static function copyProfilePicturesToDirectory($a_user_id, $a_dir)
3809  {
3810  $a_dir = trim(str_replace("..", "", $a_dir));
3811  if ($a_dir == "" || !is_dir($a_dir)) {
3812  return;
3813  }
3814 
3815  $webspace_dir = ilUtil::getWebspaceDir();
3816  $image_dir = $webspace_dir . "/usr_images";
3817  $images = array(
3818  "upload_" . $a_user_id . "pic",
3819  "usr_" . $a_user_id . "." . "jpg",
3820  "usr_" . $a_user_id . "_small.jpg",
3821  "usr_" . $a_user_id . "_xsmall.jpg",
3822  "usr_" . $a_user_id . "_xxsmall.jpg",
3823  "upload_" . $a_user_id);
3824  foreach ($images as $image) {
3825  if (is_file($image_dir . "/" . $image)) {
3826  copy($image_dir . "/" . $image, $a_dir . "/" . $image);
3827  }
3828  }
3829  }
3830 
3831 
3835  public function removeUserPicture($a_do_update = true)
3836  {
3837  $webspace_dir = ilUtil::getWebspaceDir();
3838  $image_dir = $webspace_dir . "/usr_images";
3839  $file = $image_dir . "/usr_" . $this->getID() . "." . "jpg";
3840  $thumb_file = $image_dir . "/usr_" . $this->getID() . "_small.jpg";
3841  $xthumb_file = $image_dir . "/usr_" . $this->getID() . "_xsmall.jpg";
3842  $xxthumb_file = $image_dir . "/usr_" . $this->getID() . "_xxsmall.jpg";
3843  $upload_file = $image_dir . "/upload_" . $this->getID();
3844 
3845  if ($a_do_update) {
3846  // remove user pref file name
3847  $this->setPref("profile_image", "");
3848  $this->update();
3849  }
3850 
3851  if (@is_file($file)) {
3852  unlink($file);
3853  }
3854  if (@is_file($thumb_file)) {
3855  unlink($thumb_file);
3856  }
3857  if (@is_file($xthumb_file)) {
3858  unlink($xthumb_file);
3859  }
3860  if (@is_file($xxthumb_file)) {
3861  unlink($xxthumb_file);
3862  }
3863  if (@is_file($upload_file)) {
3864  unlink($upload_file);
3865  }
3866  }
3867 
3868 
3869  public function setUserDefinedData($a_data)
3870  {
3871  if (!is_array($a_data)) {
3872  return false;
3873  }
3874  foreach ($a_data as $field => $data) {
3875  #$new_data[$field] = ilUtil::stripSlashes($data);
3876  // Assign it directly to avoid update problems of unchangable fields
3877  $this->user_defined_data['f_' . $field] = $data;
3878  }
3879  #$this->user_defined_data = $new_data;
3880 
3881  return true;
3882  }
3883 
3884  public function getUserDefinedData()
3885  {
3886  return $this->user_defined_data ? $this->user_defined_data : array();
3887  }
3888 
3889  public function updateUserDefinedFields()
3890  {
3891  global $DIC;
3892 
3893  $ilDB = $DIC['ilDB'];
3894 
3895  $fields = '';
3896 
3897  $field_def = array();
3898 
3899  include_once("./Services/User/classes/class.ilUserDefinedData.php");
3900  $udata = new ilUserDefinedData($this->getId());
3901 
3902  foreach ($this->user_defined_data as $field => $value) {
3903  if ($field != 'usr_id') {
3904  // $field_def[$field] = array('text',$value);
3905  $udata->set($field, $value);
3906  }
3907  }
3908  $udata->update();
3909 
3910  /* if(!$field_def)
3911  {
3912  return true;
3913  }
3914 
3915  $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
3916  $res = $ilDB->query($query);
3917 
3918 
3919  if($res->numRows())
3920  {
3921  // Update
3922  $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
3923  }
3924  else
3925  {
3926  $field_def['usr_id'] = array('integer',$this->getId());
3927  $ilDB->insert('udf_data',$field_def);
3928  }
3929  */
3930  return true;
3931  }
3932 
3933  public function readUserDefinedFields()
3934  {
3935  global $DIC;
3936 
3937  $ilDB = $DIC['ilDB'];
3938 
3939  include_once("./Services/User/classes/class.ilUserDefinedData.php");
3940  $udata = new ilUserDefinedData($this->getId());
3941 
3942  /* $query = "SELECT * FROM udf_data ".
3943  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
3944 
3945  $res = $this->db->query($query);
3946  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
3947  {
3948  $this->user_defined_data = $row;
3949  }*/
3950 
3951  $this->user_defined_data = $udata->getAll();
3952 
3953  return true;
3954  }
3955 
3956  public function addUserDefinedFieldEntry()
3957  {
3958  global $DIC;
3959 
3960  $ilDB = $DIC['ilDB'];
3961 
3962  // not needed. no entry in udf_text/udf_clob means no value
3963 
3964  /* $query = "INSERT INTO udf_data (usr_id ) ".
3965  "VALUES( ".
3966  $ilDB->quote($this->getId(),'integer').
3967  ")";
3968  $res = $ilDB->manipulate($query);
3969  */
3970  return true;
3971  }
3972 
3974  {
3975  global $DIC;
3976 
3977  $ilDB = $DIC['ilDB'];
3978 
3979  include_once("./Services/User/classes/class.ilUserDefinedData.php");
3981 
3982  // wrong place...
3983  /* $query = "DELETE FROM udf_data ".
3984  "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
3985  $res = $ilDB->manipulate($query);*/
3986 
3987  return true;
3988  }
3989 
3995  public function getProfileAsString(&$a_language)
3996  {
3997  include_once './Services/AccessControl/classes/class.ilObjRole.php';
3998 
3999  global $DIC;
4000 
4001  $lng = $DIC['lng'];
4002  $rbacreview = $DIC['rbacreview'];
4003 
4004  $language = &$a_language;
4005  $language->loadLanguageModule('registration');
4006  $language->loadLanguageModule('crs');
4007 
4008  $body = '';
4009  $body .= ($language->txt("login") . ": " . $this->getLogin() . "\n");
4010 
4011  if (strlen($this->getUTitle())) {
4012  $body .= ($language->txt("title") . ": " . $this->getUTitle() . "\n");
4013  }
4014  if (1 === strlen($this->getGender())) {
4015  $body .= ($language->txt("gender") . ": " . $language->txt('gender_' . strtolower($this->getGender())) . "\n");
4016  }
4017  if (strlen($this->getFirstname())) {
4018  $body .= ($language->txt("firstname") . ": " . $this->getFirstname() . "\n");
4019  }
4020  if (strlen($this->getLastname())) {
4021  $body .= ($language->txt("lastname") . ": " . $this->getLastname() . "\n");
4022  }
4023  if (strlen($this->getInstitution())) {
4024  $body .= ($language->txt("institution") . ": " . $this->getInstitution() . "\n");
4025  }
4026  if (strlen($this->getDepartment())) {
4027  $body .= ($language->txt("department") . ": " . $this->getDepartment() . "\n");
4028  }
4029  if (strlen($this->getStreet())) {
4030  $body .= ($language->txt("street") . ": " . $this->getStreet() . "\n");
4031  }
4032  if (strlen($this->getCity())) {
4033  $body .= ($language->txt("city") . ": " . $this->getCity() . "\n");
4034  }
4035  if (strlen($this->getZipcode())) {
4036  $body .= ($language->txt("zipcode") . ": " . $this->getZipcode() . "\n");
4037  }
4038  if (strlen($this->getCountry())) {
4039  $body .= ($language->txt("country") . ": " . $this->getCountry() . "\n");
4040  }
4041  if (strlen($this->getSelectedCountry())) {
4042  $body .= ($language->txt("sel_country") . ": " . $this->getSelectedCountry() . "\n");
4043  }
4044  if (strlen($this->getPhoneOffice())) {
4045  $body .= ($language->txt("phone_office") . ": " . $this->getPhoneOffice() . "\n");
4046  }
4047  if (strlen($this->getPhoneHome())) {
4048  $body .= ($language->txt("phone_home") . ": " . $this->getPhoneHome() . "\n");
4049  }
4050  if (strlen($this->getPhoneMobile())) {
4051  $body .= ($language->txt("phone_mobile") . ": " . $this->getPhoneMobile() . "\n");
4052  }
4053  if (strlen($this->getFax())) {
4054  $body .= ($language->txt("fax") . ": " . $this->getFax() . "\n");
4055  }
4056  if (strlen($this->getEmail())) {
4057  $body .= ($language->txt("email") . ": " . $this->getEmail() . "\n");
4058  }
4059  if (strlen($this->getSecondEmail())) {
4060  $body .= ($language->txt("second_email") . ": " . $this->getSecondEmail() . "\n");
4061  }
4062  if (strlen($this->getHobby())) {
4063  $body .= ($language->txt("hobby") . ": " . $this->getHobby() . "\n");
4064  }
4065  if (strlen($this->getComment())) {
4066  $body .= ($language->txt("referral_comment") . ": " . $this->getComment() . "\n");
4067  }
4068  if (strlen($this->getMatriculation())) {
4069  $body .= ($language->txt("matriculation") . ": " . $this->getMatriculation() . "\n");
4070  }
4071  if (strlen($this->getCreateDate())) {
4076 
4077  $body .= ($language->txt("create_date") . ": " . $date . "\n");
4078  }
4079 
4080  $gr = [];
4081  foreach ($rbacreview->getGlobalRoles() as $role) {
4082  if ($rbacreview->isAssigned($this->getId(), $role)) {
4083  $gr[] = ilObjRole::_lookupTitle($role);
4084  }
4085  }
4086  if (count($gr)) {
4087  $body .= ($language->txt('reg_role_info') . ': ' . implode(',', $gr) . "\n");
4088  }
4089 
4090  // Time limit
4091  if ($this->getTimeLimitUnlimited()) {
4092  $body .= ($language->txt('time_limit') . ": " . $language->txt('crs_unlimited') . "\n");
4093  } else {
4097  new ilDateTime($this->getTimeLimitFrom(), IL_CAL_UNIX),
4099  );
4101 
4102  $start = new ilDateTime($this->getTimeLimitFrom(), IL_CAL_UNIX);
4103  $end = new ilDateTime($this->getTimeLimitUntil(), IL_CAL_UNIX);
4104 
4105  $body .= $language->txt('time_limit') . ': ' .
4106  $language->txt('from') . " " .
4107  $start->get(IL_CAL_DATETIME) . " ";
4108  $body .= $language->txt('to') . ' ' . $end->get(IL_CAL_DATETIME);
4109  }
4110 
4111  include_once './Services/User/classes/class.ilUserDefinedFields.php';
4115  $user_defined_fields = ilUserDefinedFields::_getInstance();
4117 
4118  foreach ($user_defined_fields->getDefinitions() as $field_id => $definition) {
4119  $data = $user_defined_data["f_" . $field_id];
4120  if (strlen($data)) {
4121  if ($definition['field_type'] == UDF_TYPE_WYSIWYG) {
4122  $data = preg_replace('/<br(\s*)?\/?>/i', "\n", $data);
4123  $data = strip_tags($data);
4124  }
4125 
4126  $body .= $definition['field_name'] . ': ' . $data . "\n";
4127  }
4128  }
4129 
4130  return $body;
4131  }
4132 
4136  public static function _lookupFeedHash($a_user_id, $a_create = false)
4137  {
4138  global $DIC;
4139 
4140  $ilDB = $DIC['ilDB'];
4141 
4142  if ($a_user_id > 0) {
4143  $set = $ilDB->queryF(
4144  "SELECT feed_hash from usr_data WHERE usr_id = %s",
4145  array("integer"),
4146  array($a_user_id)
4147  );
4148  if ($rec = $ilDB->fetchAssoc($set)) {
4149  if (strlen($rec["feed_hash"]) == 32) {
4150  return $rec["feed_hash"];
4151  } elseif ($a_create) {
4152  $hash = md5(rand(1, 9999999) + str_replace(" ", "", (string) microtime()));
4153  $ilDB->manipulateF(
4154  "UPDATE usr_data SET feed_hash = %s" .
4155  " WHERE usr_id = %s",
4156  array("text", "integer"),
4157  array($hash, $a_user_id)
4158  );
4159  return $hash;
4160  }
4161  }
4162  }
4163 
4164  return false;
4165  }
4166 
4172  public static function _getFeedPass($a_user_id)
4173  {
4174  global $DIC;
4175 
4176  $ilDB = $DIC['ilDB'];
4177 
4178  if ($a_user_id > 0) {
4179  return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4180  }
4181  return false;
4182  }
4183 
4189  public static function _setFeedPass($a_user_id, $a_password)
4190  {
4191  global $DIC;
4192 
4193  $ilDB = $DIC['ilDB'];
4194 
4195  self::_writePref(
4196  $a_user_id,
4197  "priv_feed_pass",
4198  ($a_password == "") ? "" : md5($a_password)
4199  );
4200  }
4201 
4211  public static function _loginExists($a_login, $a_user_id = 0)
4212  {
4213  global $DIC;
4214 
4215  $ilDB = $DIC['ilDB'];
4216 
4217  $q = "SELECT DISTINCT login, usr_id FROM usr_data " .
4218  "WHERE login = %s";
4219  $types[] = "text";
4220  $values[] = $a_login;
4221 
4222  if ($a_user_id != 0) {
4223  $q .= " AND usr_id != %s ";
4224  $types[] = "integer";
4225  $values[] = $a_user_id;
4226  }
4227 
4228  $r = $ilDB->queryF($q, $types, $values);
4229 
4230  if ($row = $ilDB->fetchAssoc($r)) {
4231  return $row['usr_id'];
4232  }
4233  return false;
4234  }
4235 
4246  public static function _externalAccountExists($a_external_account, $a_auth_mode)
4247  {
4248  global $DIC;
4249 
4250  $ilDB = $DIC['ilDB'];
4251 
4252  $res = $ilDB->queryF(
4253  "SELECT * FROM usr_data " .
4254  "WHERE ext_account = %s AND auth_mode = %s",
4255  array("text", "text"),
4256  array($a_external_account, $a_auth_mode)
4257  );
4258  return $ilDB->fetchAssoc($res) ? true :false;
4259  }
4260 
4268  public static function _getUsersForRole($role_id, $active = -1)
4269  {
4270  global $DIC;
4271 
4272  $ilDB = $DIC['ilDB'];
4273  $rbacreview = $DIC['rbacreview'];
4274  $data = array();
4275 
4276  $ids = $rbacreview->assignedUsers($role_id);
4277 
4278  if (count($ids) == 0) {
4279  $ids = array(-1);
4280  }
4281 
4282  $query = "SELECT usr_data.*, usr_pref.value AS language
4283  FROM usr_data
4284  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4285  WHERE " . $ilDB->in("usr_data.usr_id", $ids, false, "integer");
4286  $values[] = "language";
4287  $types[] = "text";
4288 
4289 
4290  if (is_numeric($active) && $active > -1) {
4291  $query .= " AND usr_data.active = %s";
4292  $values[] = $active;
4293  $types[] = "integer";
4294  }
4295 
4296  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4297 
4298  $r = $ilDB->queryF($query, $types, $values);
4299  $data = array();
4300  while ($row = $ilDB->fetchAssoc($r)) {
4301  $data[] = $row;
4302  }
4303  return $data;
4304  }
4305 
4306 
4312  public static function _getUsersForFolder($ref_id, $active)
4313  {
4314  global $DIC;
4315 
4316  $ilDB = $DIC['ilDB'];
4317  $data = array();
4318  $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 ";
4319  $types[] = "text";
4320  $values[] = "language";
4321 
4322  if (is_numeric($active) && $active > -1) {
4323  $query .= " AND usr_data.active = %s";
4324  $values[] = $active;
4325  $types[] = "integer";
4326  }
4327 
4328  if ($ref_id != USER_FOLDER_ID) {
4329  $query .= " AND usr_data.time_limit_owner = %s";
4330  $values[] = $ref_id;
4331  $types[] = "integer";
4332  }
4333 
4334  $query .= " AND usr_data.usr_id != %s ";
4335  $values[] = ANONYMOUS_USER_ID;
4336  $types[] = "integer";
4337 
4338  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4339 
4340  $result = $ilDB->queryF($query, $types, $values);
4341  $data = array();
4342  while ($row = $ilDB->fetchAssoc($result)) {
4343  array_push($data, $row);
4344  }
4345 
4346  return $data;
4347  }
4348 
4349 
4355  public static function _getUsersForGroup($a_mem_ids, $active = -1)
4356  {
4357  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4358  }
4359 
4360 
4366  public static function _getUsersForIds($a_mem_ids, $active = -1, $timelimitowner = -1)
4367  {
4368  global $DIC;
4369 
4370  $rbacadmin = $DIC['rbacadmin'];
4371  $rbacreview = $DIC['rbacreview'];
4372  $ilDB = $DIC['ilDB'];
4373 
4374  $query = "SELECT usr_data.*, usr_pref.value AS language
4375  FROM usr_data
4376  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4377  WHERE " . $ilDB->in("usr_data.usr_id", $a_mem_ids, false, "integer") . "
4378  AND usr_data.usr_id != %s";
4379  $values[] = "language";
4380  $types[] = "text";
4381  $values[] = ANONYMOUS_USER_ID;
4382  $types[] = "integer";
4383 
4384  if (is_numeric($active) && $active > -1) {
4385  $query .= " AND active = %s";
4386  $values[] = $active;
4387  $types[] = "integer";
4388  }
4389 
4390  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1) {
4391  $query .= " AND usr_data.time_limit_owner = %s";
4392  $values[] = $timelimitowner;
4393  $types[] = "integer";
4394  }
4395 
4396  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4397 
4398  $result = $ilDB->queryF($query, $types, $values);
4399  while ($row = $ilDB->fetchAssoc($result)) {
4400  $mem_arr[] = $row;
4401  }
4402 
4403  return $mem_arr ? $mem_arr : array();
4404  }
4405 
4406 
4407 
4413  public static function _getUserData($a_internalids)
4414  {
4415  global $DIC;
4416 
4417  $ilDB = $DIC['ilDB'];
4418 
4419  $ids = array();
4420  if (is_array($a_internalids)) {
4421  foreach ($a_internalids as $internalid) {
4422  if (is_numeric($internalid)) {
4423  $ids[] = $internalid;
4424  } else {
4425  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4426  if (is_numeric($parsedid) && $parsedid > 0) {
4427  $ids[] = $parsedid;
4428  }
4429  }
4430  }
4431  }
4432  if (count($ids) == 0) {
4433  $ids [] = -1;
4434  }
4435 
4436  $query = "SELECT usr_data.*, usr_pref.value AS language
4437  FROM usr_data
4438  LEFT JOIN usr_pref
4439  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4440  WHERE " . $ilDB->in("usr_data.usr_id", $ids, false, "integer");
4441  $values[] = "language";
4442  $types[] = "text";
4443 
4444  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4445 
4446  $data = array();
4447  $result = $ilDB->queryF($query, $types, $values);
4448  while ($row = $ilDB->fetchAssoc($result)) {
4449  $data[] = $row;
4450  }
4451  return $data;
4452  }
4453 
4460  public static function _getPreferences($user_id)
4461  {
4462  global $DIC;
4463 
4464  $ilDB = $DIC['ilDB'];
4465 
4466  $prefs = array();
4467 
4468  $r = $ilDB->queryF(
4469  "SELECT * FROM usr_pref WHERE usr_id = %s",
4470  array("integer"),
4471  array($user_id)
4472  );
4473 
4474  while ($row = $ilDB->fetchAssoc($r)) {
4475  $prefs[$row["keyword"]] = $row["value"];
4476  }
4477 
4478  return $prefs;
4479  }
4480 
4490  public static function getUserSubsetByPreferenceValue($a_user_ids, $a_keyword, $a_val)
4491  {
4492  global $DIC;
4493 
4494  $ilDB = $DIC['ilDB'];
4495 
4496  $users = array();
4497  $set = $ilDB->query(
4498  "SELECT usr_id FROM usr_pref " .
4499  " WHERE keyword = " . $ilDB->quote($a_keyword, "text") .
4500  " AND " . $ilDB->in("usr_id", $a_user_ids, false, "integer") .
4501  " AND value = " . $ilDB->quote($a_val, "text")
4502  );
4503  while ($rec = $ilDB->fetchAssoc($set)) {
4504  $users[] = $rec["usr_id"];
4505  }
4506  return $users;
4507  }
4508 
4509 
4510  public static function _resetLoginAttempts($a_usr_id)
4511  {
4512  global $DIC;
4513 
4514  $ilDB = $DIC['ilDB'];
4515 
4516  $query = "UPDATE usr_data SET login_attempts = 0 WHERE usr_id = %s";
4517  $affected = $ilDB->manipulateF($query, array('integer'), array($a_usr_id));
4518 
4519  if ($affected) {
4520  return true;
4521  } else {
4522  return false;
4523  }
4524  }
4525 
4526  public static function _getLoginAttempts($a_usr_id)
4527  {
4528  global $DIC;
4529 
4530  $ilDB = $DIC['ilDB'];
4531 
4532  $query = "SELECT login_attempts FROM usr_data WHERE usr_id = %s";
4533  $result = $ilDB->queryF($query, array('integer'), array($a_usr_id));
4534  $record = $ilDB->fetchAssoc($result);
4535  $login_attempts = $record['login_attempts'];
4536 
4537  return $login_attempts;
4538  }
4539 
4540  public static function _incrementLoginAttempts($a_usr_id)
4541  {
4542  global $DIC;
4543 
4544  $ilDB = $DIC['ilDB'];
4545 
4546  $query = "UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s";
4547  $affected = $ilDB->manipulateF($query, array('integer'), array($a_usr_id));
4548 
4549  if ($affected) {
4550  return true;
4551  } else {
4552  return false;
4553  }
4554  }
4555 
4556  public static function _setUserInactive($a_usr_id)
4557  {
4558  global $DIC;
4559 
4560  $ilDB = $DIC['ilDB'];
4561 
4562  $query = "UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s";
4563  $affected = $ilDB->manipulateF($query, array('timestamp', 'integer'), array(ilUtil::now(), $a_usr_id));
4564 
4565  if ($affected) {
4566  return true;
4567  } else {
4568  return false;
4569  }
4570  }
4571 
4577  public function hasPublicProfile()
4578  {
4579  return in_array($this->getPref("public_profile"), array("y", "g"));
4580  }
4581 
4587  public function getPublicName()
4588  {
4589  if ($this->hasPublicProfile()) {
4590  return $this->getFirstname() . " " . $this->getLastname() . " (" . $this->getLogin() . ")";
4591  } else {
4592  return $this->getLogin();
4593  }
4594  }
4595 
4596  public static function _writeHistory($a_usr_id, $a_login)
4597  {
4598  global $DIC;
4599 
4600  $ilDB = $DIC['ilDB'];
4601 
4602  $timestamp = time();
4603 
4604  $res = $ilDB->queryF(
4605  'SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4606  array('integer', 'text', 'integer'),
4607  array($a_usr_id, $a_login, $timestamp)
4608  );
4609 
4610  if ($ilDB->numRows($res) == 0) {
4611  $ilDB->manipulateF(
4612  '
4613  INSERT INTO loginname_history
4614  (usr_id, login, history_date)
4615  VALUES (%s, %s, %s)',
4616  array('integer', 'text', 'integer'),
4617  array($a_usr_id, $a_login, $timestamp)
4618  );
4619  }
4620 
4621  return true;
4622  }
4623 
4631  public static function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4632  {
4636  global $DIC;
4637 
4638  $ilDB = $DIC->database();
4639  $rbacreview = $DIC->rbac()->review();
4640 
4641  $log = ilLoggerFactory::getLogger("user");
4642 
4643  $pd_set = new ilSetting('pd');
4644  $atime = $pd_set->get('user_activity_time') * 60;
4645  $ctime = time();
4646 
4647  $where = array();
4648 
4649  if ($a_user_id == 0) {
4650  $where[] = 'user_id > 0';
4651  } elseif (is_array($a_user_id)) {
4652  $where[] = $ilDB->in("user_id", $a_user_id, false, "integer");
4653  } else {
4654  $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
4655  }
4656 
4657  if ($a_no_anonymous) {
4658  $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
4659  }
4660 
4661  include_once 'Services/User/classes/class.ilUserAccountSettings.php';
4662  if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) {
4663  include_once 'Services/User/classes/class.ilUserFilter.php';
4664  $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
4665  }
4666 
4667  $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
4668  $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
4669 
4670  $where = 'WHERE ' . implode(' AND ', $where);
4671 
4672  $r = $ilDB->queryF(
4673  $q = "
4674  SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime, context, agree_date
4675  FROM usr_session
4676  LEFT JOIN usr_data u
4677  ON user_id = u.usr_id
4678  LEFT JOIN usr_pref p
4679  ON (p.usr_id = u.usr_id AND p.keyword = %s)
4680  {$where}
4681  GROUP BY user_id, firstname, lastname, title, login, last_login, context, agree_date
4682  ORDER BY lastname, firstname
4683  ",
4684  array('text'),
4685  array('hide_own_online_status')
4686  );
4687 
4688  $log->debug("Query: " . $q);
4689 
4690  $users = array();
4691  while ($user = $ilDB->fetchAssoc($r)) {
4692  if ($atime <= 0 || $user['ctime'] + $atime > $ctime) {
4693  $users[$user['user_id']] = $user;
4694  }
4695  }
4696 
4697  $log->debug("Found users: " . count($users));
4698 
4699  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4701  $users = array_filter($users, function ($user) {
4702  if ($user['agree_date'] || $user['user_id'] == SYSTEM_USER_ID || 'root' === $user['login']) {
4703  return true;
4704  }
4705 
4706  return false;
4707  });
4708 
4709  $log->debug("TOS filtered to users: " . count($users));
4710  }
4711 
4712  return $users;
4713  }
4714 
4721  public static function _generateRegistrationHash($a_usr_id)
4722  {
4723  global $DIC;
4724 
4725  $ilDB = $DIC['ilDB'];
4726 
4727  do {
4728  $continue = false;
4729 
4730  $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
4731 
4732  $res = $ilDB->queryf(
4733  '
4734  SELECT COUNT(usr_id) cnt FROM usr_data
4735  WHERE reg_hash = %s',
4736  array('text'),
4737  array($hashcode)
4738  );
4739  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
4740  if ($row->cnt > 0) {
4741  $continue = true;
4742  }
4743  break;
4744  }
4745 
4746  if ($continue) {
4747  continue;
4748  }
4749 
4750  $ilDB->manipulateF(
4751  '
4752  UPDATE usr_data
4753  SET reg_hash = %s
4754  WHERE usr_id = %s',
4755  array('text', 'integer'),
4756  array($hashcode, (int) $a_usr_id)
4757  );
4758 
4759  break;
4760  } while (true);
4761 
4762  return $hashcode;
4763  }
4764 
4773  public static function _verifyRegistrationHash($a_hash)
4774  {
4775  global $DIC;
4776 
4777  $ilDB = $DIC['ilDB'];
4778 
4779  $res = $ilDB->queryf(
4780  '
4781  SELECT usr_id, create_date FROM usr_data
4782  WHERE reg_hash = %s',
4783  array('text'),
4784  array($a_hash)
4785  );
4786  while ($row = $ilDB->fetchAssoc($res)) {
4787  require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
4788  $oRegSettigs = new ilRegistrationSettings();
4789 
4790  if ((int) $oRegSettigs->getRegistrationHashLifetime() != 0 &&
4791  time() - (int) $oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date'])) {
4792  require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
4793  throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
4794  }
4795 
4796  $ilDB->manipulateF(
4797  '
4798  UPDATE usr_data
4799  SET reg_hash = %s
4800  WHERE usr_id = %s',
4801  array('text', 'integer'),
4802  array('', (int) $row['usr_id'])
4803  );
4804 
4805  return (int) $row['usr_id'];
4806  }
4807 
4808  require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
4809  throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
4810  }
4811 
4812  public function setBirthday($a_birthday)
4813  {
4814  if (strlen($a_birthday)) {
4815  $date = new ilDate($a_birthday, IL_CAL_DATE);
4816  $this->birthday = $date->get(IL_CAL_DATE);
4817  } else {
4818  $this->birthday = null;
4819  }
4820  }
4821 
4822  public function getBirthday()
4823  {
4824  return $this->birthday;
4825  }
4826 
4834  public static function getUserIdsByInactivityPeriod(int $periodInDays) : array
4835  {
4836  global $DIC;
4837 
4838  if (!is_numeric($periodInDays) && $periodInDays < 1) {
4839  throw new \ilException('Invalid period given');
4840  }
4841 
4842  $date = date('Y-m-d H:i:s', (time() - ((int) $periodInDays * 24 * 60 * 60)));
4843 
4844  $query = "SELECT usr_id FROM usr_data WHERE last_login IS NOT NULL AND last_login < %s";
4845 
4846  $ids = [];
4847 
4848  $types = ['timestamp'];
4849  $values = [$date];
4850 
4851  $res = $DIC->database()->queryF($query, $types, $values);
4852  while ($row = $DIC->database()->fetchAssoc($res)) {
4853  $ids[] = $row['usr_id'];
4854  }
4855 
4856  return $ids;
4857  }
4858 
4864  public static function getUserIdsNeverLoggedIn(int $thresholdInDays) : array
4865  {
4866  global $DIC;
4867 
4868  $date = date('Y-m-d H:i:s', (time() - ((int) $thresholdInDays * 24 * 60 * 60)));
4869 
4870  $query = "SELECT usr_id FROM usr_data WHERE last_login IS NULL AND create_date < %s";
4871 
4872  $ids = [];
4873 
4874  $types = ['timestamp'];
4875  $values = [$date];
4876 
4877  $res = $DIC->database()->queryF($query, $types, $values);
4878  while ($row = $DIC->database()->fetchAssoc($res)) {
4879  $ids[] = $row['usr_id'];
4880  }
4881 
4882  return $ids;
4883  }
4884 
4893  public static function _getUserIdsByInactivationPeriod($period)
4894  {
4896  $field = 'inactivation_date';
4898 
4899  if (!(int) $period) {
4900  throw new ilException('no valid period given');
4901  }
4902 
4903  global $DIC;
4904 
4905  $ilDB = $DIC['ilDB'];
4906 
4907  $date = date('Y-m-d H:i:s', (time() - ((int) $period * 24 * 60 * 60)));
4908 
4909  $query = "SELECT usr_id FROM usr_data WHERE $field < %s AND active = %s";
4910 
4911  $res = $ilDB->queryF($query, array('timestamp', 'integer'), array($date, 0));
4912 
4913  $ids = array();
4914  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
4915  $ids[] = $row->usr_id;
4916  }
4917 
4918  return $ids;
4919  }
4920 
4930  public static function _updateLastLogin($a_usr_id, $a_last_login = null)
4931  {
4932  if ($a_last_login !== null) {
4933  $last_login = $a_last_login;
4934  } else {
4935  $last_login = date('Y-m-d H:i:s');
4936  }
4937 
4938  global $DIC;
4939 
4940  $ilDB = $DIC['ilDB'];
4941 
4942  $query = "UPDATE usr_data SET last_login = %s WHERE usr_id = %s";
4943  $affected = $ilDB->manipulateF($query, array('timestamp', 'integer'), array($last_login, $a_usr_id));
4944 
4945  $query = "UPDATE usr_data SET first_login = %s WHERE usr_id = %s AND first_login IS NULL";
4946  $ilDB->manipulateF($query, array('timestamp', 'integer'), array($last_login, $a_usr_id));
4947 
4948 
4949  if ($affected) {
4950  return $last_login;
4951  } else {
4952  return false;
4953  }
4954  }
4955 
4956  public function resetOwner()
4957  {
4958  global $DIC;
4959 
4960  $ilDB = $DIC['ilDB'];
4961 
4962  $query = "UPDATE object_data SET owner = 0 " .
4963  "WHERE owner = " . $ilDB->quote($this->getId(), 'integer');
4964  $ilDB->query($query);
4965 
4966  return true;
4967  }
4968 
4969 
4976  public static function getFirstLettersOfLastnames(?array $user_ids = null)
4977  {
4978  global $DIC;
4979 
4980  $ilDB = $DIC->database();
4981 
4982  $q = "SELECT DISTINCT " . $ilDB->upper($ilDB->substr("lastname", 1, 1)) . " let" .
4983  " FROM usr_data" .
4984  " WHERE usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") .
4985  ($user_ids !== null ? " AND " . $ilDB->in('usr_id', $user_ids, false, "integer") : "") .
4986  " ORDER BY let";
4987  $let_set = $ilDB->query($q);
4988 
4989  $lets = array();
4990  while ($let_rec = $ilDB->fetchAssoc($let_set)) {
4991  $let[$let_rec["let"]] = $let_rec["let"];
4992  }
4993  return $let;
4994  }
4995 
4996  // begin-patch deleteProgress
4997  public static function userExists($a_usr_ids = array())
4998  {
4999  global $DIC;
5000 
5001  $ilDB = $DIC['ilDB'];
5002 
5003  $query = 'SELECT count(*) num FROM object_data od ' .
5004  'JOIN usr_data ud ON obj_id = usr_id ' .
5005  'WHERE ' . $ilDB->in('obj_id', $a_usr_ids, false, 'integer') . ' ';
5006  $res = $ilDB->query($query);
5007  $num_rows = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)->num;
5008  return $num_rows == count((array) $a_usr_ids);
5009  }
5010  // end-patch deleteProgress
5011 
5015  public function isCaptchaVerified()
5016  {
5017  return (boolean) $_SESSION["user_captcha_verified"];
5018  }
5019 
5025  public function setCaptchaVerified($a_val)
5026  {
5027  $_SESSION["user_captcha_verified"] = $a_val;
5028  }
5029 
5036  public function exportPersonalData()
5037  {
5038  include_once("./Services/Export/classes/class.ilExport.php");
5039  $exp = new ilExport();
5040  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5041  ilUtil::delDir($dir, true);
5042  $title = $this->getLastname() . ", " . $this->getLastname() . " [" . $this->getLogin() . "]";
5043  $exp->exportEntity(
5044  "personal_data",
5045  $this->getId(),
5046  "",
5047  "Services/User",
5048  $title,
5049  $dir
5050  );
5051  }
5052 
5059  public function getPersonalDataExportFile()
5060  {
5061  include_once("./Services/Export/classes/class.ilExport.php");
5062  $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5063  if (!is_dir($dir)) {
5064  return "";
5065  }
5066  foreach (ilUtil::getDir($dir) as $entry) {
5067  if (is_int(strpos($entry["entry"], ".zip"))) {
5068  return $entry["entry"];
5069  }
5070  }
5071 
5072  return "";
5073  }
5074 
5081  public function sendPersonalDataFile()
5082  {
5083  include_once("./Services/Export/classes/class.ilExport.php");
5084  $file = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data") .
5085  "/" . $this->getPersonalDataExportFile();
5086  if (is_file($file)) {
5088  }
5089  }
5090 
5097  public function importPersonalData(
5098  $a_file,
5099  $a_profile_data,
5100  $a_settings,
5101  $a_notes,
5102  $a_calendar
5103  ) {
5104  include_once("./Services/Export/classes/class.ilImport.php");
5105  $imp = new ilImport();
5106  // bookmarks need to be skipped, importer does not exist anymore
5107  $imp->addSkipImporter("Services/Bookmarks");
5108  if (!$a_profile_data) {
5109  $imp->addSkipEntity("Services/User", "usr_profile");
5110  }
5111  if (!$a_settings) {
5112  $imp->addSkipEntity("Services/User", "usr_setting");
5113  }
5114  if (!$a_notes) {
5115  $imp->addSkipEntity("Services/Notes", "user_notes");
5116  }
5117  if (!$a_calendar) {
5118  $imp->addSkipEntity("Services/Calendar", "calendar");
5119  }
5120  $imp->importEntity(
5121  $a_file["tmp_name"],
5122  $a_file["name"],
5123  "personal_data",
5124  "Services/User"
5125  );
5126  }
5127 
5133  private static function initInactivationDate($usrIds)
5134  {
5135  global $DIC;
5136 
5137  $ilDB = $DIC['ilDB'];
5138 
5139  $NOW = $ilDB->now();
5140 
5141  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5142 
5143  $queryString = "
5144  UPDATE usr_data
5145  SET inactivation_date = $NOW
5146  WHERE inactivation_date IS NULL
5147  AND $usrId_IN_usrIds
5148  ";
5149 
5150  $ilDB->manipulate($queryString);
5151  }
5152 
5158  private static function resetInactivationDate($usrIds)
5159  {
5160  global $DIC;
5161 
5162  $ilDB = $DIC['ilDB'];
5163 
5164  $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5165 
5166  $queryString = "
5167  UPDATE usr_data
5168  SET inactivation_date = NULL
5169  WHERE $usrId_IN_usrIds
5170  ";
5171 
5172  $ilDB->manipulate($queryString);
5173  }
5174 
5181  {
5182  $this->inactivation_date = $inactivation_date;
5183  }
5184 
5190  public function getInactivationDate()
5191  {
5192  return $this->inactivation_date;
5193  }
5194 
5198  public function hasToAcceptTermsOfService()
5199  {
5200  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5201 
5202  if (
5204  null == $this->agree_date &&
5205  'root' != $this->login &&
5206  !in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID))
5207  ) {
5208  return true;
5209  }
5210 
5211  return false;
5212  }
5213 
5218  public static function hasUserToAcceptTermsOfService($a_username)
5219  {
5223  global $DIC;
5224 
5225  $ilDB = $DIC['ilDB'];
5226 
5227  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5228 
5230  return false;
5231  }
5232 
5233  $in = $ilDB->in('usr_id', array(ANONYMOUS_USER_ID, SYSTEM_USER_ID), true, 'integer');
5234  $res = $ilDB->queryF(
5235  "SELECT usr_id FROM usr_data WHERE login = %s AND agree_date IS NULL $in",
5236  array("text"),
5237  array($a_username)
5238  );
5239  return $ilDB->fetchAssoc($res) ? true : false;
5240  }
5241 
5249  public static function getUsersAgreed($a_agreed = true, $a_users = null)
5250  {
5251  global $DIC;
5252 
5253  $ilDB = $DIC['ilDB'];
5254 
5255  $date_is = ($a_agreed)
5256  ? "IS NOT NULL"
5257  : "IS NULL";
5258 
5259  $users = (is_array($a_users))
5260  ? " AND " . $ilDB->in("usr_id", $a_users, false, "integer")
5261  : "";
5262 
5263  $set = $ilDB->query("SELECT usr_id FROM usr_data " .
5264  " WHERE agree_date " . $date_is .
5265  $users);
5266  $ret = array();
5267  while ($rec = $ilDB->fetchAssoc($set)) {
5268  $ret[] = $rec["usr_id"];
5269  }
5270  return $ret;
5271  }
5272 
5273 
5278  public function hasToAcceptTermsOfServiceInSession($status = null)
5279  {
5280  if (null === $status) {
5281  return ilSession::get('has_to_accept_agr_in_session');
5282  }
5283 
5284  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5286  ilSession::set('has_to_accept_agr_in_session', (int) $status);
5287  }
5288  }
5289 
5293  public function isAnonymous()
5294  {
5295  return self::_isAnonymous($this->getId());
5296  }
5297 
5302  public static function _isAnonymous($usr_id)
5303  {
5304  return $usr_id == ANONYMOUS_USER_ID;
5305  }
5306 
5307  public function activateDeletionFlag()
5308  {
5309  $this->writePref("delete_flag", true);
5310  }
5311 
5312  public function removeDeletionFlag()
5313  {
5314  $this->writePref("delete_flag", false);
5315  }
5316 
5317  public function hasDeletionFlag()
5318  {
5319  return (bool) $this->getPref("delete_flag");
5320  }
5321 
5325  public function setIsSelfRegistered($status)
5326  {
5327  $this->is_self_registered = (bool) $status;
5328  }
5329 
5330  public function isSelfRegistered()
5331  {
5332  return (bool) $this->is_self_registered;
5333  }
5334 
5335 
5336  //
5337  // MULTI-TEXT / INTERESTS
5338  //
5339 
5345  public function setGeneralInterests(array $value = null)
5346  {
5347  $this->interests_general = $value;
5348  }
5349 
5355  public function getGeneralInterests()
5356  {
5357  return $this->interests_general;
5358  }
5359 
5365  public function getGeneralInterestsAsText()
5366  {
5367  return $this->buildTextFromArray("interests_general");
5368  }
5369 
5375  public function setOfferingHelp(array $value = null)
5376  {
5377  $this->interests_help_offered = $value;
5378  }
5379 
5385  public function getOfferingHelp()
5386  {
5388  }
5389 
5395  public function getOfferingHelpAsText()
5396  {
5397  return $this->buildTextFromArray("interests_help_offered");
5398  }
5399 
5405  public function setLookingForHelp(array $value = null)
5406  {
5407  $this->interests_help_looking = $value;
5408  }
5409 
5415  public function getLookingForHelp()
5416  {
5418  }
5419 
5425  public function getLookingForHelpAsText()
5426  {
5427  return $this->buildTextFromArray("interests_help_looking");
5428  }
5429 
5436  protected function buildTextFromArray($a_attr)
5437  {
5438  $current = $this->$a_attr;
5439  if (is_array($current) && sizeof($current)) {
5440  return implode(", ", $current);
5441  }
5442  }
5443 
5447  protected function readMultiTextFields()
5448  {
5449  global $DIC;
5450 
5451  $ilDB = $DIC['ilDB'];
5452 
5453  if (!$this->getId()) {
5454  return;
5455  }
5456 
5457  $set = $ilDB->query("SELECT field_id,value" .
5458  " FROM usr_data_multi" .
5459  " WHERE usr_id = " . $ilDB->quote($this->getId(), "integer") .
5460  " ORDER BY value");
5461  while ($row = $ilDB->fetchAssoc($set)) {
5462  $values[$row["field_id"]][] = $row["value"];
5463  }
5464 
5465  if (isset($values["interests_general"])) {
5466  $this->setGeneralInterests($values["interests_general"]);
5467  } else {
5468  $this->setGeneralInterests();
5469  }
5470  if (isset($values["interests_help_offered"])) {
5471  $this->setOfferingHelp($values["interests_help_offered"]);
5472  } else {
5473  $this->setOfferingHelp();
5474  }
5475  if (isset($values["interests_help_looking"])) {
5476  $this->setLookingForHelp($values["interests_help_looking"]);
5477  } else {
5478  $this->setLookingForHelp();
5479  }
5480  }
5481 
5487  public function updateMultiTextFields($a_create = false)
5488  {
5489  global $DIC;
5490 
5491  $ilDB = $DIC['ilDB'];
5492 
5493  if (!$this->getId()) {
5494  return;
5495  }
5496 
5497  if (!$a_create) {
5498  $this->deleteMultiTextFields();
5499  }
5500 
5501  $map = array(
5502  "interests_general" => $this->getGeneralInterests(),
5503  "interests_help_offered" => $this->getOfferingHelp(),
5504  "interests_help_looking" => $this->getLookingForHelp()
5505  );
5506 
5507  foreach ($map as $id => $values) {
5508  if (is_array($values) && sizeof($values)) {
5509  foreach ($values as $value) {
5510  $value = trim($value);
5511  if ($value) {
5512  $uniq_id = $ilDB->nextId('usr_data_multi');
5513 
5514  $ilDB->manipulate("INSERT usr_data_multi" .
5515  " (id,usr_id,field_id,value) VALUES" .
5516  " (" . $ilDB->quote($uniq_id, "integer") .
5517  "," . $ilDB->quote($this->getId(), "integer") .
5518  "," . $ilDB->quote($id, "text") .
5519  "," . $ilDB->quote($value, "text") .
5520  ")");
5521  }
5522  }
5523  }
5524  }
5525  }
5526 
5530  protected function deleteMultiTextFields()
5531  {
5532  global $DIC;
5533 
5534  $ilDB = $DIC['ilDB'];
5535 
5536  if (!$this->getId()) {
5537  return;
5538  }
5539 
5540  $ilDB->manipulate("DELETE FROM usr_data_multi" .
5541  " WHERE usr_id = " . $ilDB->quote($this->getId(), "integer"));
5542  }
5543 
5544  public static function findInterests($a_term, $a_user_id = null, $a_field_id = null)
5545  {
5546  global $DIC;
5547 
5548  $ilDB = $DIC['ilDB'];
5549 
5550  $res = array();
5551 
5552  $sql = "SELECT DISTINCT(value)" .
5553  " FROM usr_data_multi" .
5554  " WHERE " . $ilDB->like("value", "text", "%" . $a_term . "%");
5555  if ($a_field_id) {
5556  $sql .= " AND field_id = " . $ilDB->quote($a_field_id, "text");
5557  }
5558  if ($a_user_id) {
5559  $sql .= " AND usr_id <> " . $ilDB->quote($a_user_id, "integer");
5560  }
5561  $sql .= " ORDER BY value";
5562  $set = $ilDB->query($sql);
5563  while ($row = $ilDB->fetchAssoc($set)) {
5564  $res[] = $row["value"];
5565  }
5566 
5567  return $res;
5568  }
5569 
5579  public static function getProfileStatusOfUsers($a_user_ids)
5580  {
5581  global $DIC;
5582 
5583  $ilDB = $DIC->database();
5584 
5585  $set = $ilDB->query(
5586  "SELECT * FROM usr_pref " .
5587  " WHERE keyword = " . $ilDB->quote("public_profile", "text") .
5588  " AND " . $ilDB->in("usr_id", $a_user_ids, false, "integer")
5589  );
5590  $r = array(
5591  "global" => array(),
5592  "local" => array(),
5593  "public" => array(),
5594  "not_public" => array()
5595  );
5596  while ($rec = $ilDB->fetchAssoc($set)) {
5597  if ($rec["value"] == "g") {
5598  $r["global"][] = $rec["usr_id"];
5599  $r["public"][] = $rec["usr_id"];
5600  }
5601  if ($rec["value"] == "y") {
5602  $r["local"][] = $rec["usr_id"];
5603  $r["public"][] = $rec["usr_id"];
5604  }
5605  }
5606  foreach ($a_user_ids as $id) {
5607  if (!in_array($id, $r["public"])) {
5608  $r["not_public"][] = $id;
5609  }
5610  }
5611 
5612  return $r;
5613  }
5614 } // END class ilObjUser
getCurrentLanguage()
returns the current language (may differ from user&#39;s pref setting!)
static _lookupLogin($a_user_id)
lookup login
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
static _lookupName($a_user_id)
lookup user name
Class for user related exception handling in ILIAS.
static getUserIdsByEmail($a_email)
STATIC METHOD get all user_ids of an email address.
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.
setActive($a_active, $a_owner=0)
set user active state and updates system fields appropriately public
Class ilMailOptions this class handles user mails.
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
static _lookupSecondEmail($a_user_id)
Lookup second e-mail.
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
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.
$data
Definition: storeScorm.php:23
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 lookupMatriculation($a_usr_id)
Lookup matriculation.
Class ilUserDefinedData.
getTimeZone()
get timezone of user
$_SESSION["AccountId"]
setDepartment($a_str)
set department public
$result
static getUserIdsByInactivityPeriod(int $periodInDays)
Get ids of all users that have been inactive for at least the given period.
static styleExists($style_id)
static getFirstLettersOfLastnames(?array $user_ids=null)
Get first letters of all lastnames.
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)
static getProfileStatusOfUsers($a_user_ids)
Get profile status.
setLoginAttempts($a_login_attempts)
getLastProfilePrompt()
returns user&#39;s last profile prompt
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...
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 _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
setProfileIncomplete($a_prof_inc)
getPasswordPolicyResetStatus()
Custom block for external feeds on personal desktop.
getDepartment()
get department public
setAuthMode($a_str)
set auth mode public
setFirstLogin($a_str)
set user&#39;s first login
const IL_PASSWD_CRYPTED
static deleteByOwner($a_owner_id)
Delete all entries for owner.
static _incrementLoginAttempts($a_usr_id)
$login
all user related data in single vars public
static get($a_var)
Get a value.
getLocationZoom()
Get Location Zoom.
setId($a_id)
set object id public
static _getExternalAccountsByAuthMode($a_auth_mode, $a_read_auth_default=false)
Get list of external account by authentication method Note: If login == ext_account for two user with...
setLastProfilePrompt($a_str)
set user&#39;s last profile prompt
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
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.
login()
Definition: login.php:2
static _lookupClientIP($a_user_id)
Lookup client ip.
setLastname($a_str)
set lastame public
getCreateDate()
get create date public
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 formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static lookupTitle($a_page_id)
Lookup title.
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.
$ilErr
Definition: raiseError.php:18
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
static _getAvatar($a_usr_id)
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
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
setPasswordPolicyResetStatus(bool $status)
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...
static _lookupFirstLogin($a_user_id)
lookup first login
$a_type
Definition: workflow.php:92
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 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
getZipcode()
get zipcode public
getEmail()
get email address public
static _getAllUserData($a_fields=null, $active=-1)
STATIC METHOD get all user data.
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.
foreach($_POST as $key=> $value) $res
static execConvert($args)
execute convert command
static getUserLoginsByEmail($a_email)
get all user login names of an email address
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:93
This describes how a letter or a picture avatar could be modified during construction of UI...
Definition: Avatar.php:8
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.
Mail Box class Base class for creating and handling mail boxes.
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.
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
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.
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)
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
isCaptchaVerified()
Is user captcha verified?
$format
Definition: metadata.php:218
getLastLogin()
returns last login date public
clipboardHasObjectsOfType($a_type)
Check whether clipboard has objects of a certain type.
getOfferingHelp()
Get help offering.
$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.
setSecondEmail($second_email)
static _removeTrackingDataForUser($user_id)
$query
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 _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.
Class ilUserAvatarResolver.
const UDF_TYPE_WYSIWYG
static _lookupType($a_id, $a_reference=false)
lookup object type
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
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
setCity($a_str)
set city public
getPCClipboardContent()
Add a page content item to PC clipboard (should go to another class)
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
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
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)
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
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
static _deleteUser($a_usr_id)
setGeneralInterests(array $value=null)
Set general interests.
global $ilSetting
Definition: privfeed.php:17
static resetInactivationDate($usrIds)
type $ilDB
static _lookupEmail($a_user_id)
Lookup email.
__construct(Container $dic, ilPlugin $plugin)
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.
importPersonalData( $a_file, $a_profile_data, $a_settings, $a_notes, $a_calendar)
Import personal data.
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
setFax($a_str)
set fax public
global $ilDB
$ret
Definition: parser.php:6
$DIC
Definition: xapitoken.php:46
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.
getFirstLogin()
returns first login date
setLastPasswordChangeToNow()
static findInterests($a_term, $a_user_id=null, $a_field_id=null)
setUTitle($a_str)
set user title (note: don&#39;t mix up this method with setTitle() that is derived from ilObject and sets...
static getLogger($a_component_id)
Get component logger.
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.
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.
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
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
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.
static getUserIdsNeverLoggedIn(int $thresholdInDays)
Get ids of all users that have never logged in.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static _deleteUser($a_usr_id)
setLongitude($a_longitude)
Set Longitude.
readPrefs()
get all user preferences private
getPhoneMobile()
get mobile phone public
static _lookupLastLogin($a_user_id)
lookup last login