ILIAS  release_7 Revision v7.30-3-g800a261c036
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
6define("IL_PASSWD_PLAIN", "plain");
7define("IL_PASSWD_CRYPTED", "crypted");
8
9
10require_once "./Services/Object/classes/class.ilObject.php";
11require_once './Services/User/exceptions/class.ilUserException.php';
12require_once './Modules/OrgUnit/classes/class.ilObjOrgUnit.php';
13require_once './Modules/OrgUnit/classes/class.ilObjOrgUnitTree.php';
14
27class 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
83 public $street;
84 public $city;
85 public $zipcode;
86 public $country;
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;
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
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 {
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
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
534 // ... and update
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 'reg_hash' => null
619 );
620
621 if ($this->agree_date === null || (is_string($this->agree_date) && strtotime($this->agree_date) !== false)) {
622 $update_array["agree_date"] = array("timestamp", $this->agree_date);
623 }
624 switch ($this->passwd_type) {
625 case IL_PASSWD_PLAIN:
626 if (strlen($this->passwd)) {
627 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
628 ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
629 $update_array['passwd'] = array('text', $this->getPasswd());
630 } else {
631 $update_array["passwd"] = array("text", (string) $this->passwd);
632 }
633 break;
634
636 $update_array["passwd"] = array("text", (string) $this->passwd);
637 break;
638
639 default:
640 $ilErr->raiseError("<b>Error: passwd_type missing in function update()" . $this->id . "!</b><br />class: " .
641 get_class($this) . "<br />Script: " . __FILE__ . "<br />Line: " . __LINE__, $ilErr->FATAL);
642 }
643
644 $update_array['passwd_enc_type'] = array('text', $this->getPasswordEncodingType());
645 $update_array['passwd_salt'] = array('text', $this->getPasswordSalt());
646
647 $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
648
649 $this->updateMultiTextFields();
650
651 $this->writePrefs();
652
653 // update user defined fields
655
656 parent::update();
657 parent::updateOwner();
658
659 $this->read();
660
661 $ilAppEventHandler->raise(
662 "Services/User",
663 "afterUpdate",
664 array("user_obj" => $this)
665 );
666
667 return true;
668 }
669
673 public function writeAccepted()
674 {
675 global $DIC;
676
677 $ilDB = $DIC['ilDB'];
678
679 $ilDB->manipulateF("UPDATE usr_data SET agree_date = " . $ilDB->now() .
680 " WHERE usr_id = %s", array("integer"), array($this->getId()));
681 }
682
686 private static function _lookup($a_user_id, $a_field)
687 {
688 global $DIC;
689
690 $ilDB = $DIC['ilDB'];
691
692 $res = $ilDB->queryF(
693 "SELECT " . $a_field . " FROM usr_data WHERE usr_id = %s",
694 array("integer"),
695 array($a_user_id)
696 );
697
698 while ($set = $ilDB->fetchAssoc($res)) {
699 return $set[$a_field];
700 }
701 return false;
702 }
703
707 public static function _lookupFullname($a_user_id)
708 {
709 global $DIC;
710
711 $ilDB = $DIC['ilDB'];
712
713 $set = $ilDB->queryF(
714 "SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
715 array("integer"),
716 array($a_user_id)
717 );
718
719 if ($rec = $ilDB->fetchAssoc($set)) {
720 if ($rec["title"]) {
721 $fullname = $rec["title"] . " ";
722 }
723 if ($rec["firstname"]) {
724 $fullname .= $rec["firstname"] . " ";
725 }
726 if ($rec["lastname"]) {
727 $fullname .= $rec["lastname"];
728 }
729 }
730 return $fullname;
731 }
732
736 public static function _lookupEmail($a_user_id)
737 {
738 return ilObjUser::_lookup($a_user_id, "email");
739 }
740
746 public static function _lookupSecondEmail($a_user_id)
747 {
748 return ilObjUser::_lookup($a_user_id, "second_email");
749 }
750
754 public static function _lookupGender($a_user_id)
755 {
756 return ilObjUser::_lookup($a_user_id, "gender");
757 }
758
765 public static function _lookupClientIP($a_user_id)
766 {
767 return ilObjUser::_lookup($a_user_id, "client_ip");
768 }
769
770
776 public static function _lookupName($a_user_id)
777 {
778 global $DIC;
779
780 $ilDB = $DIC['ilDB'];
781
782 $res = $ilDB->queryF(
783 "SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
784 array("integer"),
785 array($a_user_id)
786 );
787 $user_rec = $ilDB->fetchAssoc($res);
788 return array("user_id" => $a_user_id,
789 "firstname" => $user_rec["firstname"],
790 "lastname" => $user_rec["lastname"],
791 "title" => $user_rec["title"],
792 "login" => $user_rec["login"]);
793 }
794
798 public static function _lookupFields($a_user_id)
799 {
800 global $DIC;
801
802 $ilDB = $DIC['ilDB'];
803
804 $res = $ilDB->queryF(
805 "SELECT * FROM usr_data WHERE usr_id = %s",
806 array("integer"),
807 array($a_user_id)
808 );
809 $user_rec = $ilDB->fetchAssoc($res);
810 return $user_rec;
811 }
812
816 public static function _lookupLogin($a_user_id)
817 {
818 return ilObjUser::_lookup($a_user_id, "login");
819 }
820
824 public static function _lookupExternalAccount($a_user_id)
825 {
826 return ilObjUser::_lookup($a_user_id, "ext_account");
827 }
828
832 public static function _lookupId($a_user_str)
833 {
834 global $DIC;
835
836 $ilDB = $DIC['ilDB'];
837
838 if (!is_array($a_user_str)) {
839 $res = $ilDB->queryF(
840 "SELECT usr_id FROM usr_data WHERE login = %s",
841 array("text"),
842 array($a_user_str)
843 );
844 $user_rec = $ilDB->fetchAssoc($res);
845 return $user_rec["usr_id"];
846 } else {
847 $set = $ilDB->query(
848 "SELECT usr_id FROM usr_data " .
849 " WHERE " . $ilDB->in("login", $a_user_str, false, "text")
850 );
851 $ids = array();
852 while ($rec = $ilDB->fetchAssoc($set)) {
853 $ids[] = $rec["usr_id"];
854 }
855 return $ids;
856 }
857 }
858
862 public static function _lookupLastLogin($a_user_id)
863 {
864 return ilObjUser::_lookup($a_user_id, "last_login");
865 }
866
870 public static function _lookupFirstLogin($a_user_id)
871 {
872 return ilObjUser::_lookup($a_user_id, "first_login");
873 }
874
875
881 public function refreshLogin()
882 {
883 global $DIC;
884
885 $ilDB = $DIC['ilDB'];
886
887 $ilDB->manipulateF(
888 "UPDATE usr_data SET " .
889 "last_login = " . $ilDB->now() .
890 " WHERE usr_id = %s",
891 array("integer"),
892 array($this->id)
893 );
894
895 if ($this->getFirstLogin() == "") {
896 $ilDB->manipulateF(
897 "UPDATE usr_data SET " .
898 "first_login = " . $ilDB->now() .
899 " WHERE usr_id = %s",
900 array("integer"),
901 array($this->id)
902 );
903 }
904 }
905
906
914 public function resetPassword($raw, $raw_retype)
915 {
919 global $DIC;
920
921 $ilDB = $DIC['ilDB'];
922
923 if (func_num_args() != 2) {
924 return false;
925 }
926
927 if (!isset($raw) || !isset($raw_retype)) {
928 return false;
929 }
930
931 if ($raw != $raw_retype) {
932 return false;
933 }
934
935 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
936 ilUserPasswordManager::getInstance()->encodePassword($this, $raw);
937
938 $ilDB->manipulateF(
939 'UPDATE usr_data
940 SET passwd = %s, passwd_enc_type = %s, passwd_salt = %s
941 WHERE usr_id = %s',
942 array('text', 'text', 'text', 'integer'),
943 array($this->getPasswd(), $this->getPasswordEncodingType(), $this->getPasswordSalt(), $this->getId())
944 );
945
946 return true;
947 }
948
959 public static function _doesLoginnameExistInHistory($a_login)
960 {
961 global $DIC;
962
963 $ilDB = $DIC['ilDB'];
964
965 $res = $ilDB->queryF(
966 '
967 SELECT * FROM loginname_history
968 WHERE login = %s',
969 array('text'),
970 array($a_login)
971 );
972
973 return $ilDB->fetchAssoc($res) ? true : false;
974 }
975
988 public static function _getLastHistoryDataByUserId($a_usr_id)
989 {
990 global $DIC;
991
992 $ilDB = $DIC['ilDB'];
993
994 $ilDB->setLimit(1, 0);
995 $res = $ilDB->queryF(
996 '
997 SELECT login, history_date FROM loginname_history
998 WHERE usr_id = %s ORDER BY history_date DESC',
999 array('integer'),
1000 array($a_usr_id)
1001 );
1002 $row = $ilDB->fetchAssoc($res);
1003 if (!is_array($row) || !count($row)) {
1004 throw new ilUserException('');
1005 }
1006
1007 return array(
1008 $row['login'], $row['history_date']
1009 );
1010 }
1011
1019 public function updateLogin($a_login)
1020 {
1021 global $DIC;
1022
1023 $ilDB = $DIC['ilDB'];
1024 $ilSetting = $DIC['ilSetting'];
1025
1026 if (func_num_args() != 1) {
1027 return false;
1028 }
1029
1030 if (!isset($a_login)) {
1031 return false;
1032 }
1033
1034 $former_login = self::_lookupLogin($this->getId());
1035
1036 // Update not necessary
1037 if (0 == strcmp($a_login, $former_login)) {
1038 return false;
1039 }
1040
1041 try {
1042 $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1043 } catch (ilUserException $e) {
1044 $last_history_entry = null;
1045 }
1046
1047 // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1048 if ((int) $ilSetting->get('allow_change_loginname') &&
1049 (int) $ilSetting->get('reuse_of_loginnames') == 0 &&
1050 self::_doesLoginnameExistInHistory($a_login)) {
1051 throw new ilUserException($this->lng->txt('loginname_already_exists'));
1052 } elseif ((int) $ilSetting->get('allow_change_loginname') &&
1053 (int) $ilSetting->get('loginname_change_blocking_time') &&
1054 is_array($last_history_entry) &&
1055 $last_history_entry[1] + (int) $ilSetting->get('loginname_change_blocking_time') > time()) {
1056 include_once 'Services/Calendar/classes/class.ilDate.php';
1057 throw new ilUserException(
1058 sprintf(
1059 $this->lng->txt('changing_loginname_not_possible_info'),
1061 new ilDateTime($last_history_entry[1], IL_CAL_UNIX)
1062 ),
1064 new ilDateTime(($last_history_entry[1] + (int) $ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX)
1065 )
1066 )
1067 );
1068 } else {
1069 // log old loginname in history
1070 if ((int) $ilSetting->get('allow_change_loginname') &&
1071 (int) $ilSetting->get('create_history_loginname')) {
1072 ilObjUser::_writeHistory($this->getId(), $former_login);
1073 }
1074
1075 //update login
1076 $this->login = $a_login;
1077
1078 $ilDB->manipulateF(
1079 '
1080 UPDATE usr_data
1081 SET login = %s
1082 WHERE usr_id = %s',
1083 array('text', 'integer'),
1084 array($this->getLogin(), $this->getId())
1085 );
1086 }
1087
1088 return true;
1089 }
1090
1097 public function writePref($a_keyword, $a_value)
1098 {
1099 self::_writePref($this->id, $a_keyword, $a_value);
1100 $this->setPref($a_keyword, $a_value);
1101 }
1102
1103
1109 public function deletePref($a_keyword)
1110 {
1111 self::_deletePref($this->getId(), $a_keyword);
1112 }
1113
1119 public static function _deletePref($a_user_id, $a_keyword)
1120 {
1124 global $DIC;
1125
1126 $ilDB = $DIC['ilDB'];
1127
1128 $ilDB->manipulateF(
1129 'DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s',
1130 array('integer', 'text'),
1131 array($a_user_id, $a_keyword)
1132 );
1133 }
1134
1140 public static function _deleteAllPref($a_user_id)
1141 {
1142 global $DIC;
1143
1144 $ilDB = $DIC['ilDB'];
1145
1146 $ilDB->manipulateF(
1147 "DELETE FROM usr_pref WHERE usr_id = %s",
1148 array("integer"),
1149 array($a_user_id)
1150 );
1151 }
1152
1159 public static function _writePref($a_usr_id, $a_keyword, $a_value)
1160 {
1161 global $DIC;
1162
1163 $ilDB = $DIC['ilDB'];
1164 $ilDB->replace(
1165 "usr_pref",
1166 array(
1167 "usr_id" => array("integer", $a_usr_id),
1168 "keyword" => array("text", $a_keyword),
1169 ),
1170 array(
1171 "value" => array("text",$a_value)
1172 )
1173 );
1174
1175 /*
1176 self::_deletePref($a_usr_id, $a_keyword);
1177 if(strlen($a_value))
1178 {
1179 $ilDB->manipulateF(
1180 'INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s, %s, %s)',
1181 array('integer', 'text', 'text'),
1182 array($a_usr_id, $a_keyword, $a_value)
1183 );
1184 }*/
1185 }
1186
1191 public function writePrefs()
1192 {
1193 global $DIC;
1194
1195 $ilDB = $DIC['ilDB'];
1196
1197 ilObjUser::_deleteAllPref($this->id);
1198 foreach ($this->prefs as $keyword => $value) {
1199 self::_writePref($this->id, $keyword, $value);
1200 }
1201 }
1202
1209 public function getTimeZone()
1210 {
1211 if ($tz = $this->getPref('user_tz')) {
1212 return $tz;
1213 } else {
1214 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1216 return $settings->getDefaultTimeZone();
1217 }
1218 }
1219
1226 public function getTimeFormat()
1227 {
1228 if ($format = $this->getPref('time_format')) {
1229 return $format;
1230 } else {
1231 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1233 return $settings->getDefaultTimeFormat();
1234 }
1235 }
1236
1243 public function getDateFormat()
1244 {
1245 if ($format = $this->getPref('date_format')) {
1246 return $format;
1247 } else {
1248 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1250 return $settings->getDefaultDateFormat();
1251 }
1252 }
1253
1260 public function setPref($a_keyword, $a_value)
1261 {
1262 if ($a_keyword != "") {
1263 $this->prefs[$a_keyword] = $a_value;
1264 }
1265 }
1266
1272 public function getPref($a_keyword)
1273 {
1274 if (array_key_exists($a_keyword, $this->prefs)) {
1275 return $this->prefs[$a_keyword];
1276 } else {
1277 return false;
1278 }
1279 }
1280
1281 public static function _lookupPref($a_usr_id, $a_keyword)
1282 {
1283 global $DIC;
1284
1285 $ilDB = $DIC['ilDB'];
1286
1287 $query = "SELECT * FROM usr_pref WHERE usr_id = " . $ilDB->quote($a_usr_id, "integer") . " " .
1288 "AND keyword = " . $ilDB->quote($a_keyword, "text");
1289 $res = $ilDB->query($query);
1290
1291 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1292 return $row->value;
1293 }
1294 return false;
1295 }
1296
1301 public function readPrefs()
1302 {
1303 global $DIC;
1304
1305 $ilDB = $DIC['ilDB'];
1306
1307 if (is_array($this->prefs)) {
1308 $this->oldPrefs = $this->prefs;
1309 }
1310
1311 $this->prefs = ilObjUser::_getPreferences($this->id);
1312 }
1313
1319 public function delete()
1320 {
1321 global $DIC;
1322
1323 $rbacadmin = $DIC->rbac()->admin();
1324 $ilDB = $DIC['ilDB'];
1325
1326 // deassign from ldap groups
1327 include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1329 $mapping->deleteUser($this->getId());
1330
1331 // remove mailbox / update sent mails
1332 include_once("Services/Mail/classes/class.ilMailbox.php");
1333 $mailbox = new ilMailbox($this->getId());
1334 $mailbox->delete();
1335 $mailbox->updateMailsOfDeletedUser($this->getLogin());
1336
1337 // delete feed blocks on personal desktop
1338 include_once("./Services/Block/classes/class.ilCustomBlock.php");
1339 $costum_block = new ilCustomBlock();
1340 $costum_block->setContextObjId($this->getId());
1341 $costum_block->setContextObjType("user");
1342 $c_blocks = $costum_block->queryBlocksForContext();
1343 include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1344 foreach ($c_blocks as $c_block) {
1345 if ($c_block["type"] == "pdfeed") {
1346 $fb = new ilPDExternalFeedBlock($c_block["id"]);
1347 $fb->delete();
1348 }
1349 }
1350
1351
1352 // delete block settings
1353 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1355
1356 // delete user_account
1357 $ilDB->manipulateF(
1358 "DELETE FROM usr_data WHERE usr_id = %s",
1359 array("integer"),
1360 array($this->getId())
1361 );
1362
1363 $this->deleteMultiTextFields();
1364
1365 // delete user_prefs
1367
1368 $this->removeUserPicture(false); // #8597
1369
1370 // delete user_session
1371 include_once("./Services/Authentication/classes/class.ilSession.php");
1373
1374 // remove user from rbac
1375 $rbacadmin->removeUser($this->getId());
1376
1377 // remove bookmarks
1378 // TODO: move this to class.ilBookmarkFolder
1379 $q = "DELETE FROM bookmark_tree WHERE tree = " .
1380 $ilDB->quote($this->getId(), "integer");
1381 $ilDB->manipulate($q);
1382
1383 $q = "DELETE FROM bookmark_data WHERE user_id = " .
1384 $ilDB->quote($this->getId(), "integer");
1385 $ilDB->manipulate($q);
1386
1387 // DELETE FORUM ENTRIES (not complete in the moment)
1388 include_once './Modules/Forum/classes/class.ilObjForum.php';
1390
1391 // Delete link check notify entries
1392 include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
1394
1395 // Delete crs entries
1396 include_once './Modules/Course/classes/class.ilObjCourse.php';
1398
1399 // Delete user tracking
1400 include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1402
1403 include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1405
1406 // Delete Tracking data SCORM 2004 RTE
1407 include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1409
1410 // Delete Tracking data SCORM 1.2 RTE
1411 include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1413
1414 // remove all notifications
1415 include_once "./Services/Notification/classes/class.ilNotification.php";
1417
1418 // remove portfolios
1419 include_once "./Modules/Portfolio/classes/class.ilObjPortfolio.php";
1421
1422 // remove workspace
1423 include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1424 $tree = new ilWorkspaceTree($this->getId());
1425 $tree->cascadingDelete();
1426
1427 // remove reminder entries
1428 require_once 'Services/User/classes/class.ilCronDeleteInactiveUserReminderMail.php';
1430
1431 // badges
1432 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
1434
1435 // remove org unit assignments
1436 $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
1437 $ilOrgUnitUserAssignmentQueries->deleteAllAssignmentsOfUser($this->getId());
1438
1439 // Delete user defined field entries
1441
1442 // Delete clipboard entries
1443 $this->clipboardDeleteAll();
1444
1445 // Reset owner
1446 $this->resetOwner();
1447
1448 // Trigger deleteUser Event
1449 global $DIC;
1450
1451 $ilAppEventHandler = $DIC['ilAppEventHandler'];
1452 $ilAppEventHandler->raise(
1453 'Services/User',
1454 'deleteUser',
1455 array('usr_id' => $this->getId())
1456 );
1457
1458 // delete object data
1459 parent::delete();
1460 return true;
1461 }
1462
1472 public function setFullname($a_title = "", $a_firstname = "", $a_lastname = "")
1473 {
1474 $this->fullname = "";
1475
1476 if ($a_title) {
1477 $fullname = $a_title . " ";
1478 } elseif ($this->utitle) {
1479 $this->fullname = $this->utitle . " ";
1480 }
1481
1482 if ($a_firstname) {
1483 $fullname .= $a_firstname . " ";
1484 } elseif ($this->firstname) {
1485 $this->fullname .= $this->firstname . " ";
1486 }
1487
1488 if ($a_lastname) {
1489 return $fullname . $a_lastname;
1490 }
1491
1492 $this->fullname .= $this->lastname;
1493 }
1494
1509 public function getFullname($a_max_strlen = 0)
1510 {
1511 if (!$a_max_strlen) {
1512 return ilUtil::stripSlashes($this->fullname);
1513 }
1514
1515 if (strlen($this->fullname) <= $a_max_strlen) {
1516 return ilUtil::stripSlashes($this->fullname);
1517 }
1518
1519 if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen) {
1520 return ilUtil::stripSlashes($this->utitle . " " . substr($this->firstname, 0, 1) . ". " . $this->lastname);
1521 }
1522
1523 if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen) {
1524 return ilUtil::stripSlashes($this->firstname . " " . $this->lastname);
1525 }
1526
1527 if ((strlen($this->lastname) + 3) <= $a_max_strlen) {
1528 return ilUtil::stripSlashes(substr($this->firstname, 0, 1) . ". " . $this->lastname);
1529 }
1530
1531 return ilUtil::stripSlashes(substr($this->lastname, 0, $a_max_strlen));
1532 }
1533
1539 public function setLogin($a_str)
1540 {
1541 $this->login = $a_str;
1542 }
1543
1548 public function getLogin()
1549 {
1550 return $this->login;
1551 }
1552
1558 public function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1559 {
1560 $this->passwd = $a_str;
1561 $this->passwd_type = $a_type;
1562 }
1563
1571 public function getPasswd()
1572 {
1573 return $this->passwd;
1574 }
1581 public function getPasswdType()
1582 {
1583 return $this->passwd_type;
1584 }
1585
1591 public function setGender($a_str)
1592 {
1593 $this->gender = substr($a_str, -1);
1594 }
1595
1600 public function getGender()
1601 {
1602 return $this->gender;
1603 }
1604
1612 public function setUTitle($a_str)
1613 {
1614 $this->utitle = $a_str;
1615 }
1616
1623 public function getUTitle()
1624 {
1625 return $this->utitle;
1626 }
1627
1633 public function setFirstname($a_str)
1634 {
1635 $this->firstname = $a_str;
1636 }
1637
1642 public function getFirstname()
1643 {
1644 return $this->firstname;
1645 }
1646
1652 public function setLastname($a_str)
1653 {
1654 $this->lastname = $a_str;
1655 }
1656
1661 public function getLastname()
1662 {
1663 return $this->lastname;
1664 }
1665
1671 public function setInstitution($a_str)
1672 {
1673 $this->institution = $a_str;
1674 }
1675
1680 public function getInstitution()
1681 {
1682 return $this->institution;
1683 }
1684
1690 public function setDepartment($a_str)
1691 {
1692 $this->department = $a_str;
1693 }
1694
1699 public function getDepartment()
1700 {
1701 return $this->department;
1702 }
1703
1709 public function setStreet($a_str)
1710 {
1711 $this->street = $a_str;
1712 }
1713
1718 public function getStreet()
1719 {
1720 return $this->street;
1721 }
1722
1728 public function setCity($a_str)
1729 {
1730 $this->city = $a_str;
1731 }
1732
1737 public function getCity()
1738 {
1739 return $this->city;
1740 }
1741
1747 public function setZipcode($a_str)
1748 {
1749 $this->zipcode = $a_str;
1750 }
1751
1756 public function getZipcode()
1757 {
1758 return $this->zipcode;
1759 }
1760
1767 public function setCountry($a_str)
1768 {
1769 $this->country = $a_str;
1770 }
1771
1777 public function getCountry()
1778 {
1779 return $this->country;
1780 }
1781
1787 public function setSelectedCountry($a_val)
1788 {
1789 $this->sel_country = $a_val;
1790 }
1791
1797 public function getSelectedCountry()
1798 {
1799 return $this->sel_country;
1800 }
1801
1807 public function setPhoneOffice($a_str)
1808 {
1809 $this->phone_office = $a_str;
1810 }
1811
1816 public function getPhoneOffice()
1817 {
1818 return $this->phone_office;
1819 }
1820
1826 public function setPhoneHome($a_str)
1827 {
1828 $this->phone_home = $a_str;
1829 }
1830
1835 public function getPhoneHome()
1836 {
1837 return $this->phone_home;
1838 }
1839
1845 public function setPhoneMobile($a_str)
1846 {
1847 $this->phone_mobile = $a_str;
1848 }
1849
1854 public function getPhoneMobile()
1855 {
1856 return $this->phone_mobile;
1857 }
1858
1864 public function setFax($a_str)
1865 {
1866 $this->fax = $a_str;
1867 }
1868
1873 public function getFax()
1874 {
1875 return $this->fax;
1876 }
1877
1883 public function setClientIP($a_str)
1884 {
1885 $this->client_ip = $a_str;
1886 }
1887
1892 public function getClientIP()
1893 {
1894 return $this->client_ip;
1895 }
1896
1902 public function setMatriculation($a_str)
1903 {
1904 $this->matriculation = $a_str;
1905 }
1906
1911 public function getMatriculation()
1912 {
1913 return $this->matriculation;
1914 }
1915
1922 public static function lookupMatriculation($a_usr_id)
1923 {
1924 global $DIC;
1925
1926 $ilDB = $DIC['ilDB'];
1927
1928 $query = "SELECT matriculation FROM usr_data " .
1929 "WHERE usr_id = " . $ilDB->quote($a_usr_id);
1930 $res = $ilDB->query($query);
1931 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
1932 return $row->matriculation ? $row->matriculation : '';
1933 }
1934
1940 public function setEmail($a_str)
1941 {
1942 $this->email = $a_str;
1943 }
1944
1949 public function getEmail()
1950 {
1951 return $this->email;
1952 }
1953
1957 public function getSecondEmail()
1958 {
1959 return $this->second_email;
1960 }
1961
1966 {
1967 $this->second_email = $second_email;
1968 }
1969
1975 public function setHobby($a_str)
1976 {
1977 $this->hobby = $a_str;
1978 }
1979
1984 public function getHobby()
1985 {
1986 return $this->hobby;
1987 }
1988
1994 public function setLanguage($a_str)
1995 {
1996 $this->setPref("language", $a_str);
1997 unset($_SESSION['lang']);
1998 }
1999
2005 public function getLanguage()
2006 {
2007 return $this->prefs["language"];
2008 }
2009
2010 public function setLastPasswordChangeTS($a_last_password_change_ts)
2011 {
2012 $this->last_password_change_ts = $a_last_password_change_ts;
2013 }
2014
2015 public function getLastPasswordChangeTS()
2016 {
2018 }
2019
2023 public function getPasswordPolicyResetStatus() : bool
2024 {
2025 return (bool) $this->passwd_policy_reset;
2026 }
2027
2031 public function setPasswordPolicyResetStatus(bool $status)
2032 {
2033 $this->passwd_policy_reset = $status;
2034 }
2035
2036 public static function _lookupLanguage($a_usr_id)
2037 {
2038 global $DIC;
2039
2040 $ilDB = $DIC->database();
2041 $lng = $DIC->language();
2042
2043 $q = "SELECT value FROM usr_pref WHERE usr_id= " .
2044 $ilDB->quote($a_usr_id, "integer") . " AND keyword = " .
2045 $ilDB->quote('language', "text");
2046 $r = $ilDB->query($q);
2047
2048 while ($row = $ilDB->fetchAssoc($r)) {
2049 return $row['value'];
2050 }
2051 if (is_object($lng)) {
2052 return $lng->getDefaultLanguage();
2053 }
2054 return 'en';
2055 }
2056
2057 public static function _writeExternalAccount($a_usr_id, $a_ext_id)
2058 {
2059 global $DIC;
2060
2061 $ilDB = $DIC['ilDB'];
2062
2063 $ilDB->manipulateF(
2064 "UPDATE usr_data " .
2065 " SET ext_account = %s WHERE usr_id = %s",
2066 array("text", "integer"),
2067 array($a_ext_id, $a_usr_id)
2068 );
2069 }
2070
2071 public static function _writeAuthMode($a_usr_id, $a_auth_mode)
2072 {
2073 global $DIC;
2074
2075 $ilDB = $DIC['ilDB'];
2076
2077 $ilDB->manipulateF(
2078 "UPDATE usr_data " .
2079 " SET auth_mode = %s WHERE usr_id = %s",
2080 array("text", "integer"),
2081 array($a_auth_mode, $a_usr_id)
2082 );
2083 }
2084
2089 public function getCurrentLanguage()
2090 {
2091 return $_SESSION['lang'];
2092 }
2093
2099 public function setCurrentLanguage($a_val)
2100 {
2101 $_SESSION['lang'] = $a_val;
2102 }
2103
2109 public function setLastLogin($a_str)
2110 {
2111 $this->last_login = $a_str;
2112 }
2113
2119 public function getLastLogin()
2120 {
2121 return $this->last_login;
2122 }
2123
2128 public function setFirstLogin($a_str)
2129 {
2130 $this->first_login = $a_str;
2131 }
2132
2137 public function getFirstLogin()
2138 {
2139 return $this->first_login;
2140 }
2141
2146 public function setLastProfilePrompt($a_str)
2147 {
2148 $this->last_profile_prompt = $a_str;
2149 }
2150
2155 public function getLastProfilePrompt()
2156 {
2158 }
2159
2165 public function setLastUpdate($a_str)
2166 {
2167 $this->last_update = $a_str;
2168 }
2169 public function getLastUpdate()
2170 {
2171 return $this->last_update;
2172 }
2173
2179 public function setComment($a_str)
2180 {
2181 $this->referral_comment = $a_str;
2182 }
2183
2188 public function getComment()
2189 {
2191 }
2192
2199 public function setApproveDate($a_str)
2200 {
2201 $this->approve_date = $a_str;
2202 }
2203
2209 public function getApproveDate()
2210 {
2211 return $this->approve_date;
2212 }
2213
2219 public function getAgreeDate()
2220 {
2221 return $this->agree_date;
2222 }
2229 public function setAgreeDate($a_str)
2230 {
2231 $this->agree_date = $a_str;
2232 }
2233
2240 public function setActive($a_active, $a_owner = 0)
2241 {
2242 $this->setOwner($a_owner);
2243
2244 if ($a_active) {
2245 $this->active = 1;
2246 $this->setApproveDate(date('Y-m-d H:i:s'));
2247 $this->setOwner($a_owner);
2248 } else {
2249 $this->active = 0;
2250 $this->setApproveDate(null);
2251 }
2252 }
2253
2258 public function getActive()
2259 {
2260 return $this->active;
2261 }
2262
2266 public static function _lookupActive($a_usr_id)
2267 {
2268 global $DIC;
2269
2270 $ilDB = $DIC['ilDB'];
2271
2272 $query = 'SELECT usr_id FROM usr_data ' .
2273 'WHERE active = ' . $ilDB->quote(1, 'integer') . ' ' .
2274 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
2275 $res = $ilDB->query($query);
2276 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2277 return true;
2278 }
2279 return false;
2280 }
2281
2287 public function syncActive()
2288 {
2289 $storedActive = 0;
2290 if ($this->getStoredActive($this->id)) {
2291 $storedActive = 1;
2292 }
2293
2294 $currentActive = 0;
2295 if ($this->active) {
2296 $currentActive = 1;
2297 }
2298
2299 if ((!empty($storedActive) && empty($currentActive)) ||
2300 (empty($storedActive) && !empty($currentActive))) {
2301 $this->setActive($currentActive, self::getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2302 }
2303 }
2304
2311 public function getStoredActive($a_id)
2312 {
2313 $active = ilObjUser::_lookup($a_id, "active");
2314 return $active ? true : false;
2315 }
2316
2322 public function setSkin($a_str)
2323 {
2324 // TODO: exception handling (dir exists)
2325 $this->skin = $a_str;
2326 }
2327
2328 public function setTimeLimitOwner($a_owner)
2329 {
2330 $this->time_limit_owner = $a_owner;
2331 }
2332 public function getTimeLimitOwner()
2333 {
2334 return $this->time_limit_owner ? $this->time_limit_owner : 7;
2335 }
2336 public function setTimeLimitFrom($a_from)
2337 {
2338 $this->time_limit_from = $a_from;
2339 }
2340 public function getTimeLimitFrom()
2341 {
2342 return $this->time_limit_from;
2343 }
2344 public function setTimeLimitUntil($a_until)
2345 {
2346 $this->time_limit_until = $a_until;
2347 }
2348 public function getTimeLimitUntil()
2349 {
2350 return $this->time_limit_until;
2351 }
2352 public function setTimeLimitUnlimited($a_unlimited)
2353 {
2354 $this->time_limit_unlimited = $a_unlimited;
2355 }
2356 public function getTimeLimitUnlimited()
2357 {
2358 return $this->time_limit_unlimited;
2359 }
2360 public function setTimeLimitMessage($a_time_limit_message)
2361 {
2362 return $this->time_limit_message = $a_time_limit_message;
2363 }
2364 public function getTimeLimitMessage()
2365 {
2366 return $this->time_limit_message;
2367 }
2368
2369 public function setLoginAttempts($a_login_attempts)
2370 {
2371 $this->login_attempts = $a_login_attempts;
2372 }
2373
2374 public function getLoginAttempts()
2375 {
2376 return $this->login_attempts;
2377 }
2378
2379
2380 public function checkTimeLimit()
2381 {
2382 if ($this->getTimeLimitUnlimited()) {
2383 return true;
2384 }
2385 if ($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time()) {
2386 return true;
2387 }
2388 return false;
2389 }
2390 public function setProfileIncomplete($a_prof_inc)
2391 {
2392 $this->profile_incomplete = (boolean) $a_prof_inc;
2393 }
2394 public function getProfileIncomplete()
2395 {
2396 if ($this->id == ANONYMOUS_USER_ID) {
2397 return false;
2398 }
2399 return $this->profile_incomplete;
2400 }
2401
2406 {
2407 if ($this->id == ANONYMOUS_USER_ID) {
2408 return false;
2409 }
2410
2411 if ($this->id == SYSTEM_USER_ID) {
2412 if (
2413 \ilUserPasswordManager::getInstance()->verifyPassword($this, base64_decode('aG9tZXI=')) &&
2415 ) {
2416 return true;
2417 } else {
2418 return false;
2419 }
2420 }
2421
2423
2424 $authModeAllowsPasswordChange = !ilAuthUtils::_needsExternalAccountByAuthMode($this->getAuthMode(true));
2425 $passwordResetOnFirstLogin = (
2426 $security->isPasswordChangeOnFirstLoginEnabled() &&
2427 $this->getLastPasswordChangeTS() == 0 && $this->is_self_registered == false
2428 );
2429 $passwordResetOnChangedPolicy = $this->getPasswordPolicyResetStatus();
2430
2431 return ($authModeAllowsPasswordChange && ($passwordResetOnFirstLogin || $passwordResetOnChangedPolicy));
2432 }
2433
2434 public function isPasswordExpired()
2435 {
2436 if ($this->id == ANONYMOUS_USER_ID) {
2437 return false;
2438 }
2439
2440 require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2442 if ($this->getLastPasswordChangeTS() > 0) {
2443 $max_pass_age = $security->getPasswordMaxAge();
2444 if ($max_pass_age > 0) {
2445 $max_pass_age_ts = ($max_pass_age * 86400);
2446 $pass_change_ts = $this->getLastPasswordChangeTS();
2447 $current_ts = time();
2448
2449 if (($current_ts - $pass_change_ts) > $max_pass_age_ts) {
2451 return true;
2452 }
2453 }
2454 }
2455 }
2456
2457 return false;
2458 }
2459
2460 public function getPasswordAge()
2461 {
2462 $current_ts = time();
2463 $pass_change_ts = $this->getLastPasswordChangeTS();
2464 $password_age = (int) (($current_ts - $pass_change_ts) / 86400);
2465 return $password_age;
2466 }
2467
2469 {
2470 global $DIC;
2471
2472 $ilDB = $DIC['ilDB'];
2473
2474 $this->setLastPasswordChangeTS(time());
2475
2476 $query = "UPDATE usr_data SET last_password_change = %s " .
2477 "WHERE usr_id = %s";
2478 $affected = $ilDB->manipulateF(
2479 $query,
2480 array('integer','integer'),
2481 array($this->getLastPasswordChangeTS(),$this->id)
2482 );
2483 if ($affected) {
2484 return true;
2485 } else {
2486 return false;
2487 }
2488 }
2489
2490 public function resetLastPasswordChange()
2491 {
2492 global $DIC;
2493
2494 $ilDB = $DIC['ilDB'];
2495
2496 $query = "UPDATE usr_data SET last_password_change = 0 " .
2497 "WHERE usr_id = %s";
2498 $affected = $ilDB->manipulateF(
2499 $query,
2500 array('integer'),
2501 array($this->getId())
2502 );
2503 if ($affected) {
2504 return true;
2505 } else {
2506 return false;
2507 }
2508 }
2509
2515 public function setLatitude($a_latitude)
2516 {
2517 $this->latitude = $a_latitude;
2518 }
2519
2525 public function getLatitude()
2526 {
2527 return $this->latitude;
2528 }
2529
2535 public function setLongitude($a_longitude)
2536 {
2537 $this->longitude = $a_longitude;
2538 }
2539
2545 public function getLongitude()
2546 {
2547 return $this->longitude;
2548 }
2549
2555 public function setLocationZoom($a_locationzoom)
2556 {
2557 $this->loc_zoom = $a_locationzoom;
2558 }
2559
2565 public function getLocationZoom()
2566 {
2567 return $this->loc_zoom;
2568 }
2569
2570
2576 public static function hasActiveSession($a_user_id, $a_session_id)
2577 {
2578 global $DIC;
2579
2580 $ilDB = $DIC['ilDB'];
2581
2582 $set = $ilDB->queryf(
2583 '
2584 SELECT COUNT(*) session_count
2585 FROM usr_session WHERE user_id = %s AND expires > %s AND session_id != %s ',
2586 array('integer', 'integer', 'text'),
2587 array($a_user_id, time(), $a_session_id)
2588 );
2589 $row = $ilDB->fetchAssoc($set);
2590 return (bool) $row['session_count'];
2591 }
2592
2593 /*
2594 * check user id with login name
2595 * @access public
2596 */
2597 public function checkUserId()
2598 {
2599 global $DIC;
2600
2601 $ilSetting = $DIC['ilSetting'];
2602
2605 if ($id > 0) {
2606 return $id;
2607 }
2608 return false;
2609 }
2610
2614 private static function getLoginFromAuth()
2615 {
2616 $uid = $GLOBALS['DIC']['ilAuthSession']->getUserId();
2618
2619 // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2620 require_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2623 }
2624 return $login;
2625 }
2626
2633 public static function toUsernameWithoutDomain($a_login)
2634 {
2635 // Remove all characters including the last slash or the last backslash
2636 // in the username
2637 $pos = strrpos($a_login, '/');
2638 $pos2 = strrpos($a_login, '\\');
2639 if ($pos === false || $pos < $pos2) {
2640 $pos = $pos2;
2641 }
2642 if ($pos !== false) {
2643 $a_login = substr($a_login, $pos + 1);
2644 }
2645 return $a_login;
2646 }
2647
2648 /*
2649 * check to see if current user has been made active
2650 * @access public
2651 * @return true if active, otherwise false
2652 */
2653 public function isCurrentUserActive()
2654 {
2655 global $DIC;
2656
2657 $ilDB = $DIC['ilDB'];
2658
2660 $set = $ilDB->queryF(
2661 "SELECT active FROM usr_data WHERE login= %s",
2662 array("text"),
2663 array($login)
2664 );
2665 //query has got a result
2666 if ($rec = $ilDB->fetchAssoc($set)) {
2667 if ($rec["active"]) {
2668 return true;
2669 }
2670 }
2671
2672 return false;
2673 }
2674
2675 /*
2676 * STATIC METHOD
2677 * get the user_id of a login name
2678 * @param string login name
2679 * @return integer id of user
2680 * @static
2681 * @access public
2682 */
2683 public static function getUserIdByLogin($a_login)
2684 {
2685 return (int) ilObjUser::_lookupId($a_login);
2686 }
2687
2696 public static function getUserIdsByEmail($a_email) : array
2697 {
2698 global $DIC;
2699
2700 $ilias = $DIC['ilias'];
2701 $ilDB = $DIC['ilDB'];
2702
2703 $res = $ilDB->queryF(
2704 "SELECT usr_id FROM usr_data " .
2705 "WHERE email = %s and active = 1",
2706 array("text"),
2707 array($a_email)
2708 );
2709 $ids = array();
2710 while ($row = $ilDB->fetchObject($res)) {
2711 $ids[] = $row->usr_id;
2712 }
2713
2714 return $ids;
2715 }
2716
2717
2724 public static function getUserLoginsByEmail($a_email) : array
2725 {
2726 global $DIC;
2727
2728 $ilDB = $DIC->database();
2729
2730 $res = $ilDB->queryF(
2731 "SELECT login FROM usr_data " .
2732 "WHERE email = %s and active = 1",
2733 array("text"),
2734 array($a_email)
2735 );
2736 $ids = array();
2737 while ($row = $ilDB->fetchObject($res)) {
2738 $ids[] = $row->login;
2739 }
2740
2741 return $ids;
2742 }
2743
2744 /*
2745 * STATIC METHOD
2746 * get the login name of a user_id
2747 * @param integer id of user
2748 * @return string login name; false if not found
2749 * @static
2750 * @access public
2751 */
2752 public function getLoginByUserId($a_userid)
2753 {
2754 $login = ilObjUser::_lookupLogin($a_userid);
2755 return $login ? $login : false;
2756 }
2757
2768 public static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = false)
2769 {
2770 global $DIC;
2771
2772 $ilias = $DIC['ilias'];
2773 $ilDB = $DIC['ilDB'];
2774 $ilLog = $DIC['ilLog'];
2775
2776
2777 $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2778
2779 $without_anonymous_users = true;
2780
2781 // determine join filter
2782 $join_filter = " WHERE ";
2783 if ($filter_settings !== false && strlen($filter_settings)) {
2784 switch ($filter_settings) {
2785 case 3:
2786 // show only users without courses
2787 $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.usr_id IS NULL AND ";
2788 break;
2789 case 5:
2790 // show only users with a certain course membership
2791 $ref_id = $_SESSION["user_filter_data"];
2792 if ($ref_id) {
2793 $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.obj_id = " .
2794 "(SELECT obj_id FROM object_reference WHERE ref_id = " . $ilDB->quote($ref_id, "integer") . ") AND ";
2795 }
2796 break;
2797 case 6:
2798 global $DIC;
2799
2800 $rbacreview = $DIC['rbacreview'];
2801 $ref_id = $_SESSION["user_filter_data"];
2802 if ($ref_id) {
2803 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
2804 if (is_array($local_roles) && count($local_roles)) {
2805 $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE " .
2806 $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles) . " AND ";
2807 }
2808 }
2809 break;
2810 case 7:
2811 global $DIC;
2812
2813 $rbacreview = $DIC['rbacreview'];
2814 $rol_id = $_SESSION["user_filter_data"];
2815 if ($rol_id) {
2816 $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = " .
2817 $ilDB->quote($rol_id, "integer") . " AND ";
2818 $without_anonymous_users = false;
2819 }
2820 break;
2821 }
2822 }
2823 // This is a temporary hack to search users by their role
2824 // See Mantis #338. This is a hack due to Mantis #337.
2825 if (strtolower(substr($a_search_str, 0, 5)) == "role:") {
2826 $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email " .
2827 "FROM object_data,rbac_ua,usr_data " .
2828 "WHERE " . $ilDB->like("object_data.title", "text", "%" . substr($a_search_str, 5) . "%") .
2829 " AND object_data.type = 'role' " .
2830 "AND rbac_ua.rol_id = object_data.obj_id " .
2831 "AND usr_data.usr_id = rbac_ua.usr_id " .
2832 "AND rbac_ua.usr_id != " . $ilDB->quote(ANONYMOUS_USER_ID, "integer");
2833 } else {
2834 $query .= $join_filter .
2835 "(" . $ilDB->like("usr_data.login", "text", "%" . $a_search_str . "%") . " " .
2836 "OR " . $ilDB->like("usr_data.firstname", "text", "%" . $a_search_str . "%") . " " .
2837 "OR " . $ilDB->like("usr_data.lastname", "text", "%" . $a_search_str . "%") . " " .
2838 "OR " . $ilDB->like("usr_data.email", "text", "%" . $a_search_str . "%") . ") ";
2839
2840 if ($filter_settings !== false && strlen($filter_settings)) {
2841 switch ($filter_settings) {
2842 case 0:
2843 $query .= " AND usr_data.active = " . $ilDB->quote(0, "integer") . " ";
2844 break;
2845 case 1:
2846 $query .= " AND usr_data.active = " . $ilDB->quote(1, "integer") . " ";
2847 break;
2848 case 2:
2849 $query .= " AND usr_data.time_limit_unlimited = " . $ilDB->quote(0, "integer") . " ";
2850 break;
2851 case 4:
2852 $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"]));
2853 $query .= " AND last_login < " . $ilDB->quote($date, "timestamp") . " ";
2854 break;
2855 }
2856 }
2857
2858 if ($without_anonymous_users) {
2859 $query .= "AND usr_data.usr_id != " . $ilDB->quote(ANONYMOUS_USER_ID, "integer");
2860 }
2861
2862 if (is_numeric($active) && $active > -1 && $filter_settings === false) {
2863 $query .= " AND active = " . $ilDB->quote($active, "integer") . " ";
2864 }
2865 }
2866 $ilLog->write($query);
2867 $res = $ilDB->query($query);
2868 while ($row = $ilDB->fetchObject($res)) {
2869 $users[] = array(
2870 "usr_id" => $row->usr_id,
2871 "login" => $row->login,
2872 "firstname" => $row->firstname,
2873 "lastname" => $row->lastname,
2874 "email" => $row->email,
2875 "active" => $row->active);
2876 $ids[] = $row->usr_id;
2877 }
2878 if ($a_return_ids_only) {
2879 return $ids ? $ids : array();
2880 } else {
2881 return $users ? $users : array();
2882 }
2883 }
2884
2888 public static function getAllUserLogins()
2889 {
2893 global $DIC;
2894
2895 $ilDB = $DIC['ilDB'];
2896
2897 $logins = array();
2898
2899 $res = $ilDB->query(
2900 "SELECT login FROM usr_data WHERE " . $ilDB->in('usr_id', array(ANONYMOUS_USER_ID), true, 'integer')
2901 );
2902 while ($row = $ilDB->fetchAssoc($res)) {
2903 $logins[] = $row['login'];
2904 }
2905
2906 return $logins;
2907 }
2908
2917 public static function _readUsersProfileData($a_user_ids)
2918 {
2919 global $DIC;
2920
2921 $ilDB = $DIC['ilDB'];
2922 $res = $ilDB->query("SELECT * FROM usr_data WHERE " .
2923 $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2924 while ($row = $ilDB->fetchAssoc($res)) {
2925 $user_data["$row[usr_id]"] = $row;
2926 }
2927 return $user_data ? $user_data : array();
2928 }
2929
2938 public static function _getAllUserData($a_fields = null, $active = -1)
2939 {
2940 global $DIC;
2941
2942 $ilDB = $DIC['ilDB'];
2943
2944 $result_arr = array();
2945 $types = array();
2946 $values = array();
2947
2948 if ($a_fields !== null and is_array($a_fields)) {
2949 if (count($a_fields) == 0) {
2950 $select = "*";
2951 } else {
2952 if (($usr_id_field = array_search("usr_id", $a_fields)) !== false) {
2953 unset($a_fields[$usr_id_field]);
2954 }
2955
2956 $select = implode(",", $a_fields) . ",usr_data.usr_id";
2957 // online time
2958 if (in_array('online_time', $a_fields)) {
2959 $select .= ",ut_online.online_time ";
2960 }
2961 }
2962
2963 $q = "SELECT " . $select . " FROM usr_data ";
2964
2965 // Add online_time if desired
2966 // Need left join here to show users that never logged in
2967 if (in_array('online_time', $a_fields)) {
2968 $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2969 }
2970
2971 switch ($active) {
2972 case 0:
2973 case 1:
2974 $q .= "WHERE active = " . $ilDB->quote($active, "integer");
2975 break;
2976 case 2:
2977 $q .= "WHERE time_limit_unlimited= " . $ilDB->quote(0, "integer");;
2978 break;
2979 case 3:
2980 $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND " .
2981 $ilDB->like("object_data.title", "text", "%crs%") . " AND usr_data.usr_id = rbac_ua.usr_id";
2982 $r = $ilDB->query($qtemp);
2983 $course_users = array();
2984 while ($row = $ilDB->fetchAssoc($r)) {
2985 array_push($course_users, $row["usr_id"]);
2986 }
2987 if (count($course_users)) {
2988 $q .= " WHERE " . $ilDB->in("usr_data.usr_id", $course_users, true, "integer") . " ";
2989 } else {
2990 return $result_arr;
2991 }
2992 break;
2993 case 4:
2994 $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"]));
2995 $q .= " AND last_login < " . $ilDB->quote($date, "timestamp");
2996 break;
2997 case 5:
2998 $ref_id = $_SESSION["user_filter_data"];
2999 if ($ref_id) {
3000 $q .= " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id " .
3001 "WHERE obj_members.obj_id = (SELECT obj_id FROM object_reference " .
3002 "WHERE ref_id = " . $ilDB->quote($ref_id, "integer") . ") ";
3003 }
3004 break;
3005 case 6:
3006 global $DIC;
3007
3008 $rbacreview = $DIC['rbacreview'];
3009 $ref_id = $_SESSION["user_filter_data"];
3010 if ($ref_id) {
3011 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
3012 if (is_array($local_roles) && count($local_roles)) {
3013 $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE " .
3014 $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer") . " ";
3015 }
3016 }
3017 break;
3018 case 7:
3019 $rol_id = $_SESSION["user_filter_data"];
3020 if ($rol_id) {
3021 $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = " .
3022 $ilDB->quote($rol_id, "integer");
3023 }
3024 break;
3025 }
3026 $r = $ilDB->query($q);
3027
3028 while ($row = $ilDB->fetchAssoc($r)) {
3029 $result_arr[] = $row;
3030 }
3031 }
3032
3033 return $result_arr;
3034 }
3035
3039 public static function _getNumberOfUsersForStyle($a_skin, $a_style)
3040 {
3041 global $DIC;
3042
3043 $ilDB = $DIC['ilDB'];
3044
3045 $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 " .
3046 " WHERE up1.keyword= " . $ilDB->quote("style", "text") .
3047 " AND up1.value= " . $ilDB->quote($a_style, "text") .
3048 " AND up2.keyword= " . $ilDB->quote("skin", "text") .
3049 " AND up2.value= " . $ilDB->quote($a_skin, "text") .
3050 " AND up1.usr_id = up2.usr_id ";
3051
3052 $cnt_set = $ilDB->query($q);
3053
3054 $cnt_rec = $ilDB->fetchAssoc($cnt_set);
3055
3056 return $cnt_rec["cnt"];
3057 }
3058
3062 public static function _getAllUserAssignedStyles()
3063 {
3064 global $DIC;
3065
3066 $ilDB = $DIC['ilDB'];
3067
3068 $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 " .
3069 " WHERE up1.keyword = " . $ilDB->quote("style", "text") .
3070 " AND up2.keyword = " . $ilDB->quote("skin", "text") .
3071 " AND up1.usr_id = up2.usr_id";
3072
3073 $sty_set = $ilDB->query($q);
3074
3075 $styles = array();
3076 while ($sty_rec = $ilDB->fetchAssoc($sty_set)) {
3077 $styles[] = $sty_rec["skin"] . ":" . $sty_rec["style"];
3078 }
3079
3080 return $styles;
3081 }
3082
3086 public static function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3087 {
3088 global $DIC;
3089
3090 $ilDB = $DIC['ilDB'];
3091
3092 $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 " .
3093 " WHERE up1.keyword= " . $ilDB->quote("style", "text") .
3094 " AND up1.value= " . $ilDB->quote($a_from_style, "text") .
3095 " AND up2.keyword= " . $ilDB->quote("skin", "text") .
3096 " AND up2.value= " . $ilDB->quote($a_from_skin, "text") .
3097 " AND up1.usr_id = up2.usr_id ";
3098
3099 $usr_set = $ilDB->query($q);
3100
3101 while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
3102 self::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3103 self::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3104 }
3105 }
3106
3107
3113
3121 public function addObjectToClipboard(
3122 $a_item_id,
3123 $a_type,
3124 $a_title,
3125 $a_parent = 0,
3126 $a_time = 0,
3127 $a_order_nr = 0
3128 ) {
3129 global $DIC;
3130
3131 $ilDB = $DIC['ilDB'];
3132
3133 if ($a_time == 0) {
3134 $a_time = date("Y-m-d H:i:s", time());
3135 }
3136
3137 $item_set = $ilDB->queryF(
3138 "SELECT * FROM personal_clipboard WHERE " .
3139 "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3140 array("integer", "integer", "text", "integer"),
3141 array(0, $a_item_id, $a_type, $this->getId())
3142 );
3143
3144 // only insert if item is not already in clipboard
3145 if (!$d = $item_set->fetchRow()) {
3146 $ilDB->manipulateF(
3147 "INSERT INTO personal_clipboard " .
3148 "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES " .
3149 " (%s,%s,%s,%s,%s,%s,%s)",
3150 array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3151 array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr)
3152 );
3153 } else {
3154 $ilDB->manipulateF(
3155 "UPDATE personal_clipboard SET insert_time = %s " .
3156 "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3157 array("timestamp", "integer", "integer", "text"),
3158 array($a_time, $this->getId(), $a_item_id, $a_type)
3159 );
3160 }
3161 }
3162
3166 public function addToPCClipboard($a_content, $a_time, $a_nr)
3167 {
3168 global $DIC;
3169
3170 $ilDB = $DIC['ilDB'];
3171 if ($a_time == 0) {
3172 $a_time = date("Y-m-d H:i:s", time());
3173 }
3174 ilSession::set("user_pc_clip", true);
3175 $ilDB->insert("personal_pc_clipboard", array(
3176 "user_id" => array("integer", $this->getId()),
3177 "content" => array("clob", $a_content),
3178 "insert_time" => array("timestamp", $a_time),
3179 "order_nr" => array("integer", $a_nr)
3180 ));
3181 }
3182
3186 public function getPCClipboardContent()
3187 {
3188 global $DIC;
3189
3190 $ilDB = $DIC['ilDB'];
3191
3192 if (!ilSession::get("user_pc_clip")) {
3193 return [];
3194 }
3195
3196 $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard " .
3197 " WHERE user_id = %s", array("integer"), array($this->getId()));
3198 $row = $ilDB->fetchAssoc($set);
3199
3200 $set = $ilDB->queryF(
3201 "SELECT * FROM personal_pc_clipboard " .
3202 " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3203 array("integer", "timestamp"),
3204 array($this->getId(), $row["mtime"])
3205 );
3206 $content = array();
3207 while ($row = $ilDB->fetchAssoc($set)) {
3208 $content[] = $row["content"];
3209 }
3210
3211 return $content;
3212 }
3213
3217 public function clipboardHasObjectsOfType($a_type)
3218 {
3219 global $DIC;
3220
3221 $ilDB = $DIC['ilDB'];
3222
3223 $set = $ilDB->queryF(
3224 "SELECT * FROM personal_clipboard WHERE " .
3225 "parent = %s AND type = %s AND user_id = %s",
3226 array("integer", "text", "integer"),
3227 array(0, $a_type, $this->getId())
3228 );
3229 if ($rec = $ilDB->fetchAssoc($set)) {
3230 return true;
3231 }
3232
3233 return false;
3234 }
3235
3239 public function clipboardDeleteObjectsOfType($a_type)
3240 {
3241 global $DIC;
3242
3243 $ilDB = $DIC['ilDB'];
3244
3245 $ilDB->manipulateF(
3246 "DELETE FROM personal_clipboard WHERE " .
3247 "type = %s AND user_id = %s",
3248 array("text", "integer"),
3249 array($a_type, $this->getId())
3250 );
3251 }
3252
3256 public function clipboardDeleteAll()
3257 {
3258 global $DIC;
3259
3260 $ilDB = $DIC['ilDB'];
3261
3262 $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE " .
3263 "user_id = %s", array("integer"), array($this->getId()));
3264 }
3265
3269 public function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3270 {
3271 global $DIC;
3272
3273 $ilDB = $DIC['ilDB'];
3274
3275 $par = "";
3276 if ($a_top_nodes_only) {
3277 $par = " AND parent = " . $ilDB->quote(0, "integer") . " ";
3278 }
3279
3280 $type_str = ($a_type != "")
3281 ? " AND type = " . $ilDB->quote($a_type, "text") . " "
3282 : "";
3283 $q = "SELECT * FROM personal_clipboard WHERE " .
3284 "user_id = " . $ilDB->quote($this->getId(), "integer") . " " .
3285 $type_str . $par .
3286 " ORDER BY order_nr";
3287 $objs = $ilDB->query($q);
3288 $objects = array();
3289 while ($obj = $ilDB->fetchAssoc($objs)) {
3290 if ($obj["type"] == "mob") {
3291 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3292 if (ilObject::_lookupType((int) $obj["item_id"]) !== "mob") {
3293 continue;
3294 }
3295 }
3296 if ($obj["type"] == "incl") {
3297 include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3298 $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3299 if (!ilPageObject::_exists("mep", (int) $obj["item_id"], "-")) {
3300 continue;
3301 }
3302 }
3303 $objects[] = array("id" => $obj["item_id"],
3304 "type" => $obj["type"], "title" => $obj["title"],
3305 "insert_time" => $obj["insert_time"]);
3306 }
3307 return $objects;
3308 }
3309
3313 public function getClipboardChilds($a_parent, $a_insert_time)
3314 {
3315 global $DIC;
3316
3317 $ilDB = $DIC['ilDB'];
3318 $ilUser = $DIC['ilUser'];
3319
3320 $objs = $ilDB->queryF(
3321 "SELECT * FROM personal_clipboard WHERE " .
3322 "user_id = %s AND parent = %s AND insert_time = %s " .
3323 " ORDER BY order_nr",
3324 array("integer", "integer", "timestamp"),
3325 array($ilUser->getId(), (int) $a_parent, $a_insert_time)
3326 );
3327 $objects = array();
3328 while ($obj = $ilDB->fetchAssoc($objs)) {
3329 if ($obj["type"] == "mob") {
3330 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3331 }
3332 $objects[] = array("id" => $obj["item_id"],
3333 "type" => $obj["type"], "title" => $obj["title"], "insert_time" => $obj["insert_time"]);
3334 }
3335 return $objects;
3336 }
3337
3346 public static function _getUsersForClipboadObject($a_type, $a_id)
3347 {
3348 global $DIC;
3349
3350 $ilDB = $DIC['ilDB'];
3351
3352 $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE " .
3353 "item_id = " . $ilDB->quote($a_id, "integer") . " AND " .
3354 "type = " . $ilDB->quote($a_type, "text");
3355 $user_set = $ilDB->query($q);
3356 $users = array();
3357 while ($user_rec = $ilDB->fetchAssoc($user_set)) {
3358 $users[] = $user_rec["user_id"];
3359 }
3360
3361 return $users;
3362 }
3363
3371 public function removeObjectFromClipboard($a_item_id, $a_type)
3372 {
3373 global $DIC;
3374
3375 $ilDB = $DIC['ilDB'];
3376
3377 $q = "DELETE FROM personal_clipboard WHERE " .
3378 "item_id = " . $ilDB->quote($a_item_id, "integer") .
3379 " AND type = " . $ilDB->quote($a_type, "text") . " " .
3380 " AND user_id = " . $ilDB->quote($this->getId(), "integer");
3381 $ilDB->manipulate($q);
3382 }
3383
3384 public static function _getImportedUserId($i2_id)
3385 {
3386 global $DIC;
3387
3388 $ilDB = $DIC['ilDB'];
3389
3390 $query = "SELECT obj_id FROM object_data WHERE import_id = " .
3391 $ilDB->quote($i2_id, "text");
3392
3393 $res = $ilDB->query($query);
3394 while ($row = $ilDB->fetchObject($res)) {
3395 $id = $row->obj_id;
3396 }
3397 return $id ? $id : 0;
3398 }
3399
3405 public static function lookupOrgUnitsRepresentation($a_usr_id)
3406 {
3407 require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
3408 return ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_usr_id);
3409 }
3410
3411
3416 {
3418 }
3419
3420
3425 public function setAuthMode($a_str)
3426 {
3427 $this->auth_mode = $a_str;
3428 }
3429
3434 public function getAuthMode($a_auth_key = false)
3435 {
3436 if (!$a_auth_key) {
3437 return $this->auth_mode;
3438 }
3439
3440 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3441 return ilAuthUtils::_getAuthMode($this->auth_mode);
3442 }
3443
3451 public function setExternalAccount($a_str)
3452 {
3453 $this->ext_account = $a_str;
3454 }
3455
3463 public function getExternalAccount()
3464 {
3465 return $this->ext_account;
3466 }
3467
3479 public static function _getExternalAccountsByAuthMode($a_auth_mode, $a_read_auth_default = false)
3480 {
3481 global $DIC;
3482
3483 $ilDB = $DIC['ilDB'];
3484 $ilSetting = $DIC['ilSetting'];
3485
3486 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3487 $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data " .
3488 "WHERE auth_mode = %s";
3489 $types[] = "text";
3490 $values[] = $a_auth_mode;
3491 if ($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode', AUTH_LOCAL)) == $a_auth_mode) {
3492 $q .= " OR auth_mode = %s ";
3493 $types[] = "text";
3494 $values[] = 'default';
3495 }
3496
3497 $res = $ilDB->queryF($q, $types, $values);
3498 while ($row = $ilDB->fetchObject($res)) {
3499 if ($row->auth_mode == 'default') {
3500 $accounts[$row->usr_id] = $row->login;
3501 } else {
3502 $accounts[$row->usr_id] = $row->ext_account;
3503 }
3504 }
3505 return $accounts ? $accounts : array();
3506 }
3507
3515 public static function _toggleActiveStatusOfUsers($a_usr_ids, $a_status)
3516 {
3517 global $DIC;
3518
3519 $ilDB = $DIC['ilDB'];
3520
3521 if (!is_array($a_usr_ids)) {
3522 return false;
3523 }
3524
3525
3526 if ($a_status) {
3527 $q = "UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE " .
3528 $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3529 $ilDB->manipulate($q);
3530 } else {
3531 $usrId_IN_usrIds = $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3532
3533 $q = "UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds";
3534 $ilDB->manipulate($q);
3535
3536 $queryString = "
3537 UPDATE usr_data
3538 SET inactivation_date = %s
3539 WHERE inactivation_date IS NULL
3540 AND $usrId_IN_usrIds
3541 ";
3542 $ilDB->manipulateF($queryString, array('timestamp'), array(ilUtil::now()));
3543 }
3544
3545 return true;
3546 }
3547
3548
3557 public static function _lookupAuthMode($a_usr_id)
3558 {
3559 return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3560 }
3561
3568 public static function _checkExternalAuthAccount($a_auth, $a_account, $tryFallback = true)
3569 {
3570 $db = $GLOBALS['DIC']->database();
3571 $settings = $GLOBALS['DIC']->settings();
3572
3573 // Check directly with auth_mode
3574 $r = $db->queryF(
3575 "SELECT * FROM usr_data WHERE " .
3576 " ext_account = %s AND auth_mode = %s",
3577 array("text", "text"),
3578 array($a_account, $a_auth)
3579 );
3580 if ($usr = $db->fetchAssoc($r)) {
3581 return $usr["login"];
3582 }
3583
3584 if (!$tryFallback) {
3585 return false;
3586 }
3587
3588 // For compatibility, check for login (no ext_account entry given)
3589 $res = $db->queryF(
3590 "SELECT login FROM usr_data " .
3591 "WHERE login = %s AND auth_mode = %s AND (ext_account IS NULL OR ext_account = '') ",
3592 array("text", "text"),
3593 array($a_account, $a_auth)
3594 );
3595 if ($usr = $db->fetchAssoc($res)) {
3596 return $usr['login'];
3597 }
3598
3599 // If auth_default == $a_auth => check for login
3600 if (ilAuthUtils::_getAuthModeName($settings->get('auth_mode')) == $a_auth) {
3601 $res = $db->queryF(
3602 "SELECT login FROM usr_data WHERE " .
3603 " ext_account = %s AND auth_mode = %s",
3604 array("text", "text"),
3605 array($a_account, "default")
3606 );
3607 if ($usr = $db->fetchAssoc($res)) {
3608 return $usr["login"];
3609 }
3610 // Search for login (no ext_account given)
3611 $res = $db->queryF(
3612 "SELECT login FROM usr_data " .
3613 "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3614 array("text", "text"),
3615 array($a_account, "default")
3616 );
3617 if ($usr = $db->fetchAssoc($res)) {
3618 return $usr["login"];
3619 }
3620 }
3621 return false;
3622 }
3623
3627 public static function _getNumberOfUsersPerAuthMode()
3628 {
3629 global $DIC;
3630
3631 $ilDB = $DIC['ilDB'];
3632
3633 $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data " .
3634 "GROUP BY auth_mode");
3635 $cnt_arr = array();
3636 while ($cnt = $ilDB->fetchAssoc($r)) {
3637 $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3638 }
3639
3640 return $cnt_arr;
3641 }
3642
3648 public static function _getLocalAccountsForEmail($a_email)
3649 {
3650 global $DIC;
3651
3652 $ilDB = $DIC['ilDB'];
3653 $ilSetting = $DIC['ilSetting'];
3654
3655 // default set to local (1)?
3656
3657 $q = "SELECT * FROM usr_data WHERE " .
3658 " email = %s AND (auth_mode = %s ";
3659 $types = array("text", "text");
3660 $values = array($a_email, "local");
3661
3662 if ($ilSetting->get("auth_mode") == 1) {
3663 $q .= " OR auth_mode = %s";
3664 $types[] = "text";
3665 $values[] = "default";
3666 }
3667
3668 $q .= ")";
3669
3670 $users = array();
3671 $usr_set = $ilDB->queryF($q, $types, $values);
3672 while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
3673 $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3674 }
3675
3676 return $users;
3677 }
3678
3679
3687 public static function _uploadPersonalPicture($tmp_file, $obj_id)
3688 {
3689 $webspace_dir = ilUtil::getWebspaceDir();
3690 $image_dir = $webspace_dir . "/usr_images";
3691 $store_file = "usr_" . $obj_id . "." . "jpg";
3692
3693 chmod($tmp_file, 0770);
3694
3695 // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3696 // taking only frame [0] to avoid problems with animated gifs
3697 $show_file = "$image_dir/usr_" . $obj_id . ".jpg";
3698 $thumb_file = "$image_dir/usr_" . $obj_id . "_small.jpg";
3699 $xthumb_file = "$image_dir/usr_" . $obj_id . "_xsmall.jpg";
3700 $xxthumb_file = "$image_dir/usr_" . $obj_id . "_xxsmall.jpg";
3701
3702 if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
3703 ilUtil::execConvert($tmp_file . "[0] -geometry 200x200^ -gravity center -extent 200x200 -quality 100 JPEG:" . $show_file);
3704 ilUtil::execConvert($tmp_file . "[0] -geometry 100x100^ -gravity center -extent 100x100 -quality 100 JPEG:" . $thumb_file);
3705 ilUtil::execConvert($tmp_file . "[0] -geometry 75x75^ -gravity center -extent 75x75 -quality 100 JPEG:" . $xthumb_file);
3706 ilUtil::execConvert($tmp_file . "[0] -geometry 30x30^ -gravity center -extent 30x30 -quality 100 JPEG:" . $xxthumb_file);
3707 } else {
3708 ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
3709 ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
3710 ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
3711 ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
3712 }
3713
3714 // store filename
3715 self::_writePref($obj_id, "profile_image", $store_file);
3716
3717 return true;
3718 }
3719
3720
3729 public function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3730 {
3731 if (isset(self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic])) {
3732 return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
3733 }
3734
3735 self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic] = ilObjUser::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
3736
3737 return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
3738 }
3739
3740 public function getAvatar() : Avatar
3741 {
3742 return self::_getAvatar($this->getId());
3743 }
3744
3745 public static function _getAvatar($a_usr_id) : Avatar
3746 {
3747 $define = new ilUserAvatarResolver((int) ($a_usr_id ? $a_usr_id : ANONYMOUS_USER_ID));
3748
3749 return $define->getAvatar();
3750 }
3751
3763 public static function _getPersonalPicturePath(
3764 $a_usr_id,
3765 $a_size = "small",
3766 $a_force_pic = false,
3767 $a_prevent_no_photo_image = false,
3768 $html_export = false
3769 ) {
3770 $define = new ilUserAvatarResolver((int) $a_usr_id);
3771 $define->setForcePicture($a_force_pic);
3772 $define->setSize($a_size);
3773
3774 return ilWACSignedPath::signFile($define->getLegacyPictureURL());
3775 }
3776
3783 public static function copyProfilePicturesToDirectory($a_user_id, $a_dir)
3784 {
3785 $a_dir = trim(str_replace("..", "", $a_dir));
3786 if ($a_dir == "" || !is_dir($a_dir)) {
3787 return;
3788 }
3789
3790 $webspace_dir = ilUtil::getWebspaceDir();
3791 $image_dir = $webspace_dir . "/usr_images";
3792 $images = array(
3793 "upload_" . $a_user_id . "pic",
3794 "usr_" . $a_user_id . "." . "jpg",
3795 "usr_" . $a_user_id . "_small.jpg",
3796 "usr_" . $a_user_id . "_xsmall.jpg",
3797 "usr_" . $a_user_id . "_xxsmall.jpg",
3798 "upload_" . $a_user_id);
3799 foreach ($images as $image) {
3800 if (is_file($image_dir . "/" . $image)) {
3801 copy($image_dir . "/" . $image, $a_dir . "/" . $image);
3802 }
3803 }
3804 }
3805
3806
3810 public function removeUserPicture($a_do_update = true)
3811 {
3812 $webspace_dir = ilUtil::getWebspaceDir();
3813 $image_dir = $webspace_dir . "/usr_images";
3814 $file = $image_dir . "/usr_" . $this->getID() . "." . "jpg";
3815 $thumb_file = $image_dir . "/usr_" . $this->getID() . "_small.jpg";
3816 $xthumb_file = $image_dir . "/usr_" . $this->getID() . "_xsmall.jpg";
3817 $xxthumb_file = $image_dir . "/usr_" . $this->getID() . "_xxsmall.jpg";
3818 $upload_file = $image_dir . "/upload_" . $this->getID();
3819
3820 if ($a_do_update) {
3821 // remove user pref file name
3822 $this->setPref("profile_image", "");
3823 $this->update();
3824 }
3825
3826 if (@is_file($file)) {
3827 unlink($file);
3828 }
3829 if (@is_file($thumb_file)) {
3830 unlink($thumb_file);
3831 }
3832 if (@is_file($xthumb_file)) {
3833 unlink($xthumb_file);
3834 }
3835 if (@is_file($xxthumb_file)) {
3836 unlink($xxthumb_file);
3837 }
3838 if (@is_file($upload_file)) {
3839 unlink($upload_file);
3840 }
3841 }
3842
3843
3844 public function setUserDefinedData($a_data)
3845 {
3846 if (!is_array($a_data)) {
3847 return false;
3848 }
3849 foreach ($a_data as $field => $data) {
3850 #$new_data[$field] = ilUtil::stripSlashes($data);
3851 // Assign it directly to avoid update problems of unchangable fields
3852 $this->user_defined_data['f_' . $field] = $data;
3853 }
3854 #$this->user_defined_data = $new_data;
3855
3856 return true;
3857 }
3858
3859 public function getUserDefinedData()
3860 {
3861 return $this->user_defined_data ? $this->user_defined_data : array();
3862 }
3863
3864 public function updateUserDefinedFields()
3865 {
3866 global $DIC;
3867
3868 $ilDB = $DIC['ilDB'];
3869
3870 $fields = '';
3871
3872 $field_def = array();
3873
3874 include_once("./Services/User/classes/class.ilUserDefinedData.php");
3875 $udata = new ilUserDefinedData($this->getId());
3876
3877 foreach ($this->user_defined_data as $field => $value) {
3878 if ($field != 'usr_id') {
3879 // $field_def[$field] = array('text',$value);
3880 $udata->set($field, $value);
3881 }
3882 }
3883 $udata->update();
3884
3885 /* if(!$field_def)
3886 {
3887 return true;
3888 }
3889
3890 $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
3891 $res = $ilDB->query($query);
3892
3893
3894 if($res->numRows())
3895 {
3896 // Update
3897 $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
3898 }
3899 else
3900 {
3901 $field_def['usr_id'] = array('integer',$this->getId());
3902 $ilDB->insert('udf_data',$field_def);
3903 }
3904 */
3905 return true;
3906 }
3907
3908 public function readUserDefinedFields()
3909 {
3910 global $DIC;
3911
3912 $ilDB = $DIC['ilDB'];
3913
3914 include_once("./Services/User/classes/class.ilUserDefinedData.php");
3915 $udata = new ilUserDefinedData($this->getId());
3916
3917 /* $query = "SELECT * FROM udf_data ".
3918 "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
3919
3920 $res = $this->db->query($query);
3921 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
3922 {
3923 $this->user_defined_data = $row;
3924 }*/
3925
3926 $this->user_defined_data = $udata->getAll();
3927
3928 return true;
3929 }
3930
3932 {
3933 global $DIC;
3934
3935 $ilDB = $DIC['ilDB'];
3936
3937 // not needed. no entry in udf_text/udf_clob means no value
3938
3939 /* $query = "INSERT INTO udf_data (usr_id ) ".
3940 "VALUES( ".
3941 $ilDB->quote($this->getId(),'integer').
3942 ")";
3943 $res = $ilDB->manipulate($query);
3944 */
3945 return true;
3946 }
3947
3949 {
3950 global $DIC;
3951
3952 $ilDB = $DIC['ilDB'];
3953
3954 include_once("./Services/User/classes/class.ilUserDefinedData.php");
3956
3957 // wrong place...
3958 /* $query = "DELETE FROM udf_data ".
3959 "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
3960 $res = $ilDB->manipulate($query);*/
3961
3962 return true;
3963 }
3964
3970 public function getProfileAsString(&$a_language)
3971 {
3972 include_once './Services/AccessControl/classes/class.ilObjRole.php';
3973
3974 global $DIC;
3975
3976 $lng = $DIC['lng'];
3977 $rbacreview = $DIC['rbacreview'];
3978
3979 $language = &$a_language;
3980 $language->loadLanguageModule('registration');
3981 $language->loadLanguageModule('crs');
3982
3983 $body = '';
3984 $body .= ($language->txt("login") . ": " . $this->getLogin() . "\n");
3985
3986 if (strlen($this->getUTitle())) {
3987 $body .= ($language->txt("title") . ": " . $this->getUTitle() . "\n");
3988 }
3989 if (1 === strlen($this->getGender())) {
3990 $body .= ($language->txt("gender") . ": " . $language->txt('gender_' . strtolower($this->getGender())) . "\n");
3991 }
3992 if (strlen($this->getFirstname())) {
3993 $body .= ($language->txt("firstname") . ": " . $this->getFirstname() . "\n");
3994 }
3995 if (strlen($this->getLastname())) {
3996 $body .= ($language->txt("lastname") . ": " . $this->getLastname() . "\n");
3997 }
3998 if (strlen($this->getInstitution())) {
3999 $body .= ($language->txt("institution") . ": " . $this->getInstitution() . "\n");
4000 }
4001 if (strlen($this->getDepartment())) {
4002 $body .= ($language->txt("department") . ": " . $this->getDepartment() . "\n");
4003 }
4004 if (strlen($this->getStreet())) {
4005 $body .= ($language->txt("street") . ": " . $this->getStreet() . "\n");
4006 }
4007 if (strlen($this->getCity())) {
4008 $body .= ($language->txt("city") . ": " . $this->getCity() . "\n");
4009 }
4010 if (strlen($this->getZipcode())) {
4011 $body .= ($language->txt("zipcode") . ": " . $this->getZipcode() . "\n");
4012 }
4013 if (strlen($this->getCountry())) {
4014 $body .= ($language->txt("country") . ": " . $this->getCountry() . "\n");
4015 }
4016 if (strlen($this->getSelectedCountry())) {
4017 $body .= ($language->txt("sel_country") . ": " . $this->getSelectedCountry() . "\n");
4018 }
4019 if (strlen($this->getPhoneOffice())) {
4020 $body .= ($language->txt("phone_office") . ": " . $this->getPhoneOffice() . "\n");
4021 }
4022 if (strlen($this->getPhoneHome())) {
4023 $body .= ($language->txt("phone_home") . ": " . $this->getPhoneHome() . "\n");
4024 }
4025 if (strlen($this->getPhoneMobile())) {
4026 $body .= ($language->txt("phone_mobile") . ": " . $this->getPhoneMobile() . "\n");
4027 }
4028 if (strlen($this->getFax())) {
4029 $body .= ($language->txt("fax") . ": " . $this->getFax() . "\n");
4030 }
4031 if (strlen($this->getEmail())) {
4032 $body .= ($language->txt("email") . ": " . $this->getEmail() . "\n");
4033 }
4034 if (strlen($this->getSecondEmail())) {
4035 $body .= ($language->txt("second_email") . ": " . $this->getSecondEmail() . "\n");
4036 }
4037 if (strlen($this->getHobby())) {
4038 $body .= ($language->txt("hobby") . ": " . $this->getHobby() . "\n");
4039 }
4040 if (strlen($this->getComment())) {
4041 $body .= ($language->txt("referral_comment") . ": " . $this->getComment() . "\n");
4042 }
4043 if (strlen($this->getMatriculation())) {
4044 $body .= ($language->txt("matriculation") . ": " . $this->getMatriculation() . "\n");
4045 }
4046 if (strlen($this->getCreateDate())) {
4051
4052 $body .= ($language->txt("create_date") . ": " . $date . "\n");
4053 }
4054
4055 $gr = [];
4056 foreach ($rbacreview->getGlobalRoles() as $role) {
4057 if ($rbacreview->isAssigned($this->getId(), $role)) {
4058 $gr[] = ilObjRole::_lookupTitle($role);
4059 }
4060 }
4061 if (count($gr)) {
4062 $body .= ($language->txt('reg_role_info') . ': ' . implode(',', $gr) . "\n");
4063 }
4064
4065 // Time limit
4066 if ($this->getTimeLimitUnlimited()) {
4067 $body .= ($language->txt('time_limit') . ": " . $language->txt('crs_unlimited') . "\n");
4068 } else {
4074 );
4076
4077 $start = new ilDateTime($this->getTimeLimitFrom(), IL_CAL_UNIX);
4078 $end = new ilDateTime($this->getTimeLimitUntil(), IL_CAL_UNIX);
4079
4080 $body .= $language->txt('time_limit') . ': ' .
4081 $language->txt('from') . " " .
4082 $start->get(IL_CAL_DATETIME) . " ";
4083 $body .= $language->txt('to') . ' ' . $end->get(IL_CAL_DATETIME) . "\n";
4084 }
4085
4086 include_once './Services/User/classes/class.ilUserDefinedFields.php';
4090 $user_defined_fields = ilUserDefinedFields::_getInstance();
4092
4093 foreach ($user_defined_fields->getDefinitions() as $field_id => $definition) {
4094 $data = $user_defined_data["f_" . $field_id];
4095 if (strlen($data)) {
4096 if ($definition['field_type'] == UDF_TYPE_WYSIWYG) {
4097 $data = preg_replace('/<br(\s*)?\/?>/i', "\n", $data);
4098 $data = strip_tags($data);
4099 }
4100
4101 $body .= $definition['field_name'] . ': ' . $data . "\n";
4102 }
4103 }
4104
4105 return $body;
4106 }
4107
4111 public static function _lookupFeedHash($a_user_id, $a_create = false)
4112 {
4113 global $DIC;
4114
4115 $ilDB = $DIC['ilDB'];
4116
4117 if ($a_user_id > 0) {
4118 $set = $ilDB->queryF(
4119 "SELECT feed_hash from usr_data WHERE usr_id = %s",
4120 array("integer"),
4121 array($a_user_id)
4122 );
4123 if ($rec = $ilDB->fetchAssoc($set)) {
4124 if (strlen($rec["feed_hash"]) == 32) {
4125 return $rec["feed_hash"];
4126 } elseif ($a_create) {
4127 $hash = md5(rand(1, 9999999) + str_replace(" ", "", (string) microtime()));
4128 $ilDB->manipulateF(
4129 "UPDATE usr_data SET feed_hash = %s" .
4130 " WHERE usr_id = %s",
4131 array("text", "integer"),
4132 array($hash, $a_user_id)
4133 );
4134 return $hash;
4135 }
4136 }
4137 }
4138
4139 return false;
4140 }
4141
4147 public static function _getFeedPass($a_user_id)
4148 {
4149 global $DIC;
4150
4151 $ilDB = $DIC['ilDB'];
4152
4153 if ($a_user_id > 0) {
4154 return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4155 }
4156 return false;
4157 }
4158
4164 public static function _setFeedPass($a_user_id, $a_password)
4165 {
4166 global $DIC;
4167
4168 $ilDB = $DIC['ilDB'];
4169
4171 $a_user_id,
4172 "priv_feed_pass",
4173 ($a_password == "") ? "" : md5($a_password)
4174 );
4175 }
4176
4186 public static function _loginExists($a_login, $a_user_id = 0)
4187 {
4188 global $DIC;
4189
4190 $ilDB = $DIC['ilDB'];
4191
4192 $q = "SELECT DISTINCT login, usr_id FROM usr_data " .
4193 "WHERE login = %s";
4194 $types[] = "text";
4195 $values[] = $a_login;
4196
4197 if ($a_user_id != 0) {
4198 $q .= " AND usr_id != %s ";
4199 $types[] = "integer";
4200 $values[] = $a_user_id;
4201 }
4202
4203 $r = $ilDB->queryF($q, $types, $values);
4204
4205 if ($row = $ilDB->fetchAssoc($r)) {
4206 return $row['usr_id'];
4207 }
4208 return false;
4209 }
4210
4221 public static function _externalAccountExists($a_external_account, $a_auth_mode)
4222 {
4223 global $DIC;
4224
4225 $ilDB = $DIC['ilDB'];
4226
4227 $res = $ilDB->queryF(
4228 "SELECT * FROM usr_data " .
4229 "WHERE ext_account = %s AND auth_mode = %s",
4230 array("text", "text"),
4231 array($a_external_account, $a_auth_mode)
4232 );
4233 return $ilDB->fetchAssoc($res) ? true :false;
4234 }
4235
4243 public static function _getUsersForRole($role_id, $active = -1)
4244 {
4245 global $DIC;
4246
4247 $ilDB = $DIC['ilDB'];
4248 $rbacreview = $DIC['rbacreview'];
4249 $data = array();
4250
4251 $ids = $rbacreview->assignedUsers($role_id);
4252
4253 if (count($ids) == 0) {
4254 $ids = array(-1);
4255 }
4256
4257 $query = "SELECT usr_data.*, usr_pref.value AS language
4258 FROM usr_data
4259 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4260 WHERE " . $ilDB->in("usr_data.usr_id", $ids, false, "integer");
4261 $values[] = "language";
4262 $types[] = "text";
4263
4264
4265 if (is_numeric($active) && $active > -1) {
4266 $query .= " AND usr_data.active = %s";
4267 $values[] = $active;
4268 $types[] = "integer";
4269 }
4270
4271 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4272
4273 $r = $ilDB->queryF($query, $types, $values);
4274 $data = array();
4275 while ($row = $ilDB->fetchAssoc($r)) {
4276 $data[] = $row;
4277 }
4278 return $data;
4279 }
4280
4281
4287 public static function _getUsersForFolder($ref_id, $active)
4288 {
4289 global $DIC;
4290
4291 $ilDB = $DIC['ilDB'];
4292 $data = array();
4293 $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 ";
4294 $types[] = "text";
4295 $values[] = "language";
4296
4297 if (is_numeric($active) && $active > -1) {
4298 $query .= " AND usr_data.active = %s";
4299 $values[] = $active;
4300 $types[] = "integer";
4301 }
4302
4303 if ($ref_id != USER_FOLDER_ID) {
4304 $query .= " AND usr_data.time_limit_owner = %s";
4305 $values[] = $ref_id;
4306 $types[] = "integer";
4307 }
4308
4309 $query .= " AND usr_data.usr_id != %s ";
4310 $values[] = ANONYMOUS_USER_ID;
4311 $types[] = "integer";
4312
4313 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4314
4315 $result = $ilDB->queryF($query, $types, $values);
4316 $data = array();
4317 while ($row = $ilDB->fetchAssoc($result)) {
4318 array_push($data, $row);
4319 }
4320
4321 return $data;
4322 }
4323
4324
4330 public static function _getUsersForGroup($a_mem_ids, $active = -1)
4331 {
4332 return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4333 }
4334
4335
4341 public static function _getUsersForIds($a_mem_ids, $active = -1, $timelimitowner = -1)
4342 {
4343 global $DIC;
4344
4345 $rbacadmin = $DIC['rbacadmin'];
4346 $rbacreview = $DIC['rbacreview'];
4347 $ilDB = $DIC['ilDB'];
4348
4349 $query = "SELECT usr_data.*, usr_pref.value AS language
4350 FROM usr_data
4351 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4352 WHERE " . $ilDB->in("usr_data.usr_id", $a_mem_ids, false, "integer") . "
4353 AND usr_data.usr_id != %s";
4354 $values[] = "language";
4355 $types[] = "text";
4356 $values[] = ANONYMOUS_USER_ID;
4357 $types[] = "integer";
4358
4359 if (is_numeric($active) && $active > -1) {
4360 $query .= " AND active = %s";
4361 $values[] = $active;
4362 $types[] = "integer";
4363 }
4364
4365 if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1) {
4366 $query .= " AND usr_data.time_limit_owner = %s";
4367 $values[] = $timelimitowner;
4368 $types[] = "integer";
4369 }
4370
4371 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4372
4373 $result = $ilDB->queryF($query, $types, $values);
4374 while ($row = $ilDB->fetchAssoc($result)) {
4375 $mem_arr[] = $row;
4376 }
4377
4378 return $mem_arr ? $mem_arr : array();
4379 }
4380
4381
4382
4388 public static function _getUserData($a_internalids)
4389 {
4390 global $DIC;
4391
4392 $ilDB = $DIC['ilDB'];
4393
4394 $ids = array();
4395 if (is_array($a_internalids)) {
4396 foreach ($a_internalids as $internalid) {
4397 if (is_numeric($internalid)) {
4398 $ids[] = $internalid;
4399 } else {
4400 $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4401 if (is_numeric($parsedid) && $parsedid > 0) {
4402 $ids[] = $parsedid;
4403 }
4404 }
4405 }
4406 }
4407 if (count($ids) == 0) {
4408 $ids [] = -1;
4409 }
4410
4411 $query = "SELECT usr_data.*, usr_pref.value AS language
4412 FROM usr_data
4413 LEFT JOIN usr_pref
4414 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4415 WHERE " . $ilDB->in("usr_data.usr_id", $ids, false, "integer");
4416 $values[] = "language";
4417 $types[] = "text";
4418
4419 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4420
4421 $data = array();
4422 $result = $ilDB->queryF($query, $types, $values);
4423 while ($row = $ilDB->fetchAssoc($result)) {
4424 $data[] = $row;
4425 }
4426 return $data;
4427 }
4428
4435 public static function _getPreferences($user_id)
4436 {
4437 global $DIC;
4438
4439 $ilDB = $DIC['ilDB'];
4440
4441 $prefs = array();
4442
4443 $r = $ilDB->queryF(
4444 "SELECT * FROM usr_pref WHERE usr_id = %s",
4445 array("integer"),
4446 array($user_id)
4447 );
4448
4449 while ($row = $ilDB->fetchAssoc($r)) {
4450 $prefs[$row["keyword"]] = $row["value"];
4451 }
4452
4453 return $prefs;
4454 }
4455
4465 public static function getUserSubsetByPreferenceValue($a_user_ids, $a_keyword, $a_val)
4466 {
4467 global $DIC;
4468
4469 $ilDB = $DIC['ilDB'];
4470
4471 $users = array();
4472 $set = $ilDB->query(
4473 "SELECT usr_id FROM usr_pref " .
4474 " WHERE keyword = " . $ilDB->quote($a_keyword, "text") .
4475 " AND " . $ilDB->in("usr_id", $a_user_ids, false, "integer") .
4476 " AND value = " . $ilDB->quote($a_val, "text")
4477 );
4478 while ($rec = $ilDB->fetchAssoc($set)) {
4479 $users[] = $rec["usr_id"];
4480 }
4481 return $users;
4482 }
4483
4484
4485 public static function _resetLoginAttempts($a_usr_id)
4486 {
4487 global $DIC;
4488
4489 $ilDB = $DIC['ilDB'];
4490
4491 $query = "UPDATE usr_data SET login_attempts = 0 WHERE usr_id = %s";
4492 $affected = $ilDB->manipulateF($query, array('integer'), array($a_usr_id));
4493
4494 if ($affected) {
4495 return true;
4496 } else {
4497 return false;
4498 }
4499 }
4500
4501 public static function _getLoginAttempts($a_usr_id)
4502 {
4503 global $DIC;
4504
4505 $ilDB = $DIC['ilDB'];
4506
4507 $query = "SELECT login_attempts FROM usr_data WHERE usr_id = %s";
4508 $result = $ilDB->queryF($query, array('integer'), array($a_usr_id));
4509 $record = $ilDB->fetchAssoc($result);
4510 $login_attempts = $record['login_attempts'];
4511
4512 return $login_attempts;
4513 }
4514
4515 public static function _incrementLoginAttempts($a_usr_id)
4516 {
4517 global $DIC;
4518
4519 $ilDB = $DIC['ilDB'];
4520
4521 $query = "UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s";
4522 $affected = $ilDB->manipulateF($query, array('integer'), array($a_usr_id));
4523
4524 if ($affected) {
4525 return true;
4526 } else {
4527 return false;
4528 }
4529 }
4530
4531 public static function _setUserInactive($a_usr_id)
4532 {
4533 global $DIC;
4534
4535 $ilDB = $DIC['ilDB'];
4536
4537 $query = "UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s";
4538 $affected = $ilDB->manipulateF($query, array('timestamp', 'integer'), array(ilUtil::now(), $a_usr_id));
4539
4540 if ($affected) {
4541 return true;
4542 } else {
4543 return false;
4544 }
4545 }
4546
4552 public function hasPublicProfile()
4553 {
4554 return in_array($this->getPref("public_profile"), array("y", "g"));
4555 }
4556
4562 public function getPublicName()
4563 {
4564 if ($this->hasPublicProfile()) {
4565 return $this->getFirstname() . " " . $this->getLastname() . " (" . $this->getLogin() . ")";
4566 } else {
4567 return $this->getLogin();
4568 }
4569 }
4570
4571 public static function _writeHistory($a_usr_id, $a_login)
4572 {
4573 global $DIC;
4574
4575 $ilDB = $DIC['ilDB'];
4576
4577 $timestamp = time();
4578
4579 $res = $ilDB->queryF(
4580 'SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4581 array('integer', 'text', 'integer'),
4582 array($a_usr_id, $a_login, $timestamp)
4583 );
4584
4585 if ($ilDB->numRows($res) == 0) {
4586 $ilDB->manipulateF(
4587 '
4588 INSERT INTO loginname_history
4589 (usr_id, login, history_date)
4590 VALUES (%s, %s, %s)',
4591 array('integer', 'text', 'integer'),
4592 array($a_usr_id, $a_login, $timestamp)
4593 );
4594 }
4595
4596 return true;
4597 }
4598
4606 public static function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4607 {
4611 global $DIC;
4612
4613 $ilDB = $DIC->database();
4614 $rbacreview = $DIC->rbac()->review();
4615
4617
4618 $pd_set = new ilSetting('pd');
4619 $atime = $pd_set->get('user_activity_time') * 60;
4620 $ctime = time();
4621
4622 $where = array();
4623
4624 if ($a_user_id == 0) {
4625 $where[] = 'user_id > 0';
4626 } elseif (is_array($a_user_id)) {
4627 $where[] = $ilDB->in("user_id", $a_user_id, false, "integer");
4628 } else {
4629 $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
4630 }
4631
4632 if ($a_no_anonymous) {
4633 $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
4634 }
4635
4636 include_once 'Services/User/classes/class.ilUserAccountSettings.php';
4637 if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) {
4638 include_once 'Services/User/classes/class.ilUserFilter.php';
4639 $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
4640 }
4641
4642 $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
4643 $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
4644
4645 $where = 'WHERE ' . implode(' AND ', $where);
4646
4647 $r = $ilDB->queryF(
4648 $q = "
4649 SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime, context, agree_date
4650 FROM usr_session
4651 LEFT JOIN usr_data u
4652 ON user_id = u.usr_id
4653 LEFT JOIN usr_pref p
4654 ON (p.usr_id = u.usr_id AND p.keyword = %s)
4655 {$where}
4656 GROUP BY user_id, firstname, lastname, title, login, last_login, context, agree_date
4657 ORDER BY lastname, firstname
4658 ",
4659 array('text'),
4660 array('hide_own_online_status')
4661 );
4662
4663 $log->debug("Query: " . $q);
4664
4665 $users = array();
4666 while ($user = $ilDB->fetchAssoc($r)) {
4667 if ($atime <= 0 || $user['ctime'] + $atime > $ctime) {
4668 $users[$user['user_id']] = $user;
4669 }
4670 }
4671
4672 $log->debug("Found users: " . count($users));
4673
4674 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4676 $users = array_filter($users, function ($user) {
4677 if ($user['agree_date'] || $user['user_id'] == SYSTEM_USER_ID || 'root' === $user['login']) {
4678 return true;
4679 }
4680
4681 return false;
4682 });
4683
4684 $log->debug("TOS filtered to users: " . count($users));
4685 }
4686
4687 return $users;
4688 }
4689
4696 public static function _generateRegistrationHash($a_usr_id)
4697 {
4698 global $DIC;
4699
4700 $ilDB = $DIC['ilDB'];
4701
4702 do {
4703 $continue = false;
4704
4705 $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
4706
4707 $res = $ilDB->queryf(
4708 '
4709 SELECT COUNT(usr_id) cnt FROM usr_data
4710 WHERE reg_hash = %s',
4711 array('text'),
4712 array($hashcode)
4713 );
4714 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
4715 if ($row->cnt > 0) {
4716 $continue = true;
4717 }
4718 break;
4719 }
4720
4721 if ($continue) {
4722 continue;
4723 }
4724
4725 $ilDB->manipulateF(
4726 '
4727 UPDATE usr_data
4728 SET reg_hash = %s
4729 WHERE usr_id = %s',
4730 array('text', 'integer'),
4731 array($hashcode, (int) $a_usr_id)
4732 );
4733
4734 break;
4735 } while (true);
4736
4737 return $hashcode;
4738 }
4739
4748 public static function _verifyRegistrationHash($a_hash)
4749 {
4750 global $DIC;
4751
4752 $ilDB = $DIC['ilDB'];
4753
4754 $res = $ilDB->queryf(
4755 '
4756 SELECT usr_id, create_date FROM usr_data
4757 WHERE reg_hash = %s',
4758 array('text'),
4759 array($a_hash)
4760 );
4761 while ($row = $ilDB->fetchAssoc($res)) {
4762 require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
4763 $oRegSettigs = new ilRegistrationSettings();
4764
4765 if ((int) $oRegSettigs->getRegistrationHashLifetime() != 0 &&
4766 time() - (int) $oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date'])) {
4767 require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
4768 throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
4769 }
4770
4771 $ilDB->manipulateF(
4772 '
4773 UPDATE usr_data
4774 SET reg_hash = %s
4775 WHERE usr_id = %s',
4776 array('text', 'integer'),
4777 array('', (int) $row['usr_id'])
4778 );
4779
4780 return (int) $row['usr_id'];
4781 }
4782
4783 require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
4784 throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
4785 }
4786
4787 public function setBirthday($a_birthday)
4788 {
4789 if (strlen($a_birthday)) {
4790 $date = new ilDate($a_birthday, IL_CAL_DATE);
4791 $this->birthday = $date->get(IL_CAL_DATE);
4792 } else {
4793 $this->birthday = null;
4794 }
4795 }
4796
4797 public function getBirthday()
4798 {
4799 return $this->birthday;
4800 }
4801
4809 public static function getUserIdsByInactivityPeriod(int $periodInDays) : array
4810 {
4811 global $DIC;
4812
4813 if (!is_numeric($periodInDays) && $periodInDays < 1) {
4814 throw new \ilException('Invalid period given');
4815 }
4816
4817 $date = date('Y-m-d H:i:s', (time() - ((int) $periodInDays * 24 * 60 * 60)));
4818
4819 $query = "SELECT usr_id FROM usr_data WHERE last_login IS NOT NULL AND last_login < %s";
4820
4821 $ids = [];
4822
4823 $types = ['timestamp'];
4824 $values = [$date];
4825
4826 $res = $DIC->database()->queryF($query, $types, $values);
4827 while ($row = $DIC->database()->fetchAssoc($res)) {
4828 $ids[] = $row['usr_id'];
4829 }
4830
4831 return $ids;
4832 }
4833
4839 public static function getUserIdsNeverLoggedIn(int $thresholdInDays) : array
4840 {
4841 global $DIC;
4842
4843 $date = date('Y-m-d H:i:s', (time() - ((int) $thresholdInDays * 24 * 60 * 60)));
4844
4845 $query = "SELECT usr_id FROM usr_data WHERE last_login IS NULL AND create_date < %s";
4846
4847 $ids = [];
4848
4849 $types = ['timestamp'];
4850 $values = [$date];
4851
4852 $res = $DIC->database()->queryF($query, $types, $values);
4853 while ($row = $DIC->database()->fetchAssoc($res)) {
4854 $ids[] = $row['usr_id'];
4855 }
4856
4857 return $ids;
4858 }
4859
4868 public static function _getUserIdsByInactivationPeriod($period)
4869 {
4871 $field = 'inactivation_date';
4873
4874 if (!(int) $period) {
4875 throw new ilException('no valid period given');
4876 }
4877
4878 global $DIC;
4879
4880 $ilDB = $DIC['ilDB'];
4881
4882 $date = date('Y-m-d H:i:s', (time() - ((int) $period * 24 * 60 * 60)));
4883
4884 $query = "SELECT usr_id FROM usr_data WHERE $field < %s AND active = %s";
4885
4886 $res = $ilDB->queryF($query, array('timestamp', 'integer'), array($date, 0));
4887
4888 $ids = array();
4889 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
4890 $ids[] = $row->usr_id;
4891 }
4892
4893 return $ids;
4894 }
4895
4905 public static function _updateLastLogin($a_usr_id, $a_last_login = null)
4906 {
4907 if ($a_last_login !== null) {
4908 $last_login = $a_last_login;
4909 } else {
4910 $last_login = date('Y-m-d H:i:s');
4911 }
4912
4913 global $DIC;
4914
4915 $ilDB = $DIC['ilDB'];
4916
4917 $query = "UPDATE usr_data SET last_login = %s WHERE usr_id = %s";
4918 $affected = $ilDB->manipulateF($query, array('timestamp', 'integer'), array($last_login, $a_usr_id));
4919
4920 $query = "UPDATE usr_data SET first_login = %s WHERE usr_id = %s AND first_login IS NULL";
4921 $ilDB->manipulateF($query, array('timestamp', 'integer'), array($last_login, $a_usr_id));
4922
4923
4924 if ($affected) {
4925 return $last_login;
4926 } else {
4927 return false;
4928 }
4929 }
4930
4931 public function resetOwner()
4932 {
4933 global $DIC;
4934
4935 $ilDB = $DIC['ilDB'];
4936
4937 $query = "UPDATE object_data SET owner = 0 " .
4938 "WHERE owner = " . $ilDB->quote($this->getId(), 'integer');
4939 $ilDB->query($query);
4940
4941 return true;
4942 }
4943
4944
4951 public static function getFirstLettersOfLastnames(?array $user_ids = null)
4952 {
4953 global $DIC;
4954
4955 $ilDB = $DIC->database();
4956
4957 $q = "SELECT DISTINCT " . $ilDB->upper($ilDB->substr("lastname", 1, 1)) . " let" .
4958 " FROM usr_data" .
4959 " WHERE usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") .
4960 ($user_ids !== null ? " AND " . $ilDB->in('usr_id', $user_ids, false, "integer") : "") .
4961 " ORDER BY let";
4962 $let_set = $ilDB->query($q);
4963
4964 $lets = array();
4965 while ($let_rec = $ilDB->fetchAssoc($let_set)) {
4966 $let[$let_rec["let"]] = $let_rec["let"];
4967 }
4968 return $let;
4969 }
4970
4971 // begin-patch deleteProgress
4972 public static function userExists($a_usr_ids = array())
4973 {
4974 global $DIC;
4975
4976 $ilDB = $DIC['ilDB'];
4977
4978 $query = 'SELECT count(*) num FROM object_data od ' .
4979 'JOIN usr_data ud ON obj_id = usr_id ' .
4980 'WHERE ' . $ilDB->in('obj_id', $a_usr_ids, false, 'integer') . ' ';
4981 $res = $ilDB->query($query);
4982 $num_rows = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)->num;
4983 return $num_rows == count((array) $a_usr_ids);
4984 }
4985 // end-patch deleteProgress
4986
4990 public function isCaptchaVerified()
4991 {
4992 return (boolean) $_SESSION["user_captcha_verified"];
4993 }
4994
5000 public function setCaptchaVerified($a_val)
5001 {
5002 $_SESSION["user_captcha_verified"] = $a_val;
5003 }
5004
5011 public function exportPersonalData()
5012 {
5013 include_once("./Services/Export/classes/class.ilExport.php");
5014 $exp = new ilExport();
5015 $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5016 ilUtil::delDir($dir, true);
5017 $title = $this->getLastname() . ", " . $this->getLastname() . " [" . $this->getLogin() . "]";
5018 $exp->exportEntity(
5019 "personal_data",
5020 $this->getId(),
5021 "",
5022 "Services/User",
5023 $title,
5024 $dir
5025 );
5026 }
5027
5035 {
5036 include_once("./Services/Export/classes/class.ilExport.php");
5037 $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5038 if (!is_dir($dir)) {
5039 return "";
5040 }
5041 foreach (ilUtil::getDir($dir) as $entry) {
5042 if (is_int(strpos($entry["entry"], ".zip"))) {
5043 return $entry["entry"];
5044 }
5045 }
5046
5047 return "";
5048 }
5049
5056 public function sendPersonalDataFile()
5057 {
5058 include_once("./Services/Export/classes/class.ilExport.php");
5059 $file = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data") .
5060 "/" . $this->getPersonalDataExportFile();
5061 if (is_file($file)) {
5063 }
5064 }
5065
5072 public function importPersonalData(
5073 $a_file,
5074 $a_profile_data,
5075 $a_settings,
5076 $a_notes,
5077 $a_calendar
5078 ) {
5079 include_once("./Services/Export/classes/class.ilImport.php");
5080 $imp = new ilImport();
5081 // bookmarks need to be skipped, importer does not exist anymore
5082 $imp->addSkipImporter("Services/Bookmarks");
5083 if (!$a_profile_data) {
5084 $imp->addSkipEntity("Services/User", "usr_profile");
5085 }
5086 if (!$a_settings) {
5087 $imp->addSkipEntity("Services/User", "usr_setting");
5088 }
5089 if (!$a_notes) {
5090 $imp->addSkipEntity("Services/Notes", "user_notes");
5091 }
5092 if (!$a_calendar) {
5093 $imp->addSkipEntity("Services/Calendar", "calendar");
5094 }
5095 $imp->importEntity(
5096 $a_file["tmp_name"],
5097 $a_file["name"],
5098 "personal_data",
5099 "Services/User"
5100 );
5101 }
5102
5108 private static function initInactivationDate($usrIds)
5109 {
5110 global $DIC;
5111
5112 $ilDB = $DIC['ilDB'];
5113
5114 $NOW = $ilDB->now();
5115
5116 $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5117
5118 $queryString = "
5119 UPDATE usr_data
5120 SET inactivation_date = $NOW
5121 WHERE inactivation_date IS NULL
5122 AND $usrId_IN_usrIds
5123 ";
5124
5125 $ilDB->manipulate($queryString);
5126 }
5127
5133 private static function resetInactivationDate($usrIds)
5134 {
5135 global $DIC;
5136
5137 $ilDB = $DIC['ilDB'];
5138
5139 $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5140
5141 $queryString = "
5142 UPDATE usr_data
5143 SET inactivation_date = NULL
5144 WHERE $usrId_IN_usrIds
5145 ";
5146
5147 $ilDB->manipulate($queryString);
5148 }
5149
5156 {
5157 $this->inactivation_date = $inactivation_date;
5158 }
5159
5165 public function getInactivationDate()
5166 {
5168 }
5169
5174 {
5175 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5176
5177 if (
5179 null == $this->agree_date &&
5180 'root' != $this->login &&
5181 !in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID))
5182 ) {
5183 return true;
5184 }
5185
5186 return false;
5187 }
5188
5196 public static function getUsersAgreed($a_agreed = true, $a_users = null)
5197 {
5198 global $DIC;
5199
5200 $ilDB = $DIC['ilDB'];
5201
5202 $date_is = ($a_agreed)
5203 ? "IS NOT NULL"
5204 : "IS NULL";
5205
5206 $users = (is_array($a_users))
5207 ? " AND " . $ilDB->in("usr_id", $a_users, false, "integer")
5208 : "";
5209
5210 $set = $ilDB->query("SELECT usr_id FROM usr_data " .
5211 " WHERE agree_date " . $date_is .
5212 $users);
5213 $ret = array();
5214 while ($rec = $ilDB->fetchAssoc($set)) {
5215 $ret[] = $rec["usr_id"];
5216 }
5217 return $ret;
5218 }
5219
5220
5225 public function hasToAcceptTermsOfServiceInSession($status = null)
5226 {
5227 if (null === $status) {
5228 return ilSession::get('has_to_accept_agr_in_session');
5229 }
5230
5231 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5233 ilSession::set('has_to_accept_agr_in_session', (int) $status);
5234 }
5235 }
5236
5240 public function isAnonymous()
5241 {
5242 return self::_isAnonymous($this->getId());
5243 }
5244
5249 public static function _isAnonymous($usr_id)
5250 {
5251 return $usr_id == ANONYMOUS_USER_ID;
5252 }
5253
5254 public function activateDeletionFlag()
5255 {
5256 $this->writePref("delete_flag", true);
5257 }
5258
5259 public function removeDeletionFlag()
5260 {
5261 $this->writePref("delete_flag", false);
5262 }
5263
5264 public function hasDeletionFlag()
5265 {
5266 return (bool) $this->getPref("delete_flag");
5267 }
5268
5272 public function setIsSelfRegistered($status)
5273 {
5274 $this->is_self_registered = (bool) $status;
5275 }
5276
5277 public function isSelfRegistered()
5278 {
5279 return (bool) $this->is_self_registered;
5280 }
5281
5282
5283 //
5284 // MULTI-TEXT / INTERESTS
5285 //
5286
5292 public function setGeneralInterests(array $value = null)
5293 {
5294 $this->interests_general = $value;
5295 }
5296
5302 public function getGeneralInterests()
5303 {
5305 }
5306
5313 {
5314 return $this->buildTextFromArray("interests_general");
5315 }
5316
5322 public function setOfferingHelp(array $value = null)
5323 {
5324 $this->interests_help_offered = $value;
5325 }
5326
5332 public function getOfferingHelp()
5333 {
5335 }
5336
5342 public function getOfferingHelpAsText()
5343 {
5344 return $this->buildTextFromArray("interests_help_offered");
5345 }
5346
5352 public function setLookingForHelp(array $value = null)
5353 {
5354 $this->interests_help_looking = $value;
5355 }
5356
5362 public function getLookingForHelp()
5363 {
5365 }
5366
5372 public function getLookingForHelpAsText()
5373 {
5374 return $this->buildTextFromArray("interests_help_looking");
5375 }
5376
5383 protected function buildTextFromArray($a_attr)
5384 {
5385 $current = $this->$a_attr;
5386 if (is_array($current) && sizeof($current)) {
5387 return implode(", ", $current);
5388 }
5389 }
5390
5394 protected function readMultiTextFields()
5395 {
5396 global $DIC;
5397
5398 $ilDB = $DIC['ilDB'];
5399
5400 if (!$this->getId()) {
5401 return;
5402 }
5403
5404 $set = $ilDB->query("SELECT field_id,value" .
5405 " FROM usr_data_multi" .
5406 " WHERE usr_id = " . $ilDB->quote($this->getId(), "integer") .
5407 " ORDER BY value");
5408 while ($row = $ilDB->fetchAssoc($set)) {
5409 $values[$row["field_id"]][] = $row["value"];
5410 }
5411
5412 if (isset($values["interests_general"])) {
5413 $this->setGeneralInterests($values["interests_general"]);
5414 } else {
5415 $this->setGeneralInterests();
5416 }
5417 if (isset($values["interests_help_offered"])) {
5418 $this->setOfferingHelp($values["interests_help_offered"]);
5419 } else {
5420 $this->setOfferingHelp();
5421 }
5422 if (isset($values["interests_help_looking"])) {
5423 $this->setLookingForHelp($values["interests_help_looking"]);
5424 } else {
5425 $this->setLookingForHelp();
5426 }
5427 }
5428
5434 public function updateMultiTextFields($a_create = false)
5435 {
5436 global $DIC;
5437
5438 $ilDB = $DIC['ilDB'];
5439
5440 if (!$this->getId()) {
5441 return;
5442 }
5443
5444 if (!$a_create) {
5445 $this->deleteMultiTextFields();
5446 }
5447
5448 $map = array(
5449 "interests_general" => $this->getGeneralInterests(),
5450 "interests_help_offered" => $this->getOfferingHelp(),
5451 "interests_help_looking" => $this->getLookingForHelp()
5452 );
5453
5454 foreach ($map as $id => $values) {
5455 if (is_array($values) && sizeof($values)) {
5456 foreach ($values as $value) {
5457 $value = trim($value);
5458 if ($value) {
5459 $uniq_id = $ilDB->nextId('usr_data_multi');
5460
5461 $ilDB->manipulate("INSERT usr_data_multi" .
5462 " (id,usr_id,field_id,value) VALUES" .
5463 " (" . $ilDB->quote($uniq_id, "integer") .
5464 "," . $ilDB->quote($this->getId(), "integer") .
5465 "," . $ilDB->quote($id, "text") .
5466 "," . $ilDB->quote($value, "text") .
5467 ")");
5468 }
5469 }
5470 }
5471 }
5472 }
5473
5477 protected function deleteMultiTextFields()
5478 {
5479 global $DIC;
5480
5481 $ilDB = $DIC['ilDB'];
5482
5483 if (!$this->getId()) {
5484 return;
5485 }
5486
5487 $ilDB->manipulate("DELETE FROM usr_data_multi" .
5488 " WHERE usr_id = " . $ilDB->quote($this->getId(), "integer"));
5489 }
5490
5491 public static function findInterests($a_term, $a_user_id = null, $a_field_id = null)
5492 {
5493 global $DIC;
5494
5495 $ilDB = $DIC['ilDB'];
5496
5497 $res = array();
5498
5499 $sql = "SELECT DISTINCT(value)" .
5500 " FROM usr_data_multi" .
5501 " WHERE " . $ilDB->like("value", "text", "%" . $a_term . "%");
5502 if ($a_field_id) {
5503 $sql .= " AND field_id = " . $ilDB->quote($a_field_id, "text");
5504 }
5505 if ($a_user_id) {
5506 $sql .= " AND usr_id <> " . $ilDB->quote($a_user_id, "integer");
5507 }
5508 $sql .= " ORDER BY value";
5509 $set = $ilDB->query($sql);
5510 while ($row = $ilDB->fetchAssoc($set)) {
5511 $res[] = $row["value"];
5512 }
5513
5514 return $res;
5515 }
5516
5526 public static function getProfileStatusOfUsers($a_user_ids)
5527 {
5528 global $DIC;
5529
5530 $ilDB = $DIC->database();
5531
5532 $set = $ilDB->query(
5533 "SELECT * FROM usr_pref " .
5534 " WHERE keyword = " . $ilDB->quote("public_profile", "text") .
5535 " AND " . $ilDB->in("usr_id", $a_user_ids, false, "integer")
5536 );
5537 $r = array(
5538 "global" => array(),
5539 "local" => array(),
5540 "public" => array(),
5541 "not_public" => array()
5542 );
5543 while ($rec = $ilDB->fetchAssoc($set)) {
5544 if ($rec["value"] == "g") {
5545 $r["global"][] = $rec["usr_id"];
5546 $r["public"][] = $rec["usr_id"];
5547 }
5548 if ($rec["value"] == "y") {
5549 $r["local"][] = $rec["usr_id"];
5550 $r["public"][] = $rec["usr_id"];
5551 }
5552 }
5553 foreach ($a_user_ids as $id) {
5554 if (!in_array($id, $r["public"])) {
5555 $r["not_public"][] = $id;
5556 }
5557 }
5558
5559 return $r;
5560 }
5561} // END class ilObjUser
$result
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const AUTH_LOCAL
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
const IL_PASSWD_PLAIN
const IL_PASSWD_CRYPTED
const UDF_TYPE_WYSIWYG
static _getAuthMode($a_auth_mode, $a_db_handler='')
static _needsExternalAccountByAuthMode($a_auth_mode)
Check if chosen auth mode needs an external account entry.
static _getAuthModeName($a_auth_key)
static deleteByUserId($a_user_id)
static _deleteSettingsOfUser($a_user)
Delete block settings of user.
static _getInstance()
get singleton instance
This is the super class of all custom blocks.
static resetToDefaults()
reset to defaults
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setLanguage($a_lng)
set language
static setUseRelativeDates($a_status)
set use relative dates
static formatPeriod(ilDateTime $start, ilDateTime $end, $a_skip_starting_day=false)
Format a period of two date Shows: 14.
@classDescription Date and time handling
Class for single dates.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
Import class.
static _getInstance()
Get singleton instance of this class.
static _deleteUser($a_usr_id)
static getLogger($a_component_id)
Get component logger.
Class ilMailOptions this class handles user mails.
Mail Box class Base class for creating and handling mail boxes.
static lookupTitle($a_page_id)
Lookup title.
static removeForUser($user_id)
Remove all notifications for given user.
static _deleteUser($a_usr_id)
static _deleteUser($a_usr_id)
static deleteUserPortfolios($a_user_id)
Delete all portfolio data for user.
static _deleteUser($a_usr_id)
updateMultiTextFields($a_create=false)
Write multi-text values to DB.
setCity($a_str)
set city @access public
static _resetLoginAttempts($a_usr_id)
updateLogin($a_login)
update login name
getPasswdType()
get password type
static lookupMatriculation($a_usr_id)
Lookup matriculation.
getPhoneHome()
get home phone @access public
deleteMultiTextFields()
Remove multi-text values from DB.
static _lookupFirstLogin($a_user_id)
lookup first login
static getUserIdsNeverLoggedIn(int $thresholdInDays)
Get ids of all users that have never logged in.
static _writeExternalAccount($a_usr_id, $a_ext_id)
setCurrentLanguage($a_val)
Set current language.
static _getUsersForIds($a_mem_ids, $active=-1, $timelimitowner=-1)
return user data for given user id
setUTitle($a_str)
set user title (note: don't mix up this method with setTitle() that is derived from ilObject and sets...
static copyProfilePicturesToDirectory($a_user_id, $a_dir)
Get profile picture direcotory.
setInactivationDate($inactivation_date)
setter for inactivation date
static _getUsersForRole($role_id, $active=-1)
return array of complete users which belong to a specific role
readMultiTextFields()
Fetch multi-text values from DB.
static _lookupPref($a_usr_id, $a_keyword)
static _getLastHistoryDataByUserId($a_usr_id)
Returns the last used loginname and the changedate of the passed user_id.
setSecondEmail($second_email)
addToPCClipboard($a_content, $a_time, $a_nr)
Add a page content item to PC clipboard (should go to another class)
getAgreeDate()
get the date when the user accepted the user agreement @access public
static _verifyRegistrationHash($a_hash)
Verifies a registration hash.
static _getImportedUserId($i2_id)
getLatitude()
Get Latitude.
setLocationZoom($a_locationzoom)
Set Location Zoom.
static _lookupEmail($a_user_id)
Lookup email.
getLookingForHelpAsText()
Get help looking for as plain text.
getOfferingHelpAsText()
Get help offering as plain text.
setLanguage($a_str)
set user language @access public
setClientIP($a_str)
set client ip number @access public
getPhoneOffice()
get office phone @access public
setLatitude($a_latitude)
Set Latitude.
static searchUsers($a_search_str, $active=1, $a_return_ids_only=false, $filter_settings=false)
STATIC METHOD get the user_ids which correspond a search string.
static _getUserData($a_internalids)
return user data for given user ids
setInstitution($a_str)
set institution @access public
setLastUpdate($a_str)
set last update of user data set @access public
getClipboardObjects($a_type="", $a_top_nodes_only=false)
get all clipboard objects of user and specified type
static initInactivationDate($usrIds)
@global type $ilDB
getActive()
get user active state @access public
static $personal_image_cache
sendPersonalDataFile()
Send personal data file.
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.
setAgreeDate($a_str)
set date the user account was accepted by the user nullindicates that the user has not accepted his a...
static _getAllUserData($a_fields=null, $active=-1)
STATIC METHOD get all user data.
setFirstname($a_str)
set firstname @access public
getGeneralInterests()
Get general interests.
static _lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
$login
all user related data in single vars @access public
static _lookupLogin($a_user_id)
lookup login
setDepartment($a_str)
set department @access public
getCountry()
Get country (free text)
static _lookupSecondEmail($a_user_id)
Lookup second e-mail.
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
deletePref($a_keyword)
Deletes a userpref value of the user from the database @access public.
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.
writeAccepted()
write accept date of user agreement to db
getTimeZone()
get timezone of user
getFax()
get fax @access public
static getLoginFromAuth()
Gets the username from $ilAuth, and converts it into an ILIAS login name.
static getUserIdByLogin($a_login)
addObjectToClipboard( $a_item_id, $a_type, $a_title, $a_parent=0, $a_time=0, $a_order_nr=0)
add an item to user's personal clipboard
getLastname()
get lastname @access public
removeUserPicture($a_do_update=true)
Remove user picture.
static getUserIdsByEmail($a_email)
STATIC METHOD get all user_ids of an email address.
getUTitle()
get user title (note: don'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.
setLookingForHelp(array $value=null)
Set help looking for.
static lookupOrgUnitsRepresentation($a_usr_id)
lokup org unit representation
static _writeAuthMode($a_usr_id, $a_auth_mode)
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false, $html_export=false)
Get path to personal picture.
getMatriculation()
get matriculation number @access public
setPasswordEncodingType($password_encryption_type)
static resetInactivationDate($usrIds)
@global type $ilDB
buildTextFromArray($a_attr)
Convert multi-text values to plain text.
static findInterests($a_term, $a_user_id=null, $a_field_id=null)
setExternalAccount($a_str)
set external account
setLogin($a_str)
set login / username @access public
static userExists($a_usr_ids=array())
getFirstLogin()
returns first login date
static _getPreferences($user_id)
get preferences for user
clipboardDeleteAll()
Delete objects of type for user.
setTimeLimitFrom($a_from)
readPrefs()
get all user preferences @access private
static _writePref($a_usr_id, $a_keyword, $a_value)
static _incrementLoginAttempts($a_usr_id)
hasPublicProfile()
returns true if public is profile, false otherwise
static _lookupFeedHash($a_user_id, $a_create=false)
Lookup news feed hash for user.
static _uploadPersonalPicture($tmp_file, $obj_id)
Create a personal picture image file from a temporary image file.
getDateFormat()
get date format
setSkin($a_str)
set user skin (template set) @access public
getHobby()
get hobby @access public
static _getUsersForFolder($ref_id, $active)
get users for a category or from system folder
getCurrentLanguage()
returns the current language (may differ from user's pref setting!)
setSelectedCountry($a_val)
Set selected country (selection drop down)
getLongitude()
Get Longitude.
getEmail()
get email address @access public
getLoginByUserId($a_userid)
setCaptchaVerified($a_val)
Set captcha verified.
clipboardDeleteObjectsOfType($a_type)
Delete objects of type for user.
importPersonalData( $a_file, $a_profile_data, $a_settings, $a_notes, $a_calendar)
Import personal data.
static _lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
setCountry($a_str)
Set country (free text)
setTimeLimitMessage($a_time_limit_message)
setPasswd($a_str, $a_type=IL_PASSWD_PLAIN)
set password @access public
static _lookupId($a_user_str)
Lookup id by login.
read()
loads a record "user" from database @access private
getLocationZoom()
Get Location Zoom.
getAuthMode($a_auth_key=false)
get auth mode @access public
setPasswordPolicyResetStatus(bool $status)
static _getAllUserAssignedStyles()
skins and styles
static _deleteAllPref($a_user_id)
Deletes a userpref value of the user from the database @access public.
static _getAvatar($a_usr_id)
setComment($a_str)
set referral comment @access public
getComment()
get referral comment @access public
static getUsersAgreed($a_agreed=true, $a_users=null)
Get users that have or have not agreed to the user agreement.
getTimeFormat()
get time format
getPersonalDataExportFile()
Get personal data export file.
setAuthMode($a_str)
set auth mode @access public
setPhoneHome($a_str)
set home phone @access public
static _lookupGender($a_user_id)
Lookup gender.
setPasswordSalt($password_salt)
setFirstLogin($a_str)
set user's first login
setFax($a_str)
set fax @access public
setTimeLimitUntil($a_until)
static _lookupName($a_user_id)
lookup user name
static _getNumberOfUsersPerAuthMode()
get number of users per auth mode
getStreet()
get street @access public
getPasswordPolicyResetStatus()
getClipboardChilds($a_parent, $a_insert_time)
Get childs of an item.
static _toggleActiveStatusOfUsers($a_usr_ids, $a_status)
Toggle active status of users.
getSelectedCountry()
Get selected country (selection drop down)
setTimeLimitOwner($a_owner)
getInstitution()
get institution @access public
getApproveDate()
get the date when the user account was approved @access public
getFirstname()
get firstname @access public
getZipcode()
get zipcode @access public
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
static _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
skins and styles
static _getUsersForClipboadObject($a_type, $a_id)
get all users, that have a certain object within their clipboard
setZipcode($a_str)
set zipcode @access public
setApproveDate($a_str)
set date the user account was activated null indicates that the user has not yet been activated @acce...
setLongitude($a_longitude)
Set Longitude.
getLogin()
get login / username @access public
getPasswd()
get password
getPref($a_keyword)
get a user preference
setFullname($a_title="", $a_firstname="", $a_lastname="")
builds a string with title + firstname + lastname method is used to build fullname in member variable...
setPref($a_keyword, $a_value)
set a user preference
getLastProfilePrompt()
returns user's last profile prompt
deleteUserDefinedFieldEntries()
setLastname($a_str)
set lastame @access public
hasToAcceptTermsOfServiceInSession($status=null)
static _getFeedPass($a_user_id)
Lookup news feed password for user.
setGeneralInterests(array $value=null)
Set general interests.
static _externalAccountExists($a_external_account, $a_auth_mode)
Check if an external account name already exists.
static _generateRegistrationHash($a_usr_id)
Generates a unique hashcode for activating a user profile after registration.
static _getUserIdsByInactivationPeriod($period)
get ids of all users that have been inactivated since at least the given period
static _setUserInactive($a_usr_id)
setBirthday($a_birthday)
static _lookupFullname($a_user_id)
Lookup Full Name.
setOfferingHelp(array $value=null)
Set help offering.
static _lookupAuthMode($a_usr_id)
lookup auth mode
getStoredActive($a_id)
get user active state
setStreet($a_str)
set street @access public
setLastPasswordChangeTS($a_last_password_change_ts)
getLastLogin()
returns last login date @access public
static $is_desktop_item_loaded
setActive($a_active, $a_owner=0)
set user active state and updates system fields appropriately @access public
refreshLogin()
updates the login data of a "user" // TODO set date with now() should be enough @access public
setGender($a_str)
set gender @access public
static _getUsersForGroup($a_mem_ids, $active=-1)
return user data for group members
static _lookupLastLogin($a_user_id)
lookup last login
setProfileIncomplete($a_prof_inc)
static _setFeedPass($a_user_id, $a_password)
Set news feed password for user.
setTimeLimitUnlimited($a_unlimited)
static _doesLoginnameExistInHistory($a_login)
Checks wether the passed loginname already exists in history.
static _getLoginAttempts($a_usr_id)
static getProfileStatusOfUsers($a_user_ids)
Get profile status.
getPhoneMobile()
get mobile phone @access public
getPublicName()
returns firstname lastname and login if profile is public, login otherwise
setEmail($a_str)
set email @access public
getFullname($a_max_strlen=0)
get fullname @access public
static _lookup($a_user_id, $a_field)
Private function for lookup methods.
clipboardHasObjectsOfType($a_type)
Check whether clipboard has objects of a certain type.
setIsSelfRegistered($status)
getCity()
get city @access public
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...
getLanguage()
returns a 2char-language-string @access public
__construct($a_user_id=0, $a_call_by_reference=false)
Constructor @access public.
setMatriculation($a_str)
set matriculation number @access public
static _writeHistory($a_usr_id, $a_login)
getOfferingHelp()
Get help offering.
syncActive()
synchronizes current and stored user active values for the owner value to be set correctly,...
setLastLogin($a_str)
set user's last login @access public
writePrefs()
write all userprefs @access private
static _getLocalAccountsForEmail($a_email)
check whether external account and authentication method matches with a user
getInactivationDate()
getter for inactivation date
getDepartment()
get department @access public
setLastProfilePrompt($a_str)
set user's last profile prompt
assignData($a_data)
loads a record "user" from array @access public
setLastPasswordChangeToNow()
setHobby($a_str)
set hobby @access public
getLookingForHelp()
Get help looking for.
static _isAnonymous($usr_id)
static _lookupLanguage($a_usr_id)
getGeneralInterestsAsText()
Get general interests as plain text.
setPhoneOffice($a_str)
set office phone @access public
removeObjectFromClipboard($a_item_id, $a_type)
remove object from user's personal clipboard
getPCClipboardContent()
Add a page content item to PC clipboard (should go to another class)
exportPersonalData()
Export personal data.
setUserDefinedData($a_data)
static hasActiveSession($a_user_id, $a_session_id)
Check for simultaneous login.
setPhoneMobile($a_str)
set mobile phone @access public
static getUserLoginsByEmail($a_email)
get all user login names of an email address
static getUserIdsByInactivityPeriod(int $periodInDays)
Get ids of all users that have been inactive for at least the given period.
isCaptchaVerified()
Is user captcha verified?
setLoginAttempts($a_login_attempts)
getGender()
get gender @access public
getExternalAccount()
get external account
static getFirstLettersOfLastnames(?array $user_ids=null)
Get first letters of all lastnames.
static $is_desktop_item_cache
static _lookupClientIP($a_user_id)
Lookup client ip.
static toUsernameWithoutDomain($a_login)
Static function removes Microsoft domain name from username webdav related.
static _getNumberOfUsersForStyle($a_skin, $a_style)
skins and styles
writePref($a_keyword, $a_value)
write userpref to user table @access private
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...
static _lookupActive($a_usr_id)
Check user account active.
getClientIP()
get client ip number @access public
Class ilObject Basic functions for all objects.
setId($a_id)
set object id @access public
update()
update object in db
static _lookupTitle($a_id)
lookup object title
setOwner($a_owner)
set object owner
getId()
get object id @access public
static _lookupType($a_id, $a_reference=false)
lookup object type
getCreateDate()
get create date @access public
Custom block for external feeds on personal desktop.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
Class for user related exception handling in ILIAS.
Class for user related exception handling in ILIAS.
Class ilObjAuthSettingsGUI.
static _removeTrackingDataForUser($user_id)
static _getInstance()
Get instance of ilSecuritySettings.
static set($a_var, $a_val)
Set a value.
static _destroyByUserId($a_user_id)
Destroy session.
static get($a_var)
Get a value.
ILIAS Setting Class.
static skinExists($skin_id, ilSystemStyleConfig $system_style_config=null)
Check whether a skin exists.
static styleExistsForSkinId($skin_id, $style_id)
static styleExists($style_id)
static getInstance()
Singelton get instance.
Class ilUserAvatarResolver.
Class ilUserDefinedData.
static deleteEntriesOfUser($a_user_id)
Delete data of user.
static _getInstance()
Get instance.
Class for user related exception handling in ILIAS.
static getInstance()
Singelton get instance.
static getInstance()
Single method to reduce footprint (included files, created instances)
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static isConvertVersionAtLeast($a_version)
Compare convert version numbers.
static getWebspaceDir($mode="filesystem")
get webspace directory
static execConvert($args)
execute convert command
static getDir($a_dir, $a_rec=false, $a_sub_dir="")
get directory
static now()
Return current timestamp in Y-m-d H:i:s format.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static __extractId($ilias_id, $inst_id)
extract ref id from role title, e.g.
static signFile($path_to_file)
Tree handler for personal workspace.
const USER_FOLDER_ID
Definition: constants.php:31
const SYSTEM_USER_ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: constants.php:24
const IL_INST_ID
Definition: constants.php:38
const ANONYMOUS_USER_ID
Definition: constants.php:25
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
This describes how a letter or a picture avatar could be modified during construction of UI.
Definition: Avatar.php:9
$format
Definition: metadata.php:218
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)
$ret
Definition: parser.php:6
global $ilSetting
Definition: privfeed.php:17
$query
$ilErr
Definition: raiseError.php:18
foreach($_POST as $key=> $value) $res
login()
Definition: login.php:2
global $ilDB
$data
Definition: storeScorm.php:23