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
00092 var $client_ip;
00093 var $auth_mode;
00094
00095 var $im_icq;
00096 var $im_yahoo;
00097 var $im_msn;
00098 var $im_aim;
00099 var $im_skype;
00100
00101 var $delicious;
00102 var $latitude;
00103 var $longitude;
00104 var $loc_zoom;
00105
00106 var $user_defined_data = array();
00107
00113 var $prefs;
00114
00120 var $skin;
00121
00122
00128 var $default_role;
00129
00135 var $ilias;
00136
00137
00143 function ilObjUser($a_user_id = 0, $a_call_by_reference = false)
00144 {
00145 global $ilias,$ilDB;
00146
00147
00148 $this->ilias =& $ilias;
00149 $this->db =& $ilDB;
00150
00151 $this->type = "usr";
00152 $this->ilObject($a_user_id, $a_call_by_reference);
00153 $this->auth_mode = "default";
00154 $this->passwd_type = IL_PASSWD_PLAIN;
00155
00156
00157
00158
00159
00160
00161 if (!empty($a_user_id))
00162 {
00163 $this->setId($a_user_id);
00164 $this->read();
00165 }
00166 else
00167 {
00168
00169
00170 $this->prefs = array();
00171
00172 $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
00173
00174
00175 $this->skin = $this->ilias->ini->readVariable("layout","skin");
00176
00177 $this->prefs["skin"] = $this->skin;
00178 $this->prefs["show_users_online"] = "y";
00179
00180
00181 $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
00182 }
00183 }
00184
00189 function read()
00190 {
00191 global $ilErr, $ilDB;
00192
00193
00194 $q = "SELECT * FROM usr_data ".
00195 "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
00196 "WHERE usr_data.usr_id= ".$ilDB->quote($this->id);
00197 $r = $this->ilias->db->query($q);
00198
00199 if ($r->numRows() > 0)
00200 {
00201 $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00202
00203
00204
00205 if ($data["passwd"] == "" && $data["i2passwd"] != "")
00206 {
00207 $data["passwd_type"] = IL_PASSWD_CRYPT;
00208 $data["passwd"] = $data["i2passwd"];
00209 }
00210 else
00211 {
00212 $data["passwd_type"] = IL_PASSWD_MD5;
00213
00214 }
00215 unset($data["i2passw"]);
00216
00217
00218
00219 $this->assignData($data);
00220
00221
00222 $this->readPrefs();
00223
00224
00225 if ($this->prefs["language"] == "")
00226 {
00227 $this->prefs["language"] = $this->oldPrefs["language"];
00228 }
00229
00230
00231 include_once("./classes/class.ilStyleDefinition.php");
00232 if ($this->prefs["skin"] == "" ||
00233 !ilStyleDefinition::skinExists($this->prefs["skin"]))
00234 {
00235 $this->prefs["skin"] = $this->oldPrefs["skin"];
00236 }
00237
00238 $this->skin = $this->prefs["skin"];
00239
00240
00241 if ($this->prefs["style"] == "" ||
00242 !ilStyleDefinition::skinExists($this->skin, $this->prefs["style"]))
00243 {
00244
00245 $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
00246 }
00247
00248 if (empty($this->prefs["hits_per_page"]))
00249 {
00250 $this->prefs["hits_per_page"] = 10;
00251 }
00252
00253 }
00254 else
00255 {
00256 $ilErr->raiseError("<b>Error: There is no dataset with id ".
00257 $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
00258 "<br />Line: ".__LINE__, $ilErr->FATAL);
00259 }
00260
00261 $this->readUserDefinedFields();
00262
00263 parent::read();
00264 }
00265
00271 function assignData($a_data)
00272 {
00273 global $ilErr;
00274
00275
00276 $this->setLogin($a_data["login"]);
00277 if (! $a_data["passwd_type"])
00278 {
00279 $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
00280 $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
00281 .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
00282 }
00283 if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
00284 {
00285 $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
00286 }
00287
00288 $this->setGender($a_data["gender"]);
00289 $this->setUTitle($a_data["title"]);
00290 $this->setFirstname($a_data["firstname"]);
00291 $this->setLastname($a_data["lastname"]);
00292 $this->setFullname();
00293
00294
00295 $this->setInstitution($a_data["institution"]);
00296 $this->setDepartment($a_data["department"]);
00297 $this->setStreet($a_data["street"]);
00298 $this->setCity($a_data["city"]);
00299 $this->setZipcode($a_data["zipcode"]);
00300 $this->setCountry($a_data["country"]);
00301 $this->setPhoneOffice($a_data["phone_office"]);
00302 $this->setPhoneHome($a_data["phone_home"]);
00303 $this->setPhoneMobile($a_data["phone_mobile"]);
00304 $this->setFax($a_data["fax"]);
00305 $this->setMatriculation($a_data["matriculation"]);
00306 $this->setEmail($a_data["email"]);
00307 $this->setHobby($a_data["hobby"]);
00308 $this->setClientIP($a_data["client_ip"]);
00309
00310
00311 $this->setInstantMessengerId('icq',$a_data["im_icq"]);
00312 $this->setInstantMessengerId('yahoo',$a_data["im_yahoo"]);
00313 $this->setInstantMessengerId('msn',$a_data["im_msn"]);
00314 $this->setInstantMessengerId('aim',$a_data["im_aim"]);
00315 $this->setInstantMessengerId('skype',$a_data["im_skype"]);
00316
00317
00318 $this->setDelicious($a_data["delicious"]);
00319 $this->setLatitude($a_data["latitude"]);
00320 $this->setLongitude($a_data["longitude"]);
00321 $this->setLocationZoom($a_data["loc_zoom"]);
00322
00323
00324 $this->setLastLogin($a_data["last_login"]);
00325 $this->setLastUpdate($a_data["last_update"]);
00326 $this->create_date = $a_data["create_date"];
00327 $this->setComment($a_data["referral_comment"]);
00328 $this->approve_date = $a_data["approve_date"];
00329 $this->active = $a_data["active"];
00330 $this->accept_date = $a_data["agree_date"];
00331
00332
00333 $this->setTimeLimitOwner($a_data["time_limit_owner"]);
00334 $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
00335 $this->setTimeLimitFrom($a_data["time_limit_from"]);
00336 $this->setTimeLimitUntil($a_data["time_limit_until"]);
00337 $this->setTimeLimitMessage($a_data['time_limit_message']);
00338
00339
00340 $this->setProfileIncomplete($a_data["profile_incomplete"]);
00341
00342
00343
00344
00345
00346 $this->setAuthMode($a_data['auth_mode']);
00347 $this->setExternalAccount($a_data['ext_account']);
00348 }
00349
00356 function saveAsNew($a_from_formular = true)
00357 {
00358 global $ilErr, $ilDB;
00359
00360 switch ($this->passwd_type)
00361 {
00362 case IL_PASSWD_PLAIN:
00363 $pw_field = "passwd";
00364 if(strlen($this->passwd))
00365 {
00366 $pw_value = md5($this->passwd);
00367 }
00368 else
00369 {
00370 $pw_value = $this->passwd;
00371 }
00372 break;
00373
00374 case IL_PASSWD_MD5:
00375 $pw_field = "passwd";
00376 $pw_value = $this->passwd;
00377 break;
00378
00379 case IL_PASSWD_CRYPT:
00380 $pw_field = "i2passwd";
00381 $pw_value = $this->passwd;
00382 break;
00383
00384 default :
00385 $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
00386 $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
00387 "<br />Line: ".__LINE__, $ilErr->FATAL);
00388 }
00389
00390 if ($a_from_formular)
00391 {
00392 $q = "INSERT INTO usr_data "
00393 . "(usr_id,login,".$pw_field.",firstname,lastname,title,gender,"
00394 . "email,hobby,institution,department,street,city,zipcode,country,"
00395 . "phone_office,phone_home,phone_mobile,fax,last_login,last_update,create_date,"
00396 . "referral_comment,matriculation,client_ip, approve_date,active,"
00397 . "time_limit_unlimited,time_limit_until,time_limit_from,time_limit_owner,auth_mode,ext_account,profile_incomplete,"
00398 . "im_icq,im_yahoo,im_msn,im_aim,im_skype,delicious,latitude,longitude,loc_zoom) "
00399 . "VALUES "
00400 . "(".
00401 $ilDB->quote($this->id).",".
00402 $ilDB->quote($this->login).",".
00403 $ilDB->quote($pw_value).",".
00404 $ilDB->quote($this->firstname).",".
00405 $ilDB->quote($this->lastname).",".
00406 $ilDB->quote($this->utitle).",".
00407 $ilDB->quote($this->gender).",".
00408 $ilDB->quote($this->email).",".
00409 $ilDB->quote($this->hobby).",".
00410 $ilDB->quote($this->institution).",".
00411 $ilDB->quote($this->department).",".
00412 $ilDB->quote($this->street).",".
00413 $ilDB->quote($this->city).",".
00414 $ilDB->quote($this->zipcode).",".
00415 $ilDB->quote($this->country).",".
00416 $ilDB->quote($this->phone_office).",".
00417 $ilDB->quote($this->phone_home).",".
00418 $ilDB->quote($this->phone_mobile).",".
00419 $ilDB->quote($this->fax).", 0, now(), now(),".
00420 $ilDB->quote($this->referral_comment).",".
00421 $ilDB->quote($this->matriculation).",".
00422 $ilDB->quote($this->client_ip).",".
00423 $ilDB->quote($this->approve_date).",".
00424 $ilDB->quote($this->active).",".
00425 $ilDB->quote($this->getTimeLimitUnlimited()).",".
00426 $ilDB->quote($this->getTimeLimitUntil()).",".
00427 $ilDB->quote($this->getTimeLimitFrom()).",".
00428 $ilDB->quote($this->getTimeLimitOwner()).",".
00429 $ilDB->quote($this->getAuthMode()).",".
00430 $ilDB->quote($this->getExternalAccount()).",".
00431 $ilDB->quote($this->getProfileIncomplete()).",".
00432 $ilDB->quote($this->im_icq).",".
00433 $ilDB->quote($this->im_yahoo).",".
00434 $ilDB->quote($this->im_msn).",".
00435 $ilDB->quote($this->im_aim).",".
00436 $ilDB->quote($this->im_skype).",".
00437 $ilDB->quote($this->delicious).",".
00438 $ilDB->quote($this->latitude).",".
00439 $ilDB->quote($this->longitude).",".
00440 $ilDB->quote($this->loc_zoom).
00441 ")";
00442 }
00443 else
00444 {
00445 $q = "INSERT INTO usr_data ".
00446 "(usr_id,login,".$pw_field.",firstname,lastname,title,gender,"
00447 . "email,hobby,institution,department,street,city,zipcode,country,"
00448 . "phone_office,phone_home,phone_mobile,fax,last_login,last_update,create_date,"
00449 . "referral_comment,matriculation,client_ip, approve_date,active,"
00450 . "time_limit_unlimited,time_limit_until,time_limit_from,time_limit_owner,auth_mode,ext_account,profile_incomplete,"
00451 . "im_icq,im_yahoo,im_msn,im_aim,im_skype,delicious,latitude,longitude,loc_zoom) "
00452 . "VALUES "
00453 ."(".
00454 $ilDB->quote($this->id).",".
00455 $ilDB->quote($this->login).",".
00456 $ilDB->quote($pw_value).",".
00457 $ilDB->quote($this->firstname).",".
00458 $ilDB->quote($this->lastname).",".
00459 $ilDB->quote($this->utitle).",".
00460 $ilDB->quote($this->gender).",".
00461 $ilDB->quote($this->email).",".
00462 $ilDB->quote($this->hobby).",".
00463 $ilDB->quote($this->institution).",".
00464 $ilDB->quote($this->department).",".
00465 $ilDB->quote($this->street).",".
00466 $ilDB->quote($this->city).",".
00467 $ilDB->quote($this->zipcode).",".
00468 $ilDB->quote($this->country).",".
00469 $ilDB->quote($this->phone_office).",".
00470 $ilDB->quote($this->phone_home).",".
00471 $ilDB->quote($this->phone_mobile).",".
00472 $ilDB->quote($this->fax).", 0, now(), now(),".
00473 $ilDB->quote($this->referral_comment).",".
00474 $ilDB->quote($this->matriculation).",".
00475 $ilDB->quote($this->client_ip).",".
00476 $ilDB->quote($this->approve_date).",".
00477 $ilDB->quote($this->active).",".
00478 $ilDB->quote($this->getTimeLimitUnlimited()).",".
00479 $ilDB->quote($this->getTimeLimitUntil()).",".
00480 $ilDB->quote($this->getTimeLimitFrom()).",".
00481 $ilDB->quote($this->getTimeLimitOwner()).",".
00482 $ilDB->quote($this->getAuthMode()).",".
00483 $ilDB->quote($this->getExternalAccount()).",".
00484 $ilDB->quote($this->getProfileIncomplete()).",".
00485 $ilDB->quote($this->im_icq).",".
00486 $ilDB->quote($this->im_yahoo).",".
00487 $ilDB->quote($this->im_msn).",".
00488 $ilDB->quote($this->im_aim).",".
00489 $ilDB->quote($this->im_skype).",".
00490 $ilDB->quote($this->delicious).",".
00491 $ilDB->quote($this->latitude).",".
00492 $ilDB->quote($this->longitude).",".
00493 $ilDB->quote($this->loc_zoom).
00494 ")";
00495 }
00496
00497 $this->ilias->db->query($q);
00498
00499
00500 $this->addUserDefinedFieldEntry();
00501
00502 $this->updateUserDefinedFields();
00503
00504
00505 include_once ("Services/Mail/classes/class.ilMailbox.php");
00506 $mbox = new ilMailbox($this->id);
00507 $mbox->createDefaultFolder();
00508
00509 include_once "Services/Mail/classes/class.ilMailOptions.php";
00510 $mail_options = new ilMailOptions($this->id);
00511 $mail_options->createMailOptionsEntry();
00512
00513
00514 include_once "./Services/PersonalDesktop/classes/class.ilBookmarkFolder.php";
00515 $bmf = new ilBookmarkFolder(0, $this->id);
00516 $bmf->createNewBookmarkTree();
00517
00518 }
00519
00524 function update()
00525 {
00526 global $ilErr, $ilDB;
00527
00528
00529
00530 $this->syncActive();
00531
00532 $pw_udpate = '';
00533 switch ($this->passwd_type)
00534 {
00535 case IL_PASSWD_PLAIN:
00536 if(strlen($this->passwd))
00537 {
00538 $pw_update = "i2passwd='', passwd='".md5($this->passwd)."'";
00539 }
00540 else
00541 {
00542 $pw_update = "i2passwd='', passwd='".$this->passwd."'";
00543 }
00544 break;
00545
00546 case IL_PASSWD_MD5:
00547 $pw_update = "i2passwd='', passwd='".$this->passwd."'";
00548 break;
00549
00550 case IL_PASSWD_CRYPT:
00551 $pw_update = "passwd='', i2passwd='".$this->passwd."'";
00552 break;
00553
00554 default :
00555 $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
00556 get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
00557 }
00558 $q = "UPDATE usr_data SET ".
00559 "gender = ".$ilDB->quote($this->gender).",".
00560 "title= ".$ilDB->quote($this->utitle).",".
00561 "firstname= ".$ilDB->quote($this->firstname).",".
00562 "lastname= ".$ilDB->quote($this->lastname).",".
00563 "email= ".$ilDB->quote($this->email).",".
00564 "hobby= ".$ilDB->quote($this->hobby).",".
00565 "institution= ".$ilDB->quote($this->institution).",".
00566 "department= ".$ilDB->quote($this->department).",".
00567 "street= ".$ilDB->quote($this->street).",".
00568 "city= ".$ilDB->quote($this->city).",".
00569 "zipcode= ".$ilDB->quote($this->zipcode).",".
00570 "country= ".$ilDB->quote($this->country).",".
00571 "phone_office= ".$ilDB->quote($this->phone_office).",".
00572 "phone_home= ".$ilDB->quote($this->phone_home).",".
00573 "phone_mobile= ".$ilDB->quote($this->phone_mobile).",".
00574 "fax= ".$ilDB->quote($this->fax).",".
00575 "referral_comment= ".$ilDB->quote($this->referral_comment).",".
00576 "matriculation= ".$ilDB->quote($this->matriculation).",".
00577 "client_ip= ".$ilDB->quote($this->client_ip).",".
00578 "approve_date= ".$ilDB->quote($this->approve_date).",".
00579 "active= ".$ilDB->quote($this->active).",".
00580 "time_limit_owner= ".$ilDB->quote($this->getTimeLimitOwner()).",".
00581 "time_limit_unlimited= ".$ilDB->quote($this->getTimeLimitUnlimited()).",".
00582 "time_limit_from= ".$ilDB->quote($this->getTimeLimitFrom()).",".
00583 "time_limit_until= ".$ilDB->quote($this->getTimeLimitUntil()).",".
00584 "time_limit_message= ".$ilDB->quote($this->getTimeLimitMessage()).",".
00585 "profile_incomplete = ".$ilDB->quote($this->getProfileIncomplete()).",".
00586 "auth_mode= ".$ilDB->quote($this->getAuthMode()).", ".
00587 "ext_account= ".$ilDB->quote($this->getExternalAccount()).",".
00588 $pw_update.", ".
00589 "im_icq= ".$ilDB->quote($this->getInstantMessengerId('icq')).",".
00590 "im_yahoo= ".$ilDB->quote($this->getInstantMessengerId('yahoo')).",".
00591 "im_msn= ".$ilDB->quote($this->getInstantMessengerId('msn')).",".
00592 "im_aim= ".$ilDB->quote($this->getInstantMessengerId('aim')).",".
00593 "im_skype= ".$ilDB->quote($this->getInstantMessengerId('skype')).",".
00594 "delicious= ".$ilDB->quote($this->getDelicious()).",".
00595 "latitude= ".$ilDB->quote($this->getLatitude()).",".
00596 "longitude= ".$ilDB->quote($this->getLongitude()).",".
00597 "loc_zoom= ".$ilDB->quote($this->getLocationZoom()).",".
00598 "last_update=now()".
00599
00600
00601
00602 "WHERE usr_id= ".$ilDB->quote($this->id);
00603
00604 $this->ilias->db->query($q);
00605 $this->writePrefs();
00606
00607
00608 $this->updateUserDefinedFields();
00609
00610
00611 parent::update();
00612 parent::updateOwner();
00613
00614 $this->read();
00615
00616 return true;
00617 }
00618
00622 function writeAccepted()
00623 {
00624 global $ilDB;
00625
00626 $q = "UPDATE usr_data SET agree_date = now()".
00627 "WHERE usr_id = ".$ilDB->quote($this->getId());
00628 $ilDB->query($q);
00629
00630 }
00631
00632 function _lookupEmail($a_user_id)
00633 {
00634 global $ilDB;
00635
00636 $query = "SELECT email FROM usr_data WHERE usr_id = ".$ilDB->quote((int) $a_user_id);
00637 $res = $ilDB->query($query);
00638
00639 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00640 {
00641 return $row->email;
00642 }
00643 return false;
00644 }
00645
00646 function _lookupGender($a_user_id)
00647 {
00648 global $ilDB;
00649
00650 $query = "SELECT gender FROM usr_data WHERE usr_id = ".
00651 $ilDB->quote((int) $a_user_id);
00652 $res = $ilDB->query($query);
00653
00654 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00655 {
00656 return $row->gender;
00657 }
00658 return false;
00659 }
00660
00661 function _lookupClientIP($a_user_id)
00662 {
00663 global $ilDB;
00664
00665 $query = "SELECT client_ip FROM usr_data WHERE usr_id = ".
00666 $ilDB->quote((int) $a_user_id);
00667 $res = $ilDB->query($query);
00668
00669 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00670 {
00671 return $row->client_ip;
00672 }
00673 return "";
00674 }
00675
00676
00680 function _lookupName($a_user_id)
00681 {
00682 global $ilDB;
00683
00684 $q = "SELECT firstname, lastname, title FROM usr_data".
00685 " WHERE usr_id =".$ilDB->quote($a_user_id);
00686 $user_set = $ilDB->query($q);
00687 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00688 return array("user_id" => $a_user_id,
00689 "firstname" => $user_rec["firstname"],
00690 "lastname" => $user_rec["lastname"],
00691 "title" => $user_rec["title"]);
00692 }
00693
00697 function _lookupFields($a_user_id)
00698 {
00699 global $ilDB;
00700
00701 $q = "SELECT * FROM usr_data".
00702 " WHERE usr_id =".$ilDB->quote($a_user_id);
00703 $user_set = $ilDB->query($q);
00704 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00705 return $user_rec;
00706 }
00707
00711 function _lookupLogin($a_user_id)
00712 {
00713 global $ilDB;
00714
00715 $q = "SELECT login FROM usr_data".
00716 " WHERE usr_id =".$ilDB->quote($a_user_id);
00717 $user_set = $ilDB->query($q);
00718 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00719 return $user_rec["login"];
00720 }
00721
00725 function _lookupExternalAccount($a_user_id)
00726 {
00727 global $ilDB;
00728
00729 $q = "SELECT ext_account FROM usr_data".
00730 " WHERE usr_id =".$ilDB->quote($a_user_id);
00731 $user_set = $ilDB->query($q);
00732 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00733 return $user_rec["ext_account"];
00734 }
00735
00739 function _lookupId($a_user_str)
00740 {
00741 global $ilDB;
00742
00743 $q = "SELECT usr_id FROM usr_data".
00744 " WHERE login =".$ilDB->quote($a_user_str);
00745 $user_set = $ilDB->query($q);
00746 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00747 return $user_rec["usr_id"];
00748 }
00749
00753 function _lookupLastLogin($a_user_id)
00754 {
00755 global $ilDB;
00756
00757 $q = "SELECT last_login FROM usr_data".
00758 " WHERE usr_id =".$ilDB->quote($a_user_id);
00759 $user_set = $ilDB->query($q);
00760 $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
00761 return $user_rec["last_login"];
00762 }
00763
00764
00770 function refreshLogin()
00771 {
00772 global $ilDB;
00773
00774 $q = "UPDATE usr_data SET ".
00775 "last_login = now() ".
00776 "WHERE usr_id = ".$ilDB->quote($this->id);
00777
00778 $this->ilias->db->query($q);
00779 }
00780
00787 function replacePassword($new_md5)
00788 {
00789 global $ilDB;
00790
00791 $this->passwd_type = IL_PASSWD_MD5;
00792 $this->passwd = $new_md5;
00793
00794 $q = "UPDATE usr_data SET ".
00795 "passwd= ".$ilDB->quote($this->passwd)." ".
00796 "WHERE usr_id= ".$ilDB->quote($this->id);
00797
00798 $this->ilias->db->query($q);
00799
00800 return true;
00801 }
00802
00811 function updatePassword($a_old, $a_new1, $a_new2)
00812 {
00813 global $ilDB;
00814
00815 if (func_num_args() != 3)
00816 {
00817 return false;
00818 }
00819
00820 if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
00821 {
00822 return false;
00823 }
00824
00825 if ($a_new1 != $a_new2)
00826 {
00827 return false;
00828 }
00829
00830
00831 if ($a_new1 == "" || $a_old == "")
00832 {
00833 return false;
00834 }
00835
00836
00837 switch ($this->passwd_type)
00838 {
00839 case IL_PASSWD_PLAIN:
00840 if ($a_old != $this->passwd)
00841 {
00842 return false;
00843 }
00844 break;
00845
00846 case IL_PASSWD_MD5:
00847 if (md5($a_old) != $this->passwd)
00848 {
00849 return false;
00850 }
00851 break;
00852
00853 case IL_PASSWD_CRYPT:
00854 if (_makeIlias2Password($a_old) != $this->passwd)
00855 {
00856 return false;
00857 }
00858 break;
00859 }
00860
00861
00862 $this->passwd = md5($a_new1);
00863 $this->passwd_type = IL_PASSWD_MD5;
00864
00865 $q = "UPDATE usr_data SET ".
00866 "passwd= ".$ilDB->quote($this->passwd)." ".
00867 "WHERE usr_id= ".$ilDB->quote($this->id)." ";
00868 $this->ilias->db->query($q);
00869
00870 return true;
00871 }
00872
00880 function resetPassword($a_new1, $a_new2)
00881 {
00882 global $ilDB;
00883
00884 if (func_num_args() != 2)
00885 {
00886 return false;
00887 }
00888
00889 if (!isset($a_new1) or !isset($a_new2))
00890 {
00891 return false;
00892 }
00893
00894 if ($a_new1 != $a_new2)
00895 {
00896 return false;
00897 }
00898
00899
00900 $this->passwd = md5($a_new1);
00901 $this->passwd_type = IL_PASSWD_MD5;
00902
00903 $q = "UPDATE usr_data SET ".
00904 "passwd= ".$ilDB->quote($this->passwd)." ".
00905 "WHERE usr_id= ".$ilDB->quote($this->id);
00906 $this->ilias->db->query($q);
00907
00908 return true;
00909 }
00910
00914 function _makeIlias2Password($a_passwd)
00915 {
00916 return (crypt($a_passwd,substr($a_passwd,0,2)));
00917 }
00918
00922 function _lookupHasIlias2Password($a_user_login)
00923 {
00924 global $ilias, $ilDB;
00925
00926 $q = "SELECT i2passwd FROM usr_data ".
00927 "WHERE login = ".$ilDB->quote($a_user_login)."";
00928 $user_set = $ilias->db->query($q);
00929
00930 if ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
00931 {
00932 if ($user_rec["i2passwd"] != "")
00933 {
00934 return true;
00935 }
00936 }
00937
00938 return false;
00939 }
00940
00941 function _switchToIlias3Password($a_user, $a_pw)
00942 {
00943 global $ilias, $ilDB;
00944
00945 $q = "SELECT i2passwd FROM usr_data ".
00946 "WHERE login = ".$ilDB->quote($a_user);
00947
00948 $user_set = $ilias->db->query($q);
00949
00950 if ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
00951 {
00952 if ($user_rec["i2passwd"] == ilObjUser::_makeIlias2Password($a_pw))
00953 {
00954 $q = "UPDATE usr_data SET passwd= ".$ilDB->quote(md5($a_pw)).", i2passwd=''".
00955 "WHERE login = ".$ilDB->quote($a_user);
00956 $ilias->db->query($q);
00957 return true;
00958 }
00959 }
00960
00961 return false;
00962 }
00963
00970 function updateLogin($a_login)
00971 {
00972 global $ilDB;
00973
00974 if (func_num_args() != 1)
00975 {
00976 return false;
00977 }
00978
00979 if (!isset($a_login))
00980 {
00981 return false;
00982 }
00983
00984
00985 $this->login = $a_login;
00986
00987 $q = "UPDATE usr_data SET ".
00988 "login= ".$ilDB->quote($this->login)." ".
00989 "WHERE usr_id= ".$ilDB->quote($this->id);
00990 $this->ilias->db->query($q);
00991
00992 return true;
00993 }
00994
01001 function writePref($a_keyword, $a_value)
01002 {
01003 ilObjUser::_writePref($this->id, $a_keyword, $a_value);
01004 $this->setPref($a_keyword, $a_value);
01005 }
01006
01007
01013 function deletePref($a_keyword)
01014 {
01015 global $ilDB;
01016
01017 $query = sprintf("DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s",
01018 $ilDB->quote($this->getId() . ""),
01019 $ilDB->quote($a_keyword . "")
01020 );
01021 $ilDB->query($query);
01022 }
01023
01024 function _writePref($a_usr_id, $a_keyword, $a_value)
01025 {
01026 global $ilDB;
01027
01028 $query = "";
01029 if (strlen($a_value))
01030 {
01031 $query = sprintf("REPLACE INTO usr_pref VALUES (%s, %s, %s)",
01032 $ilDB->quote($a_usr_id),
01033 $ilDB->quote($a_keyword),
01034 $ilDB->quote($a_value)
01035 );
01036 }
01037 else
01038 {
01039 $query = sprintf("DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s",
01040 $ilDB->quote($a_usr_id),
01041 $ilDB->quote($a_keyword)
01042 );
01043 }
01044 $ilDB->query($query);
01045 }
01046
01051 function writePrefs()
01052 {
01053 global $ilDB;
01054
01055
01056 $q = "DELETE FROM usr_pref ".
01057 "WHERE usr_id= ".$ilDB->quote($this->id);
01058 $this->ilias->db->query($q);
01059
01060 foreach ($this->prefs as $keyword => $value)
01061 {
01062
01063 $q = "INSERT INTO usr_pref ".
01064 "(usr_id, keyword, value) ".
01065 "VALUES ".
01066 "(".$ilDB->quote($this->id).",".$ilDB->quote($keyword).",".
01067 $ilDB->quote($value).")";
01068 $this->ilias->db->query($q);
01069 }
01070 }
01071
01078 function setPref($a_keyword, $a_value)
01079 {
01080 if ($a_keyword != "")
01081 {
01082 $this->prefs[$a_keyword] = $a_value;
01083 }
01084 }
01085
01091 function getPref($a_keyword)
01092 {
01093 if (array_key_exists($a_keyword, $this->prefs))
01094 {
01095 return $this->prefs[$a_keyword];
01096 }
01097 else
01098 {
01099 return FALSE;
01100 }
01101 }
01102
01103 function _lookupPref($a_usr_id,$a_keyword)
01104 {
01105 global $ilDB;
01106
01107 $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
01108 "AND keyword = ".$ilDB->quote($a_keyword);
01109 $res = $ilDB->query($query);
01110
01111 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01112 {
01113 return $row->value;
01114 }
01115 return false;
01116 }
01117
01123 function readPrefs()
01124 {
01125 global $ilDB;
01126
01127 if (is_array($this->prefs))
01128 {
01129 $this->oldPrefs = $this->prefs;
01130 }
01131
01132 $this->prefs = array();
01133
01134 $q = "SELECT * FROM usr_pref WHERE usr_id = ".
01135 $ilDB->quote($this->id);
01136 $r = $this->ilias->db->query($q);
01137
01138 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
01139 {
01140 $this->prefs[$row["keyword"]] = $row["value"];
01141 }
01142
01143 return $r->numRows();
01144 }
01145
01151 function delete()
01152 {
01153 global $rbacadmin, $ilDB;
01154
01155
01156 include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
01157 $mapping = ilLDAPRoleGroupMapping::_getInstance();
01158 $mapping->deleteUser($this->getId());
01159
01160
01161 include_once ("Services/Mail/classes/class.ilMailbox.php");
01162 $mailbox = new ilMailbox($this->getId());
01163 $mailbox->delete();
01164 $mailbox->updateMailsOfDeletedUser();
01165
01166
01167 include_once("./Services/Block/classes/class.ilCustomBlock.php");
01168 $costum_block = new ilCustomBlock();
01169 $costum_block->setContextObjId($this->getId());
01170 $costum_block->setContextObjType("user");
01171 $c_blocks = $costum_block->queryBlocksForContext();
01172 include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
01173 foreach($c_blocks as $c_block)
01174 {
01175 if ($c_block["type"] == "pdfeed")
01176 {
01177 $fb = new ilPDExternalFeedBlock($c_block["id"]);
01178 $fb->delete();
01179 }
01180 }
01181
01182
01183
01184 include_once("./Services/Block/classes/class.ilBlockSetting.php");
01185 ilBlockSetting::_deleteSettingsOfUser($this->getId());
01186
01187
01188 $this->ilias->db->query("DELETE FROM usr_data WHERE usr_id = ".
01189 $ilDB->quote($this->getId()));
01190
01191
01192 $this->ilias->db->query("DELETE FROM usr_pref WHERE usr_id= ".
01193 $ilDB->quote($this->getId()));
01194
01195
01196 $this->ilias->db->query("DELETE FROM usr_session WHERE user_id= ".
01197 $ilDB->quote($this->getId()));
01198
01199
01200 $rbacadmin->removeUser($this->getId());
01201
01202
01203
01204 $q = "DELETE FROM bookmark_tree WHERE tree = ".
01205 $ilDB->quote($this->getId());
01206 $this->ilias->db->query($q);
01207
01208 $q = "DELETE FROM bookmark_data WHERE user_id= ".
01209 $ilDB->quote($this->getId());
01210 $this->ilias->db->query($q);
01211
01212
01213 include_once './Modules/Forum/classes/class.ilObjForum.php';
01214 ilObjForum::_deleteUser($this->getId());
01215
01216
01217 include_once './classes/class.ilLinkCheckNotify.php';
01218 ilLinkCheckNotify::_deleteUser($this->getId());
01219
01220
01221 include_once './Modules/Course/classes/class.ilObjCourse.php';
01222 ilObjCourse::_deleteUser($this->getId());
01223
01224
01225 include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
01226 ilObjUserTracking::_deleteUser($this->getId());
01227
01228 include_once 'Modules/Course/classes/Event/class.ilEventParticipants.php';
01229 ilEventParticipants::_deleteByUser($this->getId());
01230
01231
01232 $q = "DELETE FROM grp_registration WHERE user_id= ".
01233 $ilDB->quote($this->getId());
01234 $this->ilias->db->query($q);
01235
01236
01237 $this->deleteUserDefinedFieldEntries();
01238
01239
01240 parent::delete();
01241 return true;
01242 }
01243
01253 function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
01254 {
01255 $this->fullname = "";
01256
01257 if ($a_title)
01258 {
01259 $fullname = $a_title." ";
01260 }
01261 elseif ($this->utitle)
01262 {
01263 $this->fullname = $this->utitle." ";
01264 }
01265
01266 if ($a_firstname)
01267 {
01268 $fullname .= $a_firstname." ";
01269 }
01270 elseif ($this->firstname)
01271 {
01272 $this->fullname .= $this->firstname." ";
01273 }
01274
01275 if ($a_lastname)
01276 {
01277 return $fullname.$a_lastname;
01278 }
01279
01280 $this->fullname .= $this->lastname;
01281 }
01282
01297 function getFullname($a_max_strlen = 0)
01298 {
01299 if (!$a_max_strlen)
01300 {
01301 return ilUtil::stripSlashes($this->fullname);
01302 }
01303
01304 if (strlen($this->fullname) <= $a_max_strlen)
01305 {
01306 return ilUtil::stripSlashes($this->fullname);
01307 }
01308
01309 if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
01310 {
01311 return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
01312 }
01313
01314 if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
01315 {
01316 return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
01317 }
01318
01319 if ((strlen($this->lastname) + 3) <= $a_max_strlen)
01320 {
01321 return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
01322 }
01323
01324 return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
01325 }
01326
01327
01333 function getLastVisitedLessons()
01334 {
01335 global $ilDB;
01336
01337
01338 $q = "SELECT * FROM lo_access ".
01339 "WHERE usr_id= ".$ilDB->quote($this->id)." ".
01340 "ORDER BY timestamp DESC";
01341 $rst = $this->ilias->db->query($q);
01342
01343
01344 $result = array();
01345 while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
01346 {
01347 $result[] = array(
01348 "timestamp" => $record->timestamp,
01349 "usr_id" => $record->usr_id,
01350 "lm_id" => $record->lm_id,
01351 "obj_id" => $record->obj_id,
01352 "lm_title" => $record->lm_title);
01353 }
01354 return $result;
01355 }
01356
01357
01363 function getLessons()
01364 {
01365 global $ilDB;
01366
01367
01368 $q = "SELECT * FROM lo_access ".
01369 "WHERE usr_id= ".$ilDB->quote($this->id)." ";
01370 $rst = $this->ilias->db->query($q);
01371
01372
01373 $result = array();
01374 while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
01375 {
01376 $result[] = array(
01377 "timestamp" => $record->timestamp,
01378 "usr_id" => $record->usr_id,
01379 "lm_id" => $record->lm_id,
01380 "obj_id" => $record->obj_id,
01381 "lm_title" => $record->lm_title);
01382 }
01383 return $result;
01384 }
01385
01394 public static function _hasAcceptedAgreement($a_username)
01395 {
01396 global $ilDB;
01397
01398 if($a_username == 'root')
01399 {
01400 return true;
01401 }
01402
01403 $query = "SELECT usr_id FROM usr_data ".
01404 "WHERE login = ".$ilDB->quote($a_username)." ".
01405 "AND agree_date != '0000-00-00 00:00:00'";
01406 $res = $ilDB->query($query);
01407 return $res->numRows() ? true : false;
01408 }
01409
01410
01414 function hasAcceptedUserAgreement()
01415 {
01416 if ($this->accept_date != "0000-00-00 00:00:00" || $this->login == "root")
01417 {
01418 return true;
01419 }
01420 return false;
01421 }
01422
01428 function setLogin($a_str)
01429 {
01430 $this->login = $a_str;
01431 }
01432
01437 function getLogin()
01438 {
01439 return $this->login;
01440 }
01441
01447 function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
01448 {
01449 $this->passwd = $a_str;
01450 $this->passwd_type = $a_type;
01451 }
01452
01460 function getPasswd()
01461 {
01462 return $this->passwd;
01463 }
01470 function getPasswdType()
01471 {
01472 return $this->passwd_type;
01473 }
01474
01480 function setGender($a_str)
01481 {
01482 $this->gender = substr($a_str,-1);
01483 }
01484
01489 function getGender()
01490 {
01491 return $this->gender;
01492 }
01493
01501 function setUTitle($a_str)
01502 {
01503 $this->utitle = $a_str;
01504 }
01505
01512 function getUTitle()
01513 {
01514 return $this->utitle;
01515 }
01516
01522 function setFirstname($a_str)
01523 {
01524 $this->firstname = $a_str;
01525 }
01526
01531 function getFirstname()
01532 {
01533 return $this->firstname;
01534 }
01535
01541 function setLastname($a_str)
01542 {
01543 $this->lastname = $a_str;
01544 }
01545
01550 function getLastname()
01551 {
01552 return $this->lastname;
01553 }
01554
01560 function setInstitution($a_str)
01561 {
01562 $this->institution = $a_str;
01563 }
01564
01569 function getInstitution()
01570 {
01571 return $this->institution;
01572 }
01573
01579 function setDepartment($a_str)
01580 {
01581 $this->department = $a_str;
01582 }
01583
01588 function getDepartment()
01589 {
01590 return $this->department;
01591 }
01592
01598 function setStreet($a_str)
01599 {
01600 $this->street = $a_str;
01601 }
01602
01607 function getStreet()
01608 {
01609 return $this->street;
01610 }
01611
01617 function setCity($a_str)
01618 {
01619 $this->city = $a_str;
01620 }
01621
01626 function getCity()
01627 {
01628 return $this->city;
01629 }
01630
01636 function setZipcode($a_str)
01637 {
01638 $this->zipcode = $a_str;
01639 }
01640
01645 function getZipcode()
01646 {
01647 return $this->zipcode;
01648 }
01649
01655 function setCountry($a_str)
01656 {
01657 $this->country = $a_str;
01658 }
01659
01664 function getCountry()
01665 {
01666 return $this->country;
01667 }
01668
01674 function setPhoneOffice($a_str)
01675 {
01676 $this->phone_office = $a_str;
01677 }
01678
01683 function getPhoneOffice()
01684 {
01685 return $this->phone_office;
01686 }
01687
01693 function setPhoneHome($a_str)
01694 {
01695 $this->phone_home = $a_str;
01696 }
01697
01702 function getPhoneHome()
01703 {
01704 return $this->phone_home;
01705 }
01706
01712 function setPhoneMobile($a_str)
01713 {
01714 $this->phone_mobile = $a_str;
01715 }
01716
01721 function getPhoneMobile()
01722 {
01723 return $this->phone_mobile;
01724 }
01725
01731 function setFax($a_str)
01732 {
01733 $this->fax = $a_str;
01734 }
01735
01740 function getFax()
01741 {
01742 return $this->fax;
01743 }
01744
01750 function setClientIP($a_str)
01751 {
01752 $this->client_ip = $a_str;
01753 }
01754
01759 function getClientIP()
01760 {
01761 return $this->client_ip;
01762 }
01763
01769 function setMatriculation($a_str)
01770 {
01771 $this->matriculation = $a_str;
01772 }
01773
01778 function getMatriculation()
01779 {
01780 return $this->matriculation;
01781 }
01782
01788 function setEmail($a_str)
01789 {
01790 $this->email = $a_str;
01791 }
01792
01797 function getEmail()
01798 {
01799 return $this->email;
01800 }
01801
01807 function setHobby($a_str)
01808 {
01809 $this->hobby = $a_str;
01810 }
01811
01816 function getHobby()
01817 {
01818 return $this->hobby;
01819 }
01820
01826 function setLanguage($a_str)
01827 {
01828 $this->setPref("language",$a_str);
01829 unset($_SESSION['lang']);
01830 }
01831
01837 function getLanguage()
01838 {
01839 return $this->prefs["language"];
01840 }
01841
01842 function _lookupLanguage($a_usr_id)
01843 {
01844 global $ilDB;
01845
01846 $q = "SELECT value FROM usr_pref WHERE usr_id= ".
01847 $ilDB->quote($a_usr_id)." AND keyword = 'language'";
01848 $r = $ilDB->query($q);
01849
01850 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
01851 {
01852 return $row['value'];
01853 }
01854 return 'en';
01855 }
01856
01857
01858 function _checkPassword($a_usr_id, $a_pw)
01859 {
01860 global $ilDB;
01861
01862 $q = "SELECT passwd FROM usr_data ".
01863 " WHERE usr_id = ".$ilDB->quote($a_usr_id);
01864 $usr_set = $ilDB->query($q);
01865
01866 if($usr_rec = $usr_set->fetchRow(DB_FETCHMODE_ASSOC))
01867 {
01868 if ($usr_rec["passwd"] == md5($a_pw))
01869 {
01870 return true;
01871 }
01872 }
01873 return false;
01874 }
01875
01876 function _writeExternalAccount($a_usr_id, $a_ext_id)
01877 {
01878 global $ilDB;
01879
01880 $q = "UPDATE usr_data ".
01881 " SET ext_account = ".$ilDB->quote($a_ext_id).
01882 " WHERE usr_id = ".$ilDB->quote($a_usr_id);
01883 $usr_set = $ilDB->query($q);
01884 }
01885
01886 function _writeAuthMode($a_usr_id, $a_auth_mode)
01887 {
01888 global $ilDB;
01889
01890 $q = "UPDATE usr_data ".
01891 " SET auth_mode = ".$ilDB->quote($a_auth_mode).
01892 " WHERE usr_id = ".$ilDB->quote($a_usr_id);
01893 $usr_set = $ilDB->query($q);
01894 }
01895
01900 function getCurrentLanguage()
01901 {
01902 return $_SESSION['lang'];
01903 }
01904
01910 function setLastLogin($a_str)
01911 {
01912 $this->last_login = $a_str;
01913 }
01914
01920 function getLastLogin()
01921 {
01922 return $this->last_login;
01923 }
01924
01930 function setLastUpdate($a_str)
01931 {
01932 $this->last_update = $a_str;
01933 }
01934 function getLastUpdate()
01935 {
01936 return $this->last_update;
01937 }
01938
01944 function setComment($a_str)
01945 {
01946 $this->referral_comment = $a_str;
01947 }
01948
01953 function getComment()
01954 {
01955 return $this->referral_comment;
01956 }
01957
01964 function setApproveDate($a_str)
01965 {
01966 $this->approve_date = $a_str;
01967 }
01968
01974 function getApproveDate()
01975 {
01976 return $this->approve_date;
01977 }
01978
01985 function setActive($a_active, $a_owner = 6)
01986 {
01987 if (empty($a_owner))
01988 {
01989 $a_owner = 0;
01990 }
01991
01992 if ($a_active)
01993 {
01994 $this->active = 1;
01995 $this->setApproveDate(date('Y-m-d H:i:s'));
01996 $this->setOwner($a_owner);
01997 }
01998 else
01999 {
02000 $this->active = 0;
02001 $this->setApproveDate('0000-00-00 00:00:00');
02002 $this->setOwner(0);
02003 }
02004 }
02005
02010 function getActive()
02011 {
02012 return $this->active;
02013 }
02014
02020 function syncActive()
02021 {
02022 global $ilAuth;
02023
02024 $storedActive = 0;
02025 if ($this->getStoredActive($this->id))
02026 {
02027 $storedActive = 1;
02028 }
02029
02030 $currentActive = 0;
02031 if ($this->active)
02032 {
02033 $currentActive = 1;
02034 }
02035
02036 if ((!empty($storedActive) && empty($currentActive)) ||
02037 (empty($storedActive) && !empty($currentActive)))
02038 {
02039 $this->setActive($currentActive, $this->getUserIdByLogin($ilAuth->getUsername()));
02040 }
02041 }
02042
02049 function getStoredActive($a_id)
02050 {
02051 global $ilias, $ilDB;
02052
02053 $query = "SELECT active FROM usr_data ".
02054 "WHERE usr_id = ".$ilDB->quote($a_id);
02055
02056 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
02057
02058 return $row->active ? true : false;
02059 }
02060
02066 function setSkin($a_str)
02067 {
02068
02069 $this->skin = $a_str;
02070 }
02071
02072 function setTimeLimitOwner($a_owner)
02073 {
02074 $this->time_limit_owner = $a_owner;
02075 }
02076 function getTimeLimitOwner()
02077 {
02078 return $this->time_limit_owner ? $this->time_limit_owner : 7;
02079 }
02080 function setTimeLimitFrom($a_from)
02081 {
02082 $this->time_limit_from = $a_from;
02083 }
02084 function getTimeLimitFrom()
02085 {
02086 return $this->time_limit_from ? $this->time_limit_from : time();
02087 }
02088 function setTimeLimitUntil($a_until)
02089 {
02090 $this->time_limit_until = $a_until;
02091 }
02092 function getTimeLimitUntil()
02093 {
02094 return $this->time_limit_until ? $this->time_limit_until : time();
02095 }
02096 function setTimeLimitUnlimited($a_unlimited)
02097 {
02098 $this->time_limit_unlimited = $a_unlimited;
02099 }
02100 function getTimeLimitUnlimited()
02101 {
02102 return $this->time_limit_unlimited;
02103 }
02104 function setTimeLimitMessage($a_time_limit_message)
02105 {
02106 return $this->time_limit_message = $a_time_limit_message;
02107 }
02108 function getTimeLimitMessage()
02109 {
02110 return $this->time_limit_message;
02111 }
02112
02113
02114 function checkTimeLimit()
02115 {
02116 if($this->getTimeLimitUnlimited())
02117 {
02118 return true;
02119 }
02120 if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
02121 {
02122 return true;
02123 }
02124 return false;
02125 }
02126 function setProfileIncomplete($a_prof_inc)
02127 {
02128 $this->profile_incomplete = (boolean) $a_prof_inc;
02129 }
02130 function getProfileIncomplete()
02131 {
02132 return $this->profile_incomplete;
02133 }
02134
02135
02141 function setLatitude($a_latitude)
02142 {
02143 $this->latitude = $a_latitude;
02144 }
02145
02151 function getLatitude()
02152 {
02153 return $this->latitude;
02154 }
02155
02161 function setLongitude($a_longitude)
02162 {
02163 $this->longitude = $a_longitude;
02164 }
02165
02171 function getLongitude()
02172 {
02173 return $this->longitude;
02174 }
02175
02181 function setLocationZoom($a_locationzoom)
02182 {
02183 $this->loc_zoom = $a_locationzoom;
02184 }
02185
02191 function getLocationZoom()
02192 {
02193 return $this->loc_zoom;
02194 }
02195
02196 function &getAppliedUsers()
02197 {
02198 $this->applied_users = array();
02199 $this->__readAppliedUsers($this->getId());
02200
02201 return $this->applied_users ? $this->applied_users : array();
02202 }
02203
02204 function isChild($a_usr_id)
02205 {
02206 if($a_usr_id == $this->getId())
02207 {
02208 return true;
02209 }
02210
02211 $this->applied_users = array();
02212 $this->__readAppliedUsers($this->getId());
02213
02214 return in_array($a_usr_id,$this->applied_users);
02215 }
02216
02217 function __readAppliedUsers($a_parent_id)
02218 {
02219 global $ilDB;
02220
02221 $query = "SELECT usr_id FROM usr_data ".
02222 "WHERE time_limit_owner = ".$ilDB->quote($a_parent_id);
02223
02224 $res = $this->ilias->db->query($query);
02225 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02226 {
02227 $this->applied_users[] = $row->usr_id;
02228
02229
02230 $this->__readAppliedUsers($row->usr_id);
02231 }
02232 return true;
02233 }
02234
02235
02236
02237
02238
02239 function checkUserId()
02240 {
02241 global $ilDB,$ilAuth;
02242
02243 $r = $this->ilias->db->query("SELECT usr_id FROM usr_data WHERE login = ".
02244 $ilDB->quote($ilAuth->getUsername()));
02245
02246 if ($r->numRows() > 0)
02247 {
02248 $data = $r->fetchRow();
02249 $this->id = $data[0];
02250
02251 return $this->id;
02252 }
02253
02254 return false;
02255 }
02256
02257
02258
02259
02260
02261
02262 function isCurrentUserActive()
02263 {
02264 global $ilDB,$ilAuth;
02265
02266 $r = $this->ilias->db->query("SELECT active FROM usr_data WHERE login= ".
02267 $ilDB->quote($ilAuth->getUsername()));
02268
02269 if ($r->numRows() > 0)
02270 {
02271 $data = $r->fetchRow();
02272 if (!empty($data[0]))
02273 {
02274 return true;
02275 }
02276 }
02277
02278 return false;
02279 }
02280
02281
02282
02283
02284
02285
02286
02287
02288
02289 function getUserIdByLogin($a_login)
02290 {
02291 global $ilias, $ilDB;
02292
02293 $query = "SELECT usr_id FROM usr_data ".
02294 "WHERE login = ".$ilDB->quote($a_login);
02295
02296 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
02297
02298 return $row->usr_id ? $row->usr_id : 0;
02299 }
02300
02309 function _getUserIdsByEmail($a_email)
02310 {
02311 global $ilias, $ilDB;
02312
02313 $query = "SELECT login FROM usr_data ".
02314 "WHERE email = ".$ilDB->quote($a_email)." and active=1";
02315
02316 $res = $ilias->db->query($query);
02317 $ids = array ();
02318 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02319 {
02320 $ids[] = $row->login;
02321 }
02322
02323 return $ids;
02324 }
02325
02326
02327
02336 function getUserIdByEmail($a_email)
02337 {
02338 global $ilDB;
02339
02340 $query = "SELECT usr_id FROM usr_data ".
02341 "WHERE email = ".$ilDB->quote($a_email);
02342
02343 $row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
02344 return $row->usr_id ? $row->usr_id : 0;
02345 }
02346
02347
02348
02349
02350
02351
02352
02353
02354
02355 function getLoginByUserId($a_userid)
02356 {
02357 global $ilias, $ilDB;
02358
02359 $query = "SELECT login FROM usr_data ".
02360 "WHERE usr_id = ".$ilDB->quote($a_userid);
02361
02362 $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
02363
02364 return $row->login ? $row->login : false;
02365 }
02366
02377 function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
02378 {
02379
02380 global $ilias, $ilDB;
02381
02382 $active_filter = "";
02383 $time_limit_filter = "";
02384 $join_filter = " WHERE ";
02385 $last_login_filter = "";
02386 $without_anonymous_users = "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID);
02387 if (is_numeric($active) && $active > -1 && $filter_settings === FALSE) $active_filter = " AND active = ".$ilDB->quote($active);
02388 global $ilLog; $ilLog->write("active = $active, filter settings = $filter_settings, active_filter = $active_filter");
02389
02390
02391 if ($filter_settings !== FALSE && strlen($filter_settings))
02392 {
02393 switch ($filter_settings)
02394 {
02395 case -1:
02396 $active_filter = "";
02397
02398 break;
02399 case 0:
02400 $active_filter = " AND usr_data.active = " . $ilDB->quote("0");
02401
02402 break;
02403 case 1:
02404 $active_filter = " AND usr_data.active = " . $ilDB->quote("1");
02405
02406 break;
02407 case 2:
02408 $time_limit_filter = " AND usr_data.time_limit_unlimited = " . $ilDB->quote("0");
02409
02410 break;
02411 case 3:
02412
02413 $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.usr_id IS NULL AND ";
02414 break;
02415 case 4:
02416 $date = strftime("%Y-%m-%d %H:%I:%S", mktime(0, 0, 0, $_SESSION["user_filter_data"]["m"], $_SESSION["user_filter_data"]["d"], $_SESSION["user_filter_data"]["y"]));
02417 $last_login_filter = sprintf(" AND last_login < %s", $ilDB->quote($date));
02418 break;
02419 case 5:
02420
02421 $ref_id = $_SESSION["user_filter_data"];
02422 if ($ref_id)
02423 {
02424 $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.obj_id = (SELECT obj_id FROM object_reference WHERE ref_id = " .
02425 $ilDB->quote($ref_id) . ") AND ";
02426 }
02427 break;
02428 case 6:
02429 global $rbacreview;
02430 $ref_id = $_SESSION["user_filter_data"];
02431 if ($ref_id)
02432 {
02433 $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
02434 $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
02435 if (is_array($local_roles) && count($local_roles))
02436 {
02437 $role_ids = join("','", $local_roles);
02438 $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id IN ('" . $role_ids . "') AND ";
02439 }
02440 }
02441 break;
02442 case 7:
02443 global $rbacreview;
02444 $rol_id = $_SESSION["user_filter_data"];
02445 if ($rol_id)
02446 {
02447 $join_filter = sprintf(" LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = %s AND ", $ilDB->quote($rol_id));
02448 $without_anonymous_users = "";
02449 }
02450 break;
02451 }
02452 }
02453
02454
02455 if (strtolower(substr($a_search_str, 0, 5)) == "role:")
02456 {
02457 $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
02458 "FROM object_data,rbac_ua,usr_data ".
02459 "WHERE object_data.title LIKE ".$ilDB->quote("%".substr($a_search_str,5)."%").
02460 " and object_data.type = 'role' ".
02461 "and rbac_ua.rol_id = object_data.obj_id ".
02462 "and usr_data.usr_id = rbac_ua.usr_id ".
02463 "AND rbac_ua.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID);
02464 }
02465 else
02466 {
02467 $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ".
02468 $join_filter .
02469 "(usr_data.login LIKE ".$ilDB->quote("%".$a_search_str."%")." ".
02470 "OR usr_data.firstname LIKE ".$ilDB->quote("%".$a_search_str."%")." ".
02471 "OR usr_data.lastname LIKE ".$ilDB->quote("%".$a_search_str."%")." ".
02472 "OR usr_data.email LIKE ".$ilDB->quote("%".$a_search_str."%").") ".
02473 $without_anonymous_users .
02474 $active_filter . $time_limit_filter . $last_login_filter;
02475 }
02476 $ilLog->write($query);
02477 $res = $ilias->db->query($query);
02478 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02479 {
02480 $users[] = array(
02481 "usr_id" => $row->usr_id,
02482 "login" => $row->login,
02483 "firstname" => $row->firstname,
02484 "lastname" => $row->lastname,
02485 "email" => $row->email,
02486 "active" => $row->active);
02487 $ids[] = $row->usr_id;
02488 }
02489 if ($a_return_ids_only)
02490 return $ids ? $ids : array();
02491 else
02492 return $users ? $users : array();
02493 }
02494
02502 function _search(&$a_search_obj, $active=1)
02503 {
02504 global $ilBench, $ilDB;
02505
02506
02507
02508
02509
02510 $where_condition = $a_search_obj->getWhereCondition("like",array("login","firstname","lastname","title",
02511 "email","institution","street","city",
02512 "zipcode","country","phone_home","fax"));
02513 $in = $a_search_obj->getInStatement("usr_data.usr_id");
02514
02515 $query = "SELECT DISTINCT(usr_data.usr_id) FROM usr_data ".
02516 "LEFT JOIN usr_pref USING (usr_id) ".
02517 $where_condition." ".
02518 $in." ".
02519 "AND usr_data.usr_id != '".ANONYMOUS_USER_ID."' ";
02520 # "AND usr_pref.keyword = 'public_profile' ";
02521 # "AND usr_pref.value = 'y'";
02522
02523 if (is_numeric($active) && $active > -1)
02524 $query .= "AND active = ".$ilDB->quote($active);
02525
02526 $ilBench->start("Search", "ilObjUser_search");
02527 $res = $a_search_obj->ilias->db->query($query);
02528 $ilBench->stop("Search", "ilObjUser_search");
02529
02530 $counter = 0;
02531
02532 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02533 {
02534 $result_data[$counter++]["id"] = $row->usr_id;
02535
02536 }
02537 return $result_data ? $result_data : array();
02538 }
02539
02549 function _getLinkToObject($a_id)
02550 {
02551 return array("profile.php?user=".$a_id,"");
02552 }
02553
02554
02555
02556
02557
02558
02559 function getGroupMemberships($a_user_id = "")
02560 {
02561 global $rbacreview, $tree;
02562
02563 if (strlen($a_user_id) > 0)
02564 {
02565 $user_id = $a_user_id;
02566 }
02567 else
02568 {
02569 $user_id = $this->getId();
02570 }
02571
02572 $grp_memberships = array();
02573
02574
02575 $roles = $rbacreview->assignedRoles($user_id);
02576
02577 foreach ($roles as $role)
02578 {
02579 $ass_rolefolders = $rbacreview->getFoldersAssignedToRole($role);
02580
02581 foreach ($ass_rolefolders as $role_folder)
02582 {
02583 $node = $tree->getParentNodeData($role_folder);
02584
02585 if ($node["type"] == "grp")
02586 {
02587 $group =& $this->ilias->obj_factory->getInstanceByRefId($node["child"]);
02588
02589 if ($group->isMember($user_id) == true && !in_array($group->getId(), $grp_memberships) )
02590 {
02591 array_push($grp_memberships, $group->getId());
02592 }
02593 }
02594
02595 unset($group);
02596 }
02597 }
02598
02599 return $grp_memberships;
02600 }
02601
02602
02603
02604
02605
02606
02607 function getCourseMemberships($a_user_id = "")
02608 {
02609 global $rbacreview, $tree;
02610
02611 if (strlen($a_user_id) > 0)
02612 {
02613 $user_id = $a_user_id;
02614 }
02615 else
02616 {
02617 $user_id = $this->getId();
02618 }
02619
02620 $crs_memberships = array();
02621
02622
02623 $roles = $rbacreview->assignedRoles($user_id);
02624
02625 foreach ($roles as $role)
02626 {
02627 $ass_rolefolders = $rbacreview->getFoldersAssignedToRole($role);
02628
02629 foreach ($ass_rolefolders as $role_folder)
02630 {
02631 $node = $tree->getParentNodeData($role_folder);
02632
02633 if ($node["type"] == "crs")
02634 {
02635 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
02636 $crsmem = ilCourseParticipants::_getInstanceByObjId($node['obj_id']);
02637
02638 if ($crsmem->isAssigned($user_id) && !in_array($node['obj_id'], $crs_memberships))
02639 {
02640 array_push($crs_memberships, $node['obj_id']);
02641 }
02642 }
02643 }
02644 }
02645
02646 return $crs_memberships ? $crs_memberships : array();
02647 }
02648
02649
02658 function _getAllUserLogins(&$ilias)
02659 {
02660 $query = "SELECT login FROM usr_data ";
02661
02662 $res = $ilias->db->query($query);
02663 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02664 {
02665 $logins[] = $row->login;
02666 }
02667 return $logins ? $logins : array();
02668 }
02669
02678 public static function _readUsersProfileData($a_user_ids)
02679 {
02680 global $ilDB;
02681
02682 $where = ("WHERE usr_id IN(".implode(",",ilUtil::quoteArray($a_user_ids)).") ");
02683 $query = "SELECT * FROM usr_data ".$where;
02684 $res = $ilDB->query($query);
02685 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
02686 {
02687 $user_data["$row[usr_id]"] = $row;
02688 }
02689 return $user_data ? $user_data : array();
02690 }
02691
02700 function _getAllUserData($a_fields = NULL, $active =-1)
02701 {
02702 global $ilDB;
02703
02704 $result_arr = array();
02705
02706 if ($a_fields !== NULL and is_array($a_fields))
02707 {
02708 if (count($a_fields) == 0)
02709 {
02710 $select = "*";
02711 }
02712 else
02713 {
02714 if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
02715 unset($a_fields[$usr_id_field]);
02716
02717 $select = implode(",",$a_fields).",usr_data.usr_id";
02718
02719 if(in_array('online_time',$a_fields))
02720 {
02721 $select .= ",ut_online.online_time ";
02722 }
02723 }
02724
02725 $q = "SELECT ".$select." FROM usr_data ";
02726
02727
02728
02729 if(in_array('online_time',$a_fields))
02730 {
02731 $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
02732 }
02733
02734 switch ($active)
02735 {
02736 case 0:
02737 case 1:
02738 $q .= "WHERE active= ".$ilDB->quote($active);
02739 break;
02740 case 2:
02741 $q .= "WHERE time_limit_unlimited='0'";
02742 break;
02743 case 3:
02744 $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND object_data.title LIKE '%crs%' AND usr_data.usr_id = rbac_ua.usr_id";
02745 $r = $ilDB->query($qtemp);
02746 $course_users = array();
02747 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
02748 {
02749 array_push($course_users, $row["usr_id"]);
02750 }
02751 if (count($course_users))
02752 {
02753 $q .= " WHERE usr_data.usr_id NOT IN ('" . join($course_users, "','") . "')";
02754 }
02755 else
02756 {
02757 return $result_arr;
02758 }
02759 break;
02760 case 4:
02761 $date = strftime("%Y-%m-%d %H:%I:%S", mktime(0, 0, 0, $_SESSION["user_filter_data"]["m"], $_SESSION["user_filter_data"]["d"], $_SESSION["user_filter_data"]["y"]));
02762 $q .= sprintf("WHERE last_login < %s", $ilDB->quote($date));
02763 break;
02764 case 5:
02765 $ref_id = $_SESSION["user_filter_data"];
02766 if ($ref_id)
02767 {
02768 $q .= " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.obj_id = (SELECT obj_id FROM object_reference WHERE ref_id = " .
02769 $ilDB->quote($ref_id) . ")";
02770 }
02771 break;
02772 case 6:
02773 global $rbacreview;
02774 $ref_id = $_SESSION["user_filter_data"];
02775 if ($ref_id)
02776 {
02777 $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
02778 $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
02779 if (is_array($local_roles) && count($local_roles))
02780 {
02781 $role_ids = join("','", $local_roles);
02782 $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id IN ('" . $role_ids . "')";
02783 }
02784 }
02785 break;
02786 case 7:
02787 $rol_id = $_SESSION["user_filter_data"];
02788 if ($rol_id)
02789 {
02790 $q .= sprintf(" LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = %s", $ilDB->quote($rol_id));;
02791 }
02792 break;
02793 }
02794 $r = $ilDB->query($q);
02795
02796 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
02797 {
02798 $result_arr[] = $row;
02799 }
02800 }
02801
02802 return $result_arr;
02803 }
02804
02808 function _getNumberOfUsersForStyle($a_skin, $a_style)
02809 {
02810 global $ilDB;
02811
02812 $q = "SELECT count(*) as cnt FROM usr_pref AS up1, usr_pref AS up2 ".
02813 " WHERE up1.keyword= ".$ilDB->quote("style")." AND up1.value= ".$ilDB->quote($a_style).
02814 " AND up2.keyword= ".$ilDB->quote("skin")." AND up2.value= ".$ilDB->quote($a_skin).
02815 " AND up1.usr_id = up2.usr_id ";
02816
02817 $cnt_set = $ilDB->query($q);
02818
02819 $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
02820
02821 return $cnt_rec["cnt"];
02822 }
02823
02827 function _getAllUserAssignedStyles()
02828 {
02829 global $ilDB;
02830
02831 $q = "SELECT DISTINCT up1.value as style, up2.value as skin FROM usr_pref AS up1, usr_pref AS up2 ".
02832 " WHERE up1.keyword= ".$ilDB->quote("style").
02833 " AND up2.keyword= ".$ilDB->quote("skin").
02834 " AND up1.usr_id = up2.usr_id ";
02835
02836
02837 $sty_set = $ilDB->query($q);
02838
02839 $styles = array();
02840 while($sty_rec = $sty_set->fetchRow(DB_FETCHMODE_ASSOC))
02841 {
02842 $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
02843 }
02844
02845 return $styles;
02846 }
02847
02851 function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
02852 {
02853 global $ilDB;
02854
02855 $q = "SELECT up1.usr_id as usr_id FROM usr_pref AS up1, usr_pref AS up2 ".
02856 " WHERE up1.keyword= ".$ilDB->quote("style")." AND up1.value= ".$ilDB->quote($a_from_style).
02857 " AND up2.keyword= ".$ilDB->quote("skin")." AND up2.value= ".$ilDB->quote($a_from_skin).
02858 " AND up1.usr_id = up2.usr_id ";
02859
02860 $usr_set = $ilDB->query($q);
02861
02862 while ($usr_rec = $usr_set->fetchRow(DB_FETCHMODE_ASSOC))
02863 {
02864 ilObjUser::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
02865 ilObjUser::_writePref($usr_rec["usr_id"], "style", $a_to_style);
02866 }
02867 }
02868
02869
02879 public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
02880 {
02881 global $ilDB;
02882
02883 $q = "SELECT * FROM desktop_item WHERE ".
02884 "item_id = ".$ilDB->quote($a_item_id)." AND type = ".
02885 $ilDB->quote($a_type)." AND user_id = ".
02886 $ilDB->quote($a_usr_id);
02887 $item_set = $ilDB->query($q);
02888
02889
02890 if (!$d = $item_set->fetchRow())
02891 {
02892 $q = "INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
02893 " (".$ilDB->quote($a_item_id).",".
02894 $ilDB->quote($a_type).",".
02895 $ilDB->quote($a_usr_id).",".
02896 $ilDB->quote($a_par).")";
02897 $ilDB->query($q);
02898 }
02899 }
02900
02908 function addDesktopItem($a_item_id, $a_type, $a_par = "")
02909 {
02910 ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
02911
02912
02913
02914
02915
02916
02917
02918
02919
02920
02921
02922
02923
02924
02925
02926
02927
02928
02929 }
02930
02939 function setDesktopItemParameters($a_item_id, $a_type, $a_par)
02940 {
02941 global $ilDB;
02942
02943 $q = "UPDATE desktop_item SET parameters = ".$ilDB->quote($a_par)." ".
02944 " WHERE item_id = ".$ilDB->quote($a_item_id)." AND type = ".
02945 $ilDB->quote($a_type)." ".
02946 " AND user_id = ".$ilDB->quote($this->getId())." ";
02947 $this->ilias->db->query($q);
02948 }
02949
02950
02960 public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
02961 {
02962 global $ilDB;
02963
02964 $q = "DELETE FROM desktop_item WHERE ".
02965 " item_id = ".$ilDB->quote($a_item_id)." AND ".
02966 " type = ".$ilDB->quote($a_type)." AND ".
02967 " user_id = ".$ilDB->quote($a_usr_id);
02968 $ilDB->query($q);
02969 }
02970
02978 function dropDesktopItem($a_item_id, $a_type)
02979 {
02980 ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
02981
02982
02983
02984
02985
02986
02987
02988 }
02989
02990
03000 public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
03001 {
03002 global $ilDB;
03003
03004 $q = "SELECT * FROM desktop_item WHERE ".
03005 "item_id = ".$ilDB->quote($a_item_id)." AND type = ".
03006 $ilDB->quote($a_type)." AND user_id = ".
03007 $ilDB->quote($a_usr_id);
03008 $item_set = $ilDB->query($q);
03009
03010 if ($d = $item_set->fetchRow())
03011 {
03012 return true;
03013 }
03014 else
03015 {
03016 return false;
03017 }
03018 }
03019
03027 function isDesktopItem($a_item_id, $a_type)
03028 {
03029 return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
03030
03031
03032
03033
03034
03035
03036
03037
03038
03039
03040
03041
03042
03043
03044
03045
03046 }
03047
03048 function getDesktopItems($a_types = "")
03049 {
03050 return $this->_lookupDesktopItems($this->getId(), $a_types);
03051 }
03052
03059 static function _lookupDesktopItems($user_id, $a_types = "")
03060 {
03061 global $ilUser, $rbacsystem, $tree, $ilDB;
03062
03063 if ($a_types == "")
03064 {
03065 $q = "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
03066 " FROM desktop_item AS it, object_reference AS oref ".
03067 ", object_data AS obj".
03068 " WHERE ".
03069 "it.item_id = oref.ref_id AND ".
03070 "oref.obj_id = obj.obj_id AND ".
03071 "it.user_id = ".$ilDB->quote($user_id);
03072
03073 $item_set = $ilDB->query($q);
03074 $items = array();
03075 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
03076 {
03077 if ($tree->isInTree($item_rec["ref_id"])
03078 && $item_rec["type"] != "rolf")
03079 {
03080 $parent_ref = $tree->getParentId($item_rec["ref_id"]);
03081 $par_left = $tree->getLeftValue($parent_ref);
03082 $par_left = sprintf("%010d", $par_left);
03083
03084
03085 $title = ilObject::_lookupTitle($item_rec["obj_id"]);
03086 $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
03087 $items[$par_left.$title.$item_rec["ref_id"]] =
03088 array("ref_id" => $item_rec["ref_id"],
03089 "obj_id" => $item_rec["obj_id"],
03090 "type" => $item_rec["type"],
03091 "title" => $title,
03092 "description" => $desc,
03093 "parent_ref" => $parent_ref);
03094 }
03095 }
03096 ksort($items);
03097 }
03098 else
03099 {
03100 if (!is_array($a_types))
03101 {
03102 $a_types = array($a_types);
03103 }
03104 $items = array();
03105 $foundsurveys = array();
03106 foreach($a_types as $a_type)
03107 {
03108 $q = "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item AS it, object_reference AS oref ".
03109 ", object_data AS obj WHERE ".
03110 "it.item_id = oref.ref_id AND ".
03111 "oref.obj_id = obj.obj_id AND ".
03112 "it.type = ".$ilDB->quote($a_type)." AND ".
03113 "it.user_id = ".$ilDB->quote($user_id)." ".
03114 "ORDER BY title";
03115
03116 $item_set = $ilDB->query($q);
03117 while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
03118 {
03119 $title = ilObject::_lookupTitle($item_rec["obj_id"]);
03120 $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
03121 $items[$title.$a_type.$item_rec["ref_id"]] =
03122 array("ref_id" => $item_rec["ref_id"],
03123 "obj_id" => $item_rec["obj_id"], "type" => $a_type,
03124 "title" => $title, "description" => $desc);
03125 }
03126
03127 }
03128 ksort($items);
03129 }
03130 return $items;
03131 }
03132
03140 function addObjectToClipboard($a_item_id, $a_type, $a_title)
03141 {
03142 global $ilDB;
03143
03144 $q = "SELECT * FROM personal_clipboard WHERE ".
03145 "item_id = ".$ilDB->quote($a_item_id)." AND type = ".
03146 $ilDB->quote($a_type)." AND user_id = ".
03147 $ilDB->quote($this->getId());
03148 $item_set = $this->ilias->db->query($q);
03149
03150
03151 if (!$d = $item_set->fetchRow())
03152 {
03153 $q = "INSERT INTO personal_clipboard (item_id, type, user_id, title) VALUES ".
03154 " (".$ilDB->quote($a_item_id).",".$ilDB->quote($a_type).",".
03155 $ilDB->quote($this->getId()).",".$ilDB->quote($a_title).")";
03156 $this->ilias->db->query($q);
03157 }
03158 }
03159
03163 function getClipboardObjects($a_type = "")
03164 {
03165 global $ilDB;
03166
03167 $type_str = ($a_type != "")
03168 ? " AND type = ".$ilDB->quote($a_type)." "
03169 : "";
03170 $q = "SELECT * FROM personal_clipboard WHERE ".
03171 "user_id = ".$ilDB->quote($this->getId())." ".
03172 $type_str;
03173 $objs = $this->ilias->db->query($q);
03174 $objects = array();
03175 while ($obj = $objs->fetchRow(DB_FETCHMODE_ASSOC))
03176 {
03177 if ($obj["type"] == "mob")
03178 {
03179 $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
03180 }
03181 $objects[] = array ("id" => $obj["item_id"],
03182 "type" => $obj["type"], "title" => $obj["title"]);
03183 }
03184 return $objects;
03185 }
03186
03195 function _getUsersForClipboadObject($a_type, $a_id)
03196 {
03197 global $ilDB;
03198
03199 $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
03200 "item_id = ".$ilDB->quote($a_id)." AND ".
03201 "type = ".$ilDB->quote($a_type);
03202 $user_set = $ilDB->query($q);
03203 $users = array();
03204 while ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
03205 {
03206 $users[] = $user_rec["user_id"];
03207 }
03208
03209 return $users;
03210 }
03211
03219 function removeObjectFromClipboard($a_item_id, $a_type)
03220 {
03221 global $ilDB;
03222
03223 $q = "DELETE FROM personal_clipboard WHERE ".
03224 "item_id = ".$ilDB->quote($a_item_id)." AND type = ".$ilDB->quote($a_type)." ".
03225 " AND user_id = ".$ilDB->quote($this->getId());
03226 $this->ilias->db->query($q);
03227 }
03228
03229 function _getImportedUserId($i2_id)
03230 {
03231 global $ilDB;
03232
03233 $query = "SELECT obj_id FROM object_data WHERE import_id = ".
03234 $ilDB->quote($i2_id);
03235
03236 $res = $this->ilias->db->query($query);
03237 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
03238 {
03239 $id = $row->obj_id;
03240 }
03241 return $id ? $id : 0;
03242 }
03243
03244
03245
03246
03247
03248
03249
03250
03251
03252
03253
03254
03255
03256
03257
03258
03259
03260
03261
03266 function setAuthMode($a_str)
03267 {
03268 $this->auth_mode = $a_str;
03269 }
03270
03275 function getAuthMode($a_auth_key = false)
03276 {
03277 if (!$a_auth_key)
03278 {
03279 return $this->auth_mode;
03280 }
03281
03282 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
03283 return ilAuthUtils::_getAuthMode($this->auth_mode);
03284 }
03285
03293 function setExternalAccount($a_str)
03294 {
03295 $this->ext_account = $a_str;
03296 }
03297
03305 function getExternalAccount()
03306 {
03307 return $this->ext_account;
03308 }
03309
03321 public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
03322 {
03323 global $ilDB,$ilSetting;
03324
03325 include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
03326 if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
03327 {
03328 $or = "OR auth_mode = 'default' ";
03329 }
03330 else
03331 {
03332 $or = " ";
03333 }
03334 $query = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
03335 "WHERE auth_mode = ".$ilDB->quote($a_auth_mode)." ".
03336 $or;
03337
03338 $res = $ilDB->query($query);
03339 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
03340 {
03341 if($row->auth_mode == 'default')
03342 {
03343 $accounts[$row->usr_id] = $row->login;
03344 }
03345 else
03346 {
03347 $accounts[$row->usr_id] = $row->ext_account;
03348 }
03349 }
03350 return $accounts ? $accounts : array();
03351 }
03352
03360 public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
03361 {
03362 global $ilDB;
03363
03364 if(!is_array($a_usr_ids))
03365 {
03366 return false;
03367 }
03368 $where = ("WHERE usr_id IN(".implode(",",ilUtil::quoteArray($a_usr_ids)).") ");
03369 $query = "UPDATE usr_data SET active = ".$ilDB->quote($a_status ? 1 : 0)." ".
03370 $where;
03371 $ilDB->query($query);
03372
03373 return true;
03374 }
03375
03376
03377
03384 public static function _checkExternalAuthAccount($a_auth, $a_account)
03385 {
03386 global $ilDB,$ilSetting;
03387
03388
03389 $r = $ilDB->query("SELECT * FROM usr_data WHERE ".
03390 " ext_account = ".$ilDB->quote($a_account)." AND ".
03391 " auth_mode = ".$ilDB->quote($a_auth));
03392 if ($usr = $r->fetchRow(DB_FETCHMODE_ASSOC))
03393 {
03394 return $usr["login"];
03395 }
03396
03397
03398 $query = "SELECT login FROM usr_data ".
03399 "WHERE login = ".$ilDB->quote($a_account)." ".
03400 "AND auth_mode = ".$ilDB->quote($a_auth)." ";
03401 $res = $ilDB->query($query);
03402 if($res->numRows())
03403 {
03404 $usr = $res->fetchRow(DB_FETCHMODE_ASSOC);
03405 return $usr['login'];
03406 }
03407
03408
03409 if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
03410 {
03411
03412 $query = "SELECT login FROM usr_data ".
03413 "WHERE ext_account = ".$ilDB->quote($a_account)." ".
03414 "AND auth_mode = 'default'";
03415
03416 $res = $ilDB->query($query);
03417 if ($usr = $res->fetchRow(DB_FETCHMODE_ASSOC))
03418 {
03419 return $usr["login"];
03420 }
03421
03422
03423 $query = "SELECT login FROM usr_data ".
03424 "WHERE (login =".$ilDB->quote($a_account)." AND ext_account = '') ".
03425 "AND auth_mode = 'default'";
03426
03427 $res = $ilDB->query($query);
03428 if ($usr = $res->fetchRow(DB_FETCHMODE_ASSOC))
03429 {
03430 return $usr["login"];
03431 }
03432 }
03433 return false;
03434 }
03435
03439 function _getNumberOfUsersPerAuthMode()
03440 {
03441 global $ilDB;
03442
03443 $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
03444 "GROUP BY auth_mode");
03445 $cnt_arr = array();
03446 while($cnt = $r->fetchRow(DB_FETCHMODE_ASSOC))
03447 {
03448 $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
03449 }
03450
03451 return $cnt_arr;
03452 }
03453
03459 function _getLocalAccountsForEmail($a_email)
03460 {
03461 global $ilDB, $ilSetting;
03462
03463
03464 $or_str = "";
03465 if ($ilSetting->get("auth_mode") == 1)
03466 {
03467 $or_str = " OR auth_mode = ".$ilDB->quote("default");
03468 }
03469
03470 $usr_set = $ilDB->query("SELECT * FROM usr_data WHERE ".
03471 " email = ".$ilDB->quote($a_email)." AND ".
03472 " (auth_mode = ".$ilDB->quote("local").$or_str.")");
03473
03474 $users = array();
03475
03476 while ($usr_rec = $usr_set->fetchRow(DB_FETCHMODE_ASSOC))
03477 {
03478 $users[$usr_rec["usr_id"]] = $usr_rec["login"];
03479 }
03480
03481 return $users;
03482 }
03483
03484
03492 function _uploadPersonalPicture($tmp_file, $obj_id)
03493 {
03494 $webspace_dir = ilUtil::getWebspaceDir();
03495 $image_dir = $webspace_dir."/usr_images";
03496 $store_file = "usr_".$obj_id."."."jpg";
03497 $target_file = $image_dir."/$store_file";
03498
03499 chmod($tmp_file, 0770);
03500
03501
03502
03503 $show_file = "$image_dir/usr_".$obj_id.".jpg";
03504 $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
03505 $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
03506 $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
03507
03508 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 200x200 -quality 100 JPEG:$show_file");
03509 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 100x100 -quality 100 JPEG:$thumb_file");
03510 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 75x75 -quality 100 JPEG:$xthumb_file");
03511 system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 30x30 -quality 100 JPEG:$xxthumb_file");
03512
03513
03514 ilObjUser::_writePref($obj_id, "profile_image", $store_file);
03515
03516 return TRUE;
03517 }
03518
03524 function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
03525 {
03526 return ilObjUser::_getPersonalPicturePath($this->getId(),$a_size,$a_force_pic);
03527 }
03528
03535 function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false)
03536 {
03537 global $ilDB;
03538
03539 $query = "SELECT * FROM usr_pref WHERE ".
03540 "keyword = 'public_upload' ".
03541 "AND value = 'y' ".
03542 "AND usr_id = ".$ilDB->quote($a_usr_id);
03543
03544 $res = $ilDB->query($query);
03545 $upload = $res->numRows() ? true : false;
03546
03547 $query = "SELECT * FROM usr_pref WHERE ".
03548 "keyword = 'public_profile' ".
03549 "AND value = 'y' ".
03550 "AND usr_id = ".$ilDB->quote($a_usr_id);
03551
03552 $res = $ilDB->query($query);
03553 $profile = $res->numRows() ? true : false;
03554
03555 if(defined('ILIAS_MODULE'))
03556 {
03557 $webspace_dir = ('.'.$webspace_dir);
03558 }
03559 $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
03560
03561 $image_dir = $webspace_dir."/usr_images";
03562 $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
03563
03564 if((($upload && $profile) || $a_force_pic)
03565 && @is_file($thumb_file))
03566 {
03567 $file = $thumb_file."?t=".rand(1, 99999);
03568 }
03569 else
03570 {
03571 $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
03572 }
03573
03574 return $file;
03575 }
03576
03577 function setUserDefinedData($a_data)
03578 {
03579 if(!is_array($a_data))
03580 {
03581 return false;
03582 }
03583 foreach($a_data as $field => $data)
03584 {
03585 #$new_data[$field] = ilUtil::stripSlashes($data);
03586
03587 $this->user_defined_data[$field] = $data;
03588 }
03589 #$this->user_defined_data = $new_data;
03590
03591 return true;
03592 }
03593
03594 function getUserDefinedData()
03595 {
03596 return $this->user_defined_data ? $this->user_defined_data : array();
03597 }
03598
03599 function updateUserDefinedFields()
03600 {
03601 global $ilDB;
03602
03603 $fields = '';
03604
03605 foreach($this->user_defined_data as $field => $value)
03606 {
03607 if($field != 'usr_id')
03608 {
03609 $fields .= ("`".$field."` = ".$ilDB->quote($value).", ");
03610 }
03611 }
03612
03613 $query = "REPLACE INTO usr_defined_data ".
03614 "SET ".$fields." ".
03615 "usr_id = ".$ilDB->quote($this->getId());
03616
03617 $this->db->query($query);
03618 return true;
03619 }
03620
03621 function readUserDefinedFields()
03622 {
03623 global $ilDB;
03624
03625 $query = "SELECT * FROM usr_defined_data ".
03626 "WHERE usr_id = ".$ilDB->quote($this->getId());
03627
03628 $res = $this->db->query($query);
03629 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
03630 {
03631 $this->user_defined_data = $row;
03632 }
03633 return true;
03634 }
03635
03636 function addUserDefinedFieldEntry()
03637 {
03638 global $ilDB;
03639
03640 $query = "INSERT INTO usr_defined_data ".
03641 "SET usr_id = ".$ilDB->quote($this->getId());
03642 $this->db->query($query);
03643
03644 return true;
03645 }
03646
03647 function deleteUserDefinedFieldEntries()
03648 {
03649 global $ilDB;
03650
03651 $query = "DELETE FROM usr_defined_data ".
03652 "WHERE usr_id = ".$ilDB->quote($this->getId());
03653 $this->db->query($query);
03654
03655 return true;
03656 }
03657
03663 function getProfileAsString(&$a_language)
03664 {
03665 include_once 'classes/class.ilObjRole.php';
03666 include_once 'classes/class.ilFormat.php';
03667
03668 global $lng,$rbacreview;
03669
03670 $language =& $a_language;
03671 $language->loadLanguageModule('registration');
03672 $language->loadLanguageModule('crs');
03673
03674 $body = '';
03675 $body .= ($language->txt("login").": ".$this->getLogin()."\n");
03676
03677 if(strlen($this->getUTitle()))
03678 {
03679 $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
03680 }
03681 if(strlen($this->getGender()))
03682 {
03683 $gender = ($this->getGender() == 'm') ?
03684 $language->txt('gender_m') :
03685 $language->txt('gender_f');
03686 $body .= ($language->txt("gender").": ".$gender."\n");
03687 }
03688 if(strlen($this->getFirstname()))
03689 {
03690 $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
03691 }
03692 if(strlen($this->getLastname()))
03693 {
03694 $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
03695 }
03696 if(strlen($this->getInstitution()))
03697 {
03698 $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
03699 }
03700 if(strlen($this->getDepartment()))
03701 {
03702 $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
03703 }
03704 if(strlen($this->getStreet()))
03705 {
03706 $body .= ($language->txt("street").": ".$this->getStreet()."\n");
03707 }
03708 if(strlen($this->getCity()))
03709 {
03710 $body .= ($language->txt("city").": ".$this->getCity()."\n");
03711 }
03712 if(strlen($this->getZipcode()))
03713 {
03714 $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
03715 }
03716 if(strlen($this->getCountry()))
03717 {
03718 $body .= ($language->txt("country").": ".$this->getCountry()."\n");
03719 }
03720 if(strlen($this->getPhoneOffice()))
03721 {
03722 $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
03723 }
03724 if(strlen($this->getPhoneHome()))
03725 {
03726 $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
03727 }
03728 if(strlen($this->getPhoneMobile()))
03729 {
03730 $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
03731 }
03732 if(strlen($this->getFax()))
03733 {
03734 $body .= ($language->txt("fax").": ".$this->getFax()."\n");
03735 }
03736 if(strlen($this->getEmail()))
03737 {
03738 $body .= ($language->txt("email").": ".$this->getEmail()."\n");
03739 }
03740 if(strlen($this->getHobby()))
03741 {
03742 $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
03743 }
03744 if(strlen($this->getComment()))
03745 {
03746 $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
03747 }
03748 if(strlen($this->getMatriculation()))
03749 {
03750 $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
03751 }
03752 if(strlen($this->getCreateDate()))
03753 {
03754 $body .= ($language->txt("create_date").": ".ilFormat::formatDate($this->getCreateDate(), "datetime", true)."\n");
03755 }
03756
03757 foreach($rbacreview->getGlobalRoles() as $role)
03758 {
03759 if($rbacreview->isAssigned($this->getId(),$role))
03760 {
03761 $gr[] = ilObjRole::_lookupTitle($role);
03762 }
03763 }
03764 if(count($gr))
03765 {
03766 $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
03767 }
03768
03769
03770 if($this->getTimeLimitUnlimited())
03771 {
03772 $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
03773 }
03774 else
03775 {
03776 $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
03777 ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
03778 $language->txt('crs_to')." ".
03779 ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
03780 }
03781 return $body;
03782 }
03783
03784 function setInstantMessengerId($a_im_type, $a_im_id)
03785 {
03786 $var = "im_".$a_im_type;
03787 $this->$var = $a_im_id;
03788 }
03789
03790 function getInstantMessengerId($a_im_type)
03791 {
03792 $var = "im_".$a_im_type;
03793 return $this->$var;
03794 }
03795
03796 function setDelicious($a_delicious)
03797 {
03798 $this->delicious = $a_delicious;
03799 }
03800
03801 function getDelicious()
03802 {
03803 return $this->delicious;
03804 }
03805
03809 function _lookupFeedHash($a_user_id, $a_create = false)
03810 {
03811 global $ilDB;
03812
03813 if ($a_user_id > 0)
03814 {
03815 $query = "SELECT feed_hash from usr_data WHERE usr_id = ".
03816 $ilDB->quote($a_user_id);
03817 $set = $ilDB->query($query);
03818 if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
03819 {
03820 if (strlen($rec["feed_hash"]) == 32)
03821 {
03822 return $rec["feed_hash"];
03823 }
03824 else if($a_create)
03825 {
03826 $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
03827 $query = "UPDATE usr_data SET feed_hash = ".
03828 $ilDB->quote($hash).
03829 " WHERE usr_id = ".$ilDB->quote($a_user_id);
03830 $ilDB->query($query);
03831 return $hash;
03832 }
03833 }
03834 }
03835
03836 return false;
03837 }
03838
03848 public static function _loginExists($a_login,$a_user_id = 0)
03849 {
03850 global $ilDB;
03851
03852 if ($a_user_id == 0)
03853 {
03854 $clause = "";
03855 }
03856 else
03857 {
03858 $clause = "AND usr_id != ".$ilDB->quote($a_user_id)." ";
03859 }
03860
03861 $q = "SELECT DISTINCT login FROM usr_data ".
03862 "WHERE login = ".$ilDB->quote($a_login)." ".$clause;
03863 $r = $ilDB->query($q);
03864
03865 if ($r->numRows() == 1)
03866 {
03867 return true;
03868 }
03869 return false;
03870 }
03871
03882 public static function _externalAccountExists($a_external_account,$a_auth_mode)
03883 {
03884 global $ilDB;
03885
03886 $query = "SELECT * FROM usr_data ".
03887 "WHERE ext_account = ".$ilDB->quote($a_external_account)." ".
03888 "AND auth_mode = ".$ilDB->quote($a_auth_mode);
03889 $res = $ilDB->query($query);
03890 return $res->numRows() ? true :false;
03891 }
03892
03900 public static function _getUsersForRole($role_id, $active = -1) {
03901 global $ilDB, $rbacreview;
03902 $data = array();
03903
03904 $ids = $rbacreview->assignedUsers($role_id);
03905
03906 if (count ($ids) == 0)
03907 $ids = array (-1);
03908
03909 $query = "SELECT usr_data.*, usr_pref.value AS language
03910 FROM usr_data
03911 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = 'language'
03912 WHERE usr_data.usr_id IN (".implode(',',$ids).")";
03913
03914
03915 if (is_numeric($active) && $active > -1)
03916 $query .= " AND usr_data.active = ".$ilDB->quote($active);
03917
03918 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
03919
03920 # echo $query;
03921
03922 $r = $ilDB->query($query);
03923
03924 $data = array();
03925 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
03926 {
03927 $data[] = $row;
03928 }
03929 return $data;
03930 }
03931
03932
03938 public static function _getUsersForFolder ($ref_id, $active) {
03939 global $ilDB;
03940 $data = array();
03941 $query = "SELECT usr_data.*, usr_pref.value AS language FROM usr_data LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id and usr_pref.keyword = 'language' WHERE 1 ";
03942
03943 if (is_numeric($active) && $active > -1)
03944 $query .= " AND usr_data.active = ".$ilDB->quote($active);
03945
03946 if ($ref_id != USER_FOLDER_ID)
03947 $query .= " AND usr_data.time_limit_owner = ".$ilDB->quote($ref_id);
03948
03949 $query .= " AND usr_data.usr_id != '".ANONYMOUS_USER_ID."'";
03950
03951 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
03952
03953 $result = $ilDB->query($query);
03954 $data = array();
03955 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
03956 {
03957 array_push($data, $row);
03958 }
03959
03960 return $data;
03961 }
03962
03963
03969 public static function _getUsersForGroup ($a_mem_ids, $active = -1)
03970 {
03971 global $rbacadmin, $rbacreview, $ilDB;
03972
03973
03974 $ids = array();
03975 foreach ($a_mem_ids as $mem_id) {
03976 $ids [] = $ilDB->quote($mem_id);
03977 }
03978
03979 $query = "SELECT usr_data.*, usr_pref.value AS language
03980 FROM usr_data
03981 LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = 'language'
03982 WHERE usr_data.usr_id IN (".implode(',',$ids).")
03983 AND usr_data.usr_id != '".ANONYMOUS_USER_ID."'";
03984
03985 if (is_numeric($active) && $active > -1)
03986 $query .= " AND active = '$active'";
03987
03988 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
03989
03990 $r = $ilDB->query($query);
03991
03992 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
03993 {
03994 $mem_arr[] = $row;
03995 }
03996
03997 return $mem_arr ? $mem_arr : array();
03998 }
03999
04000
04006 public static function _getUserData ($a_internalids) {
04007 global $ilDB;
04008
04009 $ids = array();
04010 if (is_array($a_internalids)) {
04011 foreach ($a_internalids as $internalid) {
04012 if (is_numeric ($internalid))
04013 {
04014 $ids[] = $internalid;
04015 }
04016 else
04017 {
04018 $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
04019 if (is_numeric($parsedid) && $parsedid > 0)
04020 {
04021 $ids[] = $parsedid;
04022 }
04023 }
04024 }
04025 }
04026 if (count($ids) == 0)
04027 $ids [] = -1;
04028
04029 $query = "SELECT usr_data.*, usr_pref.value AS language
04030 FROM usr_data
04031 LEFT JOIN usr_pref
04032 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = 'language'
04033 WHERE usr_data.usr_id IN (".join(",",$ids).")";
04034
04035 $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
04036
04037 #echo $query;
04038 $r = $ilDB->query($query);
04039 $data = array();
04040 while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
04041 {
04042 $data[] = $row;
04043 }
04044 return $data;
04045 }
04046
04047 }
04048 ?>