ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjiLincUser.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 
36 {
42  function ilObjiLincUser(&$a_user_obj,$a_from_ilinc = 'false')
43  {
44  global $ilias,$lng;
45 
46  $this->ilias =& $ilias;
47  $this->lng =& $lng;
48  $this->user =& $a_user_obj;
49 
50  $this->__init($a_from_ilinc);
51  }
52 
53  function __init(&$a_from_ilinc)
54  {
55  global $ilErr, $ilDB;
56 
57  $q = "SELECT ilinc_id,ilinc_login,ilinc_passwd FROM usr_data ".
58  "WHERE usr_data.usr_id = ".$ilDB->quote($this->user->getId());
59  $r = $ilDB->query($q);
60 
61  if ($r->numRows() > 0)
62  {
63  $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
64 
65  $this->id = $data['ilinc_id'];
66  $this->login = $data['ilinc_login'];
67  $this->passwd = $data['ilinc_passwd'];
68  }
69  else
70  {
71  $ilErr->raiseError("<b>Error: There is no dataset with id ".
72  $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
73  "<br />Line: ".__LINE__, $ilErr->FATAL);
74  }
75  }
76 
81  function update()
82  {
83  global $ilDB;
84 
85  $q = "UPDATE usr_data SET ".
86  "last_update=now(), ".
87  "ilinc_id = ".$ilDB->quote(ilUtil::prepareDBString($this->id)).", ".
88  "ilinc_login = ".$ilDB->quote(ilUtil::prepareDBString($this->login)).", ".
89  "ilinc_passwd = ".$ilDB->quote(ilUtil::prepareDBString($this->passwd))." ".
90  "WHERE usr_id = ".$ilDB->quote($this->user->getId());
91 
92  $this->ilias->db->query($q);
93 
94  return true;
95  }
96 
97  function syncILIAS2iLinc()
98  {
99  // for future use
100  }
101 
102  function synciLinc2ILIAS()
103  {
104  // for future use
105  }
106 
107  function getErrorMsg()
108  {
109  $err_msg = $this->error_msg;
110  $this->error_msg = "";
111 
112  return $err_msg;
113  }
114 
122  function __createLoginData($a_user_id,$a_user_login,$a_inst_id)
123  {
124  if (!$a_inst_id)
125  {
126  $a_inst_id = "0";
127  }
128 
129  $chars = preg_split('//', substr($a_user_login,0,3), -1, PREG_SPLIT_NO_EMPTY);
130  //$chars = str_split(substr($a_user_login,0,3)); // PHP5 only
131 
132  // convert non-allowed chars in login to <underscore>
133  // not allowed: ~!@#$%^&*()`-=+[]{};:'\|/?<>,
134  $result = preg_replace('@[^a-zA-Z0-9_]@','_',$chars);
135 
136  $data["login"] = $result."_".$a_user_id."_".$a_inst_id."_".time();
137  $data["passwd"] = md5(microtime().$a_user_login.rand(10000, 32000));
138 
139  $this->id = '';
140  $this->login = $data['login'];
141  $this->passwd = $data['passwd'];
142 
143  return $data;
144  }
145 
146  // create user account on iLinc server
147  function add()
148  {
149  include_once ('./Modules/ILinc/classes/class.ilnetucateXMLAPI.php');
150 
151  $this->ilincAPI = new ilnetucateXMLAPI();
152 
153  // create login and passwd for iLinc account
154  $login_data = $this->__createLoginData($this->user->getId(),$this->user->getLogin(),$this->ilias->getSetting($inst_id));
155 
156  //$this->ilincAPI->addUser($login_data,$this->user);
157  $this->ilincAPI->addUser($this);
158  $response = $this->ilincAPI->sendRequest();
159 
160  if ($response->isError())
161  {
162  if (!$response->getErrorMsg())
163  {
164  $this->error_msg = "err_add_user";
165  }
166  else
167  {
168  $this->error_msg = $response->getErrorMsg();
169  }
170 
171  return false;
172  }
173 
174  $this->id = $response->getFirstID();
175  $this->login = $login_data["login"];
176  $this->passwd = $login_data["passwd"];
177 
178  $this->update();
179 
180  return true;
181  }
182 
183  // edit user account on iLinc server
184  function edit()
185  {
186  include_once ('./Modules/ILinc/classes/class.ilnetucateXMLAPI.php');
187 
188  $this->ilincAPI = new ilnetucateXMLAPI();
189 
190  //$this->ilincAPI->addUser($login_data,$this->user);
191  $this->ilincAPI->editUser($this);
192  $response = $this->ilincAPI->sendRequest();
193 
194  if ($response->isError())
195  {
196  if (!$response->getErrorMsg())
197  {
198  $this->error_msg = "err_edit_user";
199  }
200  else
201  {
202  $this->error_msg = $response->getErrorMsg();
203  }
204 
205  return false;
206  }
207 
208  return true;
209  }
210 
224  function find($a_id = '',$a_login = '', $a_fullname = '')
225  {
226  include_once ('./Modules/ILinc/classes/class.ilnetucateXMLAPI.php');
227 
228  $this->ilincAPI = new ilnetucateXMLAPI();
229 
230  $this->ilincAPI->findUser($a_id,$a_login,$a_fullname);
231  $response = $this->ilincAPI->sendRequest();
232 
233  if ($response->isError())
234  {
235  if (!$response->getErrorMsg())
236  {
237  $this->error_msg = "err_find_user";
238  }
239  else
240  {
241  $this->error_msg = $response->getErrorMsg();
242  }
243 
244  return false;
245  }
246 
247  return $response->data;
248  }
249 
250  function setVar($a_varname, $a_value)
251  {
252  $this->$a_varname = $a_value;
253  }
254 } // END class.ilObjiLincUser
255 ?>