Re: [mccode] mailbox with smilies
<?php
/*
-----------------------------------------------------------------------
-- Ajax Mailbox Script
-- © 2006 Dabomstew
-----------------------------------------------------------------------
-- This script is distributed in the hope that
-- it will be useful, but WITHOUT A WARRANTY
-- OF ANY KIND.
-----------------------------------------------------------------------
-- Dabomstew, DBS-Network.net, and
-- everyone else involved with this script do not
-- take any liability for damage done to your game
-- by the use of this script.
-----------------------------------------------------------------------
*/
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm);
$h->menuarea();
if($ir['mailban'])
{
die("<font color=red><h3>! ERROR</h3>
You have been mail banned for {$ir['mailban']} days.
Reason: {$ir['mb_reason']}</font>");
}
$http= $_SERVER['HTTP_HOST']; //we grab game's domain name!
?>
<script language="javascript" type="text/javascript">
function my_getbyid(special)
{
return document.getElementById(special);
}
var url = "ajaxmail.php?PHPSESSID=<?php print $_REQUEST["PHPSESSID"]; ?>¶m="; // The server-side script
function handleHttpResponse() { if (http.readyState == 4) { // Split the comma delimited response into an array
results = http.responseText.split("<split>");
document.getElementById(results[1]).innerHTML=results[0]; } }
function showMail(mail_id) {
itm = my_getbyid("div_mail_"+mail_id);
itmer = my_getbyid("indicator_"+mail_id);
if (itmer.src == "http://<?php print $http; ?>/minus.gif")
{
document.getElementById("indicator_"+mail_id).src="http://<?php print $http; ?>/plus.gif";
document.getElementById("div_mail_"+mail_id).style.display="none";
}
else
{
document.getElementById("indicator_"+mail_id).src="http://<?php print $http; ?>/minus.gif";
document.getElementById("div_mail_"+mail_id).style.display="";
document.getElementById("div_mail_"+mail_id).innerHTML="Loading....";
}
if(itm.style.display=="")
{
var zipValue = mail_id;
http.open("GET", url + escape(zipValue), true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}
}
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
</script>
<?
$_GET['ID'] = abs((int) $_GET['ID']);
print "<table width=75% border=2><tr><td>Inbox</td> <td>Sent Messages</td> <td>Compose Message</td> <td> Messages</td> <td>Archive Messages</td></tr> </table>
";
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;
default:
mail_inbox();
break;
}
function mail_inbox()
{
global $ir,$c,$userid,$h, $http;
print "Only the last 25 messages sent to you are visible.
<table width='95%' border=2><tr class='headercolor'><th>From</th><th>Subject/Message</th></tr>";
$q=mysql_query("SELECT m.mail_subject,m.mail_to,m.mail_from,m.mail_id,m.mail_time,m.mail_read, 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",$c);
while($r=mysql_fetch_array($q))
{
$sent=date('F j, Y, g:i:s a',$r['mail_time']);
print "<tr><td>";
if($r['userid'])
{
print "{$r['username']} [{$r['userid']}]";
}
else
{
print "SYSTEM";
}
$fm=urlencode($r['mail_id']);
if(!$r['mail_subject']) { $r['mail_subject'] = "No Subject"; }
if(!$r['mail_read']) { $ur="
New!"; } else { $ur=""; }
print "$ur</td>\n<td>{$r['mail_subject']}, Sent at: $sent
(Reply |
[/url] |
Report)</td><td><a onClick='showMail({$r['mail_id']})'></a></td></tr>
<tr><td colspan='3'><div id='div_mail_{$r['mail_id']}' style='display: none;'></div></td></tr>";
}
print "</table>";
}
function mail_outbox()
{
global $ir,$c,$userid,$h, $http;
print "Only the last 25 messages you have sent are visible.
<table width=75% border=2><tr class='headercolor'><th>To</th><th>Subject/Message</th><th></th></tr>";
$q=mysql_query("SELECT m.mail_id,m.mail_from,m.mail_to,m.mail_time,m.mail_subject,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",$c);
while($r=mysql_fetch_array($q))
{
if(!$r['mail_subject']) { $r['mail_subject'] = "No Subject"; }
$sent=date('F j, Y, g:i:s a',$r['mail_time']);
print "<tr><td>{$r['username']} [{$r['userid']}]</td><td>{$r['mail_subject']}, Sent at: $sent</td><td><a onClick='showMail({$r['mail_id']})'></a></td></tr>
<tr><td colspan='3'><div id='div_mail_{$r['mail_id']}' style='display: none;'></div></td></tr>";
}
}
function mail_compose()
{
global $ir,$c,$userid,$h;
print "<form action='mailbox.php?action=send' method='post'>
<table width=75% border=2> <tr>
<td>ID to send to:</td> <td><input type='text' name='userid' value='{$_GET['ID']}' /></td></tr><tr>
<td>Subject:</td> <td><input type='text' name='subject' /></td></tr><tr>
<td>Message:</td>
<td><textarea rows=5 cols=40 name='message'></textarea>
= :) = ;) = :o = :D = :s
= :( = :red = :roll = :x = :green
= :| = ;( = :] = :horny = :cool</td></tr><tr> <td colspan=2><input type='submit' value='Send' /></td></tr></table></form>";
if($_GET['ID'])
{
print "
<table width=75% border=2><tr><td colspan=2>Your last 5 mails to/from this person:</td></tr>";
$q=mysql_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=mysql_fetch_array($q))
{
$sent=date('F j, Y, g:i:s a',$r['mail_time']);
print "<tr><td>$sent</td> <td>{$r['sender']} wrote: {$r['mail_text']}</td></tr>";
}
print "</table>";
}
}
function mail_send()
{
global $ir,$c,$userid,$h;
$subj=str_replace(array("'","\n"),array("''","
"),htmlentities($_POST['subject']));
$msg=str_replace(array("\n"),array("
"),htmlentities($_POST['message']));
$to= (int) $_POST['userid'];
if (eregi("(http://)|(com)|(.net)|(.org)|(.info)|(.co.uk)|(www.)", $subj)) {
die ("Quit sending off site links asshole, no one cares about your game");
}
else if (eregi("(http://)|(com)|(.net)|(.org)|(.info)|(.co.uk)|(www.)", $msg)) {
die ("Quit sending off site links asshole, no one cares about your game");
} else {
mysql_query("INSERT INTO mail VALUES ('',0,$userid,$to,unix_timestamp(),'$subj','$msg')",$c) or die(mysql_error());
print "Message sent.
> Back";
}
}
function mail_delete()
{
global $ir,$c,$userid,$h;
mysql_query("DELETE FROM mail WHERE mail_id={$_GET['ID']} AND mail_to=$userid",$c);
print "Message deleted.
> Back";
}
function mail_delall()
{
global $ir,$c,$userid,$h;
print "This will delete all the messages in your inbox.
There is NO undo, so be sure.
> Yes, delete all messages
> No, go back";
}
function mail_delall2()
{
global $ir,$c,$userid,$h;
mysql_query("DELETE FROM mail WHERE mail_to=$userid",$c);
print "All ".mysql_affected_rows($c)." mails in your inbox were deleted.
> Back";
}
function mail_archive()
{
global $ir,$c,$userid,$h;
print "This tool will download an archive of all your messages.
> Download Inbox
> Download Outbox";
}
$h->endpage();
?>