<?php
include_once("includes/header.php");
?>

<?php

$message_ID = (int)$_GET['ID'];

mysql_query("UPDATE User_Messages SET open_flag=1 WHERE ID=".$message_ID);

$result = mysql_query("SELECT User_Messages.*,CONCAT(Users.first_name,' ',Users.last_name) as 'name',UNIX_TIMESTAMP(User_Messages.TS) as 'timestamp' FROM User_Messages,Users WHERE Users.ID = User_Messages.from_user_ID AND User_Messages.ID = ".$message_ID." LIMIT 1");
$message = mysql_fetch_assoc($result);

?>
<div id="message-view">
	<h2><?=$message['subject'];?></h2>
	<h3>
		<?php
		$query = sprintf("SELECT photo_URL FROM `Users` WHERE `ID`='%s'",
		mysql_real_escape_string($message['from_user_ID']));
		$extension = mysql_result(mysql_query($query),0);
		$thumb_image_location = 'images/profiles/thumbnail_'.$message['from_user_ID'].'.'.$extension;
		if(file_exists($thumb_image_location))
			print '<img style="float: left;" src="'.$thumb_image_location.'" alt="Thumbnail Image"/>';
		?>
		From <b><?=$message['name'];?></b>
		Sent 
			<b><?=date("F jS",$message['timestamp']);?></b>
			at <?=date("g:i a",$message['timestamp']);?>
	</h3>
	<div id="body">
	<?=$message['body'];?>
	</div>

	<br>
	<?php
	//Yes, should be done with a div, but in the interest of getting this done, see below
	?>
	<table width="100%">
		<tr>
			<td style="text-align:right" width="50%">
				<form action="message_compose.php" method="POST" id="action-reply" style="float:right">
					<input type="hidden" class="hidden" name="message_ID" value="<?=$message['ID'];?>">
					<input type="hidden" class="hidden" name="action" value="reply">
					<input type="submit" class="submit" value="Reply">
				</form>
			</td>
			<td style="text-align:left" width="50%">
				<form action="message_inbox.php" method="POST" id="action-delete">
					<input type="hidden" class="hidden" name="action" value="delete">
					<input type="hidden" class="hidden" name="message_ID" value="<?=$message['ID'];?>">
					<input type="submit" class="submit" value="Delete">
				</form>
			</td>
		</tr>
	</table>

	<br style="clear:both"/>
</div>


<?php
include_once("includes/footer.php");
?>
