Re: Updated Mailbox [v1]
For V2 users, This is the code I'm using and it seems to work fine.....
<?php
include "globals.php";
if($ir['mailban'])
{
die("<center><font color=red><font size='4' face='Arial, Helvetica, sans-serif'>Error</font>
You have been mail banned for {$ir['mailban']} days.
[b]Reason: {$ir['mb_reason']}</font>[/b]");
}
$_GET['ID'] = abs((float) $_GET['ID']);
print "<center><font size='4' face='Arial, Helvetica, sans-serif'>Mail Box</font><hr width=90%><table width=90% border=0><tr>
<td width=20% align=center>> [url='mailbox.php?action=compose'] Compose[/url]</td>
<td width=20% align=center>> [url='mailbox.php?action=outbox'] Outbox[/url]</td>
<td width=20% align=center>> [url='mailbox.php?action=archive'] Save[/url]</td>
<td width=20% align=center>> [url='mailbox.php?action=delall'] Delete All[/url]</td>
<td width=20% align=center>> [url='mailbox.php?action=mailhome'] Inbox[/url]</td>
</tr></table><hr width=90%>";
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 'archive':
mail_archive();
break;
case 'read':
mail_view();
break;
case 'mailhome':
mail_home();
break;
default:
mail_home();
break;
}
function mail_home()
{
global $ir,$c,$userid,$h,$db;
print "Below are the Last 10 Messages Sent to You<hr width=90%>
<table width=90% cellpadding=3 class=maintable><tr bgcolor=AAAAAA><th width=30%>From</th><th width=40%>Subject</th><th width=15%>Status</th><th width=15%>Manage</th></tr>";
$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 10",$c);
while($r=$db->fetch_row($q))
{
$sent=date('F j, Y, g:i:s a',$r['mail_time']);
print "<tr><td>";
if($r['userid'])
{
print "[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]";
}
else
{
print "SYSTEM";
}
$fm=urlencode($r['mail_subject']);
if($r['mail_read'] == 0)
{
$status="<font color=red>Unread</font>";
}
else
{
$status="<font color=green>Read</font>";
}
print "</td>\n<td>[b]Subject:[/b] [url='mailbox.php?action=read&ID={$r[']{$r['mail_subject']}[/url]
[i]Sent at: $sent[/i]</td><td><center> $status</td><td><center>[[url='mailbox.php?action=delete&ID={$r[']Delete[/url]] [[url='mailbox.php?action=read&ID={$r[']Read[/url]]</td></tr>";
}
}
function mail_view()
{
global $ir,$c,$userid,$h,$db;
print "
<table width=90% cellpadding=3 class=maintable>";
$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");
while($r=$db->fetch_row($q))
{
$sent=date('F j, Y, g:i:s a',$r['mail_time']);
print "<tr><td bgcolor=#AAAAAA>";
if($r['userid'])
{
print "[b]Mail From: [/b][url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]";
}
else
{
print "SYSTEM";
}
$fm=urlencode($r['mail_text']);
print "<th bgcolor=#AAAAAA width=75%>[b]Subject:[/b] {$r['mail_subject']}</th></tr><tr><td>Sent at: $sent
[url='mailbox.php?action=compose&ID={$r[']Reply[/url]
[url='mailbox.php?action=delete&ID={$r[']Delete[/url]
[url='preport.php?ID={$r[']Report[/url]</td><td>{$r['mail_text']}</td></tr></table>
<form action='mailbox.php?action=send' method='post'>
<table width=90% cellpadding=3 class='maintable'><th colspan=2 bgcolor=#AAAAAA>[b]Reply To This Message[/b]</th> <tr>
<td>User's ID:</td> <td><input type='text' name='userid' value='{$r['userid']}' size='5' maxlength='10' /> [i]<font size=1.9>(E.g. 123456)</font>[/i]</td></tr><tr>
<td>Subject:</td> <td><input type='text' name='subject' size='50' maxlength='50' value=' ' /> [i]<font size=1.9>(E.g. Hello there)</font>[/i]</td></tr><tr>
<td>Message:</td>
<td><textarea rows='10' cols='75%' name='message'></textarea></td></tr><tr> <td colspan=2><center><input type='submit' value='Send' /></td></tr></form>";
}
$db->query("UPDATE mail SET mail_read=1 WHERE mail_id=$id",$c);
}
function mail_outbox()
{
global $ir,$c,$userid,$h,$db;
print "Below are the Last 10 Messages You have Sent<hr width=90%>
<table width=90% cellpadding=3 class=maintable><tr bgcolor=AAAAAA><th width=35%>From</th><th width=50%>Subject</th><th width=15%>Manage</th></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 10",$c);
while($r=$db->fetch_row($q))
{
$sent=date('F j, Y, g:i:s a',$r['mail_time']);
print "<tr><td>";
if($r['userid'])
{
print "[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]";
}
else
{
print "SYSTEM";
}
$fm=urlencode($r['mail_subject']);
if($r['mail_read'] == 0)
{
$status="<font color=red>Unread</font>";
}
else
{
$status="<font color=green>Read</font>";
}
print "</td>\n<td>[b]Subject:[/b] [url='mailbox.php?action=read&ID={$r[']{$r['mail_subject']}[/url]
[i]Sent at: $sent[/i]</td><td><center>[[url='mailbox.php?action=read&ID={$r[']Read[/url]]</td></tr>";
}
}
function mail_compose()
{
global $ir,$c,$userid,$h;
print "<form action='mailbox.php?action=send' method='post'>
<table width=90% cellpadding=3 class='maintable'> <tr><td colspan=3 bgcolor=#AAAAAA>[b] Send a Message[/b]</td></tr><tr>
<td>User's ID:</td> <td><input type='text' name='userid' value='' size='5' maxlength='10' /> [i]<font size=1.9>(E.g. 123456)</font>[/i]</td></tr><tr>
<td>Subject:</td> <td><input type='text' name='subject' size='50' maxlength='50' value=' ' /> [i]<font size=1.9>(E.g. Hello there)</font>[/i]</td></tr><tr>
<td>Message:</td>
<td><textarea rows='10' cols='75%' name='message'></textarea></td></tr><tr> <td colspan=2><center><input type='submit' value='Send' /></td></tr></table></form><hr width=90%>> [url='mailbox.php']Back to Messages[/url]<hr width=90%>";
if($_GET['ID'])
{
print "
<table width=90% cellpadding=3 class='maintable'><tr><td colspan=2 bgcolor=#AAAAAA>[b]Your last 5 mails to/from this person:[/b]</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);
while($r=$db->fetch_row($q))
{
$sent=date('F j, Y, g:i:s a',$r['mail_time']);
print "<tr><td bgcolor=#AAAAAA>$sent</td> <td bgcolor=#AAAAAA>[b]{$r['sender']} wrote:[/b] {$r['mail_text']}</td></tr>";
}
print "</table>";
}
}
function mail_send()
{
global $ir,$c,$userid,$h;
$subj=str_replace(array("\n"),array("
"),strip_tags($_POST['subject']));
$msg=str_replace(array("\n"),array("
"),strip_tags($_POST['message']));
$codes = array(
':]',
':D',
':oo:',
'O.o',
':/',
':angry:',
':?:',
':lol:',
':-:',
':O',
':(',
'O.O',
':roll:',
':zzz:',
':)',
':P',
':S',
':nut:',
';)',
':heart:',
'XD',
);
$images = array(
'[img=smilies/happy.gif]',
'[img=smilies/biggrin.gif]',
'[img=smilies/cool.gif]',
'[img=smilies/blink.gif]',
'[img=smilies/dry.gif]',
'[img=smilies/angry.gif]',
'[img=smilies/huh.gif]',
'[img=smilies/laugh.gif]',
'[img=smilies/mellow.gif]',
'[img=smilies/ohmy.gif]',
'[img=smilies/sad.gif]',
'[img=smilies/ph34r.gif]',
'[img=smilies/rolleyes.gif]',
'[img=smilies/sleep.gif]',
'[img=smilies/smile.gif]',
'[img=smilies/tongue.gif]',
'[img=smilies/unsure.gif]',
'[img=smilies/wacko.gif]',
'[img=smilies/wink.gif]',
'[img=smilies/wub.gif]',
'[img=smilies/XD.gif]',
);
$newmsg = str_replace($codes, $images, $msg);
$to= (int) $_POST['userid'];
$db->query("INSERT INTO mail VALUES ('',0,$userid,$to,unix_timestamp(),'$subj','$newmsg')",$c) or die(mysql_error());
print "Your Message has been Sent.
[url='mailbox.php']> Back[/url]";
}
function mail_delete()
{
global $ir,$c,$userid,$h,$db;
$db->query("DELETE FROM mail WHERE mail_id={$_GET['ID']} AND mail_to=$userid",$c);
print "Message deleted.
[url='mailbox.php']> Back[/url]";
}
function mail_delall()
{
global $ir,$c,$userid,$h;
print "This will delete all the messages in your inbox.
There is [b]NO[/b] undo, so be sure.
[url='mailbox.php?action=delall2']> Yes, delete all messages[/url]
[url='mailbox.php']> No, go back[/url]";
}
function mail_delall2()
{
global $ir,$c,$userid,$h;
$db->query("DELETE FROM mail WHERE mail_to=$userid",$c);
print "All ".mysql_affected_rows($c)." mails in your inbox were deleted.
[url='mailbox.php']> Back[/url]";
}
function mail_archive()
{
global $ir,$c,$userid,$h;
print "This tool will download an archive of all your messages.
[url='dlarchive.php?a=inbox']> Download Inbox[/url]
[url='dlarchive.php?a=outbox']> Download Outbox[/url]";
}
$h->endpage();
?>