Re: Updated Mailbox [v1]
check out my mailbox, the default mccodes mail was 2 plain and i thought i could do better :P
<?php
include "globals.php";
?><h2>Mailbox</h2><?
if($ir[mailban])
{
die("<font color=red><h1>ERROR</h1><hr />
You have been mail banned for " . $ir['mailban'] . " days.
[b]Reason: " . $ir['mb_reason'] . "</font>[/b]");
}
$_GET[iD] = abs((int) $_GET[iD]);
switch($_GET[action])
{
case 'inbox': mail_inbox();
break;
case 'outbox': mail_outbox();
break;
case 'compose': mail_compose();
break;
case 'delete': mail_delete();
break;
case 'send': mail_send();
break;
case 'delall': mail_delall();
break;
case 'delall2': mail_delall2();
break;
case 'read': mail_read();
break;
default:
mail_inbox();
break;
}
function mail_inbox()
{
global $db,$ir,$c,$userid,$h;
$q=$db->query("SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_from=u.userid WHERE m.mail_to=$userid ORDER BY mail_time DESC LIMIT 25");
if(!mysql_num_rows($q))
{ die("You have no mails. Go send some <a href=mail.php?action=compose><u>here</u></a>"); }
?>
Only the last 25 messages sent to you are visible.
[ [url="mail.php?action=outbox"] Outbox [/url] | [url="mail.php?action=delall"] Delete All [/url] ]
<table width=90% cellspacing="1">
<tr>
<td class="h">From</td>
<td class="h">Subject</td>
<td class="h" width="10%">Status</td>
<td class="h" width="10%">Delete</td>
</tr>
<?
$i=0;
$current_row = 0;
while($r=$db->fetch_row($q))
{
$current_row = 1 - $current_row;
?>
<tr class="row<? echo $current_row; ?>"><td align="left" style="text-indent:5px">
<?
$i++;
if($r['userid'])
{
?>
[url="viewuser.php?u=<? echo $r[userid]; ?>"]<? echo $r[username]; ?>[/url] [<? echo $r[userid]; ?>]
<?
}
else
{
?>
<font color="#990000">SYSTEM</font>
<?
}
if($r['mail_read'] == 0) { $status="<font color=red>Unread</font>"; }
else { $status="<font color=green>Read</font>"; }
?>
</td>
<td align="left" style="text-indent:10px;">
[b]Subject:[/b]
<?
if($r[mail_subject])
{ ?> [url="mail.php?action=read&ID=<? echo $r[mail_id]; ?>"]<? echo $r[mail_subject]; ?>[/url] <? }
else { ?> [url="mail.php?action=read&ID=<? echo $r[mail_id]; ?>"]N/A[/url] <? } ?>
</td><td align='center'>
<? echo $status; ?>
</td>
<td align=center>
[[url="mail.php?action=delete&ID=<? echo $r[mail_id]; ?>"]delete[/url]]
</td></tr>
<?
}
if($ir['new_mail'] > 0)
{
$db->query("UPDATE users SET new_mail=0 WHERE userid=$userid");
}
?> </table> <?
}
function mail_outbox()
{
global $db,$ir,$c,$userid,$h;
$current_row = 0;
?>
Only the last 25 messages you have sent are visible.
<table width="90%" cellspacing="0">
<tr class="h">
<td width="20%">To</th>
<td>Subject/Message</td>
</tr>
<?
$q=$db->query("SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_to=u.userid WHERE m.mail_from=$userid ORDER BY mail_time DESC LIMIT 25");
while($r=$db->fetch_row($q))
{
$current_row = 1 - $current_row;
$sent=date('F j, Y, g:i:s a',$r[mail_time]);
?>
<tr class="row<? echo $current_row; ?>">
<td>[url="viewuser.php?u=<? echo $r[userid]; ?>"]<? echo $r[username]; ?>[/url] <? echo $r[userid]; ?>]</td>
<td><? echo $r[mail_subject]; ?></td>
</tr>
<tr class="row<? echo $current_row; ?>">
<td>Sent at: <? echo $sent; ?>
</td>
<td><? echo $r[mail_text]; ?></td>
</tr>
<?
}
?></table><?
}
function mail_compose()
{
global $db,$ir,$c,$userid,$h;
?>
<form action="mail.php?action=send" method="post">
<table width=65% cellspacing="0" class="row1"><tr class="h"><td colspan="2">Compose Mail</td></tr><tr>
<td>Users ID:</td><td><input class="textbox" type="text" name="userid" value="<? echo $_GET[iD]; ?>" /></td></tr><tr>
<td>Subject:</td> <td><input class="textbox" type="text" name="subject" /></td></tr><tr>
<td>Message:</td>
<td>
<textarea class="textbox" rows=5 cols=40 name="message"></textarea>
</td></tr><tr> <td colspan=2><input type="submit" class="textbox" value="Send" /></td></tr></table></form>
<?
if($_GET[iD] == 3 || $_GET[iD] == 1) {
?>
<font color=brown>
Admins have a job to do and they are probably too busy to chat. If you have a problem, mail another staff member
[url="stafflist.php"]<u>here</u>[/url] and they will help you out.
</font>
<? }
if($_GET[iD] == 28 || $_GET[iD] == 38) {
?><font color=#9900CC>
Assistants are here to help and will be happy to answer any questions.
If you bad mouth staff you will get a harsher punishment.
</font>
<?
}
if($_GET[iD])
{
?>
<table width="65%" border="0">
<tr class="h">
<td colspan="2">Your last 5 mails to/from this person:</td>
</tr>
<?
$q=$db->query("SELECT m.*,u1.username as sender from mail m left join users u1 on m.mail_from=u1.userid WHERE (m.mail_from=$userid AND m.mail_to={$_GET[iD]}) OR (m.mail_to=$userid AND m.mail_from={$_GET[iD]}) ORDER BY m.mail_time DESC LIMIT 5",$c);
$current_row = 0;
while($r=$db->fetch_row($q))
{
$current_row = 1 - $current_row;
$sent=date('F j, Y, g:i:s a',$r[mail_time]);
?><tr class="row<? echo $current_row; ?>">
<td width=35%><? echo $sent; ?></td>
<td>[b]<? echo $r[sender]; ?> wrote:[/b] <? echo $r[mail_text]; ?></td>
</tr>
<? } ?>
</table>
<?
}
}
function mail_send()
{
global $db,$ir,$c,$userid,$h;
$subj=str_replace(array("\n"),array("
"),strip_tags($_POST[subject]));
$msg=str_replace(array("\n"),array("
"),strip_tags($_POST[message]));
$from = array(
':)',';)',':o',':D',':S',':(',':@','torncity','register.php?REF','roguevampires','fuck','lostpower',
);
$to = array(
'[img=images/icons/happy.gif]',
'[img=images/icons/wink.gif]',
'[img=images/icons/shocked.gif]',
'[img=images/icons/bigsmile.gif]',
'[img=images/icons/confused.gif]',
'[img=images/icons/sad.gif]',
'[img=images/icons/angry.gif]',
'banburyco',
'banburyco.com',
'banburyco',
'****',
'banburyco',
);
$newmail = str_replace($from, $to, $msg);
$to= (int) $_POST[userid];
$q=$db->query("SELECT userid FROM users WHERE userid='{$to}'");
if($db->num_rows($q)==0)
{
die("You cannot send mail to nonexistant users.<hr />
[url='mail.php']Back[/url]");
}
$to= (int) $_POST[userid];
$db->query("INSERT INTO mail VALUES ('',0,$userid,$to,unix_timestamp(),'$subj','$newmail')");
$db->query("UPDATE users SET new_mail=1 WHERE userid={$to}");
print "Message sent.<hr />
[url='mail.php']Back[/url]";
}
function mail_delete()
{
global $db,$ir,$c,$userid,$h;
$db->query("DELETE FROM mail WHERE mail_id={$_GET[iD]} AND mail_to=$userid");
print "Message deleted.<hr />[url='mail.php']Back[/url]";
}
function mail_delall()
{
global $ir,$c,$userid,$h; ?>
This will delete [i]all[/i] the messages in your inbox.
<hr />
[url="mail.php?action=delall2"]Yes! Do it[/url]
[url="mail.php"]No, go back[/url]
<? }
function mail_delall2()
{
global $db,$ir,$c,$userid,$h;
$db->query("DELETE FROM mail WHERE mail_to=$userid");
echo $db->affected_rows(); ?> mails in your inbox were deleted.
<hr />
[url="mail.php"]Back[/url]
<?
}
function mail_read()
{
global $db,$ir,$c,$userid,$h;
$id= abs((int) $_GET[iD]);
$q=$db->query("SELECT m.*,u.* FROM mail m LEFT JOIN users u ON m.mail_from=u.userid WHERE m.mail_id=$id LIMIT 1");
$r=$db->fetch_row($q);
$sent=date('F j, Y, g:i:s a',$r['mail_time']);
?>
<table width="75%" class="row1" cellspacing="0">
<tr class="h">
<td>From: <?
if($r[userid])
{
?>
[url="viewuser.php?u=<? echo $r[userid];?>"]<font color="#FFFFFF"><? echo $r[username]; ?></font>[/url]
<? echo '[' . $r[userid] . ']'; }
else
{ ?><font color="#990000">SYSTEM</font><? } ?>
</td></tr><tr style='border-bottom: thin solid #666666;'><td colspan='2' align='center'>
[[url="mail.php?action=compose&ID=<? echo $r[userid]; ?>"]Reply[/url]]
[[url="mail.php?action=delete&ID=<? echo $r[mail_id]; ?>"]Delete[/url]]
[[url="preport.php?ID=<? echo $r[userid]; ?>&report=Fradulent mail:<? echo $fm; ?>"]Report[/url]]
</td></tr><tr><td colapan='2' style='border-top: 1px solid #CCCCCC;'>
[b]Mail Text:[/b] <? echo $r[mail_text]; ?>
</td></tr></table>
<?
if($r[mail_read] == 0)
{
$db->query("UPDATE mail SET mail_read=1 WHERE mail_to=$userid AND mail_id=$id LIMIT 1");
$db->query("UPDATE users SET new_mail=new_mail-1 WHERE userid=$userid");
}
?></table><?
}
$h->endpage();
?>