00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 define ("IL_PASSWD_PLAIN", "plain");
00025 define ("IL_PASSWD_MD5", "md5");
00026 define ("IL_PASSWD_CRYPT", "crypt");
00027
00028
00029 require_once "classes/class.ilObject.php";
00030
00040 class ilObjUser extends ilObject
00041 {
00046
00047
00048 var $login;
00049
00050 var $passwd;
00051 var $passwd_type;
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 var $gender;
00069 var $utitle;
00070 var $firstname;
00071 var $lastname;
00072 var $fullname;
00073
00074
00075 var $institution;
00076 var $department;
00077 var $street;
00078 var $city;
00079 var $zipcode;
00080 var $country;
00081 var $phone_office;
00082 var $phone_home;
00083 var $phone_mobile;
00084 var $fax;
00085 var $email;
00086 var $hobby;
00087 var $matriculation;
00088 var $referral_comment;
00089 var $approve_date;
00090 var $active;
00091 var $ilinc_id;
00092 var $client_ip;
00093 var $auth_mode;
00094
00100 var $prefs;
00101
00107 var $skin;
00108
00109
00115 var $default_role;
00116
00122 var $ilias;
00123
00124
00130 function ilObjUser($a_user_id = 0, $a_call_by_reference = false)
00131 {
00132 global $ilias;
00133
00134
00135 $this->ilias =& $ilias;
00136
00137 $this->type = "usr";
00138 $this->ilObject($a_user_id, $a_call_by_reference);
00139 $this->auth_mode = "default";
00140 $this->passwd_type = IL_PASSWD_PLAIN;
00141
00142
00143
00144
00145
00146
00147
00148 if (!empty($a_user_id))
00149 {
00150 $this->setId($a_user_id);
00151 $this->read();
00152 }
00153 else
00154 {
00155
00156
00157 $this->prefs = array();
00158
00159 $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
00160
00161
00162 if (strpos($_SERVER["HTTP_USER_AGENT"],"Windows CE") > 0)
00163 {
00164 $this->skin = "pda";
00165 }
00166 else
00167 {
00168 $this->skin = $this->ilias->ini->readVariable("layout","skin");
00169 }
00170
00171 $this->prefs["skin"] = $this->skin;
00172 $this->prefs["show_users_online"] = "y";
00173
00174
00175 $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
00176 }
00177 }
00178
00183 function read()
00184 {
00185 global $ilErr;
00186
00187
00188 $q = "SELECT * FROM usr_data ".
00189 "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
00190 "WHERE usr_data.usr_id='".$this->id."'";
00191 $r = $this->ilias->db->query($q);
00192
00193 if ($r->numRows() > 0)
00194 {
00195 $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00196
00197
00198
00199 if ($data["passwd"] == "" && $data["i2passwd"] != "")
00200 {
00201 $data["passwd_type"] = IL_PASSWD_CRYPT;
00202 $data["passwd"] = $data["i2passwd"];
00203 }
00204 else
00205 {
00206 $data["passwd_type"] = IL_PASSWD_MD5;
00207
00208 }
00209 unset($data["i2passw"]);
00210
00211
00212
00213 $this->assignData($data);
00214
00215
00216 $this->readPrefs();
00217
00218
00219 if ($this->prefs["language"] == "")
00220 {
00221 $this->prefs["language"] = $this->oldPrefs["language"];
00222 }
00223
00224
00225 if ($this->prefs["skin"] == "" || file_exists($this->ilias->tplPath."/".$this->prefs["skin"]) == false)
00226 {
00227 $this->prefs["skin"] = $this->oldPrefs["skin"];
00228 }
00229
00230
00231 if (strpos($_SERVER["HTTP_USER_AGENT"],"Windows CE") > 0)
00232 {
00233 $this->skin = "pda";
00234 }
00235 else
00236 {
00237 $this->skin = $this->prefs["skin"];
00238 }
00239
00240
00241 if ($this->prefs["style"] == "" || file_exists($this->ilias->tplPath."/".$this->skin."/".$this->prefs["style"].".css") == false)
00242 {
00243
00244 $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
00245 }
00246
00247 if (empty($this->prefs["hits_per_page"]))
00248 {
00249 $this->prefs["hits_per_page"] = 10;
00250 }
00251
00252 }
00253 else
00254 {
00255 $ilErr->raiseError("<b>Error: There is no dataset with id ".$this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
00256 }
00257
00258 parent::read();
00259 }
00260
00266 function assignData($a_data)
00267 {
00268 global $ilErr;
00269
00270
00271 $this->setLogin($a_data["login"]);
00272 if (! $a_data["passwd_type"])
00273 {
00274 $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
00275 $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
00276 .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
00277 }
00278
00279 if ($a_data["passwd"] != "********")
00280 {
00281 $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
00282 }
00283
00284 $this->setGender($a_data["gender"]);
00285 $this->setUTitle($a_data["title"]);
00286 $this->setFirstname($a_data["firstname"]);
00287 $this->setLastname($a_data["lastname"]);
00288 $this->setFullname();
00289
00290
00291 $this->setInstitution($a_data["institution"]);
00292 $this->setDepartment($a_data["department"]);
00293 $this->setStreet($a_data["street"]);
00294 $this->setCity($a_data["city"]);
00295 $this->setZipcode($a_data["zipcode"]);
00296 $this->setCountry($a_data["country"]);
00297 $this->setPhoneOffice($a_data["phone_office"]);
00298 $this->setPhoneHome($a_data["phone_home"]);
00299 $this->setPhoneMobile($a_data["phone_mobile"]);
00300 $this->setFax($a_data["fax"]);
00301 $this->setMatriculation($a_data["matriculation"]);
00302 $this->setEmail($a_data["email"]);
00303 $this->setHobby($a_data["hobby"]);
00304 $this->setClientIP($a_data["client_ip"]);
00305
00306
00307 $this->setLastLogin($a_data["last_login"]);
00308 $this->setLastUpdate($a_data["last_update"]);
00309 $this->create_date = $a_data["create_date"];
00310 $this->setComment($a_data["referral_comment"]);
00311 $this->approve_date = $a_data["approve_date"];
00312 $this->active = $a_data["active"];
00313 $this->accept_date = $a_data["agree_date"];
00314
00315
00316 $this->setTimeLimitOwner($a_data["time_limit_owner"]);
00317 $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
00318 $this->setTimeLimitFrom($a_data["time_limit_from"]);
00319 $this->setTimeLimitUntil($a_data["time_limit_until"]);
00320 $this->setTimeLimitMessage($a_data['time_limit_message']);
00321
00322
00323 $this->setiLincData($a_data['ilinc_id'],$a_data['ilinc_login'],$a_data['ilinc_passwd']);
00324
00325
00326 $this->setAuthMode($a_data['auth_mode']);
00327 }
00328
00335 function saveAsNew($a_from_formular = true)
00336 {
00337 global $ilErr;
00338
00339 switch ($this->passwd_type)
00340 {
00341 case IL_PASSWD_PLAIN:
00342 $pw_field = "passwd";
00343 $pw_value = md5($this->passwd);
00344 break;
00345
00346 case IL_PASSWD_MD5:
00347 $pw_field = "passwd";
00348 $pw_value = $this->passwd;
00349 break;
00350
00351 case IL_PASSWD_CRYPT:
00352 $pw_field = "i2passwd";
00353 $pw_value = $this->passwd;
00354 break;
00355
00356 default :
00357 $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".$this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
00358 }
00359
00360 if ($a_from_formular)
00361 {
00362 $q = "INSERT INTO usr_data "
00363 . "(usr_id,login,".$pw_field.",firstname,lastname,title,gender,"
00364 . "email,hobby,institution,department,street,city,zipcode,country,"
00365 . "phone_office,phone_home,phone_mobile,fax,last_login,last_update,create_date,"
00366 . "referral_comment,matriculation,client_ip, approve_date,active,"
00367 . "time_limit_unlimited,time_limit_until,time_limit_from,time_limit_owner,auth_mode) "
00368 . "VALUES "
00369 . "('".$this->id."','".$this->login."','".$pw_value."', "
00370 . "'".ilUtil::addSlashes($this->firstname)."','".ilUtil::addSlashes($this->lastname)."', "
00371 . "'".ilUtil::addSlashes($this->utitle)."','".ilUtil::addSlashes($this->gender)."', "
00372 . "'".ilUtil::addSlashes($this->email)."','".ilUtil::addSlashes($this->hobby)."', "
00373 . "'".ilUtil::addSlashes($this->institution)."','".ilUtil::addSlashes($this->department)."', "
00374 . "'".ilUtil::addSlashes($this->street)."', "
00375 . "'".ilUtil::addSlashes($this->city)."','".ilUtil::addSlashes($this->zipcode)."','".ilUtil::addSlashes($this->country)."', "
00376 . "'".ilUtil::addSlashes($this->phone_office)."','".ilUtil::addSlashes($this->phone_home)."', "
00377 . "'".ilUtil::addSlashes($this->phone_mobile)."','".ilUtil::addSlashes($this->fax)."', 0, now(), now(), "
00378 . "'".ilUtil::addSlashes($this->referral_comment)."', '". ilUtil::addSlashes($this->matriculation) . "', '". ilUtil::addSlashes($this->client_ip) . "', '" .$this->approve_date."', '".$this->active."', "
00379 . "'".$this->getTimeLimitUnlimited()."','" . $this->getTimeLimitUntil()."','".$this->getTimeLimitFrom()."','".$this->getTimeLimitOwner()."', "
00380 . "'".$this->getAuthMode()."')";
00381 }
00382 else
00383 {
00384 $q = "INSERT INTO usr_data ".
00385 "(usr_id,login,".$pw_field.",firstname,lastname,title,gender,"
00386 . "email,hobby,institution,department,street,city,zipcode,country,"
00387 . "phone_office,phone_home,phone_mobile,fax,last_login,last_update,create_date,"
00388 . "referral_comment,matriculation,client_ip, approve_date,active,"
00389 . "time_limit_unlimited,time_limit_until,time_limit_from,time_limit_owner) "
00390 . "VALUES "
00391 . "('".$this->id."','".$this->login."','".$pw_value."', "
00392 . "'".ilUtil::prepareDBString($this->firstname)."','".ilUtil::prepareDBString($this->lastname)."', "
00393 . "'".ilUtil::prepareDBString($this->utitle)."','".ilUtil::prepareDBString($this->gender)."', "
00394 . "'".ilUtil::prepareDBString($this->email)."','".ilUtil::prepareDBString($this->hobby)."', "
00395 . "'".ilUtil::prepareDBString($this->institution)."','".ilUtil::prepareDBString($this->department)."', "
00396 . "'".ilUtil::prepareDBString($this->street)."', "
00397 . "'".ilUtil::prepareDBString($this->city)."','".ilUtil::prepareDBString($this->zipcode)."','".ilUtil::prepareDBString($this->country)."', "
00398 . "'".ilUtil::prepareDBString($this->phone_office)."','".ilUtil::prepareDBString($this->phone_home)."', "
00399 . "'".ilUtil::prepareDBString($this->phone_mobile)."','".ilUtil::prepareDBString($this->fax)."', 0, now(), now(), "
00400 . "'".ilUtil::prepareDBString($this->referral_comment)."', '".ilUtil::prepareDBString($this->matriculation)."', '".ilUtil::prepareDBString($this->client_ip)."', '".$this->approve_date."','".$this->active."', "
00401 . "'".$this->getTimeLimitUnlimited()."','".$this->getTimeLimitUntil()."','".$this->getTimeLimitFrom()."','".$this->getTimeLimitOwner()."'"
00402 . ")";
00403 }
00404
00405 $this->ilias->db->query($q);
00406
00407
00408 include_once ("classes/class.ilMailbox.php");
00409 $mbox = new ilMailbox($this->id);
00410 $mbox->createDefaultFolder();
00411
00412 include_once "classes/class.ilMailOptions.php";
00413 $mail_options = new ilMailOptions($this->id);
00414 $mail_options->createMailOptionsEntry();
00415
00416
00417 include_once "classes/class.ilBookmarkFolder.php";
00418 $bmf = new ilBookmarkFolder(0, $this->id);
00419 $bmf->createNewBookmarkTree();
00420
00421 }
00422
00427 function update()
00428 {
00429 global $ilErr;
00430
00431
00432
00433 $this->syncActive();
00434
00435 $pw_udpate = '';
00436 switch ($this->passwd_type)
00437 {
00438 case IL_PASSWD_PLAIN:
00439 $pw_update = "i2passwd='', passwd='".md5($this->passwd)."'";
00440 break;
00441
00442 case IL_PASSWD_MD5:
00443 $pw_update = "i2passwd='', passwd='".$this->passwd."'";
00444 break;
00445
00446 case IL_PASSWD_CRYPT:
00447 $pw_update = "passwd='', i2passwd='".$this->passwd."'";
00448 break;
00449
00450 default :
00451 $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
00452 }
00453 $q = "UPDATE usr_data SET ".
00454 "gender='".$this->gender."', ".
00455 "title='".ilUtil::prepareDBString($this->utitle)."', ".
00456 "firstname='".ilUtil::prepareDBString($this->firstname)."', ".
00457 "lastname='".ilUtil::prepareDBString($this->lastname)."', ".
00458 "email='".ilUtil::prepareDBString($this->email)."', ".
00459 "hobby='".ilUtil::prepareDBString($this->hobby)."', ".
00460 "institution='".ilUtil::prepareDBString($this->institution)."', ".
00461 "department='".ilUtil::prepareDBString($this->department)."', ".
00462 "street='".ilUtil::prepareDBString($this->street)."', ".
00463 "city='".ilUtil::prepareDBString($this->city)."', ".
00464 "zipcode='".ilUtil::prepareDBString($this->zipcode)."', ".
00465 "country='".ilUtil::prepareDBString($this->country)."', ".
00466 "phone_office='".ilUtil::prepareDBString($this->phone_office)."', ".
00467 "phone_home='".ilUtil::prepareDBString($this->phone_home)."', ".
00468 "phone_mobile='".ilUtil::prepareDBString($this->phone_mobile)."', ".
00469 "fax='".ilUtil::prepareDBString($this->fax)."', ".
00470 "referral_comment='".ilUtil::prepareDBString($this->referral_comment)."', ".
00471 "matriculation='".ilUtil::prepareDBString($this->matriculation)."', ".
00472 "client_ip='".ilUtil::prepareDBString($this->client_ip)."', ".
00473 "approve_date='".ilUtil::prepareDBString($this->approve_date)."', ".
00474 "active='".ilUtil::prepareDBString($this->active)."', ".
00475 "time_limit_owner='".ilUtil::prepareDBString($this->getTimeLimitOwner())."', ".
00476 "time_limit_unlimited='".ilUtil::prepareDBString($this->getTimeLimitUnlimited())."', ".
00477 "time_limit_from='".ilUtil::prepareDBString($this->getTimeLimitFrom())."', ".
00478 "time_limit_until='".ilUtil::prepareDBString($this->getTimeLimitUntil())."', ".
00479 "time_limit_message='".$this->getTimeLimitMessage()."', ".
00480 "auth_mode='".ilUtil::prepareDBString($this->getAuthMode())."', ".
00481 $pw_update.", ".
00482 "last_update=now(), ".
00483 "ilinc_id='".ilUtil::prepareDBString($this->ilinc_id)."', ".
00484 "ilinc_login='".ilUtil::prepareDBString($this->ilinc_login)."', ".
00485 "ilinc_passwd='".ilUtil::prepareDBString($this->ilinc_passwd)."' ".
00486 "WHERE usr_id='".$this->id."'";
00487
00488 $this->ilias->db->query($q);
00489
00490 $this->writePrefs();
00491
00492 parent::update();
00493 parent::updateOwner();
00494
00495 $this->read();
00496
00497 return true;
00498 }
00499
00503 function writeAccepted()
00504 {
00505 global $ilDB;
00506
00507 $q = "UPDATE usr_data SET agree_date = now()".
00508 "WHERE usr_id = ".$ilDB->quote($this->getId());
00509 $ilDB->query($q);
00510
00511 }
00512
00516 function _lookupName($a_user_id)
00517 {
00518 global $ilDB;
00519
00520 $q = "SELECT firstname, lastname, title FROM usr_data".
00521 " WHERE usr_id =".$ilDB->quote($a_user_id);
00522 $user_set = $ilDB->query($q);
00523 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00524 return array("user_id" => $a_user_id,
00525 "firstname" => $user_rec["firstname"],
00526 "lastname" => $user_rec["lastname"],
00527 "title" => $user_rec["title"]);
00528 }
00529
00533 function _lookupLogin($a_user_id)
00534 {
00535 global $ilDB;
00536
00537 $q = "SELECT login FROM usr_data".
00538 " WHERE usr_id =".$ilDB->quote($a_user_id);
00539 $user_set = $ilDB->query($q);
00540 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00541 return $user_rec["login"];
00542 }
00543
00547 function _lookupId($a_user_str)
00548 {
00549 global $ilDB;
00550
00551 $q = "SELECT usr_id FROM usr_data".
00552 " WHERE login =".$ilDB->quote($a_user_str);
00553 $user_set = $ilDB->query($q);
00554 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00555 return $user_rec["usr_id"];
00556 }
00557
00558
00564 function refreshLogin()
00565 {
00566 $q = "UPDATE usr_data SET ".
00567 "last_login = now() ".
00568 "WHERE usr_id = '".$this->id."'";
00569
00570 $this->ilias->db->query($q);
00571 }
00572
00581 function updatePassword($a_old, $a_new1, $a_new2)
00582 {
00583 if (func_num_args() != 3)
00584 {
00585 return false;
00586 }
00587
00588 if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
00589 {
00590 return false;
00591 }
00592
00593 if ($a_new1 != $a_new2)
00594 {
00595 return false;
00596 }
00597
00598
00599 if ($a_new1 == "" || $a_old == "")
00600 {
00601 return false;
00602 }
00603
00604
00605 switch ($this->passwd_type)
00606 {
00607 case IL_PASSWD_PLAIN:
00608 if ($a_old != $this->passwd)
00609 {
00610 return false;
00611 }
00612 break;
00613
00614 case IL_PASSWD_MD5:
00615 if (md5($a_old) != $this->passwd)
00616 {
00617 return false;
00618 }
00619 break;
00620
00621 case IL_PASSWD_CRYPT:
00622 if (_makeIlias2Password($a_old) != $this->passwd)
00623 {
00624 return false;
00625 }
00626 break;
00627 }
00628
00629
00630 $this->passwd = md5($a_new1);
00631 $this->passwd_type = IL_PASSWD_MD5;
00632
00633 $q = "UPDATE usr_data SET ".
00634 "passwd='".$this->passwd."' ".
00635 "WHERE usr_id='".$this->id."'";
00636 $this->ilias->db->query($q);
00637
00638 return true;
00639 }
00640
00648 function resetPassword($a_new1, $a_new2)
00649 {
00650 if (func_num_args() != 2)
00651 {
00652 return false;
00653 }
00654
00655 if (!isset($a_new1) or !isset($a_new2))
00656 {
00657 return false;
00658 }
00659
00660 if ($a_new1 != $a_new2)
00661 {
00662 return false;
00663 }
00664
00665
00666 $this->passwd = md5($a_new1);
00667 $this->passwd_type = IL_PASSWD_MD5;
00668
00669 $q = "UPDATE usr_data SET ".
00670 "passwd='".$this->passwd."' ".
00671 "WHERE usr_id='".$this->id."'";
00672 $this->ilias->db->query($q);
00673
00674 return true;
00675 }
00676
00680 function _makeIlias2Password($a_passwd)
00681 {
00682 return (crypt($a_passwd,substr($a_passwd,0,2)));
00683 }
00684
00688 function _lookupHasIlias2Password($a_user_login)
00689 {
00690 global $ilias, $ilDB;
00691
00692 $q = "SELECT i2passwd FROM usr_data ".
00693 "WHERE login = ".$ilDB->quote($a_user_login)."";
00694 $user_set = $ilias->db->query($q);
00695
00696 if ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
00697 {
00698 if ($user_rec["i2passwd"] != "")
00699 {
00700 return true;
00701 }
00702 }
00703
00704 return false;
00705 }
00706
00707 function _switchToIlias3Password($a_user, $a_pw)
00708 {
00709 global $ilias;
00710
00711 $q = "SELECT i2passwd FROM usr_data ".
00712 "WHERE login = '".$a_user."'";
00713 $user_set = $ilias->db->query($q);
00714
00715 if ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
00716 {
00717 if ($user_rec["i2passwd"] == ilObjUser::_makeIlias2Password($a_pw))
00718 {
00719 $q = "UPDATE usr_data SET passwd='".md5($a_pw)."', i2passwd=''".
00720 "WHERE login = '".$a_user."'";
00721 $ilias->db->query($q);
00722 return true;
00723 }
00724 }
00725
00726 return false;
00727 }
00728
00735 function updateLogin($a_login)
00736 {
00737 if (func_num_args() != 1)
00738 {
00739 return false;
00740 }
00741
00742 if (!isset($a_login))
00743 {
00744 return false;
00745 }
00746
00747
00748 $this->login = $a_login;
00749
00750 $q = "UPDATE usr_data SET ".
00751 "login='".$this->login."' ".
00752 "WHERE usr_id='".$this->id."'";
00753 $this->ilias->db->query($q);
00754
00755 return true;
00756 }
00757
00764 function writePref($a_keyword, $a_value)
00765 {
00766 ilObjUser::_writePref($this->id, $a_keyword, $a_value);
00767 $this->setPref($a_keyword, $a_value);
00768 }
00769
00770
00771 function _writePref($a_usr_id, $a_keyword, $a_value)
00772 {
00773 global $ilDB;
00774
00775
00776 $q = "DELETE FROM usr_pref ".
00777 "WHERE usr_id='".$a_usr_id."' ".
00778 "AND keyword='".$a_keyword."'";
00779 $ilDB->query($q);
00780
00781
00782 if ($a_value != "")
00783 {
00784 $q = "INSERT INTO usr_pref ".
00785 "(usr_id, keyword, value) ".
00786 "VALUES ".
00787 "('".$a_usr_id."', '".$a_keyword."', '".$a_value."')";
00788
00789 $ilDB->query($q);
00790 }
00791 }
00792
00797 function writePrefs()
00798 {
00799
00800 $q = "DELETE FROM usr_pref ".
00801 "WHERE usr_id='".$this->id."'";
00802 $this->ilias->db->query($q);
00803
00804 foreach ($this->prefs as $keyword => $value)
00805 {
00806
00807 $q = "INSERT INTO usr_pref ".
00808 "(usr_id, keyword, value) ".
00809 "VALUES ".
00810 "('".$this->id."', '".$keyword."', '".$value."')";
00811 $this->ilias->db->query($q);
00812 }
00813 }
00814
00815
00816
00817
00818
00819
00820
00821
00822
00829 function setPref($a_keyword, $a_value)
00830 {
00831 if ($a_keyword != "")
00832 {
00833 $this->prefs[$a_keyword] = $a_value;
00834 }
00835 }
00836
00842 function getPref($a_keyword)
00843 {
00844 return $this->prefs[$a_keyword];
00845 }
00846
00852 function readPrefs()
00853 {
00854 if (is_array($this->prefs))
00855 {
00856 $this->oldPrefs = $this->prefs;
00857 }
00858
00859 $this->prefs = array();
00860
00861 $q = "SELECT * FROM usr_pref WHERE usr_id='".$this->id."'";
00862
00863 $r = $this->ilias->db->query($q);
00864
00865 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
00866 {
00867 $this->prefs[$row["keyword"]] = $row["value"];
00868 }
00869
00870 return $r->numRows();
00871 }
00872
00873
00874
00875
00876
00877
00878
00879
00880
00886 function delete()
00887 {
00888 global $rbacadmin;
00889
00890
00891 include_once ("classes/class.ilMailbox.php");
00892 $mailbox = new ilMailbox($this->getId());
00893 $mailbox->delete();
00894 $mailbox->updateMailsOfDeletedUser();
00895
00896
00897 $this->ilias->db->query("DELETE FROM usr_data WHERE usr_id='".$this->getId()."'");
00898
00899
00900 $this->ilias->db->query("DELETE FROM usr_pref WHERE usr_id='".$this->getId()."'");
00901
00902
00903 $this->ilias->db->query("DELETE FROM usr_session WHERE user_id='".$this->getId()."'");
00904
00905
00906 $rbacadmin->removeUser($this->getId());
00907
00908
00909
00910 $q = "DELETE FROM bookmark_tree WHERE tree='".$this->getId()."'";
00911 $this->ilias->db->query($q);
00912
00913 $q = "DELETE FROM bookmark_data WHERE user_id='".$this->getId()."'";
00914 $this->ilias->db->query($q);
00915
00916
00917 include_once './classes/class.ilObjForum.php';
00918
00919 ilObjForum::_deleteUser($this->getId());
00920
00921
00922 include_once './classes/class.ilLinkCheckNotify.php';
00923
00924 ilLinkCheckNotify::_deleteUser($this->getId());
00925
00926
00927 include_once './course/classes/class.ilCourseObjectiveResult.php';
00928
00929 ilCourseObjectiveResult::_deleteAll($this->getId());
00930
00931
00932 $q = "DELETE FROM grp_registration WHERE user_id='".$this->getId()."'";
00933 $this->ilias->db->query($q);
00934
00935
00936 parent::delete();
00937 return true;
00938 }
00939
00949 function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
00950 {
00951 $this->fullname = "";
00952
00953 if ($a_title)
00954 {
00955 $fullname = $a_title." ";
00956 }
00957 elseif ($this->utitle)
00958 {
00959 $this->fullname = $this->utitle." ";
00960 }
00961
00962 if ($a_firstname)
00963 {
00964 $fullname .= $a_firstname." ";
00965 }
00966 elseif ($this->firstname)
00967 {
00968 $this->fullname .= $this->firstname." ";
00969 }
00970
00971 if ($a_lastname)
00972 {
00973 return $fullname.$a_lastname;
00974 }
00975
00976 $this->fullname .= $this->lastname;
00977 }
00978
00993 function getFullname($a_max_strlen = 0)
00994 {
00995 if (!$a_max_strlen)
00996 {
00997 return ilUtil::stripSlashes($this->fullname);
00998 }
00999
01000 if (strlen($this->fullname) <= $a_max_strlen)
01001 {
01002 return ilUtil::stripSlashes($this->fullname);
01003 }
01004
01005 if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
01006 {
01007 return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
01008 }
01009
01010 if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
01011 {
01012 return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
01013 }
01014
01015 if ((strlen($this->lastname) + 3) <= $a_max_strlen)
01016 {
01017 return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
01018 }
01019
01020 return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
01021 }
01022
01023
01029 function getLastVisitedLessons()
01030 {
01031
01032 $q = "SELECT * FROM lo_access ".
01033 "WHERE usr_id='".$this->id."' ".
01034 "ORDER BY timestamp DESC";
01035 $rst = $this->ilias->db->query($q);
01036
01037
01038 $result = array();
01039 while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
01040 {
01041 $result[] = array(
01042 "timestamp" => $record->timestamp,
01043 "usr_id" => $record->usr_id,
01044 "lm_id" => $record->lm_id,
01045 "obj_id" => $record->obj_id,
01046 "lm_title" => $record->lm_title);
01047 }
01048 return $result;
01049 }
01050
01051
01057 function getLessons()
01058 {
01059
01060 $q = "SELECT * FROM lo_access ".
01061 "WHERE usr_id='".$this->id."' ";
01062 $rst = $this->ilias->db->query($q);
01063
01064
01065 $result = array();
01066 while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
01067 {
01068 $result[] = array(
01069 "timestamp" => $record->timestamp,
01070 "usr_id" => $record->usr_id,
01071 "lm_id" => $record->lm_id,
01072 "obj_id" => $record->obj_id,
01073 "lm_title" => $record->lm_title);
01074 }
01075 return $result;
01076 }
01077
01078
01085 function getCourses()
01086 {
01087 global $lng;
01088
01089
01090 $courses = array();
01091
01092 $sql = "SELECT * FROM courses
01093 WHERE user_fk='".$this->id."'
01094 AND read=1";
01095 $courses[] = array(
01096 "id" => 1,
01097 "title" => "Course 1",
01098 "desc" => "description of course one",
01099 "content" => "This is Course One",
01100 "datetime" => date("Y-m-d")
01101 );
01102 return $courses;
01103 }
01104
01111 function getLiterature()
01112 {
01113
01114 $literature = array();
01115
01116 $sql = "SELECT * FROM literature";
01117
01118 $literature[] = array(
01119 "id" => 1,
01120 "url" => "http://www.gutenberg.de",
01121 "desc" => "project gutenberg",
01122 );
01123
01124 return $literature;
01125 }
01126
01130 function hasAcceptedUserAgreement()
01131 {
01132 if ($this->accept_date != "0000-00-00 00:00:00" || $this->login == "root")
01133 {
01134 return true;
01135 }
01136 return false;
01137 }
01138
01144 function setLogin($a_str)
01145 {
01146 $this->login = $a_str;
01147 }
01148
01153 function getLogin()
01154 {
01155 return $this->login;
01156 }
01157
01163 function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
01164 {
01165 $this->passwd = $a_str;
01166 $this->passwd_type = $a_type;
01167 }
01168
01176 function getPasswd()
01177 {
01178 return $this->passwd;
01179 }
01186 function getPasswdType()
01187 {
01188 return $this->passwd_type;
01189 }
01190
01196 function setGender($a_str)
01197 {
01198 $this->gender = substr($a_str,-1);
01199 }
01200
01205 function getGender()
01206 {
01207 return $this->gender;
01208 }
01209
01217 function setUTitle($a_str)
01218 {
01219 $this->utitle = $a_str;
01220 }
01221
01228 function getUTitle()
01229 {
01230 return $this->utitle;
01231 }
01232
01238 function setFirstname($a_str)
01239 {
01240 $this->firstname = $a_str;
01241 }
01242
01247 function getFirstname()
01248 {
01249 return $this->firstname;
01250 }
01251
01257 function setLastname($a_str)
01258 {
01259 $this->lastname = $a_str;
01260 }
01261
01266 function getLastname()
01267 {
01268 return $this->lastname;
01269 }
01270
01276 function setInstitution($a_str)
01277 {
01278 $this->institution = $a_str;
01279 }
01280
01285 function getInstitution()
01286 {
01287 return $this->institution;
01288 }
01289
01295 function setDepartment($a_str)
01296 {
01297 $this->department = $a_str;
01298 }
01299
01304 function getDepartment()
01305 {
01306 return $this->department;
01307 }
01308
01314 function setStreet($a_str)
01315 {
01316 $this->street = $a_str;
01317 }
01318
01323 function getStreet()
01324 {
01325 return $this->street;
01326 }
01327
01333 function setCity($a_str)
01334 {
01335 $this->city = $a_str;
01336 }
01337
01342 function getCity()
01343 {
01344 return $this->city;
01345 }
01346
01352 function setZipcode($a_str)
01353 {
01354 $this->zipcode = $a_str;
01355 }
01356
01361 function getZipcode()
01362 {
01363 return $this->zipcode;
01364 }
01365
01371 function setCountry($a_str)
01372 {
01373 $this->country = $a_str;
01374 }
01375
01380 function getCountry()
01381 {
01382 return $this->country;
01383 }
01384
01390 function setPhoneOffice($a_str)
01391 {
01392 $this->phone_office = $a_str;
01393 }
01394
01399 function getPhoneOffice()
01400 {
01401 return $this->phone_office;
01402 }
01403
01409 function setPhoneHome($a_str)
01410 {
01411 $this->phone_home = $a_str;
01412 }
01413
01418 function getPhoneHome()
01419 {
01420 return $this->phone_home;
01421 }
01422
01428 function setPhoneMobile($a_str)
01429 {
01430 $this->phone_mobile = $a_str;
01431 }
01432
01437 function getPhoneMobile()
01438 {
01439 return $this->phone_mobile;
01440 }
01441
01447 function setFax($a_str)
01448 {
01449 $this->fax = $a_str;
01450 }
01451
01456 function getFax()
01457 {
01458 return $this->fax;
01459 }
01460
01466 function setClientIP($a_str)
01467 {
01468 $this->client_ip = $a_str;
01469 }
01470
01475 function getClientIP()
01476 {
01477 return $this->client_ip;
01478 }
01479
01485 function setMatriculation($a_str)
01486 {
01487 $this->matriculation = $a_str;
01488 }
01489
01494 function getMatriculation()
01495 {
01496 return $this->matriculation;
01497 }
01498
01504 function setEmail($a_str)
01505 {
01506 $this->email = $a_str;
01507 }
01508
01513 function getEmail()
01514 {
01515 return $this->email;
01516 }
01517
01523 function setHobby($a_str)
01524 {
01525 $this->hobby = $a_str;
01526 }
01527
01532 function getHobby()
01533 {
01534 return $this->hobby;
01535 }
01536
01542 function setLanguage($a_str)
01543 {
01544 $this->setPref("language",$a_str);
01545 unset($_SESSION['lang']);
01546 }
01547
01553 function getLanguage()
01554 {
01555 return $this->prefs["language"];
01556 }
01557
01562 function getCurrentLanguage()
01563 {
01564 return $_SESSION['lang'];
01565 }
01566
01572 function setLastLogin($a_str)
01573 {
01574 $this->last_login = $a_str;
01575 }
01576
01582 function getLastLogin()
01583 {
01584 return $this->last_login;
01585 }
01586
01592 function setLastUpdate($a_str)
01593 {
01594 $this->last_update = $a_str;
01595 }
01596 function getLastUpdate()
01597 {
01598 return $this->last_update;
01599 }
01600
01606 function setComment($a_str)
01607 {
01608 $this->referral_comment = $a_str;
01609 }
01610
01615 function getComment()
01616 {
01617 return $this->referral_comment;
01618 }
01619
01626 function setApproveDate($a_str)
01627 {
01628 $this->approve_date = $a_str;
01629 }
01630
01636 function getApproveDate()
01637 {
01638 return $this->approve_date;
01639 }
01640
01647 function setActive($a_active, $a_owner = 6)
01648 {
01649 if (empty($a_owner))
01650 {
01651 $a_owner = 0;
01652 }
01653
01654 if ($a_active)
01655 {
01656 $this->active = 1;
01657 $this->setApproveDate(date('Y-m-d H:i:s'));
01658 $this->setOwner($a_owner);
01659 }
01660 else
01661 {
01662 $this->active = 0;
01663 $this->setApproveDate('0000-00-00 00:00:00');
01664 $this->setOwner(0);
01665 }
01666 }
01667
01672 function getActive()
01673 {
01674 return $this->active;
01675 }
01676
01682 function syncActive()
01683 {
01684 $storedActive = 0;
01685 if ($this->getStoredActive($this->id))
01686 {
01687 $storedActive = 1;
01688 }
01689
01690 $currentActive = 0;
01691 if ($this->active)
01692 {
01693 $currentActive = 1;
01694 }
01695
01696 if ((!empty($storedActive) && empty($currentActive)) ||
01697 (empty($storedActive) && !empty($currentActive)))
01698 {
01699 $this->setActive($currentActive, $this->getUserIdByLogin($this->ilias->auth->getUsername()));
01700 }
01701 }
01702
01709 function getStoredActive($a_id)
01710 {
01711 global $ilias;
01712
01713 $query = "SELECT active FROM usr_data ".
01714 "WHERE usr_id = '".$a_id."'";
01715
01716 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
01717
01718 return $row->active ? true : false;
01719 }
01720
01726 function setSkin($a_str)
01727 {
01728
01729 $this->skin = $a_str;
01730 }
01731
01732 function setTimeLimitOwner($a_owner)
01733 {
01734 $this->time_limit_owner = $a_owner;
01735 }
01736 function getTimeLimitOwner()
01737 {
01738 return $this->time_limit_owner;
01739 }
01740 function setTimeLimitFrom($a_from)
01741 {
01742 $this->time_limit_from = $a_from;
01743 }
01744 function getTimeLimitFrom()
01745 {
01746 return $this->time_limit_from ? $this->time_limit_from : time();
01747 }
01748 function setTimeLimitUntil($a_until)
01749 {
01750 $this->time_limit_until = $a_until;
01751 }
01752 function getTimeLimitUntil()
01753 {
01754 return $this->time_limit_until ? $this->time_limit_until : time();
01755 }
01756 function setTimeLimitUnlimited($a_unlimited)
01757 {
01758 $this->time_limit_unlimited = $a_unlimited;
01759 }
01760 function getTimeLimitUnlimited()
01761 {
01762 return $this->time_limit_unlimited;
01763 }
01764 function setTimeLimitMessage($a_time_limit_message)
01765 {
01766 return $this->time_limit_message = $a_time_limit_message;
01767 }
01768 function getTimeLimitMessage()
01769 {
01770 return $this->time_limit_message;
01771 }
01772
01773
01774 function checkTimeLimit()
01775 {
01776 if($this->getTimeLimitUnlimited())
01777 {
01778 return true;
01779 }
01780 if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
01781 {
01782 return true;
01783 }
01784 return false;
01785 }
01786
01787 function &getAppliedUsers()
01788 {
01789 $this->applied_users = array();
01790 $this->__readAppliedUsers($this->getId());
01791
01792 return $this->applied_users ? $this->applied_users : array();
01793 }
01794
01795 function isChild($a_usr_id)
01796 {
01797 if($a_usr_id == $this->getId())
01798 {
01799 return true;
01800 }
01801
01802 $this->applied_users = array();
01803 $this->__readAppliedUsers($this->getId());
01804
01805 return in_array($a_usr_id,$this->applied_users);
01806 }
01807
01808 function __readAppliedUsers($a_parent_id)
01809 {
01810 $query = "SELECT usr_id FROM usr_data ".
01811 "WHERE time_limit_owner = '".$a_parent_id."'";
01812
01813 $res = $this->ilias->db->query($query);
01814 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01815 {
01816 $this->applied_users[] = $row->usr_id;
01817
01818
01819 $this->__readAppliedUsers($row->usr_id);
01820 }
01821 return true;
01822 }
01823
01824
01825
01826
01827
01828 function checkUserId()
01829 {
01830 $r = $this->ilias->db->query("SELECT usr_id FROM usr_data WHERE login='".$this->ilias->auth->getUsername()."'");
01831
01832 if ($r->numRows() > 0)
01833 {
01834 $data = $r->fetchRow();
01835 $this->id = $data[0];
01836
01837 return $this->id;
01838 }
01839
01840 return false;
01841 }
01842
01843
01844
01845
01846
01847
01848 function isCurrentUserActive()
01849 {
01850 $r = $this->ilias->db->query("SELECT active FROM usr_data WHERE login='".$this->ilias->auth->getUsername()."'");
01851
01852 if ($r->numRows() > 0)
01853 {
01854 $data = $r->fetchRow();
01855 if (!empty($data[0]))
01856 {
01857 return true;
01858 }
01859 }
01860
01861 return false;
01862 }
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872 function getUserIdByLogin($a_login)
01873 {
01874 global $ilias;
01875
01876 $query = "SELECT usr_id FROM usr_data ".
01877 "WHERE login = '".$a_login."'";
01878
01879 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
01880
01881 return $row->usr_id ? $row->usr_id : 0;
01882 }
01883
01892 function _getUserIdsByEmail($a_email)
01893 {
01894 global $ilias;
01895 $query = "SELECT login FROM usr_data ".
01896 "WHERE email = '".$a_email."' and active=1";
01897
01898 $res = $ilias->db->query($query);
01899 $ids = array ();
01900 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01901 {
01902 $ids[] = $row->login;
01903 }
01904
01905 return $ids;
01906 }
01907
01908
01909
01918 function getUserIdByEmail($a_email)
01919 {
01920 $query = "SELECT usr_id FROM usr_data ".
01921 "WHERE email = '".$a_email."'";
01922
01923 $row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
01924 return $row->usr_id ? $row->usr_id : 0;
01925 }
01926
01927
01928
01929
01930
01931
01932
01933
01934
01935 function getLoginByUserId($a_userid)
01936 {
01937 global $ilias;
01938
01939 $query = "SELECT login FROM usr_data ".
01940 "WHERE usr_id = '".$a_userid."'";
01941
01942 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
01943
01944 return $row->login ? $row->login : false;
01945 }
01946
01954 function searchUsers($a_search_str, $active = 1)
01955 {
01956
01957 global $ilias;
01958
01959
01960
01961 if (strtolower(substr($a_search_str, 0, 5)) == "role:")
01962 {
01963 $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
01964 "FROM object_data,rbac_ua,usr_data ".
01965 "WHERE object_data.title LIKE '%".substr($a_search_str,5)."%' and object_data.type = 'role' ".
01966 "and rbac_ua.rol_id = object_data.obj_id ".
01967 "and usr_data.usr_id = rbac_ua.usr_id ".
01968 "AND rbac_ua.usr_id != '".ANONYMOUS_USER_ID."'";
01969 }
01970 else
01971 {
01972 $query = "SELECT usr_id,login,firstname,lastname,email,active FROM usr_data ".
01973 "WHERE (login LIKE '%".$a_search_str."%' ".
01974 "OR firstname LIKE '%".$a_search_str."%' ".
01975 "OR lastname LIKE '%".$a_search_str."%' ".
01976 "OR email LIKE '%".$a_search_str."%') ".
01977 "AND usr_id != '".ANONYMOUS_USER_ID."'";
01978 }
01979
01980 if (is_numeric($active) && $active > -1)
01981 $query .= "AND active = '$active'";
01982
01983 $res = $ilias->db->query($query);
01984 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01985 {
01986 $ids[] = array(
01987 "usr_id" => $row->usr_id,
01988 "login" => $row->login,
01989 "firstname" => $row->firstname,
01990 "lastname" => $row->lastname,
01991 "email" => $row->email,
01992 "active" => $row->active);
01993 }
01994
01995 return $ids ? $ids : array();
01996 }
01997
02005 function _search(&$a_search_obj, $active=1)
02006 {
02007 global $ilBench;
02008
02009
02010
02011
02012
02013 $where_condition = $a_search_obj->getWhereCondition("like",array("login","firstname","lastname","title",
02014 "email","institution","street","city",
02015 "zipcode","country","phone_home","fax"));
02016 $in = $a_search_obj->getInStatement("usr_data.usr_id");
02017
02018 $query = "SELECT DISTINCT(usr_data.usr_id) FROM usr_data ".
02019 "LEFT JOIN usr_pref USING (usr_id) ".
02020 $where_condition." ".
02021 $in." ".
02022 "AND usr_data.usr_id != '".ANONYMOUS_USER_ID."' ";
02023 # "AND usr_pref.keyword = 'public_profile' ";
02024 # "AND usr_pref.value = 'y'";
02025
02026 if (is_numeric($active) && $active > -1)
02027 $query .= "AND active = '$active'";
02028
02029 $ilBench->start("Search", "ilObjUser_search");
02030 $res = $a_search_obj->ilias->db->query($query);
02031 $ilBench->stop("Search", "ilObjUser_search");
02032
02033 $counter = 0;
02034
02035 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02036 {
02037 $result_data[$counter++]["id"] = $row->usr_id;
02038
02039
02040
02041 #$result_data[$counter]["link"] = "profile.php?user=".$row->usr_id;
02042 #$result_data[$counter++]["target"] = "";
02043 }
02044 return $result_data ? $result_data : array();
02045 }
02046
02056 function _getLinkToObject($a_id)
02057 {
02058 return array("profile.php?user=".$a_id,"");
02059 }
02060
02061
02062
02063
02064
02065
02066 function getGroupMemberships($a_user_id = "")
02067 {
02068 global $rbacreview, $tree;
02069
02070 if (strlen($a_user_id) > 0)
02071 {
02072 $user_id = $a_user_id;
02073 }
02074 else
02075 {
02076 $user_id = $this->getId();
02077 }
02078
02079 $grp_memberships = array();
02080
02081
02082 $roles = $rbacreview->assignedRoles($user_id);
02083
02084 foreach ($roles as $role)
02085 {
02086 $ass_rolefolders = $rbacreview->getFoldersAssignedToRole($role);
02087
02088 foreach ($ass_rolefolders as $role_folder)
02089 {
02090 $node = $tree->getParentNodeData($role_folder);
02091
02092 if ($node["type"] == "grp")
02093 {
02094 $group =& $this->ilias->obj_factory->getInstanceByRefId($node["child"]);
02095
02096 if ($group->isMember($user_id) == true && !in_array($group->getId(), $grp_memberships) )
02097 {
02098 array_push($grp_memberships, $group->getId());
02099 }
02100 }
02101
02102 unset($group);
02103 }
02104 }
02105
02106 return $grp_memberships;
02107 }
02108
02109
02118 function updateActiveRoles($a_user_id)
02119 {
02120 global $rbacreview, $ilDB;
02121
02122 if (!count($user_online = ilUtil::getUsersOnline($a_user_id)) == 1)
02123 {
02124 return false;
02125 }
02126
02127 $role_arr = $rbacreview->assignedRoles($a_user_id);
02128
02129 if ($_SESSION["AccountId"] == $a_user_id)
02130 {
02131 $_SESSION["RoleId"] = $role_arr;
02132 }
02133 else
02134 {
02135 $roles = "RoleId|".serialize($role_arr);
02136 $modified_data = preg_replace("/RoleId.*?;\}/",$roles,$user_online[$a_user_id]["data"]);
02137
02138 $q = "UPDATE usr_session SET data='".ilUtil::prepareDBString($modified_data)."' WHERE user_id = '".$a_user_id."'";
02139 $ilDB->query($q);
02140 }
02141
02142 return true;
02143 }
02144
02153 function _getAllUserLogins(&$ilias)
02154 {
02155 $query = "SELECT login FROM usr_data ";
02156
02157 $res = $ilias->db->query($query);
02158 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02159 {
02160 $logins[] = $row->login;
02161 }
02162 return $logins ? $logins : array();
02163 }
02164
02173 function _getAllUserData($a_fields = NULL, $active =-1)
02174 {
02175 global $ilDB;
02176
02177 $result_arr = array();
02178
02179 if ($a_fields !== NULL and is_array($a_fields))
02180 {
02181 if (count($a_fields) == 0)
02182 {
02183 $select = "*";
02184 }
02185 else
02186 {
02187 if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
02188 unset($a_fields[$usr_id_field]);
02189
02190 $select = implode(",",$a_fields).",usr_data.usr_id";
02191 }
02192
02193 $q = "SELECT ".$select." FROM usr_data ";
02194
02195 if (is_numeric($active) && $active > -1)
02196 $q .= "WHERE active='$active'";
02197
02198 $r = $ilDB->query($q);
02199
02200 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
02201 {
02202 $result_arr[] = $row;
02203 }
02204 }
02205
02206 return $result_arr;
02207 }
02208
02212 function _getNumberOfUsersForStyle($a_skin, $a_style)
02213 {
02214 global $ilDB;
02215
02216 $q = "SELECT count(*) as cnt FROM usr_pref AS up1, usr_pref AS up2 ".
02217 " WHERE up1.keyword= ".$ilDB->quote("style")." AND up1.value= ".$ilDB->quote($a_style).
02218 " AND up2.keyword= ".$ilDB->quote("skin")." AND up2.value= ".$ilDB->quote($a_skin).
02219 " AND up1.usr_id = up2.usr_id ";
02220
02221 $cnt_set = $ilDB->query($q);
02222
02223 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
02224
02225 return $cnt_rec["cnt"];
02226 }
02227
02231 function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
02232 {
02233 global $ilDB;
02234
02235 $q = "SELECT up1.usr_id as usr_id FROM usr_pref AS up1, usr_pref AS up2 ".
02236 " WHERE up1.keyword= ".$ilDB->quote("style")." AND up1.value= ".$ilDB->quote($a_from_style).
02237 " AND up2.keyword= ".$ilDB->quote("skin")." AND up2.value= ".$ilDB->quote($a_from_skin).
02238 " AND up1.usr_id = up2.usr_id ";
02239
02240 $usr_set = $ilDB->query($q);
02241
02242 while ($usr_rec = $usr_set->fetchRow(DB_FETCHMODE_ASSOC))
02243 {
02244 ilObjUser::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
02245 ilObjUser::_writePref($usr_rec["usr_id"], "style", $a_to_style);
02246 }
02247 }
02248
02256 function addDesktopItem($a_item_id, $a_type, $a_par = "")
02257 {
02258 $q = "SELECT * FROM desktop_item WHERE ".
02259 "item_id = '$a_item_id' AND type = '$a_type' AND user_id = '".
02260 $this->getId()."'";
02261 $item_set = $this->ilias->db->query($q);
02262
02263
02264 if (!$d = $item_set->fetchRow())
02265 {
02266 $q = "INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
02267 " ('$a_item_id','$a_type','".$this->getId()."' , '$a_par')";
02268 $this->ilias->db->query($q);
02269 }
02270 }
02271
02280 function setDesktopItemParameters($a_item_id, $a_type, $a_par)
02281 {
02282 $q = "UPDATE desktop_item SET parameters = '$a_par' ".
02283 " WHERE item_id = '$a_item_id' AND type = '$a_type' ".
02284 " AND user_id = '".$this->getId()."' ";
02285 $this->ilias->db->query($q);
02286 }
02287
02295 function dropDesktopItem($a_item_id, $a_type)
02296 {
02297 $q = "DELETE FROM desktop_item WHERE ".
02298 " item_id = '$a_item_id' AND".
02299 " type = '$a_type' AND".
02300 " user_id = '".$this->getId()."'";
02301 $this->ilias->db->query($q);
02302 }
02303
02311 function isDesktopItem($a_item_id, $a_type)
02312 {
02313 $q = "SELECT * FROM desktop_item WHERE ".
02314 "item_id = '$a_item_id' AND type = '$a_type' AND user_id = '".
02315 $this->getId()."'";
02316 $item_set = $this->ilias->db->query($q);
02317
02318 if ($d = $item_set->fetchRow())
02319 {
02320 return true;
02321 }
02322 else
02323 {
02324 return false;
02325 }
02326 }
02327
02335 function getDesktopItems($a_types)
02336 {
02337 global $ilUser, $rbacsystem;
02338
02339
02340 if (!is_array($a_types))
02341 {
02342 $a_types = array($a_types);
02343 }
02344 $items = array();
02345 $foundsurveys = array();
02346 foreach($a_types as $a_type)
02347 {
02348 $q = "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item AS it, object_reference AS oref ".
02349 ", object_data AS obj WHERE ".
02350 "it.item_id = oref.ref_id AND ".
02351 "oref.obj_id = obj.obj_id AND ".
02352 "it.type = '$a_type' AND ".
02353 "it.user_id = '".$this->getId()."' ".
02354 "ORDER BY title";
02355
02356 $item_set = $this->ilias->db->query($q);
02357 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
02358 {
02359 $items[$item_rec["title"].$a_type.$item_rec["ref_id"]] =
02360 array("ref_id" => $item_rec["ref_id"],
02361 "obj_id" => $item_rec["obj_id"], "type" => $a_type,
02362 "title" => $item_rec["title"], "description" => $item_rec["description"]);
02363 }
02364
02365
02366
02367
02368
02369
02370
02371
02372
02373
02374
02375
02376
02377
02378
02379
02380
02381
02382
02383
02384
02385
02386
02387
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399
02400
02401
02402
02403
02404
02405
02406
02407
02408
02409
02410
02411
02412
02413
02414
02415
02416
02417
02418
02419
02420
02421
02422
02423
02424
02425
02426
02427
02428
02429
02430
02431
02432
02433
02434
02435
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
02491
02492
02493
02494
02495
02496
02497
02498
02499
02500
02501
02502
02503
02504
02505
02506
02507
02508
02509
02510
02511
02512
02513
02514
02515
02516
02517
02518
02519
02520
02521
02522
02523
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596
02597
02598
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610
02611
02612
02613
02614
02615
02616
02617
02618
02619
02620
02621
02622
02623
02624
02625
02626
02627
02628
02629
02630
02631
02632
02633
02634
02635
02636
02637
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648
02649
02650
02651
02652
02653
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674
02675
02676
02677
02678
02679
02680
02681
02682
02683
02684
02685
02686
02687
02688
02689
02690
02691
02692
02693
02694
02695
02696
02697
02698
02699
02700
02701
02702
02703
02704
02705
02706
02707
02708
02709
02710
02711
02712
02713
02714
02715
02716
02717
02718
02719
02720
02721
02722
02723
02724
02725
02726
02727
02728
02729
02730
02731
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745
02746
02747
02748
02749
02750
02751
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765
02766
02767
02768
02769
02770
02771
02772
02773
02774
02775
02776
02777
02778
02779
02780
02781
02782
02783
02784
02785
02786
02787
02788
02789
02790
02791
02792
02793
02794
02795
02796 }
02797 ksort($items);
02798 return $items;
02799 }
02800
02808 function addObjectToClipboard($a_item_id, $a_type, $a_title)
02809 {
02810 $q = "SELECT * FROM personal_clipboard WHERE ".
02811 "item_id = '$a_item_id' AND type = '$a_type' AND user_id = '".
02812 $this->getId()."'";
02813 $item_set = $this->ilias->db->query($q);
02814
02815
02816 if (!$d = $item_set->fetchRow())
02817 {
02818 $q = "INSERT INTO personal_clipboard (item_id, type, user_id, title) VALUES ".
02819 " ('$a_item_id','$a_type','".$this->getId()."', '".$a_title."')";
02820 $this->ilias->db->query($q);
02821 }
02822 }
02823
02827 function getClipboardObjects($a_type = "")
02828 {
02829 $type_str = ($a_type != "")
02830 ? " AND type = '$a_type' "
02831 : "";
02832 $q = "SELECT * FROM personal_clipboard WHERE ".
02833 "user_id = '".$this->getId()."' ".
02834 $type_str;
02835 $objs = $this->ilias->db->query($q);
02836 $objects = array();
02837 while ($obj = $objs->fetchRow(DB_FETCHMODE_ASSOC))
02838 {
02839 if ($obj["type"] == "mob")
02840 {
02841 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
02842 }
02843 $objects[] = array ("id" => $obj["item_id"],
02844 "type" => $obj["type"], "title" => $obj["title"]);
02845 }
02846 return $objects;
02847 }
02848
02857 function _getUsersForClipboadObject($a_type, $a_id)
02858 {
02859 global $ilDB;
02860
02861 $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
02862 "item_id = '$a_id' AND ".
02863 "type = '$a_type'";
02864 $user_set = $ilDB->query($q);
02865 $users = array();
02866 while ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
02867 {
02868 $users[] = $user_rec["user_id"];
02869 }
02870
02871 return $users;
02872 }
02873
02881 function removeObjectFromClipboard($a_item_id, $a_type)
02882 {
02883 $q = "DELETE FROM personal_clipboard WHERE ".
02884 "item_id = '$a_item_id' AND type = '$a_type' ".
02885 " AND user_id = '".$this->getId()."'";
02886 $this->ilias->db->query($q);
02887 }
02888
02889 function _getImportedUserId($i2_id)
02890 {
02891 $query = "SELECT obj_id FROM object_data WHERE import_id = '".$i2_id."'";
02892
02893 $res = $this->ilias->db->query($query);
02894 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02895 {
02896 $id = $row->obj_id;
02897 }
02898 return $id ? $id : 0;
02899 }
02900
02905 function setiLincData($a_id,$a_login,$a_passwd)
02906 {
02907 $this->ilinc_id = $a_id;
02908 $this->ilinc_login = $a_login;
02909 $this->ilinc_passwd = $a_passwd;
02910 }
02911
02916 function getiLincData()
02917 {
02918 return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
02919 }
02920
02925 function setAuthMode($a_str)
02926 {
02927 $this->auth_mode = $a_str;
02928 }
02929
02934 function getAuthMode($a_auth_key = false)
02935 {
02936 if (!$a_auth_key)
02937 {
02938 return $this->auth_mode;
02939 }
02940
02941 include_once('classes/class.ilAuthUtils.php');
02942 return ilAuthUtils::_getAuthMode($this->auth_mode);
02943 }
02944
02952 function _uploadPersonalPicture($tmp_file, $obj_id)
02953 {
02954 $webspace_dir = ilUtil::getWebspaceDir();
02955 $image_dir = $webspace_dir."/usr_images";
02956 $store_file = "usr_".$obj_id."."."jpg";
02957 $target_file = $image_dir."/$store_file";
02958
02959 chmod($tmp_file, 0770);
02960
02961
02962
02963 $show_file = "$image_dir/usr_".$obj_id.".jpg";
02964 $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
02965 $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
02966 $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
02967
02968 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 200x200 -quality 100 JPEG:$show_file");
02969 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 100x100 -quality 100 JPEG:$thumb_file");
02970 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 75x75 -quality 100 JPEG:$xthumb_file");
02971 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 30x30 -quality 100 JPEG:$xxthumb_file");
02972
02973
02974 ilObjUser::_writePref($obj_id, "profile_image", $store_file);
02975
02976 return TRUE;
02977 }
02978 }
02979 ?>