ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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';
10
23class ilObjUser extends ilObject
24{
29 // personal data
30
31 var $login; // username in system
32
36 protected $passwd; // password encoded in the format specified by $passwd_type
37
41 protected $passwd_type;
42 // specifies the password format.
43 // value: IL_PASSWD_PLAIN or IL_PASSWD_CRYPTED.
44
45 // Differences between password format in class ilObjUser and
46 // in table usr_data:
47 // Class ilObjUser supports two different password types
48 // (plain and crypted) and it uses the variables $passwd
49 // and $passwd_type to store them.
50 // Table usr_data supports only two different password types
51 // (md5 and bcrypt) and it uses the columns "passwd" and "passwd_type" to store them.
52 // The conversion between these two storage layouts is done
53 // in the methods that perform SQL statements. All other
54 // methods work exclusively with the $passwd and $passwd_type
55 // variables.
56
62
67 protected $password_salt = null;
68
69 var $gender; // 'm' or 'f'
70 var $utitle; // user title (keep in mind, that we derive $title from object also!)
73 protected $birthday;
74 var $fullname; // title + firstname + lastname in one string
75 //var $archive_dir = "./image"; // point to image file (should be flexible)
76 // address data
80 var $city;
87 var $fax;
88 var $email;
89 var $hobby;
92 var $approve_date = null;
93 var $agree_date = null;
95 var $client_ip; // client ip to check before login
96 var $auth_mode; // authentication mode
97
105
110
113
114 var $user_defined_data = array();
115
122
128 var $skin;
129
130
137
144
147
151 protected static $personal_image_cache = array();
152
158 protected $inactivation_date = null;
159
164 private $is_self_registered = false;
165
166 protected $interests_general; // [array]
167 protected $interests_help_offered; // [array]
168 protected $interests_help_looking; // [array]
169
175 public function __construct($a_user_id = 0, $a_call_by_reference = false)
176 {
177 global $ilias,$ilDB;
178
179 // init variables
180 $this->ilias =& $ilias;
181 $this->db =& $ilDB;
182
183 $this->type = "usr";
184 parent::__construct($a_user_id, $a_call_by_reference);
185 $this->auth_mode = "default";
186 $this->passwd_type = IL_PASSWD_PLAIN;
187
188 // for gender selection. don't change this
189 /*$this->gender = array(
190 'm' => "salutation_m",
191 'f' => "salutation_f"
192 );*/
193 if ($a_user_id > 0)
194 {
195 $this->setId($a_user_id);
196 $this->read();
197 }
198 else
199 {
200 // TODO: all code in else-structure doesn't belongs in class user !!!
201 //load default data
202 $this->prefs = array();
203 //language
204 $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
205
206 //skin and pda support
207 $this->skin = $this->ilias->ini->readVariable("layout","skin");
208
209 $this->prefs["skin"] = $this->skin;
210 $this->prefs["show_users_online"] = "y";
211
212 //style (css)
213 $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
214 }
215 }
216
221 function read()
222 {
223 global $ilErr, $ilDB;
224
225 // Alex: I have removed the JOIN to rbac_ua, since there seems to be no
226 // use (3.11.0 alpha)
227 /*$q = "SELECT * FROM usr_data ".
228 "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
229 "WHERE usr_data.usr_id= ".$ilDB->quote($this->id); */
230 $r = $ilDB->queryF("SELECT * FROM usr_data ".
231 "WHERE usr_id= %s", array("integer"), array($this->id));
232
233 if ($data = $ilDB->fetchAssoc($r))
234 {
235 // convert password storage layout used by table usr_data into
236 // storage layout used by class ilObjUser
237 $data["passwd_type"] = IL_PASSWD_CRYPTED;
238
239 // this assign must not be set via $this->assignData($data)
240 // because this method will be called on profile updates and
241 // would set this values to 0, because they arent posted from form
242 $this->setLastPasswordChangeTS( $data['last_password_change'] );
243 $this->setLoginAttempts( $data['login_attempts'] );
244
245
246 // fill member vars in one shot
247 $this->assignData($data);
248
249 //get userpreferences from usr_pref table
250 $this->readPrefs();
251
252 //set language to default if not set
253 if ($this->prefs["language"] == "")
254 {
255 $this->prefs["language"] = $this->oldPrefs["language"];
256 }
257
258 //check skin-setting
259 include_once("./Services/Style/classes/class.ilStyleDefinition.php");
260 if ($this->prefs["skin"] == "" ||
261 !ilStyleDefinition::skinExists($this->prefs["skin"]))
262 {
263 $this->prefs["skin"] = $this->oldPrefs["skin"];
264 }
265
266 $this->skin = $this->prefs["skin"];
267
268 //check style-setting (skins could have more than one stylesheet
269 if ($this->prefs["style"] == "" ||
270 !ilStyleDefinition::skinExists($this->skin, $this->prefs["style"]))
271 {
272 //load default (css)
273 $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
274 }
275
276 if (empty($this->prefs["hits_per_page"]))
277 {
278 $this->prefs["hits_per_page"] = 10;
279 }
280
281 }
282 else
283 {
284 $ilErr->raiseError("<b>Error: There is no dataset with id ".
285 $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
286 "<br />Line: ".__LINE__, $ilErr->FATAL);
287 }
288
289 $this->readMultiTextFields();
290 $this->readUserDefinedFields();
291
292 parent::read();
293 }
294
298 public function getPasswordEncodingType()
299 {
301 }
302
306 public function setPasswordEncodingType($password_encryption_type)
307 {
308 $this->password_encoding_type = $password_encryption_type;
309 }
310
314 public function getPasswordSalt()
315 {
317 }
318
323 {
324 $this->password_salt = $password_salt;
325 }
326
332 function assignData($a_data)
333 {
334 global $ilErr, $ilDB, $lng;
335
336 // basic personal data
337 $this->setLogin($a_data["login"]);
338 if (! $a_data["passwd_type"])
339 {
340 $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
341 $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
342 .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
343 }
344 if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
345 {
346 $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
347 }
348
349 $this->setGender($a_data["gender"]);
350 $this->setUTitle($a_data["title"]);
351 $this->setFirstname($a_data["firstname"]);
352 $this->setLastname($a_data["lastname"]);
353 $this->setFullname();
354 if (!is_array($a_data['birthday']))
355 {
356 $this->setBirthday($a_data['birthday']);
357 }
358 else
359 {
360 $this->setBirthday(null);
361 }
362
363 // address data
364 $this->setInstitution($a_data["institution"]);
365 $this->setDepartment($a_data["department"]);
366 $this->setStreet($a_data["street"]);
367 $this->setCity($a_data["city"]);
368 $this->setZipcode($a_data["zipcode"]);
369 $this->setCountry($a_data["country"]);
370 $this->setSelectedCountry($a_data["sel_country"]);
371 $this->setPhoneOffice($a_data["phone_office"]);
372 $this->setPhoneHome($a_data["phone_home"]);
373 $this->setPhoneMobile($a_data["phone_mobile"]);
374 $this->setFax($a_data["fax"]);
375 $this->setMatriculation($a_data["matriculation"]);
376 $this->setEmail($a_data["email"]);
377 $this->setHobby($a_data["hobby"]);
378 $this->setClientIP($a_data["client_ip"]);
379 $this->setPasswordEncodingType($a_data['passwd_enc_type']);
380 $this->setPasswordSalt($a_data['passwd_salt']);
381
382 // instant messenger data
383 $this->setInstantMessengerId('icq',$a_data["im_icq"]);
384 $this->setInstantMessengerId('yahoo',$a_data["im_yahoo"]);
385 $this->setInstantMessengerId('msn',$a_data["im_msn"]);
386 $this->setInstantMessengerId('aim',$a_data["im_aim"]);
387 $this->setInstantMessengerId('skype',$a_data["im_skype"]);
388 $this->setInstantMessengerId('jabber',$a_data["im_jabber"]);
389 $this->setInstantMessengerId('voip',$a_data["im_voip"]);
390
391 // other data
392 $this->setDelicious($a_data["delicious"]);
393 $this->setLatitude($a_data["latitude"]);
394 $this->setLongitude($a_data["longitude"]);
395 $this->setLocationZoom($a_data["loc_zoom"]);
396
397 // system data
398 $this->setLastLogin($a_data["last_login"]);
399 $this->setLastUpdate($a_data["last_update"]);
400 $this->create_date = $a_data["create_date"];
401 $this->setComment($a_data["referral_comment"]);
402 $this->approve_date = $a_data["approve_date"];
403 $this->active = $a_data["active"];
404 $this->agree_date = $a_data["agree_date"];
405
406 $this->setInactivationDate($a_data["inactivation_date"]);
407
408 // time limitation
409 $this->setTimeLimitOwner($a_data["time_limit_owner"]);
410 $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
411 $this->setTimeLimitFrom($a_data["time_limit_from"]);
412 $this->setTimeLimitUntil($a_data["time_limit_until"]);
413 $this->setTimeLimitMessage($a_data['time_limit_message']);
414
415 // user profile incomplete?
416 $this->setProfileIncomplete($a_data["profile_incomplete"]);
417
418 //authentication
419 $this->setAuthMode($a_data['auth_mode']);
420 $this->setExternalAccount($a_data['ext_account']);
421
422 $this->setIsSelfRegistered((bool)$a_data['is_self_registered']);
423 }
424
431 public function saveAsNew($a_from_formular = true)
432 {
433 global $ilAppEventHandler;
434
439 global $ilErr, $ilDB;
440
441 switch ($this->passwd_type)
442 {
443 case IL_PASSWD_PLAIN:
444 if(strlen($this->passwd))
445 {
446 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
447 ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
448 $pw_value = $this->getPasswd();
449 }
450 else
451 {
452 $pw_value = $this->passwd;
453 }
454 break;
455
457 $pw_value = $this->passwd;
458 break;
459
460 default :
461 $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
462 $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
463 "<br />Line: ".__LINE__, $ilErr->FATAL);
464 }
465
466 if( !$this->active )
467 {
469 }
470 else
471 {
472 $this->setInactivationDate(null);
473 }
474
475 $insert_array = array(
476 "usr_id" => array("integer", $this->id),
477 "login" => array("text", $this->login),
478 "passwd" => array("text", $pw_value),
479 'passwd_enc_type' => array("text", $this->getPasswordEncodingType()),
480 'passwd_salt' => array("text", $this->getPasswordSalt()),
481 "firstname" => array("text", $this->firstname),
482 "lastname" => array("text", $this->lastname),
483 "title" => array("text", $this->utitle),
484 "gender" => array("text", $this->gender),
485 "email" => array("text", trim($this->email)),
486 "hobby" => array("text", (string) $this->hobby),
487 "institution" => array("text", $this->institution),
488 "department" => array("text", $this->department),
489 "street" => array("text", $this->street),
490 "city" => array("text", $this->city),
491 "zipcode" => array("text", $this->zipcode),
492 "country" => array("text", $this->country),
493 "sel_country" => array("text", $this->sel_country),
494 "phone_office" => array("text", $this->phone_office),
495 "phone_home" => array("text", $this->phone_home),
496 "phone_mobile" => array("text", $this->phone_mobile),
497 "fax" => array("text", $this->fax),
498 "birthday" => array('date', $this->getBirthday()),
499 "last_login" => array("timestamp", null),
500 "last_update" => array("timestamp", ilUtil::now()),
501 "create_date" => array("timestamp", ilUtil::now()),
502 "referral_comment" => array("text", $this->referral_comment),
503 "matriculation" => array("text", $this->matriculation),
504 "client_ip" => array("text", $this->client_ip),
505 "approve_date" => array("timestamp", $this->approve_date),
506 "agree_date" => array("timestamp", $this->agree_date),
507 "active" => array("integer", (int) $this->active),
508 "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
509 "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
510 "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
511 "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
512 "auth_mode" => array("text", $this->getAuthMode()),
513 "ext_account" => array("text", $this->getExternalAccount()),
514 "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
515 "im_icq" => array("text", $this->im_icq),
516 "im_yahoo" => array("text", $this->im_yahoo),
517 "im_msn" => array("text", $this->im_msn),
518 "im_aim" => array("text", $this->im_aim),
519 "im_skype" => array("text", $this->im_skype),
520 "delicious" => array("text", $this->delicious),
521 "latitude" => array("text", $this->latitude),
522 "longitude" => array("text", $this->longitude),
523 "loc_zoom" => array("integer", (int) $this->loc_zoom),
524 "last_password_change" => array("integer", (int) $this->last_password_change_ts),
525 "im_jabber" => array("text", $this->im_jabber),
526 "im_voip" => array("text", $this->im_voip),
527 'inactivation_date' => array('timestamp', $this->inactivation_date),
528 'is_self_registered' => array('integer', (int)$this->is_self_registered)
529 );
530 $ilDB->insert("usr_data", $insert_array);
531
532 $this->updateMultiTextFields(true);
533
534 // add new entry in usr_defined_data
536 // ... and update
538
539 // CREATE ENTRIES FOR MAIL BOX
540 include_once ("Services/Mail/classes/class.ilMailbox.php");
541 $mbox = new ilMailbox($this->id);
542 $mbox->createDefaultFolder();
543
544 include_once "Services/Mail/classes/class.ilMailOptions.php";
545 $mail_options = new ilMailOptions($this->id);
546 $mail_options->createMailOptionsEntry();
547
548 // create personal bookmark folder tree
549 include_once "./Services/Bookmarks/classes/class.ilBookmarkFolder.php";
550 $bmf = new ilBookmarkFolder(0, $this->id);
551 $bmf->createNewBookmarkTree();
552
553 $ilAppEventHandler->raise("Services/User", "afterCreate",
554 array("user_obj" => $this));
555
556 }
557
561 public function update()
562 {
568 global $ilErr, $ilDB, $ilAppEventHandler;
569
570 $this->syncActive();
571
572 if( $this->getStoredActive($this->id) && !$this->active )
573 {
575 }
576 else if($this->active)
577 {
578 $this->setInactivationDate(null);
579 }
580
581 $update_array = array(
582 "gender" => array("text", $this->gender),
583 "title" => array("text", $this->utitle),
584 "firstname" => array("text", $this->firstname),
585 "lastname" => array("text", $this->lastname),
586 "email" => array("text", trim($this->email)),
587 "birthday" => array('date', $this->getBirthday()),
588 "hobby" => array("text", $this->hobby),
589 "institution" => array("text", $this->institution),
590 "department" => array("text", $this->department),
591 "street" => array("text", $this->street),
592 "city" => array("text", $this->city),
593 "zipcode" => array("text", $this->zipcode),
594 "country" => array("text", $this->country),
595 "sel_country" => array("text", $this->sel_country),
596 "phone_office" => array("text", $this->phone_office),
597 "phone_home" => array("text", $this->phone_home),
598 "phone_mobile" => array("text", $this->phone_mobile),
599 "fax" => array("text", $this->fax),
600 "referral_comment" => array("text", $this->referral_comment),
601 "matriculation" => array("text", $this->matriculation),
602 "client_ip" => array("text", $this->client_ip),
603 "approve_date" => array("timestamp", $this->approve_date),
604 "active" => array("integer", $this->active),
605 "time_limit_unlimited" => array("integer", $this->getTimeLimitUnlimited()),
606 "time_limit_until" => array("integer", $this->getTimeLimitUntil()),
607 "time_limit_from" => array("integer", $this->getTimeLimitFrom()),
608 "time_limit_owner" => array("integer", $this->getTimeLimitOwner()),
609 "time_limit_message" => array("integer", $this->getTimeLimitMessage()),
610 "profile_incomplete" => array("integer", $this->getProfileIncomplete()),
611 "auth_mode" => array("text", $this->getAuthMode()),
612 "ext_account" => array("text", $this->getExternalAccount()),
613 "im_icq" => array("text", $this->im_icq),
614 "im_yahoo" => array("text", $this->im_yahoo),
615 "im_msn" => array("text", $this->im_msn),
616 "im_aim" => array("text", $this->im_aim),
617 "im_skype" => array("text", $this->im_skype),
618 "delicious" => array("text", $this->delicious),
619 "latitude" => array("text", $this->latitude),
620 "longitude" => array("text", $this->longitude),
621 "loc_zoom" => array("integer", (int) $this->loc_zoom),
622 "last_password_change" => array("integer", $this->last_password_change_ts),
623 "im_jabber" => array("text", $this->im_jabber),
624 "im_voip" => array("text", $this->im_voip),
625 "last_update" => array("timestamp", ilUtil::now()),
626 'inactivation_date' => array('timestamp', $this->inactivation_date)
627 );
628
629 if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == null))
630 {
631 $update_array["agree_date"] = array("timestamp", $this->agree_date);
632 }
633 switch ($this->passwd_type)
634 {
635 case IL_PASSWD_PLAIN:
636 if(strlen($this->passwd))
637 {
638 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
639 ilUserPasswordManager::getInstance()->encodePassword($this, $this->passwd);
640 $update_array['passwd'] = array('text', $this->getPasswd());
641 }
642 else
643 {
644 $update_array["passwd"] = array("text", (string) $this->passwd);
645 }
646 break;
647
649 $update_array["passwd"] = array("text", (string) $this->passwd);
650 break;
651
652 default :
653 $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
654 get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
655 }
656
657 $update_array['passwd_enc_type'] = array('text', $this->getPasswordEncodingType());
658 $update_array['passwd_salt'] = array('text', $this->getPasswordSalt());
659
660 $ilDB->update("usr_data", $update_array, array("usr_id" => array("integer", $this->id)));
661
662 $this->updateMultiTextFields();
663
664 $this->writePrefs();
665
666 // update user defined fields
668
669 parent::update();
670 parent::updateOwner();
671
672 $this->read();
673
674 $ilAppEventHandler->raise("Services/User", "afterUpdate",
675 array("user_obj" => $this));
676
677 return true;
678 }
679
683 function writeAccepted()
684 {
685 global $ilDB;
686
687 $ilDB->manipulateF("UPDATE usr_data SET agree_date = ".$ilDB->now().
688 " WHERE usr_id = %s", array("integer"), array($this->getId()));
689 }
690
694 private function _lookup($a_user_id, $a_field)
695 {
696 global $ilDB;
697
698 $res = $ilDB->queryF("SELECT ".$a_field." FROM usr_data WHERE usr_id = %s",
699 array("integer"), array($a_user_id));
700
701 while($set = $ilDB->fetchAssoc($res))
702 {
703 return $set[$a_field];
704 }
705 return false;
706 }
707
711 function _lookupFullname($a_user_id)
712 {
713 global $ilDB;
714
715 $set = $ilDB->queryF("SELECT title, firstname, lastname FROM usr_data WHERE usr_id = %s",
716 array("integer"), array($a_user_id));
717
718 if ($rec = $ilDB->fetchAssoc($set))
719 {
720 if ($rec["title"])
721 {
722 $fullname = $rec["title"]." ";
723 }
724 if ($rec["firstname"])
725 {
726 $fullname .= $rec["firstname"]." ";
727 }
728 if ($rec["lastname"])
729 {
730 $fullname .= $rec["lastname"];
731 }
732 }
733 return $fullname;
734 }
735
739 function _lookupIm($a_user_id, $a_type)
740 {
741 return ilObjUser::_lookup($a_user_id, "im_".$a_type);
742 }
743
744
748 function _lookupEmail($a_user_id)
749 {
750 return ilObjUser::_lookup($a_user_id, "email");
751 }
752
756 public static function _lookupGender($a_user_id)
757 {
758 return ilObjUser::_lookup($a_user_id, "gender");
759 }
760
767 function _lookupClientIP($a_user_id)
768 {
769 return ilObjUser::_lookup($a_user_id, "client_ip");
770 }
771
772
778 public static function _lookupName($a_user_id)
779 {
780 global $ilDB;
781
782 $res = $ilDB->queryF("SELECT firstname, lastname, title, login FROM usr_data WHERE usr_id = %s",
783 array("integer"), array($a_user_id));
784 $user_rec = $ilDB->fetchAssoc($res);
785 return array("user_id" => $a_user_id,
786 "firstname" => $user_rec["firstname"],
787 "lastname" => $user_rec["lastname"],
788 "title" => $user_rec["title"],
789 "login" => $user_rec["login"]);
790 }
791
795 function _lookupFields($a_user_id)
796 {
797 global $ilDB;
798
799 $res = $ilDB->queryF("SELECT * FROM usr_data WHERE usr_id = %s",
800 array("integer"), array($a_user_id));
801 $user_rec = $ilDB->fetchAssoc($res);
802 return $user_rec;
803 }
804
808 function _lookupLogin($a_user_id)
809 {
810 return ilObjUser::_lookup($a_user_id, "login");
811 }
812
816 function _lookupExternalAccount($a_user_id)
817 {
818 return ilObjUser::_lookup($a_user_id, "ext_account");
819 }
820
824 public static function _lookupId($a_user_str)
825 {
826 global $ilDB;
827
828 $res = $ilDB->queryF("SELECT usr_id FROM usr_data WHERE login = %s",
829 array("text"), array($a_user_str));
830 $user_rec = $ilDB->fetchAssoc($res);
831 return $user_rec["usr_id"];
832 }
833
837 function _lookupLastLogin($a_user_id)
838 {
839 return ilObjUser::_lookup($a_user_id, "last_login");
840 }
841
842
848 function refreshLogin()
849 {
850 global $ilDB;
851
852 $ilDB->manipulateF("UPDATE usr_data SET ".
853 "last_login = ".$ilDB->now().
854 " WHERE usr_id = %s",
855 array("integer"), array($this->id));
856 }
857
863 public function replacePassword($md5_encoded_password)
864 {
868 global $ilDB;
869
870 $this->setPasswd($md5_encoded_password, IL_PASSWD_CRYPTED);
871 $this->setPasswordEncodingType('md5');
872
873 $ilDB->manipulateF(
874 'UPDATE usr_data
875 SET passwd = %s, passwd_enc_type = %s
876 WHERE usr_id = %s',
877 array('text', 'text', 'integer'),
878 array($this->getPasswd(), $this->getPasswordEncodingType(), $this->getId())
879 );
880
881 return true;
882 }
883
891 public function resetPassword($raw, $raw_retype)
892 {
896 global $ilDB;
897
898 if(func_num_args() != 2)
899 {
900 return false;
901 }
902
903 if(!isset($raw) || !isset($raw_retype))
904 {
905 return false;
906 }
907
908 if($raw != $raw_retype)
909 {
910 return false;
911 }
912
913 require_once 'Services/User/classes/class.ilUserPasswordManager.php';
914 ilUserPasswordManager::getInstance()->encodePassword($this, $raw);
915
916 $ilDB->manipulateF(
917 'UPDATE usr_data
918 SET passwd = %s, passwd_enc_type = %s, passwd_salt = %s
919 WHERE usr_id = %s',
920 array('text', 'text', 'text', 'integer'),
921 array($this->getPasswd(), $this->getPasswordEncodingType(), $this->getPasswordSalt(), $this->getId())
922 );
923
924 return true;
925 }
926
937 public static function _doesLoginnameExistInHistory($a_login)
938 {
939 global $ilDB;
940
941 $res = $ilDB->queryF('
942 SELECT * FROM loginname_history
943 WHERE login = %s',
944 array('text'), array($a_login));
945
946 return $ilDB->fetchAssoc($res) ? true : false;
947 }
948
961 public static function _getLastHistoryDataByUserId($a_usr_id)
962 {
963 global $ilDB;
964
965 $ilDB->setLimit(1, 0);
966 $res = $ilDB->queryF('
967 SELECT login, history_date FROM loginname_history
968 WHERE usr_id = %s ORDER BY history_date DESC',
969 array('integer'), array($a_usr_id));
970 $row = $ilDB->fetchAssoc($res);
971 if(!is_array($row) || !count($row)) throw new ilUserException('');
972
973 return array(
974 $row['login'], $row['history_date']
975 );
976 }
977
985 function updateLogin($a_login)
986 {
987 global $ilDB, $ilSetting;
988
989 if(func_num_args() != 1)
990 {
991 return false;
992 }
993
994 if(!isset($a_login))
995 {
996 return false;
997 }
998
999 $former_login = self::_lookupLogin($this->getId());
1000
1001 // Update not necessary
1002 if(0 == strcmp($a_login, $former_login))
1003 {
1004 return false;
1005 }
1006
1007 try
1008 {
1009 $last_history_entry = ilObjUser::_getLastHistoryDataByUserId($this->getId());
1010 }
1011 catch(ilUserException $e) { $last_history_entry = null; }
1012
1013 // throw exception if the desired loginame is already in history and it is not allowed to reuse it
1014 if((int)$ilSetting->get('allow_change_loginname') &&
1015 (int)$ilSetting->get('reuse_of_loginnames') == 0 &&
1016 self::_doesLoginnameExistInHistory($a_login))
1017 {
1018 throw new ilUserException($this->lng->txt('loginname_already_exists'));
1019 }
1020 else if((int)$ilSetting->get('allow_change_loginname') &&
1021 (int)$ilSetting->get('loginname_change_blocking_time') &&
1022 is_array($last_history_entry) &&
1023 $last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time') > time())
1024 {
1025 include_once 'Services/Calendar/classes/class.ilDate.php';
1026 throw new ilUserException(
1027 sprintf(
1028 $this->lng->txt('changing_loginname_not_possible_info'),
1030 new ilDateTime($last_history_entry[1], IL_CAL_UNIX)),
1032 new ilDateTime(($last_history_entry[1] + (int)$ilSetting->get('loginname_change_blocking_time')), IL_CAL_UNIX))
1033 )
1034 );
1035 }
1036 else
1037 {
1038 // log old loginname in history
1039 if((int)$ilSetting->get('allow_change_loginname') &&
1040 (int)$ilSetting->get('create_history_loginname'))
1041 {
1042 ilObjUser::_writeHistory($this->getId(), $former_login);
1043 }
1044
1045 //update login
1046 $this->login = $a_login;
1047
1048 $ilDB->manipulateF('
1049 UPDATE usr_data
1050 SET login = %s
1051 WHERE usr_id = %s',
1052 array('text', 'integer'), array($this->getLogin(), $this->getId()));
1053
1054 include_once 'Services/Contact/classes/class.ilAddressbook.php';
1055 ilAddressbook::onLoginNameChange($former_login, $this->getLogin());
1056 }
1057
1058 return true;
1059 }
1060
1067 function writePref($a_keyword, $a_value)
1068 {
1069 self::_writePref($this->id, $a_keyword, $a_value);
1070 $this->setPref($a_keyword, $a_value);
1071 }
1072
1073
1079 function deletePref($a_keyword)
1080 {
1081 self::_deletePref($this->getId(), $a_keyword);
1082 }
1083
1089 public static function _deletePref($a_user_id, $a_keyword)
1090 {
1094 global $ilDB;
1095
1096 $ilDB->manipulateF(
1097 'DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s',
1098 array('integer', 'text'),
1099 array($a_user_id, $a_keyword)
1100 );
1101 }
1102
1108 function _deleteAllPref($a_user_id)
1109 {
1110 global $ilDB;
1111
1112 $ilDB->manipulateF("DELETE FROM usr_pref WHERE usr_id = %s",
1113 array("integer"), array($a_user_id));
1114 }
1115
1122 public static function _writePref($a_usr_id, $a_keyword, $a_value)
1123 {
1124 global $ilDB;
1125 $ilDB->replace("usr_pref",
1126 array(
1127 "usr_id" => array("integer", $a_usr_id),
1128 "keyword" => array("text", $a_keyword),
1129 ),
1130 array(
1131 "value" => array("text",$a_value)
1132 )
1133 );
1134
1135 /*
1136 self::_deletePref($a_usr_id, $a_keyword);
1137 if(strlen($a_value))
1138 {
1139 $ilDB->manipulateF(
1140 'INSERT INTO usr_pref (usr_id, keyword, value) VALUES (%s, %s, %s)',
1141 array('integer', 'text', 'text'),
1142 array($a_usr_id, $a_keyword, $a_value)
1143 );
1144 }*/
1145 }
1146
1151 function writePrefs()
1152 {
1153 global $ilDB;
1154
1155 ilObjUser::_deleteAllPref($this->id);
1156 foreach ($this->prefs as $keyword => $value)
1157 {
1158 self::_writePref($this->id, $keyword, $value);
1159 }
1160 }
1161
1168 public function getTimeZone()
1169 {
1170 if($tz = $this->getPref('user_tz'))
1171 {
1172 return $tz;
1173 }
1174 else
1175 {
1176 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1178 return $settings->getDefaultTimeZone();
1179 }
1180 }
1181
1188 public function getTimeFormat()
1189 {
1190 if($format = $this->getPref('time_format'))
1191 {
1192 return $format;
1193 }
1194 else
1195 {
1196 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1198 return $settings->getDefaultTimeFormat();
1199 }
1200 }
1201
1208 public function getDateFormat()
1209 {
1210 if($format = $this->getPref('date_format'))
1211 {
1212 return $format;
1213 }
1214 else
1215 {
1216 include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1218 return $settings->getDefaultDateFormat();
1219 }
1220 }
1221
1228 function setPref($a_keyword, $a_value)
1229 {
1230 if ($a_keyword != "")
1231 {
1232 $this->prefs[$a_keyword] = $a_value;
1233 }
1234 }
1235
1241 function getPref($a_keyword)
1242 {
1243 if (array_key_exists($a_keyword, $this->prefs))
1244 {
1245 return $this->prefs[$a_keyword];
1246 }
1247 else
1248 {
1249 return FALSE;
1250 }
1251 }
1252
1253 function _lookupPref($a_usr_id,$a_keyword)
1254 {
1255 global $ilDB;
1256
1257 $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id, "integer")." ".
1258 "AND keyword = ".$ilDB->quote($a_keyword, "text");
1259 $res = $ilDB->query($query);
1260
1261 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1262 {
1263 return $row->value;
1264 }
1265 return false;
1266 }
1267
1272 function readPrefs()
1273 {
1274 global $ilDB;
1275
1276 if (is_array($this->prefs))
1277 {
1278 $this->oldPrefs = $this->prefs;
1279 }
1280
1281 $this->prefs = ilObjUser::_getPreferences($this->id);
1282 }
1283
1289 function delete()
1290 {
1291 global $rbacadmin, $ilDB;
1292
1293 // deassign from ldap groups
1294 include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1296 $mapping->deleteUser($this->getId());
1297
1298 // remove mailbox / update sent mails
1299 include_once ("Services/Mail/classes/class.ilMailbox.php");
1300 $mailbox = new ilMailbox($this->getId());
1301 $mailbox->delete();
1302 $mailbox->updateMailsOfDeletedUser($this->getLogin());
1303
1304 // delete feed blocks on personal desktop
1305 include_once("./Services/Block/classes/class.ilCustomBlock.php");
1306 $costum_block = new ilCustomBlock();
1307 $costum_block->setContextObjId($this->getId());
1308 $costum_block->setContextObjType("user");
1309 $c_blocks = $costum_block->queryBlocksForContext();
1310 include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1311 foreach($c_blocks as $c_block)
1312 {
1313 if ($c_block["type"] == "pdfeed")
1314 {
1315 $fb = new ilPDExternalFeedBlock($c_block["id"]);
1316 $fb->delete();
1317 }
1318 }
1319
1320
1321 // delete block settings
1322 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1324
1325 // delete user_account
1326 $ilDB->manipulateF("DELETE FROM usr_data WHERE usr_id = %s",
1327 array("integer"), array($this->getId()));
1328
1329 $this->deleteMultiTextFields();
1330
1331 // delete user_prefs
1333
1334 $this->removeUserPicture(false); // #8597
1335
1336 // delete user_session
1337 include_once("./Services/Authentication/classes/class.ilSession.php");
1339
1340 // remove user from rbac
1341 $rbacadmin->removeUser($this->getId());
1342
1343 // remove bookmarks
1344 // TODO: move this to class.ilBookmarkFolder
1345 $q = "DELETE FROM bookmark_tree WHERE tree = ".
1346 $ilDB->quote($this->getId(), "integer");
1347 $ilDB->manipulate($q);
1348
1349 $q = "DELETE FROM bookmark_data WHERE user_id = ".
1350 $ilDB->quote($this->getId(), "integer");
1351 $ilDB->manipulate($q);
1352
1353 // DELETE FORUM ENTRIES (not complete in the moment)
1354 include_once './Modules/Forum/classes/class.ilObjForum.php';
1355 ilObjForum::_deleteUser($this->getId());
1356
1357 // Delete link check notify entries
1358 include_once './Services/LinkChecker/classes/class.ilLinkCheckNotify.php';
1360
1361 // Delete crs entries
1362 include_once './Modules/Course/classes/class.ilObjCourse.php';
1364
1365 // Delete user tracking
1366 include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1368
1369 include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1371
1372 // Delete Tracking data SCORM 2004 RTE
1373 include_once 'Modules/Scorm2004/classes/ilSCORM13Package.php';
1375
1376 // Delete Tracking data SCORM 1.2 RTE
1377 include_once 'Modules/ScormAicc/classes/class.ilObjSCORMLearningModule.php';
1379
1380 // remove all notifications
1381 include_once "./Services/Notification/classes/class.ilNotification.php";
1383
1384 // remove portfolios
1385 include_once "./Modules/Portfolio/classes/class.ilObjPortfolio.php";
1387
1388 // remove workspace
1389 include_once "./Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
1390 $tree = new ilWorkspaceTree($this->getId());
1391 $tree->cascadingDelete();
1392
1393 // remove disk quota entries
1394 include_once "./Services/DiskQuota/classes/class.ilDiskQuotaHandler.php";
1396
1397 // remove reminder entries
1398 require_once 'Services/User/classes/class.ilCronDeleteInactiveUserReminderMail.php';
1400
1401 // Delete user defined field entries
1403
1404 // Delete clipboard entries
1405 $this->clipboardDeleteAll();
1406
1407 // Reset owner
1408 $this->resetOwner();
1409
1410 include_once 'Services/Contact/classes/class.ilAddressbook.php';
1411 ilAddressbook::onUserDeletion($this);
1412
1413 // Trigger deleteUser Event
1414 global $ilAppEventHandler;
1415 $ilAppEventHandler->raise(
1416 'Services/User', 'deleteUser', array('usr_id' => $this->getId())
1417 );
1418
1419 // delete object data
1420 parent::delete();
1421 return true;
1422 }
1423
1433 function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1434 {
1435 $this->fullname = "";
1436
1437 if ($a_title)
1438 {
1439 $fullname = $a_title." ";
1440 }
1441 elseif ($this->utitle)
1442 {
1443 $this->fullname = $this->utitle." ";
1444 }
1445
1446 if ($a_firstname)
1447 {
1448 $fullname .= $a_firstname." ";
1449 }
1450 elseif ($this->firstname)
1451 {
1452 $this->fullname .= $this->firstname." ";
1453 }
1454
1455 if ($a_lastname)
1456 {
1457 return $fullname.$a_lastname;
1458 }
1459
1460 $this->fullname .= $this->lastname;
1461 }
1462
1477 function getFullname($a_max_strlen = 0)
1478 {
1479 if (!$a_max_strlen)
1480 {
1481 return ilUtil::stripSlashes($this->fullname);
1482 }
1483
1484 if (strlen($this->fullname) <= $a_max_strlen)
1485 {
1486 return ilUtil::stripSlashes($this->fullname);
1487 }
1488
1489 if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1490 {
1491 return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1492 }
1493
1494 if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1495 {
1496 return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1497 }
1498
1499 if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1500 {
1501 return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1502 }
1503
1504 return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1505 }
1506
1510 function hasAcceptedUserAgreement()
1511 {
1515 global $rbacreview;
1516
1517 if(
1518 null != $this->agree_date ||
1519 'root' == $this->login ||
1520 in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID)) ||
1521 $rbacreview->isAssigned($this->getId(), SYSTEM_ROLE_ID)
1522 )
1523 {
1524 return true;
1525 }
1526 return false;
1527 }
1528
1534 function setLogin($a_str)
1535 {
1536 $this->login = $a_str;
1537 }
1538
1543 function getLogin()
1544 {
1545 return $this->login;
1546 }
1547
1553 function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1554 {
1555 $this->passwd = $a_str;
1556 $this->passwd_type = $a_type;
1557 }
1558
1566 function getPasswd()
1567 {
1568 return $this->passwd;
1569 }
1576 function getPasswdType()
1577 {
1578 return $this->passwd_type;
1579 }
1580
1586 function setGender($a_str)
1587 {
1588 $this->gender = substr($a_str,-1);
1589 }
1590
1595 function getGender()
1596 {
1597 return $this->gender;
1598 }
1599
1607 function setUTitle($a_str)
1608 {
1609 $this->utitle = $a_str;
1610 }
1611
1618 function getUTitle()
1619 {
1620 return $this->utitle;
1621 }
1622
1628 function setFirstname($a_str)
1629 {
1630 $this->firstname = $a_str;
1631 }
1632
1637 function getFirstname()
1638 {
1639 return $this->firstname;
1640 }
1641
1647 function setLastname($a_str)
1648 {
1649 $this->lastname = $a_str;
1650 }
1651
1656 function getLastname()
1657 {
1658 return $this->lastname;
1659 }
1660
1666 function setInstitution($a_str)
1667 {
1668 $this->institution = $a_str;
1669 }
1670
1676 {
1677 return $this->institution;
1678 }
1679
1685 function setDepartment($a_str)
1686 {
1687 $this->department = $a_str;
1688 }
1689
1694 function getDepartment()
1695 {
1696 return $this->department;
1697 }
1698
1704 function setStreet($a_str)
1705 {
1706 $this->street = $a_str;
1707 }
1708
1713 function getStreet()
1714 {
1715 return $this->street;
1716 }
1717
1723 function setCity($a_str)
1724 {
1725 $this->city = $a_str;
1726 }
1727
1732 function getCity()
1733 {
1734 return $this->city;
1735 }
1736
1742 function setZipcode($a_str)
1743 {
1744 $this->zipcode = $a_str;
1745 }
1746
1751 function getZipcode()
1752 {
1753 return $this->zipcode;
1754 }
1755
1762 function setCountry($a_str)
1763 {
1764 $this->country = $a_str;
1765 }
1766
1772 function getCountry()
1773 {
1774 return $this->country;
1775 }
1776
1782 function setSelectedCountry($a_val)
1783 {
1784 $this->sel_country = $a_val;
1785 }
1786
1793 {
1794 return $this->sel_country;
1795 }
1796
1802 function setPhoneOffice($a_str)
1803 {
1804 $this->phone_office = $a_str;
1805 }
1806
1812 {
1813 return $this->phone_office;
1814 }
1815
1821 function setPhoneHome($a_str)
1822 {
1823 $this->phone_home = $a_str;
1824 }
1825
1830 function getPhoneHome()
1831 {
1832 return $this->phone_home;
1833 }
1834
1840 function setPhoneMobile($a_str)
1841 {
1842 $this->phone_mobile = $a_str;
1843 }
1844
1850 {
1851 return $this->phone_mobile;
1852 }
1853
1859 function setFax($a_str)
1860 {
1861 $this->fax = $a_str;
1862 }
1863
1868 function getFax()
1869 {
1870 return $this->fax;
1871 }
1872
1878 function setClientIP($a_str)
1879 {
1880 $this->client_ip = $a_str;
1881 }
1882
1887 function getClientIP()
1888 {
1889 return $this->client_ip;
1890 }
1891
1897 function setMatriculation($a_str)
1898 {
1899 $this->matriculation = $a_str;
1900 }
1901
1907 {
1908 return $this->matriculation;
1909 }
1910
1917 public static function lookupMatriculation($a_usr_id)
1918 {
1919 global $ilDB;
1920
1921 $query = "SELECT matriculation FROM usr_data ".
1922 "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1923 $res = $ilDB->query($query);
1924 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1925 return $row->matriculation ? $row->matriculation : '';
1926 }
1927
1933 function setEmail($a_str)
1934 {
1935 $this->email = $a_str;
1936 }
1937
1942 function getEmail()
1943 {
1944 return $this->email;
1945 }
1946
1952 function setHobby($a_str)
1953 {
1954 $this->hobby = $a_str;
1955 }
1956
1961 function getHobby()
1962 {
1963 return $this->hobby;
1964 }
1965
1971 function setLanguage($a_str)
1972 {
1973 $this->setPref("language",$a_str);
1974 unset($_SESSION['lang']);
1975 }
1976
1982 function getLanguage()
1983 {
1984 return $this->prefs["language"];
1985 }
1986
1995 function setDiskQuota($a_disk_quota)
1996 {
1997 $this->setPref("disk_quota",$a_disk_quota);
1998 }
1999
2009 function getDiskQuota()
2010 {
2011 return $this->prefs["disk_quota"] ? $this->prefs["disk_quota"] : 0;
2012 }
2013
2015 {
2016 return $this->prefs["wsp_disk_quota"] ? $this->prefs["wsp_disk_quota"] : 0;
2017 }
2018
2019 public function setLastPasswordChangeTS($a_last_password_change_ts)
2020 {
2021 $this->last_password_change_ts = $a_last_password_change_ts;
2022 }
2023
2024 public function getLastPasswordChangeTS()
2025 {
2027 }
2028
2029
2030 public static function _lookupLanguage($a_usr_id)
2031 {
2032 global $ilDB;
2033
2034 $q = "SELECT value FROM usr_pref WHERE usr_id= ".
2035 $ilDB->quote($a_usr_id, "integer")." AND keyword = ".
2036 $ilDB->quote('language', "text");
2037 $r = $ilDB->query($q);
2038
2039 while($row = $ilDB->fetchAssoc($r))
2040 {
2041 return $row['value'];
2042 }
2043 return 'en';
2044 }
2045
2046 function _writeExternalAccount($a_usr_id, $a_ext_id)
2047 {
2048 global $ilDB;
2049
2050 $ilDB->manipulateF("UPDATE usr_data ".
2051 " SET ext_account = %s WHERE usr_id = %s",
2052 array("text", "integer"),
2053 array($a_ext_id, $a_usr_id));
2054 }
2055
2056 function _writeAuthMode($a_usr_id, $a_auth_mode)
2057 {
2058 global $ilDB;
2059
2060 $ilDB->manipulateF("UPDATE usr_data ".
2061 " SET auth_mode = %s WHERE usr_id = %s",
2062 array("text", "integer"),
2063 array($a_auth_mode, $a_usr_id));
2064 }
2065
2071 {
2072 return $_SESSION['lang'];
2073 }
2074
2080 function setCurrentLanguage($a_val)
2081 {
2082 $_SESSION['lang'] = $a_val;
2083 }
2084
2090 function setLastLogin($a_str)
2091 {
2092 $this->last_login = $a_str;
2093 }
2094
2100 function getLastLogin()
2101 {
2102 return $this->last_login;
2103 }
2104
2110 function setLastUpdate($a_str)
2111 {
2112 $this->last_update = $a_str;
2113 }
2114 function getLastUpdate()
2115 {
2116 return $this->last_update;
2117 }
2118
2124 function setComment($a_str)
2125 {
2126 $this->referral_comment = $a_str;
2127 }
2128
2133 function getComment()
2134 {
2136 }
2137
2144 function setApproveDate($a_str)
2145 {
2146 $this->approve_date = $a_str;
2147 }
2148
2155 {
2156 return $this->approve_date;
2157 }
2158
2159 // BEGIN DiskQuota: show when user accepted user agreement
2165 function getAgreeDate()
2166 {
2167 return $this->agree_date;
2168 }
2175 function setAgreeDate($a_str)
2176 {
2177 $this->agree_date = $a_str;
2178 }
2179 // END DiskQuota: show when user accepted user agreement
2180
2187 function setActive($a_active, $a_owner = 0)
2188 {
2189 $this->setOwner($a_owner);
2190
2191 if ($a_active)
2192 {
2193 $this->active = 1;
2194 $this->setApproveDate(date('Y-m-d H:i:s'));
2195 $this->setOwner($a_owner);
2196 }
2197 else
2198 {
2199 $this->active = 0;
2200 $this->setApproveDate(null);
2201 }
2202 }
2203
2208 function getActive()
2209 {
2210 return $this->active;
2211 }
2212
2216 public function _lookupActive($a_usr_id)
2217 {
2218 global $ilDB;
2219
2220 $query = 'SELECT usr_id FROM usr_data '.
2221 'WHERE active = '.$ilDB->quote(1,'integer').' '.
2222 'AND usr_id = '.$ilDB->quote($a_usr_id,'integer');
2223 $res = $ilDB->query($query);
2224 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2225 {
2226 return true;
2227 }
2228 return false;
2229 }
2230
2236 function syncActive()
2237 {
2238 global $ilAuth;
2239
2240 $storedActive = 0;
2241 if ($this->getStoredActive($this->id))
2242 {
2243 $storedActive = 1;
2244 }
2245
2246 $currentActive = 0;
2247 if ($this->active)
2248 {
2249 $currentActive = 1;
2250 }
2251
2252 if ((!empty($storedActive) && empty($currentActive)) ||
2253 (empty($storedActive) && !empty($currentActive)))
2254 {
2255 $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2256 }
2257 }
2258
2265 function getStoredActive($a_id)
2266 {
2267 $active = ilObjUser::_lookup($a_id, "active");
2268 return $active ? true : false;
2269 }
2270
2276 function setSkin($a_str)
2277 {
2278 // TODO: exception handling (dir exists)
2279 $this->skin = $a_str;
2280 }
2281
2282 function setTimeLimitOwner($a_owner)
2283 {
2284 $this->time_limit_owner = $a_owner;
2285 }
2287 {
2288 return $this->time_limit_owner ? $this->time_limit_owner : 7;
2289 }
2290 function setTimeLimitFrom($a_from)
2291 {
2292 $this->time_limit_from = $a_from;
2293 }
2295 {
2296 return $this->time_limit_from ? $this->time_limit_from : time();
2297 }
2298 function setTimeLimitUntil($a_until)
2299 {
2300 $this->time_limit_until = $a_until;
2301 }
2303 {
2304 return $this->time_limit_until ? $this->time_limit_until : time();
2305 }
2306 function setTimeLimitUnlimited($a_unlimited)
2307 {
2308 $this->time_limit_unlimited = $a_unlimited;
2309 }
2311 {
2312 return $this->time_limit_unlimited;
2313 }
2314 function setTimeLimitMessage($a_time_limit_message)
2315 {
2316 return $this->time_limit_message = $a_time_limit_message;
2317 }
2319 {
2320 return $this->time_limit_message;
2321 }
2322
2323 public function setLoginAttempts($a_login_attempts)
2324 {
2325 $this->login_attempts = $a_login_attempts;
2326 }
2327
2328 public function getLoginAttempts()
2329 {
2330 return $this->login_attempts;
2331 }
2332
2333
2335 {
2336 if($this->getTimeLimitUnlimited())
2337 {
2338 return true;
2339 }
2340 if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2341 {
2342 return true;
2343 }
2344 return false;
2345 }
2346 function setProfileIncomplete($a_prof_inc)
2347 {
2348 $this->profile_incomplete = (boolean) $a_prof_inc;
2349 }
2351 {
2352 if($this->id == ANONYMOUS_USER_ID)
2353 {
2354 return false;
2355 }
2356 return $this->profile_incomplete;
2357 }
2358
2360 {
2361 //error_reporting(E_ALL);
2362 if( $this->id == ANONYMOUS_USER_ID || $this->id == SYSTEM_USER_ID )
2363 return false;
2364
2365 require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2367
2369 && $security->isPasswordChangeOnFirstLoginEnabled()
2370 && $this->getLastPasswordChangeTS() == 0
2371 && $this->is_self_registered == false
2372 ){
2373 return true;
2374 }
2375 else return false;
2376 }
2377
2378 public function isPasswordExpired()
2379 {
2380 //error_reporting(E_ALL);
2381 if($this->id == ANONYMOUS_USER_ID) return false;
2382
2383 require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2385 if( $this->getLastPasswordChangeTS() > 0 )
2386 {
2387 $max_pass_age = $security->getPasswordMaxAge();
2388 if( $max_pass_age > 0 )
2389 {
2390 $max_pass_age_ts = ( $max_pass_age * 86400 );
2391 $pass_change_ts = $this->getLastPasswordChangeTS();
2392 $current_ts = time();
2393
2394 if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2395 return true;
2396 }
2397 }
2398 return false;
2399 }
2400
2401 public function getPasswordAge()
2402 {
2403 $current_ts = time();
2404 $pass_change_ts = $this->getLastPasswordChangeTS();
2405 $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2406 return $password_age;
2407 }
2408
2410 {
2411 global $ilDB;
2412
2413 $this->setLastPasswordChangeTS( time() );
2414
2415 $query = "UPDATE usr_data SET last_password_change = %s " .
2416 "WHERE usr_id = %s";
2417 $affected = $ilDB->manipulateF($query,
2418 array('integer','integer'),
2419 array($this->getLastPasswordChangeTS(),$this->id));
2420 if($affected) return true;
2421 else return false;
2422 }
2423
2424 public function resetLastPasswordChange()
2425 {
2426 global $ilDB;
2427
2428 $query = "UPDATE usr_data SET last_password_change = 0 " .
2429 "WHERE usr_id = %s";
2430 $affected = $ilDB->manipulateF( $query, array('integer'),
2431 array($this->getId()) );
2432 if($affected) return true;
2433 else return false;
2434 }
2435
2441 function setLatitude($a_latitude)
2442 {
2443 $this->latitude = $a_latitude;
2444 }
2445
2451 function getLatitude()
2452 {
2453 return $this->latitude;
2454 }
2455
2461 function setLongitude($a_longitude)
2462 {
2463 $this->longitude = $a_longitude;
2464 }
2465
2471 function getLongitude()
2472 {
2473 return $this->longitude;
2474 }
2475
2481 function setLocationZoom($a_locationzoom)
2482 {
2483 $this->loc_zoom = $a_locationzoom;
2484 }
2485
2492 {
2493 return $this->loc_zoom;
2494 }
2495
2497 {
2498 $this->applied_users = array();
2499 $this->__readAppliedUsers($this->getId());
2500
2501 return $this->applied_users ? $this->applied_users : array();
2502 }
2503
2504 function isChild($a_usr_id)
2505 {
2506 if($a_usr_id == $this->getId())
2507 {
2508 return true;
2509 }
2510
2511 $this->applied_users = array();
2512 $this->__readAppliedUsers($this->getId());
2513
2514 return in_array($a_usr_id,$this->applied_users);
2515 }
2516
2517 function __readAppliedUsers($a_parent_id)
2518 {
2519 global $ilDB;
2520
2521 $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2522 "WHERE time_limit_owner = %s",
2523 array("integer"),
2524 array($a_parent_id));
2525 while ($row = $ilDB->fetchObject($res))
2526 {
2527 $this->applied_users[] = $row->usr_id;
2528
2529 // recursion
2530 $this->__readAppliedUsers($row->usr_id);
2531 }
2532 return true;
2533 }
2534
2540 static function hasActiveSession($a_user_id)
2541 {
2542 global $ilDB;
2543
2544 $set = $ilDB->queryf('
2545 SELECT COUNT(*) session_count
2546 FROM usr_session WHERE user_id = %s AND expires > %s',
2547 array('integer', 'integer'),
2548 array($a_user_id, time()));
2549 $row = $ilDB->fetchAssoc($set);
2550 return (bool)$row['session_count'];
2551 }
2552
2553 /*
2554 * check user id with login name
2555 * @access public
2556 */
2557 function checkUserId()
2558 {
2559 global $ilAuth, $ilSetting;
2560
2563 if ($id > 0)
2564 {
2565 return $id;
2566 }
2567 return false;
2568 }
2569
2573 private static function getLoginFromAuth() {
2574 global $ilAuth;
2575
2576 // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2577 require_once ('Services/WebDAV/classes/class.ilDAVActivationChecker.php');
2579 {
2580 require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2581 require_once ('Services/Database/classes/class.ilAuthContainerMDB2.php');
2582 $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2583 }
2584 else
2585 {
2586 $login =$ilAuth->getUsername();
2587 }
2588
2589 return $login;
2590 }
2591
2592 /*
2593 * check to see if current user has been made active
2594 * @access public
2595 * @return true if active, otherwise false
2596 */
2598 {
2599 global $ilDB,$ilAuth;
2600
2602 $set = $ilDB->queryF("SELECT active FROM usr_data WHERE login= %s",
2603 array("text"),
2604 array($login));
2605 //query has got a result
2606 if ($rec = $ilDB->fetchAssoc($set))
2607 {
2608 if ($rec["active"])
2609 {
2610 return true;
2611 }
2612 }
2613
2614 return false;
2615 }
2616
2617 /*
2618 * STATIC METHOD
2619 * get the user_id of a login name
2620 * @param string login name
2621 * @return integer id of user
2622 * @static
2623 * @access public
2624 */
2625 function getUserIdByLogin($a_login)
2626 {
2627 return (int) ilObjUser::_lookupId($a_login);
2628 }
2629
2638 function _getUserIdsByEmail($a_email)
2639 {
2640 global $ilias, $ilDB;
2641
2642 $res = $ilDB->queryF("SELECT login FROM usr_data ".
2643 "WHERE email = %s and active = 1",
2644 array("text"),
2645 array($a_email));
2646 $ids = array ();
2647 while($row = $ilDB->fetchObject($res))
2648 {
2649 $ids[] = $row->login;
2650 }
2651
2652 return $ids;
2653 }
2654
2655
2656
2665 function getUserIdByEmail($a_email)
2666 {
2667 global $ilDB;
2668
2669 $res = $ilDB->queryF("SELECT usr_id FROM usr_data ".
2670 "WHERE email = %s", array("text"), array($a_email));
2671
2672 $row = $ilDB->fetchObject($res);
2673 return $row->usr_id ? $row->usr_id : 0;
2674 }
2675
2676 /*
2677 * STATIC METHOD
2678 * get the login name of a user_id
2679 * @param integer id of user
2680 * @return string login name; false if not found
2681 * @static
2682 * @access public
2683 */
2684 function getLoginByUserId($a_userid)
2685 {
2686 $login = ilObjUser::_lookupLogin($a_userid);
2687 return $login ? $login : false;
2688 }
2689
2700 static function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2701 {
2702 global $ilias, $ilDB, $ilLog;
2703
2704
2705 $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ";
2706
2707 $without_anonymous_users = true;
2708
2709 // determine join filter
2710 $join_filter = " WHERE ";
2711 if ($filter_settings !== FALSE && strlen($filter_settings))
2712 {
2713 switch ($filter_settings)
2714 {
2715 case 3:
2716 // show only users without courses
2717 $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.usr_id IS NULL AND ";
2718 break;
2719 case 5:
2720 // show only users with a certain course membership
2721 $ref_id = $_SESSION["user_filter_data"];
2722 if ($ref_id)
2723 {
2724 $join_filter = " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id WHERE obj_members.obj_id = ".
2725 "(SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") AND ";
2726 }
2727 break;
2728 case 6:
2729 global $rbacreview;
2730 $ref_id = $_SESSION["user_filter_data"];
2731 if ($ref_id)
2732 {
2733 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
2734 if (is_array($local_roles) && count($local_roles))
2735 {
2736 $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2737 $ilDB->in("rbac_ua.rol_id", $local_roles, false, $local_roles)." AND ";
2738 }
2739 }
2740 break;
2741 case 7:
2742 global $rbacreview;
2743 $rol_id = $_SESSION["user_filter_data"];
2744 if ($rol_id)
2745 {
2746 $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2747 $ilDB->quote($rol_id, "integer")." AND ";
2748 $without_anonymous_users = false;
2749 }
2750 break;
2751 }
2752 }
2753 // This is a temporary hack to search users by their role
2754 // See Mantis #338. This is a hack due to Mantis #337.
2755 if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2756 {
2757 $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2758 "FROM object_data,rbac_ua,usr_data ".
2759 "WHERE ".$ilDB->like("object_data.title", "text", "%".substr($a_search_str,5)."%").
2760 " AND object_data.type = 'role' ".
2761 "AND rbac_ua.rol_id = object_data.obj_id ".
2762 "AND usr_data.usr_id = rbac_ua.usr_id ".
2763 "AND rbac_ua.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2764 }
2765 else
2766 {
2767 $query.= $join_filter.
2768 "(".$ilDB->like("usr_data.login", "text", "%".$a_search_str."%")." ".
2769 "OR ".$ilDB->like("usr_data.firstname", "text", "%".$a_search_str."%")." ".
2770 "OR ".$ilDB->like("usr_data.lastname", "text", "%".$a_search_str."%")." ".
2771 "OR ".$ilDB->like("usr_data.email", "text", "%".$a_search_str."%").") ";
2772
2773 if ($filter_settings !== FALSE && strlen($filter_settings))
2774 {
2775 switch ($filter_settings)
2776 {
2777 case 0:
2778 $query.= " AND usr_data.active = ".$ilDB->quote(0, "integer")." ";
2779 break;
2780 case 1:
2781 $query.= " AND usr_data.active = ".$ilDB->quote(1, "integer")." ";
2782 break;
2783 case 2:
2784 $query.= " AND usr_data.time_limit_unlimited = ".$ilDB->quote(0, "integer")." ";
2785 break;
2786 case 4:
2787 $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"]));
2788 $query.= " AND last_login < ".$ilDB->quote($date, "timestamp")." ";
2789 break;
2790 }
2791 }
2792
2793 if ($without_anonymous_users)
2794 {
2795 $query.= "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID, "integer");
2796 }
2797
2798 if (is_numeric($active) && $active > -1 && $filter_settings === FALSE)
2799 {
2800 $query.= " AND active = ".$ilDB->quote($active, "integer")." ";
2801 }
2802
2803 }
2804 $ilLog->write($query);
2805 $res = $ilDB->query($query);
2806 while ($row = $ilDB->fetchObject($res))
2807 {
2808 $users[] = array(
2809 "usr_id" => $row->usr_id,
2810 "login" => $row->login,
2811 "firstname" => $row->firstname,
2812 "lastname" => $row->lastname,
2813 "email" => $row->email,
2814 "active" => $row->active);
2815 $ids[] = $row->usr_id;
2816 }
2817 if ($a_return_ids_only)
2818 return $ids ? $ids : array();
2819 else
2820 return $users ? $users : array();
2821 }
2822
2832 {
2833 global $ilDB;
2834
2835 $res = $ilDB->query("SELECT login FROM usr_data");
2836 while($row = $ilDB->fetchObject($res))
2837 {
2838 $logins[] = $row->login;
2839 }
2840 return $logins ? $logins : array();
2841 }
2842
2851 public static function _readUsersProfileData($a_user_ids)
2852 {
2853 global $ilDB;
2854 $res = $ilDB->query("SELECT * FROM usr_data WHERE ".
2855 $ilDB->in("usr_id", $a_user_ids, false, "integer"));
2856 while ($row = $ilDB->fetchAssoc($res))
2857 {
2858 $user_data["$row[usr_id]"] = $row;
2859 }
2860 return $user_data ? $user_data : array();
2861 }
2862
2871 function _getAllUserData($a_fields = NULL, $active =-1)
2872 {
2873 global $ilDB;
2874
2875 $result_arr = array();
2876 $types = array();
2877 $values = array();
2878
2879 if ($a_fields !== NULL and is_array($a_fields))
2880 {
2881 if (count($a_fields) == 0)
2882 {
2883 $select = "*";
2884 }
2885 else
2886 {
2887 if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2888 unset($a_fields[$usr_id_field]);
2889
2890 $select = implode(",",$a_fields).",usr_data.usr_id";
2891 // online time
2892 if(in_array('online_time',$a_fields))
2893 {
2894 $select .= ",ut_online.online_time ";
2895 }
2896 }
2897
2898 $q = "SELECT ".$select." FROM usr_data ";
2899
2900 // Add online_time if desired
2901 // Need left join here to show users that never logged in
2902 if(in_array('online_time',$a_fields))
2903 {
2904 $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2905 }
2906
2907 switch ($active)
2908 {
2909 case 0:
2910 case 1:
2911 $q .= "WHERE active = ".$ilDB->quote($active, "integer");
2912 break;
2913 case 2:
2914 $q .= "WHERE time_limit_unlimited= ".$ilDB->quote(0, "integer");;
2915 break;
2916 case 3:
2917 $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND ".
2918 $ilDB->like("object_data.title", "text", "%crs%")." AND usr_data.usr_id = rbac_ua.usr_id";
2919 $r = $ilDB->query($qtemp);
2920 $course_users = array();
2921 while ($row = $ilDB->fetchAssoc($r))
2922 {
2923 array_push($course_users, $row["usr_id"]);
2924 }
2925 if (count($course_users))
2926 {
2927 $q .= " WHERE ".$ilDB->in("usr_data.usr_id", $course_users, true, "integer")." ";
2928 }
2929 else
2930 {
2931 return $result_arr;
2932 }
2933 break;
2934 case 4:
2935 $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"]));
2936 $q.= " AND last_login < ".$ilDB->quote($date, "timestamp");
2937 break;
2938 case 5:
2939 $ref_id = $_SESSION["user_filter_data"];
2940 if ($ref_id)
2941 {
2942 $q .= " LEFT JOIN obj_members ON usr_data.usr_id = obj_members.usr_id ".
2943 "WHERE obj_members.obj_id = (SELECT obj_id FROM object_reference ".
2944 "WHERE ref_id = ".$ilDB->quote($ref_id, "integer").") ";
2945 }
2946 break;
2947 case 6:
2948 global $rbacreview;
2949 $ref_id = $_SESSION["user_filter_data"];
2950 if ($ref_id)
2951 {
2952 $local_roles = $rbacreview->getRolesOfRoleFolder($ref_id,false);
2953 if (is_array($local_roles) && count($local_roles))
2954 {
2955 $q.= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE ".
2956 $ilDB->in("rbac_ua.rol_id", $local_roles, false, "integer")." ";
2957 }
2958 }
2959 break;
2960 case 7:
2961 $rol_id = $_SESSION["user_filter_data"];
2962 if ($rol_id)
2963 {
2964 $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = ".
2965 $ilDB->quote($rol_id, "integer");
2966 }
2967 break;
2968 }
2969 $r = $ilDB->query($q);
2970
2971 while ($row = $ilDB->fetchAssoc($r))
2972 {
2973 $result_arr[] = $row;
2974 }
2975 }
2976
2977 return $result_arr;
2978 }
2979
2983 function _getNumberOfUsersForStyle($a_skin, $a_style)
2984 {
2985 global $ilDB;
2986
2987 $q = "SELECT count(*) as cnt FROM usr_pref up1, usr_pref up2 ".
2988 " WHERE up1.keyword= ".$ilDB->quote("style", "text").
2989 " AND up1.value= ".$ilDB->quote($a_style, "text").
2990 " AND up2.keyword= ".$ilDB->quote("skin", "text").
2991 " AND up2.value= ".$ilDB->quote($a_skin, "text").
2992 " AND up1.usr_id = up2.usr_id ";
2993
2994 $cnt_set = $ilDB->query($q);
2995
2996 $cnt_rec = $ilDB->fetchAssoc($cnt_set);
2997
2998 return $cnt_rec["cnt"];
2999 }
3000
3005 {
3006 global $ilDB;
3007
3008 $q = "SELECT DISTINCT up1.value style, up2.value skin FROM usr_pref up1, usr_pref up2 ".
3009 " WHERE up1.keyword = ".$ilDB->quote("style", "text").
3010 " AND up2.keyword = ".$ilDB->quote("skin", "text").
3011 " AND up1.usr_id = up2.usr_id";
3012
3013 $sty_set = $ilDB->query($q);
3014
3015 $styles = array();
3016 while($sty_rec = $ilDB->fetchAssoc($sty_set))
3017 {
3018 $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
3019 }
3020
3021 return $styles;
3022 }
3023
3027 function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3028 {
3029 global $ilDB;
3030
3031 $q = "SELECT up1.usr_id usr_id FROM usr_pref up1, usr_pref up2 ".
3032 " WHERE up1.keyword= ".$ilDB->quote("style", "text").
3033 " AND up1.value= ".$ilDB->quote($a_from_style, "text").
3034 " AND up2.keyword= ".$ilDB->quote("skin", "text").
3035 " AND up2.value= ".$ilDB->quote($a_from_skin, "text").
3036 " AND up1.usr_id = up2.usr_id ";
3037
3038 $usr_set = $ilDB->query($q);
3039
3040 while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3041 {
3042 self::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3043 self::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3044 }
3045 }
3046
3047
3057 public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3058 {
3059 global $ilDB;
3060
3061 $item_set = $ilDB->queryF("SELECT * FROM desktop_item WHERE ".
3062 "item_id = %s AND type = %s AND user_id = %s",
3063 array("integer", "text", "integer"),
3064 array($a_item_id, $a_type, $a_usr_id));
3065
3066 // only insert if item is not already on desktop
3067 if (!$ilDB->fetchAssoc($item_set))
3068 {
3069 $ilDB->manipulateF("INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3070 " (%s,%s,%s,%s)", array("integer", "text", "integer", "text"),
3071 array($a_item_id,$a_type,$a_usr_id,$a_par));
3072 }
3073
3074 include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3076 }
3077
3085 function addDesktopItem($a_item_id, $a_type, $a_par = "")
3086 {
3087 ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3088 }
3089
3098 function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3099 {
3100 global $ilDB;
3101
3102 $ilDB->manipulateF("UPDATE desktop_item SET parameters = %s ".
3103 " WHERE item_id = %s AND type = %s AND user_id = %s",
3104 array("text", "integer", "text", "integer"),
3105 array($a_par, $a_item_id, $a_type, $this->getId()));
3106 }
3107
3108
3118 public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3119 {
3120 global $ilDB;
3121
3122 $ilDB->manipulateF("DELETE FROM desktop_item WHERE ".
3123 " item_id = %s AND type = %s AND user_id = %s",
3124 array("integer", "text", "integer"),
3125 array($a_item_id, $a_type, $a_usr_id));
3126
3127 include_once './Services/Calendar/classes/class.ilCalendarCategories.php';
3129 }
3130
3138 function dropDesktopItem($a_item_id, $a_type)
3139 {
3140 ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3141 }
3142
3149 static function _removeItemFromDesktops($a_id)
3150 {
3151 global $ilDB;
3152
3153 $r = $ilDB->queryF("SELECT user_id FROM desktop_item WHERE item_id = %s",
3154 array("integer"), array($a_id));
3155
3156 $users = array();
3157
3158 while ($row = $ilDB->fetchObject($r))
3159 {
3160 $users[] = $row->user_id;
3161 } // while
3162
3163 if (count($users) > 0)
3164 {
3165 $ilDB->manipulateF("DELETE FROM desktop_item WHERE item_id = %s",
3166 array("integer"), array($a_id));
3167 }
3168
3169 return $users;
3170 }
3171
3181 public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3182 {
3183 global $ilDB;
3184
3185 if (self::$is_desktop_item_loaded[$a_usr_id.":".$a_item_id])
3186 {
3187 return self::$is_desktop_item_cache[$a_usr_id.":".$a_item_id.":".$a_type];
3188 }
3189 $item_set = $ilDB->queryF("SELECT item_id FROM desktop_item WHERE ".
3190 "item_id = %s AND type = %s AND user_id = %s",
3191 array("integer", "text", "integer"),
3192 array($a_item_id, $a_type, $a_usr_id));
3193
3194 if ($ilDB->fetchAssoc($item_set))
3195 {
3196 return true;
3197 }
3198 else
3199 {
3200 return false;
3201 }
3202 }
3203
3210 static function preloadIsDesktopItem($a_usr_id, $a_item_ids)
3211 {
3212 global $ilDB;
3213
3214 if (!is_array($a_item_ids))
3215 {
3216 return;
3217 }
3218
3219 $item_ids = array();
3220 foreach ($a_item_ids as $id)
3221 {
3222 if (!self::$is_desktop_item_loaded[$a_usr_id.":".$id])
3223 {
3224 $item_ids[] = $id;
3225 }
3226 self::$is_desktop_item_loaded[$a_usr_id.":".$id] = true;
3227 }
3228
3229 if (count($item_ids) > 0)
3230 {
3231 $item_set = $ilDB->query("SELECT item_id, type FROM desktop_item WHERE ".
3232 $ilDB->in("item_id", $item_ids, false, "integer").
3233 " AND user_id = ".$ilDB->quote($a_usr_id, "integer"));
3234 while ($r = $ilDB->fetchAssoc($item_set))
3235 {
3236 self::$is_desktop_item_cache[$a_usr_id.":".$r["item_id"].":".$r["type"]]
3237 = true;
3238 }
3239 }
3240 }
3241
3249 function isDesktopItem($a_item_id, $a_type)
3250 {
3251 return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3252 }
3253
3254 function getDesktopItems($a_types = "")
3255 {
3256 return $this->_lookupDesktopItems($this->getId(), $a_types);
3257 }
3258
3265 static function _lookupDesktopItems($user_id, $a_types = "")
3266 {
3267 global $ilUser, $rbacsystem, $tree, $ilDB;
3268
3269 if ($a_types == "")
3270 {
3271 $is_nested_set = ($tree->getTreeImplementation() instanceof ilNestedSetTree);
3272
3273 $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3274 " FROM desktop_item it, object_reference oref ".
3275 ", object_data obj".
3276 " WHERE ".
3277 "it.item_id = oref.ref_id AND ".
3278 "oref.obj_id = obj.obj_id AND ".
3279 "it.user_id = %s", array("integer"), array($user_id));
3280 $items = $all_parent_path = array();
3281 while ($item_rec = $ilDB->fetchAssoc($item_set))
3282 {
3283 if ($tree->isInTree($item_rec["ref_id"])
3284 && $item_rec["type"] != "rolf"
3285 && $item_rec["type"] != "itgr") // due to bug 11508
3286 {
3287 $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3288
3289 if(!isset($all_parent_path[$parent_ref]))
3290 {
3291 // #15746
3292 //if($is_nested_set)
3293 //{
3294 // $par_left = $tree->getLeftValue($parent_ref);
3295 // $all_parent_path[$parent_ref] = sprintf("%010d", $par_left);
3296 //}
3297 //else
3298 //{
3299 $node = $tree->getNodeData($parent_ref);
3300 $all_parent_path[$parent_ref] = $node["title"];
3301 //}
3302 }
3303
3304 $parent_path = $all_parent_path[$parent_ref];
3305
3306 $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3307 $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3308 $items[$parent_path.$title.$item_rec["ref_id"]] =
3309 array("ref_id" => $item_rec["ref_id"],
3310 "obj_id" => $item_rec["obj_id"],
3311 "type" => $item_rec["type"],
3312 "title" => $title,
3313 "description" => $desc,
3314 "parent_ref" => $parent_ref);
3315 }
3316 }
3317 ksort($items);
3318 }
3319 else
3320 {
3321 // due to bug 11508
3322 if (!is_array($a_types))
3323 {
3324 $a_types = array($a_types);
3325 }
3326 $items = array();
3327 $foundsurveys = array();
3328 foreach($a_types as $a_type)
3329 {
3330 if ($a_type == "itgr")
3331 {
3332 continue;
3333 }
3334 $item_set = $ilDB->queryF("SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item it, object_reference oref ".
3335 ", object_data obj WHERE ".
3336 "it.item_id = oref.ref_id AND ".
3337 "oref.obj_id = obj.obj_id AND ".
3338 "it.type = %s AND ".
3339 "it.user_id = %s ".
3340 "ORDER BY title",
3341 array("text", "integer"),
3342 array($a_type, $user_id));
3343
3344 while ($item_rec = $ilDB->fetchAssoc($item_set))
3345 {
3346 $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3347 $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3348 $items[$title.$a_type.$item_rec["ref_id"]] =
3349 array("ref_id" => $item_rec["ref_id"],
3350 "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3351 "title" => $title, "description" => $desc);
3352 }
3353
3354 }
3355 ksort($items);
3356 }
3357
3358 return $items;
3359 }
3360
3366
3374 function addObjectToClipboard($a_item_id, $a_type, $a_title,
3375 $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3376 {
3377 global $ilDB;
3378
3379 if ($a_time == 0)
3380 {
3381 $a_time = date("Y-m-d H:i:s", time());
3382 }
3383
3384 $item_set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3385 "parent = %s AND item_id = %s AND type = %s AND user_id = %s",
3386 array("integer", "integer", "text", "integer"),
3387 array(0, $a_item_id, $a_type, $this->getId()));
3388
3389 // only insert if item is not already in clipboard
3390 if (!$d = $item_set->fetchRow())
3391 {
3392 $ilDB->manipulateF("INSERT INTO personal_clipboard ".
3393 "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3394 " (%s,%s,%s,%s,%s,%s,%s)",
3395 array("integer", "text", "integer", "text", "integer", "timestamp", "integer"),
3396 array($a_item_id, $a_type, $this->getId(), $a_title, (int) $a_parent, $a_time, (int) $a_order_nr));
3397 }
3398 else
3399 {
3400 $ilDB->manipulateF("UPDATE personal_clipboard SET insert_time = %s ".
3401 "WHERE user_id = %s AND item_id = %s AND type = %s AND parent = 0",
3402 array("timestamp", "integer", "integer", "text"),
3403 array($a_time, $this->getId(), $a_item_id, $a_type));
3404 }
3405 }
3406
3410 function addToPCClipboard($a_content, $a_time, $a_nr)
3411 {
3412 global $ilDB;
3413 if ($a_time == 0)
3414 {
3415 $a_time = date("Y-m-d H:i:s", time());
3416 }
3417 $ilDB->insert("personal_pc_clipboard", array(
3418 "user_id" => array("integer", $this->getId()),
3419 "content" => array("clob", $a_content),
3420 "insert_time" => array("timestamp", $a_time),
3421 "order_nr" => array("integer", $a_nr)
3422 ));
3423 }
3424
3429 {
3430 global $ilDB;
3431
3432 $set = $ilDB->queryF("SELECT MAX(insert_time) mtime FROM personal_pc_clipboard ".
3433 " WHERE user_id = %s", array("integer"), array($this->getId()));
3434 $row = $ilDB->fetchAssoc($set);
3435
3436 $set = $ilDB->queryF("SELECT * FROM personal_pc_clipboard ".
3437 " WHERE user_id = %s AND insert_time = %s ORDER BY order_nr ASC",
3438 array("integer", "timestamp"),
3439 array($this->getId(), $row["mtime"]));
3440 $content = array();
3441 while ($row = $ilDB->fetchAssoc($set))
3442 {
3443 $content[] = $row["content"];
3444 }
3445
3446 return $content;
3447 }
3448
3453 {
3454 global $ilDB;
3455
3456 $set = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3457 "parent = %s AND type = %s AND user_id = %s",
3458 array("integer", "text", "integer"),
3459 array(0, $a_type, $this->getId()));
3460 if ($rec = $ilDB->fetchAssoc($set))
3461 {
3462 return true;
3463 }
3464
3465 return false;
3466 }
3467
3472 {
3473 global $ilDB;
3474
3475 $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3476 "type = %s AND user_id = %s",
3477 array("text", "integer"),
3478 array($a_type, $this->getId()));
3479 }
3480
3485 {
3486 global $ilDB;
3487
3488 $ilDB->manipulateF("DELETE FROM personal_clipboard WHERE ".
3489 "user_id = %s", array("integer"), array($this->getId()));
3490 }
3491
3495 function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3496 {
3497 global $ilDB;
3498
3499 $par = "";
3500 if ($a_top_nodes_only)
3501 {
3502 $par = " AND parent = ".$ilDB->quote(0, "integer")." ";
3503 }
3504
3505 $type_str = ($a_type != "")
3506 ? " AND type = ".$ilDB->quote($a_type, "text")." "
3507 : "";
3508 $q = "SELECT * FROM personal_clipboard WHERE ".
3509 "user_id = ".$ilDB->quote($this->getId(), "integer")." ".
3510 $type_str.$par.
3511 " ORDER BY order_nr";
3512 $objs = $ilDB->query($q);
3513 $objects = array();
3514 while ($obj = $ilDB->fetchAssoc($objs))
3515 {
3516 if ($obj["type"] == "mob")
3517 {
3518 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3519 }
3520 if ($obj["type"] == "incl")
3521 {
3522 include_once("./Modules/MediaPool/classes/class.ilMediaPoolPage.php");
3523 $obj["title"] = ilMediaPoolPage::lookupTitle($obj["item_id"]);
3524 }
3525 $objects[] = array ("id" => $obj["item_id"],
3526 "type" => $obj["type"], "title" => $obj["title"],
3527 "insert_time" => $obj["insert_time"]);
3528 }
3529 return $objects;
3530 }
3531
3535 function getClipboardChilds($a_parent, $a_insert_time)
3536 {
3537 global $ilDB, $ilUser;
3538
3539 $objs = $ilDB->queryF("SELECT * FROM personal_clipboard WHERE ".
3540 "user_id = %s AND parent = %s AND insert_time = %s ".
3541 " ORDER BY order_nr",
3542 array("integer", "integer", "timestamp"),
3543 array($ilUser->getId(), (int) $a_parent, $a_insert_time));
3544 $objects = array();
3545 while ($obj = $ilDB->fetchAssoc($objs))
3546 {
3547 if ($obj["type"] == "mob")
3548 {
3549 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3550 }
3551 $objects[] = array ("id" => $obj["item_id"],
3552 "type" => $obj["type"], "title" => $obj["title"]);
3553 }
3554 return $objects;
3555 }
3556
3565 function _getUsersForClipboadObject($a_type, $a_id)
3566 {
3567 global $ilDB;
3568
3569 $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3570 "item_id = ".$ilDB->quote($a_id, "integer")." AND ".
3571 "type = ".$ilDB->quote($a_type, "text");
3572 $user_set = $ilDB->query($q);
3573 $users = array();
3574 while ($user_rec = $ilDB->fetchAssoc($user_set))
3575 {
3576 $users[] = $user_rec["user_id"];
3577 }
3578
3579 return $users;
3580 }
3581
3589 function removeObjectFromClipboard($a_item_id, $a_type)
3590 {
3591 global $ilDB;
3592
3593 $q = "DELETE FROM personal_clipboard WHERE ".
3594 "item_id = ".$ilDB->quote($a_item_id, "integer").
3595 " AND type = ".$ilDB->quote($a_type, "text")." ".
3596 " AND user_id = ".$ilDB->quote($this->getId(), "integer");
3597 $ilDB->manipulate($q);
3598 }
3599
3600 function _getImportedUserId($i2_id)
3601 {
3602 global $ilDB;
3603
3604 $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3605 $ilDB->quote($i2_id, "text");
3606
3607 $res = $ilDB->query($query);
3608 while($row = $ilDB->fetchObject($res))
3609 {
3610 $id = $row->obj_id;
3611 }
3612 return $id ? $id : 0;
3613 }
3614
3619 function setAuthMode($a_str)
3620 {
3621 $this->auth_mode = $a_str;
3622 }
3623
3628 function getAuthMode($a_auth_key = false)
3629 {
3630 if (!$a_auth_key)
3631 {
3632 return $this->auth_mode;
3633 }
3634
3635 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3636 return ilAuthUtils::_getAuthMode($this->auth_mode);
3637 }
3638
3646 function setExternalAccount($a_str)
3647 {
3648 $this->ext_account = $a_str;
3649 }
3650
3659 {
3660 return $this->ext_account;
3661 }
3662
3674 public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3675 {
3676 global $ilDB,$ilSetting;
3677
3678 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3679 $q = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3680 "WHERE auth_mode = %s";
3681 $types[] = "text";
3682 $values[] = $a_auth_mode;
3683 if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3684 {
3685 $q.= " OR auth_mode = %s ";
3686 $types[] = "text";
3687 $values[] = 'default';
3688 }
3689
3690 $res = $ilDB->queryF($q, $types, $values);
3691 while ($row = $ilDB->fetchObject($res))
3692 {
3693 if($row->auth_mode == 'default')
3694 {
3695 $accounts[$row->usr_id] = $row->login;
3696 }
3697 else
3698 {
3699 $accounts[$row->usr_id] = $row->ext_account;
3700 }
3701 }
3702 return $accounts ? $accounts : array();
3703 }
3704
3712 public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3713 {
3714 global $ilDB;
3715
3716 if(!is_array($a_usr_ids))
3717 {
3718 return false;
3719 }
3720
3721
3722 if( $a_status )
3723 {
3724 $q = "UPDATE usr_data SET active = 1, inactivation_date = NULL WHERE ".
3725 $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3726 $ilDB->manipulate($q);
3727 }
3728 else
3729 {
3730 $usrId_IN_usrIds = $ilDB->in("usr_id", $a_usr_ids, false, "integer");
3731
3732 $q = "UPDATE usr_data SET active = 0 WHERE $usrId_IN_usrIds";
3733 $ilDB->manipulate($q);
3734
3735 $queryString = "
3736 UPDATE usr_data
3737 SET inactivation_date = %s
3738 WHERE inactivation_date IS NULL
3739 AND $usrId_IN_usrIds
3740 ";
3741 $ilDB->manipulateF($queryString, array('timestamp'), array(ilUtil::now()));
3742 }
3743
3744 return true;
3745 }
3746
3747
3756 public static function _lookupAuthMode($a_usr_id)
3757 {
3758 return (string) ilObjUser::_lookup($a_usr_id, "auth_mode");
3759 }
3760
3767 public static function _checkExternalAuthAccount($a_auth, $a_account)
3768 {
3769 global $ilDB,$ilSetting;
3770
3771 // Check directly with auth_mode
3772 $r = $ilDB->queryF("SELECT * FROM usr_data WHERE ".
3773 " ext_account = %s AND auth_mode = %s",
3774 array("text", "text"),
3775 array($a_account, $a_auth));
3776 if ($usr = $ilDB->fetchAssoc($r))
3777 {
3778 return $usr["login"];
3779 }
3780
3781 // For compatibility, check for login (no ext_account entry given)
3782 $res = $ilDB->queryF("SELECT login FROM usr_data ".
3783 "WHERE login = %s AND auth_mode = %s",
3784 array("text", "text"),
3785 array($a_account, $a_auth));
3786 if($usr = $ilDB->fetchAssoc($res))
3787 {
3788 return $usr['login'];
3789 }
3790
3791 // If auth_default == $a_auth => check for login
3792 if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3793 {
3794 $res = $ilDB->queryF("SELECT login FROM usr_data WHERE ".
3795 " ext_account = %s AND auth_mode = %s",
3796 array("text", "text"),
3797 array($a_account, "default"));
3798 if ($usr = $ilDB->fetchAssoc($res))
3799 {
3800 return $usr["login"];
3801 }
3802 // Search for login (no ext_account given)
3803 $res = $ilDB->queryF("SELECT login FROM usr_data ".
3804 "WHERE login = %s AND (ext_account IS NULL OR ext_account = '') AND auth_mode = %s",
3805 array("text", "text"),
3806 array($a_account, "default"));
3807 if($usr = $ilDB->fetchAssoc($res))
3808 {
3809 return $usr["login"];
3810 }
3811 }
3812 return false;
3813 }
3814
3819 {
3820 global $ilDB;
3821
3822 $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3823 "GROUP BY auth_mode");
3824 $cnt_arr = array();
3825 while($cnt = $ilDB->fetchAssoc($r))
3826 {
3827 $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3828 }
3829
3830 return $cnt_arr;
3831 }
3832
3838 function _getLocalAccountsForEmail($a_email)
3839 {
3840 global $ilDB, $ilSetting;
3841
3842 // default set to local (1)?
3843
3844 $q = "SELECT * FROM usr_data WHERE ".
3845 " email = %s AND (auth_mode = %s ";
3846 $types = array("text", "text");
3847 $values = array($a_email, "local");
3848
3849 if ($ilSetting->get("auth_mode") == 1)
3850 {
3851 $q.=" OR auth_mode = %s";
3852 $types[] = "text";
3853 $values[] = "default";
3854 }
3855
3856 $q.= ")";
3857
3858 $users = array();
3859 $usr_set = $ilDB->queryF($q, $types, $values);
3860 while ($usr_rec = $ilDB->fetchAssoc($usr_set))
3861 {
3862 $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3863 }
3864
3865 return $users;
3866 }
3867
3868
3876 function _uploadPersonalPicture($tmp_file, $obj_id)
3877 {
3878 $webspace_dir = ilUtil::getWebspaceDir();
3879 $image_dir = $webspace_dir."/usr_images";
3880 $store_file = "usr_".$obj_id."."."jpg";
3881 $target_file = $image_dir."/$store_file";
3882
3883 chmod($tmp_file, 0770);
3884
3885 // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3886 // taking only frame [0] to avoid problems with animated gifs
3887 $show_file = "$image_dir/usr_".$obj_id.".jpg";
3888 $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3889 $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3890 $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3891
3892 ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:".$show_file);
3893 ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:".$thumb_file);
3894 ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:".$xthumb_file);
3895 ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:".$xxthumb_file);
3896
3897 // store filename
3898 self::_writePref($obj_id, "profile_image", $store_file);
3899
3900 return TRUE;
3901 }
3902
3903
3912 public function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3913 {
3914 if(isset(self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic]))
3915 {
3916 return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3917 }
3918
3919 self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic] = ilObjUser::_getPersonalPicturePath($this->getId(), $a_size, $a_force_pic);
3920
3921 return self::$personal_image_cache[$this->getId()][$a_size][(int)$a_force_pic];
3922 }
3923
3933 public static function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3934 $a_prevent_no_photo_image = false)
3935 {
3936 global $ilDB;
3937
3938 // BEGIN DiskQuota: Fetch all user preferences in a single query
3939 $res = $ilDB->queryF("SELECT * FROM usr_pref WHERE ".
3940 "keyword IN (%s,%s) ".
3941 "AND usr_id = %s",
3942 array("text", "text", "integer"),
3943 array('public_upload', 'public_profile', $a_usr_id));
3944 while ($row = $ilDB->fetchAssoc($res))
3945 {
3946 switch ($row['keyword'])
3947 {
3948 case 'public_upload' :
3949 $upload = $row['value'] == 'y';
3950 break;
3951 case 'public_profile' :
3952 $profile = ($row['value'] == 'y' ||
3953 $row['value'] == 'g');
3954 break;
3955 }
3956 }
3957
3958 // END DiskQuota: Fetch all user preferences in a single query
3959 $webspace_dir = "";
3960 if(defined('ILIAS_MODULE'))
3961 {
3962 $webspace_dir = ('.'.$webspace_dir);
3963 }
3964 $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
3965
3966 $image_dir = $webspace_dir."/usr_images";
3967 // BEGIN DiskQuota: Support 'big' user images
3968 if ($a_size == 'big')
3969 {
3970 $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3971 }
3972 else
3973 {
3974 $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3975 }
3976 // END DiskQuota: Support 'big' user images
3977
3978 if((($upload && $profile) || $a_force_pic)
3979 && @is_file($thumb_file))
3980 {
3981 $file = $thumb_file."?t=".rand(1, 99999);
3982 }
3983 else
3984 {
3985 if (!$a_prevent_no_photo_image)
3986 {
3987 // we only have xsmall and xxsmall for this
3988 if($a_size == "small" || $a_size == "big")
3989 {
3990 $a_size = "xsmall";
3991 }
3992 $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
3993 }
3994 }
3995
3996 return $file;
3997 }
3998
4005 static function copyProfilePicturesToDirectory($a_user_id, $a_dir)
4006 {
4007 $a_dir = trim(str_replace("..", "", $a_dir));
4008 if ($a_dir == "" || !is_dir($a_dir))
4009 {
4010 return;
4011 }
4012
4013 $webspace_dir = ilUtil::getWebspaceDir();
4014 $image_dir = $webspace_dir."/usr_images";
4015 $images = array(
4016 "upload_".$a_user_id."pic",
4017 "usr_".$a_user_id."."."jpg",
4018 "usr_".$a_user_id."_small.jpg",
4019 "usr_".$a_user_id."_xsmall.jpg",
4020 "usr_".$a_user_id."_xxsmall.jpg",
4021 "upload_".$a_user_id);
4022 foreach ($images as $image)
4023 {
4024 if (is_file($image_dir."/".$image))
4025 {
4026 copy($image_dir."/".$image, $a_dir."/".$image);
4027 }
4028 }
4029 }
4030
4031
4035 function removeUserPicture($a_do_update = true)
4036 {
4037 $webspace_dir = ilUtil::getWebspaceDir();
4038 $image_dir = $webspace_dir."/usr_images";
4039 $file = $image_dir."/usr_".$this->getID()."."."jpg";
4040 $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
4041 $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
4042 $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
4043 $upload_file = $image_dir."/upload_".$this->getID();
4044
4045 if($a_do_update)
4046 {
4047 // remove user pref file name
4048 $this->setPref("profile_image", "");
4049 $this->update();
4050 }
4051
4052 if (@is_file($file))
4053 {
4054 unlink($file);
4055 }
4056 if (@is_file($thumb_file))
4057 {
4058 unlink($thumb_file);
4059 }
4060 if (@is_file($xthumb_file))
4061 {
4062 unlink($xthumb_file);
4063 }
4064 if (@is_file($xxthumb_file))
4065 {
4066 unlink($xxthumb_file);
4067 }
4068 if (@is_file($upload_file))
4069 {
4070 unlink($upload_file);
4071 }
4072 }
4073
4074
4075 function setUserDefinedData($a_data)
4076 {
4077 if(!is_array($a_data))
4078 {
4079 return false;
4080 }
4081 foreach($a_data as $field => $data)
4082 {
4083 #$new_data[$field] = ilUtil::stripSlashes($data);
4084 // Assign it directly to avoid update problems of unchangable fields
4085 $this->user_defined_data['f_'.$field] = $data;
4086 }
4087 #$this->user_defined_data = $new_data;
4088
4089 return true;
4090 }
4091
4093 {
4094 return $this->user_defined_data ? $this->user_defined_data : array();
4095 }
4096
4098 {
4099 global $ilDB;
4100
4101 $fields = '';
4102
4103 $field_def = array();
4104
4105 include_once("./Services/User/classes/class.ilUserDefinedData.php");
4106 $udata = new ilUserDefinedData($this->getId());
4107
4108 foreach($this->user_defined_data as $field => $value)
4109 {
4110 if($field != 'usr_id')
4111 {
4112// $field_def[$field] = array('text',$value);
4113 $udata->set($field, $value);
4114 }
4115 }
4116 $udata->update();
4117
4118/* if(!$field_def)
4119 {
4120 return true;
4121 }
4122
4123 $query = "SELECT usr_id FROM udf_data WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4124 $res = $ilDB->query($query);
4125
4126
4127 if($res->numRows())
4128 {
4129 // Update
4130 $ilDB->update('udf_data',$field_def,array('usr_id' => array('integer',$this->getId())));
4131 }
4132 else
4133 {
4134 $field_def['usr_id'] = array('integer',$this->getId());
4135 $ilDB->insert('udf_data',$field_def);
4136 }
4137*/
4138 return true;
4139 }
4140
4142 {
4143 global $ilDB;
4144
4145 include_once("./Services/User/classes/class.ilUserDefinedData.php");
4146 $udata = new ilUserDefinedData($this->getId());
4147
4148/* $query = "SELECT * FROM udf_data ".
4149 "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4150
4151 $res = $this->db->query($query);
4152 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
4153 {
4154 $this->user_defined_data = $row;
4155 }*/
4156
4157 $this->user_defined_data = $udata->getAll();
4158
4159 return true;
4160 }
4161
4163 {
4164 global $ilDB;
4165
4166// not needed. no entry in udf_text/udf_clob means no value
4167
4168/* $query = "INSERT INTO udf_data (usr_id ) ".
4169 "VALUES( ".
4170 $ilDB->quote($this->getId(),'integer').
4171 ")";
4172 $res = $ilDB->manipulate($query);
4173*/
4174 return true;
4175 }
4176
4178 {
4179 global $ilDB;
4180
4181 include_once("./Services/User/classes/class.ilUserDefinedData.php");
4183
4184 // wrong place...
4185/* $query = "DELETE FROM udf_data ".
4186 "WHERE usr_id = ".$ilDB->quote($this->getId(),'integer');
4187 $res = $ilDB->manipulate($query);*/
4188
4189 return true;
4190 }
4191
4197 function getProfileAsString(&$a_language)
4198 {
4199 include_once './Services/AccessControl/classes/class.ilObjRole.php';
4200 include_once './Services/Utilities/classes/class.ilFormat.php';
4201
4202 global $lng,$rbacreview;
4203
4204 $language =& $a_language;
4205 $language->loadLanguageModule('registration');
4206 $language->loadLanguageModule('crs');
4207
4208 $body = '';
4209 $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4210
4211 if(strlen($this->getUTitle()))
4212 {
4213 $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4214 }
4215 if(strlen($this->getGender()))
4216 {
4217 $gender = ($this->getGender() == 'm') ?
4218 $language->txt('gender_m') :
4219 $language->txt('gender_f');
4220 $body .= ($language->txt("gender").": ".$gender."\n");
4221 }
4222 if(strlen($this->getFirstname()))
4223 {
4224 $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4225 }
4226 if(strlen($this->getLastname()))
4227 {
4228 $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4229 }
4230 if(strlen($this->getInstitution()))
4231 {
4232 $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4233 }
4234 if(strlen($this->getDepartment()))
4235 {
4236 $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4237 }
4238 if(strlen($this->getStreet()))
4239 {
4240 $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4241 }
4242 if(strlen($this->getCity()))
4243 {
4244 $body .= ($language->txt("city").": ".$this->getCity()."\n");
4245 }
4246 if(strlen($this->getZipcode()))
4247 {
4248 $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4249 }
4250 if(strlen($this->getCountry()))
4251 {
4252 $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4253 }
4254 if(strlen($this->getSelectedCountry()))
4255 {
4256 $body .= ($language->txt("sel_country").": ".$this->getSelectedCountry()."\n");
4257 }
4258 if(strlen($this->getPhoneOffice()))
4259 {
4260 $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4261 }
4262 if(strlen($this->getPhoneHome()))
4263 {
4264 $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4265 }
4266 if(strlen($this->getPhoneMobile()))
4267 {
4268 $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4269 }
4270 if(strlen($this->getFax()))
4271 {
4272 $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4273 }
4274 if(strlen($this->getEmail()))
4275 {
4276 $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4277 }
4278 if(strlen($this->getHobby()))
4279 {
4280 $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4281 }
4282 if(strlen($this->getComment()))
4283 {
4284 $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4285 }
4286 if(strlen($this->getMatriculation()))
4287 {
4288 $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4289 }
4290 if(strlen($this->getCreateDate()))
4291 {
4296
4297 $body .= ($language->txt("create_date").": ".$date."\n");
4298 }
4299
4300 foreach($rbacreview->getGlobalRoles() as $role)
4301 {
4302 if($rbacreview->isAssigned($this->getId(),$role))
4303 {
4304 $gr[] = ilObjRole::_lookupTitle($role);
4305 }
4306 }
4307 if(count($gr))
4308 {
4309 $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4310 }
4311
4312 // Time limit
4313 if($this->getTimeLimitUnlimited())
4314 {
4315 $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4316 }
4317 else
4318 {
4324
4325 $start = new ilDateTime($this->getTimeLimitFrom(),IL_CAL_UNIX);
4326 $end = new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX);
4327
4328 $body .= $language->txt('time_limit').': '.$start->get(IL_CAL_DATETIME);
4329 $body .= $language->txt('time_limit').': '.$end->get(IL_CAL_DATETIME);
4330
4331
4332 #$body .= $language->txt('time_limit').': '.$period;
4333 /*
4334 $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4335 ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4336 $language->txt('crs_to')." ".
4337 ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4338 */
4339 }
4340
4341 include_once './Services/User/classes/class.ilUserDefinedFields.php';
4345 $user_defined_fields = ilUserDefinedFields::_getInstance();
4347
4348 foreach($user_defined_fields->getDefinitions() as $field_id => $definition)
4349 {
4350 $data = $user_defined_data["f_".$field_id];
4351 if(strlen($data))
4352 {
4353 if($definition['field_type'] == UDF_TYPE_WYSIWYG)
4354 {
4355 $data = preg_replace('/<br(\s*)?\/?>/i', "\n", $data);
4356 $data = strip_tags($data);
4357 }
4358
4359 $body .= $definition['field_name'].': '. $data . "\n";
4360 }
4361 }
4362
4363 return $body;
4364 }
4365
4366 function setInstantMessengerId($a_im_type, $a_im_id)
4367 {
4368 $var = "im_".$a_im_type;
4369 $this->$var = $a_im_id;
4370 }
4371
4372 function getInstantMessengerId($a_im_type)
4373 {
4374 $var = "im_".$a_im_type;
4375 return $this->$var;
4376 }
4377
4378 function setDelicious($a_delicious)
4379 {
4380 $this->delicious = $a_delicious;
4381 }
4382
4383 function getDelicious()
4384 {
4385 return $this->delicious;
4386 }
4387
4391 function _lookupFeedHash($a_user_id, $a_create = false)
4392 {
4393 global $ilDB;
4394
4395 if ($a_user_id > 0)
4396 {
4397 $set = $ilDB->queryF("SELECT feed_hash from usr_data WHERE usr_id = %s",
4398 array("integer"), array($a_user_id));
4399 if ($rec = $ilDB->fetchAssoc($set))
4400 {
4401 if (strlen($rec["feed_hash"]) == 32)
4402 {
4403 return $rec["feed_hash"];
4404 }
4405 else if($a_create)
4406 {
4407 $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4408 $ilDB->manipulateF("UPDATE usr_data SET feed_hash = %s".
4409 " WHERE usr_id = %s",
4410 array("text", "integer"),
4411 array($hash, $a_user_id));
4412 return $hash;
4413 }
4414 }
4415 }
4416
4417 return false;
4418 }
4419
4425 function _getFeedPass($a_user_id)
4426 {
4427 global $ilDB;
4428
4429 if ($a_user_id > 0)
4430 {
4431 return ilObjUser::_lookupPref($a_user_id, "priv_feed_pass");
4432 }
4433 return false;
4434 }
4435
4441 function _setFeedPass($a_user_id, $a_password)
4442 {
4443 global $ilDB;
4444
4445 self::_writePref($a_user_id, "priv_feed_pass",
4446 ($a_password=="") ? "" : md5($a_password));
4447 }
4448
4458 public static function _loginExists($a_login,$a_user_id = 0)
4459 {
4460 global $ilDB;
4461
4462 $q = "SELECT DISTINCT login, usr_id FROM usr_data ".
4463 "WHERE login = %s";
4464 $types[] = "text";
4465 $values[] = $a_login;
4466
4467 if ($a_user_id != 0)
4468 {
4469 $q.= " AND usr_id != %s ";
4470 $types[] = "integer";
4471 $values[] = $a_user_id;
4472 }
4473
4474 $r = $ilDB->queryF($q, $types, $values);
4475
4476 if ($row = $ilDB->fetchAssoc($r))
4477 {
4478 return $row['usr_id'];
4479 }
4480 return false;
4481 }
4482
4493 public static function _externalAccountExists($a_external_account,$a_auth_mode)
4494 {
4495 global $ilDB;
4496
4497 $res = $ilDB->queryF("SELECT * FROM usr_data ".
4498 "WHERE ext_account = %s AND auth_mode = %s",
4499 array("text", "text"),
4500 array($a_external_account, $a_auth_mode));
4501 return $ilDB->fetchAssoc($res) ? true :false;
4502 }
4503
4511 public static function _getUsersForRole($role_id, $active = -1) {
4512 global $ilDB, $rbacreview;
4513 $data = array();
4514
4515 $ids = $rbacreview->assignedUsers($role_id);
4516
4517 if (count ($ids) == 0)
4518 {
4519 $ids = array (-1);
4520 }
4521
4522 $query = "SELECT usr_data.*, usr_pref.value AS language
4523 FROM usr_data
4524 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4525 WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4526 $values[] = "language";
4527 $types[] = "text";
4528
4529
4530 if (is_numeric($active) && $active > -1)
4531 {
4532 $query .= " AND usr_data.active = %s";
4533 $values[] = $active;
4534 $types[] = "integer";
4535 }
4536
4537 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4538
4539 $r = $ilDB->queryF($query, $types, $values);
4540 $data = array();
4541 while ($row = $ilDB->fetchAssoc($r))
4542 {
4543 $data[] = $row;
4544 }
4545 return $data;
4546 }
4547
4548
4554 public static function _getUsersForFolder ($ref_id, $active) {
4555 global $ilDB;
4556 $data = array();
4557 $query = "SELECT usr_data.*, usr_pref.value AS language FROM usr_data LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id and usr_pref.keyword = %s WHERE 1 = 1 ";
4558 $types[] = "text";
4559 $values[] = "language";
4560
4561 if (is_numeric($active) && $active > -1)
4562 {
4563 $query .= " AND usr_data.active = %s";
4564 $values[] = $active;
4565 $types[] = "integer";
4566 }
4567
4568 if ($ref_id != USER_FOLDER_ID)
4569 {
4570 $query.= " AND usr_data.time_limit_owner = %s";
4571 $values[] = $ref_id;
4572 $types[] = "integer";
4573 }
4574
4575 $query .= " AND usr_data.usr_id != %s ";
4576 $values[] = ANONYMOUS_USER_ID;
4577 $types[] = "integer";
4578
4579 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4580
4581 $result = $ilDB->queryF($query, $types, $values);
4582 $data = array();
4583 while ($row = $ilDB->fetchAssoc($result))
4584 {
4585 array_push($data, $row);
4586 }
4587
4588 return $data;
4589 }
4590
4591
4597 public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4598 {
4599 return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4600 }
4601
4602
4608 public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4609 {
4610 global $rbacadmin, $rbacreview, $ilDB;
4611
4612 // quote all ids
4613 $ids = array();
4614 foreach ($a_mem_ids as $mem_id) {
4615 $ids [] = $ilDB->quote($mem_id);
4616 }
4617
4618 $query = "SELECT usr_data.*, usr_pref.value AS language
4619 FROM usr_data
4620 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4621 WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer")."
4622 AND usr_data.usr_id != %s";
4623 $values[] = "language";
4624 $types[] = "text";
4625 $values[] = ANONYMOUS_USER_ID;
4626 $types[] = "integer";
4627
4628 if (is_numeric($active) && $active > -1)
4629 {
4630 $query .= " AND active = %s";
4631 $values[] = $active;
4632 $types[] = "integer";
4633 }
4634
4635 if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4636 {
4637 $query.= " AND usr_data.time_limit_owner = %s";
4638 $values[] = $timelimitowner;
4639 $types[] = "integer";
4640
4641 }
4642
4643 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4644
4645 $result = $ilDB->queryF($query, $types, $values);
4646 while ($row = $ilDB->fetchAssoc($result))
4647 {
4648 $mem_arr[] = $row;
4649 }
4650
4651 return $mem_arr ? $mem_arr : array();
4652 }
4653
4654
4655
4661 public static function _getUserData ($a_internalids) {
4662 global $ilDB;
4663
4664 $ids = array();
4665 if (is_array($a_internalids)) {
4666 foreach ($a_internalids as $internalid) {
4667 if (is_numeric ($internalid))
4668 {
4669 $ids[] = $internalid;
4670 }
4671 else
4672 {
4673 $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4674 if (is_numeric($parsedid) && $parsedid > 0)
4675 {
4676 $ids[] = $parsedid;
4677 }
4678 }
4679 }
4680 }
4681 if (count($ids) == 0)
4682 $ids [] = -1;
4683
4684 $query = "SELECT usr_data.*, usr_pref.value AS language
4685 FROM usr_data
4686 LEFT JOIN usr_pref
4687 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = %s
4688 WHERE ".$ilDB->in("usr_data.usr_id", $ids, false, "integer");
4689 $values[] = "language";
4690 $types[] = "text";
4691
4692 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4693
4694 $data = array();
4695 $result = $ilDB->queryF($query, $types, $values);
4696 while ($row = $ilDB->fetchAssoc($result))
4697 {
4698 $data[] = $row;
4699 }
4700 return $data;
4701 }
4702
4709 public static function _getPreferences ($user_id)
4710 {
4711 global $ilDB;
4712
4713 $prefs = array();
4714
4715 $r = $ilDB->queryF("SELECT * FROM usr_pref WHERE usr_id = %s",
4716 array("integer"), array($user_id));
4717
4718 while($row = $ilDB->fetchAssoc($r))
4719 {
4720 $prefs[$row["keyword"]] = $row["value"];
4721 }
4722
4723 return $prefs;
4724 }
4725
4726
4727 public static function _resetLoginAttempts($a_usr_id)
4728 {
4729 global $ilDB;
4730
4731 $query = "UPDATE usr_data SET login_attempts = 0 WHERE usr_id = %s";
4732 $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4733
4734 if($affected) return true;
4735 else return false;
4736 }
4737
4738 public static function _getLoginAttempts($a_usr_id)
4739 {
4740 global $ilDB;
4741
4742 $query = "SELECT login_attempts FROM usr_data WHERE usr_id = %s";
4743 $result = $ilDB->queryF( $query, array('integer'), array($a_usr_id) );
4744 $record = $ilDB->fetchAssoc( $result );
4745 $login_attempts = $record['login_attempts'];
4746
4747 return $login_attempts;
4748 }
4749
4750 public static function _incrementLoginAttempts($a_usr_id)
4751 {
4752 global $ilDB;
4753
4754 $query = "UPDATE usr_data SET login_attempts = (login_attempts + 1) WHERE usr_id = %s";
4755 $affected = $ilDB->manipulateF( $query, array('integer'), array($a_usr_id) );
4756
4757 if($affected) return true;
4758 else return false;
4759 }
4760
4761 public static function _setUserInactive($a_usr_id)
4762 {
4763 global $ilDB;
4764
4765 $query = "UPDATE usr_data SET active = 0, inactivation_date = %s WHERE usr_id = %s";
4766 $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array(ilUtil::now(), $a_usr_id) );
4767
4768 if($affected) return true;
4769 else return false;
4770 }
4771
4777 public function hasPublicProfile() {
4778 return in_array($this->getPref("public_profile"), array("y", "g"));
4779 }
4780
4786 public function getPublicName()
4787 {
4788 if ($this->hasPublicProfile())
4789 return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4790 else
4791 return $this->getLogin();
4792
4793 }
4794
4795 public static function _writeHistory($a_usr_id, $a_login)
4796 {
4797 global $ilDB;
4798
4799 $timestamp = time();
4800
4801 $res = $ilDB->queryF('SELECT * FROM loginname_history WHERE usr_id = %s AND login = %s AND history_date = %s',
4802 array('integer', 'text', 'integer'),
4803 array($a_usr_id, $a_login, $timestamp));
4804
4805 if( $ilDB->numRows($res) == 0 )
4806 {
4807 $ilDB->manipulateF('
4808 INSERT INTO loginname_history
4809 (usr_id, login, history_date)
4810 VALUES (%s, %s, %s)',
4811 array('integer', 'text', 'integer'),
4812 array($a_usr_id, $a_login, $timestamp));
4813 }
4814
4815 return true;
4816 }
4817
4825 public static function _getUsersOnline($a_user_id = 0, $a_no_anonymous = false)
4826 {
4830 global $ilDB;
4831
4832 $pd_set = new ilSetting('pd');
4833 $atime = $pd_set->get('user_activity_time') * 60;
4834 $ctime = time();
4835
4836 $where = array();
4837
4838 if($a_user_id == 0)
4839 {
4840 $where[] = 'user_id > 0';
4841
4842 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4843 if(ilTermsOfServiceHelper::isEnabled())
4844 {
4845 $where[] = '(agree_date IS NOT NULL OR user_id = ' . $ilDB->quote(SYSTEM_USER_ID, 'integer') . ')';
4846 }
4847 }
4848 else
4849 {
4850 $where[] = 'user_id = ' . $ilDB->quote($a_user_id, 'integer');
4851 }
4852
4853 if($a_no_anonymous)
4854 {
4855 $where[] = 'user_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
4856 }
4857
4858 include_once 'Services/User/classes/class.ilUserAccountSettings.php';
4859 if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
4860 {
4861 include_once 'Services/User/classes/class.ilUserFilter.php';
4862 $where[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
4863 }
4864
4865 $where[] = 'expires > ' . $ilDB->quote($ctime, 'integer');
4866 $where[] = '(p.value IS NULL OR NOT p.value = ' . $ilDB->quote('y', 'text') . ')';
4867
4868 $where = 'WHERE ' . implode(' AND ', $where);
4869
4870 $r = $ilDB->queryF("
4871 SELECT COUNT(user_id) num, user_id, firstname, lastname, title, login, last_login, MAX(ctime) ctime
4872 FROM usr_session
4873 LEFT JOIN usr_data u
4874 ON user_id = u.usr_id
4875 LEFT JOIN usr_pref p
4876 ON (p.usr_id = u.usr_id AND p.keyword = %s)
4877 {$where}
4878 GROUP BY user_id, firstname, lastname, title, login, last_login
4879 ORDER BY lastname, firstname
4880 ",
4881 array('text'),
4882 array('hide_own_online_status')
4883 );
4884
4885 $users = array();
4886 while($user = $ilDB->fetchAssoc($r))
4887 {
4888 if($atime <= 0 || $user['ctime'] + $atime > $ctime)
4889 {
4890 $users[$user['user_id']] = $user;
4891 }
4892 }
4893
4894 return $users;
4895 }
4896
4905 public static function _getAssociatedUsersOnline($a_user_id, $a_no_anonymous = false)
4906 {
4907 global $ilias, $ilDB;
4908
4909 $pd_set = new ilSetting("pd");
4910 $atime = $pd_set->get("user_activity_time") * 60;
4911 $ctime = time();
4912 $no_anonym = ($a_no_anonymous)
4913 ? "AND user_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer")." "
4914 : "";
4915
4916 // Get a list of object id's of all courses and groups for which
4917 // the current user has local roles.
4918 // Note: we have to use DISTINCT here, because a user may assume
4919 // multiple roles in a group or a course.
4920 $q = "SELECT DISTINCT dat.obj_id as obj_id ".
4921 "FROM rbac_ua ua ".
4922 "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4923 "JOIN object_reference r1 ON r1.ref_id = fa.parent ".
4924 "JOIN tree ON tree.child = r1.ref_id ".
4925 "JOIN object_reference r2 ON r2.ref_id = tree.child ". // #17674 - rolf is gone
4926 "JOIN object_data dat ON dat.obj_id = r2.obj_id ".
4927 "WHERE ua.usr_id = ".$ilDB->quote($a_user_id, "integer")." ".
4928 "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4929 "AND dat.type IN (".$ilDB->quote("crs", "text").",".
4930 $ilDB->quote("grp", "text").")";
4931 $r = $ilDB->query($q);
4932
4933 while ($row = $ilDB->fetchAssoc($r))
4934 {
4935 $groups_and_courses_of_user[] = $row["obj_id"];
4936 }
4937
4938 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
4939 $tos_condition = '';
4940 if(ilTermsOfServiceHelper::isEnabled())
4941 {
4942 $tos_condition = " AND (agree_date IS NOT NULL OR ud.usr_id = " . $ilDB->quote(SYSTEM_USER_ID, 'integer') . ") ";
4943 }
4944
4945 // If the user is not in a course or a group, he has no associated users.
4946 if (count($groups_and_courses_of_user) == 0)
4947 {
4948 $q = "SELECT count(user_id) as num,ctime,user_id,firstname,lastname,title,login,last_login ".
4949 "FROM usr_session ".
4950 "JOIN usr_data ud ON user_id = ud.usr_id ".
4951 "WHERE user_id = ".$ilDB->quote($a_user_id, "integer")." ".
4952 $no_anonym.
4953 $tos_condition.
4954 "AND expires > ".$ilDB->quote(time(), "integer")." ".
4955 "GROUP BY user_id,ctime,firstname,lastname,title,login,last_login";
4956 $r = $ilDB->query($q);
4957 }
4958 else
4959 {
4960 $q = "SELECT count(user_id) as num,s.ctime,s.user_id,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4961 "FROM usr_session s ".
4962 "JOIN usr_data ud ON ud.usr_id = s.user_id ".
4963 "JOIN rbac_ua ua ON ua.usr_id = s.user_id ".
4964 "JOIN rbac_fa fa ON fa.rol_id = ua.rol_id ".
4965 "JOIN tree ON tree.child = fa.parent ".
4966 "JOIN object_reference or1 ON or1.ref_id = tree.child ". // #17674 - rolf is gone
4967 "JOIN object_data od ON od.obj_id = or1.obj_id ".
4968 "LEFT JOIN usr_pref p ON (p.usr_id = ud.usr_id AND p.keyword = ".
4969 $ilDB->quote("hide_own_online_status", "text").") ".
4970 "WHERE s.user_id != 0 ".
4971 $no_anonym.
4972 "AND (p.value IS NULL OR NOT p.value = ".$ilDB->quote("y", "text").") ".
4973 "AND s.expires > ".$ilDB->quote(time(),"integer")." ".
4974 "AND fa.assign = ".$ilDB->quote("y", "text")." ".
4975 $tos_condition.
4976 "AND ".$ilDB->in("od.obj_id", $groups_and_courses_of_user, false, "integer")." ".
4977 "GROUP BY s.user_id,s.ctime,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
4978 "ORDER BY ud.lastname, ud.firstname";
4979 $r = $ilDB->query($q);
4980 }
4981
4982 while ($user = $ilDB->fetchAssoc($r))
4983 {
4984 if ($atime <= 0
4985 || $user["ctime"] + $atime > $ctime)
4986 {
4987 $users[$user["user_id"]] = $user;
4988 }
4989 }
4990
4991 return $users ? $users : array();
4992 }
4993
5000 public static function _generateRegistrationHash($a_usr_id)
5001 {
5002 global $ilDB;
5003
5004 do
5005 {
5006 $continue = false;
5007
5008 $hashcode = substr(md5(uniqid(rand(), true)), 0, 16);
5009
5010 $res = $ilDB->queryf('
5011 SELECT COUNT(usr_id) cnt FROM usr_data
5012 WHERE reg_hash = %s',
5013 array('text'),
5014 array($hashcode));
5015 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5016 {
5017 if($row->cnt > 0) $continue = true;
5018 break;
5019 }
5020
5021 if($continue) continue;
5022
5023 $ilDB->manipulateF('
5024 UPDATE usr_data
5025 SET reg_hash = %s
5026 WHERE usr_id = %s',
5027 array('text', 'integer'),
5028 array($hashcode, (int)$a_usr_id)
5029 );
5030
5031 break;
5032
5033 } while(true);
5034
5035 return $hashcode;
5036 }
5037
5046 public static function _verifyRegistrationHash($a_hash)
5047 {
5048 global $ilDB;
5049
5050 $res = $ilDB->queryf('
5051 SELECT usr_id, create_date FROM usr_data
5052 WHERE reg_hash = %s',
5053 array('text'),
5054 array($a_hash));
5055 while($row = $ilDB->fetchAssoc($res))
5056 {
5057 require_once 'Services/Registration/classes/class.ilRegistrationSettings.php';
5058 $oRegSettigs = new ilRegistrationSettings();
5059
5060 if((int)$oRegSettigs->getRegistrationHashLifetime() != 0 &&
5061 time() - (int)$oRegSettigs->getRegistrationHashLifetime() > strtotime($row['create_date']))
5062 {
5063 require_once 'Services/Registration/exceptions/class.ilRegConfirmationLinkExpiredException.php';
5064 throw new ilRegConfirmationLinkExpiredException('reg_confirmation_hash_life_time_expired', $row['usr_id']);
5065 }
5066
5067 $ilDB->manipulateF('
5068 UPDATE usr_data
5069 SET reg_hash = %s
5070 WHERE usr_id = %s',
5071 array('text', 'integer'),
5072 array('', (int)$row['usr_id'])
5073 );
5074
5075 return (int)$row['usr_id'];
5076 }
5077
5078 require_once 'Services/Registration/exceptions/class.ilRegistrationHashNotFoundException.php';
5079 throw new ilRegistrationHashNotFoundException('reg_confirmation_hash_not_found');
5080 }
5081
5082 function setBirthday($a_birthday)
5083 {
5084 if (strlen($a_birthday))
5085 {
5086 $date = new ilDate($a_birthday, IL_CAL_DATE);
5087 $this->birthday = $date->get(IL_CAL_DATE);
5088 }
5089 else
5090 {
5091 $this->birthday = null;
5092 }
5093 }
5094
5095 function getBirthday()
5096 {
5097 return $this->birthday;
5098 }
5099
5108 public static function _getUserIdsByInactivityPeriod($period)
5109 {
5110 if( !(int)$period ) throw new ilException('no valid period given');
5111
5112 global $ilDB;
5113
5114 $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5115
5116 $query = "SELECT usr_id FROM usr_data WHERE last_login < %s OR (ISNULL(last_login) AND create_date < %s)";
5117
5118 $res = $ilDB->queryF($query, array('timestamp', 'timestamp'), array($date, $date));
5119
5120 $ids = array();
5121 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5122 {
5123 $ids[] = $row->usr_id;
5124 }
5125
5126 return $ids;
5127 }
5128
5137 public static function _getUserIdsByInactivationPeriod($period)
5138 {
5140 $field = 'inactivation_date';
5142
5143 if( !(int)$period ) throw new ilException('no valid period given');
5144
5145 global $ilDB;
5146
5147 $date = date( 'Y-m-d H:i:s', (time() - ((int)$period * 24 * 60 * 60)) );
5148
5149 $query = "SELECT usr_id FROM usr_data WHERE $field < %s AND active = %s";
5150
5151 $res = $ilDB->queryF($query, array('timestamp', 'integer'), array($date, 0));
5152
5153 $ids = array();
5154 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
5155 {
5156 $ids[] = $row->usr_id;
5157 }
5158
5159 return $ids;
5160 }
5161
5171 public static function _updateLastLogin($a_usr_id, $a_last_login = null)
5172 {
5173 if($a_last_login !== null) $last_login = $a_last_login;
5174 else $last_login = date('Y-m-d H:i:s');
5175
5176 global $ilDB;
5177
5178 $query = "UPDATE usr_data SET last_login = %s WHERE usr_id = %s";
5179 $affected = $ilDB->manipulateF( $query, array('timestamp', 'integer'), array($last_login, $a_usr_id) );
5180
5181 if($affected) return $last_login;
5182 else return false;
5183 }
5184
5185 public function resetOwner()
5186 {
5187 global $ilDB;
5188
5189 $query = "UPDATE object_data SET owner = 0 ".
5190 "WHERE owner = ".$ilDB->quote($this->getId(),'integer');
5191 $ilDB->query($query);
5192
5193 return true;
5194 }
5195
5196
5204 {
5205 global $ilDB;
5206
5207 $q = "SELECT DISTINCT ".$ilDB->upper($ilDB->substr("lastname", 1, 1))." let".
5208 " FROM usr_data".
5209 " WHERE usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer").
5210 " ORDER BY let";
5211 $let_set = $ilDB->query($q);
5212
5213 $lets = array();
5214 while ($let_rec = $ilDB->fetchAssoc($let_set))
5215 {
5216 $let[$let_rec["let"]] = $let_rec["let"];
5217 }
5218 return $let;
5219 }
5220
5221 // begin-patch deleteProgress
5222 public static function userExists($a_usr_ids = array())
5223 {
5224 global $ilDB;
5225
5226 $query = 'SELECT count(*) num FROM object_data od '.
5227 'JOIN usr_data ud ON obj_id = usr_id '.
5228 'WHERE '.$ilDB->in('obj_id',$a_usr_ids,false,'integer').' ';
5229 $res = $ilDB->query($query);
5230 $num_rows =$res->fetchRow(DB_FETCHMODE_OBJECT)->num;
5231 return $num_rows == count((array) $a_usr_ids);
5232 }
5233 // end-patch deleteProgress
5234
5239 {
5240 return (boolean) $_SESSION["user_captcha_verified"];
5241 }
5242
5248 function setCaptchaVerified($a_val)
5249 {
5250 $_SESSION["user_captcha_verified"] = $a_val;
5251 }
5252
5260 {
5261 include_once("./Services/Export/classes/class.ilExport.php");
5262 $exp = new ilExport();
5263 $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5264 ilUtil::delDir($dir, true);
5265 $title = $this->getLastname().", ".$this->getLastname()." [".$this->getLogin()."]";
5266 $exp->exportEntity("personal_data", $this->getId(), "4.5.0",
5267 "Services/User", $title, $dir);
5268 }
5269
5277 {
5278 include_once("./Services/Export/classes/class.ilExport.php");
5279 $dir = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data");
5280 if (!is_dir($dir))
5281 {
5282 return "";
5283 }
5284 foreach(ilUtil::getDir($dir) as $entry)
5285 {
5286 if (is_int(strpos($entry["entry"], ".zip")))
5287 {
5288 return $entry["entry"];
5289 }
5290 }
5291
5292 return "";
5293 }
5294
5302 {
5303 include_once("./Services/Export/classes/class.ilExport.php");
5304 $file = ilExport::_getExportDirectory($this->getId(), "xml", "usr", "personal_data").
5305 "/".$this->getPersonalDataExportFile();
5306 if (is_file($file))
5307 {
5309 }
5310 }
5311
5318 function importPersonalData($a_file, $a_profile_data, $a_settings,
5319 $a_bookmarks, $a_notes, $a_calendar)
5320 {
5321 include_once("./Services/Export/classes/class.ilImport.php");
5322 $imp = new ilImport();
5323 if (!$a_profile_data)
5324 {
5325 $imp->addSkipEntity("Services/User", "usr_profile");
5326 }
5327 if (!$a_settings)
5328 {
5329 $imp->addSkipEntity("Services/User", "usr_setting");
5330 }
5331 if (!$a_bookmarks)
5332 {
5333 $imp->addSkipEntity("Services/Bookmarks", "bookmarks");
5334 }
5335 if (!$a_notes)
5336 {
5337 $imp->addSkipEntity("Services/Notes", "user_notes");
5338 }
5339 if (!$a_calendar)
5340 {
5341 $imp->addSkipEntity("Services/Calendar", "calendar");
5342 }
5343 $imp->importEntity($a_file["tmp_name"], $a_file["name"], "personal_data",
5344 "Services/User");
5345 }
5346
5352 private static function initInactivationDate($usrIds)
5353 {
5354 global $ilDB;
5355
5356 $NOW = $ilDB->now();
5357
5358 $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5359
5360 $queryString = "
5361 UPDATE usr_data
5362 SET inactivation_date = $NOW
5363 WHERE inactivation_date IS NULL
5364 AND $usrId_IN_usrIds
5365 ";
5366
5367 $ilDB->manipulate($queryString);
5368 }
5369
5375 private static function resetInactivationDate($usrIds)
5376 {
5377 global $ilDB;
5378
5379 $usrId_IN_usrIds = $ilDB->in('usr_id', $usrIds, false, 'integer');
5380
5381 $queryString = "
5382 UPDATE usr_data
5383 SET inactivation_date = NULL
5384 WHERE $usrId_IN_usrIds
5385 ";
5386
5387 $ilDB->manipulate($queryString);
5388 }
5389
5396 {
5397 $this->inactivation_date = $inactivation_date;
5398 }
5399
5405 public function getInactivationDate()
5406 {
5408 }
5409
5413 public function hasToAcceptTermsOfService()
5414 {
5418 global $rbacreview;
5419
5420 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5421
5422 if(
5423 ilTermsOfServiceHelper::isEnabled() &&
5424 null == $this->agree_date &&
5425 'root' != $this->agree_date &&
5426 !in_array($this->getId(), array(ANONYMOUS_USER_ID, SYSTEM_USER_ID)) &&
5427 !$rbacreview->isAssigned($this->getId(), SYSTEM_ROLE_ID)
5428 )
5429 {
5430 return true;
5431 }
5432
5433 return false;
5434 }
5435
5440 public static function hasUserToAcceptTermsOfService($a_username)
5441 {
5445 global $ilDB;
5446
5447 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5448
5449 if(!ilTermsOfServiceHelper::isEnabled())
5450 {
5451 return false;
5452 }
5453
5454 $in = $ilDB->in('usr_id', array(ANONYMOUS_USER_ID, SYSTEM_USER_ID), true, 'integer');
5455 $res = $ilDB->queryF(
5456 "SELECT usr_id FROM usr_data WHERE login = %s AND agree_date IS NULL $in",
5457 array("text"),
5458 array($a_username)
5459 );
5460 return $ilDB->fetchAssoc($res) ? true : false;
5461 }
5462
5467 public function hasToAcceptTermsOfServiceInSession($status = null)
5468 {
5469 if(null === $status)
5470 {
5471 return ilSession::get('has_to_accept_agr_in_session');
5472 }
5473
5474 require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
5475 if(ilTermsOfServiceHelper::isEnabled())
5476 {
5477 ilSession::set('has_to_accept_agr_in_session', (int)$status);
5478 }
5479 }
5480
5484 public function isAnonymous()
5485 {
5486 return $this->getId() == ANONYMOUS_USER_ID;
5487 }
5488
5489 public function activateDeletionFlag()
5490 {
5491 $this->writePref("delete_flag", true);
5492 }
5493
5494 public function removeDeletionFlag()
5495 {
5496 $this->writePref("delete_flag", false);
5497 }
5498
5499 public function hasDeletionFlag()
5500 {
5501 return (bool)$this->getPref("delete_flag");
5502 }
5503
5507 public function setIsSelfRegistered($status)
5508 {
5509 $this->is_self_registered = (bool) $status;
5510 }
5511
5512 public function isSelfRegistered()
5513 {
5514 return (bool) $this->is_self_registered;
5515 }
5516
5517
5518 //
5519 // MULTI-TEXT / INTERESTS
5520 //
5521
5527 public function setGeneralInterests(array $value = null)
5528 {
5529 $this->interests_general = $value;
5530 }
5531
5537 public function getGeneralInterests()
5538 {
5540 }
5541
5548 {
5549 return $this->buildTextFromArray("interests_general");
5550 }
5551
5557 public function setOfferingHelp(array $value = null)
5558 {
5559 $this->interests_help_offered = $value;
5560 }
5561
5567 public function getOfferingHelp()
5568 {
5570 }
5571
5577 public function getOfferingHelpAsText()
5578 {
5579 return $this->buildTextFromArray("interests_help_offered");
5580 }
5581
5587 public function setLookingForHelp(array $value = null)
5588 {
5589 $this->interests_help_looking = $value;
5590 }
5591
5597 public function getLookingForHelp()
5598 {
5600 }
5601
5607 public function getLookingForHelpAsText()
5608 {
5609 return $this->buildTextFromArray("interests_help_looking");
5610 }
5611
5618 protected function buildTextFromArray($a_attr)
5619 {
5620 $current = $this->$a_attr;
5621 if(is_array($current) && sizeof($current))
5622 {
5623 return implode(", ", $current);
5624 }
5625 }
5626
5630 protected function readMultiTextFields()
5631 {
5632 global $ilDB;
5633
5634 if(!$this->getId())
5635 {
5636 return;
5637 }
5638
5639 $set = $ilDB->query("SELECT field_id,value".
5640 " FROM usr_data_multi".
5641 " WHERE usr_id = ".$ilDB->quote($this->getId(), "integer").
5642 " ORDER BY value");
5643 while($row = $ilDB->fetchAssoc($set))
5644 {
5645 $values[$row["field_id"]][] = $row["value"];
5646 }
5647
5648 if(isset($values["interests_general"]))
5649 {
5650 $this->setGeneralInterests($values["interests_general"]);
5651 }
5652 else
5653 {
5654 $this->setGeneralInterests();
5655 }
5656 if(isset($values["interests_help_offered"]))
5657 {
5658 $this->setOfferingHelp($values["interests_help_offered"]);
5659 }
5660 else
5661 {
5662 $this->setOfferingHelp();
5663 }
5664 if(isset($values["interests_help_looking"]))
5665 {
5666 $this->setLookingForHelp($values["interests_help_looking"]);
5667 }
5668 else
5669 {
5670 $this->setLookingForHelp();
5671 }
5672 }
5673
5679 public function updateMultiTextFields($a_create = false)
5680 {
5681 global $ilDB;
5682
5683 if(!$this->getId())
5684 {
5685 return;
5686 }
5687
5688 if(!$a_create)
5689 {
5690 $this->deleteMultiTextFields();
5691 }
5692
5693 $map = array(
5694 "interests_general" => $this->getGeneralInterests(),
5695 "interests_help_offered" => $this->getOfferingHelp(),
5696 "interests_help_looking" => $this->getLookingForHelp()
5697 );
5698
5699 foreach($map as $id => $values)
5700 {
5701 if(is_array($values) && sizeof($values))
5702 {
5703 foreach($values as $value)
5704 {
5705 $value = trim($value);
5706 if($value)
5707 {
5708 $ilDB->manipulate("INSERT usr_data_multi".
5709 " (usr_id,field_id,value) VALUES".
5710 " (".$ilDB->quote($this->getId(), "integer").
5711 ",".$ilDB->quote($id, "text").
5712 ",".$ilDB->quote($value, "text").
5713 ")");
5714 }
5715 }
5716 }
5717 }
5718 }
5719
5723 protected function deleteMultiTextFields()
5724 {
5725 global $ilDB;
5726
5727 if(!$this->getId())
5728 {
5729 return;
5730 }
5731
5732 $ilDB->manipulate("DELETE FROM usr_data_multi".
5733 " WHERE usr_id = ".$ilDB->quote($this->getId(), "integer"));
5734 }
5735
5736 public static function findInterests($a_term, $a_user_id = null, $a_field_id = null)
5737 {
5738 global $ilDB;
5739
5740 $res = array();
5741
5742 $sql = "SELECT DISTINCT(value)".
5743 " FROM usr_data_multi".
5744 " WHERE ".$ilDB->like("value", "text", "%".$a_term."%");
5745 if($a_field_id)
5746 {
5747 $sql .= " AND field_id = ".$ilDB->quote($a_field_id, "text");
5748 }
5749 if($a_user_id)
5750 {
5751 $sql .= " AND usr_id <> ".$ilDB->quote($a_user_id, "integer");
5752 }
5753 $sql .= " ORDER BY value";
5754 $set = $ilDB->query($sql);
5755 while($row = $ilDB->fetchAssoc($set))
5756 {
5757 $res[] = $row["value"];
5758 }
5759
5760 return $res;
5761 }
5762} // END class ilObjUser
5763?>
$result
print $file
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
const AUTH_LOCAL
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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 toUsernameWithoutDomain($username)
Static function removes Microsoft domain name from username.
_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 _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 setLanguage($a_lng)
set language
static formatPeriod(ilDateTime $start, ilDateTime $end)
Format a period of two date Shows: 14.
static setUseRelativeDates($a_status)
set use relative dates
static formatDate(ilDateTime $date)
Format a date @access public.
@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.
Class UserMail 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.
_deleteUser($a_usr_id)
static deleteUserPortfolios($a_user_id)
Delete all portfolio data for user.
static _deleteUser($a_usr_id)
_lookupIm($a_user_id, $a_type)
Lookup IM.
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
setCurrentLanguage($a_val)
Set current language.
_lookupFields($a_user_id)
lookup fields (deprecated; use more specific methods instead)
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 _getLastHistoryDataByUserId($a_usr_id)
Returns the last used loginname and the changedate of the passed user_id.
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.
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.
_writeExternalAccount($a_usr_id, $a_ext_id)
setDelicious($a_delicious)
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 _getUserData($a_internalids)
return user data for given user ids
static _getPersonalPicturePath($a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
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...
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
getUserIdByEmail($a_email)
STATIC METHOD get the user_id of an email address.
setFirstname($a_str)
set firstname @access public
getGeneralInterests()
Get general interests.
$login
all user related data in single vars @access public
setDepartment($a_str)
set department @access public
getCountry()
Get country (free text)
_lookupLastLogin($a_user_id)
lookup last login
deletePref($a_keyword)
Deletes a userpref value of the user from the database @access public.
getInstantMessengerId($a_im_type)
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.
setDiskQuota($a_disk_quota)
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 _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
_moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
skins and styles
buildTextFromArray($a_attr)
Convert multi-text values to plain text.
_getUsersForClipboadObject($a_type, $a_id)
get all users, that have a certain object within their clipboard
static findInterests($a_term, $a_user_id=null, $a_field_id=null)
static _getAssociatedUsersOnline($a_user_id, $a_no_anonymous=false)
setExternalAccount($a_str)
set external account
setLogin($a_str)
set login / username @access public
static userExists($a_usr_ids=array())
_lookupActive($a_usr_id)
Check user account active.
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
_uploadPersonalPicture($tmp_file, $obj_id)
Create a personal picture image file from a temporary image file.
static _writePref($a_usr_id, $a_keyword, $a_value)
static _incrementLoginAttempts($a_usr_id)
hasPublicProfile()
returns true if public is profile, false otherwise
_lookupLogin($a_user_id)
lookup login
_lookupExternalAccount($a_user_id)
lookup external account for login and authmethod
_lookup($a_user_id, $a_field)
Private function for lookup methods.
getDateFormat()
get date format
_getAllUserAssignedStyles()
skins and styles
setSkin($a_str)
set user skin (template set) @access public
getHobby()
get hobby @access public
_getNumberOfUsersForStyle($a_skin, $a_style)
skins and styles
static _getUsersForFolder($ref_id, $active)
getCurrentLanguage()
returns the current language (may differ from user's pref setting!)
setSelectedCountry($a_val)
Set selected country (selection drop down)
_getFeedPass($a_user_id)
Lookup news feed password for user.
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.
static hasActiveSession($a_user_id)
Check for simultaneous login.
getUserIdByLogin($a_login)
clipboardDeleteObjectsOfType($a_type)
Delete objects of type for user.
static preloadIsDesktopItem($a_usr_id, $a_item_ids)
Preload desktop item information.
_getAllUserLogins(&$ilias)
STATIC METHOD get all user logins.
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.
_lookupFullname($a_user_id)
Lookup Full Name.
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
setComment($a_str)
set referral comment @access public
getComment()
get referral comment @access public
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
getStreet()
get street @access public
_getAllUserData($a_fields=NULL, $active=-1)
STATIC METHOD get all user data.
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)
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.
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
_lookupEmail($a_user_id)
Lookup email.
getZipcode()
get zipcode @access public
static _readUsersProfileData($a_user_ids)
STATIC METHOD get user data of selected users.
_getUserIdsByEmail($a_email)
STATIC METHOD get all user_ids of an email address.
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)
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)
isChild($a_usr_id)
_setFeedPass($a_user_id, $a_password)
Set news feed password for user.
setOfferingHelp(array $value=null)
Set help offering.
static _lookupAuthMode($a_usr_id)
lookup auth mode
_getNumberOfUsersPerAuthMode()
get number of users per auth mode
_getImportedUserId($i2_id)
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
_lookupFeedHash($a_user_id, $a_create=false)
Lookup news feed hash for user.
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
_writeAuthMode($a_usr_id, $a_auth_mode)
static _getUsersForGroup($a_mem_ids, $active=-1)
return user data for group members
setProfileIncomplete($a_prof_inc)
setTimeLimitUnlimited($a_unlimited)
static _doesLoginnameExistInHistory($a_login)
Checks wether the passed loginname already exists in history.
static _getLoginAttempts($a_usr_id)
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
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
importPersonalData($a_file, $a_profile_data, $a_settings, $a_bookmarks, $a_notes, $a_calendar)
Import personal data.
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,...
_lookupPref($a_usr_id, $a_keyword)
setLastLogin($a_str)
set user's last login @access public
writePrefs()
write all userprefs @access private
getInactivationDate()
getter for inactivation date
getDepartment()
get department @access public
assignData($a_data)
loads a record "user" from array @access public
getPersonalWorkspaceDiskQuota()
setLastPasswordChangeToNow()
_lookupClientIP($a_user_id)
Lookup client ip.
setHobby($a_str)
getLookingForHelp()
Get help looking for.
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)
setInstantMessengerId($a_im_type, $a_im_id)
static _checkExternalAuthAccount($a_auth, $a_account)
check whether external account and authentication method matches with a user
__readAppliedUsers($a_parent_id)
dropDesktopItem($a_item_id, $a_type)
drop an item from user's personal desktop
exportPersonalData()
Export personal data.
setUserDefinedData($a_data)
_getLocalAccountsForEmail($a_email)
check whether external account and authentication method matches with a user
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
_deleteAllPref($a_user_id)
Deletes a userpref value of the user from the database @access public.
getGender()
get gender @access public
getExternalAccount()
get external account
static $is_desktop_item_cache
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...
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 skinExists($skin)
Check wheter a skin exists.
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 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 getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static deliverFile($a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
Tree handler for personal workspace.
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:40
global $ilDB
global $ilUser
Definition: imgupload.php:15