/
user.php
223 lines (178 loc) · 5.81 KB
/
user.php
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
<?PHP
include_once("action.php");
class user
{
// returns id of current user
function id()
{
return(session::get("user"));
}
// fetch user information
// $id ... information of this user
// no par ... current user
function get($id="")
{
if (!$id and user::id()) $id = user::id();
if ($id)
{
$userArray = fetch_to_array(database::query("SELECT * FROM user WHERE ID='$id'"),"");
if (is_array($userArray)) $tempArray = current($userArray);
return($tempArray);
}
else return(FALSE);
}
// get user name
// if no id then get current user
// FALSE, if nobody logged in
function name($id="")
{
$userArray = user::get($id);
if ($userArray) return($userArray[user]);
}
// get program status information
function status()
{
if ($userID = user::id())
{
$tempArray = current(fetch_to_array(database::query("SELECT status FROM user WHERE ID='$userID'"),""));
return($tempArray[status]);
}
}
// get user name
// FALSE, if nobody logged in
function password()
{
$userArray = user::get($id);
if ($userArray) return($userArray[password]);
}
// returns groupID of active user
function group($id)
{
$userArray = user::get($id);
if ($userArray) return($userArray[group]);
}
// get superuser status
function superuser($id="")
{
if (!$id and ($id = user::id())) $id = user::id();
$userArray = user::get($id);
if (group::superuser($userArray[group])) return(TRUE);
else return(FALSE);
}
// checks if user exists
function exists($user)
{
if (mysql_num_rows(database::query("SELECT * FROM user WHERE user='$user'"))) return(TRUE);
return(FALSE);
}
//------------------------------------------------------------------------------
// get list of users with ordered entries
function get_users($status="")
{
switch(strtolower($status))
{
case entry:
{
$queryString = "SELECT user.ID,user.user
FROM user,entry
WHERE entry.owner=user.ID";
}
break;
case visible:
{
$queryString = "SELECT user.ID,user.user
FROM user,entry,statustype
WHERE entry.owner=user.ID and entry.status=statustype.ID and statustype.visible='0'";
}
break;
default;
$queryString = "SELECT ID,user FROM user ORDER BY user";
break;
}
//echoalert($queryString);
$resource = database::query($queryString);
$retArray = array();
while ($entry = mysql_fetch_object($resource))
{
$tempArray = array("value" => $entry->ID,"text" => $entry->user);
if (!in_array($tempArray,$retArray)) // check if already exists
array_push($retArray,$tempArray);
}
return($retArray);
}
//------------------------------------------------------------------------------
// checks login data and loggs in
function login($user,$password)
{
$tempArray = fetch_to_array(database::query("SELECT * FROM user WHERE user='$user' and password='" . md5($password) . "'"),"");
if (is_array($tempArray)) // log in
{
$tempArray = current($tempArray);
session::set("user",$tempArray[ID]);
save_status($_SESSION);
}
else
echojavascript("Login oder Passwort falsch");
}
// logout active user
function logout()
{
session::destroy("user");
}
// shows login / logout field
function show()
{
if (system::getval(debug)) echo "<div id='login_debug'>";
else echo "<div id='login'>";
if ($userID = session::get("user")) // show user and logout
{
// change password
if ($_GET[action] == "change")
{
echo "<form method='get' action='index.php'>";
echo form::field("password","password","","","","<i>Neues Passort</i>","","newpassword");
echo form::field("submit","b1","ändern");
echo form::field("hidden","action","changedo");
echo "</form>";
}
// logged in
else
{
echo "<span class='normal'>Angemeldet: </span><span class='red'>" . user::name($userID) . " </span>";
echo form::link(""," - abmelden ","index.php?action=logout","logout");
echo form::link(""," - Passwort ändern ","index.php?action=change","change-password");
// if su display admin
echo form::link(""," - Administration","admin.php","admin");
if ($_SESSION['show'])
echo form::link(""," - Import into <b>" . thesaurus::name($_SESSION['show']) . "</b>","import.php?id=" . $_SESSION['show'],"import");
// menu switches
action::hyrarchy(); // toggle hyrarchy off / on
action::descriptor();
action::visible();
action::tooltips(); // toggle tooltips off / on
if (right::write()) action::edit(); // show edit function
action::listit();
action::debug();
}
}
// show login
else
{
echo "<span class='normal'>";
echo "<form method='get' action='index.php'>";
echo "<i>Benutzername </i><input type='text' name='user' value='$user'>";
echo " <i>Passwort </i><input type='password' name='password'>";
echo " <input type='submit' name='action' value='anmelden'>";
echo "<input type='hidden' name='action' value='login'>";
echo "</form>";
echo "</span>";
}
// display javascript status
/* echo "<span class='small'>";
if (session::get("JS")) echo "JavaScript aktiv";
else echo "kein Javascript";
echo "</span>";*/
echo "</div>";
}
}
?>