-
Notifications
You must be signed in to change notification settings - Fork 0
/
owneradm.php
377 lines (314 loc) · 11.1 KB
/
owneradm.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
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
<?php
//*****************************************************************************
// $Header: /srv/cvsroot/AQasset/admin/owneradm.php,v 1.2 2005/04/14 14:04:22 druus Exp $
//
// $Author: druus $
//
// Description Provides a front end for the AQ intranet admin page,
// where various administrative tasks such as managing
// users are done.
//
// --------------------------------------
// History
// -------
// $Log: owneradm.php,v $
// Revision 1.2 2005/04/14 14:04:22 druus
// Modified how the authentication is handled. Instead of using Apache login with environmental variables, use PHPSESSID sessions.
//
// Revision 1.1.1.1 2005/04/01 06:55:06 druus
// Initial release.
//
//*****************************************************************************
// Read the configuration file if exists
include_once("../config/admin.conf.php");
// Check that the config file has been read!
if (!isset($DBSERVER))
die("Unable to read contents of configuration file.");
// We need to login before using this page.
//require("adminauth.php");
require("../include/authenticate.inc.php");
// Check if we are actually logged in.
if (!authenticate())
{
echo "<h3>Not authorised!</h3>\n";
echo "Click 'Quit Admin' to return to the asset index page and login first.\n";
die();
}
include("/srv/www/htdocs/common/utils.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> AQ intranet Administration - User Admin, version 1.0 </TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META http-equiv="Expires" content="Tue, 20 Aug 1996 14:25:27 GMT">
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="Daniel Ruus">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<LINK HREF="../style.css" TYPE="text/css" REL="stylesheet">
<!-- Create a special style for text input boxes -->
<STYLE TYPE="text/css">
.input-style
{
font-family : MS San-Serif,Verdana,Arial,Helvetica;
font-size : 12px;
color : black;
border-style : solid;
border-width : 1px;
margin-left : 0px;
margin-top : 0px;
}
</STYLE>
</HEAD>
<BODY BACKGROUND="images/tatami.gif">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!-- Hide for old browsers
function LaunchAdminWindow(adminPath)
{
newWindow = window.open(adminPath,'newWin','width=600,height=400,scrollbars=yes,resize=yes');
}
function confirmSubmit(text)
{
var agree=confirm(text);
if (agree)
return true ;
else
return false ;
}
// Finished hiding -->
</SCRIPT>
<?php
($_SERVER['REQUEST_METHOD'] == 'GET') ? $values = $_GET : $values = $_POST;
$module = dirname(__FILE__);
$module_name = basename(dirname(__FILE__));
$index = 0; // 0 - right hand menu turned off / 1 - right hand menu turned on
# Create a connection to the user database
$db = mysql_connect($DBSERVER, $DBUSER, $DBPASSWD);
if (!mysql_select_db($DBNAME, $db)) {
$errorMessage = mysql_error($db);
print "ERROR:<BR>\n";
print $errorMessage;
die;
}
// Act upon the commands that MIGHT have been passed. No command - list data.
if ($values['cmd'] == "" | $values['cmd'] == "listall")
{
/*
if (isset($values['users']))
{
if ($values['users'] == "user")
$selectUsers = "SELECT * FROM user WHERE priv = 'User' ORDER BY user_name";
else if ($values['users'] == "admin")
$selectUsers = "SELECT * FROM user WHERE priv IN ('SuperUser','Admin') ORDER BY user_name";
else if ($values['users'] == "all")
$selectUsers = "SELECT * FROM user ORDER BY user_name";
else
die("Unable to compile query.");
}
else
*/
$selectUsers = "SELECT * FROM clients ORDER BY client";
?>
<TABLE ALIGN="center" WIDTH="500" BORDER="0" CELLSPACING="0">
<TR>
<TD ALIGN="center" COLSPAN="3">
<H3>AQ Department Admin Page</H3>
</TD>
</TR>
</TABLE>
<?php
$userResult = mysql_query($selectUsers) or db_error($db);
$numUsers = mysql_num_rows($userResult);
if ($numUsers == 0)
print "No clients found.<BR>\n";
else
{
?>
<TABLE CELLSPACING="0" CELLPADDING="2">
<TR>
<TD COLSPAN="3">
<A HREF="<?php echo $_SERVER['PHP_SELF']?>?cmd=newclient">Create a new client entry</A>
</TD>
</TR>
<TR BGCOLOR="6780B8">
<TD><FONT COLOR="white">Client</FONT></TD>
<TD><FONT COLOR="white">Information</FONT></TD>
<TD><FONT COLOR="white">Active?</FONT></TD>
</TR>
<?php
while ($listuser = mysql_fetch_array($userResult))
print "<TR>\n\t<TD><A HREF=\"" . $PHP_SELF . "?cmd=edit&cid=" . $listuser['cid'] . "\">" . $listuser['client'] . "</A></TD><TD>" . substr($listuser['info'],0 , 40) . "</TD><TD>" . $listuser['active'] . "</TD></TR>\n";
}
?>
<TR>
<TD COLSPAN="3">
<HR WIDTH="75%">
<A HREF="<?php echo $_SERVER['PHP_SELF']?>?cmd=newclient">Create a new client entry</A>
</TD>
</TR>
</TABLE>
<?php
} // EOS listall
# Edit an asset
if ($values['cmd'] == "edit" || $values['cmd'] == "newclient")
{
// Is the user logged in as Administrator? If so, make sure he/she is allowed to
// update data. This is found by checking the cookie "admin", which is set if the user
// is looged as an admin.
if (!isset($_COOKIE['admin']) || $_COOKIE['admin'] == "")
unset($Authorised);
else if ($_COOKIE['admin'] > "")
$Authorised = true;
else
unset($Authorised);
// Is a new user to be created, or are we loading data from an existing user?
if ($values['cmd'] == "edit")
{
// Get details about the selected user
$query = "SELECT * FROM clients WHERE cid = " . $values['cid'] . " LIMIT 1";
$query_result = mysql_query($query, $db) or die("<H4><FONT COLOR=\"red\">DB Error</FONT></H4>Unable to execute query<BR>$query");
$num_rows = mysql_num_rows($query_result) or db_error($db, true);
if ($num_rows == 0)
{
#
# No matching entry found, so don't do anything else.
#
print "<H1>No matching entry found!</H1>\n";
print "Click <A HREF=\"javascript:history.go(-1);\">here</A> to try again.\n";
}
else
{
#
# Multiple matches found. Let the user select one of them.
#
print "<H3 ALIGN=\"center\">Edit Clients</H3>\n";
//print "<A HREF=\"javascript:history.go(-1);\">Click here to go back to the previous page</A><BR>\n";
$statusDetails = mysql_fetch_array($query_result);
}
}
else
print "<H3 ALIGN=\"center\">Create New AQ Client</H3>\n";
?>
<FORM ACTION="<?php echo $PHP_SELF;?>" METHOD="post">
<?php
if ($values['cmd'] == "edit")
{
print "<INPUT TYPE=\"hidden\" NAME=\"cmd\" VALUE=\"updateclient\">\n";
print "<INPUT TYPE=\"hidden\" NAME=\"cid\" VALUE=\"" . $statusDetails['cid'] . "\">\n";
}
else
print "<INPUT TYPE=\"hidden\" NAME=\"cmd\" VALUE=\"create_new_client\">\n";
?>
<TABLE BORDER="0" ALIGN="center">
<TR BGCOLOR="6780B8">
<TD COLSPAN="4"><FONT COLOR="white">Client details</FONT></TD>
</TR>
<TR>
<TD>Client</TD>
<TD><INPUT TYPE="text" NAME="client" CLASS="input-style" VALUE="<?php echo $statusDetails['client'] ?>" onFocus="style.backgroundColor='#FFFFCC'" onBlur="style.backgroundColor='#FFFFFF'"></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD>Full name</TD>
<TD><INPUT TYPE="text" NAME="client_full_name" CLASS="input-style" VALUE="<?php echo $statusDetails['client_full_name'] ?>" onFocus="style.backgroundColor='#FFFFCC'" onBlur="style.backgroundColor='#FFFFFF'"></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD>Active?</TD>
<TD><SELECT NAME="active" CLASS="input-style" onFocus="style.backgroundColor='#FFFFCC'" onBlur="style.backgroundColor='#FFFFFF'">
<?php
if ($statusDetails['active'] == "Yes")
{
print "\t<OPTION VALUE=\"Yes\" SELECTED>Yes</OPTION>\n";
print "\t<OPTION VALUE=\"No\">No</OPTION>\n";
}
else
{
print "\t<OPTION VALUE=\"Yes\">Yes</OPTION>\n";
print "\t<OPTION VALUE=\"No\" SELECTED>No</OPTION>\n";
}
?>
</SELECT>
</TD>
</TR>
<TR>
<TD VALIGN="top">Information</TD>
<TD COLSPAN="3">
<TEXTAREA NAME="info" COLS="60" ROWS="6" CLASS="input-style" onFocus="style.backgroundColor='#FFFFCC'" onBlur="style.backgroundColor='#FFFFFF'"><?php echo $userDetails['info'];?></TEXTAREA>
</TD>
</TR>
<TR>
<?php
if ($values['cmd'] == "edit")
{
?>
<TD COLSPAN="4">
<INPUT TYPE="submit" VALUE="Save">
<INPUT TYPE="button" VALUE="Cancel" onClick="javascript:history.back(1);">
<A HREF="<?php echo $_SERVER['PHP_SELF'];?>?cmd=delete_client&cid=<?php echo $statusDetails['cid'];?>" onClick="return confirmSubmit('Are you sure you want to delete this AQ Department?');">
<IMG SRC="images/delete_small.gif" BORDER="0" ALT="Delete Client">Delete Client
</A>
</TD>
<?php
}
else
{
?>
<TD COLSPAN="2"><INPUT TYPE="button" VALUE="Cancel" onClick="javascrpt:history.back(1);"> <INPUT TYPE="submit" VALUE="Continue -->"></TD>
<?php
}
?>
</TABLE>
</FORM>
<?php
//}
}
if ($values['cmd'] == "create_new_client")
{
// Create an INSERT statement for a new Status level
$createNew = "INSERT INTO clients ";
$createNew .= "(client, client_full_name, info, active) ";
$createNew .= "VALUES ('" . $values['client'] . "', ";
$createNew .= "VALUES ('" . $values['client_full_name'] . "', ";
$createNew .= "VALUES ('" . $values['info'] . "', ";
$createNew .= "'" . $values['active'] . "') ";
//die("Query: $createNew");
$createResult = mysql_query($createNew, $db) or db_error($db, true);
print "Department '" . $values['dep_name'] . "' successfully created.<BR>\n";
print "<A HREF=\"" . $PHP_SELF . "?cmd=\">Click here to return to the main screen.<BR></A>\n";
// Reload the screen
//print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=" . $PHP_SELF . "?cmd=\">\n";
}
if ($values['cmd'] == "updateclient")
{
$query = "UPDATE clients ";
$query .= "SET client = '" . $values['client'] . "', ";
$query .= "client_full_name = '" . $values['client_full_name'] . "', ";
$query .= "info = '" . $values['info'] . "', ";
$query .= "active = '" . $values['active'] . "' ";
$query .= "WHERE dep_id = " . $values['dep_id'];
//die("Query: $query");
$query_result = mysql_query($query, $db) or db_error($db, true);
# Reload the previous page...
print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=" . $PHP_SELF . "?cmd=\">\n";
} // End of UpdateUser
if ($values['cmd'] == "delete_client")
{
$query = "DELETE FROM clients ";
$query .= "WHERE cid = " . $values['cid'];
//die("Query: $query");
$query_result = mysql_query($query, $db) or db_error($db, true);
print "Client <b>" . $values['client'] . "</b> successfully removed.<br/>\n";
print "<A HREF=\"" . $PHP_SELF . "?cmd=\">Click here to return to the main screen.<BR></A>\n";
// Reload the previous page...
//print "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=" . $PHP_SELF . "?cmd=\">\n";
} // End of DeleteUser
# Free the resultset to save memory
@mysql_free_result($query_result);
//CloseTable();
print "<BR><BR><BR><ADDRESS>© Absolute Quality 2004 - Contact <A HREF=\"mailto:druus@AbsoluteQuality.co.uk\">webmaster</A> for comments and suggestions.<BR>\$Revision: 1.2 $</ADDRESS>\n";
//include("footer.php");
?>