User.inc
10.2 KB
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
<?php
/**
* Class User
* Represents a user as per the users table in the database
*
* @author Rob Cherry, Jam Warehouse (Pty) Ltd, South Africa
* @date 20 January 2003
* @package lib.user
*/
class User {
/** object primary key */
var $iId;
/** user's login name */
var $sUserName;
/** user's name (first and last) */
var $sName;
/** user's password */
var $sPassword;
/** user's maximum allowed file storage quota in bytes */
var $iQuotaMax;
/** user's current file storage quota in bytes */
var $iQuotaCurrent;
/** user's email address */
var $sEmail;
/** user's mobile phone number */
var $sMobile;
/** notify user by mail status */
var $bEmailNotification;
/** notify user via sms (mobile phone) status */
var $bSmsNotification;
/** user's ldap identification */
var $sLdapDn;
/** maxiumum concurrent sessions user may have */
var $iMaxSessions;
/** primary key of language preferred by user */
var $iLanguageID;
/** internal variable used to determine if the password has changed or not */
var $bPasswordChanged;
function User($sNewUserName, $sNewName, $sNewPassword, $iNewQuotaMax, $sNewEmail, $sNewMobile, $bNewEmailNotification, $bNewSmsNotification, $sNewLdapDn, $iNewMaxSessions, $iNewLanguageID) {
//object not created in database yet
$this->iId = -1;
$this->sUserName = $sNewUserName;
$this->sName = $sNewName;
$this->sPassword = $sNewPassword;
$this->iQuotaMax = $iNewQuotaMax;
$this->sEmail = $sNewEmail;
$this->sMobile = $sNewMobile;
$this->bEmailNotification = $bNewEmailNotification;
$this->bSmsNotification = $bNewSmsNotification;
$this->sLdapDn = $sNewLdapDn;
$this->iMaxSessions = $iNewMaxSessions;
$this->iLanguageID = $iNewLanguageID;
$this->bPasswordChanged = false;
}
/**
* Get the object's primary key
*
* @return int object's primary key
*
*/
function getID() {
return $this->iId;
}
/**
* Get the user's login name
*
* @return String user's login name
*
*/
function getUserName() {
return $this->sUserName;
}
/**
* Set the user's login name
*
* @param String New user login name
*
*/
function setUserName($sNewValue) {
$this->sUserName = $sNewValue;
}
/**
* Set the user's password
*
* @param String New user password
*
*/
function setPassword($sNewValue) {
$this->sPassword = $sNewValue;
$this->bPasswordChanged = true;
}
/**
* Get the user's maximum disk quota
*
* @return int user's maximum disk quota
*
*/
function getQuotaMax() {
return $this->iQuotaMax;
}
/**
* Set the user's maximum disk quota
*
* @param int User's maximum disk quota in bytes
*
*/
function setQuotaMax($iNewValue) {
$this->iQuotaMax = $iNewValue;
}
/**
* Get the user's currrently used quota
*
* @return int user's currently used quota
*
*/
function getQuotaCurrent() {
return $this->iQuotaCurrent;
}
/**
* Get the user's email address
*
* @return String user's email address
*
*/
function getEmail() {
return $this->sEmail;
}
/**
* Set the user's email address
*
* @param String User's email address
*
*/
function setEmail($sNewValue) {
$this->sEmail = $sNewValue;
}
/**
* Get the user's mobile phone number
*
* @return String user's mobile phone number
*
*/
function getMobile() {
return $this->sMobile;
}
/**
* Set the user's mobile phone number
*
* @param String User's mobile phone number
*
*/
function setMobile($sNewValue) {
$this->sMobile = $sNewValue;
}
/**
* Get the user's email notification status
*
* @return boolean user's email notification status
*
*/
function getEmailNotification() {
return $this->bEmailNotification;
}
/**
* Set the user's email notification status
*
* @param boolean User's email notification status (notify by email)
*
*/
function setEmailNotification($bNewValue) {
$this->bEmailNotification = $bNewValue;
}
/**
* Get the user's SMS (mobile phone) notification status
*
* @return boolean SMS (mobile phone) notification status
*
*/
function getSmsNotification() {
return $this->bSmsNotification;
}
/**
* Set the user's SMS (mobile phone) notification status
*
* @param boolean User's SMS (mobile phone) notification status (notify by mobile phone)
*
*/
function setSmsNotification($bNewValue) {
$this->bSmsNotification = $bNewValue;
}
/**
* Get the user's LDAP distinguished name
*
* @return String user's LDAP distinguished name
*
*/
function getLdapDn() {
return $this->sLdapDn;
}
/**
* Set the user's LDAP distinguished name
*
* @param String User's LDAP distinguished name
*
*/
function setLdapDn($sNewValue) {
$this->sLdapDn = $sNewValue;
}
/**
* Get the user's maximum number of concurrent sessions
*
* @return int user's maximum number of concurrent sessions
*
*/
function getMaxSessions() {
return $this->iMaxSessions;
}
/**
* Set the user's maximum number of concurrent sessions
*
* @param int User's maximum number of concurrent sessions
*
*/
function setMaxSessions($iNewValue) {
$this->iMaxSessions = $iNewValue;
}
/**
* Get the primary key for the language preferred by the user
*
* @return int primary key of language preferred by user
*
*/
function getLanguageID() {
return $this->iLanguageIDID;
}
/**
* Set the primary key of the language preferred by the user
*
* @param int Primary key of language preferred by user
*
*/
function setLanguageID($iNewValue) {
$this->iLanguageIDID = $iNewValue;
}
/**
* Create the current object in the database
*
* @return boolean on successful store, false otherwise and set $_SESSION["errorMessage"]
*
*/
function create() {
global $default, $lang_err_database, $lang_err_object_exists;
//if the object hasn't been created
if ($this->iId < 0) {
$sql = new Owl_DB();
$result = $sql->query("INSERT INTO " . $default->owl_users_table . " (username, name, password, quota_max, quota_current, email, mobile, email_notification, sms_notification, ldap_dn, max_sessions, language) " .
"VALUES ('" . addslashes($this->sUserName) . "', '" . addslashes($this->sName) . "', '" . addslashes(md5($this->sPassword)) . "', $this->iQuotaMax, 0, '" . addslashes($this->sEmail) . "', '" . addslashes($this->sMobile) . "', " . ($this->bEmailNotification ? 1 : 0) . ", " . ($this->bSmsNotification ? 1 : 0) . ", '" . addslashes($this->sLdapDn) . "', $this->iMaxSessions, $this->iLanguageID)");
if ($result) {
$this->iId = $sql->insert_id();
return true;
}
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
$_SESSION["errorMessage"] = $lang_err_object_exists . "id = " . $this->iId . " table = $default->owl_users_table";
return false;
}
/**
* Update the values in the database table with the object's current values
*
* @return boolean true on successful update, false otherwise and set $_SESSION["errorMessage"]
*
*/
function update() {
global $default, $lang_err_database, $lang_err_object_key;
//only update if the object has been stored
if ($this->iId > 0) {
$sql = new Owl_DB();
$result = $sql->query("UPDATE " . $default->owl_users_table . " SET username = '" . addslashes($this->sUserName) . "', name = '" . addslashes($this->sName) . "', " . ($this->bPasswordChanged ? "password = '" . addslashes(md5($this->sPassword)) . "', " : " ") . " quota_max = $this->iQuotaMax, email = '" . addslashes($this->sEmail) . "', mobile = '" . addslashes($this->sMobile) . "', email_notification = " . ($this->bEmailNotification ? 1 : 0) . ", sms_notification = " . ($this->bSmsNotification ? 1 : 0) . ", ldap_dn = '" . addslashes($this->sLdapDn) . "', max_sessions = $this->iMaxSessions, language = $this->iLanguageID WHERE id = $this->iId");
if ($result) {
return true;
}
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
$_SESSION["errorMessage"] = $lang_err_object_key;
return false;
}
/**
* Delete the current object from the database
*
* @return boolean true on successful deletion, false otherwise and set $_SESSION["errorMessage"]
*
*/
function delete() {
global $default, $lang_err_database, $lang_err_object_key;
//only delete the object if it exists in the database
if ($this->iId >= 0) {
$sql = new Owl_DB();
$result = $sql->query("DELETE FROM $default->owl_users_table WHERE id = $this->iId");
if ($result) {
return true;
}
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
$_SESSION["errorMessage"] = $lang_err_object_key;
return false;
}
/**
* Static function.
* Given a web_documents primary key it will create a
* User object and populate it with the
* corresponding database values
*
* @return User populated User object on successful query, false otherwise and set $_SESSION["errorMessage"]
*/
function & get($iUserID) {
global $default;
$sql = new Owl_DB();
$result = $sql->query("SELECT * FROM $default->owl_users_table WHERE id = $iUserID");
if ($result) {
if ($sql->next_record()) {
$oUser = & new User(stripslashes($sql->f("username")), stripslashes($sql->f("name")), stripslashes($sql->f("password")), $sql->f("quota_max"), stripslashes($sql->f("email")), stripslashes($sql->f("mobile")), $sql->f("email_notification"), $sql->f("sms_notification"), $sql->f("ldap_dn"), $sql->f("max_sessions"), $sql->f("language"));
$oUser->iId = $iUserID;
return $oUser;
}
$_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iUserID . " table = $default->owl_users_table";
return false;
}
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
/**
* Static function
* Get a list of users
*
* @param String Where clause (not required)
*
* @return Array array of User objects, false otherwise and set $_SESSION["errorMessage"]
*/
function getList($sWhereClause = null) {
global $default, $lang_err_database;
$aUserArray;
settype($aUserArray, "array");
$sql = new Owl_DB();
$result = $sql->query("SELECT * FROM " . $default->owl_users_table . (isset($sWhereClause) ? " " . $sWhereClause : ""));
if ($result) {
$iCount = 0;
while ($sql->next_record()) {
$oUser = & User::get($sql->f("id"));
$oUser->iQuotaCurrent = $sql->f("quota_current");
$aUserArray[$iCount] = $oUser;
$iCount++;
}
return $aUserArray;
}
$_SESSION["errorMessage"] = $lang_err_database;
return false;
}
}
?>