<?php

	session_start();

	//header("Cache-Control: no-cache, must-revalidate");
	header("Cache-Control: no-cache");
	header("Pragma: no-cache"); 

	include('database.php');
	DB_connexion(); 
   
    $msgs=mysql_query('SELECT * FROM tchat ORDER BY id DESC LIMIT 0,50');
	$cpt = 0;
																		
	while($infos = mysql_fetch_array($msgs)) 
		 {
			$champ = date('d-m-Y ', strtotime($infos["date_mess"])) ."  à  " .date(' H:i:s', strtotime($infos["date_mess"])); 
			$utilisateur = $infos["login"];
			$txt = $infos["mess"];
			$id = $infos["id"];
			$destinataires = $infos["destinataires"];
								
			$pieces = explode(",", $destinataires);
			$nb_elements = count($pieces);
										
			$flag_login = false;
										
			for($i = 0; $i < $nb_elements; $i++)
				{	$element = $pieces[$i];
					if($element == $_SESSION['login'])	
		 			  {  $flag_login = true;
						 echo '<div class="pseudo"><img src="images/puce_tchat_login.jpg" />&nbsp;'.$utilisateur.'</div> ';
						 if($cpt%2 == 1) /* impair */
						    echo '<div class="affiche_message_pair">'.$txt.'</div>';
						 else /* pair */
							echo '<div class="affiche_message_impair">'.$txt.'</div>';
						echo '<div class="date">'.$champ.'<img src="images/puce_tchat_date.jpg" /></div>';
						$cpt = $cpt + 1;
					 }
				}
		}             
    

?>