<?php
		session_start();

		$sql = "SELECT * FROM posts	WHERE post_topic = " . mysql_real_escape_string($_GET['id']);
		$posts_result = mysql_query($sql);
		$count = mysql_num_rows($posts_result);
		$post_data = mysql_fetch_assoc($posts_result);
		//echo '<pre>';
		//var_dump($post_data);
		//echo '</pre>';
 	
		$count = mysql_num_rows($posts_result);
		
		//echo '<br>';
		//echo '<br>';
		//echo $count;
		//echo '<br>';
	
	
		// compter le nombre de pages.
		$messagesParPage = 10;
		$nombreDePages=ceil($count/$messagesParPage);
					
		if(isset($_GET['page'])) // Si la variable $_GET['page'] existe...
		{
			$pageActuelle=intval($_GET['page']);
			
			$index_post = 1 + ($pageActuelle - 1) * 10;

			if($pageActuelle>$nombreDePages) // Si la valeur de $pageActuelle (le numéro de la page) est plus grande que $nombreDePages...
						{
							$pageActuelle=$nombreDePages;
						}
		}
		else // Sinon
			{
				$pageActuelle= 1; // La page actuelle est la n°1 
				$index_post = 1;		
			}		
					
		// On calcul la première entrée à lire
		$premiereEntree=($pageActuelle-1)* $messagesParPage; 
		$stop = $premiereEntree + $messagesParPage;  
					
		$sql = "SELECT * FROM posts	WHERE post_topic = '".mysql_real_escape_string($_GET['id'])."'  LIMIT $premiereEntree, $messagesParPage ";
		//echo $sql;
		$posts_result = mysql_query($sql);
		
		//$sql = "SELECT * FROM topics WHERE topic_id = " . mysql_real_escape_string($_GET['id']);
		//$topic_result = mysql_query($sql);
		//$topic_data = mysql_fetch_assoc($topic_result);
							
		//for ($i = 1; $i <= 10; $i++) 
		
		while($posts_row = mysql_fetch_assoc($posts_result))		
			{	
				$id_membre = $posts_row['post_by'];
				$sql = "SELECT * FROM membres WHERE id =  '".$id_membre."' ";
				$user_result = mysql_query($sql);
				$user_data = mysql_fetch_assoc($user_result);
				
				$chemin_avatar = "./Avatar/" .$user_data["avatar"];
			
							echo '	<div align="center">
									<div class="page" style="width:100%; text-align:left">
									<div style="padding:0px 25px 0px 25px">

									<div id="edit40195" style="padding:0px 0px 6px 0px">
		
									<table class="tborder" id="post40195" align="center" border="0" cellpadding="6" cellspacing="1" width="100%">
									<tbody>
									<tr>
									<td class="thead">
									<div class="normal" style="float:right">
									&nbsp;# '; 
							echo	$index_post;
							echo    '<strong>';
														
							echo '	</strong>&nbsp;
									</div>
									<div class="normal">
									<img title="post" class="inlineimg" src="images/post.gif" alt="post" border="0">
									&nbsp&nbsp&nbsp&nbsp';
									
							echo	date('d-m-Y ', strtotime($posts_row['post_date'])) ."  à  " .date(' H:i:s', strtotime($posts_row['post_date'])); 
									
							echo '  </div>
									</td>
									</tr>

									<tr>
									<td class="alt1" style="padding:0px">
									<table border="0" cellpadding="0" cellspacing="6" width="100%">
									<tbody>
									<tr>
									<td class="alt2">
									<img title="Avatar" src='.$chemin_avatar.' alt="avatar" border="0" height="50" width="48">
									</td>

									<td nowrap="nowrap">
									<div id="postmenu_40195">
									<span class="bigusername" style="color:#754C24;">';
									echo $user_data["login"];
									echo '</span>';
									
									$test = strcmp ( $_SESSION['login'], $user_data["login"]);
									if($test == 0 )
									{
										echo '<img class="inlineimg" src="images/connected.png" title="Membre connecté" border="0">';
									}
									else {
										echo '<img class="inlineimg" src="images/disconnected.png" title="Membre non connecté" border="0">';
									}
									
									echo '
									</div>
									</td>

									<td width="100%">&nbsp;</td>
									<td nowrap="nowrap" valign="top">
									<div class="smallfont">
									<div>Posts: xxx</div>
									<div>
        
									</div>
									</div>
				
									</td>
									</tr>
									</tbody>
									</table>
									</td>
									</tr>

									<tr>
									<td class="alt2" id="td_post_40195" style="padding-bottom:21px;">
									<div class="smallfont">';
									echo '<h3>';
									
									if( $index_post == 1) // $premiereEntree == 0
									{	echo $topic_data['topic_subject'];
									}
									else {
											echo "Réponse : " .$topic_data['topic_subject'];
										 }
										 
									echo '</h3>';
									echo '</div>
									<hr style="color:#D1D1E1" size="1">
									<div id="post_message_40195"><span class="IL_AD" id="IL_AD1">';
									echo $posts_row['post_content'];
									echo '</div>
									
									<div>__________________
									<br> 
									Signature:
									';

									echo $user_data['signature'];
									
									/*echo '
									<br></br>sign';*/

									/*
									<img border="0" alt="" src="http://www.lightroomqueen.com/images/acp_logo_140.png"></img>
									<img border="0" alt="" src="http://www.lightroomqueen.com/images/ace_logo_169.png"></img>
									<br></br>*/
									
									echo '
									
									</div>
									
									</td>
									</tr>

									</tbody>
									</table>

									</div>
									</div>	
									</div>
									</div>';
									
									$index_post = $index_post + 1;
			}
					

?>		


	<?php 

	echo '<p align="center">Page : '; 

	for($i=1; $i<=$nombreDePages; $i++) 
	{
     
		if($i == $pageActuelle) 
		{
			echo ' [ '.$i.' ] '; 
		}	
		else 
		{
			echo ' <a href="visualiser_post.php?id='.$id.'&page='.$i.'">'.$i.'</a> ';
		}
	}
	echo '</p>';

?>
