-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsiteadmin.php
More file actions
338 lines (268 loc) · 6.91 KB
/
Copy pathsiteadmin.php
File metadata and controls
338 lines (268 loc) · 6.91 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
<?php
//
// GiftWeb: PHP/PostgreSQL online Gift Registry System
// Matthew T. Jachimstal
// Copyright (C) 2000-2008 Matthew T. Jachimstal
//
// email: matthew@jachimstal.com
//
// Snail mail: Matthew Jachimstal
// 1106 Canterbury Ct, Unit D
// Elgin, IL 60120
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
require "./main.inc";
require "./util.php";
$s = $_COOKIE["GiftWeb_Session"];
$mode = $_GET["mode"];
$uid = validatesession($s);
$conn = ADONewConnection($dbtype);
$conn->PConnect($dbhost, $dbuser, $dbpass, $dbname);
$sql = "SELECT * FROM giftweb WHERE admin='$uid'";
$result1 = $conn->Execute($sql);
if ($result1->RecordCount() == 0)
{
startpage_old("Error: Not Administrator", 0);
?>
<h2>Error: You are not the site administrator</h2>
<?php
redir("./main.php", "the main GiftWeb page", 3);
endpage_old(-1);
exit();
}
function upload_image()
{
// no file to upload
if (!$_FILES["newimg"]["name"])
{
return;
}
// file already exists with this name
if (file_exists($destfile))
{
echo "<h3>This file already exists, please delete it first</h3>\n";
return;
}
// determine where on the server the web site files are
// maybe there's an easier way to do this?
$path = explode("/", $_SERVER["SCRIPT_FILENAME"]);
array_pop($path);
$basedir = implode("/", $path);
// copy the uploaded image to our image directory
$basedir .= "/images/";
$destfile = $basedir . $_FILES["newimg"]["name"];
move_uploaded_file($_FILES["newimg"]["tmp_name"], $destfile);
// make sure we have a valid JPG, PNG or GIF
$file = exec("file $destfile");
$filetype = explode(":", $file);
echo "$filetype[1]<p>\n";
if (!(stristr($filetype[1], "jpeg") || stristr($filetype[1], "gif") ||
stristr($filetype[1], "png")))
{
echo "<h3>Invalid image file!</h3>\n";
unlink($destfile);
}
}
function show_users()
{
global $conn;
global $uid;
$sql = "SELECT * FROM users WHERE uid != '$uid' and uid != '-1'
ORDER BY last_name, first_name";
$result = $conn->Execute($sql);
?>
<form method="post" action="siteadmin.php?mode=userman">
<table cellspaceing=0 cellpadding=2 border=0>
<tr><th width=20%>Last Name</th>
<th width=20%>First Name</th>
<th width=5%>Select</th>
<th width=40%>Groups (<b>Primary</b>)</th>
<th width=15%> </th></tr>
<?php
$result->MoveFirst();
while (!$result->EOF)
{
$fname = chop($result->fields["first_name"]);
$lname = chop($result->fields["last_name"]);
$userid = chop($result->fields["uid"]);
$groups = "";
$comma = 0;
// find the user's primary group (if any)
$sql2 = "SELECT groups.description
FROM members, groups
WHERE groups.gid = members.gid
and members.uid = '$userid'
and members.prim = 't'";
$result2 = $conn->Execute($sql2);
$result2->MoveFirst();
while (!$result2->EOF)
{
$groups .= "<b>".chop($result2->fields["description"])."</b>";
$comma = 1;
$result2->MoveNext(); // should only be one result, though
}
// find the users non-primary groups (if any)
$sql3 = "SELECT groups.description
FROM members, groups
WHERE groups.gid = members.gid
and members.uid = '$userid'
and members.prim = 'f'";
$result3 = $conn->Execute($sql3);
$result3->MoveFirst();
while (!$result3->EOF)
{
if($comma)
$groups .= ", ";
$comma = 1;
$groups .= chop($result3->fields["description"]);
$result3->MoveNext();
}
?>
<tr><td><?php echo $lname?></td>
<td><?php echo $fname?></td>
<td><input type=checkbox name=userlist[]
value="<?php echo $userid?>"></td>
<td><?php echo $groups?></td>
<td> </td></tr>
<?php
$result->MoveNext();
}
?>
</table>
<center>
<table><tr>
<td><input type=submit name=del_users value="Delete users"></td>
<td width=90%> </td>
</tr></table>
</form>
<br>
<center>
<a href="siteadmin.php">Back to Site Maintenance Page</a>
</center>
<?php
}
function delete_users()
{
global $conn;
if (isset($_POST["del_users"]))
{
$userlist = $_POST["userlist"];
$cntdel = count($userlist);
for ($i=0; $i < $cntdel; $i++)
{
$sql = "DELETE FROM users WHERE uid='$userlist[$i]'";
$result = $conn->Execute($sql);
$sql2 = "DELETE FROM members WHERE uid='$userlist[$i]'";
$result2 = $conn->Execute($sql2);
$sql3 = "DELETE FROM items WHERE uid='$userlist[$i]'";
$result3 = $conn->Execute($sql3);
$sql4 = "UPDATE items SET purchased=-1 ";
$sql4 .= "WHERE purchased='$userlist[$i]'";
$result4 = $conn->Execute($sql4);
$sql5 = "DELETE FROM session WHERE uid='$userlist[$i]'";
$result5 = $conn->Execute($sql5);
}
?>
<h3>Users have been deleted.</h3>
<?php
redir("./siteadmin.php", "the GiftWeb site administrator page", 3);
endpage_old(0);
exit();
}
}
function change_image()
{
global $conn;
}
function show_options()
{
global $conn;
}
startpage_old("Site Administration", 0);
if ($mode == "purgedb")
{
?>
<h3>This will purge all purchased items from the database. Are you
<em>sure</em> you want to do this?</h3>
<p>
<a href="./siteadmin.php?mode=confirmpurge">Yes</a>
<p>
<a href="./siteadmin.php">No</a>
<?php
endpage_old(0);
exit();
}
if ($mode == "confirmpurge")
{
$sql = "DELETE FROM items WHERE purchased > 0";
$result = $conn->Execute($sql);
if($result->RecordCount() == -1)
{
?>
<h3>There was an error purging the purchased items. Please check
the database manually.</h3>
<?php
}
else
{
?>
<h3>The purchased items have been purged.</h3>
<?php
redir("./siteadmin.php", "Site Administration", 5);
}
endpage_old(0);
exit();
}
if ($mode == "userman")
{
if (isset($_POST["del_users"]))
{
delete_users();
}
show_users();
endpage_old(0);
exit();
}
// display/change website options.
if ($mode == "options")
{
if (isset($_POST["upload"]))
{
upload_image();
}
if (isset($_POST["chg_img"]))
{
change_image();
redir("./siteadmin.php?mode=options", "site administrator options", 0);
}
show_options();
endpage_old(0);
exit();
}
?>
<h3>Site Maintenance options</h3>
<a href="./siteadmin.php?mode=options">Set website options</a>
<p>
<a href="./siteadmin.php?mode=purgedb">Purge Purchased Items</a>
<p>
<a href="./siteadmin.php?mode=userman">Manage Users</a>
<p>
<a href="./grpedit.php">Manage Groups</a>
<p>
<a href="">Manage System Events</a>
<?php
endpage_old(0);
?>