invalidatedatacache("mail-{$session['user']['acctid']}");
//
header("Location: mail.php");
exit();
}elseif($op=="process"){
$msg = httppost('msg');
if (!is_array($msg) || count($msg)<1){
$session['message'] = "`\$`bYou cannot delete zero messages! What does this mean? You pressed \"Delete Checked\" but there are no messages checked! What sort of world is this that people press buttons that have no meaning?!?`b`0";
header("Location: mail.php");
}else{
$sql = "DELETE FROM " . db_prefix("mail") . " WHERE msgto='".$session['user']['acctid']."' AND messageid IN ('".join("','",$msg)."')";
db_query($sql);
invalidatedatacache("mail-{$session['user']['acctid']}");
header("Location: mail.php");
exit();
}
}elseif ($op=="unread"){
$sql = "UPDATE " . db_prefix("mail") . " SET seen=0 WHERE msgto='".$session['user']['acctid']."' AND messageid='$id'";
db_query($sql);
invalidatedatacache("mail-{$session['user']['acctid']}");
header("Location: mail.php");
exit();
}
popup_header("Ye Olde Poste Office");
$inbox = translate_inline("Inbox");
$write = translate_inline("Write");
// Build the initial args array
$args = array();
array_push($args, array("mail.php", $inbox));
array_push($args, array("mail.php?op=address",$write));
// to use this hook,
// just call array_push($args, array("pagename", "functionname"));,
// where "pagename" is the name of the page to forward the user to,
// and "functionname" is the name of the mail function to add
$mailfunctions = modulehook("mailfunctions", $args);
//output_notl("
$inbox | $write | ", true);
rawoutput("");
rawoutput("");
for($i=0;$i$name");
// addnav("", $page);
// No need for addnav since mail function pages are (or should
// be) outside the page nav system.
}
}
}
rawoutput("
");
output_notl("`n`n");
if($op=="send"){
$to = httppost('to');
$sql = "SELECT acctid FROM " . db_prefix("accounts") . " WHERE login='$to'";
$result = db_query($sql);
if (db_num_rows($result)>0){
$row1 = db_fetch_assoc($result);
$sql = "SELECT count(messageid) AS count FROM " . db_prefix("mail") . " WHERE msgto='".$row1['acctid']."' AND seen=0";
$result = db_query($sql);
$row = db_fetch_assoc($result);
if ($row['count']>=getsetting("inboxlimit",50)) {
output("`\$You cannot send that person mail, their mailbox is full!`0`n`n");
}else{
$subject = str_replace("`n","",httppost('subject'));
$body = str_replace("`n","\n",httppost('body'));
$body = str_replace("\r\n","\n",$body);
$body = str_replace("\r","\n",$body);
$body = addslashes(substr(stripslashes($body),0,(int)getsetting("mailsizelimit",1024)));
systemmail($row1['acctid'],$subject,$body,$session['user']['acctid']);
output("Your message was sent!`n");
}
}else{
output("Could not find the recipient, please try again.`n");
}
if (httppost("returnto")>""){
$op="read";
httpset('op','read');
$id = httppost('returnto');
httpset('id',$id);
}else{
$op="";
httpset('op', "");
}
}
if ($op==""){
output("`b`iMail Box`i`b");
if (isset($session['message'])) {
output($session['message']);
}
$session['message']="";
$sql = "SELECT subject,messageid," . db_prefix("accounts") . ".name,msgfrom,seen,sent FROM " . db_prefix("mail") . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("accounts") . ".acctid=" . db_prefix("mail") . ".msgfrom WHERE msgto=\"".$session['user']['acctid']."\" ORDER BY sent DESC";
$result = db_query($sql);
if (db_num_rows($result)>0){
output_notl("",true);
}else{
output("`iAww, you have no mail, how sad.`i");
}
output("`n`n`iYou currently have %s messages in your inbox.`nYou will no longer be able to receive messages from players if you have more than %s unread messages in your inbox. `nMessages are automatically deleted (read or unread) after %s days.",db_num_rows($result),getsetting('inboxlimit',50),getsetting("oldmail",14));
}elseif ($op=="read"){
$sql = "SELECT " . db_prefix("mail") . ".*,". db_prefix("accounts"). ".name FROM " . db_prefix("mail") ." LEFT JOIN " . db_prefix("accounts") . " ON ". db_prefix("accounts") . ".acctid=" . db_prefix("mail"). ".msgfrom WHERE msgto=\"".$session['user']['acctid']."\" AND messageid=\"".$id."\"";
$result = db_query($sql);
if (db_num_rows($result)>0){
$row = db_fetch_assoc($result);
if ((int)$row['msgfrom']==0){
$row['name']=translate_inline("`i`^System`0`i");
// No translation for subject if it's not an array
if (is_array(@unserialize($row['subject']))) {
$row['subject'] = unserialize($row['subject']);
$row['subject'] =
call_user_func_array("sprintf_translate", $row['subject']);
}
// No translation for body if it's not an array
if (is_array(@unserialize($row['body']))) {
$row['body'] = unserialize($row['body']);
$row['body'] =
call_user_func_array("sprintf_translate", $row['body']);
}
}
if (!$row['seen']) output("`b`#NEW`b`n");
else output("`n");
output("`b`2From:`b `^%s`n",$row['name']);
output("`b`2Subject:`b `^%s`n",$row['subject']);
output("`b`2Sent:`b `^%s`n",$row['sent']);
output_notl("`n",true);
output_notl(str_replace("\n","`n",$row['body']));
output_notl("`n`n",true);
$sql = "UPDATE " . db_prefix("mail") . " SET seen=1 WHERE msgto=\"".$session['user']['acctid']."\" AND messageid=\"".$id."\"";
db_query($sql);
$reply = translate_inline("Reply");
$del = translate_inline("Delete");
$unread = translate_inline("Mark Unread");
$report = translate_inline("Report to Admin");
$problem = "Abusive Email Report:\nFrom: {$row['name']}\nSubject: {$row['subject']}\nSent: {$row['sent']}\nID: {$row['messageid']}\nBody:\n{$row['body']}";
rawoutput("
$reply |
$del |
$unread | ");
// Don't allow reporting of system messages as abuse.
if ((int)$row['msgfrom']!=0) {
rawoutput("$report | ");
} else {
rawoutput(" | ");
}
rawoutput("
");
$sql = "SELECT messageid FROM ".db_prefix("mail")." WHERE msgto='{$session['user']['acctid']}' AND messageid < '$id' ORDER BY messageid DESC LIMIT 1";
$result = db_query($sql);
if (db_num_rows($result)>0){
$row = db_fetch_assoc($result);
$pid = $row['messageid'];
}else{
$pid = 0;
}
$sql = "SELECT messageid FROM ".db_prefix("mail")." WHERE msgto='{$session['user']['acctid']}' AND messageid > '$id' ORDER BY messageid LIMIT 1";
$result = db_query($sql);
if (db_num_rows($result)>0){
$row = db_fetch_assoc($result);
$nid = $row['messageid'];
}else{
$nid = 0;
}
$prev = translate_inline("< Previous");
$next = translate_inline("Next >");
rawoutput("");
if ($pid > 0) rawoutput("".htmlentities($prev)."");
else rawoutput(htmlentities($prev));
rawoutput(" | ");
if ($nid > 0) rawoutput("".htmlentities($next)."");
else rawoutput(htmlentities($next));
rawoutput(" | ");
rawoutput("
");
}else{
output("Eek, no such message was found!");
}
}elseif($op=="address"){
output_notl("",true);
}elseif($op=="write"){
$subject=httppost('subject');
$body="";
$row = "";
output_notl("",true);
$sizemsg = "`#Max message size is `@%s`#, you have `^XX`# characters left.";
$sizemsg = translate_inline($sizemsg);
$sizemsg = sprintf($sizemsg,getsetting("mailsizelimit",1024));
$sizemsgover = "`\$Max message size is `@%s`\$, you are over by `^XX`\$ characters!";
$sizemsgover = translate_inline($sizemsgover);
$sizemsgover = sprintf($sizemsgover,getsetting("mailsizelimit",1024));
$sizemsg = explode("XX",$sizemsg);
$sizemsgover = explode("XX",$sizemsgover);
$usize1 = addslashes("".appoencode($sizemsg[0])."");
$usize2 = addslashes("".appoencode($sizemsg[1])."");
$osize1 = addslashes("".appoencode($sizemsgover[0])."");
$osize2 = addslashes("".appoencode($sizemsgover[1])."");
rawoutput("
");
}
popup_footer();
?>