• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilObjUser.php

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

Generated on Fri Dec 13 2013 10:18:28 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1