ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4define("IL_PASSWD_PLAIN", "plain");
5define("IL_PASSWD_CRYPTED", "crypted");
6
7
8require_once "./Services/Object/classes/class.ilObject.php";
9require_once './Services/User/exceptions/class.ilUserException.php';
10require_once './Modules/OrgUnit/classes/class.ilObjOrgUnit.php';
11require_once './Modules/OrgUnit/classes/class.ilObjOrgUnitTree.php';
12
25class ilObjUser extends ilObject
26{
31 // personal data
32
33 public $login; // username in system
34
38 protected $passwd; // password encoded in the format specified by $passwd_type
39
43 protected $passwd_type;
44 // specifies the password format.
45 // value: IL_PASSWD_PLAIN or IL_PASSWD_CRYPTED.
46
47 // Differences between password format in class ilObjUser and
48 // in table usr_data:
49 // Class ilObjUser supports two different password types
50 // (plain and crypted) and it uses the variables $passwd
51 // and $passwd_type to store them.
52 // Table usr_data supports only two different password types
53 // (md5 and bcrypt) and it uses the columns "passwd" and "passwd_type" to store them.
54 // The conversion between these two storage layouts is done
55 // in the methods that perform SQL statements. All other
56 // methods work exclusively with the $passwd and $passwd_type
57 // variables.
58
64
69 protected $password_salt = null;
70
71 public $gender; // 'm' or 'f'
72 public $utitle; // user title (keep in mind, that we derive $title from object also!)
73 public $firstname;
74 public $lastname;
75 protected $birthday;
76 public $fullname; // title + firstname + lastname in one string
77 //var $archive_dir = "./image"; // point to image file (should be flexible)
78 // address data
81 public $street;
82 public $city;
83 public $zipcode;
84 public $country;
89 public $fax;
90 public $email;
91 protected $second_email = null;
92 public $hobby;
95 public $approve_date = null;
96 public $agree_date = null;
97 public $active;
98 public $client_ip; // client ip to check before login
99 public $auth_mode; // authentication mode
100
101 public $latitude;
103 public $loc_zoom;
104
107
108 public $user_defined_data = array();
109
115 public $prefs;
116
122 public $skin;
123
124
131
137 public $ilias;
138
141
145 protected static $personal_image_cache = array();
146
152 protected $inactivation_date = null;
153
158 private $is_self_registered = false;
159
164 protected $org_units;
165
166 protected $interests_general; // [array]
167 protected $interests_help_offered; // [array]
168 protected $interests_help_looking; // [array]
169
175 public function __construct($a_user_id = 0, $a_call_by_reference = false)
176 {
177 global $ilias,$ilDB;
178
179 // init variables
180 $this->ilias =&$ilias;
181 $this->db =&$ilDB;
182
183 $this->type = "usr";
184 parent::__construct($a_user_id, $a_call_by_reference);
185 $this->auth_mode = "default";
186 $this->passwd_type = IL_PASSWD_PLAIN;
187
188 // for gender selection. don't change this
189 /*$this->gender = array(
190 'n' => "salutation_n",
191 'm' => "salutation_m",
192 'f' => "salutation_f"
193 );*/
194 if ($a_user_id > 0) {
195 $this->setId($a_user_id);
196 $this->read();
197 } else {
198 // TODO: all code in else-structure doesn't belongs in class user !!!
199 //load default data
200 $this->prefs = array();
201 //language
202 $this->prefs["language"] = $this->ilias->ini->readVariable("language", "default");
203
204 //skin and pda support
205 $this->skin = $this->ilias->ini->readVariable("layout", "skin");
206
207 $this->prefs["skin"] = $this->skin;
208 // $this->prefs["show_users_online"] = "y";
209
210 //style (css)
211 $this->prefs["style"] = $this->ilias->ini->readVariable("layout", "style");
212 }
213 }
214
219 public function read()
220 {
221 global $ilErr, $ilDB;
222
223 // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
224 // use (3.11.0 alpha)
225 /*$q = "SELECT * FROM usr_data ".
226 "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
227 "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
228 $r = $ilDB->queryF("SELECT * FROM usr_data " .
229 "WHERE usr_id= %s", array("integer"), array($this->id));
230
231 if ($data = $ilDB->fetchAssoc($r)) {
232 // convert password storage layout used by table usr_data into
233 // storage layout used by class ilObjUser
234 $data["passwd_type"] = IL_PASSWD_CRYPTED;
235
236 // this assign must not be set via $this->assignData($data)
237 // because this method will be called on profile updates and
238 // would set this values to 0, because they arent posted from form
239 $this->setLastPasswordChangeTS($data['last_password_change']);
240 $this->setLoginAttempts($data['login_attempts']);
241
242
243 // fill member vars in one shot
244 $this->assignData($data);
245
246 //get userpreferences from usr_pref table
247 $this->readPrefs();
248
249 //set language to default if not set
250 if ($this->prefs["language"] == "") {
251 $this->prefs["language"] = $this->oldPrefs["language"];
252 }
253
254 //check skin-setting
255 include_once("./Services/Style/System/classes/class.ilStyleDefinition.php");
256 if ($this->prefs["skin"] == "" ||
257 !ilStyleDefinition::skinExists($this->prefs["skin"])) {
258 $this->prefs["skin"] = $this->oldPrefs["skin"];
259 }
260
261 $this->skin = $this->prefs["skin"];
262
263 //check style-setting (skins could have more than one stylesheet
264 if ($this->prefs["style"] == "" ||
265 (!ilStyleDefinition::skinExists($this->skin) && ilStyleDefinition::styleExistsForSkinId($this->skin, $this->prefs["style"]))) {
266 //load default (css)
267 $this->prefs["style"] = $this->ilias->ini->readVariable("layout", "style");
268 }
269
270 if (empty($this->prefs["hits_per_page"])) {
271 $this->prefs["hits_per_page"] = 10;
272 }
273 } else {
274 $ilErr->raiseError("<b>Error: There is no dataset with id " .
275 $this->id . "!</b><br />class: " . get_class($this) . "<br />Script: " . __FILE__ .
276 "<br />Line: " . __LINE__, $ilErr->FATAL);
277 }
278
279 $this->readMultiTextFields();
280 $this->readUserDefinedFields();
281
282 parent::read();
283 }
284
288 public function getPasswordEncodingType()
289 {
291 }
292
296 public function setPasswordEncodingType($password_encryption_type)
297 {
298 $this->password_encoding_type = $password_encryption_type;
299 }
300
304 public function getPasswordSalt()
305 {
307 }
308
313 {
314 $this->password_salt = $password_salt;
315 }
316
322 public function assignData($a_data)
323 {
324 global $ilErr, $ilDB, $lng;
325
326 // basic personal data
327 $this->setLogin($a_data["login"]);
328 if (!$a_data["passwd_type"]) {
329 $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). " .
330 $this->id . "!</b><br />class: " . get_class($this) . "<br />Script: "
331 . __FILE__ . "<br />Line: " . __LINE__, $ilErr->FATAL);
332 }
333 if ($a_data["passwd"] != "********" and strlen($a_data['passwd'])) {
334 $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
335 }
336
337 $this->setGender($a_data["gender"]);
338 $this->setUTitle($a_data["title"]);
339 $this->setFirstname($a_data["firstname"]);
340 $this->setLastname($a_data["lastname"]);
341 $this->setFullname();
342 if (!is_array($a_data['birthday'])) {
343 $this->setBirthday($a_data['birthday']);
344 } else {
345 $this->setBirthday(null);
346 }
347
348 // address data
349 $this->setInstitution($a_data["institution"]);
350 $this->setDepartment($a_data["department"]);
351 $this->setStreet($a_data["street"]);
352 $this->setCity($a_data["city"]);
353 $this->setZipcode($a_data["zipcode"]);
354 $this->setCountry($a_data["country"]);
355 $this->setSelectedCountry($a_data["sel_country"]);
356 $this->setPhoneOffice($a_data["phone_office"]);
357 $this->setPhoneHome($a_data["phone_home"]);
358 $this->setPhoneMobile($a_data["phone_mobile"]);
359 $this->setFax($a_data["fax"]);
360 $this->setMatriculation($a_data["matriculation"]);
361 $this->setEmail($a_data["email"]);
362 $this->setSecondEmail($a_data["second_email"]);
363 $this->setHobby($a_data["hobby"]);
364 $this->setClientIP($a_data["client_ip"]);
365 $this->setPasswordEncodingType($a_data['passwd_enc_type']);
366 $this->setPasswordSalt($a_data['passwd_salt']);
367
368 // other data
369 $this->setLatitude($a_data["latitude"]);
370 $this->setLongitude($a_data["longitude"]);
371 $this->setLocationZoom($a_data["loc_zoom"]);
372
373 // system data
374 $this->setLastLogin($a_data["last_login"]);
375 $this->setLastUpdate($a_data["last_update"]);
376 $this->create_date = $a_data["create_date"];
377 $this->setComment($a_data["referral_comment"]);
378 $this->approve_date = $a_data["approve_date"];
379 $this->active = $a_data["active"];
380 $this->agree_date = $a_data["agree_date"];
381
382 $this->setInactivationDate($a_data["inactivation_date"]);
383
384 // time limitation
385 $this->setTimeLimitOwner($a_data["time_limit_owner"]);
386 $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
387 $this->setTimeLimitFrom($a_data["time_limit_from"]);
388 $this->setTimeLimitUntil($a_data["time_limit_until"]);
389 $this->setTimeLimitMessage($a_data['time_limit_message']);
390
391 // user profile incomplete?
392 $this->setProfileIncomplete($a_data["profile_incomplete"]);
393
394 //authentication
395 $this->setAuthMode($a_data['auth_mode']);
396 $this->setExternalAccount($a_data['ext_account']);
397
398 $this->setIsSelfRegistered((bool) $a_data['is_self_registered']);
399 }
400
407 public function saveAsNew($a_from_formular = true)
408 {
409 global $ilAppEventHandler;
410
415 global $ilErr, $ilDB;
416
417 switch ($this->passwd_type) {
418 case IL_PASSWD_PLAIN:
419 if (strlen($this->passwd)) {
420 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
421 ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
422 $pw_value = $this->getPasswd();
423 } else {
424 $pw_value = $this->passwd;
425 }
426 break;
427
429 $pw_value = $this->passwd;
430 break;
431
432 default:
433 $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. " .
434 $this->id . "!</b><br />class: " . get_class($this) . "<br />Script: " . __FILE__ .
435 "<br />Line: " . __LINE__, $ilErr->FATAL);
436 }
437
438 if (!$this->active) {
440 } else {
441 $this->setInactivationDate(null);
442 }
443
444 $insert_array = array(
445 "usr_id" => array("integer", $this->id),
446 "login" => array("text", $this->login),
447 "passwd" => array("text", $pw_value),
448 'passwd_enc_type' => array("text", $this->getPasswordEncodingType()),
449 'passwd_salt' => array("text", $this->getPasswordSalt()),
450 "firstname" => array("text", $this->firstname),
451 "lastname" => array("text", $this->lastname),
452 "title" => array("text", $this->utitle),
453 "gender" => array("text", $this->gender),
454 "email" => array("text", trim($this->email)),
455 "second_email" => array("text", trim($this->second_email)),
456 "hobby" => array("text", (string) $this->hobby),
457 "institution" => array("text", $this->institution),
458 "department" => array("text", $this->department),
459 "street" => array("text", $this->street),
460 "city" => array("text", $this->city),
461 "zipcode" => array("text", $this->zipcode),
462 "country" => array("text", $this->country),
463 "sel_country" => array("text", $this->sel_country),
464 "phone_office" => array("text", $this->phone_office),
465 "phone_home" => array("text", $this->phone_home),
466 "phone_mobile" => array("text", $this->phone_mobile),
467 "fax" => array("text", $this->fax),
468 "birthday" => array('date', $this->getBirthday()),
469 "last_login" => array("timestamp", null),
470 "last_update" => array("timestamp", ilUtil::now()),
471 "create_date" => array("timestamp", ilUtil::now()),
472 "referral_comment" => array("text", $this->referral_comment),
473 "matriculation" => array("text", $this->matriculation),
474 "client_ip" => array("text", $this->client_ip),
475 "approve_date" => array("timestamp", $this->approve_date),
476 "agree_date" => array("timestamp", $this->agree_date),
477 "active" => array("integer", (int) $this->active),
478 "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
479 "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
480 "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
481 "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
482 "auth_mode" => array("text", $this->getAuthMode()),
483 "ext_account" => array("text", $this->getExternalAccount()),
484 "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
485 "latitude" => array("text", $this->latitude),
486 "longitude" => array("text", $this->longitude),
487 "loc_zoom" => array("integer", (int) $this->loc_zoom),
488 "last_password_change" => array("integer", (int) $this->last_password_change_ts),
489 'inactivation_date' => array('timestamp', $this->inactivation_date),
490 'is_self_registered' => array('integer', (int) $this->is_self_registered),
491 );
492 $ilDB->insert("usr_data", $insert_array);
493
494 $this->updateMultiTextFields(true);
495
496 // add new entry in usr_defined_data
498 // ... and update
500
501 // CREATE ENTRIES FOR MAIL BOX
502 include_once("Services/Mail/classes/class.ilMailbox.php");
503 $mbox = new ilMailbox($this->id);
504 $mbox->createDefaultFolder();
505
506 include_once "Services/Mail/classes/class.ilMailOptions.php";
507 $mail_options = new ilMailOptions($this->id);
508 $mail_options->createMailOptionsEntry();
509
510 // create personal bookmark folder tree
511 include_once "./Services/Bookmarks/classes/class.ilBookmarkFolder.php";
512 $bmf = new ilBookmarkFolder(0, $this->id);
513 $bmf->createNewBookmarkTree();
514
515 $ilAppEventHandler->raise(
516 "Services/User",
517 "afterCreate",
518 array("user_obj" => $this)
519 );
520 }
521
525 public function update()
526 {
532 global $ilErr, $ilDB, $ilAppEventHandler;
533
534 $this->syncActive();
535
536 if ($this->getStoredActive($this->id) && !$this->active) {
538 } elseif ($this->active) {
539 $this->setInactivationDate(null);
540 }
541
542 $update_array = array(
543 "gender" => array("text", $this->gender),
544 "title" => array("text", $this->utitle),
545 "firstname" => array("text", $this->firstname),
546 "lastname" => array("text", $this->lastname),
547 "email" => array("text", trim($this->email)),
548 "second_email" => array("text", trim($this->second_email)),
549 "birthday" => array('date', $this->getBirthday()),
550 "hobby" => array("text", $this->hobby),
551 "institution" => array("text", $this->institution),
552 "department" => array("text", $this->department),
553 "street" => array("text", $this->street),
554 "city" => array("text", $this->city),
555 "zipcode" => array("text", $this->zipcode),
556 "country" => array("text", $this->country),
557 "sel_country" => array("text", $this->sel_country),
558 "phone_office" => array("text", $this->phone_office),
559 "phone_home" => array("text", $this->phone_home),
560 "phone_mobile" => array("text", $this->phone_mobile),
561 "fax" => array("text", $this->fax),
562 "referral_comment" => array("text", $this->referral_comment),
563 "matriculation" => array("text", $this->matriculation),
564 "client_ip" => array("text", $this->client_ip),
565 "approve_date" => array("timestamp", $this->approve_date),
566 "active" => array("integer", $this->active),
567 "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
568 "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
569 "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
570 "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
571 "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
572 "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
573 "auth_mode" => array("text", $this->getAuthMode()),
574 "ext_account" => array("text", $this->getExternalAccount()),
575 "latitude" => array("text", $this->latitude),
576 "longitude" => array("text", $this->longitude),
577 "loc_zoom" => array("integer", (int) $this->loc_zoom),
578 "last_password_change" => array("integer", $this->last_password_change_ts),
579 "last_update" => array("timestamp", ilUtil::now()),
580 'inactivation_date' => array('timestamp', $this->inactivation_date)
581 );
582
583 if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null)) {
584 $update_array["agree_date"] = array("timestamp", $this->agree_date);
585 }
586 switch ($this->passwd_type) {
587 case IL_PASSWD_PLAIN:
588 if (strlen($this->passwd)) {
589 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
590 ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
591 $update_array['passwd'] = array('text', $this->getPasswd());
592 } else {
593 $update_array["passwd"] = array("text", (string) $this->passwd);
594 }
595 break;
596
598 $update_array["passwd"] = array("text", (string) $this->passwd);
599 break;
600
601 default:
602 $ilErr->raiseError("<b>Error: passwd_type missing in function update()" . $this->id . "!</b><br />class: " .
603 get_class($this) . "<br />Script: " . __FILE__ . "<br />Line: " . __LINE__, $ilErr->FATAL);
604 }
605
606 $update_array['passwd_enc_type'] = array('text', $this->getPasswordEncodingType());
607 $update_array['passwd_salt'] = array('text', $this->getPasswordSalt());
608
609 $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
610
611 $this->updateMultiTextFields();
612
613 $this->writePrefs();
614
615 // update user defined fields
617
619 parent::updateOwner();
620
621 $this->read();
622
623 $ilAppEventHandler->raise(
624 "Services/User",
625 "afterUpdate",
626 array("user_obj" => $this)
627 );
628
629 return true;
630 }
631
635 public function writeAccepted()
636 {
637 global $ilDB;
638
639 $ilDB->manipulateF("UPDATE usr_data SET agree_date = " . $ilDB->now() .
640 " WHERE usr_id = %s", array("integer"), array($this->getId()));
641 }
642
646 private static function _lookup($a_user_id, $a_field)
647 {
648 global $ilDB;
649
650 $res = $ilDB->queryF(
651 "SELECT " . $a_field . " FROM usr_data WHERE usr_id = %s",
652 array("integer"),
653 array($a_user_id)
654 );
655
656 while ($set = $ilDB->fetchAssoc($res)) {
657 return $set[$a_field];
658 }
659 return false;
660 }
661
665 public static function _lookupFullname($a_user_id)
666 {
667 global $ilDB;
668
669 $set = $ilDB->queryF(
670 "SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
671 array("integer"),
672 array($a_user_id)
673 );
674
675 if ($rec = $ilDB->fetchAssoc($set)) {
676 if ($rec["title"]) {
677 $fullname = $rec["title"] . " ";
678 }
679 if ($rec["firstname"]) {
680 $fullname .= $rec["firstname"] . " ";
681 }
682 if ($rec["lastname"]) {
683 $fullname .= $rec["lastname"];
684 }
685 }
686 return $fullname;
687 }
688
692 public static function _lookupEmail($a_user_id)
693 {
694 return ilObjUser::_lookup($a_user_id, "email");
695 }
696
702 public static function _lookupSecondEmail($a_user_id)
703 {
704 return ilObjUser::_lookup($a_user_id, "second_email");
705 }
706
710 public static function _lookupGender($a_user_id)
711 {
712 return ilObjUser::_lookup($a_user_id, "gender");
713 }
714
721 public static function _lookupClientIP($a_user_id)
722 {
723 return ilObjUser::_lookup($a_user_id, "client_ip");
724 }
725
726
732 public static function _lookupName($a_user_id)
733 {
734 global $ilDB;
735
736 $res = $ilDB->queryF(
737 "SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
738 array("integer"),
739 array($a_user_id)
740 );
741 $user_rec = $ilDB->fetchAssoc($res);
742 return array("user_id" => $a_user_id,
743 "firstname" => $user_rec["firstname"],
744 "lastname" => $user_rec["lastname"],
745 "title" => $user_rec["title"],
746 "login" => $user_rec["login"]);
747 }
748
752 public static function _lookupFields($a_user_id)
753 {
754 global $ilDB;
755
756 $res = $ilDB->queryF(
757 "SELECT * FROM usr_data WHERE usr_id = %s",
758 array("integer"),
759 array($a_user_id)
760 );
761 $user_rec = $ilDB->fetchAssoc($res);
762 return $user_rec;
763 }
764
768 public static function _lookupLogin($a_user_id)
769 {
770 return ilObjUser::_lookup($a_user_id, "login");
771 }
772
776 public static function _lookupExternalAccount($a_user_id)
777 {
778 return ilObjUser::_lookup($a_user_id, "ext_account");
779 }
780
784 public static function _lookupId($a_user_str)
785 {
786 global $ilDB;
787
788 if (!is_array($a_user_str)) {
789 $res = $ilDB->queryF(
790 "SELECT usr_id FROM usr_data WHERE login = %s",
791 array("text"),
792 array($a_user_str)
793 );
794 $user_rec = $ilDB->fetchAssoc($res);
795 return $user_rec["usr_id"];
796 } else {
797 $set = $ilDB->query(
798 "SELECT usr_id FROM usr_data " .
799 " WHERE " . $ilDB->in("login", $a_user_str, false, "text")
800 );
801 $ids = array();
802 while ($rec = $ilDB->fetchAssoc($set)) {
803 $ids[] = $rec["usr_id"];
804 }
805 return $ids;
806 }
807 }
808
812 public static function _lookupLastLogin($a_user_id)
813 {
814 return ilObjUser::_lookup($a_user_id, "last_login");
815 }
816
817
823 public function refreshLogin()
824 {
825 global $ilDB;
826
827 $ilDB->manipulateF(
828 "UPDATE usr_data SET " .
829 "last_login = " . $ilDB->now() .
830 " WHERE usr_id = %s",
831 array("integer"),
832 array($this->id)
833 );
834 }
835
836
844 public function resetPassword($raw, $raw_retype)
845 {
849 global $ilDB;
850
851 if (func_num_args() != 2) {
852 return false;
853 }
854
855 if (!isset($raw) || !isset($raw_retype)) {
856 return false;
857 }
858
859 if ($raw != $raw_retype) {
860 return false;
861 }
862
863 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
864 ilUserPasswordManager::getInstance()->encodePassword($this, $raw);
865
866 $ilDB->manipulateF(
867 'UPDATE usr_data
868 SET passwd = %s, passwd_enc_type = %s, passwd_salt = %s
869 WHERE usr_id = %s',
870 array('text', 'text', 'text', 'integer'),
871 array($this->getPasswd(), $this->getPasswordEncodingType(), $this->getPasswordSalt(), $this->getId())
872 );
873
874 return true;
875 }
876
887 public static function _doesLoginnameExistInHistory($a_login)
888 {
889 global $ilDB;
890
891 $res = $ilDB->queryF(
892 '
893 SELECT * FROM loginname_history
894 WHERE login = %s',
895 array('text'),
896 array($a_login)
897 );
898
899 return $ilDB->fetchAssoc($res) ? true : false;
900 }
901
914 public static function _getLastHistoryDataByUserId($a_usr_id)
915 {
916 global $ilDB;
917
918 $ilDB->setLimit(1, 0);
919 $res = $ilDB->queryF(
920 '
921 SELECT login, history_date FROM loginname_history
922 WHERE usr_id = %s ORDER BY history_date DESC',
923 array('integer'),
924 array($a_usr_id)
925 );
926 $row = $ilDB->fetchAssoc($res);
927 if (!is_array($row) || !count($row)) {
928 throw new ilUserException('');
929 }
930
931 return array(
932 $row['login'], $row['history_date']
933 );
934 }
935
943 public function updateLogin($a_login)
944 {
945 global $ilDB, $ilSetting;
946
947 if (func_num_args() != 1) {
948 return false;
949 }
950
951 if (!isset($a_login)) {
952 return false;
953 }
954
955 $former_login = self::_lookupLogin($this->getId());
956
957 // Update not necessary
958 if (0 == strcmp($a_login, $former_login)) {
959 return false;
960 }
961
962 try {
963 $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
964 } catch (ilUserException $e) {
965 $last_history_entry = null;
966 }
967
968 // throw exception if the desired loginame is already in history and it is not allowed to reuse it
969 if ((int) $ilSetting->get('allow_change_loginname') &&
970 (int) $ilSetting->get('reuse_of_loginnames') == 0 &&
971 self::_doesLoginnameExistInHistory($a_login)) {
972 throw new ilUserException($this->lng->txt('loginname_already_exists'));
973 } elseif ((int) $ilSetting->get('allow_change_loginname') &&
974 (int) $ilSetting->get('loginname_change_blocking_time') &&
975 is_array($last_history_entry) &&
976 $last_history_entry[1] + (int) $ilSetting->get('loginname_change_blocking_time') > time()) {
977 include_once 'Services/Calendar/classes/class.ilDate.php';
978 throw new ilUserException(
979 sprintf(
980 $this->lng->txt('changing_loginname_not_possible_info'),
982 new ilDateTime($last_history_entry[1], IL_CAL_UNIX)
983 ),
985 new ilDateTime(($last_history_entry[1] + (int) $ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX)
986 )
987 )
988 );
989 } else {
990 // log old loginname in history
991 if ((int) $ilSetting->get('allow_change_loginname') &&
992 (int) $ilSetting->get('create_history_loginname')) {
993 ilObjUser::_writeHistory($this->getId(), $former_login);
994 }
995
996 //update login
997 $this->login = $a_login;
998
999 $ilDB->manipulateF(
1000 '
1001 UPDATE usr_data
1002 SET login = %s
1003 WHERE usr_id = %s',
1004 array('text', 'integer'),
1005 array($this->getLogin(), $this->getId())
1006 );
1007 }
1008
1009 return true;
1010 }
1011
1018 public function writePref($a_keyword, $a_value)
1019 {
1020 self::_writePref($this->id, $a_keyword, $a_value);
1021 $this->setPref($a_keyword, $a_value);
1022 }
1023
1024
1030 public function deletePref($a_keyword)
1031 {
1032 self::_deletePref($this->getId(), $a_keyword);
1033 }
1034
1040 public static function _deletePref($a_user_id, $a_keyword)
1041 {
1045 global $ilDB;
1046
1047 $ilDB->manipulateF(
1048 'DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s',
1049 array('integer', 'text'),
1050 array($a_user_id, $a_keyword)
1051 );
1052 }
1053
1059 public static function _deleteAllPref($a_user_id)
1060 {
1061 global $ilDB;
1062
1063 $ilDB->manipulateF(
1064 "DELETE FROM usr_pref WHERE usr_id = %s",
1065 array("integer"),
1066 array($a_user_id)
1067 );
1068 }
1069
1076 public static function _writePref($a_usr_id, $a_keyword, $a_value)
1077 {
1078 global $ilDB;
1079 $ilDB->replace(
1080 "usr_pref",
1081 array(
1082 "usr_id" => array("integer", $a_usr_id),
1083 "keyword" => array("text", $a_keyword),
1084 ),
1085 array(
1086 "value" => array("text",$a_value)
1087 )
1088 );
1089
1090 /*
1091 self::_deletePref($a_usr_id, $a_keyword);
1092 if(strlen($a_value))
1093 {
1094 $ilDB->manipulateF(
1095 'INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s, %s, %s)',
1096 array('integer', 'text', 'text'),
1097 array($a_usr_id, $a_keyword, $a_value)
1098 );
1099 }*/
1100 }
1101
1106 public function writePrefs()
1107 {
1108 global $ilDB;
1109
1110 ilObjUser::_deleteAllPref($this->id);
1111 foreach ($this->prefs as $keyword => $value) {
1112 self::_writePref($this->id, $keyword, $value);
1113 }
1114 }
1115
1122 public function getTimeZone()
1123 {
1124 if ($tz = $this->getPref('user_tz')) {
1125 return $tz;
1126 } else {
1127 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1129 return $settings->getDefaultTimeZone();
1130 }
1131 }
1132
1139 public function getTimeFormat()
1140 {
1141 if ($format = $this->getPref('time_format')) {
1142 return $format;
1143 } else {
1144 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1146 return $settings->getDefaultTimeFormat();
1147 }
1148 }
1149
1156 public function getDateFormat()
1157 {
1158 if ($format = $this->getPref('date_format')) {
1159 return $format;
1160 } else {
1161 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1163 return $settings->getDefaultDateFormat();
1164 }
1165 }
1166
1173 public function setPref($a_keyword, $a_value)
1174 {
1175 if ($a_keyword != "") {
1176 $this->prefs[$a_keyword] = $a_value;
1177 }
1178 }
1179
1185 public function getPref($a_keyword)
1186 {
1187 if (array_key_exists($a_keyword, $this->prefs)) {
1188 return $this->prefs[$a_keyword];
1189 } else {
1190 return false;
1191 }
1192 }
1193
1194 public static function _lookupPref($a_usr_id, $a_keyword)
1195 {
1196 global $ilDB;
1197
1198 $query = "SELECT * FROM usr_pref WHERE usr_id = " . $ilDB->quote($a_usr_id, "integer") . " " .
1199 "AND keyword = " . $ilDB->quote($a_keyword, "text");
1200 $res = $ilDB->query($query);
1201
1202 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
1203 return $row->value;
1204 }
1205 return false;
1206 }
1207
1212 public function readPrefs()
1213 {
1214 global $ilDB;
1215
1216 if (is_array($this->prefs)) {
1217 $this->oldPrefs = $this->prefs;
1218 }
1219
1220 $this->prefs = ilObjUser::_getPreferences($this->id);
1221 }
1222
1228 public function delete()
1229 {
1230 global $rbacadmin, $ilDB;
1231
1232 // deassign from ldap groups
1233 include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1235 $mapping->deleteUser($this->getId());
1236
1237 // remove mailbox / update sent mails
1238 include_once("Services/Mail/classes/class.ilMailbox.php");
1239 $mailbox = new ilMailbox($this->getId());
1240 $mailbox->delete();
1241 $mailbox->updateMailsOfDeletedUser($this->getLogin());
1242
1243 // delete feed blocks on personal desktop
1244 include_once("./Services/Block/classes/class.ilCustomBlock.php");
1245 $costum_block = new ilCustomBlock();
1246 $costum_block->setContextObjId($this->getId());
1247 $costum_block->setContextObjType("user");
1248 $c_blocks = $costum_block->queryBlocksForContext();
1249 include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1250 foreach ($c_blocks as $c_block) {
1251 if ($c_block["type"] == "pdfeed") {
1252 $fb = new ilPDExternalFeedBlock($c_block["id"]);
1253 $fb->delete();
1254 }
1255 }
1256
1257
1258 // delete block settings
1259 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1261
1262 // delete user_account
1263 $ilDB->manipulateF(
1264 "DELETE FROM usr_data WHERE usr_id = %s",
1265 array("integer"),
1266 array($this->getId())
1267 );
1268
1269 $this->deleteMultiTextFields();
1270
1271 // delete user_prefs
1273
1274 $this->removeUserPicture(false); // #8597
1275
1276 // delete user_session
1277 include_once("./Services/Authentication/classes/class.ilSession.php");
1279
1280 // remove user from rbac
1281 $rbacadmin->removeUser($this->getId());
1282
1283 // remove bookmarks
1284 // TODO: move this to class.ilBookmarkFolder
1285 $q = "DELETE FROM bookmark_tree WHERE tree = " .
1286 $ilDB->quote($this->getId(), "integer");
1287 $ilDB->manipulate($q);
1288
1289 $q = "DELETE FROM bookmark_data WHERE user_id = " .
1290 $ilDB->quote($this->getId(), "integer");
1291 $ilDB->manipulate($q);
1292
1293 // DELETE FORUM ENTRIES (not complete in the moment)
1294 include_once './Modules/Forum/classes/class.ilObjForum.php';
1296
1297 // Delete link check notify entries
1298 include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
1300
1301 // Delete crs entries
1302 include_once './Modules/Course/classes/class.ilObjCourse.php';
1304
1305 // Delete user tracking
1306 include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1308
1309 include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1311
1312 // Delete Tracking data SCORM 2004 RTE
1313 include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1315
1316 // Delete Tracking data SCORM 1.2 RTE
1317 include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1319
1320 // remove all notifications
1321 include_once "./Services/Notification/classes/class.ilNotification.php";
1323
1324 // remove portfolios
1325 include_once "./Modules/Portfolio/classes/class.ilObjPortfolio.php";
1327
1328 // remove workspace
1329 include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1330 $tree = new ilWorkspaceTree($this->getId());
1331 $tree->cascadingDelete();
1332
1333 // remove disk quota entries
1334 include_once "./Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1336
1337 // remove reminder entries
1338 require_once 'Services/User/classes/class.ilCronDeleteInactiveUserReminderMail.php';
1340
1341 // badges
1342 include_once "Services/Badge/classes/class.ilBadgeAssignment.php";
1344
1345 // remove org unit assignments
1346 $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
1347 $ilOrgUnitUserAssignmentQueries->deleteAllAssignmentsOfUser($this->getId());
1348
1349 // Delete user defined field entries
1351
1352 // Delete clipboard entries
1353 $this->clipboardDeleteAll();
1354
1355 // Reset owner
1356 $this->resetOwner();
1357
1358 // Trigger deleteUser Event
1359 global $ilAppEventHandler;
1360 $ilAppEventHandler->raise(
1361 'Services/User',
1362 'deleteUser',
1363 array('usr_id' => $this->getId())
1364 );
1365
1366 // delete object data
1367 parent::delete();
1368 return true;
1369 }
1370
1380 public function setFullname($a_title = "", $a_firstname = "", $a_lastname = "")
1381 {
1382 $this->fullname = "";
1383
1384 if ($a_title) {
1385 $fullname = $a_title . " ";
1386 } elseif ($this->utitle) {
1387 $this->fullname = $this->utitle . " ";
1388 }
1389
1390 if ($a_firstname) {
1391 $fullname .= $a_firstname . " ";
1392 } elseif ($this->firstname) {
1393 $this->fullname .= $this->firstname . " ";
1394 }
1395
1396 if ($a_lastname) {
1397 return $fullname . $a_lastname;
1398 }
1399
1400 $this->fullname .= $this->lastname;
1401 }
1402
1417 public function getFullname($a_max_strlen = 0)
1418 {
1419 if (!$a_max_strlen) {
1420 return ilUtil::stripSlashes($this->fullname);
1421 }
1422
1423 if (strlen($this->fullname) <= $a_max_strlen) {
1424 return ilUtil::stripSlashes($this->fullname);
1425 }
1426
1427 if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen) {
1428 return ilUtil::stripSlashes($this->utitle . " " . substr($this->firstname, 0, 1) . ". " . $this->lastname);
1429 }
1430
1431 if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen) {
1432 return ilUtil::stripSlashes($this->firstname . " " . $this->lastname);
1433 }
1434
1435 if ((strlen($this->lastname) + 3) <= $a_max_strlen) {
1436 return ilUtil::stripSlashes(substr($this->firstname, 0, 1) . ". " . $this->lastname);
1437 }
1438
1439 return ilUtil::stripSlashes(substr($this->lastname, 0, $a_max_strlen));
1440 }
1441
1447 public function setLogin($a_str)
1448 {
1449 $this->login = $a_str;
1450 }
1451
1456 public function getLogin()
1457 {
1458 return $this->login;
1459 }
1460
1466 public function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1467 {
1468 $this->passwd = $a_str;
1469 $this->passwd_type = $a_type;
1470 }
1471
1479 public function getPasswd()
1480 {
1481 return $this->passwd;
1482 }
1489 public function getPasswdType()
1490 {
1491 return $this->passwd_type;
1492 }
1493
1499 public function setGender($a_str)
1500 {
1501 $this->gender = substr($a_str, -1);
1502 }
1503
1508 public function getGender()
1509 {
1510 return $this->gender;
1511 }
1512
1520 public function setUTitle($a_str)
1521 {
1522 $this->utitle = $a_str;
1523 }
1524
1531 public function getUTitle()
1532 {
1533 return $this->utitle;
1534 }
1535
1541 public function setFirstname($a_str)
1542 {
1543 $this->firstname = $a_str;
1544 }
1545
1550 public function getFirstname()
1551 {
1552 return $this->firstname;
1553 }
1554
1560 public function setLastname($a_str)
1561 {
1562 $this->lastname = $a_str;
1563 }
1564
1569 public function getLastname()
1570 {
1571 return $this->lastname;
1572 }
1573
1579 public function setInstitution($a_str)
1580 {
1581 $this->institution = $a_str;
1582 }
1583
1588 public function getInstitution()
1589 {
1590 return $this->institution;
1591 }
1592
1598 public function setDepartment($a_str)
1599 {
1600 $this->department = $a_str;
1601 }
1602
1607 public function getDepartment()
1608 {
1609 return $this->department;
1610 }
1611
1617 public function setStreet($a_str)
1618 {
1619 $this->street = $a_str;
1620 }
1621
1626 public function getStreet()
1627 {
1628 return $this->street;
1629 }
1630
1636 public function setCity($a_str)
1637 {
1638 $this->city = $a_str;
1639 }
1640
1645 public function getCity()
1646 {
1647 return $this->city;
1648 }
1649
1655 public function setZipcode($a_str)
1656 {
1657 $this->zipcode = $a_str;
1658 }
1659
1664 public function getZipcode()
1665 {
1666 return $this->zipcode;
1667 }
1668
1675 public function setCountry($a_str)
1676 {
1677 $this->country = $a_str;
1678 }
1679
1685 public function getCountry()
1686 {
1687 return $this->country;
1688 }
1689
1695 public function setSelectedCountry($a_val)
1696 {
1697 $this->sel_country = $a_val;
1698 }
1699
1705 public function getSelectedCountry()
1706 {
1707 return $this->sel_country;
1708 }
1709
1715 public function setPhoneOffice($a_str)
1716 {
1717 $this->phone_office = $a_str;
1718 }
1719
1724 public function getPhoneOffice()
1725 {
1726 return $this->phone_office;
1727 }
1728
1734 public function setPhoneHome($a_str)
1735 {
1736 $this->phone_home = $a_str;
1737 }
1738
1743 public function getPhoneHome()
1744 {
1745 return $this->phone_home;
1746 }
1747
1753 public function setPhoneMobile($a_str)
1754 {
1755 $this->phone_mobile = $a_str;
1756 }
1757
1762 public function getPhoneMobile()
1763 {
1764 return $this->phone_mobile;
1765 }
1766
1772 public function setFax($a_str)
1773 {
1774 $this->fax = $a_str;
1775 }
1776
1781 public function getFax()
1782 {
1783 return $this->fax;
1784 }
1785
1791 public function setClientIP($a_str)
1792 {
1793 $this->client_ip = $a_str;
1794 }
1795
1800 public function getClientIP()
1801 {
1802 return $this->client_ip;
1803 }
1804
1810 public function setMatriculation($a_str)
1811 {
1812 $this->matriculation = $a_str;
1813 }
1814
1819 public function getMatriculation()
1820 {
1821 return $this->matriculation;
1822 }
1823
1830 public static function lookupMatriculation($a_usr_id)
1831 {
1832 global $ilDB;
1833
1834 $query = "SELECT matriculation FROM usr_data " .
1835 "WHERE usr_id = " . $ilDB->quote($a_usr_id);
1836 $res = $ilDB->query($query);
1838 return $row->matriculation ? $row->matriculation : '';
1839 }
1840
1846 public function setEmail($a_str)
1847 {
1848 $this->email = $a_str;
1849 }
1850
1855 public function getEmail()
1856 {
1857 return $this->email;
1858 }
1859
1863 public function getSecondEmail()
1864 {
1865 return $this->second_email;
1866 }
1867
1872 {
1873 $this->second_email = $second_email;
1874 }
1875
1881 public function setHobby($a_str)
1882 {
1883 $this->hobby = $a_str;
1884 }
1885
1890 public function getHobby()
1891 {
1892 return $this->hobby;
1893 }
1894
1900 public function setLanguage($a_str)
1901 {
1902 $this->setPref("language", $a_str);
1903 unset($_SESSION['lang']);
1904 }
1905
1911 public function getLanguage()
1912 {
1913 return $this->prefs["language"];
1914 }
1915
1924 public function setDiskQuota($a_disk_quota)
1925 {
1926 $this->setPref("disk_quota", $a_disk_quota);
1927 }
1928
1938 public function getDiskQuota()
1939 {
1940 return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
1941 }
1942
1944 {
1945 return $this->prefs["wsp_disk_quota"] ? $this->prefs["wsp_disk_quota"] : 0;
1946 }
1947
1948 public function setLastPasswordChangeTS($a_last_password_change_ts)
1949 {
1950 $this->last_password_change_ts = $a_last_password_change_ts;
1951 }
1952
1953 public function getLastPasswordChangeTS()
1954 {
1956 }
1957
1958
1959 public static function _lookupLanguage($a_usr_id)
1960 {
1961 global $DIC;
1962
1963 $ilDB = $DIC->database();
1964 $lng = $DIC->language();
1965
1966 $q = "SELECT value FROM usr_pref WHERE usr_id= " .
1967 $ilDB->quote($a_usr_id, "integer") . " AND keyword = " .
1968 $ilDB->quote('language', "text");
1969 $r = $ilDB->query($q);
1970
1971 while ($row = $ilDB->fetchAssoc($r)) {
1972 return $row['value'];
1973 }
1974 if (is_object($lng)) {
1975 return $lng->getDefaultLanguage();
1976 }
1977 return 'en';
1978 }
1979
1980 public static function _writeExternalAccount($a_usr_id, $a_ext_id)
1981 {
1982 global $ilDB;
1983
1984 $ilDB->manipulateF(
1985 "UPDATE usr_data " .
1986 " SET ext_account = %s WHERE usr_id = %s",
1987 array("text", "integer"),
1988 array($a_ext_id, $a_usr_id)
1989 );
1990 }
1991
1992 public static function _writeAuthMode($a_usr_id, $a_auth_mode)
1993 {
1994 global $ilDB;
1995
1996 $ilDB->manipulateF(
1997 "UPDATE usr_data " .
1998 " SET auth_mode = %s WHERE usr_id = %s",
1999 array("text", "integer"),
2000 array($a_auth_mode, $a_usr_id)
2001 );
2002 }
2003
2008 public function getCurrentLanguage()
2009 {
2010 return $_SESSION['lang'];
2011 }
2012
2018 public function setCurrentLanguage($a_val)
2019 {
2020 $_SESSION['lang'] = $a_val;
2021 }
2022
2028 public function setLastLogin($a_str)
2029 {
2030 $this->last_login = $a_str;
2031 }
2032
2038 public function getLastLogin()
2039 {
2040 return $this->last_login;
2041 }
2042
2048 public function setLastUpdate($a_str)
2049 {
2050 $this->last_update = $a_str;
2051 }
2052 public function getLastUpdate()
2053 {
2054 return $this->last_update;
2055 }
2056
2062 public function setComment($a_str)
2063 {
2064 $this->referral_comment = $a_str;
2065 }
2066
2071 public function getComment()
2072 {
2074 }
2075
2082 public function setApproveDate($a_str)
2083 {
2084 $this->approve_date = $a_str;
2085 }
2086
2092 public function getApproveDate()
2093 {
2094 return $this->approve_date;
2095 }
2096
2097 // BEGIN DiskQuota: show when user accepted user agreement
2103 public function getAgreeDate()
2104 {
2105 return $this->agree_date;
2106 }
2113 public function setAgreeDate($a_str)
2114 {
2115 $this->agree_date = $a_str;
2116 }
2117 // END DiskQuota: show when user accepted user agreement
2118
2125 public function setActive($a_active, $a_owner = 0)
2126 {
2127 $this->setOwner($a_owner);
2128
2129 if ($a_active) {
2130 $this->active = 1;
2131 $this->setApproveDate(date('Y-m-d H:i:s'));
2132 $this->setOwner($a_owner);
2133 } else {
2134 $this->active = 0;
2135 $this->setApproveDate(null);
2136 }
2137 }
2138
2143 public function getActive()
2144 {
2145 return $this->active;
2146 }
2147
2151 public static function _lookupActive($a_usr_id)
2152 {
2153 global $ilDB;
2154
2155 $query = 'SELECT usr_id FROM usr_data ' .
2156 'WHERE active = ' . $ilDB->quote(1, 'integer') . ' ' .
2157 'AND usr_id = ' . $ilDB->quote($a_usr_id, 'integer');
2158 $res = $ilDB->query($query);
2159 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
2160 return true;
2161 }
2162 return false;
2163 }
2164
2170 public function syncActive()
2171 {
2172 global $ilAuth;
2173
2174 $storedActive = 0;
2175 if ($this->getStoredActive($this->id)) {
2176 $storedActive = 1;
2177 }
2178
2179 $currentActive = 0;
2180 if ($this->active) {
2181 $currentActive = 1;
2182 }
2183
2184 if ((!empty($storedActive) && empty($currentActive)) ||
2185 (empty($storedActive) && !empty($currentActive))) {
2186 $this->setActive($currentActive, self::getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2187 }
2188 }
2189
2196 public function getStoredActive($a_id)
2197 {
2198 $active = ilObjUser::_lookup($a_id, "active");
2199 return $active ? true : false;
2200 }
2201
2207 public function setSkin($a_str)
2208 {
2209 // TODO: exception handling (dir exists)
2210 $this->skin = $a_str;
2211 }
2212
2213 public function setTimeLimitOwner($a_owner)
2214 {
2215 $this->time_limit_owner = $a_owner;
2216 }
2217 public function getTimeLimitOwner()
2218 {
2219 return $this->time_limit_owner ? $this->time_limit_owner : 7;
2220 }
2221 public function setTimeLimitFrom($a_from)
2222 {
2223 $this->time_limit_from = $a_from;
2224 }
2225 public function getTimeLimitFrom()
2226 {
2227 return $this->time_limit_from;
2228 }
2229 public function setTimeLimitUntil($a_until)
2230 {
2231 $this->time_limit_until = $a_until;
2232 }
2233 public function getTimeLimitUntil()
2234 {
2235 return $this->time_limit_until;
2236 }
2237 public function setTimeLimitUnlimited($a_unlimited)
2238 {
2239 $this->time_limit_unlimited = $a_unlimited;
2240 }
2241 public function getTimeLimitUnlimited()
2242 {
2243 return $this->time_limit_unlimited;
2244 }
2245 public function setTimeLimitMessage($a_time_limit_message)
2246 {
2247 return $this->time_limit_message = $a_time_limit_message;
2248 }
2249 public function getTimeLimitMessage()
2250 {
2251 return $this->time_limit_message;
2252 }
2253
2254 public function setLoginAttempts($a_login_attempts)
2255 {
2256 $this->login_attempts = $a_login_attempts;
2257 }
2258
2259 public function getLoginAttempts()
2260 {
2261 return $this->login_attempts;
2262 }
2263
2264
2265 public function checkTimeLimit()
2266 {
2267 if ($this->getTimeLimitUnlimited()) {
2268 return true;
2269 }
2270 if ($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time()) {
2271 return true;
2272 }
2273 return false;
2274 }
2275 public function setProfileIncomplete($a_prof_inc)
2276 {
2277 $this->profile_incomplete = (boolean) $a_prof_inc;
2278 }
2279 public function getProfileIncomplete()
2280 {
2281 if ($this->id == ANONYMOUS_USER_ID) {
2282 return false;
2283 }
2284 return $this->profile_incomplete;
2285 }
2286
2291 {
2292 if ($this->id == ANONYMOUS_USER_ID) {
2293 return false;
2294 }
2295
2296 if ($this->id == SYSTEM_USER_ID) {
2297 require_once './Services/User/classes/class.ilUserPasswordManager.php';
2298 if (
2299 \ilUserPasswordManager::getInstance()->verifyPassword($this, base64_decode('aG9tZXI=')) &&
2301 ) {
2302 return true;
2303 } else {
2304 return false;
2305 }
2306 }
2307
2308 require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2310
2311 if (
2313 $security->isPasswordChangeOnFirstLoginEnabled() &&
2314 $this->getLastPasswordChangeTS() == 0 &&
2315 $this->is_self_registered == false
2316 ) {
2317 return true;
2318 }
2319
2320 return false;
2321 }
2322
2323 public function isPasswordExpired()
2324 {
2325 if ($this->id == ANONYMOUS_USER_ID) {
2326 return false;
2327 }
2328
2329 require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2331 if ($this->getLastPasswordChangeTS() > 0) {
2332 $max_pass_age = $security->getPasswordMaxAge();
2333 if ($max_pass_age > 0) {
2334 $max_pass_age_ts = ($max_pass_age * 86400);
2335 $pass_change_ts = $this->getLastPasswordChangeTS();
2336 $current_ts = time();
2337
2338 if (($current_ts - $pass_change_ts) > $max_pass_age_ts) {
2340 return true;
2341 }
2342 }
2343 }
2344 }
2345
2346 return false;
2347 }
2348
2349 public function getPasswordAge()
2350 {
2351 $current_ts = time();
2352 $pass_change_ts = $this->getLastPasswordChangeTS();
2353 $password_age = (int) (($current_ts - $pass_change_ts) / 86400);
2354 return $password_age;
2355 }
2356
2358 {
2359 global $ilDB;
2360
2361 $this->setLastPasswordChangeTS(time());
2362
2363 $query = "UPDATE usr_data SET last_password_change = %s " .
2364 "WHERE usr_id = %s";
2365 $affected = $ilDB->manipulateF(
2366 $query,
2367 array('integer','integer'),
2368 array($this->getLastPasswordChangeTS(),$this->id)
2369 );
2370 if ($affected) {
2371 return true;
2372 } else {
2373 return false;
2374 }
2375 }
2376
2377 public function resetLastPasswordChange()
2378 {
2379 global $ilDB;
2380
2381 $query = "UPDATE usr_data SET last_password_change = 0 " .
2382 "WHERE usr_id = %s";
2383 $affected = $ilDB->manipulateF(
2384 $query,
2385 array('integer'),
2386 array($this->getId())
2387 );
2388 if ($affected) {
2389 return true;
2390 } else {
2391 return false;
2392 }
2393 }
2394
2400 public function setLatitude($a_latitude)
2401 {
2402 $this->latitude = $a_latitude;
2403 }
2404
2410 public function getLatitude()
2411 {
2412 return $this->latitude;
2413 }
2414
2420 public function setLongitude($a_longitude)
2421 {
2422 $this->longitude = $a_longitude;
2423 }
2424
2430 public function getLongitude()
2431 {
2432 return $this->longitude;
2433 }
2434
2440 public function setLocationZoom($a_locationzoom)
2441 {
2442 $this->loc_zoom = $a_locationzoom;
2443 }
2444
2450 public function getLocationZoom()
2451 {
2452 return $this->loc_zoom;
2453 }
2454
2455
2461 public static function hasActiveSession($a_user_id, $a_session_id)
2462 {
2463 global $ilDB;
2464
2465 $set = $ilDB->queryf(
2466 '
2467 SELECT COUNT(*) session_count
2468 FROM usr_session WHERE user_id = %s AND expires > %s AND session_id != %s ',
2469 array('integer', 'integer', 'text'),
2470 array($a_user_id, time(), $a_session_id)
2471 );
2472 $row = $ilDB->fetchAssoc($set);
2473 return (bool) $row['session_count'];
2474 }
2475
2476 /*
2477 * check user id with login name
2478 * @access public
2479 */
2480 public function checkUserId()
2481 {
2482 global $ilAuth, $ilSetting;
2483
2486 if ($id > 0) {
2487 return $id;
2488 }
2489 return false;
2490 }
2491
2495 private static function getLoginFromAuth()
2496 {
2497 global $ilAuth;
2498
2499 $uid = $GLOBALS['DIC']['ilAuthSession']->getUserId();
2501
2502 // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2503 require_once('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2506 }
2507 return $login;
2508 }
2509
2516 public static function toUsernameWithoutDomain($a_login)
2517 {
2518 // Remove all characters including the last slash or the last backslash
2519 // in the username
2520 $pos = strrpos($a_login, '/');
2521 $pos2 = strrpos($a_login, '\\');
2522 if ($pos === false || $pos < $pos2) {
2523 $pos = $pos2;
2524 }
2525 if ($pos !== false) {
2526 $a_login = substr($a_login, $pos + 1);
2527 }
2528 return $a_login;
2529 }
2530
2531 /*
2532 * check to see if current user has been made active
2533 * @access public
2534 * @return true if active, otherwise false
2535 */
2536 public function isCurrentUserActive()
2537 {
2538 global $ilDB,$ilAuth;
2539
2541 $set = $ilDB->queryF(
2542 "SELECT active FROM usr_data WHERE login= %s",
2543 array("text"),
2544 array($login)
2545 );
2546 //query has got a result
2547 if ($rec = $ilDB->fetchAssoc($set)) {
2548 if ($rec["active"]) {
2549 return true;
2550 }
2551 }
2552
2553 return false;
2554 }
2555
2556 /*
2557 * STATIC METHOD
2558 * get the user_id of a login name
2559 * @param string login name
2560 * @return integer id of user
2561 * @static
2562 * @access public
2563 */
2564 public static function getUserIdByLogin($a_login)
2565 {
2566 return (int) ilObjUser::_lookupId($a_login);
2567 }
2568
2577 public static function _getUserIdsByEmail($a_email)
2578 {
2579 global $ilias, $ilDB;
2580
2581 $res = $ilDB->queryF(
2582 "SELECT login FROM usr_data " .
2583 "WHERE email = %s and active = 1",
2584 array("text"),
2585 array($a_email)
2586 );
2587 $ids = array();
2588 while ($row = $ilDB->fetchObject($res)) {
2589 $ids[] = $row->login;
2590 }
2591
2592 return $ids;
2593 }
2594
2595
2596
2605 public function getUserIdByEmail($a_email)
2606 {
2607 global $ilDB;
2608
2609 $res = $ilDB->queryF("SELECT usr_id FROM usr_data " .
2610 "WHERE email = %s", array("text"), array($a_email));
2611
2612 $row = $ilDB->fetchObject($res);
2613 return $row->usr_id ? $row->usr_id : 0;
2614 }
2615
2616 /*
2617 * STATIC METHOD
2618 * get the login name of a user_id
2619 * @param integer id of user
2620 * @return string login name; false if not found
2621 * @static
2622 * @access public
2623 */
2624 public function getLoginByUserId($a_userid)
2625 {
2626 $login = ilObjUser::_lookupLogin($a_userid);
2627 return $login ? $login : false;
2628 }
2629
2640 public static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = false)
2641 {
2642 global $ilias, $ilDB, $ilLog;
2643
2644
2645 $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2646
2647 $without_anonymous_users = true;
2648
2649 // determine join filter
2650 $join_filter = " WHERE ";
2651 if ($filter_settings !== false && strlen($filter_settings)) {
2652 switch ($filter_settings) {
2653 case 3:
2654 // show only users without courses
2655 $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.usr_id IS NULL AND ";
2656 break;
2657 case 5:
2658 // show only users with a certain course membership
2659 $ref_id = $_SESSION["user_filter_data"];
2660 if ($ref_id) {
2661 $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.obj_id = " .
2662 "(SELECT obj_id FROM object_reference WHERE ref_id = " . $ilDB->quote($ref_id, "integer") . ") AND ";
2663 }
2664 break;
2665 case 6:
2666 global $rbacreview;
2667 $ref_id = $_SESSION["user_filter_data"];
2668 if ($ref_id) {
2669 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
2670 if (is_array($local_roles) && count($local_roles)) {
2671 $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE " .
2672 $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles) . " AND ";
2673 }
2674 }
2675 break;
2676 case 7:
2677 global $rbacreview;
2678 $rol_id = $_SESSION["user_filter_data"];
2679 if ($rol_id) {
2680 $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = " .
2681 $ilDB->quote($rol_id, "integer") . " AND ";
2682 $without_anonymous_users = false;
2683 }
2684 break;
2685 }
2686 }
2687 // This is a temporary hack to search users by their role
2688 // See Mantis #338. This is a hack due to Mantis #337.
2689 if (strtolower(substr($a_search_str, 0, 5)) == "role:") {
2690 $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email " .
2691 "FROM object_data,rbac_ua,usr_data " .
2692 "WHERE " . $ilDB->like("object_data.title", "text", "%" . substr($a_search_str, 5) . "%") .
2693 " AND object_data.type = 'role' " .
2694 "AND rbac_ua.rol_id = object_data.obj_id " .
2695 "AND usr_data.usr_id = rbac_ua.usr_id " .
2696 "AND rbac_ua.usr_id != " . $ilDB->quote(ANONYMOUS_USER_ID, "integer");
2697 } else {
2698 $query.= $join_filter .
2699 "(" . $ilDB->like("usr_data.login", "text", "%" . $a_search_str . "%") . " " .
2700 "OR " . $ilDB->like("usr_data.firstname", "text", "%" . $a_search_str . "%") . " " .
2701 "OR " . $ilDB->like("usr_data.lastname", "text", "%" . $a_search_str . "%") . " " .
2702 "OR " . $ilDB->like("usr_data.email", "text", "%" . $a_search_str . "%") . ") ";
2703
2704 if ($filter_settings !== false && strlen($filter_settings)) {
2705 switch ($filter_settings) {
2706 case 0:
2707 $query.= " AND usr_data.active = " . $ilDB->quote(0, "integer") . " ";
2708 break;
2709 case 1:
2710 $query.= " AND usr_data.active = " . $ilDB->quote(1, "integer") . " ";
2711 break;
2712 case 2:
2713 $query.= " AND usr_data.time_limit_unlimited = " . $ilDB->quote(0, "integer") . " ";
2714 break;
2715 case 4:
2716 $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"]));
2717 $query.= " AND last_login < " . $ilDB->quote($date, "timestamp") . " ";
2718 break;
2719 }
2720 }
2721
2722 if ($without_anonymous_users) {
2723 $query.= "AND usr_data.usr_id != " . $ilDB->quote(ANONYMOUS_USER_ID, "integer");
2724 }
2725
2726 if (is_numeric($active) && $active > -1 && $filter_settings === false) {
2727 $query.= " AND active = " . $ilDB->quote($active, "integer") . " ";
2728 }
2729 }
2730 $ilLog->write($query);
2731 $res = $ilDB->query($query);
2732 while ($row = $ilDB->fetchObject($res)) {
2733 $users[] = array(
2734 "usr_id" => $row->usr_id,
2735 "login" => $row->login,
2736 "firstname" => $row->firstname,
2737 "lastname" => $row->lastname,
2738 "email" => $row->email,
2739 "active" => $row->active);
2740 $ids[] = $row->usr_id;
2741 }
2742 if ($a_return_ids_only) {
2743 return $ids ? $ids : array();
2744 } else {
2745 return $users ? $users : array();
2746 }
2747 }
2748
2752 public static function getAllUserLogins()
2753 {
2757 global $ilDB;
2758
2759 $logins = array();
2760
2761 $res = $ilDB->query(
2762 "SELECT login FROM usr_data WHERE " . $ilDB->in('usr_id', array(ANONYMOUS_USER_ID), true, 'integer')
2763 );
2764 while ($row = $ilDB->fetchAssoc($res)) {
2765 $logins[] = $row['login'];
2766 }
2767
2768 return $logins;
2769 }
2770
2779 public static function _readUsersProfileData($a_user_ids)
2780 {
2781 global $ilDB;
2782 $res = $ilDB->query("SELECT * FROM usr_data WHERE " .
2783 $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2784 while ($row = $ilDB->fetchAssoc($res)) {
2785 $user_data["$row[usr_id]"] = $row;
2786 }
2787 return $user_data ? $user_data : array();
2788 }
2789
2798 public static function _getAllUserData($a_fields = null, $active =-1)
2799 {
2800 global $ilDB;
2801
2802 $result_arr = array();
2803 $types = array();
2804 $values = array();
2805
2806 if ($a_fields !== null and is_array($a_fields)) {
2807 if (count($a_fields) == 0) {
2808 $select = "*";
2809 } else {
2810 if (($usr_id_field = array_search("usr_id", $a_fields)) !== false) {
2811 unset($a_fields[$usr_id_field]);
2812 }
2813
2814 $select = implode(",", $a_fields) . ",usr_data.usr_id";
2815 // online time
2816 if (in_array('online_time', $a_fields)) {
2817 $select .= ",ut_online.online_time ";
2818 }
2819 }
2820
2821 $q = "SELECT " . $select . " FROM usr_data ";
2822
2823 // Add online_time if desired
2824 // Need left join here to show users that never logged in
2825 if (in_array('online_time', $a_fields)) {
2826 $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2827 }
2828
2829 switch ($active) {
2830 case 0:
2831 case 1:
2832 $q .= "WHERE active = " . $ilDB->quote($active, "integer");
2833 break;
2834 case 2:
2835 $q .= "WHERE time_limit_unlimited= " . $ilDB->quote(0, "integer");;
2836 break;
2837 case 3:
2838 $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND " .
2839 $ilDB->like("object_data.title", "text", "%crs%") . " AND usr_data.usr_id = rbac_ua.usr_id";
2840 $r = $ilDB->query($qtemp);
2841 $course_users = array();
2842 while ($row = $ilDB->fetchAssoc($r)) {
2843 array_push($course_users, $row["usr_id"]);
2844 }
2845 if (count($course_users)) {
2846 $q .= " WHERE " . $ilDB->in("usr_data.usr_id", $course_users, true, "integer") . " ";
2847 } else {
2848 return $result_arr;
2849 }
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 $q.= " AND last_login < " . $ilDB->quote($date, "timestamp");
2854 break;
2855 case 5:
2856 $ref_id = $_SESSION["user_filter_data"];
2857 if ($ref_id) {
2858 $q .= " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id " .
2859 "WHERE obj_members.obj_id = (SELECT obj_id FROM object_reference " .
2860 "WHERE ref_id = " . $ilDB->quote($ref_id, "integer") . ") ";
2861 }
2862 break;
2863 case 6:
2864 global $rbacreview;
2865 $ref_id = $_SESSION["user_filter_data"];
2866 if ($ref_id) {
2867 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id, false);
2868 if (is_array($local_roles) && count($local_roles)) {
2869 $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE " .
2870 $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer") . " ";
2871 }
2872 }
2873 break;
2874 case 7:
2875 $rol_id = $_SESSION["user_filter_data"];
2876 if ($rol_id) {
2877 $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = " .
2878 $ilDB->quote($rol_id, "integer");
2879 }
2880 break;
2881 }
2882 $r = $ilDB->query($q);
2883
2884 while ($row = $ilDB->fetchAssoc($r)) {
2885 $result_arr[] = $row;
2886 }
2887 }
2888
2889 return $result_arr;
2890 }
2891
2895 public static function _getNumberOfUsersForStyle($a_skin, $a_style)
2896 {
2897 global $ilDB;
2898
2899 $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 " .
2900 " WHERE up1.keyword= " . $ilDB->quote("style", "text") .
2901 " AND up1.value= " . $ilDB->quote($a_style, "text") .
2902 " AND up2.keyword= " . $ilDB->quote("skin", "text") .
2903 " AND up2.value= " . $ilDB->quote($a_skin, "text") .
2904 " AND up1.usr_id = up2.usr_id ";
2905
2906 $cnt_set = $ilDB->query($q);
2907
2908 $cnt_rec = $ilDB->fetchAssoc($cnt_set);
2909
2910 return $cnt_rec["cnt"];
2911 }
2912
2916 public static function _getAllUserAssignedStyles()
2917 {
2918 global $ilDB;
2919
2920 $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 " .
2921 " WHERE up1.keyword = " . $ilDB->quote("style", "text") .
2922 " AND up2.keyword = " . $ilDB->quote("skin", "text") .
2923 " AND up1.usr_id = up2.usr_id";
2924
2925 $sty_set = $ilDB->query($q);
2926
2927 $styles = array();
2928 while ($sty_rec = $ilDB->fetchAssoc($sty_set)) {
2929 $styles[] = $sty_rec["skin"] . ":" . $sty_rec["style"];
2930 }
2931
2932 return $styles;
2933 }
2934
2938 public static function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
2939 {
2940 global $ilDB;
2941
2942 $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 " .
2943 " WHERE up1.keyword= " . $ilDB->quote("style", "text") .
2944 " AND up1.value= " . $ilDB->quote($a_from_style, "text") .
2945 " AND up2.keyword= " . $ilDB->quote("skin", "text") .
2946 " AND up2.value= " . $ilDB->quote($a_from_skin, "text") .
2947 " AND up1.usr_id = up2.usr_id ";
2948
2949 $usr_set = $ilDB->query($q);
2950
2951 while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
2952 self::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
2953 self::_writePref($usr_rec["usr_id"], "style", $a_to_style);
2954 }
2955 }
2956
2957
2967 public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
2968 {
2969 global $ilDB;
2970
2971 $item_set = $ilDB->queryF(
2972 "SELECT * FROM desktop_item WHERE " .
2973 "item_id = %s AND type = %s AND user_id = %s",
2974 array("integer", "text", "integer"),
2975 array($a_item_id, $a_type, $a_usr_id)
2976 );
2977
2978 // only insert if item is not already on desktop
2979 if (!$ilDB->fetchAssoc($item_set)) {
2980 $ilDB->manipulateF(
2981 "INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES " .
2982 " (%s,%s,%s,%s)",
2983 array("integer", "text", "integer", "text"),
2984 array($a_item_id,$a_type,$a_usr_id,$a_par)
2985 );
2986 }
2987
2988 include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
2990 }
2991
2999 public function addDesktopItem($a_item_id, $a_type, $a_par = "")
3000 {
3001 ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3002 }
3003
3012 public function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3013 {
3014 global $ilDB;
3015
3016 $ilDB->manipulateF(
3017 "UPDATE desktop_item SET parameters = %s " .
3018 " WHERE item_id = %s AND type = %s AND user_id = %s",
3019 array("text", "integer", "text", "integer"),
3020 array($a_par, $a_item_id, $a_type, $this->getId())
3021 );
3022 }
3023
3024
3034 public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3035 {
3036 global $ilDB;
3037
3038 $ilDB->manipulateF(
3039 "DELETE FROM desktop_item WHERE " .
3040 " item_id = %s AND type = %s AND user_id = %s",
3041 array("integer", "text", "integer"),
3042 array($a_item_id, $a_type, $a_usr_id)
3043 );
3044
3045 include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3047 }
3048
3056 public function dropDesktopItem($a_item_id, $a_type)
3057 {
3058 ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3059 }
3060
3067 public static function _removeItemFromDesktops($a_id)
3068 {
3069 global $ilDB;
3070
3071 $r = $ilDB->queryF(
3072 "SELECT user_id FROM desktop_item WHERE item_id = %s",
3073 array("integer"),
3074 array($a_id)
3075 );
3076
3077 $users = array();
3078
3079 while ($row = $ilDB->fetchObject($r)) {
3080 $users[] = $row->user_id;
3081 } // while
3082
3083 if (count($users) > 0) {
3084 $ilDB->manipulateF(
3085 "DELETE FROM desktop_item WHERE item_id = %s",
3086 array("integer"),
3087 array($a_id)
3088 );
3089 }
3090
3091 return $users;
3092 }
3093
3103 public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3104 {
3105 global $ilDB;
3106
3107 if (self::$is_desktop_item_loaded[$a_usr_id . ":" . $a_item_id]) {
3108 return self::$is_desktop_item_cache[$a_usr_id . ":" . $a_item_id . ":" . $a_type];
3109 }
3110 $item_set = $ilDB->queryF(
3111 "SELECT item_id FROM desktop_item WHERE " .
3112 "item_id = %s AND type = %s AND user_id = %s",
3113 array("integer", "text", "integer"),
3114 array($a_item_id, $a_type, $a_usr_id)
3115 );
3116
3117 if ($ilDB->fetchAssoc($item_set)) {
3118 return true;
3119 } else {
3120 return false;
3121 }
3122 }
3123
3130 public static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3131 {
3132 global $ilDB;
3133
3134 if (!is_array($a_item_ids)) {
3135 return;
3136 }
3137
3138 $item_ids = array();
3139 foreach ($a_item_ids as $id) {
3140 if (!self::$is_desktop_item_loaded[$a_usr_id . ":" . $id]) {
3141 $item_ids[] = $id;
3142 }
3143 self::$is_desktop_item_loaded[$a_usr_id . ":" . $id] = true;
3144 }
3145
3146 if (count($item_ids) > 0) {
3147 $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE " .
3148 $ilDB->in("item_id", $item_ids, false, "integer") .
3149 " AND user_id = " . $ilDB->quote($a_usr_id, "integer"));
3150 while ($r = $ilDB->fetchAssoc($item_set)) {
3151 self::$is_desktop_item_cache[$a_usr_id . ":" . $r["item_id"] . ":" . $r["type"]]
3152 = true;
3153 }
3154 }
3155 }
3156
3164 public function isDesktopItem($a_item_id, $a_type)
3165 {
3166 return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3167 }
3168
3169 public function getDesktopItems($a_types = "")
3170 {
3171 return $this->_lookupDesktopItems($this->getId(), $a_types);
3172 }
3173
3180 public static function _lookupDesktopItems($user_id, $a_types = "")
3181 {
3182 global $ilUser, $rbacsystem, $tree, $ilDB;
3183
3184 if ($a_types == "") {
3185 $is_nested_set = ($tree->getTreeImplementation() instanceof ilNestedSetTree);
3186
3187 $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type " .
3188 " FROM desktop_item it, object_reference oref " .
3189 ", object_data obj" .
3190 " WHERE " .
3191 "it.item_id = oref.ref_id AND " .
3192 "oref.obj_id = obj.obj_id AND " .
3193 "it.user_id = %s", array("integer"), array($user_id));
3194 $items = $all_parent_path = array();
3195 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
3196 if ($tree->isInTree($item_rec["ref_id"])
3197 && $item_rec["type"] != "rolf"
3198 && $item_rec["type"] != "itgr") { // due to bug 11508
3199 $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3200
3201 if (!isset($all_parent_path[$parent_ref])) {
3202 // #15746
3203 //if($is_nested_set)
3204 //{
3205 // $par_left = $tree->getLeftValue($parent_ref);
3206 // $all_parent_path[$parent_ref] = sprintf("%010d", $par_left);
3207 //}
3208 //else
3209 //{
3210 if ($parent_ref > 0) { // workaround for #0023176
3211 $node = $tree->getNodeData($parent_ref);
3212 $all_parent_path[$parent_ref] = $node["title"];
3213 } else {
3214 $all_parent_path[$parent_ref] = "";
3215 }
3216 //}
3217 }
3218
3219 $parent_path = $all_parent_path[$parent_ref];
3220
3221 $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3222 $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3223 $items[$parent_path . $title . $item_rec["ref_id"]] =
3224 array("ref_id" => $item_rec["ref_id"],
3225 "obj_id" => $item_rec["obj_id"],
3226 "type" => $item_rec["type"],
3227 "title" => $title,
3228 "description" => $desc,
3229 "parent_ref" => $parent_ref);
3230 }
3231 }
3232 ksort($items);
3233 } else {
3234 // due to bug 11508
3235 if (!is_array($a_types)) {
3236 $a_types = array($a_types);
3237 }
3238 $items = array();
3239 $foundsurveys = array();
3240 foreach ($a_types as $a_type) {
3241 if ($a_type == "itgr") {
3242 continue;
3243 }
3244 $item_set = $ilDB->queryF(
3245 "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref " .
3246 ", object_data obj WHERE " .
3247 "it.item_id = oref.ref_id AND " .
3248 "oref.obj_id = obj.obj_id AND " .
3249 "it.type = %s AND " .
3250 "it.user_id = %s " .
3251 "ORDER BY title",
3252 array("text", "integer"),
3253 array($a_type, $user_id)
3254 );
3255
3256 while ($item_rec = $ilDB->fetchAssoc($item_set)) {
3257 $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3258 $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3259 $items[$title . $a_type . $item_rec["ref_id"]] =
3260 array("ref_id" => $item_rec["ref_id"],
3261 "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3262 "title" => $title, "description" => $desc);
3263 }
3264 }
3265 ksort($items);
3266 }
3267
3268 return $items;
3269 }
3270
3276
3284 public function addObjectToClipboard(
3285 $a_item_id,
3286 $a_type,
3287 $a_title,
3288 $a_parent = 0,
3289 $a_time = 0,
3290 $a_order_nr = 0
3291 ) {
3292 global $ilDB;
3293
3294 if ($a_time == 0) {
3295 $a_time = date("Y-m-d H:i:s", time());
3296 }
3297
3298 $item_set = $ilDB->queryF(
3299 "SELECT * FROM personal_clipboard WHERE " .
3300 "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3301 array("integer", "integer", "text", "integer"),
3302 array(0, $a_item_id, $a_type, $this->getId())
3303 );
3304
3305 // only insert if item is not already in clipboard
3306 if (!$d = $item_set->fetchRow()) {
3307 $ilDB->manipulateF(
3308 "INSERT INTO personal_clipboard " .
3309 "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES " .
3310 " (%s,%s,%s,%s,%s,%s,%s)",
3311 array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3312 array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr)
3313 );
3314 } else {
3315 $ilDB->manipulateF(
3316 "UPDATE personal_clipboard SET insert_time = %s " .
3317 "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3318 array("timestamp", "integer", "integer", "text"),
3319 array($a_time, $this->getId(), $a_item_id, $a_type)
3320 );
3321 }
3322 }
3323
3327 public function addToPCClipboard($a_content, $a_time, $a_nr)
3328 {
3329 global $ilDB;
3330 if ($a_time == 0) {
3331 $a_time = date("Y-m-d H:i:s", time());
3332 }
3333 $ilDB->insert("personal_pc_clipboard", array(
3334 "user_id" => array("integer", $this->getId()),
3335 "content" => array("clob", $a_content),
3336 "insert_time" => array("timestamp", $a_time),
3337 "order_nr" => array("integer", $a_nr)
3338 ));
3339 }
3340
3344 public function getPCClipboardContent()
3345 {
3346 global $ilDB;
3347
3348 $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard " .
3349 " WHERE user_id = %s", array("integer"), array($this->getId()));
3350 $row = $ilDB->fetchAssoc($set);
3351
3352 $set = $ilDB->queryF(
3353 "SELECT * FROM personal_pc_clipboard " .
3354 " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3355 array("integer", "timestamp"),
3356 array($this->getId(), $row["mtime"])
3357 );
3358 $content = array();
3359 while ($row = $ilDB->fetchAssoc($set)) {
3360 $content[] = $row["content"];
3361 }
3362
3363 return $content;
3364 }
3365
3370 {
3371 global $ilDB;
3372
3373 $set = $ilDB->queryF(
3374 "SELECT * FROM personal_clipboard WHERE " .
3375 "parent = %s AND type = %s AND user_id = %s",
3376 array("integer", "text", "integer"),
3377 array(0, $a_type, $this->getId())
3378 );
3379 if ($rec = $ilDB->fetchAssoc($set)) {
3380 return true;
3381 }
3382
3383 return false;
3384 }
3385
3390 {
3391 global $ilDB;
3392
3393 $ilDB->manipulateF(
3394 "DELETE FROM personal_clipboard WHERE " .
3395 "type = %s AND user_id = %s",
3396 array("text", "integer"),
3397 array($a_type, $this->getId())
3398 );
3399 }
3400
3404 public function clipboardDeleteAll()
3405 {
3406 global $ilDB;
3407
3408 $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE " .
3409 "user_id = %s", array("integer"), array($this->getId()));
3410 }
3411
3415 public function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3416 {
3417 global $ilDB;
3418
3419 $par = "";
3420 if ($a_top_nodes_only) {
3421 $par = " AND parent = " . $ilDB->quote(0, "integer") . " ";
3422 }
3423
3424 $type_str = ($a_type != "")
3425 ? " AND type = " . $ilDB->quote($a_type, "text") . " "
3426 : "";
3427 $q = "SELECT * FROM personal_clipboard WHERE " .
3428 "user_id = " . $ilDB->quote($this->getId(), "integer") . " " .
3429 $type_str . $par .
3430 " ORDER BY order_nr";
3431 $objs = $ilDB->query($q);
3432 $objects = array();
3433 while ($obj = $ilDB->fetchAssoc($objs)) {
3434 if ($obj["type"] == "mob") {
3435 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3436 }
3437 if ($obj["type"] == "incl") {
3438 include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3439 $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3440 }
3441 $objects[] = array("id" => $obj["item_id"],
3442 "type" => $obj["type"], "title" => $obj["title"],
3443 "insert_time" => $obj["insert_time"]);
3444 }
3445 return $objects;
3446 }
3447
3451 public function getClipboardChilds($a_parent, $a_insert_time)
3452 {
3453 global $ilDB, $ilUser;
3454
3455 $objs = $ilDB->queryF(
3456 "SELECT * FROM personal_clipboard WHERE " .
3457 "user_id = %s AND parent = %s AND insert_time = %s " .
3458 " ORDER BY order_nr",
3459 array("integer", "integer", "timestamp"),
3460 array($ilUser->getId(), (int) $a_parent, $a_insert_time)
3461 );
3462 $objects = array();
3463 while ($obj = $ilDB->fetchAssoc($objs)) {
3464 if ($obj["type"] == "mob") {
3465 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3466 }
3467 $objects[] = array("id" => $obj["item_id"],
3468 "type" => $obj["type"], "title" => $obj["title"], "insert_time" => $obj["insert_time"]);
3469 }
3470 return $objects;
3471 }
3472
3481 public static function _getUsersForClipboadObject($a_type, $a_id)
3482 {
3483 global $ilDB;
3484
3485 $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE " .
3486 "item_id = " . $ilDB->quote($a_id, "integer") . " AND " .
3487 "type = " . $ilDB->quote($a_type, "text");
3488 $user_set = $ilDB->query($q);
3489 $users = array();
3490 while ($user_rec = $ilDB->fetchAssoc($user_set)) {
3491 $users[] = $user_rec["user_id"];
3492 }
3493
3494 return $users;
3495 }
3496
3504 public function removeObjectFromClipboard($a_item_id, $a_type)
3505 {
3506 global $ilDB;
3507
3508 $q = "DELETE FROM personal_clipboard WHERE " .
3509 "item_id = " . $ilDB->quote($a_item_id, "integer") .
3510 " AND type = " . $ilDB->quote($a_type, "text") . " " .
3511 " AND user_id = " . $ilDB->quote($this->getId(), "integer");
3512 $ilDB->manipulate($q);
3513 }
3514
3515 public static function _getImportedUserId($i2_id)
3516 {
3517 global $ilDB;
3518
3519 $query = "SELECT obj_id FROM object_data WHERE import_id = " .
3520 $ilDB->quote($i2_id, "text");
3521
3522 $res = $ilDB->query($query);
3523 while ($row = $ilDB->fetchObject($res)) {
3524 $id = $row->obj_id;
3525 }
3526 return $id ? $id : 0;
3527 }
3528
3534 public static function lookupOrgUnitsRepresentation($a_usr_id)
3535 {
3536 require_once('./Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php');
3537 return ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_usr_id);
3538 }
3539
3540
3545 {
3547 }
3548
3549
3554 public function setAuthMode($a_str)
3555 {
3556 $this->auth_mode = $a_str;
3557 }
3558
3563 public function getAuthMode($a_auth_key = false)
3564 {
3565 if (!$a_auth_key) {
3566 return $this->auth_mode;
3567 }
3568
3569 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3570 return ilAuthUtils::_getAuthMode($this->auth_mode);
3571 }
3572
3580 public function setExternalAccount($a_str)
3581 {
3582 $this->ext_account = $a_str;
3583 }
3584
3592 public function getExternalAccount()
3593 {
3594 return $this->ext_account;
3595 }
3596
3608 public static function _getExternalAccountsByAuthMode($a_auth_mode, $a_read_auth_default = false)
3609 {
3610 global $ilDB,$ilSetting;
3611
3612 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3613 $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data " .
3614 "WHERE auth_mode = %s";
3615 $types[] = "text";
3616 $values[] = $a_auth_mode;
3617 if ($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode', AUTH_LOCAL)) == $a_auth_mode) {
3618 $q.= " OR auth_mode = %s ";
3619 $types[] = "text";
3620 $values[] = 'default';
3621 }
3622
3623 $res = $ilDB->queryF($q, $types, $values);
3624 while ($row = $ilDB->fetchObject($res)) {
3625 if ($row->auth_mode == 'default') {
3626 $accounts[$row->usr_id] = $row->login;
3627 } else {
3628 $accounts[$row->usr_id] = $row->ext_account;
3629 }
3630 }
3631 return $accounts ? $accounts : array();
3632 }
3633
3641 public static function _toggleActiveStatusOfUsers($a_usr_ids, $a_status)
3642 {
3643 global $ilDB;
3644
3645 if (!is_array($a_usr_ids)) {
3646 return false;
3647 }
3648
3649
3650 if ($a_status) {
3651 $q = "UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE " .
3652 $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3653 $ilDB->manipulate($q);
3654 } else {
3655 $usrId_IN_usrIds = $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3656
3657 $q = "UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds";
3658 $ilDB->manipulate($q);
3659
3660 $queryString = "
3661 UPDATE usr_data
3662 SET inactivation_date = %s
3663 WHERE inactivation_date IS NULL
3664 AND $usrId_IN_usrIds
3665 ";
3666 $ilDB->manipulateF($queryString, array('timestamp'), array(ilUtil::now()));
3667 }
3668
3669 return true;
3670 }
3671
3672
3681 public static function _lookupAuthMode($a_usr_id)
3682 {
3683 return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3684 }
3685
3692 public static function _checkExternalAuthAccount($a_auth, $a_account, $tryFallback = true)
3693 {
3694 $db = $GLOBALS['DIC']->database();
3695 $settings = $GLOBALS['DIC']->settings();
3696
3697 // Check directly with auth_mode
3698 $r = $db->queryF(
3699 "SELECT * FROM usr_data WHERE " .
3700 " ext_account = %s AND auth_mode = %s",
3701 array("text", "text"),
3702 array($a_account, $a_auth)
3703 );
3704 if ($usr = $db->fetchAssoc($r)) {
3705 return $usr["login"];
3706 }
3707
3708 if (!$tryFallback) {
3709 return false;
3710 }
3711
3712 // For compatibility, check for login (no ext_account entry given)
3713 $res = $db->queryF(
3714 "SELECT login FROM usr_data " .
3715 "WHERE login = %s AND auth_mode = %s AND (ext_account IS NULL OR ext_account = '') ",
3716 array("text", "text"),
3717 array($a_account, $a_auth)
3718 );
3719 if ($usr = $db->fetchAssoc($res)) {
3720 return $usr['login'];
3721 }
3722
3723 // If auth_default == $a_auth => check for login
3724 if (ilAuthUtils::_getAuthModeName($settings->get('auth_mode')) == $a_auth) {
3725 $res = $db->queryF(
3726 "SELECT login FROM usr_data WHERE " .
3727 " ext_account = %s AND auth_mode = %s",
3728 array("text", "text"),
3729 array($a_account, "default")
3730 );
3731 if ($usr = $db->fetchAssoc($res)) {
3732 return $usr["login"];
3733 }
3734 // Search for login (no ext_account given)
3735 $res = $db->queryF(
3736 "SELECT login FROM usr_data " .
3737 "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3738 array("text", "text"),
3739 array($a_account, "default")
3740 );
3741 if ($usr = $db->fetchAssoc($res)) {
3742 return $usr["login"];
3743 }
3744 }
3745 return false;
3746 }
3747
3751 public static function _getNumberOfUsersPerAuthMode()
3752 {
3753 global $ilDB;
3754
3755 $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data " .
3756 "GROUP BY auth_mode");
3757 $cnt_arr = array();
3758 while ($cnt = $ilDB->fetchAssoc($r)) {
3759 $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3760 }
3761
3762 return $cnt_arr;
3763 }
3764
3770 public static function _getLocalAccountsForEmail($a_email)
3771 {
3772 global $ilDB, $ilSetting;
3773
3774 // default set to local (1)?
3775
3776 $q = "SELECT * FROM usr_data WHERE " .
3777 " email = %s AND (auth_mode = %s ";
3778 $types = array("text", "text");
3779 $values = array($a_email, "local");
3780
3781 if ($ilSetting->get("auth_mode") == 1) {
3782 $q.=" OR auth_mode = %s";
3783 $types[] = "text";
3784 $values[] = "default";
3785 }
3786
3787 $q.= ")";
3788
3789 $users = array();
3790 $usr_set = $ilDB->queryF($q, $types, $values);
3791 while ($usr_rec = $ilDB->fetchAssoc($usr_set)) {
3792 $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3793 }
3794
3795 return $users;
3796 }
3797
3798
3806 public static function _uploadPersonalPicture($tmp_file, $obj_id)
3807 {
3808 $webspace_dir = ilUtil::getWebspaceDir();
3809 $image_dir = $webspace_dir . "/usr_images";
3810 $store_file = "usr_" . $obj_id . "." . "jpg";
3811 $target_file = $image_dir . "/$store_file";
3812
3813 chmod($tmp_file, 0770);
3814
3815 // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3816 // taking only frame [0] to avoid problems with animated gifs
3817 $show_file = "$image_dir/usr_" . $obj_id . ".jpg";
3818 $thumb_file = "$image_dir/usr_" . $obj_id . "_small.jpg";
3819 $xthumb_file = "$image_dir/usr_" . $obj_id . "_xsmall.jpg";
3820 $xxthumb_file = "$image_dir/usr_" . $obj_id . "_xxsmall.jpg";
3821
3822 ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
3823 ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
3824 ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
3825 ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
3826
3827 // store filename
3828 self::_writePref($obj_id, "profile_image", $store_file);
3829
3830 return true;
3831 }
3832
3833
3842 public function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3843 {
3844 if (isset(self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic])) {
3845 return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
3846 }
3847
3848 self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic] = ilObjUser::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
3849
3850 return self::$personal_image_cache[$this->getId()][$a_size][(int) $a_force_pic];
3851 }
3852
3862 public static function _getPersonalPicturePath(
3863 $a_usr_id,
3864 $a_size = "small",
3865 $a_force_pic = false,
3866 $a_prevent_no_photo_image = false
3867 ) {
3868 global $DIC;
3869
3870 $login = $firstname = $lastname = '';
3871 $upload = $profile = false;
3872
3873 $in = $DIC->database()->in('usr_pref.keyword', array('public_upload', 'public_profile'), false, 'text');
3874 $res = $DIC->database()->queryF(
3875 "
3876 SELECT usr_pref.*, ud.login, ud.firstname, ud.lastname
3877 FROM usr_data ud LEFT JOIN usr_pref ON usr_pref.usr_id = ud.usr_id AND $in
3878 WHERE ud.usr_id = %s",
3879 array("integer"),
3880 array($a_usr_id)
3881 );
3882 while ($row = $DIC->database()->fetchAssoc($res)) {
3883 $login = $row['login'];
3884 $firstname = $row['firstname'];
3885 $lastname = $row['lastname'];
3886
3887 switch ($row['keyword']) {
3888 case 'public_upload':
3889 $upload = $row['value'] == 'y';
3890 break;
3891 case 'public_profile':
3892 $profile = ($row['value'] == 'y' ||
3893 $row['value'] == 'g');
3894 break;
3895 }
3896 }
3897
3898 // END DiskQuota: Fetch all user preferences in a single query
3899 $webspace_dir = "";
3900 if (defined('ILIAS_MODULE')) {
3901 $webspace_dir = ('.' . $webspace_dir);
3902 }
3903 $webspace_dir .= ('./' . ltrim(ilUtil::getWebspaceDir(), "./"));
3904
3905 $image_dir = $webspace_dir . "/usr_images";
3906 // BEGIN DiskQuota: Support 'big' user images
3907 if ($a_size == 'big') {
3908 $thumb_file = $image_dir . "/usr_" . $a_usr_id . ".jpg";
3909 } else {
3910 $thumb_file = $image_dir . "/usr_" . $a_usr_id . "_" . $a_size . ".jpg";
3911 }
3912 // END DiskQuota: Support 'big' user images
3913
3914 $random = new \ilRandom();
3915 if ((($upload && $profile) || $a_force_pic)
3916 && @is_file($thumb_file)) {
3917 $file = $thumb_file . "?t=" . $random->int(1, 99999);
3918 } else {
3919 if (!$a_prevent_no_photo_image) {
3920 // we only have xsmall and xxsmall for this
3921 if ($a_size == "small" || $a_size == "big") {
3922 $a_size = "xsmall";
3923 }
3924
3925 if ($profile) {
3926 $short = ilStr::subStr($firstname, 0, 1) . ilStr::subStr($lastname, 0, 1);
3927 } else {
3928 $short = ilStr::subStr($login, 0, 2);
3929 }
3930
3932 $avatar = $DIC["user.avatar.factory"]->avatar($a_size);
3933 $avatar->setName($short);
3934 $avatar->setUsrId($a_usr_id);
3935
3936 return $avatar->getUrl();
3937 }
3938 }
3939
3940 require_once('./Services/WebAccessChecker/classes/class.ilWACSignedPath.php');
3942 }
3943
3950 public static function copyProfilePicturesToDirectory($a_user_id, $a_dir)
3951 {
3952 $a_dir = trim(str_replace("..", "", $a_dir));
3953 if ($a_dir == "" || !is_dir($a_dir)) {
3954 return;
3955 }
3956
3957 $webspace_dir = ilUtil::getWebspaceDir();
3958 $image_dir = $webspace_dir . "/usr_images";
3959 $images = array(
3960 "upload_" . $a_user_id . "pic",
3961 "usr_" . $a_user_id . "." . "jpg",
3962 "usr_" . $a_user_id . "_small.jpg",
3963 "usr_" . $a_user_id . "_xsmall.jpg",
3964 "usr_" . $a_user_id . "_xxsmall.jpg",
3965 "upload_" . $a_user_id);
3966 foreach ($images as $image) {
3967 if (is_file($image_dir . "/" . $image)) {
3968 copy($image_dir . "/" . $image, $a_dir . "/" . $image);
3969 }
3970 }
3971 }
3972
3973
3977 public function removeUserPicture($a_do_update = true)
3978 {
3979 $webspace_dir = ilUtil::getWebspaceDir();
3980 $image_dir = $webspace_dir . "/usr_images";
3981 $file = $image_dir . "/usr_" . $this->getID() . "." . "jpg";
3982 $thumb_file = $image_dir . "/usr_" . $this->getID() . "_small.jpg";
3983 $xthumb_file = $image_dir . "/usr_" . $this->getID() . "_xsmall.jpg";
3984 $xxthumb_file = $image_dir . "/usr_" . $this->getID() . "_xxsmall.jpg";
3985 $upload_file = $image_dir . "/upload_" . $this->getID();
3986
3987 if ($a_do_update) {
3988 // remove user pref file name
3989 $this->setPref("profile_image", "");
3990 $this->update();
3991 }
3992
3993 if (@is_file($file)) {
3994 unlink($file);
3995 }
3996 if (@is_file($thumb_file)) {
3997 unlink($thumb_file);
3998 }
3999 if (@is_file($xthumb_file)) {
4000 unlink($xthumb_file);
4001 }
4002 if (@is_file($xxthumb_file)) {
4003 unlink($xxthumb_file);
4004 }
4005 if (@is_file($upload_file)) {
4006 unlink($upload_file);
4007 }
4008 }
4009
4010
4011 public function setUserDefinedData($a_data)
4012 {
4013 if (!is_array($a_data)) {
4014 return false;
4015 }
4016 foreach ($a_data as $field => $data) {
4017 #$new_data[$field] = ilUtil::stripSlashes($data);
4018 // Assign it directly to avoid update problems of unchangable fields
4019 $this->user_defined_data['f_' . $field] = $data;
4020 }
4021 #$this->user_defined_data = $new_data;
4022
4023 return true;
4024 }
4025
4026 public function getUserDefinedData()
4027 {
4028 return $this->user_defined_data ? $this->user_defined_data : array();
4029 }
4030
4031 public function updateUserDefinedFields()
4032 {
4033 global $ilDB;
4034
4035 $fields = '';
4036
4037 $field_def = array();
4038
4039 include_once("./Services/User/classes/class.ilUserDefinedData.php");
4040 $udata = new ilUserDefinedData($this->getId());
4041
4042 foreach ($this->user_defined_data as $field => $value) {
4043 if ($field != 'usr_id') {
4044 // $field_def[$field] = array('text',$value);
4045 $udata->set($field, $value);
4046 }
4047 }
4048 $udata->update();
4049
4050 /* if(!$field_def)
4051 {
4052 return true;
4053 }
4054
4055 $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4056 $res = $ilDB->query($query);
4057
4058
4059 if($res->numRows())
4060 {
4061 // Update
4062 $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4063 }
4064 else
4065 {
4066 $field_def['usr_id'] = array('integer',$this->getId());
4067 $ilDB->insert('udf_data',$field_def);
4068 }
4069 */
4070 return true;
4071 }
4072
4073 public function readUserDefinedFields()
4074 {
4075 global $ilDB;
4076
4077 include_once("./Services/User/classes/class.ilUserDefinedData.php");
4078 $udata = new ilUserDefinedData($this->getId());
4079
4080 /* $query = "SELECT * FROM udf_data ".
4081 "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4082
4083 $res = $this->db->query($query);
4084 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
4085 {
4086 $this->user_defined_data = $row;
4087 }*/
4088
4089 $this->user_defined_data = $udata->getAll();
4090
4091 return true;
4092 }
4093
4095 {
4096 global $ilDB;
4097
4098 // not needed. no entry in udf_text/udf_clob means no value
4099
4100 /* $query = "INSERT INTO udf_data (usr_id ) ".
4101 "VALUES( ".
4102 $ilDB->quote($this->getId(),'integer').
4103 ")";
4104 $res = $ilDB->manipulate($query);
4105 */
4106 return true;
4107 }
4108
4110 {
4111 global $ilDB;
4112
4113 include_once("./Services/User/classes/class.ilUserDefinedData.php");
4115
4116 // wrong place...
4117 /* $query = "DELETE FROM udf_data ".
4118 "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4119 $res = $ilDB->manipulate($query);*/
4120
4121 return true;
4122 }
4123
4129 public function getProfileAsString(&$a_language)
4130 {
4131 include_once './Services/AccessControl/classes/class.ilObjRole.php';
4132
4133 global $lng,$rbacreview;
4134
4135 $language =&$a_language;
4136 $language->loadLanguageModule('registration');
4137 $language->loadLanguageModule('crs');
4138
4139 $body = '';
4140 $body .= ($language->txt("login") . ": " . $this->getLogin() . "\n");
4141
4142 if (strlen($this->getUTitle())) {
4143 $body .= ($language->txt("title") . ": " . $this->getUTitle() . "\n");
4144 }
4145 if (1 === strlen($this->getGender())) {
4146 $body .= ($language->txt("gender") . ": " . $language->txt('gender_' . strtolower($this->getGender())) . "\n");
4147 }
4148 if (strlen($this->getFirstname())) {
4149 $body .= ($language->txt("firstname") . ": " . $this->getFirstname() . "\n");
4150 }
4151 if (strlen($this->getLastname())) {
4152 $body .= ($language->txt("lastname") . ": " . $this->getLastname() . "\n");
4153 }
4154 if (strlen($this->getInstitution())) {
4155 $body .= ($language->txt("institution") . ": " . $this->getInstitution() . "\n");
4156 }
4157 if (strlen($this->getDepartment())) {
4158 $body .= ($language->txt("department") . ": " . $this->getDepartment() . "\n");
4159 }
4160 if (strlen($this->getStreet())) {
4161 $body .= ($language->txt("street") . ": " . $this->getStreet() . "\n");
4162 }
4163 if (strlen($this->getCity())) {
4164 $body .= ($language->txt("city") . ": " . $this->getCity() . "\n");
4165 }
4166 if (strlen($this->getZipcode())) {
4167 $body .= ($language->txt("zipcode") . ": " . $this->getZipcode() . "\n");
4168 }
4169 if (strlen($this->getCountry())) {
4170 $body .= ($language->txt("country") . ": " . $this->getCountry() . "\n");
4171 }
4172 if (strlen($this->getSelectedCountry())) {
4173 $body .= ($language->txt("sel_country") . ": " . $this->getSelectedCountry() . "\n");
4174 }
4175 if (strlen($this->getPhoneOffice())) {
4176 $body .= ($language->txt("phone_office") . ": " . $this->getPhoneOffice() . "\n");
4177 }
4178 if (strlen($this->getPhoneHome())) {
4179 $body .= ($language->txt("phone_home") . ": " . $this->getPhoneHome() . "\n");
4180 }
4181 if (strlen($this->getPhoneMobile())) {
4182 $body .= ($language->txt("phone_mobile") . ": " . $this->getPhoneMobile() . "\n");
4183 }
4184 if (strlen($this->getFax())) {
4185 $body .= ($language->txt("fax") . ": " . $this->getFax() . "\n");
4186 }
4187 if (strlen($this->getEmail())) {
4188 $body .= ($language->txt("email") . ": " . $this->getEmail() . "\n");
4189 }
4190 if (strlen($this->getSecondEmail())) {
4191 $body .= ($language->txt("second_email") . ": " . $this->getSecondEmail() . "\n");
4192 }
4193 if (strlen($this->getHobby())) {
4194 $body .= ($language->txt("hobby") . ": " . $this->getHobby() . "\n");
4195 }
4196 if (strlen($this->getComment())) {
4197 $body .= ($language->txt("referral_comment") . ": " . $this->getComment() . "\n");
4198 }
4199 if (strlen($this->getMatriculation())) {
4200 $body .= ($language->txt("matriculation") . ": " . $this->getMatriculation() . "\n");
4201 }
4202 if (strlen($this->getCreateDate())) {
4207
4208 $body .= ($language->txt("create_date") . ": " . $date . "\n");
4209 }
4210
4211 foreach ($rbacreview->getGlobalRoles() as $role) {
4212 if ($rbacreview->isAssigned($this->getId(), $role)) {
4213 $gr[] = ilObjRole::_lookupTitle($role);
4214 }
4215 }
4216 if (count($gr)) {
4217 $body .= ($language->txt('reg_role_info') . ': ' . implode(',', $gr) . "\n");
4218 }
4219
4220 // Time limit
4221 if ($this->getTimeLimitUnlimited()) {
4222 $body .= ($language->txt('time_limit') . ": " . $language->txt('crs_unlimited') . "\n");
4223 } else {
4229 );
4231
4232 $start = new ilDateTime($this->getTimeLimitFrom(), IL_CAL_UNIX);
4234
4235 $body .= $language->txt('time_limit') . ': ' . $start->get(IL_CAL_DATETIME);
4236 $body .= $language->txt('time_limit') . ': ' . $end->get(IL_CAL_DATETIME);
4237 }
4238
4239 include_once './Services/User/classes/class.ilUserDefinedFields.php';
4243 $user_defined_fields = ilUserDefinedFields::_getInstance();
4245
4246 foreach ($user_defined_fields->getDefinitions() as $field_id => $definition) {
4247 $data = $user_defined_data["f_" . $field_id];
4248 if (strlen($data)) {
4249 if ($definition['field_type'] == UDF_TYPE_WYSIWYG) {
4250 $data = preg_replace('/<br(\s*)?\/?>/i', "\n", $data);
4251 $data = strip_tags($data);
4252 }
4253
4254 $body .= $definition['field_name'] . ': ' . $data . "\n";
4255 }
4256 }
4257
4258 return $body;
4259 }
4260
4264 public static function _lookupFeedHash($a_user_id, $a_create = false)
4265 {
4266 global $ilDB;
4267
4268 if ($a_user_id > 0) {
4269 $set = $ilDB->queryF(
4270 "SELECT feed_hash from usr_data WHERE usr_id = %s",
4271 array("integer"),
4272 array($a_user_id)
4273 );
4274 if ($rec = $ilDB->fetchAssoc($set)) {
4275 if (strlen($rec["feed_hash"]) == 32) {
4276 return $rec["feed_hash"];
4277 } elseif ($a_create) {
4278 $random = new \ilRandom();
4279 $hash = md5($random->int(1, 9999999) + str_replace(" ", "", (string) microtime()));
4280 $ilDB->manipulateF(
4281 "UPDATE usr_data SET feed_hash = %s" .
4282 " WHERE usr_id = %s",
4283 array("text", "integer"),
4284 array($hash, $a_user_id)
4285 );
4286 return $hash;
4287 }
4288 }
4289 }
4290
4291 return false;
4292 }
4293
4299 public static function _getFeedPass($a_user_id)
4300 {
4301 global $ilDB;
4302
4303 if ($a_user_id > 0) {
4304 return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4305 }
4306 return false;
4307 }
4308
4314 public static function _setFeedPass($a_user_id, $a_password)
4315 {
4316 global $ilDB;
4317
4319 $a_user_id,
4320 "priv_feed_pass",
4321 ($a_password=="") ? "" : md5($a_password)
4322 );
4323 }
4324
4334 public static function _loginExists($a_login, $a_user_id = 0)
4335 {
4336 global $ilDB;
4337
4338 $q = "SELECT DISTINCT login, usr_id FROM usr_data " .
4339 "WHERE login = %s";
4340 $types[] = "text";
4341 $values[] = $a_login;
4342
4343 if ($a_user_id != 0) {
4344 $q.= " AND usr_id != %s ";
4345 $types[] = "integer";
4346 $values[] = $a_user_id;
4347 }
4348
4349 $r = $ilDB->queryF($q, $types, $values);
4350
4351 if ($row = $ilDB->fetchAssoc($r)) {
4352 return $row['usr_id'];
4353 }
4354 return false;
4355 }
4356
4367 public static function _externalAccountExists($a_external_account, $a_auth_mode)
4368 {
4369 global $ilDB;
4370
4371 $res = $ilDB->queryF(
4372 "SELECT * FROM usr_data " .
4373 "WHERE ext_account = %s AND auth_mode = %s",
4374 array("text", "text"),
4375 array($a_external_account, $a_auth_mode)
4376 );
4377 return $ilDB->fetchAssoc($res) ? true :false;
4378 }
4379
4387 public static function _getUsersForRole($role_id, $active = -1)
4388 {
4389 global $ilDB, $rbacreview;
4390 $data = array();
4391
4392 $ids = $rbacreview->assignedUsers($role_id);
4393
4394 if (count($ids) == 0) {
4395 $ids = array(-1);
4396 }
4397
4398 $query = "SELECT usr_data.*, usr_pref.value AS language
4399 FROM usr_data
4400 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4401 WHERE " . $ilDB->in("usr_data.usr_id", $ids, false, "integer");
4402 $values[] = "language";
4403 $types[] = "text";
4404
4405
4406 if (is_numeric($active) && $active > -1) {
4407 $query .= " AND usr_data.active = %s";
4408 $values[] = $active;
4409 $types[] = "integer";
4410 }
4411
4412 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4413
4414 $r = $ilDB->queryF($query, $types, $values);
4415 $data = array();
4416 while ($row = $ilDB->fetchAssoc($r)) {
4417 $data[] = $row;
4418 }
4419 return $data;
4420 }
4421
4422
4428 public static function _getUsersForFolder($ref_id, $active)
4429 {
4430 global $ilDB;
4431 $data = array();
4432 $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 ";
4433 $types[] = "text";
4434 $values[] = "language";
4435
4436 if (is_numeric($active) && $active > -1) {
4437 $query .= " AND usr_data.active = %s";
4438 $values[] = $active;
4439 $types[] = "integer";
4440 }
4441
4442 if ($ref_id != USER_FOLDER_ID) {
4443 $query.= " AND usr_data.time_limit_owner = %s";
4444 $values[] = $ref_id;
4445 $types[] = "integer";
4446 }
4447
4448 $query .= " AND usr_data.usr_id != %s ";
4449 $values[] = ANONYMOUS_USER_ID;
4450 $types[] = "integer";
4451
4452 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4453
4454 $result = $ilDB->queryF($query, $types, $values);
4455 $data = array();
4456 while ($row = $ilDB->fetchAssoc($result)) {
4457 array_push($data, $row);
4458 }
4459
4460 return $data;
4461 }
4462
4463
4469 public static function _getUsersForGroup($a_mem_ids, $active = -1)
4470 {
4471 return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4472 }
4473
4474
4480 public static function _getUsersForIds($a_mem_ids, $active = -1, $timelimitowner = -1)
4481 {
4482 global $rbacadmin, $rbacreview, $ilDB;
4483
4484 $query = "SELECT usr_data.*, usr_pref.value AS language
4485 FROM usr_data
4486 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4487 WHERE " . $ilDB->in("usr_data.usr_id", $a_mem_ids, false, "integer") . "
4488 AND usr_data.usr_id != %s";
4489 $values[] = "language";
4490 $types[] = "text";
4491 $values[] = ANONYMOUS_USER_ID;
4492 $types[] = "integer";
4493
4494 if (is_numeric($active) && $active > -1) {
4495 $query .= " AND active = %s";
4496 $values[] = $active;
4497 $types[] = "integer";
4498 }
4499
4500 if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1) {
4501 $query.= " AND usr_data.time_limit_owner = %s";
4502 $values[] = $timelimitowner;
4503 $types[] = "integer";
4504 }
4505
4506 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4507
4508 $result = $ilDB->queryF($query, $types, $values);
4509 while ($row = $ilDB->fetchAssoc($result)) {
4510 $mem_arr[] = $row;
4511 }
4512
4513 return $mem_arr ? $mem_arr : array();
4514 }
4515
4516
4517
4523 public static function _getUserData($a_internalids)
4524 {
4525 global $ilDB;
4526
4527 $ids = array();
4528 if (is_array($a_internalids)) {
4529 foreach ($a_internalids as $internalid) {
4530 if (is_numeric($internalid)) {
4531 $ids[] = $internalid;
4532 } else {
4533 $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4534 if (is_numeric($parsedid) && $parsedid > 0) {
4535 $ids[] = $parsedid;
4536 }
4537 }
4538 }
4539 }
4540 if (count($ids) == 0) {
4541 $ids [] = -1;
4542 }
4543
4544 $query = "SELECT usr_data.*, usr_pref.value AS language
4545 FROM usr_data
4546 LEFT JOIN usr_pref
4547 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4548 WHERE " . $ilDB->in("usr_data.usr_id", $ids, false, "integer");
4549 $values[] = "language";
4550 $types[] = "text";
4551
4552 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4553
4554 $data = array();
4555 $result = $ilDB->queryF($query, $types, $values);
4556 while ($row = $ilDB->fetchAssoc($result)) {
4557 $data[] = $row;
4558 }
4559 return $data;
4560 }
4561
4568 public static function _getPreferences($user_id)
4569 {
4570 global $ilDB;
4571
4572 $prefs = array();
4573
4574 $r = $ilDB->queryF(
4575 "SELECT * FROM usr_pref WHERE usr_id = %s",
4576 array("integer"),
4577 array($user_id)
4578 );
4579
4580 while ($row = $ilDB->fetchAssoc($r)) {
4581 $prefs[$row["keyword"]] = $row["value"];
4582 }
4583
4584 return $prefs;
4585 }
4586
4596 public static function getUserSubsetByPreferenceValue($a_user_ids, $a_keyword, $a_val)
4597 {
4598 global $ilDB;
4599
4600 $users = array();
4601 $set = $ilDB->query(
4602 "SELECT usr_id FROM usr_pref " .
4603 " WHERE keyword = " . $ilDB->quote($a_keyword, "text") .
4604 " AND " . $ilDB->in("usr_id", $a_user_ids, false, "integer") .
4605 " AND value = " . $ilDB->quote($a_val, "text")
4606 );
4607 while ($rec = $ilDB->fetchAssoc($set)) {
4608 $users[] = $rec["usr_id"];
4609 }
4610 return $users;
4611 }
4612
4613
4614 public static function _resetLoginAttempts($a_usr_id)
4615 {
4616 global $ilDB;
4617
4618 $query = "UPDATE usr_data SET login_attempts = 0 WHERE usr_id = %s";
4619 $affected = $ilDB->manipulateF($query, array('integer'), array($a_usr_id));
4620
4621 if ($affected) {
4622 return true;
4623 } else {
4624 return false;
4625 }
4626 }
4627
4628 public static function _getLoginAttempts($a_usr_id)
4629 {
4630 global $ilDB;
4631
4632 $query = "SELECT login_attempts FROM usr_data WHERE usr_id = %s";
4633 $result = $ilDB->queryF($query, array('integer'), array($a_usr_id));
4634 $record = $ilDB->fetchAssoc($result);
4635 $login_attempts = $record['login_attempts'];
4636
4637 return $login_attempts;
4638 }
4639
4640 public static function _incrementLoginAttempts($a_usr_id)
4641 {
4642 global $ilDB;
4643
4644 $query = "UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s";
4645 $affected = $ilDB->manipulateF($query, array('integer'), array($a_usr_id));
4646
4647 if ($affected) {
4648 return true;
4649 } else {
4650 return false;
4651 }
4652 }
4653
4654 public static function _setUserInactive($a_usr_id)
4655 {
4656 global $ilDB;
4657
4658 $query = "UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s";
4659 $affected = $ilDB->manipulateF($query, array('timestamp', 'integer'), array(ilUtil::now(), $a_usr_id));
4660
4661 if ($affected) {
4662 return true;
4663 } else {
4664 return false;
4665 }
4666 }
4667
4673 public function hasPublicProfile()
4674 {
4675 return in_array($this->getPref("public_profile"), array("y", "g"));
4676 }
4677
4683 public function getPublicName()
4684 {
4685 if ($this->hasPublicProfile()) {
4686 return $this->getFirstname() . " " . $this->getLastname() . " (" . $this->getLogin() . ")";
4687 } else {
4688 return $this->getLogin();
4689 }
4690 }
4691
4692 public static function _writeHistory($a_usr_id, $a_login)
4693 {
4694 global $ilDB;
4695
4696 $timestamp = time();
4697
4698 $res = $ilDB->queryF(
4699 'SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4700 array('integer', 'text', 'integer'),
4701 array($a_usr_id, $a_login, $timestamp)
4702 );
4703
4704 if ($ilDB->numRows($res) == 0) {
4705 $ilDB->manipulateF(
4706 '
4707 INSERT INTO loginname_history
4708 (usr_id, login, history_date)
4709 VALUES (%s, %s, %s)',
4710 array('integer', 'text', 'integer'),
4711 array($a_usr_id, $a_login, $timestamp)
4712 );
4713 }
4714
4715 return true;
4716 }
4717
4725 public static function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4726 {
4730 global $DIC;
4731
4732 $ilDB = $DIC->database();
4733 $rbacreview = $DIC->rbac()->review();
4734
4736
4737 $pd_set = new ilSetting('pd');
4738 $atime = $pd_set->get('user_activity_time') * 60;
4739 $ctime = time();
4740
4741 $where = array();
4742
4743 if ($a_user_id == 0) {
4744 $where[] = 'user_id > 0';
4745 } elseif (is_array($a_user_id)) {
4746 $where[] = $ilDB->in("user_id", $a_user_id, false, "integer");
4747 } else {
4748 $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
4749 }
4750
4751 if ($a_no_anonymous) {
4752 $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
4753 }
4754
4755 include_once 'Services/User/classes/class.ilUserAccountSettings.php';
4756 if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) {
4757 include_once 'Services/User/classes/class.ilUserFilter.php';
4758 $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
4759 }
4760
4761 $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
4762 $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
4763
4764 $where = 'WHERE ' . implode(' AND ', $where);
4765
4766 $r = $ilDB->queryF(
4767 $q = "
4768 SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime, context, agree_date
4769 FROM usr_session
4770 LEFT JOIN usr_data u
4771 ON user_id = u.usr_id
4772 LEFT JOIN usr_pref p
4773 ON (p.usr_id = u.usr_id AND p.keyword = %s)
4774 {$where}
4775 GROUP BY user_id, firstname, lastname, title, login, last_login, context, agree_date
4776 ORDER BY lastname, firstname
4777 ",
4778 array('text'),
4779 array('hide_own_online_status')
4780 );
4781
4782 $log->debug("Query: " . $q);
4783
4784 $users = array();
4785 while ($user = $ilDB->fetchAssoc($r)) {
4786 if ($atime <= 0 || $user['ctime'] + $atime > $ctime) {
4787 $users[$user['user_id']] = $user;
4788 }
4789 }
4790
4791 $log->debug("Found users: " . count($users));
4792
4793 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4795 $users = array_filter($users, function ($user) {
4796 if ($user['agree_date'] || $user['user_id'] == SYSTEM_USER_ID || 'root' === $user['login']) {
4797 return true;
4798 }
4799
4800 return false;
4801 });
4802
4803 $log->debug("TOS filtered to users: " . count($users));
4804 }
4805
4806 return $users;
4807 }
4808
4818 public static function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4819 {
4820 global $ilias, $ilDB;
4821
4822 $pd_set = new ilSetting("pd");
4823 $atime = $pd_set->get("user_activity_time") * 60;
4824 $ctime = time();
4825 $no_anonym = ($a_no_anonymous)
4826 ? "AND user_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") . " "
4827 : "";
4828
4829 // Get a list of object id's of all courses and groups for which
4830 // the current user has local roles.
4831 // Note: we have to use DISTINCT here, because a user may assume
4832 // multiple roles in a group or a course.
4833 $q = "SELECT DISTINCT dat.obj_id as obj_id " .
4834 "FROM rbac_ua ua " .
4835 "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id " .
4836 "JOIN object_reference r1 ON r1.ref_id = fa.parent " .
4837 "JOIN tree ON tree.child = r1.ref_id " .
4838 "JOIN object_reference r2 ON r2.ref_id = tree.child " . // #17674 - rolf is gone
4839 "JOIN object_data dat ON dat.obj_id = r2.obj_id " .
4840 "WHERE ua.usr_id = " . $ilDB->quote($a_user_id, "integer") . " " .
4841 "AND fa.assign = " . $ilDB->quote("y", "text") . " " .
4842 "AND dat.type IN (" . $ilDB->quote("crs", "text") . "," .
4843 $ilDB->quote("grp", "text") . ")";
4844 $r = $ilDB->query($q);
4845
4846 while ($row = $ilDB->fetchAssoc($r)) {
4847 $groups_and_courses_of_user[] = $row["obj_id"];
4848 }
4849
4850 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4851 $tos_condition = '';
4853 $tos_condition = " AND (agree_date IS NOT NULL OR ud.usr_id = " . $ilDB->quote(SYSTEM_USER_ID, 'integer') . ") ";
4854 }
4855
4856 // If the user is not in a course or a group, he has no associated users.
4857 if (count($groups_and_courses_of_user) == 0) {
4858 $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login " .
4859 "FROM usr_session " .
4860 "JOIN usr_data ud ON user_id = ud.usr_id " .
4861 "WHERE user_id = " . $ilDB->quote($a_user_id, "integer") . " " .
4862 $no_anonym .
4863 $tos_condition .
4864 "AND expires > " . $ilDB->quote(time(), "integer") . " " .
4865 "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4866 $r = $ilDB->query($q);
4867 } else {
4868 $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login " .
4869 "FROM usr_session s " .
4870 "JOIN usr_data ud ON ud.usr_id = s.user_id " .
4871 "JOIN rbac_ua ua ON ua.usr_id = s.user_id " .
4872 "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id " .
4873 "JOIN tree ON tree.child = fa.parent " .
4874 "JOIN object_reference or1 ON or1.ref_id = tree.child " . // #17674 - rolf is gone
4875 "JOIN object_data od ON od.obj_id = or1.obj_id " .
4876 "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = " .
4877 $ilDB->quote("hide_own_online_status", "text") . ") " .
4878 "WHERE s.user_id != 0 " .
4879 $no_anonym .
4880 "AND (p.value IS NULL OR NOT p.value = " . $ilDB->quote("y", "text") . ") " .
4881 "AND s.expires > " . $ilDB->quote(time(), "integer") . " " .
4882 "AND fa.assign = " . $ilDB->quote("y", "text") . " " .
4883 $tos_condition .
4884 "AND " . $ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer") . " " .
4885 "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login " .
4886 "ORDER BY ud.lastname, ud.firstname";
4887 $r = $ilDB->query($q);
4888 }
4889
4890 while ($user = $ilDB->fetchAssoc($r)) {
4891 if ($atime <= 0
4892 || $user["ctime"] + $atime > $ctime) {
4893 $users[$user["user_id"]] = $user;
4894 }
4895 }
4896
4897 return $users ? $users : array();
4898 }
4899
4906 public static function _generateRegistrationHash($a_usr_id)
4907 {
4908 global $ilDB;
4909
4910 do {
4911 $continue = false;
4912
4913 $random = new \ilRandom();
4914 $hashcode = substr(md5(uniqid($random->int(), true)), 0, 16);
4915
4916 $res = $ilDB->queryf(
4917 '
4918 SELECT COUNT(usr_id) cnt FROM usr_data
4919 WHERE reg_hash = %s',
4920 array('text'),
4921 array($hashcode)
4922 );
4923 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
4924 if ($row->cnt > 0) {
4925 $continue = true;
4926 }
4927 break;
4928 }
4929
4930 if ($continue) {
4931 continue;
4932 }
4933
4934 $ilDB->manipulateF(
4935 '
4936 UPDATE usr_data
4937 SET reg_hash = %s
4938 WHERE usr_id = %s',
4939 array('text', 'integer'),
4940 array($hashcode, (int) $a_usr_id)
4941 );
4942
4943 break;
4944 } while (true);
4945
4946 return $hashcode;
4947 }
4948
4957 public static function _verifyRegistrationHash($a_hash)
4958 {
4959 global $ilDB;
4960
4961 $res = $ilDB->queryf(
4962 '
4963 SELECT usr_id, create_date FROM usr_data
4964 WHERE reg_hash = %s',
4965 array('text'),
4966 array($a_hash)
4967 );
4968 while ($row = $ilDB->fetchAssoc($res)) {
4969 require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
4970 $oRegSettigs = new ilRegistrationSettings();
4971
4972 if ((int) $oRegSettigs->getRegistrationHashLifetime() != 0 &&
4973 time() - (int) $oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date'])) {
4974 require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
4975 throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
4976 }
4977
4978 $ilDB->manipulateF(
4979 '
4980 UPDATE usr_data
4981 SET reg_hash = %s
4982 WHERE usr_id = %s',
4983 array('text', 'integer'),
4984 array('', (int) $row['usr_id'])
4985 );
4986
4987 return (int) $row['usr_id'];
4988 }
4989
4990 require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
4991 throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
4992 }
4993
4994 public function setBirthday($a_birthday)
4995 {
4996 if (strlen($a_birthday)) {
4997 $date = new ilDate($a_birthday, IL_CAL_DATE);
4998 $this->birthday = $date->get(IL_CAL_DATE);
4999 } else {
5000 $this->birthday = null;
5001 }
5002 }
5003
5004 public function getBirthday()
5005 {
5006 return $this->birthday;
5007 }
5008
5017 public static function _getUserIdsByInactivityPeriod($period)
5018 {
5019 if (!(int) $period) {
5020 throw new ilException('no valid period given');
5021 }
5022
5023 global $ilDB;
5024
5025 $date = date('Y-m-d H:i:s', (time() - ((int) $period * 24 * 60 * 60)));
5026
5027 $query = "SELECT usr_id FROM usr_data WHERE last_login < %s OR (ISNULL(last_login) AND create_date < %s)";
5028
5029 $res = $ilDB->queryF($query, array('timestamp', 'timestamp'), array($date, $date));
5030
5031 $ids = array();
5032 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
5033 $ids[] = $row->usr_id;
5034 }
5035
5036 return $ids;
5037 }
5038
5047 public static function _getUserIdsByInactivationPeriod($period)
5048 {
5050 $field = 'inactivation_date';
5052
5053 if (!(int) $period) {
5054 throw new ilException('no valid period given');
5055 }
5056
5057 global $ilDB;
5058
5059 $date = date('Y-m-d H:i:s', (time() - ((int) $period * 24 * 60 * 60)));
5060
5061 $query = "SELECT usr_id FROM usr_data WHERE $field < %s AND active = %s";
5062
5063 $res = $ilDB->queryF($query, array('timestamp', 'integer'), array($date, 0));
5064
5065 $ids = array();
5066 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
5067 $ids[] = $row->usr_id;
5068 }
5069
5070 return $ids;
5071 }
5072
5082 public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5083 {
5084 if ($a_last_login !== null) {
5085 $last_login = $a_last_login;
5086 } else {
5087 $last_login = date('Y-m-d H:i:s');
5088 }
5089
5090 global $ilDB;
5091
5092 $query = "UPDATE usr_data SET last_login = %s WHERE usr_id = %s";
5093 $affected = $ilDB->manipulateF($query, array('timestamp', 'integer'), array($last_login, $a_usr_id));
5094
5095 if ($affected) {
5096 return $last_login;
5097 } else {
5098 return false;
5099 }
5100 }
5101
5102 public function resetOwner()
5103 {
5104 global $ilDB;
5105
5106 $query = "UPDATE object_data SET owner = 0 " .
5107 "WHERE owner = " . $ilDB->quote($this->getId(), 'integer');
5108 $ilDB->query($query);
5109
5110 return true;
5111 }
5112
5113
5120 public static function getFirstLettersOfLastnames()
5121 {
5122 global $ilDB;
5123
5124 $q = "SELECT DISTINCT " . $ilDB->upper($ilDB->substr("lastname", 1, 1)) . " let" .
5125 " FROM usr_data" .
5126 " WHERE usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") .
5127 " ORDER BY let";
5128 $let_set = $ilDB->query($q);
5129
5130 $lets = array();
5131 while ($let_rec = $ilDB->fetchAssoc($let_set)) {
5132 $let[$let_rec["let"]] = $let_rec["let"];
5133 }
5134 return $let;
5135 }
5136
5137 // begin-patch deleteProgress
5138 public static function userExists($a_usr_ids = array())
5139 {
5140 global $ilDB;
5141
5142 $query = 'SELECT count(*) num FROM object_data od ' .
5143 'JOIN usr_data ud ON obj_id = usr_id ' .
5144 'WHERE ' . $ilDB->in('obj_id', $a_usr_ids, false, 'integer') . ' ';
5145 $res = $ilDB->query($query);
5146 $num_rows =$res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)->num;
5147 return $num_rows == count((array) $a_usr_ids);
5148 }
5149 // end-patch deleteProgress
5150
5154 public function isCaptchaVerified()
5155 {
5156 return (boolean) $_SESSION["user_captcha_verified"];
5157 }
5158
5164 public function setCaptchaVerified($a_val)
5165 {
5166 $_SESSION["user_captcha_verified"] = $a_val;
5167 }
5168
5175 public function exportPersonalData()
5176 {
5177 include_once("./Services/Export/classes/class.ilExport.php");
5178 $exp = new ilExport();
5179 $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5180 ilUtil::delDir($dir, true);
5181 $title = $this->getLastname() . ", " . $this->getLastname() . " [" . $this->getLogin() . "]";
5182 $exp->exportEntity(
5183 "personal_data",
5184 $this->getId(),
5185 "",
5186 "Services/User",
5187 $title,
5188 $dir
5189 );
5190 }
5191
5199 {
5200 include_once("./Services/Export/classes/class.ilExport.php");
5201 $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5202 if (!is_dir($dir)) {
5203 return "";
5204 }
5205 foreach (ilUtil::getDir($dir) as $entry) {
5206 if (is_int(strpos($entry["entry"], ".zip"))) {
5207 return $entry["entry"];
5208 }
5209 }
5210
5211 return "";
5212 }
5213
5220 public function sendPersonalDataFile()
5221 {
5222 include_once("./Services/Export/classes/class.ilExport.php");
5223 $file = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data") .
5224 "/" . $this->getPersonalDataExportFile();
5225 if (is_file($file)) {
5227 }
5228 }
5229
5236 public function importPersonalData(
5237 $a_file,
5238 $a_profile_data,
5239 $a_settings,
5240 $a_bookmarks,
5241 $a_notes,
5242 $a_calendar
5243 ) {
5244 include_once("./Services/Export/classes/class.ilImport.php");
5245 $imp = new ilImport();
5246 if (!$a_profile_data) {
5247 $imp->addSkipEntity("Services/User", "usr_profile");
5248 }
5249 if (!$a_settings) {
5250 $imp->addSkipEntity("Services/User", "usr_setting");
5251 }
5252 if (!$a_bookmarks) {
5253 $imp->addSkipEntity("Services/Bookmarks", "bookmarks");
5254 }
5255 if (!$a_notes) {
5256 $imp->addSkipEntity("Services/Notes", "user_notes");
5257 }
5258 if (!$a_calendar) {
5259 $imp->addSkipEntity("Services/Calendar", "calendar");
5260 }
5261 $imp->importEntity(
5262 $a_file["tmp_name"],
5263 $a_file["name"],
5264 "personal_data",
5265 "Services/User"
5266 );
5267 }
5268
5274 private static function initInactivationDate($usrIds)
5275 {
5276 global $ilDB;
5277
5278 $NOW = $ilDB->now();
5279
5280 $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5281
5282 $queryString = "
5283 UPDATE usr_data
5284 SET inactivation_date = $NOW
5285 WHERE inactivation_date IS NULL
5286 AND $usrId_IN_usrIds
5287 ";
5288
5289 $ilDB->manipulate($queryString);
5290 }
5291
5297 private static function resetInactivationDate($usrIds)
5298 {
5299 global $ilDB;
5300
5301 $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5302
5303 $queryString = "
5304 UPDATE usr_data
5305 SET inactivation_date = NULL
5306 WHERE $usrId_IN_usrIds
5307 ";
5308
5309 $ilDB->manipulate($queryString);
5310 }
5311
5318 {
5319 $this->inactivation_date = $inactivation_date;
5320 }
5321
5327 public function getInactivationDate()
5328 {
5330 }
5331
5336 {
5337 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5338
5339 if (
5341 null == $this->agree_date &&
5342 'root' != $this->login &&
5343 !in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID))
5344 ) {
5345 return true;
5346 }
5347
5348 return false;
5349 }
5350
5355 public static function hasUserToAcceptTermsOfService($a_username)
5356 {
5360 global $ilDB;
5361
5362 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5363
5365 return false;
5366 }
5367
5368 $in = $ilDB->in('usr_id', array(ANONYMOUS_USER_ID, SYSTEM_USER_ID), true, 'integer');
5369 $res = $ilDB->queryF(
5370 "SELECT usr_id FROM usr_data WHERE login = %s AND agree_date IS NULL $in",
5371 array("text"),
5372 array($a_username)
5373 );
5374 return $ilDB->fetchAssoc($res) ? true : false;
5375 }
5376
5384 public static function getUsersAgreed($a_agreed = true, $a_users = null)
5385 {
5386 global $ilDB;
5387
5388 $date_is = ($a_agreed)
5389 ? "IS NOT NULL"
5390 : "IS NULL";
5391
5392 $users = (is_array($a_users))
5393 ? " AND " . $ilDB->in("usr_id", $a_users, false, "integer")
5394 : "";
5395
5396 $set = $ilDB->query("SELECT usr_id FROM usr_data " .
5397 " WHERE agree_date " . $date_is .
5398 $users);
5399 $ret = array();
5400 while ($rec = $ilDB->fetchAssoc($set)) {
5401 $ret[] = $rec["usr_id"];
5402 }
5403 return $ret;
5404 }
5405
5406
5411 public function hasToAcceptTermsOfServiceInSession($status = null)
5412 {
5413 if (null === $status) {
5414 return ilSession::get('has_to_accept_agr_in_session');
5415 }
5416
5417 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5419 ilSession::set('has_to_accept_agr_in_session', (int) $status);
5420 }
5421 }
5422
5426 public function isAnonymous()
5427 {
5428 return self::_isAnonymous($this->getId());
5429 }
5430
5435 public static function _isAnonymous($usr_id)
5436 {
5437 return $usr_id == ANONYMOUS_USER_ID;
5438 }
5439
5440 public function activateDeletionFlag()
5441 {
5442 $this->writePref("delete_flag", true);
5443 }
5444
5445 public function removeDeletionFlag()
5446 {
5447 $this->writePref("delete_flag", false);
5448 }
5449
5450 public function hasDeletionFlag()
5451 {
5452 return (bool) $this->getPref("delete_flag");
5453 }
5454
5458 public function setIsSelfRegistered($status)
5459 {
5460 $this->is_self_registered = (bool) $status;
5461 }
5462
5463 public function isSelfRegistered()
5464 {
5465 return (bool) $this->is_self_registered;
5466 }
5467
5468
5469 //
5470 // MULTI-TEXT / INTERESTS
5471 //
5472
5478 public function setGeneralInterests(array $value = null)
5479 {
5480 $this->interests_general = $value;
5481 }
5482
5488 public function getGeneralInterests()
5489 {
5491 }
5492
5499 {
5500 return $this->buildTextFromArray("interests_general");
5501 }
5502
5508 public function setOfferingHelp(array $value = null)
5509 {
5510 $this->interests_help_offered = $value;
5511 }
5512
5518 public function getOfferingHelp()
5519 {
5521 }
5522
5528 public function getOfferingHelpAsText()
5529 {
5530 return $this->buildTextFromArray("interests_help_offered");
5531 }
5532
5538 public function setLookingForHelp(array $value = null)
5539 {
5540 $this->interests_help_looking = $value;
5541 }
5542
5548 public function getLookingForHelp()
5549 {
5551 }
5552
5558 public function getLookingForHelpAsText()
5559 {
5560 return $this->buildTextFromArray("interests_help_looking");
5561 }
5562
5569 protected function buildTextFromArray($a_attr)
5570 {
5571 $current = $this->$a_attr;
5572 if (is_array($current) && sizeof($current)) {
5573 return implode(", ", $current);
5574 }
5575 }
5576
5580 protected function readMultiTextFields()
5581 {
5582 global $ilDB;
5583
5584 if (!$this->getId()) {
5585 return;
5586 }
5587
5588 $set = $ilDB->query("SELECT field_id,value" .
5589 " FROM usr_data_multi" .
5590 " WHERE usr_id = " . $ilDB->quote($this->getId(), "integer") .
5591 " ORDER BY value");
5592 while ($row = $ilDB->fetchAssoc($set)) {
5593 $values[$row["field_id"]][] = $row["value"];
5594 }
5595
5596 if (isset($values["interests_general"])) {
5597 $this->setGeneralInterests($values["interests_general"]);
5598 } else {
5599 $this->setGeneralInterests();
5600 }
5601 if (isset($values["interests_help_offered"])) {
5602 $this->setOfferingHelp($values["interests_help_offered"]);
5603 } else {
5604 $this->setOfferingHelp();
5605 }
5606 if (isset($values["interests_help_looking"])) {
5607 $this->setLookingForHelp($values["interests_help_looking"]);
5608 } else {
5609 $this->setLookingForHelp();
5610 }
5611 }
5612
5618 public function updateMultiTextFields($a_create = false)
5619 {
5620 global $ilDB;
5621
5622 if (!$this->getId()) {
5623 return;
5624 }
5625
5626 if (!$a_create) {
5627 $this->deleteMultiTextFields();
5628 }
5629
5630 $map = array(
5631 "interests_general" => $this->getGeneralInterests(),
5632 "interests_help_offered" => $this->getOfferingHelp(),
5633 "interests_help_looking" => $this->getLookingForHelp()
5634 );
5635
5636 foreach ($map as $id => $values) {
5637 if (is_array($values) && sizeof($values)) {
5638 foreach ($values as $value) {
5639 $value = trim($value);
5640 if ($value) {
5641 $uniq_id = $ilDB->nextId('usr_data_multi');
5642
5643 $ilDB->manipulate("INSERT usr_data_multi" .
5644 " (id,usr_id,field_id,value) VALUES" .
5645 " (" . $ilDB->quote($uniq_id, "integer") .
5646 "," . $ilDB->quote($this->getId(), "integer") .
5647 "," . $ilDB->quote($id, "text") .
5648 "," . $ilDB->quote($value, "text") .
5649 ")");
5650 }
5651 }
5652 }
5653 }
5654 }
5655
5659 protected function deleteMultiTextFields()
5660 {
5661 global $ilDB;
5662
5663 if (!$this->getId()) {
5664 return;
5665 }
5666
5667 $ilDB->manipulate("DELETE FROM usr_data_multi" .
5668 " WHERE usr_id = " . $ilDB->quote($this->getId(), "integer"));
5669 }
5670
5671 public static function findInterests($a_term, $a_user_id = null, $a_field_id = null)
5672 {
5673 global $ilDB;
5674
5675 $res = array();
5676
5677 $sql = "SELECT DISTINCT(value)" .
5678 " FROM usr_data_multi" .
5679 " WHERE " . $ilDB->like("value", "text", "%" . $a_term . "%");
5680 if ($a_field_id) {
5681 $sql .= " AND field_id = " . $ilDB->quote($a_field_id, "text");
5682 }
5683 if ($a_user_id) {
5684 $sql .= " AND usr_id <> " . $ilDB->quote($a_user_id, "integer");
5685 }
5686 $sql .= " ORDER BY value";
5687 $set = $ilDB->query($sql);
5688 while ($row = $ilDB->fetchAssoc($set)) {
5689 $res[] = $row["value"];
5690 }
5691
5692 return $res;
5693 }
5694
5704 public static function getProfileStatusOfUsers($a_user_ids)
5705 {
5706 global $DIC;
5707
5708 $ilDB = $DIC->database();
5709
5710 $set = $ilDB->query(
5711 "SELECT * FROM usr_pref " .
5712 " WHERE keyword = " . $ilDB->quote("public_profile", "text") .
5713 " AND " . $ilDB->in("usr_id", $a_user_ids, false, "integer")
5714 );
5715 $r = array(
5716 "global" => array(),
5717 "local" => array(),
5718 "public" => array(),
5719 "not_public" => array()
5720 );
5721 while ($rec = $ilDB->fetchAssoc($set)) {
5722 if ($rec["value"] == "g") {
5723 $r["global"][] = $rec["usr_id"];
5724 $r["public"][] = $rec["usr_id"];
5725 }
5726 if ($rec["value"] == "y") {
5727 $r["local"][] = $rec["usr_id"];
5728 $r["public"][] = $rec["usr_id"];
5729 }
5730 }
5731 foreach ($a_user_ids as $id) {
5732 if (!in_array($id, $r["public"])) {
5733 $r["not_public"][] = $id;
5734 }
5735 }
5736
5737 return $r;
5738 }
5739} // END class ilObjUser
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$result
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
$users
Definition: authpage.php:44
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
const USER_FOLDER_ID
Class ilObjUserFolder.
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.
bookmark folder (note: this class handles personal bookmarks folders only)
static deletePDItemsCache($a_usr_id)
Delete cache (add remove desktop item)
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)
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.
static deleteByOwner($a_owner_id)
Delete all entries for owner.
Base class for ILIAS Exception handling.
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.
Base class for nested set path based trees.
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 _writeExternalAccount($a_usr_id, $a_ext_id)
setCurrentLanguage($a_val)
Set current language.
getDiskQuota()
Returns the minimal disk quota imposed by this user account.
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.
addDesktopItem($a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
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.
getUserIdByEmail($a_email)
STATIC METHOD get the user_id of an email address.
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
static getFirstLettersOfLastnames()
Get first letters of all lastnames.
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
setDiskQuota($a_disk_quota)
Sets the minimal disk quota imposed by this user account.
getLastname()
get lastname @access public
removeUserPicture($a_do_update=true)
Remove user picture.
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 _isDesktopItem($a_usr_id, $a_item_id, $a_type)
check wether an item is on the users desktop or not
static _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
drop an item from user's personal desktop
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)
static _getAssociatedUsersOnline($a_user_id, $a_no_anonymous=false)
reads all active sessions from db and returns users that are online and who have a local role in a gr...
setExternalAccount($a_str)
set external account
setLogin($a_str)
set login / username @access public
static userExists($a_usr_ids=array())
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)
importPersonalData( $a_file, $a_profile_data, $a_settings, $a_bookmarks, $a_notes, $a_calendar)
Import personal data.
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)
isDesktopItem($a_item_id, $a_type)
check wether an item is on the users desktop or not
setCaptchaVerified($a_val)
Set captcha verified.
clipboardDeleteObjectsOfType($a_type)
Delete objects of type for user.
static preloadIsDesktopItem($a_usr_id, $a_item_ids)
Preload desktop item information.
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
static _lookupDesktopItems($user_id, $a_types="")
get all desktop items of user and specified type
static _getAllUserAssignedStyles()
skins and styles
static _deleteAllPref($a_user_id)
Deletes a userpref value of the user from the database @access public.
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 _getUserIdsByInactivityPeriod($period)
get ids of all users that have been inactive for at least the given period
static _lookupGender($a_user_id)
Lookup gender.
setPasswordSalt($password_salt)
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
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
getDesktopItems($a_types="")
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
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,...
static _getUserIdsByEmail($a_email)
STATIC METHOD get all user_ids of an email address.
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
assignData($a_data)
loads a record "user" from array @access public
getPersonalWorkspaceDiskQuota()
setLastPasswordChangeToNow()
setHobby($a_str)
set hobby @access public
getLookingForHelp()
Get help looking for.
static _isAnonymous($usr_id)
static _removeItemFromDesktops($a_id)
removes object from all user's desktops @access public
static _lookupLanguage($a_usr_id)
getGeneralInterestsAsText()
Get general interests as plain text.
static _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par="")
add an item to user's personal desktop
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)
dropDesktopItem($a_item_id, $a_type)
drop an item from user's personal desktop
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
isCaptchaVerified()
Is user captcha verified?
setLoginAttempts($a_login_attempts)
setDesktopItemParameters($a_item_id, $a_type, $a_par)
set parameters of a desktop item entry
getGender()
get gender @access public
getExternalAccount()
get external account
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
static _lookupDescription($a_id)
lookup object description
setOwner($a_owner)
set object owner
getId()
get object id @access public
getCreateDate()
get create date @access public
Custom block for external feeds on personal desktop.
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 subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
static skinExists($skin_id, ilSystemStyleConfig $system_style_config=null)
Check whether a skin exists.
static styleExistsForSkinId($skin_id, $style_id)
static getInstance()
Singelton get instance.
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 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.
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$r
Definition: example_031.php:79
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$format
Definition: metadata.php:141
$end
Definition: saml1-acs.php:18
update($pash, $contents, Config $config)
redirection script todo: (a better solution should control the processing via a xml file)
$ret
Definition: parser.php:6
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
global $ilSetting
Definition: privfeed.php:17
$query
global $ilErr
Definition: raiseError.php:16
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_content
Definition: workflow.php:93
$a_type
Definition: workflow.php:92