-
Notifications
You must be signed in to change notification settings - Fork 7
/
groups.php
executable file
·415 lines (361 loc) · 12.4 KB
/
groups.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
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
409
410
411
412
413
414
415
<?php
/*************************************************************
* THE ADDRESS BOOK : version 1.04
*
*
*************************************************************
*
* groups.php
* Manages groups
*
*************************************************************/
// ** GET CONFIGURATION DATA **
require_once('constants.inc');
require_once(FILE_FUNCTIONS);
// ** OPEN CONNECTION TO THE DATABASE **
$db_link = openDatabase($db_hostname, $db_username, $db_password, $db_name);
// ** CHECK FOR LOGIN **
checkForLogin("admin");
// ** PERFORM USER UPDATE TASKS **
$actionMsg = "";
switch($_GET['action']) {
// EDIT A GROUP
case "edit":
// CHECK FOR GROUP ID
if (!$_GET['id']) {
reportScriptError("<B>No group provided for this action.</B>");
exit();
}
// DETERMINE THE GROUP TO DISPLAY
$group_id = $_GET['id'];
// OBTAIN GROUP NAME
if (($group_id <= 1) || (!$group_id)) {
$group_name = "All Entries";
}
elseif (($group_id == 2)) {
$group_name = "Ungrouped Entries";
}
else {
$r_grouplist = mysql_query("SELECT * FROM " . TABLE_GROUPLIST . " AS grouplist WHERE groupid=$group_id", $db_link);
$tbl_grouplist = mysql_fetch_array($r_grouplist);
$group_name = $tbl_grouplist["groupname"];
// Reassign to "All Entries" if given a groupid that doesn't exist
if ($group_name == "") {
$group_id = 1;
$group_name = "All Entries";
}
}
// RETRIEVE LIST OF CONTACTS, DEPENDING ON GROUP
// The following query displays all entries.
if (($group_id <= 1) || (!$group_id)) {
$listsql = "SELECT DISTINCT contact.id, CONCAT(lastname,', ',firstname) AS fullname, lastname, firstname
FROM ". TABLE_CONTACT ." AS contact
ORDER BY fullname";
}
// the following displays all ungrouped entries.
elseif (($group_id == 2)) {
$listsql = "SELECT DISTINCT contact.id, CONCAT(lastname,', ',firstname) AS fullname, lastname, firstname
FROM ". TABLE_CONTACT ." AS contact
LEFT JOIN ". TABLE_GROUPS ." AS groups ON groups.id=contact.id
WHERE groups.id IS NULL
ORDER BY fullname";
}
// The following query will display all entries in a given group.
else {
$listsql = "SELECT DISTINCT contact.id, CONCAT(lastname,', ',firstname) AS fullname, lastname, firstname
FROM ". TABLE_CONTACT ." AS contact, ". TABLE_GROUPS ." AS groups
WHERE contact.id=groups.id AND groups.groupid=$group_id
ORDER BY fullname";
}
// Execute the specified query
$r_contact = mysql_query($listsql, $db_link)
or die(reportSQLError($listsql));
// HTML OUTPUT
?>
<HTML>
<HEAD>
<TITLE>Address Book - Edit Group</TITLE>
<LINK REL="stylesheet" HREF="styles.css" TYPE="text/css">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="-1">
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $lang['CHARSET']?>"
</HEAD>
<BODY>
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=570>
<TR>
<TD>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=570>
<TR VALIGN=bottom>
<TD CLASS="headTitle">Mailing List</TD>
<TD CLASS="headText" ALIGN="right">
<FORM NAME="selectGroup" METHOD="get" ACTION="<?php echo(FILE_GROUPS); ?>">
select group <SELECT NAME="id" CLASS="formSelect" onChange="document.selectGroup.submit();">
<?php
// -- GENERATE GROUP SELECTION LIST --
$r_grouplist = mysql_query("SELECT groupid, groupname FROM " . TABLE_GROUPLIST . " AS grouplist WHERE groupid > 0 ORDER BY groupname", $db_link);
while ($tbl_grouplist = mysql_fetch_array($r_grouplist)) {
$selectGroupID = $tbl_grouplist['groupid'];
$selectGroupName = $tbl_grouplist['groupname'];
echo("<OPTION VALUE=$selectGroupID");
if ($selectGroupID == $group_id) {
echo(" SELECTED");
}
echo(">$selectGroupName</OPTION>\n");
}
?>
</SELECT>
</FORM>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<TR>
<TD CLASS="infoBox">
<BR>
<CENTER>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=560>
<FORM NAME="groupform" METHOD="post" ACTION="<?php echo(FILE_GROUPS); ?>">
<?php
// DISPLAY GROUP NAME
echo(" <TR VALIGN=\"top\">\n");
echo(" <TD WIDTH=560 COLSPAN=4 CLASS=\"listHeader\">$group_name</TD>\n");
echo(" </TR>\n");
?>
<TR VALIGN="top">
<TD WIDTH=190 CLASS="data">
<?php
// Display Group Checkboxes.
$groupsql = "SELECT grouplist.groupid, groupname, id
FROM " . TABLE_GROUPLIST . " AS grouplist
LEFT JOIN " . TABLE_GROUPS . " AS groups
ON grouplist.groupid=groups.groupid AND id=$id
WHERE grouplist.groupid >= 3
ORDER BY groupname";
$r_grouplist = mysql_query($groupsql, $db_link);
$numGroups = mysql_num_rows($r_grouplist);
$numGroups = round($numGroups/2); // assigns to $numGroups the number of Groups to display in the first column.
$x = 0;
$groupCheck = "";
// COLUMN 1
// $x is checked FIRST because if that fails, $tbl_grouplist will have already been evaluated
while ( ($x < $numGroups) && ($tbl_grouplist = mysql_fetch_array($r_grouplist)) ) {
$group_id = $tbl_grouplist['groupid'];
$group_name = $tbl_grouplist['groupname'];
if ( $tbl_grouplist['id'] == $id ) {
$groupCheck = " CHECKED";
}
echo("<INPUT TYPE=\"checkbox\" NAME=\"groups[]\" VALUE=\"$group_id\"$groupCheck><B>$group_name</B>\n<BR>");
//reset $groupCheck so that it doesn't stay set if the next ID does not equal $id.
$groupCheck = "";
$x++;
}
?>
</TD>
<TD WIDTH=185 CLASS="data">
<?php
// COLUMN 2
while ($tbl_grouplist = mysql_fetch_array($r_grouplist)) {
$group_id = $tbl_grouplist['groupid'];
$group_name = $tbl_grouplist['groupname'];
if ( $tbl_grouplist['id'] == $id ) {
$groupCheck = " CHECKED";
}
echo("<INPUT TYPE=\"checkbox\" NAME=\"groups[]\" VALUE=\"$group_id\"$groupCheck><B>$group_name</B>\n<BR>");
//reset $groupCheck so that it doesn't stay set if the next ID does not equal $id.
$groupCheck = "";
}
?>
</TD>
<TD WIDTH=185 CLASS="data">
<INPUT TYPE="checkbox" NAME="groupAddNew" VALUE="addNew"><B>Add New Group</B>
<BR><INPUT TYPE="text" SIZE=20 CLASS="formTextbox" NAME="groupAddName" VALUE="" MAXLENGTH=60>
</TD>
</TR>
<TR>
<TD CLASS="infoBox">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=560>
<?php
// DISPLAY ACTION MESSAGE, IF ANY
if (!empty($actionMsg)) {
?>
<TR VALIGN="top">
<TD CLASS="data"><B><FONT STYLE="color:#FF0000"><?php echo($actionMsg); ?></FONT></B></TD>
</TR>
<?php
}
?>
<TR VALIGN="top">
<TD WIDTH=560 CLASS="listHeader">Groups</TD>
</TR>
<TR VALIGN="top">
<TD WIDTH=560 CLASS="data">
<?php
// Display Group Checkboxes.
$groupsql = "SELECT grouplist.groupid, groupname
FROM " . TABLE_GROUPLIST . " AS grouplist
WHERE grouplist.groupid >= 3
ORDER BY groupname";
$r_grouplist = mysql_query($groupsql, $db_link);
while ($tbl_grouplist = mysql_fetch_array($r_grouplist)) {
$group_id = $tbl_grouplist['groupid'];
$group_name = $tbl_grouplist['groupname'];
echo("<INPUT TYPE=\"checkbox\" NAME=\"groups[]\" VALUE=\"$group_id\"><B>$group_name</B>\n<BR>");
}
?>
</TD>
</TR>
<TR VALIGN="top">
<TD WIDTH=560 COLSPAN=3 CLASS="listDivide"> </TD>
</TR>
<TR VALIGN="top">
<TD WIDTH=560 COLSPAN=3 CLASS="navmenu">
<A HREF="<?php echo(FILE_LIST); ?>">return</A>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</CENTER>
<?php
break;
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
//********************************************************************************************************
// Add a new user (admin only)
case "adduser":
checkForLogin("admin");
// Perform checks and then add if things are OK
$newuserName = $_POST['newuserName'];
if ((!empty($newuserName)) && (isAlphaNumeric($newuserName))) {
if ($_POST['newuserPass'] == $_POST['newuserConfirmPass']) {
$newuserPass = $_POST['newuserPass'];
$newuserType = $_POST['newuserType'];
$sql = "INSERT INTO ". TABLE_USERS ." (username, usertype, password) VALUES ('$newuserName', '$newuserType', MD5('$newuserPass'))";
mysql_query($sql, $db_link)
or die(ReportSQLError($sql));
$actionMsg = "User '$newuserName' has been added.";
}
else {
$actionMsg = "Password and password confirmation did not match.";
}
}
else {
$actionMsg = "Username is blank or contains non-alphanumeric characters.";
}
break;
// Delete a user (admin only)
case "deleteuser":
checkForLogin("admin");
if (empty($_GET['id'])) {
ReportScriptError("There is no user specified for deletion.");
}
$sql = "SELECT username FROM ". TABLE_USERS ." WHERE id=". $_GET['id'] ." LIMIT 1";
$deluserName = mysql_query($sql, $db_link)
or die(ReportSQLError($sql));
if (mysql_num_rows($deluserName)<1) {
ReportScriptError("The user you tried to delete does not exist.");
}
$deluserName = mysql_fetch_array($deluserName);
$deluserName = $deluserName['username'];
$sql = "DELETE FROM ". TABLE_USERS ." WHERE id=". $_GET['id'] ." LIMIT 1";
mysql_query($sql, $db_link)
or die(ReportSQLError($sql));
$actionMsg = "User '$deluserName' has been deleted.";
break;
// Change password (all users)
case "changepass":
// Check to see if password and confirmation matches
if ($_POST['passwordNew'] == $_POST['passwordNewRetype']) {
// SQL query checks to make sure username and old password is corrrect.
$sql = "UPDATE ". TABLE_USERS ." SET password=MD5('". $_POST['passwordNew'] ."') WHERE username='". $_SESSION['username'] ."' AND password=MD5('". $_POST['passwordOld'] ."') LIMIT 1";
$updatePassword = mysql_query($sql, $db_link)
or die(ReportSQLError($sql));
if (mysql_affected_rows()<1) {
$actionMsg = "Incorrect password.";
}
else {
$actionMsg = "Your password has been changed.";
}
}
else {
$actionMsg = "New password and password confirmation did not match.";
}
break;
// DEFAULT
default:
?>
<HTML>
<HEAD>
<TITLE>Address Book - Manage Groups</TITLE>
<LINK REL="stylesheet" HREF="styles.css" TYPE="text/css">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="-1">
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $lang['CHARSET']?>"
</HEAD>
<BODY>
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=570>
<TR>
<TD CLASS="headTitle">
Manage Groups
</TD>
</TR>
<TR>
<TD CLASS="infoBox">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=560>
<?php
// DISPLAY ACTION MESSAGE, IF ANY
if (!empty($actionMsg)) {
?>
<TR VALIGN="top">
<TD CLASS="data"><B><FONT STYLE="color:#FF0000"><?php echo($actionMsg); ?></FONT></B></TD>
</TR>
<?php
}
?>
<TR VALIGN="top">
<TD WIDTH=560 CLASS="listHeader">Groups</TD>
</TR>
<TR VALIGN="top">
<TD WIDTH=560 CLASS="data">
<?php
// Display Group Checkboxes.
$groupsql = "SELECT grouplist.groupid, groupname
FROM " . TABLE_GROUPLIST . " AS grouplist
WHERE grouplist.groupid >= 3
ORDER BY groupname";
$r_grouplist = mysql_query($groupsql, $db_link);
while ($tbl_grouplist = mysql_fetch_array($r_grouplist)) {
$group_id = $tbl_grouplist['groupid'];
$group_name = $tbl_grouplist['groupname'];
echo("<INPUT TYPE=\"checkbox\" NAME=\"groups[]\" VALUE=\"$group_id\"><B>$group_name</B>\n<BR>");
}
?>
</TD>
</TR>
<TR VALIGN="top">
<TD WIDTH=560 COLSPAN=3 CLASS="listDivide"> </TD>
</TR>
<TR VALIGN="top">
<TD WIDTH=560 COLSPAN=3 CLASS="navmenu">
<A HREF="<?php echo(FILE_LIST); ?>">return</A>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</CENTER>
<?php
break;
}
?>
</BODY>
</HTML>