1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/**
* class to handle ILIAS 3 user-accounts
*
* This class contains methods to handle connected ILIAS 3 user-accounts.
*
* @author Arne Schröder <schroeder@data-quest.de>
* @access public
* @modulegroup elearning_interface_modules
* @module Ilias3ConnectedUser
* @package ELearning-Interface
*/
class Ilias3ConnectedUser extends ConnectedUser
{
var $roles;
var $user_sid;
/**
* constructor
*
* init class.
* @access
* @param string $cms system-type
*/
function __construct($cms, $user_id = false)
{
global $connected_cms, $perm;
parent::__construct($cms, $user_id);
// create account automatically if it doesn't exist
if (! $this->isConnected() AND ($connected_cms[$this->cms_type]->USER_AUTO_CREATE == true))
{
$this->setPassword(md5(uniqid("4dfmjsnll")));
$this->newUser(true);
$this->readData();
}
$this->roles = [$connected_cms[$cms]->roles[$perm->get_perm($this->studip_id)]];
}
function readData()
{
global $connected_cms;
parent::readData();
if($this->is_connected){
$user_id = $connected_cms[$this->cms_type]->soap_client->lookupUser($this->login);
if (!$user_id) {
//do not delete in case of error
if($user_id !== false) {
$query = "DELETE FROM auth_extern WHERE studip_user_id = ? LIMIT 1";
$statement = DBManager::get()->prepare($query);
$statement->execute([$this->studip_id]);
}
$this->id = '';
$this->login = '';
$this->external_password = '';
$this->category = '';
$this->type = '';
$this->is_connected = false;
} elseif($this->category != ''){
$cat = $connected_cms[$this->cms_type]->soap_client->checkReferenceById($this->category);
if(!$cat){
$query = "UPDATE auth_extern SET external_user_category = '' WHERE studip_user_id = ? LIMIT 1";
$statement = DBManager::get()->prepare($query);
$statement->execute([$this->studip_id]);
$this->category = '';
}
}
}
return $this->is_connected;
}
/**
* get login-data
*
* gets login-data from database
* @access public
* @param string $username username
* @return boolean returns false, if no data was found
*/
function getLoginData($username)
{
global $connected_cms;
if (!$username) {
return false;
}
$user_id = $connected_cms[$this->cms_type]->soap_client->lookupUser($username);
if ($user_id == false)
return false;
$user_data = $connected_cms[$this->cms_type]->soap_client->getUser($user_id);
if ($user_data == false)
return false;
$this->id = $user_data["usr_id"];
$this->login = $user_data["login"];
$this->external_password = $user_data["passwd"];
return true;
}
/**
* get crypted password
*
* returns ILIAS 3 password
* @access public
* @param string $password password
* @return string password
*/
function getCryptedPassword($password)
{
return md5($password);
}
/**
* set roles
*
* sets roles
* @access public
* @param array $role_array role-array
*/
function setRoles($role_array)
{
$this->roles = $role_array;
}
/**
* get roles
*
* returns roles
* @access public
* @return array roles
*/
function getRoles()
{
return $this->roles;
}
/**
* create new user category
*
* create new user category
* @access public
* @return boolean returns false on error
*/
function newUserCategory()
{
global $connected_cms, $messages;
$connected_cms[$this->cms_type]->soap_client->setCachingStatus(false);
// data for user-category in ILIAS 3
$object_data["title"] = sprintf(_("Eigene Daten von %s (%s)."), $this->getName(), $this->getId());
$object_data["description"] = sprintf(_("Hier befinden sich die persönlichen Lernmodule des Benutzers %s."), $this->getName());
$object_data["type"] = "cat";
$object_data["owner"] = $this->getId();
$cat = $connected_cms[$this->cms_type]->soap_client->getReferenceByTitle($object_data["title"]);
if ($cat != false && $connected_cms[$this->cms_type]->soap_client->checkReferenceById($cat) )
{
$messages["info"] .= sprintf(_("Ihre persönliche Kategorie wurde bereits angelegt."), $this->login) . "<br>\n";
$this->category = $cat;
}
else
{
$this->category = $connected_cms[$this->cms_type]->soap_client->addObject($object_data, $connected_cms[$this->cms_type]->main_category_node_id);
}
if ($this->category != false)
parent::setConnection( $this->getUserType() );
else
{
echo "CATEGORY_ERROR".$connected_cms[$this->cms_type]->main_category_node_id ."-";
return false;
}
// data for personal user-role in ILIAS 3
$role_data["title"] = "studip_usr" . $this->getId() . "_cat" . $this->category;
$role_data["description"] = sprintf(_("User-Rolle von %s. Diese Rolle wurde von Stud.IP generiert."), $this->getName());
$role_id = $connected_cms[$this->cms_type]->soap_client->getObjectByTitle($role_data["title"], "role");
if ($role_id != false)
$messages["info"] .= sprintf(_("Ihre persönliche Userrolle wurde bereits angelegt."), $this->login) . "<br>\n";
else
$role_id = $connected_cms[$this->cms_type]->soap_client->addRoleFromTemplate($role_data, $this->category, $connected_cms[$this->cms_type]->user_role_template_id);
$connected_cms[$this->cms_type]->soap_client->addUserRoleEntry($this->getId(), $role_id);
// delete permissions for all global roles for this category
foreach ($connected_cms[$this->cms_type]->global_roles as $key => $role)
$connected_cms[$this->cms_type]->soap_client->revokePermissions($role, $this->category);
return true;
}
/**
* new user
*
* save new user
* @access public
* @return boolean returns false on error
*/
function newUser($ignore_encrypt_passwords = false)
{
global $connected_cms, $auth, $messages;
if ($this->getLoginData($this->login))
{
$messages["error"] .= sprintf(_("Es existiert bereits ein Account mit dem Benutzernamen \"%s\"."), $this->login) . "<br>\n";
return false;
}
// data for user-account in ILIAS 3
$user_data["login"] = $this->login;
$user_data["passwd"] = $this->external_password;
$user_data["firstname"] = $this->firstname;
$user_data["lastname"] = $this->lastname;
$user_data["title"] = $this->title;
$user_data["gender"] = $this->gender;
$user_data["email"] = $this->email;
$user_data["street"] = $this->street;
$user_data["phone_home"] = $this->phone_home;
$user_data["time_limit_unlimited"] = 1;
$user_data["active"] = 1;
$user_data["approve_date"] = date('Y-m-d H:i:s');
$user_data["accepted_agreement"] = true;
if ($connected_cms[$this->cms_type]->user_style != "")
$user_data["user_style"] = $connected_cms[$this->cms_type]->user_style;
if ($connected_cms[$this->cms_type]->user_skin != "")
$user_data["user_skin"] = $connected_cms[$this->cms_type]->user_skin;
$role_id = $connected_cms[$this->cms_type]->roles[$auth->auth["perm"]];
$user_id = $connected_cms[$this->cms_type]->soap_client->addUser($user_data, $role_id);
if ($user_id != false)
{
$this->id = $user_id;
// $connected_cms[$this->cms_type]->soap_client->updatePassword($user_id, $user_data["passwd"]);
// $this->newUserCategory();
$this->setConnection(USER_TYPE_CREATED, $ignore_encrypt_passwords);
return true;
}
echo $connected_cms[$this->cms_type]->soap_client->getError();
return false;
}
/**
* update user-account
*/
public function updateUser()
{
}
/**
* delete user
*
* delete user-account
* @access public
* @return boolean returns false on error
*/
function deleteUser()
{
global $connected_cms;
$ret = null;
$connected_cms[$this->cms_type]->soap_client->user_type == "admin";
$connected_cms[$this->cms_type]->soap_client->caching_active = false;
if($this->category){
$ret['cat_deleted'] = $connected_cms[$this->cms_type]->soap_client->deleteObject($this->category);
}
if($this->type == 0 && $this->id){
$ret['iliasuser_deleted'] = $connected_cms[$this->cms_type]->soap_client->deleteUser($this->id);
}
$query = "DELETE FROM auth_extern WHERE studip_user_id = ? LIMIT 1";
$statement = DBManager::get()->prepare($query);
$statement->execute([$this->studip_id]);
$ret['auth_extern_deleted'] = $statement->rowCount();
return $ret;
}
/**
* set connection
*
* set user connection
* @access public
* @param string user_type user-type
*/
public function setConnection($user_type, $ignore_encrypt_passwords = false)
{
global $connected_cms;
if (!$ignore_encrypt_passwords && $connected_cms[$this->cms_type]->encrypt_passwords === "md5")
{
// echo "PASSWORD-ENCRYPTION";
$this->external_password = $this->getCryptedPassword( $this->external_password );
}
$connected_cms[$this->cms_type]->soap_client->setCachingStatus(false);
parent::setConnection($user_type);
}
/**
* get sid
*
* returns soap-sid
* @access public
* @return string soap-sid
*/
function getSID()
{
global $connected_cms;
$caching_status = $connected_cms[$this->cms_type]->soap_client->getCachingStatus();
$connected_cms[$this->cms_type]->soap_client->setCachingStatus(false);
$connected_cms[$this->cms_type]->soap_client->setUserType("user");
$this->user_sid = $connected_cms[$this->cms_type]->soap_client->login();
$connected_cms[$this->cms_type]->soap_client->setCachingStatus($caching_status);
$connected_cms[$this->cms_type]->soap_client->setUserType("admin");
return $this->user_sid;
}
/**
* get session-id
*
* returns soap-session-id
* @access public
* @return string soap-session-id
*/
function getSessionId()
{
$sid = $this->getSID();
if ($sid == false)
return false;
$arr = explode("::", $sid);
return $arr[0];
}
}
?>
|