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

?>
<form action="forum_create_topic.php" method="GET" class='action'>
	<input type=submit class="submit" value="New Topic">
</form>



<h2>National Forum</h2>
<table width="100%" cellspacing="0" id="forum">
	<thead>
		<tr>
			<th width="305" style="text-align:left">Date of Original Posting</th>
			<th style="text-align:left">Topic</th>
			<th width="220">Topic Author</th>
			<th width="20">Posts</th>
		</tr>
	</thead>
	<tbody>
<?php
$result = mysql_query("SELECT 
		Forum_Topics.ID,
		Users.ID as 'user_ID', 
		Users.first_name, 
		Users.last_name, 
		Forum_Topics.topic, 
		UNIX_TIMESTAMP(Forum_Topics.TS) as 'timestamp',
		COUNT( Comments.ID ) as 'count'
	FROM 
		Forum_Topics, Users, Comments
	WHERE 
		Forum_Topics.user_ID = Users.ID
		AND Comments.forum_topic_ID = Forum_Topics.ID
	GROUP BY Comments.forum_topic_ID
	ORDER BY Forum_Topics.TS DESC");

while($topic = mysql_fetch_assoc($result)){
	?>
	<tr>
		<td><?=format_datetime($topic['timestamp']);?> </td>
		<td style="text-align:left"><a href="forum_view_topic.php?ID=<?=$topic['ID'];?>"><?=$topic['topic'];?></a></td>
		<td style="text-align:center"><a href="profile_user.php?ID=<?=$topic['user_ID'];?>"><?=$topic['first_name'].' '.$topic['last_name'];?></a></td>
		<td style="text-align:right"><?=$topic['count'];?></td>
	</tr>
	<?php
}
?>
	</tbody>
</table>

<script type="text/javascript">
	$('table#forum tr:odd').css({'background-color' : '#f2f8ff'});
</script>

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