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