<?php
include "globals.php";
include "bbcode.php";
include "bbcodestyle.css";
if($ir['mailban']) {
printf("<span style='color:red;'><h3>ERROR</h3>You have been mail banned for {$ir['mailban']} days.<strong>Reason: {$ir['mb_reason']}</font></strong>");
$h->endpage();
exit;
}
$_GET['ID'] = isset($_GET['ID']) && ctype_digit($_GET['ID']) ? abs(@intval($_GET['ID'])) : null;
if($ir['pagetutorials'] == 'ON') {
echo "
<table width='75%' border='3' bordercolor='#BDBDBD' cellspacing='0' bgcolor='#FBFBE0' frame='border'>
<tr>
<td width='75'><img src='images/lightbulb.gif' alt='Lightbulb' /><br /><span style='color:#999;'><em>[<a href='preferences.php?action=pagetutorialschange'></a>]</em></span></td>
<td><strong>Your Mailbox</strong><br /><span style='color:#000;font-size:3em;'>Hopefully, I shouldnt have to tell you how this works.</span></td>
</tr>
</table><br />";
}
echo "<br /><hr /><br /><table width='87%' class='table' cellspacing='1' style='text-align:center;'>
<tr>
<td><a href='mailbox.php?action=inbox'><img src='images/indox.gif' width='75px' height='79px'></a></td>
<td><a href='mailbox.php?action=outbox'><img src='images/sent.gif' width='75px' height='79px'></a></td>
<td><a href='mailbox.php?action=compose'><img src='images/compose.gif' width='75px' height='79px'></a></td>
<td><a href='mailbox.php?action=delall'><img src='images/deleteall.gif' width='75px' height='79px'></a></td>
<td><a href='mailbox.php?action=archive'><img src='images/archiveall.gif' width='75px' height='79px'></a></td>
<td><a href='contactlist.php'><img src='images/contacts.gif' width='75px' height='79px'></a></td>
</tr>
</table><br /><hr /><br />";
$_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : null;
switch($_GET['action']) {
case 'inbox':
mail_inbox();
break;
case 'outbox':
mail_outbox();
break;
case 'compose':
mail_compose();
break;
case 'delete':
mail_delete();
break;
case 'delall':
mail_delall();
break;
case 'archive':
mail_archive();
break;
case 'del':
mail_massdel();
break;
case 'read':
mail_view();
break;
default:
mail_inbox();
break;
}
function mail_inbox() {
global $db, $ir, $c, $userid, $h;
?>
<script><!-- HIDE
function setCheckboxes(the_form, do_check) {
var elts = (typeof(document.forms[the_form].elements['ID[]']) != 'undefined')
? document.forms[the_form].elements['ID[]']
: (typeof(document.forms[the_form].elements['ID[]']) != 'undefined')
? document.forms[the_form].elements['ID[]']
: document.forms[the_form].elements['ID[]'];
var elts_cnt = (typeof(elts.length) != 'undefined')
? elts.length
: 0;
if (elts_cnt) {
for (var i = 0; i < elts_cnt; i++) {
elts[i].checked = do_check;
} // end for
} else {
elts.checked = do_check;
} // end if... else
return true;
}
// STOP HIDING --></script>
Only the last 25 messages sent to you are visible.
<form name='masssell' method='post' action='mailbox.php?action=del'>
<table width='100%' class='table1' cellspacing='1' border='0'>
<tr>
<th>From</th>
<th>Status</th>
<th>Read</th>
<th>Delete</th>
</tr>
<?php
$q = $db->query(sprintf("SELECT `m`.*, `u`.`username` FROM `mail` AS `m` " . "LEFT JOIN `users` AS `u` ON (`m`.`mail_from` = `u`.`userid`) " . "WHERE (`m`.`mail_to` = %d) " . "ORDER BY `m`.`mail_time` DESC LIMIT 25", $ir['userid']));
$i = 0;
while($r = $db->fetch_row($q)) {
printf("<tr class='d%d'>", $i & 1);
$i++;
echo "<td>";
echo $r['mail_from'] ? sprintf("<center><a href='viewuser.php?u=%d' style='color:%s;'>%s</a> (%s)", $r['mail_from'], stripslashes($r['colour']), stripslashes($r['username']), number_format($r['mail_from'])) : "<span style='color:yellow;font-weight:700;'>SYSTEM</span>";
echo "</center></td>";
printf("<td>%s</td>", !$r['mail_read'] ? "<span style='color:red;'>Unopened</span>" : "<span style='color:green;'>Read</span>");
printf("<td><a href='mailbox.php?action=read&ID=%d'>Open</a></td>", $r['mail_id']);
printf("<td><a href='mailbox.php?action=delete&ID=%d'><img src='images/trash.gif' height='20' width='20' alt='Delete' /></a> <input type='checkbox' name='del%d' value='yes' /><input type='hidden' name='id%d' value='%d' /></td>", $r['mail_id'], $i, $i, $r['mail_id']);
echo "</tr>";
}
?> <tr>
<td colspan='5'><center><hr /><input name='sellmass' type='submit' id='sellmass' value='Delete selected' /><br /><a href='#' onClick='setCheckboxes("masssell",true); return false;'>Check All</a> | <a href='#' onClick='setCheckboxes("masssell",false); return true;'>Uncheck All </a></center></td>
</tr>
</table>
</form><?
}
function mail_outbox() {
global $db, $ir, $c, $userid, $h;
?>Only the last 25 messages you have sent are visible.<br />
<table width='75%' cellspacing='1' class='table'>
<tr>
<th>To</th>
<th>Message</th>
</tr><?
$q = $db->query(sprintf("SELECT `m`.*, `u`.`username` FROM `mail` AS `m` " . "LEFT JOIN `users` AS `u` ON (`m`.`mail_to` = `u`.`userid`) " . "WHERE (`m`.`mail_from` = %d) " . "ORDER BY `m`.`mail_time` DESC LIMIT 25", $ir['userid']));
while($r = $db->fetch_row($q)) {
echo "<tr>";
printf("<td><a href='viewuser.php?u=%d' style='color:%s;'>%s</a> [%s]</td>", $r['mail_from'], $r['colour'], stripslashes($r['username']), number_format($r['mail_from']));
printf("<td>%s</td>", stripslashes($r['mail_subject']));
echo "</tr>";
echo "<tr>";
printf("<td>Sent at: %s</td>", date('F j, Y, g:i:s a', $r['mail_time']));
printf("<td>%s</td>", stripslashes($r['mail_text']));
echo "</tr>";
}
echo '</table>';
}
function mail_compose() {
global $db, $ir, $db, $userid, $h;
if(!isset($_POST['form'])) {
?><script type="text/javascript">
function insert(el,ins) {
if (el.setSelectionRange){
el.value = el.value.substring(0,el.selectionStart) + ins + el.value.substring(el.selectionStart,el.selectionEnd) + el.value.substring(el.selectionEnd,el.value.length);
} else if (document.selection && document.selection.createRange) {
el.focus();
var range = document.selection.createRange();
range.text = ins + range.text;
}
}
</script>
<form action='mailbox.php?action=compose' method='post'>
<input type='hidden' name='form' value='1' />
<table width='75%' border='0'>
<tr>
<th>ID to send to:</th>
<td><input type='text' name='userid' value='<?
echo $_GET['ID'];
?>' style='color: white; background-color:#2E2E2E' class='loginbox' /></td>
</tr>
<tr>
<td colspan='2'> </td>
</tr>
<tr>
<th>Message:</th>
<td>
<input type="button" class="bbcode_hover" onClick="insert(this.form.message,'[b][/b]'); return false;" value="" />
<input type="button" class="bbcode_hover0" onClick="insert(this.form.message,'[br]'); return false;" value="" />
<input type="button" class="bbcode_hover1" onClick="insert(this.form.message,'[i][/i]'); return false;" value="" />
<input type="button" class="bbcode_hover2" onClick="insert(this.form.message,'[u][/u]'); return false;" value="" />
<input type="button" class="bbcode_hover3" onClick="insert(this.form.message,'[url][/url]'); return false;" value="" />
<input type="button" class="bbcode_hover5" onClick="insert(this.form.message,'[img][/img]'); return false;" value="" />
<input type="button" class="bbcode_hover7" onClick="insert(this.form.message,'[color=#xxxxxx][/color]'); return false;" value="" />
<br />
<input type="image" src="smilies/smiley1.gif" alt="Smile" title="smile" onclick="insert(this.form.message,':)'); return false;" />
<input type="image" src="smilies/smiley2.gif" alt="Wink" title="Wink" onclick="insert(this.form.message,';)'); return false;" />
<input type="image" src="smilies/smiley3.gif" alt="Suprised" title="Suprised" onclick="insert(this.form.message,':o'); return false;" />
<input type="image" src="smilies/smiley4.gif" alt="Cheesy Grin" title="Cheesy Grin" onclick="insert(this.form.message,':D'); return false;" />
<input type="image" src="smilies/smiley5.gif" alt="Confused" title="Confused" onclick="insert(this.form.message,':s'); return false;" />
<input type="image" src="smilies/smiley6.gif" alt="Sad" title="Sad" onclick="insert(this.form.message,':('); return false;" />
<input type="image" src="smilies/smiley7.gif" alt="Angry" title="Angry" onclick="insert(this.form.message,':red'); return false;" />
<input type="image" src="smilies/smiley8.gif" alt="Clown" title="Clown" onclick="insert(this.form.message,':clown'); return false;" />
<input type="image" src="smilies/smiley9.gif" alt="Embarrassed" title="Embarrassed" onclick="insert(this.form.message,':bashful'); return false;" />
<input type="image" src="smilies/smiley10.gif" alt="Star" title="Star" onclick="insert(this.form.message,':x'); return false;" />
<input type="image" src="smilies/smiley11.gif" alt="Sick" title="Sick" onclick="insert(this.form.message,':green'); return false;" />
<input type="image" src="smilies/smiley12.gif" alt="Bored" title="Bored" onclick="insert(this.form.message,':|'); return false;" />
<input type="image" src="smilies/smiley13.gif" alt="Begging" title="Begging" onclick="insert(this.form.message,';('); return false;" />
<input type="image" src="smilies/smiley14.gif" alt="Smug" title="Smug" onclick="insert(this.form.message,':]'); return false;" />
<input type="image" src="smilies/smiley15.gif" alt="Horny" title="Horny" onclick="insert(this.form.message,':horny'); return false;" />
<input type="image" src="smilies/smiley16.gif" alt="Cool" title="Cool" onclick="insert(this.form.message,':cool'); return false;" /><br />
<textarea name='message' rows='10' cols='70' style='color: white; background-color: #2E2E2E' class="loginbox"></textarea>
</td>
</tr>
<tr>
<td colspan='2'> </td>
</tr>
<tr>
<td colspan='2' class='center'><center><input type='image' src='images/mailsend.jpeg' id='btn' name='submit' /></center></td>
</tr>
</table>
</form><?
if($_GET['ID']) {
echo "<br /><hr /><br />
<table width='75%' border='0'>
<tr>
<th colspan='2'>Your last 5 mails to/from this person:</th>
</tr>";
$q = $db->query(sprintf("SELECT `m`.*, `u1`.`username` AS `sender` FROM `mail` AS `m` " . "LEFT JOIN `users` AS `u1` ON (`m`.`mail_from` = `u1`.`userid`) " . "WHERE (((`m`.`mail_from` = %d) AND (`m`.`mail_to` = %d)) OR ((`m`.`mail_to` = %d) AND (`m`.`mail_from` = %d))) " . "ORDER BY `m`.`mail_time` DESC LIMIT 5", $ir['userid'], $_GET['ID'], $ir['userid'], $_GET['ID']));
if(!$db->num_rows($q)) {
echo "<tr><td colspan='2' class='center'>No messages exist</td></tr>";
} else {
while($r = $db->fetch_row($q)) {
echo "<tr>";
printf("<td>%s</td>", date('F j, Y, g:i:s a', $r['mail_time']));
printf("<td><strong><span style='color:%s;'>%s</span> [%s] wrote:</strong> %s</td>", stripslashes($r['colour']), stripslashes($r['sender']), number_format($_GET['ID']), stripslashes($r['mail_text']));
echo "</tr>";
}
}
echo '</table>';
}
} else {
$_POST['userid'] = isset($_POST['userid']) && ctype_digit($_POST['userid']) ? abs(@intval($_POST['userid'])) : null;
if(empty($_POST['userid'])) {
echo "You didn't select a valid player to send a message to";
$h->endpage();
exit;
}
$selectPlayer = $db->query(sprintf("SELECT `username` FROM `users` WHERE (`userid` = %d)", $_POST['userid']));
if(!$db->num_rows($selectPlayer)) {
echo "That player doesn't exist";
$h->endpage();
exit;
}
$subj = str_replace("\n", "<br />", strip_tags($_POST['subject']));
$codes = array(
":)",
";)",
":o",
":D",
":s",
":(",
":red",
":clown",
":bashful",
":x",
":green",
":|",
";(",
":]",
":horny",
":cool",
"(LK)",
"(O)"
);
$images = array(
"<img src='smilies/smiley1.gif' />",
"<img src='smilies/smiley2.gif' />",
"<img src='smilies/smiley3.gif' />",
"<img src='smilies/smiley4.gif' />",
"<img src='smilies/smiley5.gif' />",
"<img src='smilies/smiley6.gif' />",
"<img src='smilies/smiley7.gif' />",
"<img src='smilies/smiley8.gif' />",
"<img src='smilies/smiley9.gif' />",
"<img src='smilies/smiley10.gif' />",
"<img src='smilies/smiley11.gif' />",
"<img src='smilies/smiley12.gif' />",
"<img src='smilies/smiley13.gif' />",
"<img src='smilies/smiley14.gif' />",
"<img src='smilies/smiley15.gif' />",
"<img src='smilies/smiley16.gif' />",
"<img src='lk.png' />",
"<img src='one.png' />"
);
$newmsg = $db->escape(str_replace($codes, $images, $_POST['message']));
$to = $_POST['userid'];
$db->query(sprintf("INSERT INTO `mail` VALUES ('', 0, %d, %d, %s, '%s', '%s')", $ir['userid'], $to, time(), $subj, $newmsg));
$db->query(sprintf("UPDATE `users` SET `new_mail` = `new_mail` + 1 WHERE (`userid` = %d)", $to));
printf("Your message to %s has been sent", stripslashes($player));
}
}
function mail_delete() {
global $db, $ir, $c, $userid, $h;
if(empty($_GET['ID'])) {
echo "You didn't select a valid message to delete";
$h->endpage();
exit;
}
$select = $db->query(sprintf("SELECT `mail_id` FROM `mail` WHERE ((`mail_id` = %d) AND (`mail_to` = %d))", $_GET['ID'], $ir['userid']));
if(!$db->num_rows($select)) {
echo "Either that message doesn't exist, or it's not yours";
$h->endpage();
exit;
}
$db->query(sprintf("DELETE FROM `mail` WHERE (`mail_id` = %d)", $_GET['ID']));
echo "Message deleted.<br /><a href='mailbox.php'>> Back</a>";
}
function mail_view() {
global $db, $ir, $c, $userid, $h;
?><table width='100%' class='table' border='0' cellspacing='1'>
<tr>
<th width='25%'>From</th>
<th width='75%'>Message</th>
</tr><?
$q = $db->query(sprintf("SELECT `m`.*, `u`.`username` FROM `mail` AS `m` " . "LEFT JOIN `users` AS `u` ON (`m`.`mail_from` = `u`.`userid`) " . "WHERE ((`m`.`mail_id` = %d) AND (`m`.`mail_to` = %d))", $_GET['ID'], $ir['userid']));
if(!$db->num_rows($q)) {
echo "Either that message doesn't exist, or it's not yours";
$h->endpage();
exit;
}
$r = $db->fetch_row($q);
echo "<tr>";
printf("<td>%s</td>", $r['mail_from'] ? sprintf("<a href='viewuser.php?u=%d' style='color:%s;'>%s</a> [%s]", $r['mail_from'], stripslashes($r['colour']), stripslashes($r['username']), number_format($r['mail_from'])) : "SYSTEM");
printf("<td>%s</td>", stripslashes($r['mail_subject']));
echo "</tr>";
echo "<tr>";
printf("<td>Sent at: %s<br /><br /><a href='mailbox.php?action=compose&ID=%d'>Reply</a><br /><a href='mailbox.php?action=delete&ID=%d'>Delete</a><br /><a href='preport.php?ID=%d'>Report</a></td>", date('F j, Y, g:i:s a', $r['mail_time']), $r['mail_from'], $r['mail_id'], $r['mail_from']);
printf("<td>%s</td>", stripslashes($r['mail_text']));
echo "</tr>";
echo "</table>";
if($r['mail_text'] == 'You have just been mailed bomb, damm unlucky.') {
$db->query(sprintf("UPDATE `users` SET `hospital` = `hospital` + %d, `hospreason` = 'Mailbombed' WHERE (`userid` = %d)", mt_rand(10, 140), $ir['userid']));
}
if(!$r['mail_read']) {
$db->query(sprintf("UPDATE `mail` SET `mail_read` = 1 WHERE (`mail_id` = %d)", $_GET['ID']));
$db->query(sprintf("UPDATE `users` SET `new_mail` = `new_mail` - 1 WHERE (`userid` = %d)", $ir['userid']));
}
}
function mail_delall() {
global $db, $ir;
if(!isset($_GET['ans'])) {
echo "This will delete all the messages in your inbox.<br />There is <strong>NO</strong> undo, so be sure.<br /><a href='mailbox.php?action=delall&ans=yes'>> Yes, delete all messages</a><br /><a href='mailbox.php'>> No, go back</a>";
} else {
$db->query(sprintf("DELETE FROM `mail` WHERE (`mail_to` = %d)", $ir['userid']));
printf("%s message%s ha%s been deleted", $db->affected_rows(), ($db->affected_rows() == 1) ? '' : 's', ($db->affected_rows() == 1) ? 's' : 've');
}
}
function mail_archive() {
echo "This tool will download an archive of all your messages.<br /><a href='dlarchive.php?a=inbox'>> Download Inbox</a><br /><a href='dlarchive.php?a=outbox'>> Download Outbox</a>";
}
function mail_massdel() {
global $db, $ir, $c, $userid, $h;
$counter = 1;
$deleted = 0;
while($counter < 25) {
$dodel = "del" . $counter;
if($_POST[$dodel] == "yes") {
$delid = "id" . $counter;
$db->query(sprintf("DELETE FROM `mail` WHERE ((`mail_to` = %d) AND (`mail_id` = %d))", $ir['userid'], $_POST[$delid]));
$deleted++;
}
$counter++;
}
printf("%s message%s ha%s been deleted", $deleted, ($deleted == 1) ? '' : 's', ($deleted == 1) ? 's' : 've');
}
echo "<br /><br />Mail count mixed up? Click <a href='fix.php?fix=1'>Here</a> to fix";
$h->endpage();
?>
http://pastebin.com/9jwzQnra
Thanks goes to MTG for coding this for me ages.
Please do give thanks.
Oh and dont forget to edit the code to suit your game.