-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.php
305 lines (263 loc) · 10.7 KB
/
messages.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
<?php
# ------------------------------------------------
# License and copyright:
# See license.txt for license information.
# ------------------------------------------------
include('config.php');
# Grab the data
$Responder_ID = MakeSafe($_REQUEST['r_ID']);
$M_ID = MakeSafe($_REQUEST['MSG_ID']);
$action = MakeSafe($_REQUEST['action']);
if (!(is_numeric($Responder_ID))) {
# A small bit of magic to filter out any screwy crackerness of the RespID
$Responder_ID = NULL;
}
if (!(is_numeric($M_ID))) {
# Same with Message ID.
$M_ID = NULL;
}
if ($Is_Auth = User_Auth()) {
# Template top
include('templates/open.page.php');
include_once('popup_js.php');
# Check responder ID
if (!(ResponderExists($Responder_ID))) { admin_redirect(); }
# Action processing
if ($action == "create") {
# Init vars
$DB_absDay = "";
$DB_absHours = 0;
$DB_absMins = 0;
# Display template
include('templates/create.messages.php');
}
elseif ($action == "update") {
GetMsgInfo($M_ID);
# Do the math
$T_minutes = intval($DB_MsgSeconds / 60);
$T_seconds = $DB_MsgSeconds - ($T_minutes * 60);
$T_hours = intval($T_minutes / 60);
$T_minutes = $T_minutes - ($T_hours * 60);
$T_days = intval($T_hours / 24);
$T_hours = $T_hours - ($T_days * 24);
$T_weeks = intval($T_days / 7);
$T_days = $T_days - ($T_weeks * 7);
$T_months = $DB_MsgMonths;
# Select the correct absDay
if ($DB_absDay == "Sunday") {
$absday['Sunday'] = " SELECTED";
} else {
$absday['Sunday'] = "";
}
if ($DB_absDay == "Monday") {
$absday['Monday'] = " SELECTED";
} else {
$absday['Monday'] = "";
}
if ($DB_absDay == "Tuesday") {
$absday['Tuesday'] = " SELECTED";
} else {
$absday['Tuesday'] = "";
}
if ($DB_absDay == "Wednesday") {
$absday['Wednesday'] = " SELECTED";
} else {
$absday['Wednesday'] = "";
}
if ($DB_absDay == "Thursday") {
$absday['Thursday'] = " SELECTED";
} else {
$absday['Thursday'] = "";
}
if ($DB_absDay == "Friday") {
$absday['Friday'] = " SELECTED";
} else {
$absday['Friday'] = "";
}
if ($DB_absDay == "Saturday") {
$absday['Saturday'] = " SELECTED";
} else {
$absday['Saturday'] = "";
}
# Debug info
# print " MsgID $DB_MsgID<br>\n";
# print " MsgSub $DB_MsgSub<br>\n";
# print " MsgSec $DB_MsgSeconds<br>\n";
# print " Months $DB_MsgMonths<br>\n";
# print " AbsDay $DB_absDay<br>\n";
# print " AbsMin $DB_absMins<br>\n";
# print " AbsHour $DB_absHours<br>\n";
# print " MsgBody $DB_MsgBodyText<br>\n";
# print " MsgHTML $DB_MsgBodyHTML<br>\n";
# Display template
include('templates/update.messages.php');
}
elseif ($action == "delete") {
GetMsgInfo($M_ID);
# gmp_mod and fmod aren't working on my host for some reason. :-(
$T_minutes = intval($DB_MsgSeconds / 60);
$T_seconds = $DB_MsgSeconds - ($T_minutes * 60);
$T_hours = intval($T_minutes / 60);
$T_minutes = $T_minutes - ($T_hours * 60);
$T_days = intval($T_hours / 24);
$T_hours = $T_hours - ($T_days * 24);
$T_weeks = intval($T_days / 7);
$T_days = $T_days - ($T_weeks * 7);
$T_months = $DB_MsgMonths;
# Display template
include('templates/delete.messages.php');
}
elseif ($action == "do_create") {
# Prep data
$P_subj = MakeSemiSafe($_REQUEST['subj']);
$P_bodytext = MakeSemiSafe($_REQUEST['bodytext']);
$P_bodyhtml = MakeSemiSafe($_REQUEST['bodyhtml']);
$P_months = MakeSafe($_REQUEST['months']);
$P_weeks = MakeSafe($_REQUEST['weeks']);
$P_days = MakeSafe($_REQUEST['days']);
$P_hours = MakeSafe($_REQUEST['hours']);
$P_min = MakeSafe($_REQUEST['min']);
$P_absday = MakeSafe($_REQUEST['abs_day']);
$P_abshours = MakeSafe($_REQUEST['abs_hours']);
$P_absmin = MakeSafe($_REQUEST['abs_min']);
if (!(is_numeric($P_months))) { $P_months = 0; }
if (!(is_numeric($P_weeks))) { $P_weeks = 0; }
if (!(is_numeric($P_days))) { $P_days = 0; }
if (!(is_numeric($P_hours))) { $P_hours = 0; }
if (!(is_numeric($P_min))) { $P_min = 0; }
if (!(is_numeric($P_abshours))) { $P_abshours = 0; }
if (!(is_numeric($P_absmin))) { $P_absmin = 0; }
if (($P_absday != "Monday") && ($P_absday != "Tuesday") && ($P_absday != "Wednesday") && ($P_absday != "Thursday") && ($P_absday != "Friday") && ($P_absday != "Saturday") && ($P_absday != "Sunday")) {
$P_absday = "";
}
GetResponderInfo();
$TempDay_Seconds = (($P_weeks * 7) + $P_days) * 86400;
$TempHour_Seconds = 3600 * $P_hours;
$TempMin_Seconds = 60 * $P_min;
$Time_stamp = $TempDay_Seconds + $TempHour_Seconds + $TempMin_Seconds;
# Add row to database
$query = "INSERT INTO InfResp_messages (Subject, SecMinHoursDays, Months, absDay, absMins, absHours, BodyText, BodyHTML)
VALUES('$P_subj', '$Time_stamp', '$P_months', '$P_absday', '$P_absmin', '$P_abshours', '$P_bodytext', '$P_bodyhtml')";
$DB_result = mysql_query($query)
or die("Invalid query: " . mysql_error());
# Clear $M_ID. If the query was successful then get the new $M_ID and
# and attach it to the end of the Responder's message list.
$M_ID = 0;
if (mysql_affected_rows()>0) {
$M_ID=mysql_insert_id();
$Update_MsgList = $DB_MsgList.",".$M_ID;
$Update_MsgList = trim($Update_MsgList, ",");
}
# Update Responder MsgList with new list string.
$query = "UPDATE InfResp_responders
SET MsgList = '$Update_MsgList'
WHERE ResponderID = '$Responder_ID'";
$DB_result = mysql_query($query)
or die("Invalid query: " . mysql_error());
# Done!
print "<H3 style=\"color : #003300\">Message added!</H3> \n";
print "<font size=4 color=\"#660000\">Return to list. <br></font> \n";
# Print back button
$return_action = "update";
include('templates/back_button.messages.php');
}
elseif ($action == "do_update") {
# Prep the data
$P_subj = MakeSemiSafe($_REQUEST['subj']);
$P_bodytext = MakeSemiSafe($_REQUEST['bodytext']);
$P_bodyhtml = MakeSemiSafe($_REQUEST['bodyhtml']);
$P_months = MakeSafe($_REQUEST['months']);
$P_weeks = MakeSafe($_REQUEST['weeks']);
$P_days = MakeSafe($_REQUEST['days']);
$P_hours = MakeSafe($_REQUEST['hours']);
$P_min = MakeSafe($_REQUEST['min']);
$P_absday = MakeSafe($_REQUEST['abs_day']);
$P_abshours = MakeSafe($_REQUEST['abs_hours']);
$P_absmin = MakeSafe($_REQUEST['abs_min']);
if (!(is_numeric($P_months))) { $P_months = 0; }
if (!(is_numeric($P_weeks))) { $P_weeks = 0; }
if (!(is_numeric($P_days))) { $P_days = 0; }
if (!(is_numeric($P_hours))) { $P_hours = 0; }
if (!(is_numeric($P_min))) { $P_min = 0; }
if (!(is_numeric($P_abshours))) { $P_abshours = 0; }
if (!(is_numeric($P_absmin))) { $P_absmin = 0; }
if (($P_absday != "Monday") && ($P_absday != "Tuesday") && ($P_absday != "Wednesday") && ($P_absday != "Thursday") && ($P_absday != "Friday") && ($P_absday != "Saturday") && ($P_absday != "Sunday")) {
$P_absday = "";
}
$TempDay_Seconds = (($P_weeks * 7) + $P_days) * 86400;
$TempHour_Seconds = 3600 * $P_hours;
$TempMin_Seconds = 60 * $P_min;
$Time_stamp = $TempDay_Seconds + $TempHour_Seconds + $TempMin_Seconds;
#print "M_ID: $M_ID <br>\n";
#print "P_subj: $P_subj <br>\n";
#print "P_bodytext: $P_bodytext <br>\n";
#print "P_bodyhtml: $P_bodyhtml <br>\n";
#print "P_months: $P_months <br>\n";
#print "P_weeks: $P_weeks <br>\n";
#print "P_days: $P_days <br>\n";
#print "P_hours: $P_hours <br>\n";
#print "P_min: $P_min <br>\n";
#print "Time: $Time_stamp <br>\n";
#print "Abs day: " . $P_absday . "<br>\n";
#print "Abs min: " . $P_absmin . "<br>\n";
#print "Abs hour: " . $P_abshours . "<br>\n";
# subject, body text, body html, timestamp, months
$query = "UPDATE InfResp_messages
SET Subject = '$P_subj',
SecMinHoursDays = '$Time_stamp',
Months = '$P_months',
absDay = '$P_absday',
absMins = '$P_absmin',
absHours = '$P_abshours',
BodyText = '$P_bodytext',
BodyHTML = '$P_bodyhtml'
WHERE MsgID = '$M_ID'";
$DB_result = mysql_query($query)
or die("Invalid query: " . mysql_error());
# Done!
print "<H3 style=\"color : #003300\">Message Saved!</H3> \n";
print "<font size=4 color=\"#660000\">Return to list. <br></font> \n";
# Print back button
$return_action = "update";
include('templates/back_button.messages.php');
}
elseif ($action == "do_delete") {
if (!(ResponderExists($Responder_ID)))
{ die("Responder $Responder_ID does not exist"); }
GetResponderInfo();
$NewList = "";
$MsgList_Array=explode(',',$DB_MsgList);
$Max_Index = sizeof($MsgList_Array);
for ($i=0; $i<=$Max_Index-1; $i++) {
$Temp_ID = trim($MsgList_Array[$i]);
if ($Temp_ID != $M_ID) {
$NewList = $NewList.",".$Temp_ID;
}
}
$NewList = trim($NewList, ",");
$query = "DELETE FROM InfResp_messages WHERE MsgID = '$M_ID'";
$DB_result = mysql_query($query)
or die("Invalid query: " . mysql_error());
$query = "UPDATE InfResp_responders SET MsgList = '$NewList' WHERE ResponderID = '$Responder_ID'";
$DB_result = mysql_query($query)
or die("Invalid query: " . mysql_error());
# Done!
print "<H3 style=\"color : #003300\">Message deleted!</H3> \n";
print "<font size=4 color=\"#660000\">Return to list. <br></font> \n";
# Print back button
$return_action = "update";
include('templates/back_button.messages.php');
}
else {
print "<br> \n";
print "I'm sorry, I didn't understand your 'action' variable. Please try again. <br> \n";
}
# Template bottom
copyright();
include('templates/close.page.php');
}
else {
admin_redirect();
}
DB_disconnect();
?>