1 |
<?php |
1 |
<?php |
2 |
|
2 |
|
3 |
/** |
3 |
/** |
4 |
* User class. |
4 |
* User class. |
5 |
* |
5 |
* |
6 |
* @author Tamlyn Rhodes <tam at zenology dot co dot uk> |
6 |
* @author Tamlyn Rhodes <tam at zenology dot co dot uk> |
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License |
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU General Public License |
8 |
* @copyright (c)2003, 2004 Tamlyn Rhodes |
8 |
* @copyright (c)2003, 2004 Tamlyn Rhodes |
9 |
* @version $Id: user.class.php,v 1.5 2006/03/14 19:38:54 tamlyn Exp $ |
9 |
* @version $Id: user.class.php,v 1.5 2006/03/14 19:38:54 tamlyn Exp $ |
10 |
*/ |
10 |
*/ |
11 |
|
11 |
|
12 |
/** |
12 |
/** |
13 |
* Class used to represent a user. |
13 |
* Class used to represent a user. |
14 |
* @package singapore |
14 |
* @package singapore |
15 |
* @author Tamlyn Rhodes <tam at zenology dot co dot uk> |
15 |
* @author Tamlyn Rhodes <tam at zenology dot co dot uk> |
16 |
* @copyright (c)2003, 2004 Tamlyn Rhodes |
16 |
* @copyright (c)2003, 2004 Tamlyn Rhodes |
17 |
*/ |
17 |
*/ |
18 |
class sgUser |
18 |
class sgUser |
19 |
{ |
19 |
{ |
20 |
/** |
20 |
/** |
21 |
* Username of user. Special cases are 'guest' and 'admin'. |
21 |
* Username of user. Special cases are 'guest' and 'admin'. |
22 |
* @var string |
22 |
* @var string |
23 |
*/ |
23 |
*/ |
24 |
var $username = ""; |
24 |
var $username = ""; |
25 |
|
25 |
|
26 |
/** |
26 |
/** |
27 |
* MD5 hash of password |
27 |
* MD5 hash of password |
28 |
* @var string |
28 |
* @var string |
29 |
*/ |
29 |
*/ |
30 |
var $userpass = "5f4dcc3b5aa765d61d8327deb882cf99"; |
30 |
var $userpass = "5f4dcc3b5aa765d61d8327deb882cf99"; |
31 |
|
31 |
|
32 |
/** |
32 |
/** |
33 |
* Bit-field of permissions |
33 |
* Bit-field of permissions |
34 |
* @var int |
34 |
* @var int |
35 |
*/ |
35 |
*/ |
36 |
var $permissions = 0; |
36 |
var $permissions = 0; |
37 |
|
37 |
|
38 |
/** |
38 |
/** |
39 |
* Space-separated list of groups of which the user is a member |
39 |
* Space-separated list of groups of which the user is a member |
40 |
* @var string |
40 |
* @var string |
41 |
*/ |
41 |
*/ |
42 |
var $groups = ""; |
42 |
var $groups = ""; |
43 |
|
43 |
|
44 |
/** |
44 |
/** |
45 |
* Email address of user |
45 |
* Email address of user |
46 |
* @var string |
46 |
* @var string |
47 |
*/ |
47 |
*/ |
48 |
var $email = ""; |
48 |
var $email = ""; |
49 |
|
49 |
|
50 |
/** |
50 |
/** |
51 |
* The name or title of the user |
51 |
* The name or title of the user |
52 |
* @var string |
52 |
* @var string |
53 |
*/ |
53 |
*/ |
54 |
var $fullname = ""; |
54 |
var $fullname = ""; |
55 |
|
55 |
|
56 |
/** |
56 |
/** |
57 |
*Description of user account |
57 |
*Description of user account |
58 |
* @var string |
58 |
* @var string |
59 |
*/ |
59 |
*/ |
60 |
var $description = ""; |
60 |
var $description = ""; |
61 |
|
61 |
|
62 |
/** |
62 |
/** |
63 |
* Statistics (what's this? I don't know!) |
63 |
* Statistics (what's this? I don't know!) |
64 |
* @var string |
64 |
* @var string |
65 |
*/ |
65 |
*/ |
66 |
var $stats = ""; |
66 |
var $stats = ""; |
67 |
|
67 |
|
68 |
/** |
68 |
/** |
69 |
* Constructor ensures username and userpass have values |
69 |
* Constructor ensures username and userpass have values |
70 |
*/ |
70 |
*/ |
71 |
function sgUser($username, $userpass) |
71 |
function sgUser($username, $userpass) |
72 |
{ |
72 |
{ |
73 |
$this->username = $username; |
73 |
$this->username = $username; |
74 |
$this->userpass = $userpass; |
74 |
$this->userpass = $userpass; |
75 |
} |
75 |
} |
76 |
|
76 |
|
77 |
/** |
77 |
/** |
78 |
* Checks if currently logged in user is an administrator. |
78 |
* Checks if currently logged in user is an administrator. |
79 |
* |
79 |
* |
80 |
* @return bool true on success; false otherwise |
80 |
* @return bool true on success; false otherwise |
81 |
*/ |
81 |
*/ |
82 |
function isAdmin() |
82 |
function isAdmin() |
83 |
{ |
83 |
{ |
84 |
return $this->permissions & SG_ADMIN; |
84 |
return $this->permissions & SG_ADMIN; |
85 |
} |
85 |
} |
86 |
|
86 |
|
87 |
/** |
87 |
/** |
88 |
* Checks if currently logged in user is a guest. |
88 |
* Checks if currently logged in user is a guest. |
89 |
* |
89 |
* |
90 |
* @return bool true on success; false otherwise |
90 |
* @return bool true on success; false otherwise |
91 |
*/ |
91 |
*/ |
92 |
function isGuest() |
92 |
function isGuest() |
93 |
{ |
93 |
{ |
94 |
return $this->username == "guest"; |
94 |
return $this->username == "guest"; |
95 |
} |
95 |
} |
96 |
|
96 |
|
97 |
/** |
97 |
/** |
98 |
* Checks if this user is the owner of the specified item. |
98 |
* Checks if this user is the owner of the specified item. |
99 |
* |
99 |
* |
100 |
* @param sgItem the item to check |
100 |
* @param sgItem the item to check |
101 |
* @return bool true if this user is the owner; false otherwise |
101 |
* @return bool true if this user is the owner; false otherwise |
102 |
*/ |
102 |
*/ |
103 |
function isOwner($item) |
103 |
function isOwner($item) |
104 |
{ |
104 |
{ |
105 |
return $item->owner == $this->username; |
105 |
return $item->owner == $this->username; |
106 |
} |
106 |
} |
107 |
|
107 |
|
108 |
/** |
108 |
/** |
109 |
* Checks if this user is a member of the group(s) supplied |
109 |
* Checks if this user is a member of the group(s) supplied |
110 |
* |
110 |
* |
111 |
* @return bool true on success; false otherwise |
111 |
* @return bool true on success; false otherwise |
112 |
*/ |
112 |
*/ |
113 |
function isInGroup($groups) |
113 |
function isInGroup($groups) |
114 |
{ |
114 |
{ |
115 |
return (bool) array_intersect(explode(" ",$groups),explode(" ",$this->groups)); |
115 |
return (bool) array_intersect(explode(" ",$groups),explode(" ",$this->groups)); |
116 |
} |
116 |
} |
117 |
|
117 |
|
118 |
|
118 |
|
119 |
} |
119 |
} |
120 |
|
120 |
|
121 |
?> |
121 |
?> |