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 if (!empty($a_user_id))
00148 {
00149 $this->setId($a_user_id);
00150 $this->read();
00151 }
00152 else
00153 {
00154
00155
00156 $this->prefs = array();
00157
00158 $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
00159
00160
00161 $this->skin = $this->ilias->ini->readVariable("layout","skin");
00162
00163 $this->prefs["skin"] = $this->skin;
00164 $this->prefs["show_users_online"] = "y";
00165
00166
00167 $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
00168 }
00169 }
00170
00175 function read()
00176 {
00177 global $ilErr;
00178
00179
00180 $q = "SELECT * FROM usr_data ".
00181 "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
00182 "WHERE usr_data.usr_id='".$this->id."'";
00183 $r = $this->ilias->db->query($q);
00184
00185 if ($r->numRows() > 0)
00186 {
00187 $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00188
00189
00190
00191 if ($data["passwd"] == "" && $data["i2passwd"] != "")
00192 {
00193 $data["passwd_type"] = IL_PASSWD_CRYPT;
00194 $data["passwd"] = $data["i2passwd"];
00195 }
00196 else
00197 {
00198 $data["passwd_type"] = IL_PASSWD_MD5;
00199
00200 }
00201 unset($data["i2passw"]);
00202
00203
00204
00205 $this->assignData($data);
00206
00207
00208 $this->readPrefs();
00209
00210
00211 if ($this->prefs["language"] == "")
00212 {
00213 $this->prefs["language"] = $this->oldPrefs["language"];
00214 }
00215
00216
00217 if ($this->prefs["skin"] == "" || file_exists($this->ilias->tplPath."/".$this->prefs["skin"]) == false)
00218 {
00219 $this->prefs["skin"] = $this->oldPrefs["skin"];
00220 }
00221
00222 $this->skin = $this->prefs["skin"];
00223
00224
00225 if ($this->prefs["style"] == "" || !file_exists($this->ilias->tplPath."/".$this->skin."/".$this->prefs["style"].".css"))
00226 {
00227
00228 $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
00229 }
00230
00231 if (empty($this->prefs["hits_per_page"]))
00232 {
00233 $this->prefs["hits_per_page"] = 10;
00234 }
00235
00236 }
00237 else
00238 {
00239 $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);
00240 }
00241
00242 parent::read();
00243 }
00244
00250 function assignData($a_data)
00251 {
00252 global $ilErr;
00253
00254
00255 $this->setLogin($a_data["login"]);
00256 if (! $a_data["passwd_type"])
00257 {
00258 $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
00259 $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
00260 .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
00261 }
00262
00263 if ($a_data["passwd"] != "********")
00264 {
00265 $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
00266 }
00267
00268 $this->setGender($a_data["gender"]);
00269 $this->setUTitle($a_data["title"]);
00270 $this->setFirstname($a_data["firstname"]);
00271 $this->setLastname($a_data["lastname"]);
00272 $this->setFullname();
00273
00274
00275 $this->setInstitution($a_data["institution"]);
00276 $this->setDepartment($a_data["department"]);
00277 $this->setStreet($a_data["street"]);
00278 $this->setCity($a_data["city"]);
00279 $this->setZipcode($a_data["zipcode"]);
00280 $this->setCountry($a_data["country"]);
00281 $this->setPhoneOffice($a_data["phone_office"]);
00282 $this->setPhoneHome($a_data["phone_home"]);
00283 $this->setPhoneMobile($a_data["phone_mobile"]);
00284 $this->setFax($a_data["fax"]);
00285 $this->setMatriculation($a_data["matriculation"]);
00286 $this->setEmail($a_data["email"]);
00287 $this->setHobby($a_data["hobby"]);
00288 $this->setClientIP($a_data["client_ip"]);
00289
00290
00291 $this->setLastLogin($a_data["last_login"]);
00292 $this->setLastUpdate($a_data["last_update"]);
00293 $this->create_date = $a_data["create_date"];
00294 $this->setComment($a_data["referral_comment"]);
00295 $this->approve_date = $a_data["approve_date"];
00296 $this->active = $a_data["active"];
00297 $this->accept_date = $a_data["agree_date"];
00298
00299
00300 $this->setTimeLimitOwner($a_data["time_limit_owner"]);
00301 $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
00302 $this->setTimeLimitFrom($a_data["time_limit_from"]);
00303 $this->setTimeLimitUntil($a_data["time_limit_until"]);
00304 $this->setTimeLimitMessage($a_data['time_limit_message']);
00305
00306
00307 $this->setiLincData($a_data['ilinc_id'],$a_data['ilinc_login'],$a_data['ilinc_passwd']);
00308
00309
00310 $this->setAuthMode($a_data['auth_mode']);
00311 }
00312
00319 function saveAsNew($a_from_formular = true)
00320 {
00321 global $ilErr;
00322
00323 switch ($this->passwd_type)
00324 {
00325 case IL_PASSWD_PLAIN:
00326 $pw_field = "passwd";
00327 $pw_value = md5($this->passwd);
00328 break;
00329
00330 case IL_PASSWD_MD5:
00331 $pw_field = "passwd";
00332 $pw_value = $this->passwd;
00333 break;
00334
00335 case IL_PASSWD_CRYPT:
00336 $pw_field = "i2passwd";
00337 $pw_value = $this->passwd;
00338 break;
00339
00340 default :
00341 $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);
00342 }
00343
00344 if ($a_from_formular)
00345 {
00346 $q = "INSERT INTO usr_data "
00347 . "(usr_id,login,".$pw_field.",firstname,lastname,title,gender,"
00348 . "email,hobby,institution,department,street,city,zipcode,country,"
00349 . "phone_office,phone_home,phone_mobile,fax,last_login,last_update,create_date,"
00350 . "referral_comment,matriculation,client_ip, approve_date,active,"
00351 . "time_limit_unlimited,time_limit_until,time_limit_from,time_limit_owner,auth_mode) "
00352 . "VALUES "
00353 . "('".$this->id."','".$this->login."','".$pw_value."', "
00354 . "'".ilUtil::addSlashes($this->firstname)."','".ilUtil::addSlashes($this->lastname)."', "
00355 . "'".ilUtil::addSlashes($this->utitle)."','".ilUtil::addSlashes($this->gender)."', "
00356 . "'".ilUtil::addSlashes($this->email)."','".ilUtil::addSlashes($this->hobby)."', "
00357 . "'".ilUtil::addSlashes($this->institution)."','".ilUtil::addSlashes($this->department)."', "
00358 . "'".ilUtil::addSlashes($this->street)."', "
00359 . "'".ilUtil::addSlashes($this->city)."','".ilUtil::addSlashes($this->zipcode)."','".ilUtil::addSlashes($this->country)."', "
00360 . "'".ilUtil::addSlashes($this->phone_office)."','".ilUtil::addSlashes($this->phone_home)."', "
00361 . "'".ilUtil::addSlashes($this->phone_mobile)."','".ilUtil::addSlashes($this->fax)."', 0, now(), now(), "
00362 . "'".ilUtil::addSlashes($this->referral_comment)."', '". ilUtil::addSlashes($this->matriculation) . "', '". ilUtil::addSlashes($this->client_ip) . "', '" .$this->approve_date."', '".$this->active."', "
00363 . "'".$this->getTimeLimitUnlimited()."','" . $this->getTimeLimitUntil()."','".$this->getTimeLimitFrom()."','".$this->getTimeLimitOwner()."', "
00364 . "'".$this->getAuthMode()."')";
00365 }
00366 else
00367 {
00368 $q = "INSERT INTO usr_data ".
00369 "(usr_id,login,".$pw_field.",firstname,lastname,title,gender,"
00370 . "email,hobby,institution,department,street,city,zipcode,country,"
00371 . "phone_office,phone_home,phone_mobile,fax,last_login,last_update,create_date,"
00372 . "referral_comment,matriculation,client_ip, approve_date,active,"
00373 . "time_limit_unlimited,time_limit_until,time_limit_from,time_limit_owner) "
00374 . "VALUES "
00375 . "('".$this->id."','".$this->login."','".$pw_value."', "
00376 . "'".ilUtil::prepareDBString($this->firstname)."','".ilUtil::prepareDBString($this->lastname)."', "
00377 . "'".ilUtil::prepareDBString($this->utitle)."','".ilUtil::prepareDBString($this->gender)."', "
00378 . "'".ilUtil::prepareDBString($this->email)."','".ilUtil::prepareDBString($this->hobby)."', "
00379 . "'".ilUtil::prepareDBString($this->institution)."','".ilUtil::prepareDBString($this->department)."', "
00380 . "'".ilUtil::prepareDBString($this->street)."', "
00381 . "'".ilUtil::prepareDBString($this->city)."','".ilUtil::prepareDBString($this->zipcode)."','".ilUtil::prepareDBString($this->country)."', "
00382 . "'".ilUtil::prepareDBString($this->phone_office)."','".ilUtil::prepareDBString($this->phone_home)."', "
00383 . "'".ilUtil::prepareDBString($this->phone_mobile)."','".ilUtil::prepareDBString($this->fax)."', 0, now(), now(), "
00384 . "'".ilUtil::prepareDBString($this->referral_comment)."', '".ilUtil::prepareDBString($this->matriculation)."', '".ilUtil::prepareDBString($this->client_ip)."', '".$this->approve_date."','".$this->active."', "
00385 . "'".$this->getTimeLimitUnlimited()."','".$this->getTimeLimitUntil()."','".$this->getTimeLimitFrom()."','".$this->getTimeLimitOwner()."'"
00386 . ")";
00387 }
00388
00389 $this->ilias->db->query($q);
00390
00391
00392 include_once ("classes/class.ilMailbox.php");
00393 $mbox = new ilMailbox($this->id);
00394 $mbox->createDefaultFolder();
00395
00396 include_once "classes/class.ilMailOptions.php";
00397 $mail_options = new ilMailOptions($this->id);
00398 $mail_options->createMailOptionsEntry();
00399
00400
00401 include_once "classes/class.ilBookmarkFolder.php";
00402 $bmf = new ilBookmarkFolder(0, $this->id);
00403 $bmf->createNewBookmarkTree();
00404
00405 }
00406
00411 function update()
00412 {
00413 global $ilErr;
00414
00415
00416
00417 $this->syncActive();
00418
00419 $pw_udpate = '';
00420 switch ($this->passwd_type)
00421 {
00422 case IL_PASSWD_PLAIN:
00423 $pw_update = "i2passwd='', passwd='".md5($this->passwd)."'";
00424 break;
00425
00426 case IL_PASSWD_MD5:
00427 $pw_update = "i2passwd='', passwd='".$this->passwd."'";
00428 break;
00429
00430 case IL_PASSWD_CRYPT:
00431 $pw_update = "passwd='', i2passwd='".$this->passwd."'";
00432 break;
00433
00434 default :
00435 $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);
00436 }
00437 $q = "UPDATE usr_data SET ".
00438 "gender='".$this->gender."', ".
00439 "title='".ilUtil::prepareDBString($this->utitle)."', ".
00440 "firstname='".ilUtil::prepareDBString($this->firstname)."', ".
00441 "lastname='".ilUtil::prepareDBString($this->lastname)."', ".
00442 "email='".ilUtil::prepareDBString($this->email)."', ".
00443 "hobby='".ilUtil::prepareDBString($this->hobby)."', ".
00444 "institution='".ilUtil::prepareDBString($this->institution)."', ".
00445 "department='".ilUtil::prepareDBString($this->department)."', ".
00446 "street='".ilUtil::prepareDBString($this->street)."', ".
00447 "city='".ilUtil::prepareDBString($this->city)."', ".
00448 "zipcode='".ilUtil::prepareDBString($this->zipcode)."', ".
00449 "country='".ilUtil::prepareDBString($this->country)."', ".
00450 "phone_office='".ilUtil::prepareDBString($this->phone_office)."', ".
00451 "phone_home='".ilUtil::prepareDBString($this->phone_home)."', ".
00452 "phone_mobile='".ilUtil::prepareDBString($this->phone_mobile)."', ".
00453 "fax='".ilUtil::prepareDBString($this->fax)."', ".
00454 "referral_comment='".ilUtil::prepareDBString($this->referral_comment)."', ".
00455 "matriculation='".ilUtil::prepareDBString($this->matriculation)."', ".
00456 "client_ip='".ilUtil::prepareDBString($this->client_ip)."', ".
00457 "approve_date='".ilUtil::prepareDBString($this->approve_date)."', ".
00458 "active='".ilUtil::prepareDBString($this->active)."', ".
00459 "time_limit_owner='".ilUtil::prepareDBString($this->getTimeLimitOwner())."', ".
00460 "time_limit_unlimited='".ilUtil::prepareDBString($this->getTimeLimitUnlimited())."', ".
00461 "time_limit_from='".ilUtil::prepareDBString($this->getTimeLimitFrom())."', ".
00462 "time_limit_until='".ilUtil::prepareDBString($this->getTimeLimitUntil())."', ".
00463 "time_limit_message='".$this->getTimeLimitMessage()."', ".
00464 "auth_mode='".ilUtil::prepareDBString($this->getAuthMode())."', ".
00465 $pw_update.", ".
00466 "last_update=now(), ".
00467 "ilinc_id='".ilUtil::prepareDBString($this->ilinc_id)."', ".
00468 "ilinc_login='".ilUtil::prepareDBString($this->ilinc_login)."', ".
00469 "ilinc_passwd='".ilUtil::prepareDBString($this->ilinc_passwd)."' ".
00470 "WHERE usr_id='".$this->id."'";
00471
00472 $this->ilias->db->query($q);
00473
00474 $this->writePrefs();
00475
00476 parent::update();
00477 parent::updateOwner();
00478
00479 $this->read();
00480
00481 return true;
00482 }
00483
00487 function writeAccepted()
00488 {
00489 global $ilDB;
00490
00491 $q = "UPDATE usr_data SET agree_date = now()".
00492 "WHERE usr_id = ".$ilDB->quote($this->getId());
00493 $ilDB->query($q);
00494
00495 }
00496
00497 function _lookupEmail($a_user_id)
00498 {
00499 global $ilDB;
00500
00501 $query = "SELECT email FROM usr_data WHERE usr_id = '".(int) $a_user_id."'";
00502 $res = $ilDB->query($query);
00503
00504 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00505 {
00506 return $row->email;
00507 }
00508 return false;
00509 }
00510
00511 function _lookupClientIP($a_user_id)
00512 {
00513 global $ilDB;
00514
00515 $query = "SELECT client_ip FROM usr_data WHERE usr_id = '".(int) $a_user_id."'";
00516 $res = $ilDB->query($query);
00517
00518 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00519 {
00520 return $row->client_ip;
00521 }
00522 return "";
00523 }
00524
00525
00529 function _lookupName($a_user_id)
00530 {
00531 global $ilDB;
00532
00533 $q = "SELECT firstname, lastname, title FROM usr_data".
00534 " WHERE usr_id =".$ilDB->quote($a_user_id);
00535 $user_set = $ilDB->query($q);
00536 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00537 return array("user_id" => $a_user_id,
00538 "firstname" => $user_rec["firstname"],
00539 "lastname" => $user_rec["lastname"],
00540 "title" => $user_rec["title"]);
00541 }
00542
00546 function _lookupLogin($a_user_id)
00547 {
00548 global $ilDB;
00549
00550 $q = "SELECT login FROM usr_data".
00551 " WHERE usr_id =".$ilDB->quote($a_user_id);
00552 $user_set = $ilDB->query($q);
00553 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00554 return $user_rec["login"];
00555 }
00556
00560 function _lookupId($a_user_str)
00561 {
00562 global $ilDB;
00563
00564 $q = "SELECT usr_id FROM usr_data".
00565 " WHERE login =".$ilDB->quote($a_user_str);
00566 $user_set = $ilDB->query($q);
00567 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00568 return $user_rec["usr_id"];
00569 }
00570
00571
00577 function refreshLogin()
00578 {
00579 $q = "UPDATE usr_data SET ".
00580 "last_login = now() ".
00581 "WHERE usr_id = '".$this->id."'";
00582
00583 $this->ilias->db->query($q);
00584 }
00585
00592 function replacePassword($new_md5)
00593 {
00594 $this->passwd_type = IL_PASSWD_MD5;
00595 $this->passwd = $new_md5;
00596
00597 $q = "UPDATE usr_data SET ".
00598 "passwd='".$this->passwd."' ".
00599 "WHERE usr_id='".$this->id."'";
00600
00601 $this->ilias->db->query($q);
00602
00603 return true;
00604 }
00605
00614 function updatePassword($a_old, $a_new1, $a_new2)
00615 {
00616 if (func_num_args() != 3)
00617 {
00618 return false;
00619 }
00620
00621 if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
00622 {
00623 return false;
00624 }
00625
00626 if ($a_new1 != $a_new2)
00627 {
00628 return false;
00629 }
00630
00631
00632 if ($a_new1 == "" || $a_old == "")
00633 {
00634 return false;
00635 }
00636
00637
00638 switch ($this->passwd_type)
00639 {
00640 case IL_PASSWD_PLAIN:
00641 if ($a_old != $this->passwd)
00642 {
00643 return false;
00644 }
00645 break;
00646
00647 case IL_PASSWD_MD5:
00648 if (md5($a_old) != $this->passwd)
00649 {
00650 return false;
00651 }
00652 break;
00653
00654 case IL_PASSWD_CRYPT:
00655 if (_makeIlias2Password($a_old) != $this->passwd)
00656 {
00657 return false;
00658 }
00659 break;
00660 }
00661
00662
00663 $this->passwd = md5($a_new1);
00664 $this->passwd_type = IL_PASSWD_MD5;
00665
00666 $q = "UPDATE usr_data SET ".
00667 "passwd='".$this->passwd."' ".
00668 "WHERE usr_id='".$this->id."'";
00669 $this->ilias->db->query($q);
00670
00671 return true;
00672 }
00673
00681 function resetPassword($a_new1, $a_new2)
00682 {
00683 if (func_num_args() != 2)
00684 {
00685 return false;
00686 }
00687
00688 if (!isset($a_new1) or !isset($a_new2))
00689 {
00690 return false;
00691 }
00692
00693 if ($a_new1 != $a_new2)
00694 {
00695 return false;
00696 }
00697
00698
00699 $this->passwd = md5($a_new1);
00700 $this->passwd_type = IL_PASSWD_MD5;
00701
00702 $q = "UPDATE usr_data SET ".
00703 "passwd='".$this->passwd."' ".
00704 "WHERE usr_id='".$this->id."'";
00705 $this->ilias->db->query($q);
00706
00707 return true;
00708 }
00709
00713 function _makeIlias2Password($a_passwd)
00714 {
00715 return (crypt($a_passwd,substr($a_passwd,0,2)));
00716 }
00717
00721 function _lookupHasIlias2Password($a_user_login)
00722 {
00723 global $ilias, $ilDB;
00724
00725 $q = "SELECT i2passwd FROM usr_data ".
00726 "WHERE login = ".$ilDB->quote($a_user_login)."";
00727 $user_set = $ilias->db->query($q);
00728
00729 if ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
00730 {
00731 if ($user_rec["i2passwd"] != "")
00732 {
00733 return true;
00734 }
00735 }
00736
00737 return false;
00738 }
00739
00740 function _switchToIlias3Password($a_user, $a_pw)
00741 {
00742 global $ilias;
00743
00744 $q = "SELECT i2passwd FROM usr_data ".
00745 "WHERE login = '".$a_user."'";
00746 $user_set = $ilias->db->query($q);
00747
00748 if ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
00749 {
00750 if ($user_rec["i2passwd"] == ilObjUser::_makeIlias2Password($a_pw))
00751 {
00752 $q = "UPDATE usr_data SET passwd='".md5($a_pw)."', i2passwd=''".
00753 "WHERE login = '".$a_user."'";
00754 $ilias->db->query($q);
00755 return true;
00756 }
00757 }
00758
00759 return false;
00760 }
00761
00768 function updateLogin($a_login)
00769 {
00770 if (func_num_args() != 1)
00771 {
00772 return false;
00773 }
00774
00775 if (!isset($a_login))
00776 {
00777 return false;
00778 }
00779
00780
00781 $this->login = $a_login;
00782
00783 $q = "UPDATE usr_data SET ".
00784 "login='".$this->login."' ".
00785 "WHERE usr_id='".$this->id."'";
00786 $this->ilias->db->query($q);
00787
00788 return true;
00789 }
00790
00797 function writePref($a_keyword, $a_value)
00798 {
00799 ilObjUser::_writePref($this->id, $a_keyword, $a_value);
00800 $this->setPref($a_keyword, $a_value);
00801 }
00802
00803
00804 function _writePref($a_usr_id, $a_keyword, $a_value)
00805 {
00806 global $ilDB;
00807
00808
00809 $q = "DELETE FROM usr_pref ".
00810 "WHERE usr_id='".$a_usr_id."' ".
00811 "AND keyword='".$a_keyword."'";
00812 $ilDB->query($q);
00813
00814
00815 if ($a_value != "")
00816 {
00817 $q = "INSERT INTO usr_pref ".
00818 "(usr_id, keyword, value) ".
00819 "VALUES ".
00820 "('".$a_usr_id."', '".$a_keyword."', '".$a_value."')";
00821
00822 $ilDB->query($q);
00823 }
00824 }
00825
00830 function writePrefs()
00831 {
00832
00833 $q = "DELETE FROM usr_pref ".
00834 "WHERE usr_id='".$this->id."'";
00835 $this->ilias->db->query($q);
00836
00837 foreach ($this->prefs as $keyword => $value)
00838 {
00839
00840 $q = "INSERT INTO usr_pref ".
00841 "(usr_id, keyword, value) ".
00842 "VALUES ".
00843 "('".$this->id."', '".$keyword."', '".$value."')";
00844 $this->ilias->db->query($q);
00845 }
00846 }
00847
00854 function setPref($a_keyword, $a_value)
00855 {
00856 if ($a_keyword != "")
00857 {
00858 $this->prefs[$a_keyword] = $a_value;
00859 }
00860 }
00861
00867 function getPref($a_keyword)
00868 {
00869 return $this->prefs[$a_keyword];
00870 }
00871
00877 function readPrefs()
00878 {
00879 if (is_array($this->prefs))
00880 {
00881 $this->oldPrefs = $this->prefs;
00882 }
00883
00884 $this->prefs = array();
00885
00886 $q = "SELECT * FROM usr_pref WHERE usr_id='".$this->id."'";
00887
00888 $r = $this->ilias->db->query($q);
00889
00890 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
00891 {
00892 $this->prefs[$row["keyword"]] = $row["value"];
00893 }
00894
00895 return $r->numRows();
00896 }
00897
00898
00899
00900
00901
00902
00903
00904
00905
00911 function delete()
00912 {
00913 global $rbacadmin;
00914
00915
00916 include_once ("classes/class.ilMailbox.php");
00917 $mailbox = new ilMailbox($this->getId());
00918 $mailbox->delete();
00919 $mailbox->updateMailsOfDeletedUser();
00920
00921
00922 $this->ilias->db->query("DELETE FROM usr_data WHERE usr_id='".$this->getId()."'");
00923
00924
00925 $this->ilias->db->query("DELETE FROM usr_pref WHERE usr_id='".$this->getId()."'");
00926
00927
00928 $this->ilias->db->query("DELETE FROM usr_session WHERE user_id='".$this->getId()."'");
00929
00930
00931 $rbacadmin->removeUser($this->getId());
00932
00933
00934
00935 $q = "DELETE FROM bookmark_tree WHERE tree='".$this->getId()."'";
00936 $this->ilias->db->query($q);
00937
00938 $q = "DELETE FROM bookmark_data WHERE user_id='".$this->getId()."'";
00939 $this->ilias->db->query($q);
00940
00941
00942 include_once './classes/class.ilObjForum.php';
00943 ilObjForum::_deleteUser($this->getId());
00944
00945
00946 include_once './classes/class.ilLinkCheckNotify.php';
00947 ilLinkCheckNotify::_deleteUser($this->getId());
00948
00949
00950 include_once './course/classes/class.ilObjCourse.php';
00951 ilObjCourse::_deleteUser($this->getId());
00952
00953
00954 include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
00955 ilObjUserTracking::_deleteUser($this->getId());
00956
00957
00958 $q = "DELETE FROM grp_registration WHERE user_id='".$this->getId()."'";
00959 $this->ilias->db->query($q);
00960
00961
00962 parent::delete();
00963 return true;
00964 }
00965
00975 function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
00976 {
00977 $this->fullname = "";
00978
00979 if ($a_title)
00980 {
00981 $fullname = $a_title." ";
00982 }
00983 elseif ($this->utitle)
00984 {
00985 $this->fullname = $this->utitle." ";
00986 }
00987
00988 if ($a_firstname)
00989 {
00990 $fullname .= $a_firstname." ";
00991 }
00992 elseif ($this->firstname)
00993 {
00994 $this->fullname .= $this->firstname." ";
00995 }
00996
00997 if ($a_lastname)
00998 {
00999 return $fullname.$a_lastname;
01000 }
01001
01002 $this->fullname .= $this->lastname;
01003 }
01004
01019 function getFullname($a_max_strlen = 0)
01020 {
01021 if (!$a_max_strlen)
01022 {
01023 return ilUtil::stripSlashes($this->fullname);
01024 }
01025
01026 if (strlen($this->fullname) <= $a_max_strlen)
01027 {
01028 return ilUtil::stripSlashes($this->fullname);
01029 }
01030
01031 if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
01032 {
01033 return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
01034 }
01035
01036 if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
01037 {
01038 return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
01039 }
01040
01041 if ((strlen($this->lastname) + 3) <= $a_max_strlen)
01042 {
01043 return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
01044 }
01045
01046 return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
01047 }
01048
01049
01055 function getLastVisitedLessons()
01056 {
01057
01058 $q = "SELECT * FROM lo_access ".
01059 "WHERE usr_id='".$this->id."' ".
01060 "ORDER BY timestamp DESC";
01061 $rst = $this->ilias->db->query($q);
01062
01063
01064 $result = array();
01065 while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
01066 {
01067 $result[] = array(
01068 "timestamp" => $record->timestamp,
01069 "usr_id" => $record->usr_id,
01070 "lm_id" => $record->lm_id,
01071 "obj_id" => $record->obj_id,
01072 "lm_title" => $record->lm_title);
01073 }
01074 return $result;
01075 }
01076
01077
01083 function getLessons()
01084 {
01085
01086 $q = "SELECT * FROM lo_access ".
01087 "WHERE usr_id='".$this->id."' ";
01088 $rst = $this->ilias->db->query($q);
01089
01090
01091 $result = array();
01092 while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
01093 {
01094 $result[] = array(
01095 "timestamp" => $record->timestamp,
01096 "usr_id" => $record->usr_id,
01097 "lm_id" => $record->lm_id,
01098 "obj_id" => $record->obj_id,
01099 "lm_title" => $record->lm_title);
01100 }
01101 return $result;
01102 }
01103
01104
01111 function getCourses()
01112 {
01113 global $lng;
01114
01115
01116 $courses = array();
01117
01118 $sql = "SELECT * FROM courses
01119 WHERE user_fk='".$this->id."'
01120 AND read=1";
01121 $courses[] = array(
01122 "id" => 1,
01123 "title" => "Course 1",
01124 "desc" => "description of course one",
01125 "content" => "This is Course One",
01126 "datetime" => date("Y-m-d")
01127 );
01128 return $courses;
01129 }
01130
01137 function getLiterature()
01138 {
01139
01140 $literature = array();
01141
01142 $sql = "SELECT * FROM literature";
01143
01144 $literature[] = array(
01145 "id" => 1,
01146 "url" => "http://www.gutenberg.de",
01147 "desc" => "project gutenberg",
01148 );
01149
01150 return $literature;
01151 }
01152
01156 function hasAcceptedUserAgreement()
01157 {
01158 if ($this->accept_date != "0000-00-00 00:00:00" || $this->login == "root")
01159 {
01160 return true;
01161 }
01162 return false;
01163 }
01164
01170 function setLogin($a_str)
01171 {
01172 $this->login = $a_str;
01173 }
01174
01179 function getLogin()
01180 {
01181 return $this->login;
01182 }
01183
01189 function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
01190 {
01191 $this->passwd = $a_str;
01192 $this->passwd_type = $a_type;
01193 }
01194
01202 function getPasswd()
01203 {
01204 return $this->passwd;
01205 }
01212 function getPasswdType()
01213 {
01214 return $this->passwd_type;
01215 }
01216
01222 function setGender($a_str)
01223 {
01224 $this->gender = substr($a_str,-1);
01225 }
01226
01231 function getGender()
01232 {
01233 return $this->gender;
01234 }
01235
01243 function setUTitle($a_str)
01244 {
01245 $this->utitle = $a_str;
01246 }
01247
01254 function getUTitle()
01255 {
01256 return $this->utitle;
01257 }
01258
01264 function setFirstname($a_str)
01265 {
01266 $this->firstname = $a_str;
01267 }
01268
01273 function getFirstname()
01274 {
01275 return $this->firstname;
01276 }
01277
01283 function setLastname($a_str)
01284 {
01285 $this->lastname = $a_str;
01286 }
01287
01292 function getLastname()
01293 {
01294 return $this->lastname;
01295 }
01296
01302 function setInstitution($a_str)
01303 {
01304 $this->institution = $a_str;
01305 }
01306
01311 function getInstitution()
01312 {
01313 return $this->institution;
01314 }
01315
01321 function setDepartment($a_str)
01322 {
01323 $this->department = $a_str;
01324 }
01325
01330 function getDepartment()
01331 {
01332 return $this->department;
01333 }
01334
01340 function setStreet($a_str)
01341 {
01342 $this->street = $a_str;
01343 }
01344
01349 function getStreet()
01350 {
01351 return $this->street;
01352 }
01353
01359 function setCity($a_str)
01360 {
01361 $this->city = $a_str;
01362 }
01363
01368 function getCity()
01369 {
01370 return $this->city;
01371 }
01372
01378 function setZipcode($a_str)
01379 {
01380 $this->zipcode = $a_str;
01381 }
01382
01387 function getZipcode()
01388 {
01389 return $this->zipcode;
01390 }
01391
01397 function setCountry($a_str)
01398 {
01399 $this->country = $a_str;
01400 }
01401
01406 function getCountry()
01407 {
01408 return $this->country;
01409 }
01410
01416 function setPhoneOffice($a_str)
01417 {
01418 $this->phone_office = $a_str;
01419 }
01420
01425 function getPhoneOffice()
01426 {
01427 return $this->phone_office;
01428 }
01429
01435 function setPhoneHome($a_str)
01436 {
01437 $this->phone_home = $a_str;
01438 }
01439
01444 function getPhoneHome()
01445 {
01446 return $this->phone_home;
01447 }
01448
01454 function setPhoneMobile($a_str)
01455 {
01456 $this->phone_mobile = $a_str;
01457 }
01458
01463 function getPhoneMobile()
01464 {
01465 return $this->phone_mobile;
01466 }
01467
01473 function setFax($a_str)
01474 {
01475 $this->fax = $a_str;
01476 }
01477
01482 function getFax()
01483 {
01484 return $this->fax;
01485 }
01486
01492 function setClientIP($a_str)
01493 {
01494 $this->client_ip = $a_str;
01495 }
01496
01501 function getClientIP()
01502 {
01503 return $this->client_ip;
01504 }
01505
01511 function setMatriculation($a_str)
01512 {
01513 $this->matriculation = $a_str;
01514 }
01515
01520 function getMatriculation()
01521 {
01522 return $this->matriculation;
01523 }
01524
01530 function setEmail($a_str)
01531 {
01532 $this->email = $a_str;
01533 }
01534
01539 function getEmail()
01540 {
01541 return $this->email;
01542 }
01543
01549 function setHobby($a_str)
01550 {
01551 $this->hobby = $a_str;
01552 }
01553
01558 function getHobby()
01559 {
01560 return $this->hobby;
01561 }
01562
01568 function setLanguage($a_str)
01569 {
01570 $this->setPref("language",$a_str);
01571 unset($_SESSION['lang']);
01572 }
01573
01579 function getLanguage()
01580 {
01581 return $this->prefs["language"];
01582 }
01583
01588 function getCurrentLanguage()
01589 {
01590 return $_SESSION['lang'];
01591 }
01592
01598 function setLastLogin($a_str)
01599 {
01600 $this->last_login = $a_str;
01601 }
01602
01608 function getLastLogin()
01609 {
01610 return $this->last_login;
01611 }
01612
01618 function setLastUpdate($a_str)
01619 {
01620 $this->last_update = $a_str;
01621 }
01622 function getLastUpdate()
01623 {
01624 return $this->last_update;
01625 }
01626
01632 function setComment($a_str)
01633 {
01634 $this->referral_comment = $a_str;
01635 }
01636
01641 function getComment()
01642 {
01643 return $this->referral_comment;
01644 }
01645
01652 function setApproveDate($a_str)
01653 {
01654 $this->approve_date = $a_str;
01655 }
01656
01662 function getApproveDate()
01663 {
01664 return $this->approve_date;
01665 }
01666
01673 function setActive($a_active, $a_owner = 6)
01674 {
01675 if (empty($a_owner))
01676 {
01677 $a_owner = 0;
01678 }
01679
01680 if ($a_active)
01681 {
01682 $this->active = 1;
01683 $this->setApproveDate(date('Y-m-d H:i:s'));
01684 $this->setOwner($a_owner);
01685 }
01686 else
01687 {
01688 $this->active = 0;
01689 $this->setApproveDate('0000-00-00 00:00:00');
01690 $this->setOwner(0);
01691 }
01692 }
01693
01698 function getActive()
01699 {
01700 return $this->active;
01701 }
01702
01708 function syncActive()
01709 {
01710 $storedActive = 0;
01711 if ($this->getStoredActive($this->id))
01712 {
01713 $storedActive = 1;
01714 }
01715
01716 $currentActive = 0;
01717 if ($this->active)
01718 {
01719 $currentActive = 1;
01720 }
01721
01722 if ((!empty($storedActive) && empty($currentActive)) ||
01723 (empty($storedActive) && !empty($currentActive)))
01724 {
01725 $this->setActive($currentActive, $this->getUserIdByLogin($this->ilias->auth->getUsername()));
01726 }
01727 }
01728
01735 function getStoredActive($a_id)
01736 {
01737 global $ilias;
01738
01739 $query = "SELECT active FROM usr_data ".
01740 "WHERE usr_id = '".$a_id."'";
01741
01742 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
01743
01744 return $row->active ? true : false;
01745 }
01746
01752 function setSkin($a_str)
01753 {
01754
01755 $this->skin = $a_str;
01756 }
01757
01758 function setTimeLimitOwner($a_owner)
01759 {
01760 $this->time_limit_owner = $a_owner;
01761 }
01762 function getTimeLimitOwner()
01763 {
01764 return $this->time_limit_owner ? $this->time_limit_owner : 7;
01765 }
01766 function setTimeLimitFrom($a_from)
01767 {
01768 $this->time_limit_from = $a_from;
01769 }
01770 function getTimeLimitFrom()
01771 {
01772 return $this->time_limit_from ? $this->time_limit_from : time();
01773 }
01774 function setTimeLimitUntil($a_until)
01775 {
01776 $this->time_limit_until = $a_until;
01777 }
01778 function getTimeLimitUntil()
01779 {
01780 return $this->time_limit_until ? $this->time_limit_until : time();
01781 }
01782 function setTimeLimitUnlimited($a_unlimited)
01783 {
01784 $this->time_limit_unlimited = $a_unlimited;
01785 }
01786 function getTimeLimitUnlimited()
01787 {
01788 return $this->time_limit_unlimited;
01789 }
01790 function setTimeLimitMessage($a_time_limit_message)
01791 {
01792 return $this->time_limit_message = $a_time_limit_message;
01793 }
01794 function getTimeLimitMessage()
01795 {
01796 return $this->time_limit_message;
01797 }
01798
01799
01800 function checkTimeLimit()
01801 {
01802 if($this->getTimeLimitUnlimited())
01803 {
01804 return true;
01805 }
01806 if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
01807 {
01808 return true;
01809 }
01810 return false;
01811 }
01812
01813 function &getAppliedUsers()
01814 {
01815 $this->applied_users = array();
01816 $this->__readAppliedUsers($this->getId());
01817
01818 return $this->applied_users ? $this->applied_users : array();
01819 }
01820
01821 function isChild($a_usr_id)
01822 {
01823 if($a_usr_id == $this->getId())
01824 {
01825 return true;
01826 }
01827
01828 $this->applied_users = array();
01829 $this->__readAppliedUsers($this->getId());
01830
01831 return in_array($a_usr_id,$this->applied_users);
01832 }
01833
01834 function __readAppliedUsers($a_parent_id)
01835 {
01836 $query = "SELECT usr_id FROM usr_data ".
01837 "WHERE time_limit_owner = '".$a_parent_id."'";
01838
01839 $res = $this->ilias->db->query($query);
01840 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01841 {
01842 $this->applied_users[] = $row->usr_id;
01843
01844
01845 $this->__readAppliedUsers($row->usr_id);
01846 }
01847 return true;
01848 }
01849
01850
01851
01852
01853
01854 function checkUserId()
01855 {
01856 $r = $this->ilias->db->query("SELECT usr_id FROM usr_data WHERE login='".$this->ilias->auth->getUsername()."'");
01857
01858 if ($r->numRows() > 0)
01859 {
01860 $data = $r->fetchRow();
01861 $this->id = $data[0];
01862
01863 return $this->id;
01864 }
01865
01866 return false;
01867 }
01868
01869
01870
01871
01872
01873
01874 function isCurrentUserActive()
01875 {
01876 $r = $this->ilias->db->query("SELECT active FROM usr_data WHERE login='".$this->ilias->auth->getUsername()."'");
01877
01878 if ($r->numRows() > 0)
01879 {
01880 $data = $r->fetchRow();
01881 if (!empty($data[0]))
01882 {
01883 return true;
01884 }
01885 }
01886
01887 return false;
01888 }
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898 function getUserIdByLogin($a_login)
01899 {
01900 global $ilias, $ilDB;
01901
01902 $query = "SELECT usr_id FROM usr_data ".
01903 "WHERE login = ".$ilDB->quote($a_login);
01904
01905 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
01906
01907 return $row->usr_id ? $row->usr_id : 0;
01908 }
01909
01918 function _getUserIdsByEmail($a_email)
01919 {
01920 global $ilias, $ilDB;
01921
01922 $query = "SELECT login FROM usr_data ".
01923 "WHERE email = ".$ilDB->quote($a_email)." and active=1";
01924
01925 $res = $ilias->db->query($query);
01926 $ids = array ();
01927 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01928 {
01929 $ids[] = $row->login;
01930 }
01931
01932 return $ids;
01933 }
01934
01935
01936
01945 function getUserIdByEmail($a_email)
01946 {
01947 $query = "SELECT usr_id FROM usr_data ".
01948 "WHERE email = '".$a_email."'";
01949
01950 $row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
01951 return $row->usr_id ? $row->usr_id : 0;
01952 }
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962 function getLoginByUserId($a_userid)
01963 {
01964 global $ilias;
01965
01966 $query = "SELECT login FROM usr_data ".
01967 "WHERE usr_id = '".$a_userid."'";
01968
01969 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
01970
01971 return $row->login ? $row->login : false;
01972 }
01973
01981 function searchUsers($a_search_str, $active = 1)
01982 {
01983
01984 global $ilias;
01985
01986
01987
01988 if (strtolower(substr($a_search_str, 0, 5)) == "role:")
01989 {
01990 $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
01991 "FROM object_data,rbac_ua,usr_data ".
01992 "WHERE object_data.title LIKE '%".substr($a_search_str,5)."%' and object_data.type = 'role' ".
01993 "and rbac_ua.rol_id = object_data.obj_id ".
01994 "and usr_data.usr_id = rbac_ua.usr_id ".
01995 "AND rbac_ua.usr_id != '".ANONYMOUS_USER_ID."'";
01996 }
01997 else
01998 {
01999 $query = "SELECT usr_id,login,firstname,lastname,email,active FROM usr_data ".
02000 "WHERE (login LIKE '%".$a_search_str."%' ".
02001 "OR firstname LIKE '%".$a_search_str."%' ".
02002 "OR lastname LIKE '%".$a_search_str."%' ".
02003 "OR email LIKE '%".$a_search_str."%') ".
02004 "AND usr_id != '".ANONYMOUS_USER_ID."'";
02005 }
02006
02007 if (is_numeric($active) && $active > -1)
02008 $query .= "AND active = '$active'";
02009
02010 $res = $ilias->db->query($query);
02011 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02012 {
02013 $ids[] = array(
02014 "usr_id" => $row->usr_id,
02015 "login" => $row->login,
02016 "firstname" => $row->firstname,
02017 "lastname" => $row->lastname,
02018 "email" => $row->email,
02019 "active" => $row->active);
02020 }
02021
02022 return $ids ? $ids : array();
02023 }
02024
02032 function _search(&$a_search_obj, $active=1)
02033 {
02034 global $ilBench;
02035
02036
02037
02038
02039
02040 $where_condition = $a_search_obj->getWhereCondition("like",array("login","firstname","lastname","title",
02041 "email","institution","street","city",
02042 "zipcode","country","phone_home","fax"));
02043 $in = $a_search_obj->getInStatement("usr_data.usr_id");
02044
02045 $query = "SELECT DISTINCT(usr_data.usr_id) FROM usr_data ".
02046 "LEFT JOIN usr_pref USING (usr_id) ".
02047 $where_condition." ".
02048 $in." ".
02049 "AND usr_data.usr_id != '".ANONYMOUS_USER_ID."' ";
02050 # "AND usr_pref.keyword = 'public_profile' ";
02051 # "AND usr_pref.value = 'y'";
02052
02053 if (is_numeric($active) && $active > -1)
02054 $query .= "AND active = '$active'";
02055
02056 $ilBench->start("Search", "ilObjUser_search");
02057 $res = $a_search_obj->ilias->db->query($query);
02058 $ilBench->stop("Search", "ilObjUser_search");
02059
02060 $counter = 0;
02061
02062 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02063 {
02064 $result_data[$counter++]["id"] = $row->usr_id;
02065
02066
02067
02068 #$result_data[$counter]["link"] = "profile.php?user=".$row->usr_id;
02069 #$result_data[$counter++]["target"] = "";
02070 }
02071 return $result_data ? $result_data : array();
02072 }
02073
02083 function _getLinkToObject($a_id)
02084 {
02085 return array("profile.php?user=".$a_id,"");
02086 }
02087
02088
02089
02090
02091
02092
02093 function getGroupMemberships($a_user_id = "")
02094 {
02095 global $rbacreview, $tree;
02096
02097 if (strlen($a_user_id) > 0)
02098 {
02099 $user_id = $a_user_id;
02100 }
02101 else
02102 {
02103 $user_id = $this->getId();
02104 }
02105
02106 $grp_memberships = array();
02107
02108
02109 $roles = $rbacreview->assignedRoles($user_id);
02110
02111 foreach ($roles as $role)
02112 {
02113 $ass_rolefolders = $rbacreview->getFoldersAssignedToRole($role);
02114
02115 foreach ($ass_rolefolders as $role_folder)
02116 {
02117 $node = $tree->getParentNodeData($role_folder);
02118
02119 if ($node["type"] == "grp")
02120 {
02121 $group =& $this->ilias->obj_factory->getInstanceByRefId($node["child"]);
02122
02123 if ($group->isMember($user_id) == true && !in_array($group->getId(), $grp_memberships) )
02124 {
02125 array_push($grp_memberships, $group->getId());
02126 }
02127 }
02128
02129 unset($group);
02130 }
02131 }
02132
02133 return $grp_memberships;
02134 }
02135
02136
02145 function updateActiveRoles($a_user_id)
02146 {
02147 global $rbacreview, $ilDB;
02148
02149 if (!count($user_online = ilUtil::getUsersOnline($a_user_id)) == 1)
02150 {
02151 return false;
02152 }
02153
02154 $role_arr = $rbacreview->assignedRoles($a_user_id);
02155
02156 if ($_SESSION["AccountId"] == $a_user_id)
02157 {
02158 $_SESSION["RoleId"] = $role_arr;
02159 }
02160 else
02161 {
02162 $roles = "RoleId|".serialize($role_arr);
02163 $modified_data = preg_replace("/RoleId.*?;\}/",$roles,$user_online[$a_user_id]["data"]);
02164
02165 $q = "UPDATE usr_session SET data='".ilUtil::prepareDBString($modified_data)."' WHERE user_id = '".$a_user_id."'";
02166 $ilDB->query($q);
02167 }
02168
02169 return true;
02170 }
02171
02180 function _getAllUserLogins(&$ilias)
02181 {
02182 $query = "SELECT login FROM usr_data ";
02183
02184 $res = $ilias->db->query($query);
02185 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02186 {
02187 $logins[] = $row->login;
02188 }
02189 return $logins ? $logins : array();
02190 }
02191
02200 function _getAllUserData($a_fields = NULL, $active =-1)
02201 {
02202 global $ilDB;
02203
02204 $result_arr = array();
02205
02206 if ($a_fields !== NULL and is_array($a_fields))
02207 {
02208 if (count($a_fields) == 0)
02209 {
02210 $select = "*";
02211 }
02212 else
02213 {
02214 if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
02215 unset($a_fields[$usr_id_field]);
02216
02217 $select = implode(",",$a_fields).",usr_data.usr_id";
02218 }
02219
02220 $q = "SELECT ".$select." FROM usr_data ";
02221
02222 if (is_numeric($active) && $active > -1)
02223 $q .= "WHERE active='$active'";
02224
02225 $r = $ilDB->query($q);
02226
02227 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
02228 {
02229 $result_arr[] = $row;
02230 }
02231 }
02232
02233 return $result_arr;
02234 }
02235
02239 function _getNumberOfUsersForStyle($a_skin, $a_style)
02240 {
02241 global $ilDB;
02242
02243 $q = "SELECT count(*) as cnt FROM usr_pref AS up1, usr_pref AS up2 ".
02244 " WHERE up1.keyword= ".$ilDB->quote("style")." AND up1.value= ".$ilDB->quote($a_style).
02245 " AND up2.keyword= ".$ilDB->quote("skin")." AND up2.value= ".$ilDB->quote($a_skin).
02246 " AND up1.usr_id = up2.usr_id ";
02247
02248 $cnt_set = $ilDB->query($q);
02249
02250 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
02251
02252 return $cnt_rec["cnt"];
02253 }
02254
02258 function _getAllUserAssignedStyles()
02259 {
02260 global $ilDB;
02261
02262 $q = "SELECT DISTINCT up1.value as style, up2.value as skin FROM usr_pref AS up1, usr_pref AS up2 ".
02263 " WHERE up1.keyword= ".$ilDB->quote("style").
02264 " AND up2.keyword= ".$ilDB->quote("skin").
02265 " AND up1.usr_id = up2.usr_id ";
02266
02267
02268 $sty_set = $ilDB->query($q);
02269
02270 $styles = array();
02271 while($sty_rec = $sty_set->fetchRow(DB_FETCHMODE_ASSOC))
02272 {
02273 $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
02274 }
02275
02276 return $styles;
02277 }
02278
02282 function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
02283 {
02284 global $ilDB;
02285
02286 $q = "SELECT up1.usr_id as usr_id FROM usr_pref AS up1, usr_pref AS up2 ".
02287 " WHERE up1.keyword= ".$ilDB->quote("style")." AND up1.value= ".$ilDB->quote($a_from_style).
02288 " AND up2.keyword= ".$ilDB->quote("skin")." AND up2.value= ".$ilDB->quote($a_from_skin).
02289 " AND up1.usr_id = up2.usr_id ";
02290
02291 $usr_set = $ilDB->query($q);
02292
02293 while ($usr_rec = $usr_set->fetchRow(DB_FETCHMODE_ASSOC))
02294 {
02295 ilObjUser::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
02296 ilObjUser::_writePref($usr_rec["usr_id"], "style", $a_to_style);
02297 }
02298 }
02299
02307 function addDesktopItem($a_item_id, $a_type, $a_par = "")
02308 {
02309 $q = "SELECT * FROM desktop_item WHERE ".
02310 "item_id = '$a_item_id' AND type = '$a_type' AND user_id = '".
02311 $this->getId()."'";
02312 $item_set = $this->ilias->db->query($q);
02313
02314
02315 if (!$d = $item_set->fetchRow())
02316 {
02317 $q = "INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
02318 " ('$a_item_id','$a_type','".$this->getId()."' , '$a_par')";
02319 $this->ilias->db->query($q);
02320 }
02321 }
02322
02331 function setDesktopItemParameters($a_item_id, $a_type, $a_par)
02332 {
02333 $q = "UPDATE desktop_item SET parameters = '$a_par' ".
02334 " WHERE item_id = '$a_item_id' AND type = '$a_type' ".
02335 " AND user_id = '".$this->getId()."' ";
02336 $this->ilias->db->query($q);
02337 }
02338
02346 function dropDesktopItem($a_item_id, $a_type)
02347 {
02348 $q = "DELETE FROM desktop_item WHERE ".
02349 " item_id = '$a_item_id' AND".
02350 " type = '$a_type' AND".
02351 " user_id = '".$this->getId()."'";
02352 $this->ilias->db->query($q);
02353 }
02354
02362 function isDesktopItem($a_item_id, $a_type)
02363 {
02364 $q = "SELECT * FROM desktop_item WHERE ".
02365 "item_id = '$a_item_id' AND type = '$a_type' AND user_id = '".
02366 $this->getId()."'";
02367 $item_set = $this->ilias->db->query($q);
02368
02369 if ($d = $item_set->fetchRow())
02370 {
02371 return true;
02372 }
02373 else
02374 {
02375 return false;
02376 }
02377 }
02378
02385 function getDesktopItems($a_types = "")
02386 {
02387 global $ilUser, $rbacsystem, $tree;
02388
02389
02390 if ($a_types == "")
02391 {
02392 $q = "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
02393 " FROM desktop_item AS it, object_reference AS oref ".
02394 ", object_data AS obj".
02395 " WHERE ".
02396 "it.item_id = oref.ref_id AND ".
02397 "oref.obj_id = obj.obj_id AND ".
02398 "it.user_id = '".$this->getId()."'";
02399
02400 $item_set = $this->ilias->db->query($q);
02401 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
02402 {
02403 if ($tree->isInTree($item_rec["ref_id"]))
02404 {
02405 $parent_ref = $tree->getParentId($item_rec["ref_id"]);
02406 $par_left = $tree->getLeftValue($parent_ref);
02407 $par_left = sprintf("%010d", $par_left);
02408 $items[$par_left.$item_rec["title"].$item_rec["ref_id"]] =
02409 array("ref_id" => $item_rec["ref_id"],
02410 "obj_id" => $item_rec["obj_id"],
02411 "type" => $item_rec["type"],
02412 "title" => $item_rec["title"],
02413 "description" => $item_rec["description"],
02414 "parent_ref" => $parent_ref);
02415 }
02416 }
02417 ksort($items);
02418 }
02419 else
02420 {
02421 if (!is_array($a_types))
02422 {
02423 $a_types = array($a_types);
02424 }
02425 $items = array();
02426 $foundsurveys = array();
02427 foreach($a_types as $a_type)
02428 {
02429 $q = "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item AS it, object_reference AS oref ".
02430 ", object_data AS obj WHERE ".
02431 "it.item_id = oref.ref_id AND ".
02432 "oref.obj_id = obj.obj_id AND ".
02433 "it.type = '$a_type' AND ".
02434 "it.user_id = '".$this->getId()."' ".
02435 "ORDER BY title";
02436
02437 $item_set = $this->ilias->db->query($q);
02438 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
02439 {
02440 $items[$item_rec["title"].$a_type.$item_rec["ref_id"]] =
02441 array("ref_id" => $item_rec["ref_id"],
02442 "obj_id" => $item_rec["obj_id"], "type" => $a_type,
02443 "title" => $item_rec["title"], "description" => $item_rec["description"]);
02444 }
02445
02446 }
02447 ksort($items);
02448 }
02449 return $items;
02450 }
02451
02459 function addObjectToClipboard($a_item_id, $a_type, $a_title)
02460 {
02461 $q = "SELECT * FROM personal_clipboard WHERE ".
02462 "item_id = '$a_item_id' AND type = '$a_type' AND user_id = '".
02463 $this->getId()."'";
02464 $item_set = $this->ilias->db->query($q);
02465
02466
02467 if (!$d = $item_set->fetchRow())
02468 {
02469 $q = "INSERT INTO personal_clipboard (item_id, type, user_id, title) VALUES ".
02470 " ('$a_item_id','$a_type','".$this->getId()."', '".$a_title."')";
02471 $this->ilias->db->query($q);
02472 }
02473 }
02474
02478 function getClipboardObjects($a_type = "")
02479 {
02480 $type_str = ($a_type != "")
02481 ? " AND type = '$a_type' "
02482 : "";
02483 $q = "SELECT * FROM personal_clipboard WHERE ".
02484 "user_id = '".$this->getId()."' ".
02485 $type_str;
02486 $objs = $this->ilias->db->query($q);
02487 $objects = array();
02488 while ($obj = $objs->fetchRow(DB_FETCHMODE_ASSOC))
02489 {
02490 if ($obj["type"] == "mob")
02491 {
02492 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
02493 }
02494 $objects[] = array ("id" => $obj["item_id"],
02495 "type" => $obj["type"], "title" => $obj["title"]);
02496 }
02497 return $objects;
02498 }
02499
02508 function _getUsersForClipboadObject($a_type, $a_id)
02509 {
02510 global $ilDB;
02511
02512 $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
02513 "item_id = '$a_id' AND ".
02514 "type = '$a_type'";
02515 $user_set = $ilDB->query($q);
02516 $users = array();
02517 while ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
02518 {
02519 $users[] = $user_rec["user_id"];
02520 }
02521
02522 return $users;
02523 }
02524
02532 function removeObjectFromClipboard($a_item_id, $a_type)
02533 {
02534 $q = "DELETE FROM personal_clipboard WHERE ".
02535 "item_id = '$a_item_id' AND type = '$a_type' ".
02536 " AND user_id = '".$this->getId()."'";
02537 $this->ilias->db->query($q);
02538 }
02539
02540 function _getImportedUserId($i2_id)
02541 {
02542 $query = "SELECT obj_id FROM object_data WHERE import_id = '".$i2_id."'";
02543
02544 $res = $this->ilias->db->query($query);
02545 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02546 {
02547 $id = $row->obj_id;
02548 }
02549 return $id ? $id : 0;
02550 }
02551
02556 function setiLincData($a_id,$a_login,$a_passwd)
02557 {
02558 $this->ilinc_id = $a_id;
02559 $this->ilinc_login = $a_login;
02560 $this->ilinc_passwd = $a_passwd;
02561 }
02562
02567 function getiLincData()
02568 {
02569 return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
02570 }
02571
02576 function setAuthMode($a_str)
02577 {
02578 $this->auth_mode = $a_str;
02579 }
02580
02585 function getAuthMode($a_auth_key = false)
02586 {
02587 if (!$a_auth_key)
02588 {
02589 return $this->auth_mode;
02590 }
02591
02592 include_once('classes/class.ilAuthUtils.php');
02593 return ilAuthUtils::_getAuthMode($this->auth_mode);
02594 }
02595
02603 function _uploadPersonalPicture($tmp_file, $obj_id)
02604 {
02605 $webspace_dir = ilUtil::getWebspaceDir();
02606 $image_dir = $webspace_dir."/usr_images";
02607 $store_file = "usr_".$obj_id."."."jpg";
02608 $target_file = $image_dir."/$store_file";
02609
02610 chmod($tmp_file, 0770);
02611
02612
02613
02614 $show_file = "$image_dir/usr_".$obj_id.".jpg";
02615 $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
02616 $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
02617 $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
02618
02619 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 200x200 -quality 100 JPEG:$show_file");
02620 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 100x100 -quality 100 JPEG:$thumb_file");
02621 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 75x75 -quality 100 JPEG:$xthumb_file");
02622 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 30x30 -quality 100 JPEG:$xxthumb_file");
02623
02624
02625 ilObjUser::_writePref($obj_id, "profile_image", $store_file);
02626
02627 return TRUE;
02628 }
02629
02635 function getPersonalPicturePath($a_size = "small")
02636 {
02637 return ilObjUser::_getPersonalPicturePath($this->getId(),$a_size);
02638 }
02639
02646 function _getPersonalPicturePath($a_usr_id,$a_size = "small")
02647 {
02648 global $ilDB;
02649
02650 $query = "SELECT * FROM usr_pref WHERE ".
02651 "keyword = 'public_upload' ".
02652 "AND value = 'y' ".
02653 "AND usr_id = '".$a_usr_id."'";
02654
02655 $res = $ilDB->query($query);
02656 $upload = $res->numRows() ? true : false;
02657
02658 $query = "SELECT * FROM usr_pref WHERE ".
02659 "keyword = 'public_profile' ".
02660 "AND value = 'y' ".
02661 "AND usr_id = '".$a_usr_id."'";
02662
02663 $res = $ilDB->query($query);
02664 $profile = $res->numRows() ? true : false;
02665
02666
02667 if(defined('ILIAS_MODULE'))
02668 {
02669 $webspace_dir = ('.'.$webspace_dir);
02670 }
02671 $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
02672
02673 $image_dir = $webspace_dir."/usr_images";
02674 $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
02675
02676 if($upload and $profile and @is_file($thumb_file))
02677 {
02678 $file = $thumb_file."?t=".rand(1, 99999);
02679 }
02680 else
02681 {
02682 $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
02683 }
02684
02685 return $file;
02686 }
02687
02688
02689 }
02690 ?>