<? 
	require_once("includes/config.php");
	
	if(!isset($_GET["id"]) || empty($_GET["id"]))
	{
		blog_redirect("index.php");
	}

	// grab the post id from the query string "id" parameter
	$id = mysql_real_escape_string($_GET['id']);
	
	// select post by id and join with users table
	$result = mysql_query("SELECT posts.*, CONCAT(users.first_name, ' ', users.last_name) as author FROM posts JOIN users ON posts.user_id = users.id WHERE posts.id = $id ORDER BY posts.date desc");
	if($result === FALSE)
	{
		exit( "Could not query database: " . mysql_error() );
	}
	
	// verify we found a post with that id, if not redirect to index.php
	if(mysql_num_rows($result) != 1)
	{
		blog_redirect("index.php");
	}
	
	// retrieve the post as an object from the result set
	$post = mysql_fetch_object($result);
	
	// look for feedback object in the session
	if(isset($_SESSION[BLOG_FEEDBACK]))
	{
		$feedback = $_SESSION[BLOG_FEEDBACK];		
		unset($_SESSION[BLOG_FEEDBACK]);
	}
?>

<? require_once("templates/begin.php"); ?>

<div id="contentnav">
	<h6><a href="index.php">&#60; home</a></h6>
</div>

<?
	// display the post, do not show the title as a link, do show the comments, and pass along the feedback object
	blog_displaypost($post, FALSE, TRUE, $feedback);
?>

<? require_once("templates/end.php"); ?>