<?php
	/* WebWall */
	define("ONLINE", 1);
	$root = dirname( dirname( dirname(__FILE__) ) );
	require_once "$root/core.php";
	$userProfile = text_filter(ucfirst(strtolower($_GET["user"])), 1);
	$postID = text_filter($_GET["pid"], 1);
	define("PROFILE_USER", $userProfile, true);

	if(is_numeric($postID))
	{
		$checkpostOwner = mysql_query('SELECT to_user, from_user, post, image, time, anonymous from posts where id = '.$postID);
		$checkComments = mysql_query('SELECT *  from comments where post_id = "'.$postID.'" ORDER BY id');
		$numOfposts = mysql_num_rows($checkComments);
		if(mysql_num_rows($checkpostOwner) != 0)
		{
			$pageExhibition = true;
			$pageUserExists = true;
			$getpostData = mysql_fetch_assoc($checkpostOwner);
		} 
		else 
		{
			$pageExhibition = false;
			$pageUserExists = false;
		}
	}
	
	$template_session->loadhead(''.PROFILE_USER.'');
	$template_session->loadlogo(); 
	$template_session->loadmenu(); 
	if($result["userView"] != false)
	{
		$template_session->addline('<center>');
		$template_session->loadTpl("security");
		$template_session->addline('</center>');
	}
	else
	{ 
		if($pageExhibition) 
		{
		?>
		<div id="content">
		 	<div id="commcontent">	
				<div class="post postact">  
					<div style="width:600px;display:inline-block">
						<?php
							$fromuser = $getpostData["from_user"];
							$sqlgetphoto = mysql_query("SELECT photo FROM users WHERE username = '$fromuser'");
							$iii = mysql_fetch_assoc($sqlgetphoto);
							if(!$iii['photo']) $iii['photo'] = "photo_anonymous.png";
						?>
						<?php if($fromuser!="" && $fromuser!=SITE_NAME) { ?>
							<a href="http://<?php echo SITE_DOMAIN; ?>/<?php echo $fromuser; ?>">
								<img src="media/images/users/<?php echo $iii['photo']; ?>" id="postavatar" style="float:left;" />
							</a>
						<?php } else { ?>
							<img src="media/images/users/photo_anonymous.png" id="postavatar" style="float:left;"/>
						<?php } ?>
							<div style="width:600px">
								<h4> <?php echo getsmiles(txt2link($getpostData["post"])); ?></h4>
								<?php if($getpostData["image"]!="") $imgrespond = "<a href='http://".SITE_DOMAIN."/image/".$fromuser."/".$postID."'><img src='http://". SITE_DOMAIN ."/media/images/answers/".$getpostData["image"]."' width='300px'/></a>";
									  else $imgrespond =""; ?>
								<p><?php echo getsmiles(txt2link($getpostData["answer"])) . "<br />" . $imgrespond; ?></p>
								<span id="postInfo">
									<?php echo langVar(64); ?> <?php echo counttime(usertime($getpostData["date"].' '.$getpostData["time"])); if($getpostData["anonymous"] != 1) { ?> <?php echo langVar(66); ?> <a href="http://<?php echo SITE_DOMAIN; ?>/<?php echo $getpostData["from_user"]; ?>"><?php echo $getpostData["from_user"]; ?></a><?php } else { ?>, <?php echo langVar(82); ?><?php } ?> <?php echo langVar(90); ?> <a href="http://<?php echo SITE_DOMAIN; ?>/<?php echo $getpostData["to_user"]; ?>"><?php echo $getpostData["to_user"]; ?></a>
								</span>
							</div>
							<div class="clear"></div>
					</div>
					<span id="post<?php echo $postID; ?>"><?php echo ''.getlikes($postID,8,PROFILE_USER,0).''; ?><span class="clear"></span></span>
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
				<div id="comments">
					<ul id="commentslist" class="comments">
					<?php
						if($numOfposts != 0)
						{ 
							while($getQD = mysql_fetch_assoc($checkComments))
							{
								$fromuser = $getQD["from_user"];
								$sqlgetphoto = mysql_query("SELECT photo FROM users WHERE username = '$fromuser'");
								$iii = mysql_fetch_assoc($sqlgetphoto);
								if(!$iii['photo']) $iii['photo'] = "photo_anonymous.png";
								if($iii['photo'] != "photo_anonymous.png")
								{ 
									$msg = '<a href="http://'.SITE_DOMAIN.'/'.$getQD["from_user"].'"><img src="media/images/users/'.$iii['photo'].'" id="postavatar" /></a>'.$getQD["from_user"]; 
								} 
								else 
								{ 
									$msg = '<img src="media/images/users/photo_anonymous.png" id="postavatar" /> '.langVar(300); 
								}
								$html .= '<li id="comment'.$getQD["id"].'" style="display: list-item;" class="commentbox">';
								$html .= '<div id="commentname">'.$msg.':</div>';
								$html .= '<div id="commenttext">';
								$html .= getsmiles(txt2link($getQD["comment"]));
								$html .= '</div>';
								$html .= '<a class="commentDate">'.langVar(420).' '. counttime(usertime($getQD["time"])). '</a>&nbsp;&nbsp;';
								$html .= '</li><span class="clear"></span>';  
							}
							echo $html;
						}
						else echo '<span class="nocomm">'.langVar(67).'</span>';
					?>
					<div class="clear"></div>
					</ul>
				</div>
				<div id="addcomment">
					<h3><?php echo langVar(416); ?>:</h3>
					<form method="post" id="commentForm" onsubmit="addComment('<?php echo $postID; ?>'); return false;">
						<textarea name="comment" id="comment" maxlength="255" rows="4"></textarea>
						<div class="radios" style="margin:0">
							<a id="sendButton" class="btn btn-primary" onclick="addComment('<?php echo $postID; ?>')"><?php echo langVar(417); ?></a>
							<div class="clear"></div>
							<img id="sendIndicator" src="media/images/indicator.gif" alt="." style="display:none;" />
							<?php if(SESSION_STATUS!="")  { ?>
								<label for="anonymous" style="margin-top:10px;padding-bottom:10px;display:block"><input type="checkbox" name="anonymous" value="1" id="anonymous" /> <?php echo langVar(82); ?></label>
							<?php } else { ?>
								<label for="anonymous" style="margin-top:10px;padding-bottom:10px;display:block"><input name="anonymous" type="hidden" value="1" id="anonymous" /></label>
							<?php } ?>
						</div>
					</form>
					<div id="commentSuccess" class="commentSuccess" style="display:none">
						<?php echo langVar(418); ?>. <a href="javascript://" onclick="commentAgain()" class="nofollow"><?php echo langVar(419); ?></a>      
					</div>
				</div>
				<div class="clear"></div>
		 	</div>
		</div>
		<div id="footerspace"></div>
	</div>
	<?php } 
		if(!$pageExhibition) { ?>
			<div id="content">    
				<noscript><div class="error"><b>ERROR:</b> JavaScript is not enabled. You must enable JavaScript to use the application.</div></noscript>   
				<h1>Unknown post</h1>    
				<p>The requested post does not exist, <a href="">click here</a> to visit the home page.</p>  
			</div>
			<div id="footerspace"></div>
			</div>
		<?php 
		} 	
	}
	$template_session->loadtpl("footer");
	$template_session->loadend();
 ?>
