-
Notifications
You must be signed in to change notification settings - Fork 1
/
messaging.php
400 lines (395 loc) · 17.7 KB
/
messaging.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
<?
$title="Private Messages";
include ("members/config.php");
checks();
online();
include ("BBCode.php");
include ("members/striphtml.php");
$res=$mysqli->query("SELECT lmessage, username, avatar FROM Players WHERE id='$_COOKIE[id]' LIMIT 1;");
$row=$res->fetch_array();
$lastmessage = $row[0];
$nmessage = (time() + 30);
$countdown = ($lastmessage - time());
$user = $row[1];
require_once("members/header.php");
// If the user is sending a message...
if (isset($_POST['to'])) {
$subject = htmlspecialchars(addslashes("$_POST[subject]"));
if ($subject == NULL) {
$subject = 'No Subject';
}
if (strlen(stripslashes(trim($subject))) < 1) {
echo "<div class=\"alert alert-danger\"><span class=\"label label-important\">Error</span> You must have at least one character in the title of your message, other than a space.</div>";
exit();
}
$message = stripHTML(addslashes($_POST['message']));
if ($message == NULL) {
echo "<div class=\"alert alert-danger\"><span class=\"label label-important\">Error</span> You must enter a message.</div>";
echo var_dump($_POST);
exit();
}
$to = htmlspecialchars(addslashes("$_POST[to]"));
$query=$mysqli->query("SELECT id FROM Players WHERE username = '$to' LIMIT 1");
$row=$query->fetch_array();
$to = $row[0];
if ($to == NULL){
echo("<div class=\"alert alert-danger\"><span class=\"label label-important\">Error</span> You left the username field blank!</div>");
exit();
}
$block=$mysqli->query("SELECT * FROM blocklist WHERE block='$user' AND username='$to' LIMIT 1;");
if ($block->num_rows > 0) {
echo "<div class=\"alert alert-danger\"><span class=\"label label-danger\">Error</span> $to has you on their block list, so you are unable to send them a message.</div>";
exit();
}
if (time() <= $lastmessage) {
echo "<div class=\"alert alert-danger\"><span class=\"label label-danger\">Error</span> You have already sent a message in the last 30 seconds! Try again in $countdown seconds!</div>";
exit();
}
$mysqli->query("UPDATE Players SET lmessage='$nmessage' WHERE id='$_COOKIE[id]' LIMIT 1;");
$mysqli->query("INSERT INTO `pmessages` (`title`, `message`, `touser`, `from`, `unread`, `date`, `reply`) VALUES ('$subject', '$message', '$to', '$_COOKIE[id]', 'unread', '$date', 'no')");
echo "<div class=\"alert alert-success\"><span class=\"label label-success\">Success</span> Your message has been sent.</div>";
}
$res=$mysqli->query("SELECT lmessage, username, avatar FROM Players WHERE id='$_COOKIE[id]' LIMIT 1;");
$row=$res->fetch_array();
$lastmessage = $row[0];
$nmessage = (time() + 30);
$countdown = ($lastmessage - time());
$user = $row[1];
switch($_GET['page']) {
default:
if(isset($_GET['outbox'])) {
$get=$mysqli->query("SELECT * from pmessages where `from` = $_COOKIE[id] AND `cleared` IS NULL order by id desc");
$nummessages = $get->num_rows;
} else {
$get=$mysqli->query("SELECT * from pmessages where `touser` = $_COOKIE[id] order by id desc");
$nummessages = $get->num_rows;
}
$deletingrows = ($nummessages - 30);
?>
<header>
<?
echo '
<script type="text/javascript">
$(document).ready(function() {
$("#sendBtn").click(function() {
setTimeout(function() {
if($(\'#recipient\').val() == \'\' || $(\'#subject\').val() == \'\') {
$(".modal-body").prepend(\'<div class="alert alert-danger"><span class="label label-important">Error</span> You must enter a recipient and a subject</div>\');
return false;
} else if ($(\'#area1\').val() == \'\' || $(\'#area1\').val() == \'<br />\') {
$(".modal-body").prepend(\'<div class="alert alert-danger"><span class="label label-important">Error</span> The message content cannot be blank</div>\');
return false;
}
$("#sendMsgForm").submit();
$.ajax({
url: "messaging.php",
data: {\'to\':$("#recipient").val(),\'subject\':$("#subject").val(),\'message\':$("$area1").val()},
type: "POST",
async: false,
success: function(html){
$(".modal").modal("hide");
$(".page-header").after(html);
}
});
}, 100);
});
$("#checkAll").click(function () {
$(".well input:checkbox").attr(\'checked\', \'checked\');
});
$("#removeAll").click(function () {
$(".well input:checkbox").removeAttr(\'checked\');
});
});
</script>';
echo "<div class=\"page-header\" id=\"messageHead\">
<h1>Messaging <small>"; if(isset($_GET['outbox'])) { echo "Outbox"; } else { echo "Inbox"; } echo "</small></h1>
</div>
<form id='form_id' name='myform' action=\"messaging.php?page=deletemultiple\" method=\"post\">
<div class=\"btn-toolbar\">
<div class=\"btn-group\">";
if(isset($_GET['outbox'])) {
echo "<a class=\"btn\" href=\"messaging.php\"><i class=\"icon-inbox\"></i> Inbox</a>";
} else {
echo "<a class=\"btn\" href=\"messaging.php?outbox=true\"><i class=\"icon-inbox\"></i> Outbox</a>";
}
echo "<a href=\"#sendMessage\" role=\"button\" class=\"btn sendMsg\" data-toggle=\"modal\"><i class=\"icon-envelope\"></i> New Message</a>
</div>
<div class=\"btn-group\">
<button type=\"button\" name=\"Submit\" id=\"checkAll\" class=\"btn\"\"><i class=\"icon-plus\"></i> Check All</button>
<button type=\"button\" name=\"Submit\" id=\"removeAll\" class=\"btn\"\"><i class=\"icon-minus\"></i> Uncheck All</button>
<button type=\"submit\" name=\"deletem\" class=\"btn\" value=\"Delete Selected\"><i class=\"icon-trash\"></i> Delete Selected</button>
</div>
</div>
<div class=\"well\">
<table class=\"table table-striped table-bordered\">
<thead><tr>
<th width=\"5\">Select</th>
<th>Subject</b></th>
<th>From</b></th>
<th>Date</th>
<th>Delete</th>
</tr></thead><tbody>";
if ($nummessages == 0) {
echo ("<tr><td colspan=\"5\"><strong>You have no messages.</strong></td></tr></tbody></table></div>");
} else {
while ($messages = $get->fetch_array()) {
if ($messages['unread'] == 'unread'){
echo "<tr class=\"info\">
<td><input name=\"checkbox[]\" type=\"checkbox\" value=\"$messages[id]\"></td>
<td><a href=\"messaging.php?page=view&msgid=$messages[id]\"><i class=\"icon-asterisk\"></i> ";
} else {
echo "<tr>
<td><input name=\"checkbox[]\" type=\"checkbox\" value=\"$messages[id]\"></td>
<td><a href=\"messaging.php?page=view&msgid=$messages[id]\">";
}
if ($messages['reply'] == 'yes') {
echo "<i class=\"icon-share-alt\"></i>";
}
echo ("$messages[title]</a></td></font>");
$result=$mysqli->query("SELECT `username` FROM Players WHERE id ='$messages[from]' LIMIT 1;");
$usern = $result->fetch_assoc();
if (($result->num_rows > 0) AND $messages['from'] != 'Global Takeover') {
echo "<td><a href=\"profile.php?id=$messages[from]\">$usern[username]</a></td>";
} elseif (($result->num_rows== 0) OR $usern['username'] == 'Global Takeover') {
echo "<td>$messages[from]</td>";
}
if(!isset($_GET['outbox'])) {
echo "<td>$messages[date]</td><td><a href=\"messaging.php?page=delete&msgid=$messages[id]\">Delete</a></td></tr>";
} else {
echo "<td>$messages[date]</td><td><a href=\"messaging.php?page=delete&msgid=$messages[id]&outbox=true\">Delete</a></td></tr>";
}
}
echo "</table></div></form><h5>$nummessages of 30 messages in your ";
if(!isset($_GET['outbox'])) { echo "inbox"; } else { echo "outbox"; } echo "</h5>";
if ($nummessages > 30 AND !isset($_GET['outbox'])) {
$mysqli->query("DELETE FROM pmessages WHERE touser = '$user' ORDER BY id ASC LIMIT $deletingrows;");
}
}
if (!isset($_POST['send'])) {
$recipient = isset($_GET["recipient"]) ? trim($_GET["recipient"]) : "";
echo "
<div class=\"modal hide\" id=\"sendMessage\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"sendMessageLabel\" aria-hidden=\"true\">
<div class=\"modal-header\">
<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>
<h3 id=\"sendMessageLabel\">Send New Message</h3>
</div>
<div class=\"modal-body\">
<label for=\"recipient\">Recipient</label>
<form method=\"POST\" id=\"sendMsgForm\">
<input autocomplete=\"off\" type=\"text\" id=\"recipient\" name=\"to\" class=\"span12\" style=\"margin: 0 auto;\" data-provide=\"typeahead\" data-items=\"4\" data-source=\"";
$res=$mysqli->query("SELECT username FROM Players WHERE `dead` = '0' AND `banned` = '0' ORDER BY username ASC");
$users='[';
while($row=$res->fetch_assoc()) {
$users.=""".$row['username']."",";
}
$users=substr($users,0,-1);
$users.="]";
echo $users."\">
<label for=\"subject\">Subject</label>
<script>$(document).ready(function() { $('.typeahead').typeahead(); });</script>
<input type=\"text\" id=\"subject\" name=\"subject\" class=\"span12\">
<label for=\"message\">Message</label>
<textarea rows=\"10\" id=\"area1\" name=\"message\" class=\"span12\"></textarea>
</div>
<div class=\"modal-footer\">
<a id=\"sendBtn\" class=\"btn btn-success\" href=\"#\"><i class=\"icon-ok icon-white\"></i> Send</a>
<button class=\"btn btn-warning\" data-dismiss=\"modal\" aria-hidden=\"true\">Cancel</button>
</div>
</div>
</div>";
require_once("members/footer.php");
}
break;
case 'delete':
if (!$_GET['msgid']) {
echo "<div id=\"crimestext\" align=\"center\">Sorry, but this message is invalid.<br /><a href=\"messaging.php\">Go back.</a></div>";
require_once("members/footer.php");
exit();
} else {
$getmsg=$mysqli->query("SELECT * from pmessages where id = '$_GET[msgid]' LIMIT 1;");
$msg=$getmsg->fetch_assoc();
if ($msg['touser'] != $_COOKIE['id']) {
echo "<div id=\"crimestext\" align=\"center\">This message was not sent to you, so you cannot delete it.<br /><a href=\"messaging.php\">Go back.</a></div>";
require_once("members/footer.php");
exit();
} else {
if(!isset($_GET['outbox'])) {
$mysqli->query("DELETE FROM pmessages WHERE id = '$_GET[msgid]' LIMIT 1");
} else {
$mysqli->query("UPDATE `pmessages` SET `cleared` = 1 WHERE id = '$_GET[msgid]' LIMIT 1");
}
echo "<head><meta HTTP-EQUIV=\"REFRESH\" content=\"2; url=messaging.php\"></head>
<div class=\"alert alert-success\"><span class=\"label label-success\">Success</span> The message has been deleted. Redirecting...</div>";
require_once("members/footer.php");
exit();
}
}
break;
case 'deletemultiple':
$a = $_POST['checkbox'];
if($a == NULL){
echo"<div align=\"center\" id='crimestext'>You didn't select any messages!<br /><a href=\"messaging.php\">Go back</a></div>";
require_once("members/footer.php");
exit();
}
if ($_REQUEST['deletem']) {
$vs = 0;
foreach ($a as $id) {
$getmsg=$mysqli->query("SELECT * from pmessages where id='$id' LIMIT 1;");
$msg=$getmsg->fetch_assoc();;
if ($msg['touser'] != $_COOKIE['id']) {
echo "<div id=\"crimestext\" align=\"center\">This message was not sent to you, so you cannot delete it.<br /><a href=\"messaging.php\">Go back.</a></div>";
require_once("members/footer.php");
exit();
} else {
if(isset($_GET['outbox'])) {
$mysqli->query("UPDATE `pmessages` SET `cleared` = 1 where id='$id' LIMIT 1;");
} else {
$mysqli->query("DELETE FROM pmessages where id='$id' LIMIT 1;");
}
$vs=($vs+1);
}
}
echo "<head><meta HTTP-EQUIV=\"REFRESH\" content=\"2; url=messaging.php\"></head>
<div class=\"alert alert-success\"><span class=\"label label-success\">Success</span> Successfully deleted $vs messages. Redirecting...</div>";
require_once("members/footer.php");
exit();
}
break;
case 'view':
if (!$_GET['msgid']) {
echo "<div id=\"crimestext\" align=\"center\">Invalid message!<br /><a href=\"messaging.php\">Go back.</a></div>";
require_once("members/footer.php");
exit();
} else {
$getmsg=$mysqli->query("SELECT * FROM pmessages WHERE id = '$_GET[msgid]' LIMIT 1;");
$msg=$getmsg->fetch_assoc();
if ($msg['touser'] == $_COOKIE['id']) {
if (!$_POST['message']) {
$markread=$mysqli->query("UPDATE pmessages SET unread = 'read' WHERE id = '$_GET[msgid]' LIMIT 1;");
$Text=(stripslashes("$msg[message]"));
$message=BBcode($Text);
$result=$mysqli->query("SELECT username, avatar FROM Players WHERE id='$msg[from]' LIMIT 1;");
$user=$result->fetch_assoc();
$avatar=$user['avatar'];
if ($avatar != NULL AND $result->num_rows > 0) {
$av = "<img src=\"$avatar\" height=\"80px\ width=\"80px\" />";
} else {
$av = "<img src=\"images/noavatar.png\" height=\"80px\ width=\"80px\" />";
}
echo '<script type="text/javascript" src="members/nicEdit.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".replyMsg").click(function() {
setTimeout(function() {
var niceditor = new nicEditor();
var niceditorpanel = new nicEditor({
iconsPath : \'members/nicEditorIcons.gif\',
buttonList : [\'bold\',\'italic\',\'underline\',\'strikethrough\',\'removeformat\',\'image\',\'link\',\'unlink\',\'forecolor\'],
bbCode : false,
xhtml : true
}).panelInstance(\'area1\');
niceditorpanel.nicInstances[0].setContent(niceditorpanel.nicInstances[0].getContent())
}, 100);
});
});
</script>';
echo "<div class=\"page-header\">
<h1>Messages <small>$msg[title]</small></h1>
</div>
<ul class=\"breadcrumb\">
<li>
<a href=\"messaging.php\">Messaging</a> <span class=\"divider\">/</span>
</li>
<li class=\"active\">$msg[title]</li>
</ul>
<div class=\"well\">";
?>
<table class="table table-bordered table-striped">
<tr>
<td rowspan="2" align="center" width="10%"><? echo("$av"); ?>
<br><strong>
<?
if ($msg['from'] != 'Global Takeover' AND $msg['from'] != 'Help Desk') {
echo "<a href=\"profile.php?id=$msg[from]\"> $user[username]</a>";
} else {
echo $msg['from'];
}
?>
</strong></td>
<td width="90%" height="1%"><span style="float:left;">Sent: <? echo "$msg[date]"; ?></span>
<span style="float:right;">
<div class="btn-group">
<a href="#replyMessage" role="button" class="btn btn-small replyMsg" data-toggle="modal"><i class="icon-share-alt"></i> Reply</a>
<a class="btn btn-small" href="<? echo "messaging.php?page=delete&msgid=$_GET[msgid]"; ?>"><i class="icon-trash"></i> Delete</a>
</div>
</span></td>
</tr>
<tr>
<td><? echo "$message"; ?></td>
</tr>
</table>
</form></div>
<?
echo "
<div class=\"modal hide\" id=\"replyMessage\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"replyMessageLabel\" aria-hidden=\"true\">
<div class=\"modal-header\">
<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>
<h3 id=\"replyMessageLabel\">Reply To Message</h3>
</div>
<div class=\"modal-body\">
<form method=\"POST\" style=\"margin: 0px;\">
<textarea rows=\"10\" id=\"area1\" name=\"message\" class=\"span12\"></textarea>
<input type=\"hidden\" name=\"quote\" value=\"$_GET[msgid]\">
</div>
<div class=\"modal-footer\">
<button type=\"submit\" class=\"btn btn-success\" name=\"send\" value=\"Submit\"><i class=\"icon-share-alt icon-white\"></i> Send</button>
<button class=\"btn btn-warning\" data-dismiss=\"modal\" aria-hidden=\"true\">Cancel</button>
</div>
</div>
</form>";
require_once("members/footer.php");
exit();
}
if ($_POST['message']) {
if (isset($_POST['quote'])) {
$res=$mysqli->query("SELECT message, `from` FROM pmessages WHERE id='$_POST[quote]' LIMIT 1;");
$row=$res->fetch_array();
$quote=$row[0];
//Get rid of previous quotes
function killquote($quote) {
$quote = preg_replace("(\[quote=(.+?)\](.+?)\[\/quote\])is",'',$quote);
return $quote;
}
$quote=killquote($quote);
$from=$row[1];
$res=$mysqli->query("SELECT `username` FROM `Players` WHERE id='$msg[from]' LIMIT 1;");
$username=$res->fetch_array();
$message="[quote=$username[0]]$quote\[/quote]
$_POST[message]";
} else {
$message=$_POST['message'];
}
$message = stripHTML(addslashes("$message"));
$block=$mysqli->query("SELECT * FROM blocklist WHERE block='$_COOKIE[id]' AND username='$msg[from]' LIMIT 1");
if ($block->num_rows > 0) {
echo "<div id=\"crimestext\" align=\"center\">$msg[from] has you on their block list, so you are unable to send them a message.<br /><a href=\"messaging.php\">Go back.</a></div>";
exit();
}
$mysqli->query("INSERT INTO `pmessages` (`title`, `message`, `touser`, `from`, `unread`, `date`, `reply`) VALUES ('$msg[title]', '$message', '$msg[from]', '$_COOKIE[id]', 'unread', '$date', 'yes')");
echo "<head><meta HTTP-EQUIV=\"REFRESH\" content=\"2; url=messaging.php\"></head>
<div class=\"page-header\"><h1>Messaging <small>Sent</small></h1></div>
<div class=\"alert alert-success\"><span class=\"label label-success\">Success</span> Your message has been sent. Redirecting...</div>";
require_once("members/footer.php");
exit();
}
} else {
echo "<h1>Error</h1><br />";
echo "<div id=\"crimestext\" align=\"center\">This message was not sent to you, so you cannot open it.<br /><a href=\"messaging.php\">Go back.</a></div>";
require_once("members/footer.php");
exit();
}
}
break;
}
?>