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


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

$result = mysql_query("SELECT * FROM Forum_Topics WHERE ID = ".$forum_topic_ID." LIMIT 1");
$topic = mysql_fetch_assoc($result);


?>



<h2><?=$topic['topic'];?></h2>

<?php

	if(isset($_GET['new_topic'])){
	?>
	
		<p>Now that you've created a new topic, you'll need to post the first comment. Your topic will not appear to others until you post a comment.</p>
	
	<?php
	}

?>


<ul id="forum" class="comments">
	<?php
	$comment_count = 0;

	$Comments = new Comments($user_data['ID'],0,$forum_topic_ID);
	
	$comments = $Comments->getComments();
	if($comments != FALSE)
		foreach($comments as $comment){
			$comment_count++;
			?>
			<li>
				<a name="comment<?=$comment['ID'];?>"></a>
				<span class='number'><?=$comment_count;?></span>
				<p class="post">
					<?=stripslashes($comment['body']);?>
				</p>
				<div class="attribution">
<?php 
$query = sprintf("SELECT photo_URL FROM `Users` WHERE `ID`='%s'",
mysql_real_escape_string($comment['user_ID']));
$extension = mysql_result(mysql_query($query),0);
$thumb_image_location = 'images/profiles/thumbnail_'.(int)$comment['user_ID'].'.'.$extension;
if(file_exists($thumb_image_location))
	print '<img style="float: left;" src="'.$thumb_image_location.'" alt="Thumbnail Image"/>';
?>

					<p>Posted by <b><a href="profile_user.php?ID=<?=$comment['user_ID'];?>"><?=$comment['first_name']." ".$comment['last_name'];?></b></a> on <b><?=format_datetime($comment['timestamp']);?></b></p>
				</div>
			</li>
			<?php
		}
	

?>
	<li>
		<span class='number'><?=($comment_count+1);?></span>

		<form action="forum_post.php" method="POST">
			<input type="hidden" class="hidden" name="forum_topic_ID" value="<?=$forum_topic_ID;?>">
			
			<br>
		
			<p class="post">
				<textarea name="body" rows="12" style="width:100%;"></textarea>
			</p>
		
			<div class="attribution">
				<input type="submit" class="submit" value="Post Comment">
			</div>
		</form>

	
	</li>
</ul>


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



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