ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjUser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 define ("IL_PASSWD_PLAIN", "plain");
25 define ("IL_PASSWD_MD5", "md5"); // ILIAS 3 Password
26 define ("IL_PASSWD_CRYPT", "crypt"); // ILIAS 2 Password
27 
28 
29 require_once "classes/class.ilObject.php";
30 
43 class ilObjUser extends ilObject
44 {
49  // personal data
50 
51  var $login; // username in system
52 
53  var $passwd; // password encoded in the format specified by $passwd_type
55  // specifies the password format.
56  // value: IL_PASSWD_PLAIN, IL_PASSWD_MD5 or IL_PASSWD_CRYPT.
57 
58  // Differences between password format in class ilObjUser and
59  // in table usr_data:
60  // Class ilObjUser supports three different password types
61  // (plain, MD5 and CRYPT) and it uses the variables $passwd
62  // and $passwd_type to store them.
63  // Table usr_data supports only two different password types
64  // (MD5 and CRYPT) and it uses the columns "passwd" and
65  // "il2passwd" to store them.
66  // The conversion between these two storage layouts is done
67  // in the methods that perform SQL statements. All other
68  // methods work exclusively with the $passwd and $passwd_type
69  // variables.
70 
71  var $gender; // 'm' or 'f'
72  var $utitle; // user title (keep in mind, that we derive $title from object also!)
74  var $lastname;
75  var $fullname; // title + firstname + lastname in one string
76  //var $archive_dir = "./image"; // point to image file (should be flexible)
77  // address data
80  var $street;
81  var $city;
82  var $zipcode;
83  var $country;
87  var $fax;
88  var $email;
89  var $hobby;
93  var $active;
94  //var $ilinc_id; // unique Id for netucate ilinc service
95  var $client_ip; // client ip to check before login
96  var $auth_mode; // authentication mode
97 
98  var $im_icq;
99  var $im_yahoo;
100  var $im_msn;
101  var $im_aim;
103 
108 
111 
112  var $user_defined_data = array();
113 
119  var $prefs;
120 
126  var $skin;
127 
128 
135 
141  var $ilias;
142 
143 
149  function ilObjUser($a_user_id = 0, $a_call_by_reference = false)
150  {
151  global $ilias,$ilDB;
152 
153  // init variables
154  $this->ilias =& $ilias;
155  $this->db =& $ilDB;
156 
157  $this->type = "usr";
158  $this->ilObject($a_user_id, $a_call_by_reference);
159  $this->auth_mode = "default";
160  $this->passwd_type = IL_PASSWD_PLAIN;
161 
162  // for gender selection. don't change this
163  /*$this->gender = array(
164  'm' => "salutation_m",
165  'f' => "salutation_f"
166  );*/
167  if (!empty($a_user_id))
168  {
169  $this->setId($a_user_id);
170  $this->read();
171  }
172  else
173  {
174  // TODO: all code in else-structure doesn't belongs in class user !!!
175  //load default data
176  $this->prefs = array();
177  //language
178  $this->prefs["language"] = $this->ilias->ini->readVariable("language","default");
179 
180  //skin and pda support
181  $this->skin = $this->ilias->ini->readVariable("layout","skin");
182 
183  $this->prefs["skin"] = $this->skin;
184  $this->prefs["show_users_online"] = "y";
185 
186  //style (css)
187  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
188  }
189  }
190 
195  function read()
196  {
197  global $ilErr, $ilDB;
198 
199  // TODO: fetching default role should be done in rbacadmin
200  $q = "SELECT * FROM usr_data ".
201  "LEFT JOIN rbac_ua ON usr_data.usr_id=rbac_ua.usr_id ".
202  "WHERE usr_data.usr_id= ".$ilDB->quote($this->id);
203  $r = $this->ilias->db->query($q);
204 
205  if ($r->numRows() > 0)
206  {
207  $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
208 
209  // convert password storage layout used by table usr_data into
210  // storage layout used by class ilObjUser
211  if ($data["passwd"] == "" && $data["i2passwd"] != "")
212  {
213  $data["passwd_type"] = IL_PASSWD_CRYPT;
214  $data["passwd"] = $data["i2passwd"];
215  }
216  else
217  {
218  $data["passwd_type"] = IL_PASSWD_MD5;
219  //$data["passwd"] = $data["passwd"]; (implicit)
220  }
221  unset($data["i2passw"]);
222 
223  // this assign must not be set via $this->assignData($data)
224  // because this method will be called on profile updates and
225  // would set this values to 0, because they arent posted from form
226  $this->setLastPasswordChangeTS( $data['last_password_change'] );
227  $this->setLoginAttempts( $data['login_attempts'] );
228 
229 
230  // fill member vars in one shot
231  $this->assignData($data);
232 
233  //get userpreferences from usr_pref table
234  $this->readPrefs();
235 
236  //set language to default if not set
237  if ($this->prefs["language"] == "")
238  {
239  $this->prefs["language"] = $this->oldPrefs["language"];
240  }
241 
242  //check skin-setting
243  include_once("./Services/Style/classes/class.ilStyleDefinition.php");
244  if ($this->prefs["skin"] == "" ||
245  !ilStyleDefinition::skinExists($this->prefs["skin"]))
246  {
247  $this->prefs["skin"] = $this->oldPrefs["skin"];
248  }
249 
250  $this->skin = $this->prefs["skin"];
251 
252  //check style-setting (skins could have more than one stylesheet
253  if ($this->prefs["style"] == "" ||
254  !ilStyleDefinition::skinExists($this->skin, $this->prefs["style"]))
255  {
256  //load default (css)
257  $this->prefs["style"] = $this->ilias->ini->readVariable("layout","style");
258  }
259 
260  if (empty($this->prefs["hits_per_page"]))
261  {
262  $this->prefs["hits_per_page"] = 10;
263  }
264 
265  }
266  else
267  {
268  $ilErr->raiseError("<b>Error: There is no dataset with id ".
269  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
270  "<br />Line: ".__LINE__, $ilErr->FATAL);
271  }
272 
273  $this->readUserDefinedFields();
274 
275  parent::read();
276  }
277 
283  function assignData($a_data)
284  {
285  global $ilErr;
286 
287  // basic personal data
288  $this->setLogin($a_data["login"]);
289  if (! $a_data["passwd_type"])
290  {
291  $ilErr->raiseError("<b>Error: passwd_type missing in function assignData(). ".
292  $this->id."!</b><br />class: ".get_class($this)."<br />Script: "
293  .__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
294  }
295  if ($a_data["passwd"] != "********" and strlen($a_data['passwd']))
296  {
297  $this->setPasswd($a_data["passwd"], $a_data["passwd_type"]);
298  }
299 
300  $this->setGender($a_data["gender"]);
301  $this->setUTitle($a_data["title"]);
302  $this->setFirstname($a_data["firstname"]);
303  $this->setLastname($a_data["lastname"]);
304  $this->setFullname();
305 
306  // address data
307  $this->setInstitution($a_data["institution"]);
308  $this->setDepartment($a_data["department"]);
309  $this->setStreet($a_data["street"]);
310  $this->setCity($a_data["city"]);
311  $this->setZipcode($a_data["zipcode"]);
312  $this->setCountry($a_data["country"]);
313  $this->setPhoneOffice($a_data["phone_office"]);
314  $this->setPhoneHome($a_data["phone_home"]);
315  $this->setPhoneMobile($a_data["phone_mobile"]);
316  $this->setFax($a_data["fax"]);
317  $this->setMatriculation($a_data["matriculation"]);
318  $this->setEmail($a_data["email"]);
319  $this->setHobby($a_data["hobby"]);
320  $this->setClientIP($a_data["client_ip"]);
321 
322  // instant messenger data
323  $this->setInstantMessengerId('icq',$a_data["im_icq"]);
324  $this->setInstantMessengerId('yahoo',$a_data["im_yahoo"]);
325  $this->setInstantMessengerId('msn',$a_data["im_msn"]);
326  $this->setInstantMessengerId('aim',$a_data["im_aim"]);
327  $this->setInstantMessengerId('skype',$a_data["im_skype"]);
328 
329  // other data
330  $this->setDelicious($a_data["delicious"]);
331  $this->setLatitude($a_data["latitude"]);
332  $this->setLongitude($a_data["longitude"]);
333  $this->setLocationZoom($a_data["loc_zoom"]);
334 
335  // system data
336  $this->setLastLogin($a_data["last_login"]);
337  $this->setLastUpdate($a_data["last_update"]);
338  $this->create_date = $a_data["create_date"];
339  $this->setComment($a_data["referral_comment"]);
340  $this->approve_date = $a_data["approve_date"];
341  $this->active = $a_data["active"];
342  $this->agree_date = $a_data["agree_date"];
343 
344  // time limitation
345  $this->setTimeLimitOwner($a_data["time_limit_owner"]);
346  $this->setTimeLimitUnlimited($a_data["time_limit_unlimited"]);
347  $this->setTimeLimitFrom($a_data["time_limit_from"]);
348  $this->setTimeLimitUntil($a_data["time_limit_until"]);
349  $this->setTimeLimitMessage($a_data['time_limit_message']);
350 
351  // user profile incomplete?
352  $this->setProfileIncomplete($a_data["profile_incomplete"]);
353 
354  //iLinc
355  //$this->setiLincData($a_data['ilinc_id'],$a_data['ilinc_login'],$a_data['ilinc_passwd']);
356 
357  //authentication
358  $this->setAuthMode($a_data['auth_mode']);
359  $this->setExternalAccount($a_data['ext_account']);
360  }
361 
368  function saveAsNew($a_from_formular = true)
369  {
370  global $ilErr, $ilDB;
371 
372  switch ($this->passwd_type)
373  {
374  case IL_PASSWD_PLAIN:
375  $pw_field = "passwd";
376  if(strlen($this->passwd))
377  {
378  $pw_value = md5($this->passwd);
379  }
380  else
381  {
382  $pw_value = $this->passwd;
383  }
384  break;
385 
386  case IL_PASSWD_MD5:
387  $pw_field = "passwd";
388  $pw_value = $this->passwd;
389  break;
390 
391  case IL_PASSWD_CRYPT:
392  $pw_field = "i2passwd";
393  $pw_value = $this->passwd;
394  break;
395 
396  default :
397  $ilErr->raiseError("<b>Error: passwd_type missing in function saveAsNew. ".
398  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
399  "<br />Line: ".__LINE__, $ilErr->FATAL);
400  }
401 
402  if ($a_from_formular)
403  {
404  $q = "INSERT INTO usr_data "
405  . "(usr_id,login,".$pw_field.",firstname,lastname,title,gender,"
406  . "email,hobby,institution,department,street,city,zipcode,country,"
407  . "phone_office,phone_home,phone_mobile,fax,last_login,last_update,create_date,"
408  . "referral_comment,matriculation,client_ip, approve_date,agree_date,active,"
409  . "time_limit_unlimited,time_limit_until,time_limit_from,time_limit_owner,auth_mode,ext_account,profile_incomplete,"
410  . "im_icq,im_yahoo,im_msn,im_aim,im_skype,delicious,latitude,longitude,loc_zoom,last_password_change) "
411  . "VALUES "
412  . "(".
413  $ilDB->quote($this->id).",".
414  $ilDB->quote($this->login).",".
415  $ilDB->quote($pw_value).",".
416  $ilDB->quote($this->firstname).",".
417  $ilDB->quote($this->lastname).",".
418  $ilDB->quote($this->utitle).",".
419  $ilDB->quote($this->gender).",".
420  $ilDB->quote($this->email).",".
421  $ilDB->quote($this->hobby).",".
422  $ilDB->quote($this->institution).",".
423  $ilDB->quote($this->department).",".
424  $ilDB->quote($this->street).",".
425  $ilDB->quote($this->city).",".
426  $ilDB->quote($this->zipcode).",".
427  $ilDB->quote($this->country).",".
428  $ilDB->quote($this->phone_office).",".
429  $ilDB->quote($this->phone_home).",".
430  $ilDB->quote($this->phone_mobile).",".
431  $ilDB->quote($this->fax).", 0, now(), now(),".
432  $ilDB->quote($this->referral_comment).",".
433  $ilDB->quote($this->matriculation).",".
434  $ilDB->quote($this->client_ip).",".
435  $ilDB->quote($this->approve_date).",".
436  $ilDB->quote($this->agree_date).",".
437  $ilDB->quote($this->active).",".
438  $ilDB->quote($this->getTimeLimitUnlimited()).",".
439  $ilDB->quote($this->getTimeLimitUntil()).",".
440  $ilDB->quote($this->getTimeLimitFrom()).",".
441  $ilDB->quote($this->getTimeLimitOwner()).",".
442  $ilDB->quote($this->getAuthMode()).",".
443  $ilDB->quote($this->getExternalAccount()).",".
444  $ilDB->quote($this->getProfileIncomplete()).",".
445  $ilDB->quote($this->im_icq).",".
446  $ilDB->quote($this->im_yahoo).",".
447  $ilDB->quote($this->im_msn).",".
448  $ilDB->quote($this->im_aim).",".
449  $ilDB->quote($this->im_skype).",".
450  $ilDB->quote($this->delicious).",".
451  $ilDB->quote($this->latitude).",".
452  $ilDB->quote($this->longitude).",".
453  $ilDB->quote($this->loc_zoom).",".
454  $ilDB->quote($this->last_password_change_ts).
455  ")";
456  }
457  else
458  {
459  $q = "INSERT INTO usr_data ".
460  "(usr_id,login,".$pw_field.",firstname,lastname,title,gender,"
461  . "email,hobby,institution,department,street,city,zipcode,country,"
462  . "phone_office,phone_home,phone_mobile,fax,last_login,last_update,create_date,"
463  . "referral_comment,matriculation,client_ip, approve_date,agree_date,active,"
464  . "time_limit_unlimited,time_limit_until,time_limit_from,time_limit_owner,auth_mode,ext_account,profile_incomplete,"
465  . "im_icq,im_yahoo,im_msn,im_aim,im_skype,delicious,latitude,longitude,loc_zoom,last_password_change) "
466  . "VALUES "
467  ."(".
468  $ilDB->quote($this->id).",".
469  $ilDB->quote($this->login).",".
470  $ilDB->quote($pw_value).",".
471  $ilDB->quote($this->firstname).",".
472  $ilDB->quote($this->lastname).",".
473  $ilDB->quote($this->utitle).",".
474  $ilDB->quote($this->gender).",".
475  $ilDB->quote($this->email).",".
476  $ilDB->quote($this->hobby).",".
477  $ilDB->quote($this->institution).",".
478  $ilDB->quote($this->department).",".
479  $ilDB->quote($this->street).",".
480  $ilDB->quote($this->city).",".
481  $ilDB->quote($this->zipcode).",".
482  $ilDB->quote($this->country).",".
483  $ilDB->quote($this->phone_office).",".
484  $ilDB->quote($this->phone_home).",".
485  $ilDB->quote($this->phone_mobile).",".
486  $ilDB->quote($this->fax).", 0, now(), now(),".
487  $ilDB->quote($this->referral_comment).",".
488  $ilDB->quote($this->matriculation).",".
489  $ilDB->quote($this->client_ip).",".
490  $ilDB->quote($this->approve_date).",".
491  $ilDB->quote($this->agree_date).",".
492  $ilDB->quote($this->active).",".
493  $ilDB->quote($this->getTimeLimitUnlimited()).",".
494  $ilDB->quote($this->getTimeLimitUntil()).",".
495  $ilDB->quote($this->getTimeLimitFrom()).",".
496  $ilDB->quote($this->getTimeLimitOwner()).",".
497  $ilDB->quote($this->getAuthMode()).",".
498  $ilDB->quote($this->getExternalAccount()).",".
499  $ilDB->quote($this->getProfileIncomplete()).",".
500  $ilDB->quote($this->im_icq).",".
501  $ilDB->quote($this->im_yahoo).",".
502  $ilDB->quote($this->im_msn).",".
503  $ilDB->quote($this->im_aim).",".
504  $ilDB->quote($this->im_skype).",".
505  $ilDB->quote($this->delicious).",".
506  $ilDB->quote($this->latitude).",".
507  $ilDB->quote($this->longitude).",".
508  $ilDB->quote($this->loc_zoom).",".
509  $ilDB->quote($this->last_password_change_ts).
510  ")";
511  }
512 
513  $this->ilias->db->query($q);
514 
515  // add new entry in usr_defined_data
516  $this->addUserDefinedFieldEntry();
517  // ... and update
518  $this->updateUserDefinedFields();
519 
520  // CREATE ENTRIES FOR MAIL BOX
521  include_once ("Services/Mail/classes/class.ilMailbox.php");
522  $mbox = new ilMailbox($this->id);
523  $mbox->createDefaultFolder();
524 
525  include_once "Services/Mail/classes/class.ilMailOptions.php";
526  $mail_options = new ilMailOptions($this->id);
527  $mail_options->createMailOptionsEntry();
528 
529  // create personal bookmark folder tree
530  include_once "./Services/PersonalDesktop/classes/class.ilBookmarkFolder.php";
531  $bmf = new ilBookmarkFolder(0, $this->id);
532  $bmf->createNewBookmarkTree();
533 
534  }
535 
540  function update()
541  {
542  global $ilErr, $ilDB;
543 
544  //$this->id = $this->data["Id"];
545 
546  $this->syncActive();
547 
548  if (isset($this->agree_date) && (strtotime($this->agree_date) !== false || $this->agree_date == "0000-00-00 00:00:00"))
549  {
550  $agreedate_update = "agree_date= ".$ilDB->quote($this->agree_date).",";
551  } else
552  {
553  $agreedate_update = "";
554  }
555 
556  $pw_udpate = '';
557  switch ($this->passwd_type)
558  {
559  case IL_PASSWD_PLAIN:
560  if(strlen($this->passwd))
561  {
562  $pw_update = "i2passwd='', passwd='".md5($this->passwd)."'";
563  }
564  else
565  {
566  $pw_update = "i2passwd='', passwd='".$this->passwd."'";
567  }
568  break;
569 
570  case IL_PASSWD_MD5:
571  $pw_update = "i2passwd='', passwd='".$this->passwd."'";
572  break;
573 
574  case IL_PASSWD_CRYPT:
575  $pw_update = "passwd='', i2passwd='".$this->passwd."'";
576  break;
577 
578  default :
579  $ilErr->raiseError("<b>Error: passwd_type missing in function update()".$this->id."!</b><br />class: ".
580  get_class($this)."<br />Script: ".__FILE__."<br />Line: ".__LINE__, $ilErr->FATAL);
581  }
582  $q = "UPDATE usr_data SET ".
583  "gender = ".$ilDB->quote($this->gender).",".
584  "title= ".$ilDB->quote($this->utitle).",".
585  "firstname= ".$ilDB->quote($this->firstname).",".
586  "lastname= ".$ilDB->quote($this->lastname).",".
587  "email= ".$ilDB->quote($this->email).",".
588  "hobby= ".$ilDB->quote($this->hobby).",".
589  "institution= ".$ilDB->quote($this->institution).",".
590  "department= ".$ilDB->quote($this->department).",".
591  "street= ".$ilDB->quote($this->street).",".
592  "city= ".$ilDB->quote($this->city).",".
593  "zipcode= ".$ilDB->quote($this->zipcode).",".
594  "country= ".$ilDB->quote($this->country).",".
595  "phone_office= ".$ilDB->quote($this->phone_office).",".
596  "phone_home= ".$ilDB->quote($this->phone_home).",".
597  "phone_mobile= ".$ilDB->quote($this->phone_mobile).",".
598  "fax= ".$ilDB->quote($this->fax).",".
599  "referral_comment= ".$ilDB->quote($this->referral_comment).",".
600  "matriculation= ".$ilDB->quote($this->matriculation).",".
601  "client_ip= ".$ilDB->quote($this->client_ip).",".
602  "approve_date= ".$ilDB->quote($this->approve_date).",".
603  $agreedate_update.
604  "active= ".$ilDB->quote($this->active).",".
605  "time_limit_owner= ".$ilDB->quote($this->getTimeLimitOwner()).",".
606  "time_limit_unlimited= ".$ilDB->quote($this->getTimeLimitUnlimited()).",".
607  "time_limit_from= ".$ilDB->quote($this->getTimeLimitFrom()).",".
608  "time_limit_until= ".$ilDB->quote($this->getTimeLimitUntil()).",".
609  "time_limit_message= ".$ilDB->quote($this->getTimeLimitMessage()).",".
610  "profile_incomplete = ".$ilDB->quote($this->getProfileIncomplete()).",".
611  "auth_mode= ".$ilDB->quote($this->getAuthMode()).", ".
612  "ext_account= ".$ilDB->quote($this->getExternalAccount()).",".
613  $pw_update.", ".
614  "im_icq= ".$ilDB->quote($this->getInstantMessengerId('icq')).",".
615  "im_yahoo= ".$ilDB->quote($this->getInstantMessengerId('yahoo')).",".
616  "im_msn= ".$ilDB->quote($this->getInstantMessengerId('msn')).",".
617  "im_aim= ".$ilDB->quote($this->getInstantMessengerId('aim')).",".
618  "im_skype= ".$ilDB->quote($this->getInstantMessengerId('skype')).",".
619  "delicious= ".$ilDB->quote($this->getDelicious()).",".
620  "latitude= ".$ilDB->quote($this->getLatitude()).",".
621  "longitude= ".$ilDB->quote($this->getLongitude()).",".
622  "loc_zoom= ".$ilDB->quote($this->getLocationZoom()).",".
623  "last_update=now()".",".
624  "last_password_change= ".$ilDB->quote($this->getLastPasswordChangeTS()).
625  // "ilinc_id= ".$ilDB->quote($this->ilinc_id).",".
626  // "ilinc_login= ".$ilDB->quote($this->ilinc_login).",".
627  // "ilinc_passwd= ".$ilDB->quote($this->ilinc_passwd)." ".
628  " WHERE usr_id= ".$ilDB->quote($this->id);
629 
630  $this->ilias->db->query($q);
631  $this->writePrefs();
632 
633  // update user defined fields
634  $this->updateUserDefinedFields();
635 
636 
637  parent::update();
639 
640  $this->read();
641 
642  return true;
643  }
644 
648  function writeAccepted()
649  {
650  global $ilDB;
651 
652  $q = "UPDATE usr_data SET agree_date = now()".
653  "WHERE usr_id = ".$ilDB->quote($this->getId());
654  $ilDB->query($q);
655 
656  }
657 
658  function _lookupEmail($a_user_id)
659  {
660  global $ilDB;
661 
662  $query = "SELECT email FROM usr_data WHERE usr_id = ".$ilDB->quote((int) $a_user_id);
663  $res = $ilDB->query($query);
664 
665  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
666  {
667  return $row->email;
668  }
669  return false;
670  }
671 
672  function _lookupGender($a_user_id)
673  {
674  global $ilDB;
675 
676  $query = "SELECT gender FROM usr_data WHERE usr_id = ".
677  $ilDB->quote((int) $a_user_id);
678  $res = $ilDB->query($query);
679 
680  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
681  {
682  return $row->gender;
683  }
684  return false;
685  }
686 
687  function _lookupClientIP($a_user_id)
688  {
689  global $ilDB;
690 
691  $query = "SELECT client_ip FROM usr_data WHERE usr_id = ".
692  $ilDB->quote((int) $a_user_id);
693  $res = $ilDB->query($query);
694 
695  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
696  {
697  return $row->client_ip;
698  }
699  return "";
700  }
701 
702 
706  function _lookupName($a_user_id)
707  {
708  global $ilDB;
709 
710  $q = "SELECT firstname, lastname, title FROM usr_data".
711  " WHERE usr_id =".$ilDB->quote($a_user_id);
712  $user_set = $ilDB->query($q);
713  $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
714  return array("user_id" => $a_user_id,
715  "firstname" => $user_rec["firstname"],
716  "lastname" => $user_rec["lastname"],
717  "title" => $user_rec["title"]);
718  }
719 
723  function _lookupFields($a_user_id)
724  {
725  global $ilDB;
726 
727  $q = "SELECT * FROM usr_data".
728  " WHERE usr_id =".$ilDB->quote($a_user_id);
729  $user_set = $ilDB->query($q);
730  $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
731  return $user_rec;
732  }
733 
737  function _lookupLogin($a_user_id)
738  {
739  global $ilDB;
740 
741  $q = "SELECT login FROM usr_data".
742  " WHERE usr_id =".$ilDB->quote($a_user_id);
743  $user_set = $ilDB->query($q);
744  $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
745  return $user_rec["login"];
746  }
747 
751  function _lookupExternalAccount($a_user_id)
752  {
753  global $ilDB;
754 
755  $q = "SELECT ext_account FROM usr_data".
756  " WHERE usr_id =".$ilDB->quote($a_user_id);
757  $user_set = $ilDB->query($q);
758  $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
759  return $user_rec["ext_account"];
760  }
761 
765  function _lookupId($a_user_str)
766  {
767  global $ilDB;
768 
769  $q = "SELECT usr_id FROM usr_data".
770  " WHERE login =".$ilDB->quote($a_user_str);
771  $user_set = $ilDB->query($q);
772  $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
773  return $user_rec["usr_id"];
774  }
775 
779  function _lookupLastLogin($a_user_id)
780  {
781  global $ilDB;
782 
783  $q = "SELECT last_login FROM usr_data".
784  " WHERE usr_id =".$ilDB->quote($a_user_id);
785  $user_set = $ilDB->query($q);
786  $user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC);
787  return $user_rec["last_login"];
788  }
789 
790 
796  function refreshLogin()
797  {
798  global $ilDB;
799 
800  $q = "UPDATE usr_data SET ".
801  "last_login = now() ".
802  "WHERE usr_id = ".$ilDB->quote($this->id);
803 
804  $this->ilias->db->query($q);
805  }
806 
813  function replacePassword($new_md5)
814  {
815  global $ilDB;
816 
817  $this->passwd_type = IL_PASSWD_MD5;
818  $this->passwd = $new_md5;
819 
820  $q = "UPDATE usr_data SET ".
821  "passwd= ".$ilDB->quote($this->passwd)." ".
822  "WHERE usr_id= ".$ilDB->quote($this->id);
823 
824  $this->ilias->db->query($q);
825 
826  return true;
827  }
828 
837  function updatePassword($a_old, $a_new1, $a_new2)
838  {
839  global $ilDB;
840 
841  if (func_num_args() != 3)
842  {
843  return false;
844  }
845 
846  if (!isset($a_old) or !isset($a_new1) or !isset($a_new2))
847  {
848  return false;
849  }
850 
851  if ($a_new1 != $a_new2)
852  {
853  return false;
854  }
855 
856  // is catched by isset() ???
857  if ($a_new1 == "" || $a_old == "")
858  {
859  return false;
860  }
861 
862  //check old password
863  switch ($this->passwd_type)
864  {
865  case IL_PASSWD_PLAIN:
866  if ($a_old != $this->passwd)
867  {
868  return false;
869  }
870  break;
871 
872  case IL_PASSWD_MD5:
873  if (md5($a_old) != $this->passwd)
874  {
875  return false;
876  }
877  break;
878 
879  case IL_PASSWD_CRYPT:
880  if (_makeIlias2Password($a_old) != $this->passwd)
881  {
882  return false;
883  }
884  break;
885  }
886 
887  //update password
888  $this->passwd = md5($a_new1);
889  $this->passwd_type = IL_PASSWD_MD5;
890 
891  $q = "UPDATE usr_data SET ".
892  "passwd= ".$ilDB->quote($this->passwd)." ".
893  "WHERE usr_id= ".$ilDB->quote($this->id)." ";
894  $this->ilias->db->query($q);
895 
896  return true;
897  }
898 
906  function resetPassword($a_new1, $a_new2)
907  {
908  global $ilDB;
909 
910  if (func_num_args() != 2)
911  {
912  return false;
913  }
914 
915  if (!isset($a_new1) or !isset($a_new2))
916  {
917  return false;
918  }
919 
920  if ($a_new1 != $a_new2)
921  {
922  return false;
923  }
924 
925  //update password
926  $this->passwd = md5($a_new1);
927  $this->passwd_type = IL_PASSWD_MD5;
928 
929  $q = "UPDATE usr_data SET ".
930  "passwd= ".$ilDB->quote($this->passwd)." ".
931  "WHERE usr_id= ".$ilDB->quote($this->id);
932  $this->ilias->db->query($q);
933 
934  return true;
935  }
936 
940  function _makeIlias2Password($a_passwd)
941  {
942  return (crypt($a_passwd,substr($a_passwd,0,2)));
943  }
944 
948  function _lookupHasIlias2Password($a_user_login)
949  {
950  global $ilias, $ilDB;
951 
952  $q = "SELECT i2passwd FROM usr_data ".
953  "WHERE login = ".$ilDB->quote($a_user_login)."";
954  $user_set = $ilias->db->query($q);
955 
956  if ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
957  {
958  if ($user_rec["i2passwd"] != "")
959  {
960  return true;
961  }
962  }
963 
964  return false;
965  }
966 
967  function _switchToIlias3Password($a_user, $a_pw)
968  {
969  global $ilias, $ilDB;
970 
971  $q = "SELECT i2passwd FROM usr_data ".
972  "WHERE login = ".$ilDB->quote($a_user);
973 
974  $user_set = $ilias->db->query($q);
975 
976  if ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
977  {
978  if ($user_rec["i2passwd"] == ilObjUser::_makeIlias2Password($a_pw))
979  {
980  $q = "UPDATE usr_data SET passwd= ".$ilDB->quote(md5($a_pw)).", i2passwd=''".
981  "WHERE login = ".$ilDB->quote($a_user);
982  $ilias->db->query($q);
983  return true;
984  }
985  }
986 
987  return false;
988  }
989 
996  function updateLogin($a_login)
997  {
998  global $ilDB;
999 
1000  if (func_num_args() != 1)
1001  {
1002  return false;
1003  }
1004 
1005  if (!isset($a_login))
1006  {
1007  return false;
1008  }
1009 
1010  //update login
1011  $this->login = $a_login;
1012 
1013  $q = "UPDATE usr_data SET ".
1014  "login= ".$ilDB->quote($this->login)." ".
1015  "WHERE usr_id= ".$ilDB->quote($this->id);
1016  $this->ilias->db->query($q);
1017 
1018  return true;
1019  }
1020 
1027  function writePref($a_keyword, $a_value)
1028  {
1029  ilObjUser::_writePref($this->id, $a_keyword, $a_value);
1030  $this->setPref($a_keyword, $a_value);
1031  }
1032 
1033 
1039  function deletePref($a_keyword)
1040  {
1041  global $ilDB;
1042 
1043  $query = sprintf("DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s",
1044  $ilDB->quote($this->getId() . ""),
1045  $ilDB->quote($a_keyword . "")
1046  );
1047  $ilDB->query($query);
1048  }
1049 
1050  function _writePref($a_usr_id, $a_keyword, $a_value)
1051  {
1052  global $ilDB;
1053 
1054  $query = "";
1055  if (strlen($a_value))
1056  {
1057  $query = sprintf("REPLACE INTO usr_pref VALUES (%s, %s, %s)",
1058  $ilDB->quote($a_usr_id),
1059  $ilDB->quote($a_keyword),
1060  $ilDB->quote($a_value)
1061  );
1062  }
1063  else
1064  {
1065  $query = sprintf("DELETE FROM usr_pref WHERE usr_id = %s AND keyword = %s",
1066  $ilDB->quote($a_usr_id),
1067  $ilDB->quote($a_keyword)
1068  );
1069  }
1070  $ilDB->query($query);
1071  }
1072 
1077  function writePrefs()
1078  {
1079  global $ilDB;
1080 
1081  //DELETE
1082  $q = "DELETE FROM usr_pref ".
1083  "WHERE usr_id= ".$ilDB->quote($this->id);
1084  $this->ilias->db->query($q);
1085 
1086  foreach ($this->prefs as $keyword => $value)
1087  {
1088  //INSERT
1089  $q = "INSERT INTO usr_pref ".
1090  "(usr_id, keyword, value) ".
1091  "VALUES ".
1092  "(".$ilDB->quote($this->id).",".$ilDB->quote($keyword).",".
1093  $ilDB->quote($value).")";
1094  $this->ilias->db->query($q);
1095  }
1096  }
1097 
1104  public function getTimeZone()
1105  {
1106  if($tz = $this->getPref('user_tz'))
1107  {
1108  return $tz;
1109  }
1110  else
1111  {
1112  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1113  $settings = ilCalendarSettings::_getInstance();
1114  return $settings->getDefaultTimeZone();
1115  }
1116  }
1117 
1124  public function getTimeFormat()
1125  {
1126  if($format = $this->getPref('time_format'))
1127  {
1128  return $format;
1129  }
1130  else
1131  {
1132  include_once('Services/Calendar/classes/class.ilCalendarSettings.php');
1133  $settings = ilCalendarSettings::_getInstance();
1134  return $settings->getDefaultTimeFormat();
1135  }
1136  }
1137 
1144  function setPref($a_keyword, $a_value)
1145  {
1146  if ($a_keyword != "")
1147  {
1148  $this->prefs[$a_keyword] = $a_value;
1149  }
1150  }
1151 
1157  function getPref($a_keyword)
1158  {
1159  if (array_key_exists($a_keyword, $this->prefs))
1160  {
1161  return $this->prefs[$a_keyword];
1162  }
1163  else
1164  {
1165  return FALSE;
1166  }
1167  }
1168 
1169  function _lookupPref($a_usr_id,$a_keyword)
1170  {
1171  global $ilDB;
1172 
1173  $query = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($a_usr_id)." ".
1174  "AND keyword = ".$ilDB->quote($a_keyword);
1175  $res = $ilDB->query($query);
1176 
1177  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
1178  {
1179  return $row->value;
1180  }
1181  return false;
1182  }
1183 
1189  function readPrefs()
1190  {
1191  global $ilDB;
1192 
1193  if (is_array($this->prefs))
1194  {
1195  $this->oldPrefs = $this->prefs;
1196  }
1197 
1198  $this->prefs = ilObjUser::_getPreferences($this->id);
1199  return count($prefs);
1200  }
1201 
1207  function delete()
1208  {
1209  global $rbacadmin, $ilDB;
1210 
1211  // deassign from ldap groups
1212  include_once('Services/LDAP/classes/class.ilLDAPRoleGroupMapping.php');
1214  $mapping->deleteUser($this->getId());
1215 
1216  // remove mailbox / update sent mails
1217  include_once ("Services/Mail/classes/class.ilMailbox.php");
1218  $mailbox = new ilMailbox($this->getId());
1219  $mailbox->delete();
1220  $mailbox->updateMailsOfDeletedUser();
1221 
1222  // delete feed blocks on personal desktop
1223  include_once("./Services/Block/classes/class.ilCustomBlock.php");
1224  $costum_block = new ilCustomBlock();
1225  $costum_block->setContextObjId($this->getId());
1226  $costum_block->setContextObjType("user");
1227  $c_blocks = $costum_block->queryBlocksForContext();
1228  include_once("./Services/Feeds/classes/class.ilPDExternalFeedBlock.php");
1229  foreach($c_blocks as $c_block)
1230  {
1231  if ($c_block["type"] == "pdfeed")
1232  {
1233  $fb = new ilPDExternalFeedBlock($c_block["id"]);
1234  $fb->delete();
1235  }
1236  }
1237 
1238 
1239  // delete block settings
1240  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1242 
1243  // delete user_account
1244  $this->ilias->db->query("DELETE FROM usr_data WHERE usr_id = ".
1245  $ilDB->quote($this->getId()));
1246 
1247  // delete user_prefs
1248  $this->ilias->db->query("DELETE FROM usr_pref WHERE usr_id= ".
1249  $ilDB->quote($this->getId()));
1250 
1251  // delete user_session
1252  $this->ilias->db->query("DELETE FROM usr_session WHERE user_id= ".
1253  $ilDB->quote($this->getId()));
1254 
1255  // remove user from rbac
1256  $rbacadmin->removeUser($this->getId());
1257 
1258  // remove bookmarks
1259  // TODO: move this to class.ilBookmarkFolder
1260  $q = "DELETE FROM bookmark_tree WHERE tree = ".
1261  $ilDB->quote($this->getId());
1262  $this->ilias->db->query($q);
1263 
1264  $q = "DELETE FROM bookmark_data WHERE user_id= ".
1265  $ilDB->quote($this->getId());
1266  $this->ilias->db->query($q);
1267 
1268  // DELETE FORUM ENTRIES (not complete in the moment)
1269  include_once './Modules/Forum/classes/class.ilObjForum.php';
1270  ilObjForum::_deleteUser($this->getId());
1271 
1272  // Delete link check notify entries
1273  include_once './classes/class.ilLinkCheckNotify.php';
1275 
1276  // Delete crs entries
1277  include_once './Modules/Course/classes/class.ilObjCourse.php';
1278  ilObjCourse::_deleteUser($this->getId());
1279 
1280  // Delete user tracking
1281  include_once './Services/Tracking/classes/class.ilObjUserTracking.php';
1283 
1284  include_once 'Modules/Session/classes/class.ilEventParticipants.php';
1286 
1287  // Delete user defined field entries
1289 
1290  // delete object data
1291  parent::delete();
1292  return true;
1293  }
1294 
1304  function setFullname($a_title = "",$a_firstname = "",$a_lastname = "")
1305  {
1306  $this->fullname = "";
1307 
1308  if ($a_title)
1309  {
1310  $fullname = $a_title." ";
1311  }
1312  elseif ($this->utitle)
1313  {
1314  $this->fullname = $this->utitle." ";
1315  }
1316 
1317  if ($a_firstname)
1318  {
1319  $fullname .= $a_firstname." ";
1320  }
1321  elseif ($this->firstname)
1322  {
1323  $this->fullname .= $this->firstname." ";
1324  }
1325 
1326  if ($a_lastname)
1327  {
1328  return $fullname.$a_lastname;
1329  }
1330 
1331  $this->fullname .= $this->lastname;
1332  }
1333 
1348  function getFullname($a_max_strlen = 0)
1349  {
1350  if (!$a_max_strlen)
1351  {
1352  return ilUtil::stripSlashes($this->fullname);
1353  }
1354 
1355  if (strlen($this->fullname) <= $a_max_strlen)
1356  {
1357  return ilUtil::stripSlashes($this->fullname);
1358  }
1359 
1360  if ((strlen($this->utitle) + strlen($this->lastname) + 4) <= $a_max_strlen)
1361  {
1362  return ilUtil::stripSlashes($this->utitle." ".substr($this->firstname,0,1).". ".$this->lastname);
1363  }
1364 
1365  if ((strlen($this->firstname) + strlen($this->lastname) + 1) <= $a_max_strlen)
1366  {
1367  return ilUtil::stripSlashes($this->firstname." ".$this->lastname);
1368  }
1369 
1370  if ((strlen($this->lastname) + 3) <= $a_max_strlen)
1371  {
1372  return ilUtil::stripSlashes(substr($this->firstname,0,1).". ".$this->lastname);
1373  }
1374 
1375  return ilUtil::stripSlashes(substr($this->lastname,0,$a_max_strlen));
1376  }
1377 
1378 // ### AA 03.09.01 updated page access logger ###
1385  {
1386  global $ilDB;
1387 
1388  //query
1389  $q = "SELECT * FROM lo_access ".
1390  "WHERE usr_id= ".$ilDB->quote($this->id)." ".
1391  "ORDER BY timestamp DESC";
1392  $rst = $this->ilias->db->query($q);
1393 
1394  // fill array
1395  $result = array();
1396  while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
1397  {
1398  $result[] = array(
1399  "timestamp" => $record->timestamp,
1400  "usr_id" => $record->usr_id,
1401  "lm_id" => $record->lm_id,
1402  "obj_id" => $record->obj_id,
1403  "lm_title" => $record->lm_title);
1404  }
1405  return $result;
1406  }
1407 
1408 // ### AA 03.09.01 updated page access logger ###
1414  function getLessons()
1415  {
1416  global $ilDB;
1417 
1418  //query
1419  $q = "SELECT * FROM lo_access ".
1420  "WHERE usr_id= ".$ilDB->quote($this->id)." ";
1421  $rst = $this->ilias->db->query($q);
1422 
1423  // fill array
1424  $result = array();
1425  while($record = $rst->fetchRow(DB_FETCHMODE_OBJECT))
1426  {
1427  $result[] = array(
1428  "timestamp" => $record->timestamp,
1429  "usr_id" => $record->usr_id,
1430  "lm_id" => $record->lm_id,
1431  "obj_id" => $record->obj_id,
1432  "lm_title" => $record->lm_title);
1433  }
1434  return $result;
1435  }
1436 
1445  public static function _hasAcceptedAgreement($a_username)
1446  {
1447  global $ilDB;
1448 
1449  if($a_username == 'root')
1450  {
1451  return true;
1452  }
1453 
1454  $query = "SELECT usr_id FROM usr_data ".
1455  "WHERE login = ".$ilDB->quote($a_username)." ".
1456  "AND agree_date != '0000-00-00 00:00:00'";
1457  $res = $ilDB->query($query);
1458  return $res->numRows() ? true : false;
1459  }
1460 
1461 
1466  {
1467  if ($this->agree_date != "0000-00-00 00:00:00" || $this->login == "root")
1468  {
1469  return true;
1470  }
1471  return false;
1472  }
1473 
1479  function setLogin($a_str)
1480  {
1481  $this->login = $a_str;
1482  }
1483 
1488  function getLogin()
1489  {
1490  return $this->login;
1491  }
1492 
1498  function setPasswd($a_str, $a_type = IL_PASSWD_PLAIN)
1499  {
1500  $this->passwd = $a_str;
1501  $this->passwd_type = $a_type;
1502  }
1503 
1511  function getPasswd()
1512  {
1513  return $this->passwd;
1514  }
1521  function getPasswdType()
1522  {
1523  return $this->passwd_type;
1524  }
1525 
1531  function setGender($a_str)
1532  {
1533  $this->gender = substr($a_str,-1);
1534  }
1535 
1540  function getGender()
1541  {
1542  return $this->gender;
1543  }
1544 
1552  function setUTitle($a_str)
1553  {
1554  $this->utitle = $a_str;
1555  }
1556 
1563  function getUTitle()
1564  {
1565  return $this->utitle;
1566  }
1567 
1573  function setFirstname($a_str)
1574  {
1575  $this->firstname = $a_str;
1576  }
1577 
1582  function getFirstname()
1583  {
1584  return $this->firstname;
1585  }
1586 
1592  function setLastname($a_str)
1593  {
1594  $this->lastname = $a_str;
1595  }
1596 
1601  function getLastname()
1602  {
1603  return $this->lastname;
1604  }
1605 
1611  function setInstitution($a_str)
1612  {
1613  $this->institution = $a_str;
1614  }
1615 
1620  function getInstitution()
1621  {
1622  return $this->institution;
1623  }
1624 
1630  function setDepartment($a_str)
1631  {
1632  $this->department = $a_str;
1633  }
1634 
1639  function getDepartment()
1640  {
1641  return $this->department;
1642  }
1643 
1649  function setStreet($a_str)
1650  {
1651  $this->street = $a_str;
1652  }
1653 
1658  function getStreet()
1659  {
1660  return $this->street;
1661  }
1662 
1668  function setCity($a_str)
1669  {
1670  $this->city = $a_str;
1671  }
1672 
1677  function getCity()
1678  {
1679  return $this->city;
1680  }
1681 
1687  function setZipcode($a_str)
1688  {
1689  $this->zipcode = $a_str;
1690  }
1691 
1696  function getZipcode()
1697  {
1698  return $this->zipcode;
1699  }
1700 
1706  function setCountry($a_str)
1707  {
1708  $this->country = $a_str;
1709  }
1710 
1715  function getCountry()
1716  {
1717  return $this->country;
1718  }
1719 
1725  function setPhoneOffice($a_str)
1726  {
1727  $this->phone_office = $a_str;
1728  }
1729 
1734  function getPhoneOffice()
1735  {
1736  return $this->phone_office;
1737  }
1738 
1744  function setPhoneHome($a_str)
1745  {
1746  $this->phone_home = $a_str;
1747  }
1748 
1753  function getPhoneHome()
1754  {
1755  return $this->phone_home;
1756  }
1757 
1763  function setPhoneMobile($a_str)
1764  {
1765  $this->phone_mobile = $a_str;
1766  }
1767 
1772  function getPhoneMobile()
1773  {
1774  return $this->phone_mobile;
1775  }
1776 
1782  function setFax($a_str)
1783  {
1784  $this->fax = $a_str;
1785  }
1786 
1791  function getFax()
1792  {
1793  return $this->fax;
1794  }
1795 
1801  function setClientIP($a_str)
1802  {
1803  $this->client_ip = $a_str;
1804  }
1805 
1810  function getClientIP()
1811  {
1812  return $this->client_ip;
1813  }
1814 
1820  function setMatriculation($a_str)
1821  {
1822  $this->matriculation = $a_str;
1823  }
1824 
1829  function getMatriculation()
1830  {
1831  return $this->matriculation;
1832  }
1833 
1840  public static function lookupMatriculation($a_usr_id)
1841  {
1842  global $ilDB;
1843 
1844  $query = "SELECT matriculation FROM usr_data ".
1845  "WHERE usr_id = ".$ilDB->quote($a_usr_id);
1846  $res = $ilDB->query($query);
1847  $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
1848  return $row->matriculation ? $row->matriculation : '';
1849  }
1850 
1856  function setEmail($a_str)
1857  {
1858  $this->email = $a_str;
1859  }
1860 
1865  function getEmail()
1866  {
1867  return $this->email;
1868  }
1869 
1875  function setHobby($a_str)
1876  {
1877  $this->hobby = $a_str;
1878  }
1879 
1884  function getHobby()
1885  {
1886  return $this->hobby;
1887  }
1888 
1894  function setLanguage($a_str)
1895  {
1896  $this->setPref("language",$a_str);
1897  unset($_SESSION['lang']);
1898  }
1899 
1905  function getLanguage()
1906  {
1907  return $this->prefs["language"];
1908  }
1909 
1910  public function setLastPasswordChangeTS($a_last_password_change_ts)
1911  {
1912  $this->last_password_change_ts = $a_last_password_change_ts;
1913  }
1914 
1915  public function getLastPasswordChangeTS()
1916  {
1918  }
1919 
1920 
1921  function _lookupLanguage($a_usr_id)
1922  {
1923  global $ilDB;
1924 
1925  $q = "SELECT value FROM usr_pref WHERE usr_id= ".
1926  $ilDB->quote($a_usr_id)." AND keyword = 'language'";
1927  $r = $ilDB->query($q);
1928 
1929  while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
1930  {
1931  return $row['value'];
1932  }
1933  return 'en';
1934  }
1935 
1936 
1937  function _checkPassword($a_usr_id, $a_pw)
1938  {
1939  global $ilDB;
1940 
1941  $q = "SELECT passwd FROM usr_data ".
1942  " WHERE usr_id = ".$ilDB->quote($a_usr_id);
1943  $usr_set = $ilDB->query($q);
1944 
1945  if($usr_rec = $usr_set->fetchRow(DB_FETCHMODE_ASSOC))
1946  {
1947  if ($usr_rec["passwd"] == md5($a_pw))
1948  {
1949  return true;
1950  }
1951  }
1952  return false;
1953  }
1954 
1955  function _writeExternalAccount($a_usr_id, $a_ext_id)
1956  {
1957  global $ilDB;
1958 
1959  $q = "UPDATE usr_data ".
1960  " SET ext_account = ".$ilDB->quote($a_ext_id).
1961  " WHERE usr_id = ".$ilDB->quote($a_usr_id);
1962  $usr_set = $ilDB->query($q);
1963  }
1964 
1965  function _writeAuthMode($a_usr_id, $a_auth_mode)
1966  {
1967  global $ilDB;
1968 
1969  $q = "UPDATE usr_data ".
1970  " SET auth_mode = ".$ilDB->quote($a_auth_mode).
1971  " WHERE usr_id = ".$ilDB->quote($a_usr_id);
1972  $usr_set = $ilDB->query($q);
1973  }
1974 
1980  {
1981  return $_SESSION['lang'];
1982  }
1983 
1989  function setLastLogin($a_str)
1990  {
1991  $this->last_login = $a_str;
1992  }
1993 
1999  function getLastLogin()
2000  {
2001  return $this->last_login;
2002  }
2003 
2009  function setLastUpdate($a_str)
2010  {
2011  $this->last_update = $a_str;
2012  }
2013  function getLastUpdate()
2014  {
2015  return $this->last_update;
2016  }
2017 
2023  function setComment($a_str)
2024  {
2025  $this->referral_comment = $a_str;
2026  }
2027 
2032  function getComment()
2033  {
2034  return $this->referral_comment;
2035  }
2036 
2043  function setApproveDate($a_str)
2044  {
2045  $this->approve_date = $a_str;
2046  }
2047 
2053  function getApproveDate()
2054  {
2055  return $this->approve_date;
2056  }
2057 
2058  // BEGIN DiskQuota: show when user accepted user agreement
2064  function getAgreeDate()
2065  {
2066  return $this->agree_date;
2067  }
2074  function setAgreeDate($a_str)
2075  {
2076  $this->agree_date = $a_str;
2077  }
2078  // END DiskQuota: show when user accepted user agreement
2079 
2086  function setActive($a_active, $a_owner = 6)
2087  {
2088  if (empty($a_owner))
2089  {
2090  $a_owner = 0;
2091  }
2092 
2093  if ($a_active)
2094  {
2095  $this->active = 1;
2096  $this->setApproveDate(date('Y-m-d H:i:s'));
2097  $this->setOwner($a_owner);
2098  }
2099  else
2100  {
2101  $this->active = 0;
2102  $this->setApproveDate('0000-00-00 00:00:00');
2103  $this->setOwner(0);
2104  }
2105  }
2106 
2111  function getActive()
2112  {
2113  return $this->active;
2114  }
2115 
2121  function syncActive()
2122  {
2123  global $ilAuth;
2124 
2125  $storedActive = 0;
2126  if ($this->getStoredActive($this->id))
2127  {
2128  $storedActive = 1;
2129  }
2130 
2131  $currentActive = 0;
2132  if ($this->active)
2133  {
2134  $currentActive = 1;
2135  }
2136 
2137  if ((!empty($storedActive) && empty($currentActive)) ||
2138  (empty($storedActive) && !empty($currentActive)))
2139  {
2140  $this->setActive($currentActive, $this->getUserIdByLogin(ilObjUser::getLoginFromAuth()));
2141  }
2142  }
2143 
2150  function getStoredActive($a_id)
2151  {
2152  global $ilias, $ilDB;
2153 
2154  $query = "SELECT active FROM usr_data ".
2155  "WHERE usr_id = ".$ilDB->quote($a_id);
2156 
2157  $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
2158 
2159  return $row->active ? true : false;
2160  }
2161 
2167  function setSkin($a_str)
2168  {
2169  // TODO: exception handling (dir exists)
2170  $this->skin = $a_str;
2171  }
2172 
2173  function setTimeLimitOwner($a_owner)
2174  {
2175  $this->time_limit_owner = $a_owner;
2176  }
2178  {
2179  return $this->time_limit_owner ? $this->time_limit_owner : 7;
2180  }
2181  function setTimeLimitFrom($a_from)
2182  {
2183  $this->time_limit_from = $a_from;
2184  }
2185  function getTimeLimitFrom()
2186  {
2187  return $this->time_limit_from ? $this->time_limit_from : time();
2188  }
2189  function setTimeLimitUntil($a_until)
2190  {
2191  $this->time_limit_until = $a_until;
2192  }
2194  {
2195  return $this->time_limit_until ? $this->time_limit_until : time();
2196  }
2197  function setTimeLimitUnlimited($a_unlimited)
2198  {
2199  $this->time_limit_unlimited = $a_unlimited;
2200  }
2202  {
2203  return $this->time_limit_unlimited;
2204  }
2205  function setTimeLimitMessage($a_time_limit_message)
2206  {
2207  return $this->time_limit_message = $a_time_limit_message;
2208  }
2210  {
2211  return $this->time_limit_message;
2212  }
2213 
2214  public function setLoginAttempts($a_login_attempts)
2215  {
2216  $this->login_attempts = $a_login_attempts;
2217  }
2218 
2219  public function getLoginAttempts()
2220  {
2221  return $this->login_attempts;
2222  }
2223 
2224 
2225  function checkTimeLimit()
2226  {
2227  if($this->getTimeLimitUnlimited())
2228  {
2229  return true;
2230  }
2231  if($this->getTimeLimitFrom() < time() and $this->getTimeLimitUntil() > time())
2232  {
2233  return true;
2234  }
2235  return false;
2236  }
2237  function setProfileIncomplete($a_prof_inc)
2238  {
2239  $this->profile_incomplete = (boolean) $a_prof_inc;
2240  }
2242  {
2243  return $this->profile_incomplete;
2244  }
2245 
2246  public function isPasswordChangeDemanded()
2247  {
2248  //error_reporting(E_ALL);
2249  if( $this->id == ANONYMOUS_USER_ID || $this->id == SYSTEM_USER_ID )
2250  return false;
2251 
2252  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2253  $security = ilSecuritySettings::_getInstance();
2254  if( $security->isPasswordChangeOnFirstLoginEnabled() &&
2255  $this->getLastPasswordChangeTS() == 0 )
2256  {
2257  return true;
2258  }
2259  return false;
2260  }
2261 
2262  public function isPasswordExpired()
2263  {
2264  //error_reporting(E_ALL);
2265  if($this->id == ANONYMOUS_USER_ID) return false;
2266 
2267  require_once('./Services/PrivacySecurity/classes/class.ilSecuritySettings.php');
2268  $security = ilSecuritySettings::_getInstance();
2269  if( $security->getAccountSecurityMode() == ilSecuritySettings::ACCOUNT_SECURITY_MODE_CUSTOMIZED &&
2270  $this->getLastPasswordChangeTS() > 0 )
2271  {
2272  $max_pass_age = $security->getPasswordMaxAge();
2273  if( $max_pass_age > 0 )
2274  {
2275  $max_pass_age_ts = ( $max_pass_age * 86400 );
2276  $pass_change_ts = $this->getLastPasswordChangeTS();
2277  $current_ts = time();
2278 
2279  if( ($current_ts - $pass_change_ts) > $max_pass_age_ts )
2280  return true;
2281  }
2282  }
2283  return false;
2284  }
2285 
2286  public function getPasswordAge()
2287  {
2288  $current_ts = time();
2289  $pass_change_ts = $this->getLastPasswordChangeTS();
2290  $password_age = (int) ( ($current_ts - $pass_change_ts) / 86400 );
2291  return $password_age;
2292  }
2293 
2294  public function setLastPasswordChangeToNow()
2295  {
2296  $this->setLastPasswordChangeTS( time() );
2297 
2298  $query = "UPDATE usr_data SET usr_data.last_password_change = ? " .
2299  "WHERE usr_data.usr_id = ?";
2300  $statement = $this->db->prepareManip( $query, array('integer','integer') );
2301  $affected = $this->db->execute( $statement, array($this->getLastPasswordChangeTS(),$this->id) );
2302  if($affected) return true;
2303  else return false;
2304  }
2305 
2306  public function resetLastPasswordChange()
2307  {
2308  $query = "UPDATE usr_data SET usr_data.last_password_change = 0 " .
2309  "WHERE usr_data.usr_id = ?";
2310  $statement = $this->db->prepareManip( $query, array('integer') );
2311  $affected = $this->db->execute( $statement, array($this->getId()) );
2312  if($affected) return true;
2313  else return false;
2314  }
2315 
2321  function setLatitude($a_latitude)
2322  {
2323  $this->latitude = $a_latitude;
2324  }
2325 
2331  function getLatitude()
2332  {
2333  return $this->latitude;
2334  }
2335 
2341  function setLongitude($a_longitude)
2342  {
2343  $this->longitude = $a_longitude;
2344  }
2345 
2351  function getLongitude()
2352  {
2353  return $this->longitude;
2354  }
2355 
2361  function setLocationZoom($a_locationzoom)
2362  {
2363  $this->loc_zoom = $a_locationzoom;
2364  }
2365 
2371  function getLocationZoom()
2372  {
2373  return $this->loc_zoom;
2374  }
2375 
2376  function &getAppliedUsers()
2377  {
2378  $this->applied_users = array();
2379  $this->__readAppliedUsers($this->getId());
2380 
2381  return $this->applied_users ? $this->applied_users : array();
2382  }
2383 
2384  function isChild($a_usr_id)
2385  {
2386  if($a_usr_id == $this->getId())
2387  {
2388  return true;
2389  }
2390 
2391  $this->applied_users = array();
2392  $this->__readAppliedUsers($this->getId());
2393 
2394  return in_array($a_usr_id,$this->applied_users);
2395  }
2396 
2397  function __readAppliedUsers($a_parent_id)
2398  {
2399  global $ilDB;
2400 
2401  $query = "SELECT usr_id FROM usr_data ".
2402  "WHERE time_limit_owner = ".$ilDB->quote($a_parent_id);
2403 
2404  $res = $this->ilias->db->query($query);
2405  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2406  {
2407  $this->applied_users[] = $row->usr_id;
2408 
2409  // recursion
2410  $this->__readAppliedUsers($row->usr_id);
2411  }
2412  return true;
2413  }
2414 
2415  /*
2416  * check user id with login name
2417  * @access public
2418  */
2419  function checkUserId()
2420  {
2421  global $ilDB,$ilAuth;
2422 
2424  $r = $this->ilias->db->query("SELECT usr_id FROM usr_data WHERE login = ".
2425  $ilDB->quote($login));
2426 
2427  //query has got a result
2428  if ($r->numRows() > 0)
2429  {
2430  $data = $r->fetchRow();
2431  $this->id = $data[0];
2432 
2433  return $this->id;
2434  }
2435 
2436  return false;
2437  }
2438 
2442  private static function getLoginFromAuth() {
2443  global $ilAuth;
2444 
2445  // BEGIN WebDAV: Strip Microsoft Domain Names from logins
2446  require_once ('Services/WebDAV/classes/class.ilDAVServer.php');
2447  if (ilDAVServer::_isActive())
2448  {
2449  require_once ('Services/Authentication/classes/class.ilAuthContainerMDB2.php');
2450  $login = ilAuthContainerMDB2::toUsernameWithoutDomain($ilAuth->getUsername());
2451  }
2452  else
2453  {
2454  $login =$ilAuth->getUsername();
2455  }
2456 
2457  return $login;
2458  }
2459 
2460  /*
2461  * check to see if current user has been made active
2462  * @access public
2463  * @return true if active, otherwise false
2464  */
2466  {
2467  global $ilDB,$ilAuth;
2468 
2470  $r = $this->ilias->db->query("SELECT active FROM usr_data WHERE login= ".
2471  $ilDB->quote($login));
2472  //query has got a result
2473  if ($r->numRows() > 0)
2474  {
2475  $data = $r->fetchRow();
2476  if (!empty($data[0]))
2477  {
2478  return true;
2479  }
2480  }
2481 
2482  return false;
2483  }
2484 
2485  /*
2486  * STATIC METHOD
2487  * get the user_id of a login name
2488  * @param string login name
2489  * @return integer id of user
2490  * @static
2491  * @access public
2492  */
2493  function getUserIdByLogin($a_login)
2494  {
2495  global $ilias, $ilDB;
2496 
2497  $query = "SELECT usr_id FROM usr_data ".
2498  "WHERE login = ".$ilDB->quote($a_login);
2499 
2500  $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
2501 
2502  return $row->usr_id ? $row->usr_id : 0;
2503  }
2504 
2513  function _getUserIdsByEmail($a_email)
2514  {
2515  global $ilias, $ilDB;
2516 
2517  $query = "SELECT login FROM usr_data ".
2518  "WHERE email = ".$ilDB->quote($a_email)." and active=1";
2519 
2520  $res = $ilias->db->query($query);
2521  $ids = array ();
2522  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2523  {
2524  $ids[] = $row->login;
2525  }
2526 
2527  return $ids;
2528  }
2529 
2530 
2531 
2540  function getUserIdByEmail($a_email)
2541  {
2542  global $ilDB;
2543 
2544  $query = "SELECT usr_id FROM usr_data ".
2545  "WHERE email = ".$ilDB->quote($a_email);
2546 
2547  $row = $this->ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
2548  return $row->usr_id ? $row->usr_id : 0;
2549  }
2550 
2551  /*
2552  * STATIC METHOD
2553  * get the login name of a user_id
2554  * @param integer id of user
2555  * @return string login name; false if not found
2556  * @static
2557  * @access public
2558  */
2559  function getLoginByUserId($a_userid)
2560  {
2561  global $ilias, $ilDB;
2562 
2563  $query = "SELECT login FROM usr_data ".
2564  "WHERE usr_id = ".$ilDB->quote($a_userid);
2565 
2566  $row = $ilias->db->getRow($query,DB_FETCHMODE_OBJECT);
2567 
2568  return $row->login ? $row->login : false;
2569  }
2570 
2581  function searchUsers($a_search_str, $active = 1, $a_return_ids_only = false, $filter_settings = FALSE)
2582  {
2583  // NO CLASS VARIABLES IN STATIC METHODS
2584  global $ilias, $ilDB;
2585 
2586  $active_filter = "";
2587  $time_limit_filter = "";
2588  $join_filter = " WHERE ";
2589  $last_login_filter = "";
2590  $without_anonymous_users = "AND usr_data.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID);
2591  if (is_numeric($active) && $active > -1 && $filter_settings === FALSE) $active_filter = " AND active = ".$ilDB->quote($active);
2592  global $ilLog; $ilLog->write("active = $active, filter settings = $filter_settings, active_filter = $active_filter");
2593 
2594 
2595  if ($filter_settings !== FALSE && strlen($filter_settings))
2596  {
2597  switch ($filter_settings)
2598  {
2599  case -1:
2600  $active_filter = "";
2601  // show all users
2602  break;
2603  case 0:
2604  $active_filter = " AND usr_data.active = " . $ilDB->quote("0");
2605  // show only inactive users
2606  break;
2607  case 1:
2608  $active_filter = " AND usr_data.active = " . $ilDB->quote("1");
2609  // show only active users
2610  break;
2611  case 2:
2612  $time_limit_filter = " AND usr_data.time_limit_unlimited = " . $ilDB->quote("0");
2613  // show only users with limited access
2614  break;
2615  case 3:
2616  // show only users without courses
2617  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.usr_id IS NULL AND ";
2618  break;
2619  case 4:
2620  $date = strftime("%Y-%m-%d %H:%I:%S", mktime(0, 0, 0, $_SESSION["user_filter_data"]["m"], $_SESSION["user_filter_data"]["d"], $_SESSION["user_filter_data"]["y"]));
2621  $last_login_filter = sprintf(" AND last_login < %s", $ilDB->quote($date));
2622  break;
2623  case 5:
2624  // show only users with a certain course membership
2625  $ref_id = $_SESSION["user_filter_data"];
2626  if ($ref_id)
2627  {
2628  $join_filter = " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.obj_id = (SELECT obj_id FROM object_reference WHERE ref_id = " .
2629  $ilDB->quote($ref_id) . ") AND ";
2630  }
2631  break;
2632  case 6:
2633  global $rbacreview;
2634  $ref_id = $_SESSION["user_filter_data"];
2635  if ($ref_id)
2636  {
2637  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2638  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2639  if (is_array($local_roles) && count($local_roles))
2640  {
2641  $role_ids = join("','", $local_roles);
2642  $join_filter = " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id IN ('" . $role_ids . "') AND ";
2643  }
2644  }
2645  break;
2646  case 7:
2647  global $rbacreview;
2648  $rol_id = $_SESSION["user_filter_data"];
2649  if ($rol_id)
2650  {
2651  $join_filter = sprintf(" LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = %s AND ", $ilDB->quote($rol_id));
2652  $without_anonymous_users = "";
2653  }
2654  break;
2655  }
2656  }
2657  // This is a temporary hack to search users by their role
2658  // See Mantis #338. This is a hack due to Mantis #337.
2659  if (strtolower(substr($a_search_str, 0, 5)) == "role:")
2660  {
2661  $query = "SELECT DISTINCT usr_data.usr_id,usr_data.login,usr_data.firstname,usr_data.lastname,usr_data.email ".
2662  "FROM object_data,rbac_ua,usr_data ".
2663  "WHERE object_data.title LIKE ".$ilDB->quote("%".substr($a_search_str,5)."%").
2664  " and object_data.type = 'role' ".
2665  "and rbac_ua.rol_id = object_data.obj_id ".
2666  "and usr_data.usr_id = rbac_ua.usr_id ".
2667  "AND rbac_ua.usr_id != ".$ilDB->quote(ANONYMOUS_USER_ID);
2668  }
2669  else
2670  {
2671  $query = "SELECT usr_data.usr_id, usr_data.login, usr_data.firstname, usr_data.lastname, usr_data.email, usr_data.active FROM usr_data ".
2672  $join_filter .
2673  "(usr_data.login LIKE ".$ilDB->quote("%".$a_search_str."%")." ".
2674  "OR usr_data.firstname LIKE ".$ilDB->quote("%".$a_search_str."%")." ".
2675  "OR usr_data.lastname LIKE ".$ilDB->quote("%".$a_search_str."%")." ".
2676  "OR usr_data.email LIKE ".$ilDB->quote("%".$a_search_str."%").") ".
2677  $without_anonymous_users .
2678  $active_filter . $time_limit_filter . $last_login_filter;
2679  }
2680  $ilLog->write($query);
2681  $res = $ilias->db->query($query);
2682  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2683  {
2684  $users[] = array(
2685  "usr_id" => $row->usr_id,
2686  "login" => $row->login,
2687  "firstname" => $row->firstname,
2688  "lastname" => $row->lastname,
2689  "email" => $row->email,
2690  "active" => $row->active);
2691  $ids[] = $row->usr_id;
2692  }
2693  if ($a_return_ids_only)
2694  return $ids ? $ids : array();
2695  else
2696  return $users ? $users : array();
2697  }
2698 
2706  function _search(&$a_search_obj, $active=1)
2707  {
2708  global $ilBench, $ilDB;
2709 
2710  // NO CLASS VARIABLES IN STATIC METHODS
2711 
2712  // TODO: CHECK IF ITEMS ARE PUBLIC VISIBLE
2713 
2714  $where_condition = $a_search_obj->getWhereCondition("like",array("login","firstname","lastname","title",
2715  "email","institution","street","city",
2716  "zipcode","country","phone_home","fax"));
2717  $in = $a_search_obj->getInStatement("usr_data.usr_id");
2718 
2719  $query = "SELECT DISTINCT(usr_data.usr_id) FROM usr_data ".
2720  "LEFT JOIN usr_pref USING (usr_id) ".
2721  $where_condition." ".
2722  $in." ".
2723  "AND usr_data.usr_id != '".ANONYMOUS_USER_ID."' ";
2724 # "AND usr_pref.keyword = 'public_profile' ";
2725 # "AND usr_pref.value = 'y'";
2726 
2727  if (is_numeric($active) && $active > -1)
2728  $query .= "AND active = ".$ilDB->quote($active);
2729 
2730  $ilBench->start("Search", "ilObjUser_search");
2731  $res = $a_search_obj->ilias->db->query($query);
2732  $ilBench->stop("Search", "ilObjUser_search");
2733 
2734  $counter = 0;
2735 
2736  while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2737  {
2738  $result_data[$counter++]["id"] = $row->usr_id;
2739 
2740  }
2741  return $result_data ? $result_data : array();
2742  }
2743 
2744  /*
2745  * get the memberships(group_ids) of groups that are subscribed to the current user object
2746  * @param integer optional user_id
2747  * @access public
2748  */
2749  function getGroupMemberships($a_user_id = "")
2750  {
2751  global $rbacreview, $tree;
2752 
2753  if (strlen($a_user_id) > 0)
2754  {
2755  $user_id = $a_user_id;
2756  }
2757  else
2758  {
2759  $user_id = $this->getId();
2760  }
2761 
2762  $grp_memberships = array();
2763 
2764  // get all roles which the user is assigned to
2765  $roles = $rbacreview->assignedRoles($user_id);
2766 
2767  foreach ($roles as $role)
2768  {
2769  $ass_rolefolders = $rbacreview->getFoldersAssignedToRole($role); //rolef_refids
2770 
2771  foreach ($ass_rolefolders as $role_folder)
2772  {
2773  $node = $tree->getParentNodeData($role_folder);
2774 
2775  if ($node["type"] == "grp")
2776  {
2777  $group =& $this->ilias->obj_factory->getInstanceByRefId($node["child"]);
2778 
2779  if ($group->isMember($user_id) == true && !in_array($group->getId(), $grp_memberships) )
2780  {
2781  array_push($grp_memberships, $group->getId());
2782  }
2783  }
2784 
2785  unset($group);
2786  }
2787  }
2788 
2789  return $grp_memberships;
2790  }
2791 
2792  /*
2793  * get the memberships(course_ids) of courses that are subscribed to the current user object
2794  * @param integer optional user_id
2795  * @access public
2796  */
2797  function getCourseMemberships($a_user_id = "")
2798  {
2799  global $rbacreview, $tree;
2800 
2801  if (strlen($a_user_id) > 0)
2802  {
2803  $user_id = $a_user_id;
2804  }
2805  else
2806  {
2807  $user_id = $this->getId();
2808  }
2809 
2810  $crs_memberships = array();
2811 
2812  // get all roles which the user is assigned to
2813  $roles = $rbacreview->assignedRoles($user_id);
2814 
2815  foreach ($roles as $role)
2816  {
2817  $ass_rolefolders = $rbacreview->getFoldersAssignedToRole($role); //rolef_refids
2818 
2819  foreach ($ass_rolefolders as $role_folder)
2820  {
2821  $node = $tree->getParentNodeData($role_folder);
2822 
2823  if ($node["type"] == "crs")
2824  {
2825  include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
2826  $crsmem = ilCourseParticipants::_getInstanceByObjId($node['obj_id']);
2827 
2828  if ($crsmem->isAssigned($user_id) && !in_array($node['obj_id'], $crs_memberships))
2829  {
2830  array_push($crs_memberships, $node['obj_id']);
2831  }
2832  }
2833  }
2834  }
2835 
2836  return $crs_memberships ? $crs_memberships : array();
2837  }
2838 
2839 
2849  {
2850  $query = "SELECT login FROM usr_data ";
2851 
2852  $res = $ilias->db->query($query);
2853  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
2854  {
2855  $logins[] = $row->login;
2856  }
2857  return $logins ? $logins : array();
2858  }
2859 
2868  public static function _readUsersProfileData($a_user_ids)
2869  {
2870  global $ilDB;
2871 
2872  $where = ("WHERE usr_id IN(".implode(",",ilUtil::quoteArray($a_user_ids)).") ");
2873  $query = "SELECT * FROM usr_data ".$where;
2874  $res = $ilDB->query($query);
2875  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
2876  {
2877  $user_data["$row[usr_id]"] = $row;
2878  }
2879  return $user_data ? $user_data : array();
2880  }
2881 
2890  function _getAllUserData($a_fields = NULL, $active =-1)
2891  {
2892  global $ilDB;
2893 
2894  $result_arr = array();
2895 
2896  if ($a_fields !== NULL and is_array($a_fields))
2897  {
2898  if (count($a_fields) == 0)
2899  {
2900  $select = "*";
2901  }
2902  else
2903  {
2904  if (($usr_id_field = array_search("usr_id",$a_fields)) !== false)
2905  unset($a_fields[$usr_id_field]);
2906 
2907  $select = implode(",",$a_fields).",usr_data.usr_id";
2908  // online time
2909  if(in_array('online_time',$a_fields))
2910  {
2911  $select .= ",ut_online.online_time ";
2912  }
2913  }
2914 
2915  $q = "SELECT ".$select." FROM usr_data ";
2916 
2917  // Add online_time if desired
2918  // Need left join here to show users that never logged in
2919  if(in_array('online_time',$a_fields))
2920  {
2921  $q .= "LEFT JOIN ut_online ON usr_data.usr_id = ut_online.usr_id ";
2922  }
2923 
2924  switch ($active)
2925  {
2926  case 0:
2927  case 1:
2928  $q .= "WHERE active= ".$ilDB->quote($active);
2929  break;
2930  case 2:
2931  $q .= "WHERE time_limit_unlimited='0'";
2932  break;
2933  case 3:
2934  $qtemp = $q . ", rbac_ua, object_data WHERE rbac_ua.rol_id = object_data.obj_id AND object_data.title LIKE '%crs%' AND usr_data.usr_id = rbac_ua.usr_id";
2935  $r = $ilDB->query($qtemp);
2936  $course_users = array();
2937  while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
2938  {
2939  array_push($course_users, $row["usr_id"]);
2940  }
2941  if (count($course_users))
2942  {
2943  $q .= " WHERE usr_data.usr_id NOT IN ('" . join($course_users, "','") . "')";
2944  }
2945  else
2946  {
2947  return $result_arr;
2948  }
2949  break;
2950  case 4:
2951  $date = strftime("%Y-%m-%d %H:%I:%S", mktime(0, 0, 0, $_SESSION["user_filter_data"]["m"], $_SESSION["user_filter_data"]["d"], $_SESSION["user_filter_data"]["y"]));
2952  $q .= sprintf("WHERE last_login < %s", $ilDB->quote($date));
2953  break;
2954  case 5:
2955  $ref_id = $_SESSION["user_filter_data"];
2956  if ($ref_id)
2957  {
2958  $q .= " LEFT JOIN crs_members ON usr_data.usr_id = crs_members.usr_id WHERE crs_members.obj_id = (SELECT obj_id FROM object_reference WHERE ref_id = " .
2959  $ilDB->quote($ref_id) . ")";
2960  }
2961  break;
2962  case 6:
2963  global $rbacreview;
2964  $ref_id = $_SESSION["user_filter_data"];
2965  if ($ref_id)
2966  {
2967  $rolf = $rbacreview->getRoleFolderOfObject($ref_id);
2968  $local_roles = $rbacreview->getRolesOfRoleFolder($rolf["ref_id"],false);
2969  if (is_array($local_roles) && count($local_roles))
2970  {
2971  $role_ids = join("','", $local_roles);
2972  $q .= " LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id IN ('" . $role_ids . "')";
2973  }
2974  }
2975  break;
2976  case 7:
2977  $rol_id = $_SESSION["user_filter_data"];
2978  if ($rol_id)
2979  {
2980  $q .= sprintf(" LEFT JOIN rbac_ua ON usr_data.usr_id = rbac_ua.usr_id WHERE rbac_ua.rol_id = %s", $ilDB->quote($rol_id));;
2981  }
2982  break;
2983  }
2984 
2985  $r = $ilDB->query($q);
2986 
2987  while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
2988  {
2989  $result_arr[] = $row;
2990  }
2991  }
2992 
2993  return $result_arr;
2994  }
2995 
2999  function _getNumberOfUsersForStyle($a_skin, $a_style)
3000  {
3001  global $ilDB;
3002 
3003  $q = "SELECT count(*) as cnt FROM usr_pref AS up1, usr_pref AS up2 ".
3004  " WHERE up1.keyword= ".$ilDB->quote("style")." AND up1.value= ".$ilDB->quote($a_style).
3005  " AND up2.keyword= ".$ilDB->quote("skin")." AND up2.value= ".$ilDB->quote($a_skin).
3006  " AND up1.usr_id = up2.usr_id ";
3007 
3008  $cnt_set = $ilDB->query($q);
3009 
3010  $cnt_rec = $cnt_set->fetchRow(DB_FETCHMODE_ASSOC);
3011 
3012  return $cnt_rec["cnt"];
3013  }
3014 
3019  {
3020  global $ilDB;
3021 
3022  $q = "SELECT DISTINCT up1.value as style, up2.value as skin FROM usr_pref AS up1, usr_pref AS up2 ".
3023  " WHERE up1.keyword= ".$ilDB->quote("style").
3024  " AND up2.keyword= ".$ilDB->quote("skin").
3025  " AND up1.usr_id = up2.usr_id ";
3026 
3027 
3028  $sty_set = $ilDB->query($q);
3029 
3030  $styles = array();
3031  while($sty_rec = $sty_set->fetchRow(DB_FETCHMODE_ASSOC))
3032  {
3033  $styles[] = $sty_rec["skin"].":".$sty_rec["style"];
3034  }
3035 
3036  return $styles;
3037  }
3038 
3042  function _moveUsersToStyle($a_from_skin, $a_from_style, $a_to_skin, $a_to_style)
3043  {
3044  global $ilDB;
3045 
3046  $q = "SELECT up1.usr_id as usr_id FROM usr_pref AS up1, usr_pref AS up2 ".
3047  " WHERE up1.keyword= ".$ilDB->quote("style")." AND up1.value= ".$ilDB->quote($a_from_style).
3048  " AND up2.keyword= ".$ilDB->quote("skin")." AND up2.value= ".$ilDB->quote($a_from_skin).
3049  " AND up1.usr_id = up2.usr_id ";
3050 
3051  $usr_set = $ilDB->query($q);
3052 
3053  while ($usr_rec = $usr_set->fetchRow(DB_FETCHMODE_ASSOC))
3054  {
3055  ilObjUser::_writePref($usr_rec["usr_id"], "skin", $a_to_skin);
3056  ilObjUser::_writePref($usr_rec["usr_id"], "style", $a_to_style);
3057  }
3058  }
3059 
3060 
3070  public static function _addDesktopItem($a_usr_id, $a_item_id, $a_type, $a_par = "")
3071  {
3072  global $ilDB;
3073 
3074  $q = "SELECT * FROM desktop_item WHERE ".
3075  "item_id = ".$ilDB->quote($a_item_id)." AND type = ".
3076  $ilDB->quote($a_type)." AND user_id = ".
3077  $ilDB->quote($a_usr_id);
3078  $item_set = $ilDB->query($q);
3079 
3080  // only insert if item is not already on desktop
3081  if (!$d = $item_set->fetchRow())
3082  {
3083  $q = "INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3084  " (".$ilDB->quote($a_item_id).",".
3085  $ilDB->quote($a_type).",".
3086  $ilDB->quote($a_usr_id).",".
3087  $ilDB->quote($a_par).")";
3088  $ilDB->query($q);
3089  }
3090  }
3091 
3099  function addDesktopItem($a_item_id, $a_type, $a_par = "")
3100  {
3101  ilObjUser::_addDesktopItem($this->getId(), $a_item_id, $a_type, $a_par);
3102 /* global $ilDB;
3103 
3104  $q = "SELECT * FROM desktop_item WHERE ".
3105  "item_id = ".$ilDB->quote($a_item_id)." AND type = ".
3106  $ilDB->quote($a_type)." AND user_id = ".
3107  $ilDB->quote($this->getId());
3108  $item_set = $this->ilias->db->query($q);
3109 
3110  // only insert if item is not already on desktop
3111  if (!$d = $item_set->fetchRow())
3112  {
3113  $q = "INSERT INTO desktop_item (item_id, type, user_id, parameters) VALUES ".
3114  " (".$ilDB->quote($a_item_id).",".
3115  $ilDB->quote($a_type).",".
3116  $ilDB->quote($this->getId()).",".
3117  $ilDB->quote($a_par).")";
3118  $this->ilias->db->query($q);
3119  }
3120 */ }
3121 
3130  function setDesktopItemParameters($a_item_id, $a_type, $a_par)
3131  {
3132  global $ilDB;
3133 
3134  $q = "UPDATE desktop_item SET parameters = ".$ilDB->quote($a_par)." ".
3135  " WHERE item_id = ".$ilDB->quote($a_item_id)." AND type = ".
3136  $ilDB->quote($a_type)." ".
3137  " AND user_id = ".$ilDB->quote($this->getId())." ";
3138  $this->ilias->db->query($q);
3139  }
3140 
3141 
3151  public static function _dropDesktopItem($a_usr_id, $a_item_id, $a_type)
3152  {
3153  global $ilDB;
3154 
3155  $q = "DELETE FROM desktop_item WHERE ".
3156  " item_id = ".$ilDB->quote($a_item_id)." AND ".
3157  " type = ".$ilDB->quote($a_type)." AND ".
3158  " user_id = ".$ilDB->quote($a_usr_id);
3159  $ilDB->query($q);
3160  }
3161 
3169  function dropDesktopItem($a_item_id, $a_type)
3170  {
3171  ilObjUser::_dropDesktopItem($this->getId(), $a_item_id, $a_type);
3172 /* global $ilDB;
3173 
3174  $q = "DELETE FROM desktop_item WHERE ".
3175  " item_id = ".$ilDB->quote($a_item_id)." AND ".
3176  " type = ".$ilDB->quote($a_type)." AND ".
3177  " user_id = ".$ilDB->quote($this->getId());
3178  $this->ilias->db->query($q);
3179 */ }
3180 
3181 
3191  public static function _isDesktopItem($a_usr_id, $a_item_id, $a_type)
3192  {
3193  global $ilDB;
3194 
3195  $q = "SELECT * FROM desktop_item WHERE ".
3196  "item_id = ".$ilDB->quote($a_item_id)." AND type = ".
3197  $ilDB->quote($a_type)." AND user_id = ".
3198  $ilDB->quote($a_usr_id);
3199  $item_set = $ilDB->query($q);
3200 
3201  if ($d = $item_set->fetchRow())
3202  {
3203  return true;
3204  }
3205  else
3206  {
3207  return false;
3208  }
3209  }
3210 
3218  function isDesktopItem($a_item_id, $a_type)
3219  {
3220  return ilObjUser::_isDesktopItem($this->getId(), $a_item_id, $a_type);
3221 /* global $ilDB;
3222 
3223  $q = "SELECT * FROM desktop_item WHERE ".
3224  "item_id = ".$ilDB->quote($a_item_id)." AND type = ".
3225  $ilDB->quote($a_type)." AND user_id = ".
3226  $ilDB->quote($this->getId());
3227  $item_set = $this->ilias->db->query($q);
3228 
3229  if ($d = $item_set->fetchRow())
3230  {
3231  return true;
3232  }
3233  else
3234  {
3235  return false;
3236  }*/
3237  }
3238 
3239  function getDesktopItems($a_types = "")
3240  {
3241  return $this->_lookupDesktopItems($this->getId(), $a_types);
3242  }
3243 
3250  static function _lookupDesktopItems($user_id, $a_types = "")
3251  {
3252  global $ilUser, $rbacsystem, $tree, $ilDB;
3253 
3254  if ($a_types == "")
3255  {
3256  $q = "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title, obj.type ".
3257  " FROM desktop_item AS it, object_reference AS oref ".
3258  ", object_data AS obj".
3259  " WHERE ".
3260  "it.item_id = oref.ref_id AND ".
3261  "oref.obj_id = obj.obj_id AND ".
3262  "it.user_id = ".$ilDB->quote($user_id);
3263 
3264  $item_set = $ilDB->query($q);
3265  $items = array();
3266  while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
3267  {
3268  if ($tree->isInTree($item_rec["ref_id"])
3269  && $item_rec["type"] != "rolf")
3270  {
3271  $parent_ref = $tree->getParentId($item_rec["ref_id"]);
3272  $par_left = $tree->getLeftValue($parent_ref);
3273  $par_left = sprintf("%010d", $par_left);
3274 
3275 
3276  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3277  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3278  $items[$par_left.$title.$item_rec["ref_id"]] =
3279  array("ref_id" => $item_rec["ref_id"],
3280  "obj_id" => $item_rec["obj_id"],
3281  "type" => $item_rec["type"],
3282  "title" => $title,
3283  "description" => $desc,
3284  "parent_ref" => $parent_ref);
3285  }
3286  }
3287  ksort($items);
3288  }
3289  else
3290  {
3291  if (!is_array($a_types))
3292  {
3293  $a_types = array($a_types);
3294  }
3295  $items = array();
3296  $foundsurveys = array();
3297  foreach($a_types as $a_type)
3298  {
3299  $q = "SELECT obj.obj_id, obj.description, oref.ref_id, obj.title FROM desktop_item AS it, object_reference AS oref ".
3300  ", object_data AS obj WHERE ".
3301  "it.item_id = oref.ref_id AND ".
3302  "oref.obj_id = obj.obj_id AND ".
3303  "it.type = ".$ilDB->quote($a_type)." AND ".
3304  "it.user_id = ".$ilDB->quote($user_id)." ".
3305  "ORDER BY title";
3306 
3307  $item_set = $ilDB->query($q);
3308  while ($item_rec = $item_set->fetchRow(DB_FETCHMODE_ASSOC))
3309  {
3310  $title = ilObject::_lookupTitle($item_rec["obj_id"]);
3311  $desc = ilObject::_lookupDescription($item_rec["obj_id"]);
3312  $items[$title.$a_type.$item_rec["ref_id"]] =
3313  array("ref_id" => $item_rec["ref_id"],
3314  "obj_id" => $item_rec["obj_id"], "type" => $a_type,
3315  "title" => $title, "description" => $desc);
3316  }
3317 
3318  }
3319  ksort($items);
3320  }
3321  return $items;
3322  }
3323 
3331  function addObjectToClipboard($a_item_id, $a_type, $a_title,
3332  $a_parent = 0, $a_time = 0, $a_order_nr = 0)
3333  {
3334  global $ilDB;
3335 
3336  if ($a_time == 0)
3337  {
3338  $a_time = date("Y-m-d H:i:s", time());
3339  }
3340 
3341  $st = $ilDB->prepare("SELECT * FROM personal_clipboard WHERE ".
3342  "parent = ? AND item_id = ? AND type = ? AND user_id = ?",
3343  array("integer", "integer", "text", "integer"));
3344  $item_set = $ilDB->execute($st,
3345  array(0, $a_item_id, $a_type, $this->getId()));
3346 
3347  // only insert if item is not already in clipboard
3348  if (!$d = $item_set->fetchRow())
3349  {
3350  $st = $ilDB->prepareManip("INSERT INTO personal_clipboard ".
3351  "(item_id, type, user_id, title, parent, insert_time, order_nr) VALUES ".
3352  " (?,?,?,?,?,?,?)",
3353  array("integer", "text", "integer", "text", "integer", "timestamp", "integer"));
3354  $ilDB->execute($st,
3355  array($a_item_id, $a_type, $this->getId(), $a_title, $a_parent, $a_time, $a_order_nr));
3356  }
3357  else
3358  {
3359  $st = $ilDB->prepareManip("UPDATE personal_clipboard SET insert_time = ? ".
3360  "WHERE user_id = ? AND item_id = ? AND type = ? AND parent = 0",
3361  array("timestamp", "integer", "integer", "text"));
3362  $ilDB->execute($st, array($a_time, $this->getId(), $a_item_id, $a_type));
3363  }
3364  }
3365 
3369  function clipboardHasObjectsOfType($a_type)
3370  {
3371  global $ilDB;
3372 
3373  $st = $ilDB->prepare("SELECT * FROM personal_clipboard WHERE ".
3374  "parent = ? AND type = ? AND user_id = ?",
3375  array("integer", "text", "integer"));
3376  $set = $ilDB->execute($st,
3377  array(0, $a_type, $this->getId()));
3378  if ($rec = $ilDB->fetchAssoc($set))
3379  {
3380  return true;
3381  }
3382 
3383  return false;
3384  }
3385 
3390  {
3391  global $ilDB;
3392 
3393  $st = $ilDB->prepareManip("DELETE FROM personal_clipboard WHERE ".
3394  "type = ? AND user_id = ?",
3395  array("text", "integer"));
3396  $ilDB->execute($st,
3397  array($a_type, $this->getId()));
3398  }
3399 
3403  function getClipboardObjects($a_type = "", $a_top_nodes_only = false)
3404  {
3405  global $ilDB;
3406 
3407  $par = "";
3408  if ($a_top_nodes_only)
3409  {
3410  $par = " AND parent = ".$ilDB->quote(0)." ";
3411  }
3412 
3413  $type_str = ($a_type != "")
3414  ? " AND type = ".$ilDB->quote($a_type)." "
3415  : "";
3416  $q = "SELECT * FROM personal_clipboard WHERE ".
3417  "user_id = ".$ilDB->quote($this->getId())." ".
3418  $type_str.$par.
3419  " ORDER BY order_nr";
3420  $objs = $this->ilias->db->query($q);
3421  $objects = array();
3422  while ($obj = $objs->fetchRow(DB_FETCHMODE_ASSOC))
3423  {
3424  if ($obj["type"] == "mob")
3425  {
3426  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3427  }
3428  $objects[] = array ("id" => $obj["item_id"],
3429  "type" => $obj["type"], "title" => $obj["title"],
3430  "insert_time" => $obj["insert_time"]);
3431  }
3432  return $objects;
3433  }
3434 
3438  function getClipboardChilds($a_parent, $a_insert_time)
3439  {
3440  global $ilDB, $ilUser;
3441 
3442  $st = $ilDB->prepare("SELECT * FROM personal_clipboard WHERE ".
3443  "user_id = ? AND parent = ? AND insert_time = ? ".
3444  " ORDER BY order_nr",
3445  array("integer", "integer", "timestamp"));
3446  $objs = $ilDB->execute($st,
3447  array($ilUser->getId(), $a_parent, $a_insert_time));
3448  $objects = array();
3449  while ($obj = $objs->fetchRow(DB_FETCHMODE_ASSOC))
3450  {
3451  if ($obj["type"] == "mob")
3452  {
3453  $obj["title"] = ilObject::_lookupTitle($obj["item_id"]);
3454  }
3455  $objects[] = array ("id" => $obj["item_id"],
3456  "type" => $obj["type"], "title" => $obj["title"]);
3457  }
3458  return $objects;
3459  }
3460 
3469  function _getUsersForClipboadObject($a_type, $a_id)
3470  {
3471  global $ilDB;
3472 
3473  $q = "SELECT DISTINCT user_id FROM personal_clipboard WHERE ".
3474  "item_id = ".$ilDB->quote($a_id)." AND ".
3475  "type = ".$ilDB->quote($a_type);
3476  $user_set = $ilDB->query($q);
3477  $users = array();
3478  while ($user_rec = $user_set->fetchRow(DB_FETCHMODE_ASSOC))
3479  {
3480  $users[] = $user_rec["user_id"];
3481  }
3482 
3483  return $users;
3484  }
3485 
3493  function removeObjectFromClipboard($a_item_id, $a_type)
3494  {
3495  global $ilDB;
3496 
3497  $q = "DELETE FROM personal_clipboard WHERE ".
3498  "item_id = ".$ilDB->quote($a_item_id)." AND type = ".$ilDB->quote($a_type)." ".
3499  " AND user_id = ".$ilDB->quote($this->getId());
3500  $this->ilias->db->query($q);
3501  }
3502 
3503  function _getImportedUserId($i2_id)
3504  {
3505  global $ilDB;
3506 
3507  $query = "SELECT obj_id FROM object_data WHERE import_id = ".
3508  $ilDB->quote($i2_id);
3509 
3510  $res = $this->ilias->db->query($query);
3511  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
3512  {
3513  $id = $row->obj_id;
3514  }
3515  return $id ? $id : 0;
3516  }
3517 
3518 /*
3519 
3520  function setiLincData($a_id,$a_login,$a_passwd)
3521  {
3522  $this->ilinc_id = $a_id;
3523  $this->ilinc_login = $a_login;
3524  $this->ilinc_passwd = $a_passwd;
3525  }
3526 
3527 */
3528 
3529 /*
3530 
3531  function getiLincData()
3532  {
3533  return array ("id" => $this->ilinc_id, "login" => $this->ilinc_login, "passwd" => $this->ilinc_passwd);
3534  }
3535 */
3540  function setAuthMode($a_str)
3541  {
3542  $this->auth_mode = $a_str;
3543  }
3544 
3549  function getAuthMode($a_auth_key = false)
3550  {
3551  if (!$a_auth_key)
3552  {
3553  return $this->auth_mode;
3554  }
3555 
3556  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3557  return ilAuthUtils::_getAuthMode($this->auth_mode);
3558  }
3559 
3567  function setExternalAccount($a_str)
3568  {
3569  $this->ext_account = $a_str;
3570  }
3571 
3580  {
3581  return $this->ext_account;
3582  }
3583 
3595  public static function _getExternalAccountsByAuthMode($a_auth_mode,$a_read_auth_default = false)
3596  {
3597  global $ilDB,$ilSetting;
3598 
3599  include_once('./Services/Authentication/classes/class.ilAuthUtils.php');
3600  if($a_read_auth_default and ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode',AUTH_LOCAL)) == $a_auth_mode)
3601  {
3602  $or = "OR auth_mode = 'default' ";
3603  }
3604  else
3605  {
3606  $or = " ";
3607  }
3608  $query = "SELECT login,usr_id,ext_account,auth_mode FROM usr_data ".
3609  "WHERE auth_mode = ".$ilDB->quote($a_auth_mode)." ".
3610  $or;
3611 
3612  $res = $ilDB->query($query);
3613  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
3614  {
3615  if($row->auth_mode == 'default')
3616  {
3617  $accounts[$row->usr_id] = $row->login;
3618  }
3619  else
3620  {
3621  $accounts[$row->usr_id] = $row->ext_account;
3622  }
3623  }
3624  return $accounts ? $accounts : array();
3625  }
3626 
3634  public static function _toggleActiveStatusOfUsers($a_usr_ids,$a_status)
3635  {
3636  global $ilDB;
3637 
3638  if(!is_array($a_usr_ids))
3639  {
3640  return false;
3641  }
3642  $where = ("WHERE usr_id IN(".implode(",",ilUtil::quoteArray($a_usr_ids)).") ");
3643  $query = "UPDATE usr_data SET active = ".$ilDB->quote($a_status ? 1 : 0)." ".
3644  $where;
3645  $ilDB->query($query);
3646 
3647  return true;
3648  }
3649 
3650 
3659  public static function _lookupAuthMode($a_usr_id)
3660  {
3661  global $ilDB;
3662 
3663  $query = "SELECT auth_mode FROM usr_data ".
3664  "WHERE usr_id = ".$ilDB->quote($a_usr_id)." ";
3665  $res = $ilDB->query($query);
3666  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
3667  {
3668  return $row->auth_mode;
3669  }
3670  return '';
3671  }
3672 
3679  public static function _checkExternalAuthAccount($a_auth, $a_account)
3680  {
3681  global $ilDB,$ilSetting;
3682 
3683  // Check directly with auth_mode
3684  $r = $ilDB->query("SELECT * FROM usr_data WHERE ".
3685  " ext_account = ".$ilDB->quote($a_account)." AND ".
3686  " auth_mode = ".$ilDB->quote($a_auth));
3687  if ($usr = $r->fetchRow(DB_FETCHMODE_ASSOC))
3688  {
3689  return $usr["login"];
3690  }
3691 
3692  // For compatibility, check for login (no ext_account entry given)
3693  $query = "SELECT login FROM usr_data ".
3694  "WHERE login = ".$ilDB->quote($a_account)." ".
3695  "AND auth_mode = ".$ilDB->quote($a_auth)." ";
3696  $res = $ilDB->query($query);
3697  if($res->numRows())
3698  {
3699  $usr = $res->fetchRow(DB_FETCHMODE_ASSOC);
3700  return $usr['login'];
3701  }
3702 
3703  // If auth_default == $a_auth => check for login
3704  if(ilAuthUtils::_getAuthModeName($ilSetting->get('auth_mode')) == $a_auth)
3705  {
3706  // First search for ext_account
3707  $query = "SELECT login FROM usr_data ".
3708  "WHERE ext_account = ".$ilDB->quote($a_account)." ".
3709  "AND auth_mode = 'default'";
3710 
3711  $res = $ilDB->query($query);
3712  if ($usr = $res->fetchRow(DB_FETCHMODE_ASSOC))
3713  {
3714  return $usr["login"];
3715  }
3716 
3717  // Search for login (no ext_account given)
3718  $query = "SELECT login FROM usr_data ".
3719  "WHERE (login =".$ilDB->quote($a_account)." AND ext_account = '') ".
3720  "AND auth_mode = 'default'";
3721 
3722  $res = $ilDB->query($query);
3723  if ($usr = $res->fetchRow(DB_FETCHMODE_ASSOC))
3724  {
3725  return $usr["login"];
3726  }
3727  }
3728  return false;
3729  }
3730 
3735  {
3736  global $ilDB;
3737 
3738  $r = $ilDB->query("SELECT count(*) AS cnt, auth_mode FROM usr_data ".
3739  "GROUP BY auth_mode");
3740  $cnt_arr = array();
3741  while($cnt = $r->fetchRow(DB_FETCHMODE_ASSOC))
3742  {
3743  $cnt_arr[$cnt["auth_mode"]] = $cnt["cnt"];
3744  }
3745 
3746  return $cnt_arr;
3747  }
3748 
3754  function _getLocalAccountsForEmail($a_email)
3755  {
3756  global $ilDB, $ilSetting;
3757 
3758  // default set to local (1)?
3759  $or_str = "";
3760  if ($ilSetting->get("auth_mode") == 1)
3761  {
3762  $or_str = " OR auth_mode = ".$ilDB->quote("default");
3763  }
3764 
3765  $usr_set = $ilDB->query("SELECT * FROM usr_data WHERE ".
3766  " email = ".$ilDB->quote($a_email)." AND ".
3767  " (auth_mode = ".$ilDB->quote("local").$or_str.")");
3768 
3769  $users = array();
3770 
3771  while ($usr_rec = $usr_set->fetchRow(DB_FETCHMODE_ASSOC))
3772  {
3773  $users[$usr_rec["usr_id"]] = $usr_rec["login"];
3774  }
3775 
3776  return $users;
3777  }
3778 
3779 
3787  function _uploadPersonalPicture($tmp_file, $obj_id)
3788  {
3789  $webspace_dir = ilUtil::getWebspaceDir();
3790  $image_dir = $webspace_dir."/usr_images";
3791  $store_file = "usr_".$obj_id."."."jpg";
3792  $target_file = $image_dir."/$store_file";
3793 
3794  chmod($tmp_file, 0770);
3795 
3796  // take quality 100 to avoid jpeg artefacts when uploading jpeg files
3797  // taking only frame [0] to avoid problems with animated gifs
3798  $show_file = "$image_dir/usr_".$obj_id.".jpg";
3799  $thumb_file = "$image_dir/usr_".$obj_id."_small.jpg";
3800  $xthumb_file = "$image_dir/usr_".$obj_id."_xsmall.jpg";
3801  $xxthumb_file = "$image_dir/usr_".$obj_id."_xxsmall.jpg";
3802 
3803  system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 200x200 -quality 100 JPEG:$show_file");
3804  system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 100x100 -quality 100 JPEG:$thumb_file");
3805  system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 75x75 -quality 100 JPEG:$xthumb_file");
3806  system(ilUtil::getConvertCmd()." $tmp_file" . "[0] -geometry 30x30 -quality 100 JPEG:$xxthumb_file");
3807 
3808  // store filename
3809  ilObjUser::_writePref($obj_id, "profile_image", $store_file);
3810 
3811  return TRUE;
3812  }
3813 
3819  function getPersonalPicturePath($a_size = "small", $a_force_pic = false)
3820  {
3821  return ilObjUser::_getPersonalPicturePath($this->getId(),$a_size,$a_force_pic);
3822  }
3823 
3830  function _getPersonalPicturePath($a_usr_id,$a_size = "small", $a_force_pic = false,
3831  $a_prevent_no_photo_image = false)
3832  {
3833  global $ilDB;
3834 
3835  // BEGIN DiskQuota: Fetch all user preferences in a single query
3836  $query = "SELECT * FROM usr_pref WHERE ".
3837  "keyword IN ('public_upload','public_profile') ".
3838  "AND usr_id = ".$ilDB->quote($a_usr_id);
3839 
3840  $res = $ilDB->query($query);
3841  while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
3842  {
3843  switch ($row['keyword'])
3844  {
3845  case 'public_upload' :
3846  $upload = $row['value'] == 'y';
3847  break;
3848  case 'public_profile' :
3849  $profile = $row['value'] == 'y';
3850  break;
3851  }
3852  }
3853  // END DiskQuota: Fetch all user preferences in a single query
3854 
3855  if(defined('ILIAS_MODULE'))
3856  {
3857  $webspace_dir = ('.'.$webspace_dir);
3858  }
3859  $webspace_dir .= ('./'.ilUtil::getWebspaceDir());
3860 
3861  $image_dir = $webspace_dir."/usr_images";
3862  // BEGIN DiskQuota: Support 'big' user images
3863  if ($a_size == 'big')
3864  {
3865  $thumb_file = $image_dir."/usr_".$a_usr_id.".jpg";
3866  }
3867  else
3868  {
3869  $thumb_file = $image_dir."/usr_".$a_usr_id."_".$a_size.".jpg";
3870  }
3871  // END DiskQuota: Support 'big' user images
3872 
3873  if((($upload && $profile) || $a_force_pic)
3874  && @is_file($thumb_file))
3875  {
3876  $file = $thumb_file."?t=".rand(1, 99999);
3877  }
3878  else
3879  {
3880  if (!$a_prevent_no_photo_image)
3881  {
3882  $file = ilUtil::getImagePath("no_photo_".$a_size.".jpg");
3883  }
3884  }
3885 
3886  return $file;
3887  }
3888 
3893  {
3894  $webspace_dir = ilUtil::getWebspaceDir();
3895  $image_dir = $webspace_dir."/usr_images";
3896  $file = $image_dir."/usr_".$this->getID()."."."jpg";
3897  $thumb_file = $image_dir."/usr_".$this->getID()."_small.jpg";
3898  $xthumb_file = $image_dir."/usr_".$this->getID()."_xsmall.jpg";
3899  $xxthumb_file = $image_dir."/usr_".$this->getID()."_xxsmall.jpg";
3900  $upload_file = $image_dir."/upload_".$this->getID();
3901 
3902  // remove user pref file name
3903  $this->setPref("profile_image", "");
3904  $this->update();
3905 
3906  if (@is_file($file))
3907  {
3908  unlink($file);
3909  }
3910  if (@is_file($thumb_file))
3911  {
3912  unlink($thumb_file);
3913  }
3914  if (@is_file($xthumb_file))
3915  {
3916  unlink($xthumb_file);
3917  }
3918  if (@is_file($xxthumb_file))
3919  {
3920  unlink($xxthumb_file);
3921  }
3922  if (@is_file($upload_file))
3923  {
3924  unlink($upload_file);
3925  }
3926  }
3927 
3928 
3929  function setUserDefinedData($a_data)
3930  {
3931  if(!is_array($a_data))
3932  {
3933  return false;
3934  }
3935  foreach($a_data as $field => $data)
3936  {
3937  #$new_data[$field] = ilUtil::stripSlashes($data);
3938  // Assign it directly to avoid update problems of unchangable fields
3939  $this->user_defined_data[$field] = $data;
3940  }
3941  #$this->user_defined_data = $new_data;
3942 
3943  return true;
3944  }
3945 
3947  {
3948  return $this->user_defined_data ? $this->user_defined_data : array();
3949  }
3950 
3952  {
3953  global $ilDB;
3954 
3955  $fields = '';
3956 
3957  foreach($this->user_defined_data as $field => $value)
3958  {
3959  if($field != 'usr_id')
3960  {
3961  $fields .= ("`".$field."` = ".$ilDB->quote($value).", ");
3962  }
3963  }
3964 
3965  $query = "REPLACE INTO usr_defined_data ".
3966  "SET ".$fields." ".
3967  "usr_id = ".$ilDB->quote($this->getId());
3968 
3969  $this->db->query($query);
3970  return true;
3971  }
3972 
3974  {
3975  global $ilDB;
3976 
3977  $query = "SELECT * FROM usr_defined_data ".
3978  "WHERE usr_id = ".$ilDB->quote($this->getId());
3979 
3980  $res = $this->db->query($query);
3981  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
3982  {
3983  $this->user_defined_data = $row;
3984  }
3985  return true;
3986  }
3987 
3989  {
3990  global $ilDB;
3991 
3992  $query = "INSERT INTO usr_defined_data ".
3993  "SET usr_id = ".$ilDB->quote($this->getId());
3994  $this->db->query($query);
3995 
3996  return true;
3997  }
3998 
4000  {
4001  global $ilDB;
4002 
4003  $query = "DELETE FROM usr_defined_data ".
4004  "WHERE usr_id = ".$ilDB->quote($this->getId());
4005  $this->db->query($query);
4006 
4007  return true;
4008  }
4009 
4015  function getProfileAsString(&$a_language)
4016  {
4017  include_once './Services/AccessControl/classes/class.ilObjRole.php';
4018  include_once 'classes/class.ilFormat.php';
4019 
4020  global $lng,$rbacreview;
4021 
4022  $language =& $a_language;
4023  $language->loadLanguageModule('registration');
4024  $language->loadLanguageModule('crs');
4025 
4026  $body = '';
4027  $body .= ($language->txt("login").": ".$this->getLogin()."\n");
4028 
4029  if(strlen($this->getUTitle()))
4030  {
4031  $body .= ($language->txt("title").": ".$this->getUTitle()."\n");
4032  }
4033  if(strlen($this->getGender()))
4034  {
4035  $gender = ($this->getGender() == 'm') ?
4036  $language->txt('gender_m') :
4037  $language->txt('gender_f');
4038  $body .= ($language->txt("gender").": ".$gender."\n");
4039  }
4040  if(strlen($this->getFirstname()))
4041  {
4042  $body .= ($language->txt("firstname").": ".$this->getFirstname()."\n");
4043  }
4044  if(strlen($this->getLastname()))
4045  {
4046  $body .= ($language->txt("lastname").": ".$this->getLastname()."\n");
4047  }
4048  if(strlen($this->getInstitution()))
4049  {
4050  $body .= ($language->txt("institution").": ".$this->getInstitution()."\n");
4051  }
4052  if(strlen($this->getDepartment()))
4053  {
4054  $body .= ($language->txt("department").": ".$this->getDepartment()."\n");
4055  }
4056  if(strlen($this->getStreet()))
4057  {
4058  $body .= ($language->txt("street").": ".$this->getStreet()."\n");
4059  }
4060  if(strlen($this->getCity()))
4061  {
4062  $body .= ($language->txt("city").": ".$this->getCity()."\n");
4063  }
4064  if(strlen($this->getZipcode()))
4065  {
4066  $body .= ($language->txt("zipcode").": ".$this->getZipcode()."\n");
4067  }
4068  if(strlen($this->getCountry()))
4069  {
4070  $body .= ($language->txt("country").": ".$this->getCountry()."\n");
4071  }
4072  if(strlen($this->getPhoneOffice()))
4073  {
4074  $body .= ($language->txt("phone_office").": ".$this->getPhoneOffice()."\n");
4075  }
4076  if(strlen($this->getPhoneHome()))
4077  {
4078  $body .= ($language->txt("phone_home").": ".$this->getPhoneHome()."\n");
4079  }
4080  if(strlen($this->getPhoneMobile()))
4081  {
4082  $body .= ($language->txt("phone_mobile").": ".$this->getPhoneMobile()."\n");
4083  }
4084  if(strlen($this->getFax()))
4085  {
4086  $body .= ($language->txt("fax").": ".$this->getFax()."\n");
4087  }
4088  if(strlen($this->getEmail()))
4089  {
4090  $body .= ($language->txt("email").": ".$this->getEmail()."\n");
4091  }
4092  if(strlen($this->getHobby()))
4093  {
4094  $body .= ($language->txt("hobby").": ".$this->getHobby()."\n");
4095  }
4096  if(strlen($this->getComment()))
4097  {
4098  $body .= ($language->txt("referral_comment").": ".$this->getComment()."\n");
4099  }
4100  if(strlen($this->getMatriculation()))
4101  {
4102  $body .= ($language->txt("matriculation").": ".$this->getMatriculation()."\n");
4103  }
4104  if(strlen($this->getCreateDate()))
4105  {
4110 
4111  $body .= ($language->txt("create_date").": ".$date."\n");
4112  }
4113 
4114  foreach($rbacreview->getGlobalRoles() as $role)
4115  {
4116  if($rbacreview->isAssigned($this->getId(),$role))
4117  {
4118  $gr[] = ilObjRole::_lookupTitle($role);
4119  }
4120  }
4121  if(count($gr))
4122  {
4123  $body .= ($language->txt('reg_role_info').': '.implode(',',$gr)."\n");
4124  }
4125 
4126  // Time limit
4127  if($this->getTimeLimitUnlimited())
4128  {
4129  $body .= ($language->txt('time_limit').": ".$language->txt('crs_unlimited')."\n");
4130  }
4131  else
4132  {
4136  new ilDateTime($this->getTimeLimitUntil(),IL_CAL_UNIX));
4138 
4139  $body .= $language->txt('time_limit').': '.$period;
4140  /*
4141  $body .= ($language->txt('time_limit').": ".$language->txt('crs_from')." ".
4142  ilFormat::formatUnixTime($this->getTimeLimitFrom(), true)." ".
4143  $language->txt('crs_to')." ".
4144  ilFormat::formatUnixTime($this->getTimeLimitUntil(), true)."\n");
4145  */
4146  }
4147  return $body;
4148  }
4149 
4150  function setInstantMessengerId($a_im_type, $a_im_id)
4151  {
4152  $var = "im_".$a_im_type;
4153  $this->$var = $a_im_id;
4154  }
4155 
4156  function getInstantMessengerId($a_im_type)
4157  {
4158  $var = "im_".$a_im_type;
4159  return $this->$var;
4160  }
4161 
4162  function setDelicious($a_delicious)
4163  {
4164  $this->delicious = $a_delicious;
4165  }
4166 
4167  function getDelicious()
4168  {
4169  return $this->delicious;
4170  }
4171 
4175  function _lookupFeedHash($a_user_id, $a_create = false)
4176  {
4177  global $ilDB;
4178 
4179  if ($a_user_id > 0)
4180  {
4181  $query = "SELECT feed_hash from usr_data WHERE usr_id = ".
4182  $ilDB->quote($a_user_id);
4183  $set = $ilDB->query($query);
4184  if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
4185  {
4186  if (strlen($rec["feed_hash"]) == 32)
4187  {
4188  return $rec["feed_hash"];
4189  }
4190  else if($a_create)
4191  {
4192  $hash = md5(rand(1,9999999) + str_replace(" ", "", (string) microtime()));
4193  $query = "UPDATE usr_data SET feed_hash = ".
4194  $ilDB->quote($hash).
4195  " WHERE usr_id = ".$ilDB->quote($a_user_id);
4196  $ilDB->query($query);
4197  return $hash;
4198  }
4199  }
4200  }
4201 
4202  return false;
4203  }
4204 
4210  function _getFeedPass($a_user_id)
4211  {
4212  global $ilDB;
4213 
4214  if ($a_user_id > 0)
4215  {
4216  $query = "SELECT value from usr_pref WHERE usr_id = ".
4217  $ilDB->quote($a_user_id) ." AND keyword=\"priv_feed_pass\"";
4218  $set = $ilDB->query($query);
4219  if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
4220  {
4221 
4222  return $rec["value"];
4223  }
4224  }
4225  return false;
4226  }
4227 
4233  function _setFeedPass($a_user_id, $a_password)
4234  {
4235  global $ilDB;
4236 
4237  if ($a_user_id > 0 )
4238  {
4239  if ($a_password=="")
4240  {
4241  $statement = $ilDB->prepare("REPLACE INTO usr_pref (usr_id,keyword,value) VALUES (? ,? , ?)");
4242  $data = array($a_user_id, "priv_feed_pass", "");
4243  }
4244  else
4245  {
4246  $statement = $ilDB->prepare("REPLACE INTO usr_pref (usr_id,keyword,value) VALUES (? ,? , ?)");
4247  $data = array($a_user_id, "priv_feed_pass", md5($a_password));
4248  }
4249  $statement->execute($data);
4250  }
4251  }
4252 
4262  public static function _loginExists($a_login,$a_user_id = 0)
4263  {
4264  global $ilDB;
4265 
4266  if ($a_user_id == 0)
4267  {
4268  $clause = "";
4269  }
4270  else
4271  {
4272  $clause = "AND usr_id != ".$ilDB->quote($a_user_id)." ";
4273  }
4274 
4275  $q = "SELECT DISTINCT login FROM usr_data ".
4276  "WHERE login = ".$ilDB->quote($a_login)." ".$clause;
4277  $r = $ilDB->query($q);
4278 
4279  if ($r->numRows() == 1)
4280  {
4281  return true;
4282  }
4283  return false;
4284  }
4285 
4296  public static function _externalAccountExists($a_external_account,$a_auth_mode)
4297  {
4298  global $ilDB;
4299 
4300  $query = "SELECT * FROM usr_data ".
4301  "WHERE ext_account = ".$ilDB->quote($a_external_account)." ".
4302  "AND auth_mode = ".$ilDB->quote($a_auth_mode);
4303  $res = $ilDB->query($query);
4304  return $res->numRows() ? true :false;
4305  }
4306 
4314  public static function _getUsersForRole($role_id, $active = -1) {
4315  global $ilDB, $rbacreview;
4316  $data = array();
4317 
4318  $ids = $rbacreview->assignedUsers($role_id);
4319 
4320  if (count ($ids) == 0)
4321  $ids = array (-1);
4322 
4323  $query = "SELECT usr_data.*, usr_pref.value AS language
4324  FROM usr_data
4325  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = 'language'
4326  WHERE usr_data.usr_id IN (".implode(',',$ids).")";
4327 
4328 
4329  if (is_numeric($active) && $active > -1)
4330  $query .= " AND usr_data.active = ".$ilDB->quote($active);
4331 
4332  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4333 
4334 # echo $query;
4335 
4336  $r = $ilDB->query($query);
4337 
4338  $data = array();
4339  while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
4340  {
4341  $data[] = $row;
4342  }
4343  return $data;
4344  }
4345 
4346 
4352  public static function _getUsersForFolder ($ref_id, $active) {
4353  global $ilDB;
4354  $data = array();
4355  $query = "SELECT usr_data.*, usr_pref.value AS language FROM usr_data LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id and usr_pref.keyword = 'language' WHERE 1 ";
4356 
4357  if (is_numeric($active) && $active > -1)
4358  $query .= " AND usr_data.active = ".$ilDB->quote($active);
4359 
4360  if ($ref_id != USER_FOLDER_ID)
4361  $query .= " AND usr_data.time_limit_owner = ".$ilDB->quote($ref_id);
4362 
4363  $query .= " AND usr_data.usr_id != '".ANONYMOUS_USER_ID."'";
4364 
4365  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4366  //echo $query;
4367  $result = $ilDB->query($query);
4368  $data = array();
4369  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
4370  {
4371  array_push($data, $row);
4372  }
4373 
4374  return $data;
4375  }
4376 
4377 
4383  public static function _getUsersForGroup ($a_mem_ids, $active = -1)
4384  {
4385  return ilObjUser::_getUsersForIds($a_mem_ids, $active);
4386  }
4387 
4388 
4394  public static function _getUsersForIds ($a_mem_ids, $active = -1, $timelimitowner = -1)
4395  {
4396  global $rbacadmin, $rbacreview, $ilDB;
4397 
4398  // quote all ids
4399  $ids = array();
4400  foreach ($a_mem_ids as $mem_id) {
4401  $ids [] = $ilDB->quote($mem_id);
4402  }
4403 
4404  $query = "SELECT usr_data.*, usr_pref.value AS language
4405  FROM usr_data
4406  LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = 'language'
4407  WHERE usr_data.usr_id IN (".implode(',',$ids).")
4408  AND usr_data.usr_id != '".ANONYMOUS_USER_ID."'";
4409 
4410  if (is_numeric($active) && $active > -1)
4411  $query .= " AND active = '$active'";
4412 
4413  if ($timelimitowner != USER_FOLDER_ID && $timelimitowner != -1)
4414  $query .= " AND usr_data.time_limit_owner = ".$ilDB->quote($timelimitowner);
4415 
4416  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4417 
4418  $r = $ilDB->query($query);
4419 
4420  while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
4421  {
4422  $mem_arr[] = $row;
4423  }
4424 
4425  return $mem_arr ? $mem_arr : array();
4426  }
4427 
4428 
4429 
4435  public static function _getUserData ($a_internalids) {
4436  global $ilDB;
4437 
4438  $ids = array();
4439  if (is_array($a_internalids)) {
4440  foreach ($a_internalids as $internalid) {
4441  if (is_numeric ($internalid))
4442  {
4443  $ids[] = $internalid;
4444  }
4445  else
4446  {
4447  $parsedid = ilUtil::__extractId($internalid, IL_INST_ID);
4448  if (is_numeric($parsedid) && $parsedid > 0)
4449  {
4450  $ids[] = $parsedid;
4451  }
4452  }
4453  }
4454  }
4455  if (count($ids) == 0)
4456  $ids [] = -1;
4457 
4458  $query = "SELECT usr_data.*, usr_pref.value AS language
4459  FROM usr_data
4460  LEFT JOIN usr_pref
4461  ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = 'language'
4462  WHERE usr_data.usr_id IN (".join(",",$ids).")";
4463 
4464  $query .= " ORDER BY usr_data.lastname, usr_data.firstname ";
4465 
4466  #echo $query;
4467  $r = $ilDB->query($query);
4468  $data = array();
4469  while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
4470  {
4471  $data[] = $row;
4472  }
4473  return $data;
4474  }
4475 
4482  public static function _getPreferences ($user_id)
4483  {
4484  global $ilDB;
4485 
4486  $prefs = array();
4487 
4488  $q = "SELECT * FROM usr_pref WHERE usr_id = ".$ilDB->quote($user_id);
4489  $r = $ilDB->query($q);
4490 #echo $q;
4491  while($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
4492  {
4493  $prefs[$row["keyword"]] = $row["value"];
4494  } // while
4495 
4496  return $prefs;
4497  }
4498 
4499 
4500  public static function _resetLoginAttempts($a_usr_id)
4501  {
4502  global $ilDB;
4503 
4504  $query = "UPDATE usr_data SET usr_data.login_attempts = 0 WHERE usr_data.usr_id = ?";
4505  $statement = $ilDB->prepareManip( $query, array('integer') );
4506  $affected = $ilDB->execute( $statement, array($a_usr_id) );
4507 
4508  if($affected) return true;
4509  else return false;
4510  }
4511 
4512  public static function _getLoginAttempts($a_usr_id)
4513  {
4514  global $ilDB;
4515 
4516  $query = "SELECT usr_data.login_attempts FROM usr_data WHERE usr_data.usr_id = ?";
4517  $statement = $ilDB->prepare( $query, array('integer') );
4518  $result = $ilDB->execute( $statement, array($a_usr_id) );
4519  $record = $ilDB->fetchAssoc( $result );
4520  $login_attempts = $record['login_attempts'];
4521 
4522  return $login_attempts;
4523  }
4524 
4525  public static function _incrementLoginAttempts($a_usr_id)
4526  {
4527  global $ilDB;
4528 
4529  $query = "UPDATE usr_data SET usr_data.login_attempts = (usr_data.login_attempts + 1) WHERE usr_data.usr_id = ?";
4530  $statement = $ilDB->prepareManip( $query, array('integer') );
4531  $affected = $ilDB->execute( $statement, array($a_usr_id) );
4532 
4533  if($affected) return true;
4534  else return false;
4535  }
4536 
4537  public static function _setUserInactive($a_usr_id)
4538  {
4539  global $ilDB;
4540 
4541  $query = "UPDATE usr_data SET usr_data.active = 0 WHERE usr_data.usr_id = ?";
4542  $statement = $ilDB->prepareManip( $query, array('integer') );
4543  $affected = $ilDB->execute( $statement, array($a_usr_id) );
4544 
4545  if($affected) return true;
4546  else return false;
4547  }
4548 
4554  public function hasPublicProfile() {
4555  return $this->getPref("public_profile") == "y";
4556  }
4557 
4563  public function getPublicName()
4564  {
4565  if ($this->hasPublicProfile())
4566  return $this->getFirstname()." ".$this->getLastname()." (".$this->getLogin().")";
4567  else
4568  return $this->getLogin();
4569 
4570  }
4571 
4572 } // END class ilObjUser
4573 ?>