<?php
/*
This file accessess the history of the previous postings for a user. 
*/
session_start();
require_once("includes/mysql_login.php");
if(!isset($_SESSION['autheticate']))
{
	header("Location: index.php");
	exit;
}
include("header.htm");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>IEEE Student Chapter| Account History </title>
<link rel="stylesheet" href="includes/style.css" type="text/css" /></head>
<body> 
<?php
echo "<div class=left>";
include("includes/left.htm");
echo "</div>";
echo "<div class = body>"; 
$userid = $_GET[userid];
$user_name_date = "SELECT * FROM `user` where identification = $userid";
$user_name_date_query = mysql_query($user_name_date);
while($user_row_query_result = mysql_fetch_array($user_name_date_query))
{
	echo "Your account summary <br>";
	echo "<b>Username: ". $user_row_query_result[username] . "</b><br>";
	echo "<b>Date Created: ". $user_row_query_result[date_created] . "</b><br>";
}
$query   = "SELECT COUNT(*) AS numrows FROM post where identification = $userid";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
echo "Number of Post <b>" . $numrows = $row['numrows'] . "</b><br>";
/*
Multipaging algorithm starts here. 
*/
$rowPerPage = 2;
$pageNum = 1; 
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowPerPage;
$read_post = "SELECT * FROM `post` where identification = $userid ORDER BY `date_created` DESC LIMIT $offset, $rowPerPage";
$PageMax = ceil($numrows/$rowPerPage);
$self = $_SERVER['PHP_SELF']; 
$nav = '';
for($page = 1; $page <= $PageMax; $page++)
		{
			if($pageNum == $page)
			{
			$nav = $nav. " $page";
			} else
			{
			$nav = $nav."<a href = \"$self?page=$page&userid=$userid\">$page ||</a>";
			}
		}
			if($pageNum > 1)
			{
				$page = $pageNum - 1;
				$prev = "<a href = \"$self?page=$page&userid=$userid\">[prev]</a>";
				$first = "<a href = \"$self?page=1&userid=$userid\"><< </a>";
			
			} else
			{
				$prev = "";
				$first = "";
			}
			if($pageNum < $PageMax)
			{
				$page = $pageNum + 1;
				$next = "<a href = \"$self?page=$page&userid=$userid\">[next]</a>";
				$last = "<a href = \"$self?page=$PageMax&userid=$userid\"> >> </a>";
			} else 
			{
				$next = "";
				$last = "";
			}
$user_post_result = mysql_query($read_post) or die ('Error, query failed');
echo "<i><h4>Your Posting summery </h4></i>";
while($user_post_result_row = mysql_fetch_array($user_post_result))
{ 
			echo "<h4>Title: ". $user_post_result_row[title] . "</h4>";
			echo "<table width=727 border=0 bgcolor=#999999>";               // Create the table with different background for odd and even row
			echo "<tr>";
			echo "<td>";
		echo "<i>Category:</i> ". $user_post_result_row[category]. "<br>";
		echo "<b>Post:<br></b> ". $user_post_result_row[post]. "";
		if($user_post_result_row[attachment] != NULL)
		{
		echo "<i><a href=file_upload/$user_post_result_row[attachment]> Attachment</a></i><br>"; 
		} 
		echo "Date submitted : " . $user_post_result_row[date_created] ;
		 include("includes/getcomment.php") ;
		echo "</td>";
		echo "</tr>";
		echo "</table>";
} 
echo "<br>$first$nav$last" ;
echo "</div>";
include("bottom.htm");
?>
</body>
</html>