-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrpadm.php
More file actions
408 lines (327 loc) · 8.49 KB
/
Copy pathgrpadm.php
File metadata and controls
408 lines (327 loc) · 8.49 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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<?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"];
$uid = validatesession($s);
$conn = ADONewConnection($dbtype);
$conn->PConnect($dbhost, $dbuser, $dbpass, $dbname);
// check if this user is the admin of any groups
$sql = "SELECT * FROM groups WHERE admin='$uid' ORDER BY description";
$result1 = $conn->Execute($sql);
if ($result1->RecordCount() == 0)
{
startpage_old("Error: Not Administrator", 0);
?>
<h2>Error: You are not a group administrator</h2>
<?php
redir("./main.php", "the Main GiftWeb page", 3);
endpage_old(-1);
exit();
}
// user is admin of at least on group
startpage_old("Group Administration", 0);
if (isset($_GET["grp"]))
{
if (isset($_POST["submit"]))
{
process_form();
}
admin_group($_GET["grp"]);
}
else
{
list_groups();
}
endpage_old(0);
// process_form()
// Remove members and approve or deny membership requests
function process_form()
{
global $conn;
// copy POST variables for easy reference
$group = $_POST["group"];
$approve = $_POST["approve"];
$deny = $_POST["deny"];
$userdel = $_POST["userdel"];
$cntdel = count($userdel);
$cntapp = count($approve);
$cntdeny = count($deny);
// setup an associative array (by uid) of requests to deny
$deny_check[0]=0;
for ( $i=0; $i < $cntdeny; $i++ )
{
$deny_check[$deny[$i]] = 1;
}
// if they're in the $approve array, set the deny_check[uid] to 0
for ( $i=0; $i < $cntapp; $i++ )
{
$deny_check[$approve[$i]] = 0;
}
// delete users
$del_err = 0;
for ( $i=0; $i < $cntdel; $i++ )
{
$sql = "DELETE FROM members WHERE uid='$userdel[$i]'";
$sql .= " and gid='$group'";
$result = $conn->Execute($sql);
// remove all purchases in the group this user is being
// removed from. If they're no longer a member and can't see
// the lists, they shouldn't be able to purchase anything on it
// right?
// Since this has to be about the most complex SQL I've ever
// written by hand (CASE tools don't count), I'm going to
// explain it in detail. Lines are number to make it easier to follow
// 1: Mark these items as not purchased
// 2: duh!
// 3: ditto
// 4: we're going to join members to items
// 5: only the group being removed from
// 6: find all items of users in the group
// 7: that have been marked purchased by the user being removed
$sql = "UPDATE items SET purchased = -1 "; //1
$sql .= "WHERE item_num in "; //2
$sql .= "(SELECT items.item_num "; //3
$sql .= " FROM members, items "; //4
$sql .= " WHERE members.gid = '$group' "; //5
$sql .= " AND members.uid=items.uid "; //6
$sql .= " AND items.purchased='$userdel[$i]')"; //7
$result = $conn->Execute($sql);
// cleanup any items this user added to the lists
$sql = "DELETE FROM items WHERE purchased=-1 and added='t'";
$result = $conn->Execute($sql);
/*
* FIX
* check for deletion error
* mail to user that they've been removed
*/
}
if ($del_err == 1)
{
/*
* FIX
* display error
*/
}
// approve requests
$app_err = 0;
for ( $i=0; $i < $cntapp; $i++ )
{
$sql = "UPDATE members SET request = 'f' WHERE";
$sql .= " uid='$approve[$i]' and gid='$group'";
$result = $conn->Execute($sql);
/*
* FIX
* check for error
*/
notify_user($approve[$i], $group, 1);
}
if ($app_err == 1)
{
/*
* FIX
* display error
*/
}
// deny requests, only if the check_deny value for that uid is 1
$deny_err = 0;
for ( $i=0; $i < $cntdeny; $i++ )
{
if ( $deny_check[$deny[$i]] == 1 )
{
$sql = "DELETE FROM members WHERE uid='$deny[$i]'";
$sql .= " and gid='$group'";
$result = $conn->Execute($sql);
/*
* FIX
* check for error
*/
notify_user($deny[$i], $group, 0);
}
}
if ( $deny_error == 1)
{
/*
* FIX
* display error
*/
}
}
// list_groups()
// List all groups that the user is group admin for.
// Each group name is a clickable link to show the members and
// requests of that group
function list_groups()
{
global $uid;
global $conn;
$sql = "SELECT * FROM groups WHERE admin='$uid' ORDER BY description";
$result = $conn->Execute($sql);
$result->MoveFirst();
echo "<h2>Choose the group you wish to view</h2>";
while (!$result->EOF)
{
$gid = $result->fields["gid"];
$group = chop($result->fields["description"]);
$sql = "SELECT * FROM members ";
$sql .= "WHERE gid='$gid' and request='t'";
$result2 = $conn->Execute($sql);
?>
<a href="./grpadm.php?grp=<?php echo $gid?>"><?php echo $group?></a>
<?php
if ($result2->RecordCount() > 0)
{
echo " Requests pending";
}
echo "<br>";
$result->MoveNext();
}
}
// admin_group()
// Show all current members and allow them to be removed
// Show all pending requests for membership and allow them to
// be approved or denied
function admin_group($gid)
{
global $uid;
global $conn;
$sql = "SELECT * FROM groups WHERE gid='$gid'";
$result = $conn->Execute($sql);
$group = chop($result->fields["description"]);
?>
<h2>Group: <?php echo $group?></h2>
<table>
<tr>
<th width=10%></th>
<th><h3>Members:</h3></th>
</tr>
</table>
<form method="post" action="./grpadm.php?grp=<?php echo $gid?>">
<input type="hidden" name="group" value="<?php echo $gid?>">
<table>
<tr>
<th width=5%></th>
<th width=25% align=left>Name</th>
<th width=5%></th>
<th align=left>Remove User</th>
</tr>
<?php
$sql = "SELECT * FROM members, users ";
$sql .= "WHERE members.gid='$gid' and members.request='f' ";
$sql .= "and members.uid = users.uid ";
$sql .= "ORDER BY users.last_name, users.first_name";
$result2 = $conn->Execute($sql);
if (!$result2)
{
echo "<tr></tr>\n";
}
// foreach user that is an approved member of this group
$result2->MoveFirst();
while (!$result2->EOF)
{
$user = $result2->fields["uid"];
$name = chop($result2->fields["last_name"]);
$name .= ", " . chop($result2->fields["first_name"]);
?>
<tr>
<td></td>
<td><?php echo $name?></td>
<td></td>
<td>
<?php
if ($user != $uid)
{
?>
<input type=checkbox name="userdel[]"
value="<?php echo $user?>">
<?php
}
else
{
echo "Group Admin";
}
?>
</td>
</tr>
<?php
$result2->MoveNext();
}
echo "</table>\n";
$sql = "SELECT * FROM members, users ";
$sql .= "WHERE members.gid='$gid' and members.request='t' ";
$sql .= "and members.uid = users.uid ";
$sql .= "ORDER BY users.last_name, users.first_name";
$result2 = $conn->Execute($sql);
if ($result2->RecordCount() > 0)
{
?>
<hr align=center width=70% size=5>
<table>
<tr>
<td width=10%></td>
<td><h3>Requests to be added:</h3></td>
</tr>
</table>
<table cellspacing=0 cellpadding=5>
<tr>
<th width=10%></th>
<th>Name</th>
<th>Approve</th>
<th>Deny</th>
</tr>
<?php
$result2->MoveFirst();
while(!$result2->EOF)
{
$user = $result2->fields["uid"];
$name = chop($result2->fields["last_name"]);
$name .= ", " . chop($result2->fields["first_name"]);
?>
<tr>
<td></td>
<td><?php echo $name?></td>
<td><input type=checkbox name="approve[]"
value="<?php echo $user?>"></td>
<td><input type=checkbox name="deny[]"
value="<?php echo $user?>"></td>
<?php
$result2->MoveNext();
}
echo "</table>\n";
echo "(If both approve and deny are selected for a user, ";
echo "they will be approved.)";
}
?>
<p>
<input type=submit name=submit value="Update Group">
<input type=reset value="Clear changes">
<p>
</form>
<p>
<a href="./grpadm.php">Return to group list</a>
<?php
}
?>