<?php
require_once("includes/user_data.php");

$profile_user_ID = (int)$_GET['ID'];
if($profile_user_ID<1)
	header("Location:district.php?error=It seems that that user does not exist.");
else{
	$result = mysql_query("SELECT *,UNIX_TIMESTAMP(join_TS) as 'timestamp' FROM Users WHERE ID = ".$profile_user_ID);
	$profile = mysql_fetch_assoc($result);
}

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

?>



<?php


if((int)$profile_user_ID != (int)$user_data['ID']){
	?>
	<form action="message_compose.php" method="GET" class="action">
		<input type="hidden" class="hidden" name="to_user_ID" value="<?=$profile['ID'];?>">
		<input type=submit class="submit" value="Send Message">
	</form>
<?php
}
else{
?>
	<form action="profile_user_edit.php" method="GET" class="action">
		<input type=submit class="submit" value="Edit My Profile">
	</form>	
<?php
}
?>


<h2><?=$profile['first_name'].' '.$profile['last_name'];?>'s Profile</h2>

<?php 
$query = sprintf("SELECT photo_URL FROM `Users` WHERE `ID`='%s'",
mysql_real_escape_string($profile_user_ID));
$extension = mysql_result(mysql_query($query),0);
$thumb_image_location = 'images/profiles/thumbnail_'.$profile_user_ID.'.'.$extension;
if(file_exists($thumb_image_location))
	print '<img src="'.$thumb_image_location.'" alt="Thumbnail Image"/>';
?>

<label>Email:</label>
<input type="text" value="<?=$profile['email'];?>" class="large">

<label>City, State</label>
<input type="text" value="<?php

if(isset($profile['city']) && strlen($profile['city'])>0 )
	echo $profile['city'];
else
	echo "Not set yet";
	
	echo ", ";

if(isset($profile['state']) && strlen($profile['state'])>0 )
	echo $profile['state'];
else
	echo "Not set yet";

?>" class="large">

<p>
	
	Member since <?=format_datetime($profile['timestamp']);?>. 

</p>

<h3>Most Recent Forum Posts</h3>
<ul id="forum" class="comments">
	<?php
	$comment_count = 0;

	$Comments = new Comments($profile_user_ID,0,0);
	
	$comments = $Comments->getComments();
	if($comments != FALSE)
		foreach($comments as $comment){
			$comment_count++;
			?>
			<li>
				<span class='number'><?=$comment_count;?></span>
				<h4 style='margin-top:0px;'><a href="forum_view_topic.php?ID=<?=$comment['forum_topic_ID'];?>#comment<?=$comment['ID'];?>"><?=$comment['topic'];?></a></h4>

				<p class="post">
					<?=stripslashes($comment['body']);?>
				</p>
				<div class="attribution">
					Posted on <b><?=format_datetime($comment['timestamp']);?></b>
				</div>
			</li>
			<?php
		}
	
?>
</ul>



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


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