PHP Code
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function wrapText(el, openTag, closeTag) {
if (el.setSelectionRange) {
// W3C/Mozilla
el.value = el.value.substring(0,el.selectionStart) + openTag + el.value.substring(el.selectionStart,el.selectionEnd) + closeTag + el.value.substring(el.selectionEnd,el.value.length);
}
else if (document.selection && document.selection.createRange) {
// IE code goes here
el.focus(); //or else text is added to the activating control
var range = document.selection.createRange();
range.text = openTag + range.text + closeTag;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
session_start(); //Start session
if(!$logged[id]){ //Check if user is logged in
header("Location: index.php?page=home&i=6");
}else{ //Their loggedin
switch($_GET[act]){ //make some links ?page=case
default: //set up the default page upon going to pms.php
$msgs = mysql_query("SELECT * FROM `privates` WHERE `to` = '" . $logged[username] . "' ORDER BY `pid` ASC") or die(mysql_error()); //get all the messages to the loged in user
echo "<div align='left'><font size='4'><strong>Private Messages</strong></font>
</div>
</div>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='21' align='left' class='row1' scope='col'>Page Location » Private Messages » In Box</td>
</tr>
</table>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' cellpadding='2' cellspacing='1' class='box'>
<tr>
<td height='18' align='left' class='row2' scope='col'>Options</td>
</tr>
<tr>
<td height='20' align='left' class='row1' scope='col'><a href=\"?page=pms&act=compose\">» Compose Message</a></td>
</tr>
<tr>
<td height='20' align='left' class='row1' scope='col'><a href=\"?page=pms&act=delall\"> » Delete All Messages</a></td>
</tr>
</table>"; //echo the start5 table and create msg link/delete all links!
if(mysql_num_rows($msgs) == 0){ //check if there are messages or not
echo "<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='18' colspan='5' align='left' class='row2' scope='col'>In Box</td>
</tr>
<tr>
<td width='266' height='15' class='row3' scope='col'><div align='center'>Subject </div></td>
<td width='266' class='row3' scope='col'><div align='center'>From</div></td>
<td width='479' class='row3' scope='col'><div align='center'>Date</div></td>
<td width='266' class='row3' scope='col'><div align='center'>Status</div></td>
<th width='124' class='row3' scope='col'></th>
</tr>
<tr>
<td height='18' colspan='5' align='left' class='row1' scope='col'>You Have No New Messages!</td>
</tr>
</table>
<table width='100%' cellpadding=\'0\' cellspacing=\'0\'>
<tr>
<td align=\'center\' valign=\'middle\' width='100%'>"; //no new messages
}else{ //or if there are messages
echo "<table width='101%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>";
echo "<table width='100%' border='0' cellpadding='3' cellspacing='1'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='18' colspan='5' align='left' class='row2' scope='col'>In Box</td>
</tr>
<tr>
<td width='266' height='15' class='row3' scope='col'><div align='center'>Subject </div></td>
<td width='266' class='row3' scope='col'><div align='center'>From</div></td>
<td width='479' class='row3' scope='col'><div align='center'>Date</div></td>
<td width='266' class='row3' scope='col'><div align='center'>Status</div></td>
<th width='124' class='row3' scope='col'></th>
</tr>";
while($r = mysql_fetch_array($msgs)){ //repeat for all the messages
echo "<tr>
<td align='center' class='row1' scope='col'><a href=\"?page=pms&act=view&id=$r[pid]\">$r[subject]</a></td>
<td align='center' class='row1' scope='col'><a href=\"members.php?user=$r[from]\"><a href=\"members.php?user=$r[from]\">$r[from]</a></td>
<td align='center' class='row1' scope='col'>$r[date]</td>
<td align='center' class='row1' scope='col'>$r[status]</td>
<td align='center' class='row1' scope='col'><a href=\"?page=pms&act=delete&id=$r[pid]\"><img src='images/Icons/delete.png'></a></td>
</tr>"; //echo the messages
} //end while
} //end message amount check echo
echo "</table>"; //end table
error_reporting(E_ALL);
$MyMessages = mysql_query("SELECT * FROM `privates` WHERE `to` = '$logged[username]' AND `status` = 'unread';");
//shows the user menu
$MyMessages = mysql_num_rows($MyMessages);
echo "
<table width='100%' border='0' cellpadding='0' cellspacing='0'>
<tr>
<td height='10' align='left' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' cellpadding='0' cellspacing='0' class='box'>
<tr>
<td height='22' align='left' class='row1' scope='col'> You have $MyMessages new message.</td>
</tr>
</table>
";
break; //end the default page
case 'view': //define the view page
$id = (int)htmlspecialchars(strip_tags($_GET[id])); //make the ID safe
if(!$id){ //if there is no ID to select
$bbmsg = BBCODE($message);
header("Location: index.php?page=pms&i=19");
}else{ //or if there is....
$select = mysql_query("SELECT * FROM `privates` WHERE `pid` = '" . $id . "';"); //get the message's info
$msg = mysql_fetch_array($select); //select all data
if($msg[to] != $logged[username]){ //check if the user logged in is the owner of the message
header("Location: index.php?page=pms&i=20");
}else{ //maybe...
if(!$_POST[reply]) { //if the reply was not submitted
$mark = mysql_query("UPDATE `privates` SET `status` = 'Read' WHERE `pid` = '" . $id . "'") or die(mysql_error()); //mark it as Read
$message = nl2br(stripslashes($msg[content])); //make new lines to and strip the slashes
$subject = stripslashes($msg[subject]); //strip the slashes
$date = date("F j, Y, g:i a"); //the date sent
echo"<div align='left'><font size='4'><strong>Private Messages</strong></font>
</div>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='21' align='left' class='row1' scope='col'>Page Location » Private Messages » Viewing Messages</td>
</tr>
</table>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'>
<form method=\"post\">
<table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='18' colspan='3' align='left' class='row2' scope='col'> <IMG height='6' src='images/bullet.gif' width='4'> <span class='forum_text'>$subject</span></td>
</tr>
<tr>
<td width='24%' height='12' align='left' class='row3' scope='col'>$msg[from]</td>
<td colspan='2' align='left' class='row3' scope='col'><div align='right'>$date </div></td>
</tr>
<tr>
<td height='16' align='left' class='row1' scope='col'>";{
if ($user[userlevel] == 6)
{
echo ("<img src=\"images/titles/icon4.bmp\">");
}
elseif ($user[userlevel] == 4)
{
echo ("<img src=\"images/titles/icon1.bmp\">");
}
else
{
echo ("<img src=\"images/titles/icon5.bmp\">");
}
}
echo "</td>
<td width='65%' align='left' class='row1' scope='col'> $message</td>
<td width='11%' align='left' class='row1' scope='col'></td>
</tr>
<tr>
<td height='10' align='left' class='row1' scope='col'></td>
<td align='left' class='row1' scope='col'></td>
<td align='left' class='row1' scope='col'></td>
</tr>
</table>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='18' colspan='3' align='left' class='row2' scope='col'>Add Reply</td>
</tr>
<tr>
<td colspan='3' align='right' class='row3' scope='col'><a href='?page=bbcode'>BB Code Help?</a></td>
</tr>
<tr>
<td width='23%' align='left' valign='bottom' class='row1' scope='col'><div align='left'><font size='1'>
<div align='center'>$emotion</div>
</div>
<div align='left'><font size='1'> BBcode<FONT COLOR='green'> » Enabled </font></div>
<div align='left'><font size='1'> Smileys<FONT COLOR='green'> » Enabled </font></div></td>
<td width='77%' colspan='2' align='left' class='row1' scope='col'><center>$tags</center>
<center>
<textarea id=\"TheTextArea\" name=\"msg\"2 cols=\"45\" rows=\"6\" class='input'></textarea></td>
</tr>
<tr>
<td colspan='3' align='left' class='row1' scope='col'><input name=\"reply\" type=\"submit\" class='boxbutton' value=\"Reply\"></td>
</tr>
</table>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='21' align='left' class='row1' scope='col'><a href='index.php?page=pms'>Go Back?</a></td>
</tr>
</table>
</form ></td>
</tr>
</table>"; //echo the message and reply box.
}else{ //if the form was submitted
$to = $msg[from]; //get who it is to
$from = $logged[username]; //who its from
$subject = "RE: " . $msg[subject]; //new subject
$msg = addslashes($_POST[msg]); //the content
$date = date("F j, Y, g:i a"); //the date sent
$do = mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!
header("Location: index.php?page=pms&i=21");
} //end reply check
} //end check posession
} //end id check
break;
case 'compose': //create a new message
echo "<div align='left'><font size='4'><strong>Private Messages</strong></font>
</div>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='21' align='left' class='row1' scope='col'>Page Location » Private Messages » Compose Message</td>
</tr>
</table>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>
<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>
</table>";
echo " <table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='box'>";
if(!$_POST[send]){ //if the form was not submitted
echo "<form method=\"post\" action=\"\">
<tr>
<td height='20' colspan='2' align='left' class='row2' scope='row'>Compose Message.</td>
</tr>"; //echo some of the form and whatnot
if(isset($_GET[user])){ //check if there is a user in the address bar
echo "<tr>
<td colspan='2' align='left' class='row1' scope='row'>» To User
<input class='input' type=\"text\" name=\"to\" value=\"$_GET[user]\" size=\"15\">
<span class='imp'>* Provided </span></td>
</tr>";
}else{ //or not..
echo "<tr>
<td colspan='2' align='left' class='row1' scope='row'>» To User
<input class='input' type=\"text\" name=\"to\" size=\"15\">
<span class='imp'>* Required </span></td>
</tr>"; //echo the input box without the value of the user!
} //end user check in address bar
echo "<form>
<tr>
<td width='17%' align='left' class='row1' scope='col'>» Subject:</td>
<td width='83%' align='left' class='row1' scope='col'>
<input name=\"title\" type=\"text\" class='input' value=\"Unitiled Message\" size=\"15\" Message\> </td>
</tr>
<tr>
<td width='22%' align='left' class='row1' scope='row'>» Content</td>
<td width='83%' align='left' class='row1' scope='row'><div align='right'><a href='?page=bbcode'>BB Code Help?</a></div></td>
</tr>
<tr>
<td width='17%' valign='bottom' class='row1' scope='col'><div align='left'><font size='1'>
<div align='center'>$emotion</div>
</div>
<div align='left'><font size='1'><FONT COLOR='green'><A href='?page=bbcode'>BBcode</A> » Enabled </font></div>
<div align='left'><font size='1'><FONT COLOR='green'><A href='?page=bbcode'>Smileys</A> » Enabled </font></div></td>
<td width='83%' class='row1' scope='col'><center>
$tags
<textarea id=\"TheTextArea\" name=\"message\" cols=\"45\" rows=\"6\" class='input'></textarea>
<br><div style='padding-left: 5px; padding-top:5px;'>
</tr>
<tr>
<td colspan='2' align='left' class='row1' scope='row'><input name=\"send\" type=\"submit\" class='boxbutton' value=\"Send Message\"> </td>
</tr>
</form>"; //echo the rest of the form
echo "<table width='99%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr>
<td height='5' scope='col'></td>
</tr>";
echo "<table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='box'>
<tr>
<td height='21' align='left' class='row1' scope='col'><a href='index.php?page=pms'>Go Back?</a></td>
</tr>";
echo "</table>";
}else{ //or if it was..
echo "</table>";
echo "</table>";
echo "</table>";
$to = stripslashes(htmlspecialchars(strip_tags($_POST[to]))); //who its to
$from = $logged[username]; //who its from
$date = date("F j, Y, g:i a"); //the date sent
$msg = addslashes($_POST[message]); //the message variable
$subject = addslashes($_POST[title]); //the subject
$do = mysql_query("INSERT INTO `privates` (`to`,`from`,`date`,`subject`,`content`) VALUES ('" . $to . "','" . $from . "','" . $date . "','" . $subject . "','" . $msg . "')") or die(mysql_error()); //insert into the table!
header("Location: index.php?page=pms&i=21");
} //end sent check
break; //end make new msg
case 'delall': //delete all page
$get = mysql_query("SELECT * FROM `privates` WHERE `to` = '" . $logged[username] . "'"); //get the private messages
if(mysql_num_rows($get) == "0"){
header("Location: index.php?page=pms&i=23");
}else{
$delete = mysql_query("DELETE FROM `privates` WHERE `to` = '" . $logged[username] . "'"); //delete tehm
if($delete) { //check if theres a mySQL error
header("Location: index.php?page=pms&i=22"); //success
}else{ //or not
header("Location: index.php?page=pms&i=24");
} //end error check
} //end msg check
break; //end page
case 'delete': //start the delete page!
$id = (int)htmlspecialchars(strip_tags($_GET[id])); //make the ID safe
if(!$id){ //if there is no ID to select
echo "<a href=\"?page=pms\">Go Back</a>No ID Selected!"; //echo the error
}else{ //or if there is....
$select = mysql_query("SELECT * FROM `privates` WHERE `pid` = '" . $id . "'"); //get the message's info
$msg = mysql_fetch_array($select); //select all data
if($msg[to] != $logged[username]){ //check if the user logged in is the owner of the message
header("Location: index.php?page=pms&i=20"); //if not
}else{ //maybe...
$do = mysql_query("DELETE FROM `privates` WHERE `pid` = '" . $id . "'") or die(mysql_error());
header("Location: index.php?page=pms&i=25");
} //end check possession
} //end id check
break; //end the delete page!
} //end switch/get
} //end login check
?>
</body>
</html>