Location: PHPKode > projects > Terra Nova > messages.php
<?php

$require_login = true;
$gamescript = true;
$summaryscript = true;

include("common.php");

if(!isset($action))
{

$newnumber = $db->selectcount("*","privatemessages","WHERE message_to='$userinfo[userid]' AND message_read='n'");

$messageheader = $page->FetchTemplate("PMHeader");

$messagehtml .= $messageheader;

//

$messages = $db->select("*","privatemessages","message_to='$userinfo[userid]'",0);

while($row = mysql_fetch_array($messages))
{

$messagehtml .= "<TR>";
$messagehtml .= "<TD CLASS=\"genericbox1_body\"><A CLASS=\"nav\" HREF=\"messages.php?action=read&mid=$row[message_id]\">$row[message_subject]</A></TD>";
$sendername = $user->getusername($row[message_from]);
$messagehtml .= "<TD CLASS=\"genericbox1_body\">$sendername</TD>";
$datetime = date("F j, Y, g:i a",$row[message_timestamp]); 
$messagehtml .= "<TD CLASS=\"genericbox1_body\">$datetime</TD>";
$messagehtml .= "<TD CLASS=\"genericbox1_body\">$row[message_read]</TD>";
$messagehtml .= "</TR>";

}

//

$messagehtml .= "</TABLE>";

$page->Assign("newnumber",$newnumber);
$content = newbox("Private Messages",$page->FetchTemplate("PrivateMessagesMenu")) . "<BR>" . newbox("Messages",$messagehtml);
$page->Assign("content",$content);

$page->Display("template");


}
elseif($action=="send")
{

if(!isset($step))
{
//go through list of users...
$usersres = $db->select("user_id,user_screenname","users","user_id>0",0);
while($row = mysql_fetch_array($usersres))
{
$touserhtml .= "<option value=\"$row[user_id]\">$row[user_screenname]</option>";
}

$page->Assign("touserhtml",$touserhtml);
$page->Assign("fromusername",$username);
$content = newbox("Send Private Message",$page->FetchTemplate("PrivateMessageSend"));
$page->Assign("content",$content);

$page->Display("template");
}
else
{

//send message...

$db->insert("privatemessages","$input_to:$userinfo[userid]:$input_subject:$input_content:$timestamp:N",1);

$content = newbox("Sending Private Message",$page->FetchTemplate("MessageSent"));

$page->Assign("content",$content);

$page->Display("template");

}

}
elseif($action=="read")
{

if(!isset($mid))
{
$page->Assign("content",newbox("Read Message","Sorry, but that is an invalid message ID<BR>Please click <A CLASS=\"nav\">here</A> to return to the private message index"));
$page->Display("template");
}
else
{

$message = $db->select("*","privatemessages","message_id='$mid'",1);

$datetime = date("F j, Y, g:i a",$message[message_timestamp]); 

$page->Assign("fromtext",$user->getusername($message[message_from]));
$page->Assign("receiveddate",$datetime);
$page->Assign("subjecttext",$message[message_subject]);
$page->Assign("messagetext",$message[message_text]);
$pmhtml = $page->FetchTemplate("ReadPM");
$page->Assign("content",newbox("Read Message",$pmhtml));
$page->Display("template");
}
}

?>
Return current item: Terra Nova