1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* User and rights management |
4
|
|
|
* |
5
|
|
|
* NOTICE: |
6
|
|
|
* Keep in mind the relation between User.php, UserAdministration.php and |
7
|
|
|
* UserMaintenance.php |
8
|
|
|
* |
9
|
|
|
* User.php is ONLY for the function that the normal user is allowed to. That |
10
|
|
|
* means NOT create other users. The user should not be allowed to change is |
11
|
|
|
* own rights. |
12
|
|
|
* |
13
|
|
|
* UserAdministration.php is for the administrator of the intranet. Can create |
14
|
|
|
* new user. Administrator is not allowed to disable a User, as it will affect |
15
|
|
|
* all intranets. |
16
|
|
|
* |
17
|
|
|
* UserMaintenance.php is for overall maintenance team. Should be allowed everthing. |
18
|
|
|
* |
19
|
|
|
* @package Intraface |
20
|
|
|
* @author Sune Jensen <[email protected]> |
21
|
|
|
* @author Lars Olesen <[email protected]> |
22
|
|
|
* @since 0.1.0 |
23
|
|
|
* @version @package-version@ |
24
|
|
|
*/ |
25
|
|
|
require_once 'Intraface/functions.php'; |
26
|
|
|
|
27
|
|
|
class Intraface_User extends Intraface_Standard implements Intraface_Identity |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var db |
31
|
|
|
*/ |
32
|
|
|
protected $db; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var integer |
36
|
|
|
*/ |
37
|
|
|
protected $id; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
public $value; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var integer |
46
|
|
|
*/ |
47
|
|
|
protected $intranet_id = 0; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var error |
51
|
|
|
*/ |
52
|
|
|
public $error; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $permissions = array(); |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
protected $modules = array(); |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var address |
66
|
|
|
*/ |
67
|
|
|
private $address; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var boolean |
71
|
|
|
*/ |
72
|
|
|
private $permissions_loaded = false; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Constructor |
76
|
|
|
* |
77
|
|
|
* @param integer $id User id |
78
|
|
|
* |
79
|
|
|
* @return void |
|
|
|
|
80
|
|
|
*/ |
81
|
19 |
|
public function __construct($id = 0) |
82
|
|
|
{ |
83
|
19 |
|
$this->id = $this->value['id'] = intval($id); |
84
|
19 |
|
$this->db = MDB2::singleton(DB_DSN); |
85
|
19 |
|
$this->error = $this->getError(); |
|
|
|
|
86
|
|
|
|
87
|
19 |
|
if (PEAR::isError($this->db)) { |
88
|
|
|
throw new Exception($this->db->getMessage() . $this->db->getUserInfo()); |
89
|
|
|
} |
90
|
|
|
|
91
|
19 |
|
if ($this->id > 0) { |
92
|
19 |
|
$this->load(); |
93
|
19 |
|
} |
94
|
19 |
|
} |
95
|
|
|
|
96
|
19 |
|
public function getError() |
97
|
|
|
{ |
98
|
19 |
|
if ($this->error) { |
99
|
|
|
return $this->error; |
100
|
|
|
} |
101
|
19 |
|
return ($this->error = new Intraface_Error); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Load |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
19 |
|
protected function load() |
110
|
|
|
{ |
111
|
19 |
|
$result = $this->db->query("SELECT id, email, disabled FROM user WHERE id = " . $this->db->quote($this->id, 'integer')); |
112
|
|
|
|
113
|
19 |
|
if (PEAR::isError($result)) { |
114
|
|
|
throw new Exception($result->getUserInfo()); |
115
|
|
|
} |
116
|
19 |
View Code Duplication |
if ($result->numRows() == 1) { |
117
|
19 |
|
$row = $result->fetchRow(MDB2_FETCHMODE_ASSOC); |
118
|
19 |
|
$this->value = $row; |
119
|
19 |
|
return $this->id; |
120
|
|
|
} else { |
121
|
|
|
return ($this->id = 0); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Gets the address object |
127
|
|
|
* |
128
|
|
|
* @return object |
129
|
|
|
*/ |
130
|
2 |
|
public function getAddress() |
131
|
|
|
{ |
132
|
2 |
|
if (!empty($this->address)) { |
133
|
|
|
return $this->address; |
134
|
|
|
} |
135
|
2 |
|
return ($this->address = Intraface_Address::factory('user', $this->id)); |
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Gets permissions |
140
|
|
|
* |
141
|
|
|
* @return array |
142
|
|
|
*/ |
143
|
2 |
|
public function getPermissions() |
144
|
|
|
{ |
145
|
2 |
|
return $this->permissions; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Loads permissions |
150
|
|
|
* |
151
|
|
|
* @param integer $intranet_id |
152
|
|
|
* |
153
|
|
|
* @return boolean |
154
|
|
|
*/ |
155
|
9 |
|
private function loadPermissions($intranet_id = null) |
156
|
|
|
{ |
157
|
9 |
|
if (!$intranet_id) { |
|
|
|
|
158
|
2 |
|
$intranet_id = $this->intranet_id; |
159
|
2 |
|
} |
160
|
|
|
|
161
|
9 |
|
$result = $this->db->query("SELECT intranet_id, module_id |
162
|
|
|
FROM permission |
163
|
9 |
|
WHERE permission.intranet_id = ". $this->db->quote($intranet_id, 'integer')." |
164
|
9 |
|
AND permission.user_id = ". $this->db->quote($this->get('id'), 'integer')); |
165
|
|
|
|
166
|
9 |
|
if (PEAR::isError($result)) { |
167
|
|
|
throw new Exception($result->getUserInfo()); |
168
|
|
|
} |
169
|
|
|
|
170
|
9 |
|
while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
171
|
8 |
|
$this->permissions['intranet']['module'][$row['module_id']] = true; |
172
|
8 |
|
$this->permissions['user']['module'][$row['module_id']] = true; |
173
|
8 |
|
$this->permissions['user']['intranet'][$row['intranet_id']] = true; |
174
|
8 |
|
} |
175
|
|
|
|
176
|
9 |
|
$this->permissions_loaded = true; |
177
|
|
|
|
178
|
9 |
|
return true; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Gets module id from string |
183
|
|
|
* |
184
|
|
|
* @param integer $module |
185
|
|
|
* |
186
|
|
|
* @return integer |
187
|
|
|
*/ |
188
|
3 |
|
private function getModuleIdFromString($module) |
189
|
|
|
{ |
190
|
3 |
View Code Duplication |
if (empty($this->modules)) { |
191
|
3 |
|
$result = $this->db->query("SELECT id, name FROM module WHERE active = 1"); |
192
|
3 |
|
if (PEAR::isError($result)) { |
193
|
|
|
throw new Exception($result->getUserInfo()); |
194
|
|
|
} |
195
|
|
|
|
196
|
3 |
|
while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
197
|
3 |
|
$this->modules[$row['name']] = $row['id']; |
198
|
3 |
|
} |
199
|
3 |
|
} |
200
|
3 |
View Code Duplication |
if (!empty($this->modules[$module])) { |
201
|
3 |
|
return $module_id = $this->modules[$module]; |
|
|
|
|
202
|
|
|
} else { |
203
|
|
|
throw new Exception('user says unknown module ' . $module); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Clears cached permissions |
209
|
|
|
* |
210
|
|
|
* @return void |
211
|
|
|
*/ |
212
|
1 |
|
public function clearCachedPermission() |
213
|
|
|
{ |
214
|
1 |
|
$this->permissions = array(); |
215
|
1 |
|
$this->modules = array(); |
216
|
1 |
|
$this->permissions_loaded = false; |
217
|
1 |
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Returns whether the permissions has been loaded |
221
|
|
|
* |
222
|
|
|
* @return boolean |
223
|
|
|
*/ |
224
|
3 |
|
private function permissionsLoaded() |
225
|
|
|
{ |
226
|
3 |
|
return $this->permissions_loaded; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Returns whether the user has intranetaccess |
231
|
|
|
* |
232
|
|
|
* @param integer $intranet_id |
233
|
|
|
* |
234
|
|
|
* @return boolean |
235
|
|
|
*/ |
236
|
9 |
|
public function hasIntranetAccess($intranet_id = 0) |
237
|
|
|
{ |
238
|
9 |
|
if ($intranet_id == 0) { |
239
|
5 |
|
$intranet_id = $this->intranet_id; |
240
|
5 |
|
} |
241
|
|
|
|
242
|
|
|
//if (!$this->permissionsLoaded()) { |
|
|
|
|
243
|
9 |
|
$this->loadPermissions($intranet_id); |
244
|
|
|
//} |
245
|
|
|
|
246
|
9 |
|
if (!empty($this->permissions['user']['intranet'][$intranet_id])) { |
247
|
8 |
|
return $this->permissions['user']['intranet'][$intranet_id]; |
248
|
|
|
} |
249
|
|
|
|
250
|
2 |
|
return false; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Returns whether user has module Access |
255
|
|
|
* |
256
|
|
|
* @param integer $module |
257
|
|
|
* @param integer $intranet_id |
258
|
|
|
* |
259
|
|
|
* @return integer |
260
|
|
|
*/ |
261
|
3 |
|
public function hasModuleAccess($module, $intranet_id = 0) |
262
|
|
|
{ |
263
|
3 |
|
$filename = PATH_INCLUDE_MODULE . $module . '/Main' . ucfirst($module) . '.php'; |
264
|
3 |
View Code Duplication |
if (file_exists($filename)) { |
265
|
3 |
|
require_once $filename; |
266
|
3 |
|
$module_class = 'Main'.ucfirst($module); |
267
|
3 |
|
$module_object = new $module_class; |
268
|
3 |
|
if ($module_object->isShared()) { |
269
|
|
|
return true; |
270
|
|
|
} |
271
|
3 |
|
if ($module_object->isRequired()) { |
272
|
|
|
return true; |
273
|
|
|
} |
274
|
3 |
|
} |
275
|
|
|
|
276
|
3 |
|
$intranet_id = intval($intranet_id); |
277
|
|
|
|
278
|
3 |
|
if ($intranet_id == 0) { |
279
|
3 |
|
$intranet_id = $this->intranet_id; |
280
|
3 |
|
} |
281
|
|
|
|
282
|
3 |
|
if (!$this->permissionsLoaded()) { |
283
|
1 |
|
$this->loadPermissions($intranet_id); |
284
|
1 |
|
} |
285
|
|
|
|
286
|
|
|
// getting the module |
287
|
3 |
|
if (is_string($module)) { |
288
|
3 |
|
$module_id = $this->getModuleIdFromString($module); |
289
|
3 |
|
} else { |
290
|
|
|
$module_id = intval($module); |
291
|
|
|
} |
292
|
|
|
|
293
|
3 |
|
if (!empty($this->permissions) and is_array($this->permissions)) { |
|
|
|
|
294
|
3 |
|
if (empty($this->permissions['intranet']['module'][$module_id]) or $this->permissions['intranet']['module'][$module_id] !== true) { |
|
|
|
|
295
|
2 |
|
return false; |
296
|
2 |
View Code Duplication |
} elseif (empty($this->permissions['user']['module'][$module_id]) or $this->permissions['user']['module'][$module_id] !== true) { |
|
|
|
|
297
|
|
|
return false; |
298
|
|
|
} else { |
299
|
2 |
|
return true; |
300
|
|
|
} |
301
|
|
|
} |
302
|
1 |
|
return false; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* Returns whether user has subaccess |
307
|
|
|
* |
308
|
|
|
* @param integer $module |
309
|
|
|
* @param integer $sub_access |
310
|
|
|
* @param integer intranet_id (n�r den skal tilg�s fra intranetmaintenance (til hvad?) |
311
|
|
|
* |
312
|
|
|
* @return boolean |
313
|
|
|
*/ |
314
|
1 |
|
public function hasSubAccess($module, $sub_access, $intranet_id = 0) |
315
|
|
|
{ |
316
|
1 |
|
settype($intranet_id, "integer"); |
317
|
1 |
|
if ($intranet_id == 0) { |
318
|
1 |
|
$intranet_id = $this->intranet_id; |
319
|
1 |
|
} |
320
|
|
|
|
321
|
1 |
|
if (is_string($module)) { |
322
|
|
|
$module_id = $this->getModuleIdFromString($module); |
323
|
|
|
} else { |
324
|
1 |
|
$module_id = intval($module); |
325
|
|
|
} |
326
|
|
|
|
327
|
1 |
|
if (is_string($sub_access)) { |
328
|
|
|
$result = $this->db->query("SELECT id FROM module_sub_access WHERE module_id = ".$module_id." AND name = \"".$sub_access."\""); |
329
|
|
|
if (PEAR::isError($result)) { |
330
|
|
|
throw new Exception($result->getUserInfo()); |
331
|
|
|
} |
332
|
|
|
if ($row = $result->fetchRow()) { |
333
|
|
|
$sub_access_id = $row['id']; |
334
|
|
|
} else { |
335
|
|
|
throw new Exception("user says unknown subaccess"); |
336
|
|
|
} |
337
|
|
|
} else { |
338
|
1 |
|
$sub_access_id = intval($sub_access); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
// If the permissions are not loaded, we will do that. |
342
|
1 |
|
if (empty($this->permissions['intranet']['module'])) { |
343
|
|
|
// Vi tjekker om intranettet har adgang til modullet. |
344
|
|
|
// er den ikke un�dvendig - det kan vi vel lave i den n�ste |
345
|
|
|
// sql-s�tning? |
346
|
1 |
|
$result = $this->db->query("SELECT module.id |
347
|
|
|
FROM permission |
348
|
|
|
INNER JOIN module |
349
|
|
|
ON permission.module_id = module.id |
350
|
1 |
|
WHERE permission.intranet_id = ".$intranet_id." |
351
|
1 |
|
AND permission.user_id = 0"); |
352
|
1 |
|
if (PEAR::isError($result)) { |
353
|
|
|
throw new Exception($result->getUserInfo()); |
354
|
|
|
} |
355
|
1 |
|
while ($row = $result->fetchRow()) { |
356
|
|
|
$this->permissions['intranet']['module'][$row['id']]; |
357
|
|
|
} |
358
|
1 |
|
} |
359
|
|
|
|
360
|
|
|
// first we check whether the use has access to the module. |
361
|
1 |
View Code Duplication |
if (empty($this->permissions['intranet']['module'][$module_id]) or $this->permissions['intranet']['module'][$module_id] !== true) { |
|
|
|
|
362
|
1 |
|
return false; |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
// then we check whether there is access to the sub access |
366
|
|
View Code Duplication |
if (!empty($this->permissions['user']['module']['subaccess'][$sub_access_id]) and $this->permissions['user']['module']['subaccess'][$sub_access_id] === true) { |
|
|
|
|
367
|
|
|
return true; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
// if the check on the array did not go possitive, we make sure it is because they are not loaded. |
371
|
|
|
// @todo: this is probably not a good way to do it. |
372
|
|
|
$sql = "SELECT module_sub_access.id |
373
|
|
|
FROM permission |
374
|
|
|
INNER JOIN module_sub_access |
375
|
|
|
ON permission.module_sub_access_id = module_sub_access.id |
376
|
|
|
INNER JOIN module |
377
|
|
|
ON permission.module_id = module.id |
378
|
|
|
WHERE permission.intranet_id = ".$intranet_id." |
379
|
|
|
AND permission.user_id = ".$this->id." |
380
|
|
|
AND module.id = ".$module_id." |
381
|
|
|
AND module_sub_access.module_id = module.id"; |
382
|
|
|
|
383
|
|
|
$result = $this->db->query($sql); |
384
|
|
|
if (PEAR::isError($result)) { |
385
|
|
|
throw new Exception($result->getUserInfo()); |
386
|
|
|
} |
387
|
|
|
while ($row = $result->fetchRow()) { |
388
|
|
|
$this->permissions['user']['module']['subaccess'][$row['id']] = true; |
389
|
|
|
} |
390
|
|
|
|
391
|
|
View Code Duplication |
if (!empty($this->permissions['user']['module']['subaccess'][$sub_access_id]) and $this->permissions['user']['module']['subaccess'][$sub_access_id] === true) { |
|
|
|
|
392
|
|
|
return true; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
return false; |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Returns the active intranet |
400
|
|
|
* |
401
|
|
|
* @return integer |
402
|
|
|
*/ |
403
|
2 |
|
public function getActiveIntranetId() |
404
|
|
|
{ |
405
|
2 |
|
$result = $this->db->query("SELECT active_intranet_id FROM user WHERE id = ".$this->db->quote($this->id, 'integer')); |
406
|
2 |
|
if (PEAR::isError($result)) { |
407
|
|
|
throw new Exception($result->getUserInfo()); |
408
|
|
|
} |
409
|
|
|
|
410
|
2 |
|
if ($result->numRows() == 1) { |
411
|
2 |
|
$row = $result->fetchRow(MDB2_FETCHMODE_ASSOC); |
412
|
2 |
|
if ($this->hasIntranetAccess($row['active_intranet_id']) and $row['active_intranet_id'] != 0) { |
|
|
|
|
413
|
1 |
|
return $row['active_intranet_id']; |
414
|
|
|
} |
415
|
1 |
|
} |
416
|
|
|
|
417
|
1 |
|
$result = $this->db->query("SELECT intranet.id |
418
|
|
|
FROM intranet |
419
|
|
|
INNER JOIN permission |
420
|
|
|
ON permission.intranet_id = intranet.id |
421
|
1 |
|
WHERE permission.user_id = " . $this->db->quote($this->id, 'integer')); |
422
|
1 |
|
if (PEAR::isError($result)) { |
423
|
|
|
throw new Exception($result->getUserInfo()); |
424
|
|
|
} |
425
|
1 |
|
if ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) { |
426
|
1 |
|
return $row['id']; |
427
|
|
|
} else { |
428
|
|
|
return false; |
|
|
|
|
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
function getActiveIntranet() |
433
|
|
|
{ |
434
|
|
|
return new Intraface_Intranet($this->getActiveIntranetId()); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
function getSetting() |
438
|
|
|
{ |
439
|
|
|
return new Intraface_Setting($this->getActiveIntranet()->getId(), $this->getId()); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* Sets intranet_id |
444
|
|
|
* |
445
|
|
|
* @todo what is this used for? |
446
|
|
|
* |
447
|
|
|
* @return boolean |
448
|
|
|
*/ |
449
|
4 |
|
public function setIntranetId($id) |
450
|
|
|
{ |
451
|
4 |
|
$this->intranet_id = intval($id); |
452
|
4 |
|
if ($this->id == 0 || $this->hasIntranetAccess()) { |
453
|
4 |
|
$this->load(); |
454
|
4 |
|
return true; |
455
|
|
|
} |
456
|
|
|
throw new Exception('you do not have access to this intranet'); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Sets active intranet_id |
461
|
|
|
* |
462
|
|
|
* @return boolean |
463
|
|
|
*/ |
464
|
2 |
|
public function setActiveIntranetId($id) |
465
|
|
|
{ |
466
|
2 |
|
$id = intval($id); |
467
|
2 |
|
if ($this->hasIntranetAccess($id)) { |
468
|
2 |
|
$this->db->exec("UPDATE user SET active_intranet_id = ". $this->db->quote($id, 'integer')." WHERE id = ". $this->db->quote($this->get('id'), 'integer')); |
469
|
2 |
|
return $id; |
470
|
|
|
} |
471
|
|
|
return false; |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
/////////////////////////////////////////////////////////////////////////////// |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* Gets a list with the users intranets |
478
|
|
|
* |
479
|
|
|
* @return array |
480
|
|
|
*/ |
481
|
19 |
|
public function getIntranetList() |
482
|
|
|
{ |
483
|
|
|
// Skal denne funktion v�re her? M�ske den istedet skulle v�re i intranet. |
484
|
19 |
|
$result = $this->db->query("SELECT DISTINCT(intranet.id), intranet.name FROM intranet |
485
|
|
|
INNER JOIN permission |
486
|
|
|
ON permission.intranet_id = intranet.id |
487
|
|
|
WHERE permission.user_id = ".$this->id); |
488
|
|
|
|
489
|
|
|
if (PEAR::isError($result)) { |
490
|
|
|
throw new Exception($result->getUserInfo()); |
491
|
19 |
|
} |
492
|
|
|
return $result->fetchAll(); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* Validates user info |
497
|
|
|
* |
498
|
|
|
* NOTICE: As it is created now, $input has to be injected by reference, |
499
|
|
|
* because of the little hack with disabled. |
500
|
|
|
* |
501
|
|
|
* @param array $input |
502
|
|
|
* |
503
|
|
|
* @return boolean |
504
|
|
|
*/ |
505
|
17 |
|
protected function validate(&$input) |
506
|
|
|
{ |
507
|
17 |
|
$input = safeToDb($input); |
508
|
17 |
|
$validator = new Intraface_Validator($this->error); |
509
|
|
|
|
510
|
17 |
|
$validator->isEmail($input["email"], "Ugyldig E-mail"); |
511
|
17 |
|
$result = $this->db->query("SELECT id FROM user WHERE email = \"".$input["email"]."\" AND id != ".$this->id); |
512
|
17 |
|
if (PEAR::isError($result)) { |
513
|
|
|
throw new Exception($result->getUserInfo()); |
514
|
|
|
} |
515
|
17 |
|
if ($result->numRows() > 0) { |
516
|
|
|
$this->error->set("E-mail-adressen er allerede benyttet"); |
|
|
|
|
517
|
|
|
} |
518
|
|
|
|
519
|
17 |
|
if (isset($input["disabled"])) { |
520
|
17 |
|
$input["disabled"] = 1; |
521
|
17 |
|
} else { |
522
|
|
|
$input["disabled"] = 0; |
523
|
|
|
} |
524
|
17 |
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* Updates the user |
528
|
|
|
* |
529
|
|
|
* @param array $input Data to update |
530
|
|
|
* |
531
|
|
|
* @return integer |
532
|
|
|
*/ |
533
|
|
|
public function update($input) |
534
|
|
|
{ |
535
|
|
|
$this->validate($input); |
536
|
|
|
|
537
|
|
|
$sql = "email = \"".$input["email"]."\", |
538
|
|
|
disabled = ".$input["disabled"].""; |
539
|
|
|
|
540
|
|
|
if ($this->error->isError()) { |
|
|
|
|
541
|
|
|
return false; |
|
|
|
|
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
if ($this->id) { |
545
|
|
|
$this->db->exec("UPDATE user SET ".$sql." WHERE id = ".$this->id); |
546
|
|
|
$this->load(); |
547
|
|
|
return $this->id; |
548
|
|
|
} else { |
549
|
|
|
throw new Exception("An id is needed to update user details in User->Update()"); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
return true; |
|
|
|
|
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
function generateNewPassword($email) |
556
|
|
|
{ |
557
|
|
|
if (!Validate::email($email)) { |
558
|
|
|
return false; |
559
|
|
|
} |
560
|
|
|
$db = MDB2::singleton(DB_DSN); |
561
|
|
|
$result = $db->query("SELECT id FROM user WHERE email = '".$email."'"); |
562
|
|
|
if (PEAR::isError($result)) { |
563
|
|
|
throw new Exception($result->getUserInfo()); |
564
|
|
|
} |
565
|
|
|
if ($result->numRows() != 1) { |
566
|
|
|
return false; |
567
|
|
|
} |
568
|
|
|
$row = $result->fetchRow(MDB2_FETCHMODE_ASSOC); |
569
|
|
|
$new_password = Intraface_Kernel::randomKey(8); |
570
|
|
|
|
571
|
|
|
$db->exec("UPDATE user SET password = '".md5($new_password)."' WHERE id =" . $row['id']); |
572
|
|
|
|
573
|
|
|
return $new_password; |
574
|
|
|
} |
575
|
|
|
|
576
|
2 |
|
public function updatePassword($old_password, $new_password, $repeat_password) |
577
|
|
|
{ |
578
|
2 |
|
if ($this->id == 0) { |
579
|
|
|
return false; |
580
|
|
|
} |
581
|
|
|
|
582
|
2 |
|
$result = $this->db->query("SELECT * FROM user WHERE password = '".safeToDb(md5($old_password))."' AND id = " . $this->get('id')); |
583
|
2 |
|
if ($result->numRows() < 1) { |
584
|
|
|
$this->error->set('error in old password'); |
|
|
|
|
585
|
|
|
} |
586
|
|
|
|
587
|
2 |
|
$validator = new Intraface_Validator($this->error); |
588
|
2 |
|
$validator->isPassword($new_password, 6, 16, "error in new password"); |
589
|
|
|
|
590
|
2 |
|
if ($new_password != $repeat_password) { |
591
|
1 |
|
$this->error->set('error in password'); |
|
|
|
|
592
|
1 |
|
} |
593
|
|
|
|
594
|
2 |
|
if ($this->error->isError()) { |
|
|
|
|
595
|
1 |
|
return false; |
596
|
|
|
} |
597
|
|
|
|
598
|
1 |
|
$this->db->query("UPDATE user SET password = '".safeToDb(md5($new_password))."' WHERE id = " . $this->get('id')); |
599
|
|
|
|
600
|
1 |
|
return true; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* TODO M�ske kan det g�res enklere, s� der ikke skal bruges s� mange tabeller |
605
|
|
|
*/ |
606
|
|
View Code Duplication |
public function getList() |
|
|
|
|
607
|
|
|
{ |
608
|
|
|
$i = 0; |
|
|
|
|
609
|
|
|
$result = $this->db->query("SELECT DISTINCT user.id, user.email, address.name |
610
|
|
|
FROM user |
611
|
|
|
INNER JOIN permission ON permission.user_id = user.id |
612
|
|
|
LEFT JOIN address ON user.id = address.belong_to_id AND address.type = 2 |
613
|
|
|
WHERE (address.active = 1 OR address.type IS NULL) AND permission.intranet_id = ".$this->intranet_id." |
614
|
|
|
ORDER BY address.name"); |
615
|
|
|
|
616
|
|
|
if (PEAR::isError($result)) { |
617
|
|
|
throw new Exception($result->getUserInfo()); |
618
|
|
|
} |
619
|
|
|
return $result->fetchAll(); |
620
|
|
|
} |
621
|
|
|
|
622
|
1 |
|
public function isFilledIn() |
623
|
|
|
{ |
624
|
1 |
|
if ($this->getAddress()->get('phone')) { |
625
|
|
|
return true; |
626
|
|
|
} |
627
|
1 |
|
return false; |
628
|
|
|
} |
629
|
|
|
|
630
|
2 |
|
public function getId() |
631
|
|
|
{ |
632
|
2 |
|
return $this->id; |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
function getLanguage() |
636
|
|
|
{ |
637
|
|
|
return $this->getSetting()->get('user', 'language'); |
638
|
|
|
} |
639
|
|
|
} |
640
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.