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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
|
<?php
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/**
* class to handle user-accounts
*
* This class contains methods to handle connected user-accounts.
*
* @author Arne Schröder <schroeder@data-quest.de>
* @access public
* @modulegroup elearning_interface_modules
* @module ConnectedUser
* @package ELearning-Interface
*/
class IliasUser
{
const USER_TYPE_ORIGINAL= '1';
const USER_TYPE_CREATED= '0';
public $index;
private $ilias_config;
public $version;
public $id;
public $studip_id;
public $studip_login;
public $studip_password;
public $login;
public $external_password;
public $category;
public $gender;
public $title_front;
public $title_rear;
public $title;
public $firstname;
public $lastname;
public $institution;
public $street;
public $country;
public $phone_home;
public $fax;
public $matriculation;
public $email;
public $type;
public $is_connected;
public $auth_plugin;
/**
* constructor
*
* init class. don't call directly, class is loaded by ConnectedIlias.
* @access public
* @param string $index ILIAS installation index
*/
function __construct($index, $version, $user_id = false)
{
global $auth;
$this->studip_id = $user_id ? $user_id : $GLOBALS['user']->id;
$this->auth_plugin = DBManager::get()->query("SELECT IFNULL(auth_plugin, 'standard') FROM auth_user_md5 WHERE user_id = '" . $this->studip_id. "'")->fetchColumn();
$this->index = $index;
$this->version = $version;
$ilias_configs = Config::get()->ILIAS_INTERFACE_SETTINGS;
$this->ilias_config = $ilias_configs[$this->index];
$this->readData();
$this->getStudipUserData();
}
/**
* get data
*
* gets data from database
* @access public
* @return boolean returns false, if no data was found
*/
function readData()
{
$query = "SELECT external_user_id, external_user_name, external_user_password, external_user_category, external_user_type
FROM auth_extern
WHERE studip_user_id = ? AND external_user_system_type = ? ORDER BY external_user_type DESC";
$statement = DBManager::get()->prepare($query);
$statement->execute([$this->studip_id, $this->index]);
$data = $statement->fetch(PDO::FETCH_ASSOC);
if (!$data) {
$this->id = '';
$this->is_connected = false;
return false;
}
$this->id = $data['external_user_id'];
$this->login = $data['external_user_name'];
$this->external_password = $data['external_user_password'];
$this->category = $data['external_user_category'];
$this->type = $data['external_user_type'];
$this->is_connected = true;
return true;
}
/**
* get stud.ip-user-data
*
* gets stud.ip-user-data from database
* @access public
* @return boolean returns false, if no data was found
*/
function getStudipUserData()
{
$query = "SELECT username, password, title_front, title_rear, Vorname,
Nachname, Email, privatnr, privadr, geschlecht
FROM auth_user_md5
LEFT JOIN user_info USING (user_id)
WHERE user_id = ?";
$statement = DBManager::get()->prepare($query);
$statement->execute([$this->studip_id]);
$data = $statement->fetch(PDO::FETCH_ASSOC);
if (!$data) {
return false;
}
$this->studip_login = $data['username'];
$this->studip_password = $data['password'];
$this->title_front = $data['title_front'];
$this->title_rear = $data['title_rear'];
$this->firstname = $data['Vorname'];
$this->lastname = $data['Nachname'];
$this->email = $data['Email'];
$this->phone_home = $data['privatnr'];
$this->street = $data['privadr'];
switch($data['geschlecht']) {
case 1: $this->gender = 'm'; break;
case 2: $this->gender = 'f'; break;
default: $this->gender = 'f';
}
$this->matriculation = '';
if (array_key_exists('matriculation', $this->ilias_config) && $this->ilias_config['matriculation']) {
$this->matriculation = 0;
foreach (DataFieldEntry::getDataFieldEntries($this->studip_id, 'user') as $entry) {
if ($entry->getName() == $this->ilias_config['matriculation']) {
$this->matriculation = $entry->getDisplayValue();
}
}
}
if ($this->title_front != '') {
$this->title = $this->title_front;
}
if ($this->title_front != '' && $this->title_rear != '') {
$this->title .= ' ';
}
if ($this->title_rear != '') {
$this->title .= $this->title_rear;
}
return true;
}
/**
* get array of user account data
*
* returns array of user account data
* @access public
* @return array user account data
*/
function getUserArray()
{
// data for user-account in ILIAS
$user_data["id"] = $this->id;
$user_data["login"] = $this->studip_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["matriculation"] = $this->matriculation;
$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;
$user_data["agree_date"] = date('Y-m-d H:i:s');
return $user_data;
}
/**
* get id
*
* returns id
* @access public
* @return string id
*/
function getId()
{
return $this->id;
}
/**
* set id
*
* returns id
* @return string id
*/
public function setId($ilias_user_id)
{
return $this->id = $ilias_user_id;
}
/**
* get stud.ip user-id
*
* returns id
* @access public
* @return string stud.ip user-id
*/
function getStudipId()
{
return $this->studip_id;
}
/**
* get username
*
* returns username
* @access public
* @return string username
*/
function getUsername()
{
return $this->login;
}
/**
* set username
*
* sets username
* @access public
* @param string $user_login username
*/
function setUsername($user_login)
{
$this->login = $user_login;
}
/**
* get password
*
* returns password
* @access public
* @return string password
*/
function getPassword()
{
return $this->external_password;
}
/**
* set password
*
* sets password
* @access public
* @param string $user_password password
*/
function setPassword($user_password)
{
$this->external_password = $user_password;
}
/**
* get user category
*
* returns id
* @access public
* @return string id
*/
function getCategory()
{
return $this->category;
}
/**
* set user category
*
* sets user category
* @access public
* @param string $user_category category
*/
function setCategory($user_category)
{
$this->category = $user_category;
}
/**
* get gender
*
* returns gender-setting
* @access public
* @return string gender-setting
*/
function getGender()
{
return $this->gender;
}
/**
* set gender
*
* sets gender
* @access public
* @param string $user_gender gender-setting
*/
function setGender($user_gender)
{
$this->gender = $user_gender;
}
/**
* get full name
*
* returns full name
* @access public
* @return string name
*/
function getName()
{
if ($this->title != "")
return $this->title . ' ' . $this->firstname . ' ' . $this->lastname;
else
return $this->firstname . ' ' . $this->lastname;
}
/**
* get firstname
*
* returns firstname
* @access public
* @return string firstname
*/
function getFirstname()
{
return $this->firstname;
}
/**
* set firstname
*
* sets firstname
* @access public
* @param string $user_firstname firstname
*/
function setFirstname($user_firstname)
{
$this->firstname = $user_firstname;
}
/**
* get lastname
*
* returns lastname
* @access public
* @return string lastname
*/
function getLastname()
{
return $this->lastname;
}
/**
* set lastname
*
* sets lastname
* @access public
* @param string $user_lastname lastname
*/
function setLastname($user_lastname)
{
$this->lastname = $user_lastname;
}
/**
* get email-adress
*
* returns email-adress
* @access public
* @return string email-adress
*/
function getEmail()
{
return $this->email;
}
/**
* set email-adress
*
* sets email-adress
* @access public
* @param string $user_email email-adress
*/
function setEmail($user_email)
{
$this->email = $user_email;
}
/**
* get user-type
*
* returns user-type
* @access public
* @return string user-type
*/
function getUserType()
{
return $this->type;
}
/**
* set user-type
*
* sets user-type
* @access public
* @param string $user_type user-type
*/
function setUserType($user_type)
{
$this->type = $user_type;
}
/**
* save connection for user-account
*
* saves user-connection to database and sets type for actual user
* @access public
* @param string $user_type user-type
*/
function setConnection($user_type)
{
$this->setUserType($user_type);
$query = "INSERT INTO auth_extern (studip_user_id, external_user_id, external_user_name,
external_user_password, external_user_category,
external_user_system_type, external_user_type)
VALUES (?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY
UPDATE external_user_name = VALUES(external_user_name),
external_user_password = VALUES(external_user_password),
external_user_category = VALUES(external_user_category),
external_user_id = VALUES(external_user_id)";
$statement = DBManager::get()->prepare($query);
$statement->execute([
(string)$this->studip_id,
(string)$this->id,
(string)$this->login,
(string)$this->external_password,
(string)$this->category,
(string)$this->index,
(int)$this->type,
]);
$this->is_connected = true;
$this->readData();
}
/**
* remove connection for user-account
*
* deletes user-connection from database (only for manually connected user)
* @access public
*/
function unsetConnection($ignore_usertype = false)
{
if (!$ignore_usertype && ($this->getUserType() != self::USER_TYPE_ORIGINAL)) {
return;
}
$query = "DELETE FROM auth_extern WHERE studip_user_id = ? AND external_user_system_type = ? AND external_user_type = ?";
$statement = DBManager::get()->prepare($query);
$statement->execute([
(string)$this->studip_id,
(string)$this->index,
(int)$this->type
]);
$this->is_connected = false;
$this->readData();
}
/**
* get connection-status
*
* returns true, if there is a connected user
* @access public
* @return boolean connection-status
*/
function isConnected()
{
return $this->is_connected;
}
/**
* get authentication token
*
* generates authentication token and updates auth_extern
* @access public
*/
function getToken()
{
$token = md5(uniqid("iliastoken538"));
$query = "UPDATE `auth_extern` SET `external_user_token` = ?, `external_user_token_valid_until` = ?
WHERE `auth_extern`.`studip_user_id` = ? AND `auth_extern`.`external_user_system_type` = ? AND `auth_extern`.`external_user_type` = ?";
$statement = DBManager::get()->prepare($query);
$statement->execute([
$token,
time() + 600,
(string)$this->studip_id,
(string)$this->index,
(int)$this->type
]);
return $token;
}
}
?>
|