<?
require_once ("data_class.php");
class Msg extends Data {
function Language() {
// language initalization
$this->DefineLang();
}
function Init() {
$this->GetUserData();
}
function Write() {
if (isset($_POST["send_msg"])) {
$to = mysql_real_escape_string($_POST["rid"]);
$subj = mysql_real_escape_string($_POST["subj"]);
$body = mysql_real_escape_string($_POST["body"]);
mysql_query("
INSERT INTO private_msgs (id ,mfrom ,mto ,mread ,subject ,msg)
VALUES ('' , '".$_SESSION["id"]."', '$to', '0', '$subj', '$body');
");
$subj1 = "<input type='text' name='subj' value='".stripslashes($subj)."' style='width:300px;' readonly=readonly/>";
$body1 = "<textarea name='body' value='".stripslashes($body)."' style='width:300px; height:120px;' readonly=readonly></textarea>";
echo "<table width='560' align='left' border='0'><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'><b>Message sent succesfully:</b></td></tr><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Subject:<br />$subj<br />";
echo "<br />Message:<br />$body</td></tr>";
echo "</table>";
}
else
if (isset($_GET["write"])) {
$rid = mysql_real_escape_string($_GET["write"]);
$s = mysql_query("SELECT name FROM player_creatures WHERE user_id = '$rid'");
if (empty($rid) OR preg_match("/[^0-9]+/", $rid) OR mysql_num_rows($s) <= 0) {
$this->r[name] = '<i>No user selected...</i>';
$subj = "<input type='text' name='subj' style='width:300px;' readonly=readonly/>";
$body = "<textarea name='body' style='width:300px; height:120px;' readonly=readonly></textarea>";
$send = "<div style='height:12px; width:100px;'>Disabled</div>";
}
else {
$this->r = mysql_fetch_assoc($s);
$subj = "<input type='text' style='width:300px;' name='subj'/>";
$body = "<textarea name='body' style='width:300px; height:120px;'></textarea>";
$send = "<input name='send_msg' value='Send message' type='submit' />";
}
echo "<form action='?p=msg&write' method='POST'>";
echo "<table width='560' align='left' border='0'><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Send message: </td></tr><tr>";
echo "<td style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>To: ".$this->r[name]."</td></tr><tr>";
echo "<td><input type='hidden' name='rid' value='$rid'/>Subject:<br />$subj<br />";
echo "Message:<br />$body</td></tr>";
echo "<tr><td>$send</td></tr>";
echo "</table>";
echo "</form>";
}
} //
function ReadMsg($m) {
//include lang file
$this->Language();
require $this->lang;
echo "<table width='560' align='left' border='0'>";
if (empty($m) OR preg_match("/[^0-9]+/", $m)) {
echo "<tr><td>$gui_error</td></tr>";
} else {
$m = mysql_query("SELECT * FROM private_msgs WHERE id = '$m'");
$this->msg = mysql_fetch_assoc($m);
$f = mysql_query("SELECT name FROM player_creatures WHERE user_id = '".$this->msg[mfrom]."'");
$this->from = mysql_fetch_assoc($f);
mysql_query("UPDATE private_msgs SET mread = '1' WHERE id = ".$this->msg[id]." LIMIT 1");
echo "<tr><td style='border-bottom: 1px solid #ccc;'><b>From:</b> ".$this->from[name]."</td>";
echo "<td style='border-bottom: 1px solid #ccc;'><b>Subject:</b> ".$this->msg[subject]."</td></tr>";
echo "<tr><td colspan='2' style='padding-top: 8px; style='padding-bottom: 8px;'>".$this->msg[msg]."</td></tr>";
echo "<tr><td colspan='2' style='padding-top: 8px; border-top: 1px solid #ccc;'><a href='?p=msg&write=".$this->msg[mfrom]."'>Reply?</a></td></tr>";
}
echo "</table>";
}
function Inbox() {
$this->Init();
if (isset($_GET["d"])) {
$mid = $_GET["d"];
if (empty($mid) OR preg_match("/[^0-9]+/", $mid)) {
echo "<tr><td>$gui_error</td></tr>";
} else {
mysql_query("DELETE FROM private_msgs WHERE id = '$mid'");
}
} // end delete msg
if (isset($_GET["read"])) {
$this->ReadMsg($_GET["read"]);
} else
if (isset($_GET["p"]) && isset($_GET["reply"])) {
$this->Reply();
} else {
$m = mysql_query("
SELECT
private_msgs.id,
private_msgs.mfrom,
private_msgs.mto,
private_msgs.subject,
private_msgs.mread,
player_creatures.user_id,
player_creatures.name
FROM
private_msgs,
player_creatures
WHERE
private_msgs.mto = '".$this->creature[user_id]."'
AND
player_creatures.user_id = private_msgs.mfrom
ORDER BY id DESC
");
$max = mysql_num_rows($m);
echo "<table width='560' align='left' border='0'><tr>";
echo "<td colspan='3' style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>
<a href=''>Inbox($max)</a>
</td></tr><tr>";
echo "<td width='300' style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>
Subject</td><td width='160' style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>From</td>
<td width='80' style='margin-bottom: 2px; border-bottom: 1px solid #ccc;'>Delete?</td></tr><tr>";
$i = 1;
while ($i <= $max) {
$this->msg[$i] = mysql_fetch_assoc($m);
if ($this->msg[$i][mread] == 0) {
echo "<td><a href='?p=msg&read=".$this->msg[$i][id]."'>".$this->msg[$i][subject]."</a>(New)</td>";
echo "<td>".$this->msg[$i][name]."</td><td><a href='?p=msg&d=".$this->msg[$i][id]."'>[X]</a></td></tr><tr>";
} else {
echo "<td><a href='?p=msg&read=".$this->msg[$i][id]."'>".$this->msg[$i][subject]." </a></td>";
echo "<td>".$this->msg[$i][name]."</td><td><a href='?p=msg&d=".$this->msg[$i][id]."'>[X]</a></td></tr><tr>";
}
$i++;
}
echo "</tr></table>";
}
}
}
?>