<?php
	session_start();
	include('database.php');
	DB_connexion(); 
	error_reporting( 0 );
	
	/*if(!isset($_SESSION['logged']) )
	{		header ('Location: interdiction.php');
	}
	
	if($_SESSION['logged']== "no")
	{
		header ('Location: interdiction.php');
	}*/
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="Site perso,cours,ouvrages" />
<meta name="Keywords" content="WEBSITE perso " />
<meta name="Distribution" content="Global" />
<meta name="Robots" content="" />
<meta http-equiv="Content-Language" content="fr" />
<meta name="rating" content="general" />
<meta name="author" content="Patrice DELPY" />
<meta name="copyright" content="Copyright 2013" />
<meta name="generator" content="Patoche" />
<title>Patoche WEBSITE - 2013 - Template du site - en cours de développemment ...Classement ELO</title>

<!---------------------------------------------------------->	
<?php
		include('include_css_template_commun.php');
		include('include_css.php');
		include('css_tools_skill.php');
		include('include_javascript.php');
?> 

<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>


<style type="text/css">
#bloc_classement_joueur { float: left;
					width: 831px; 
					padding: 50px 50px 25px 50px;
					}	
					
#navigation_tournoi{
					float: left;
					width: 910px; // 870
					padding: 10px 0px 0px 10px;
					text-align: center;
		}
					
</style>

<script type="text/javascript">

function call_update()
{
			scruter(); 
			setTimeout("call_update()", 1000); 
}

function scruter()
{
			var xhr = getXhr()
			// On défini ce qu'on va faire quand on aura la réponse
			xhr.onreadystatechange = function()
			{
					// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
					if(xhr.readyState == 4 && xhr.status == 200)
					{
						//alert(xhr.responseText);
						retour = xhr.responseText;
						
						if(retour == 0)
						{  	
		
							$(function()
							{
									$( "#message_expiration" ).dialog({
									modal: true,
									title: "Infos",
									buttons: {
												Ok: function()
												{
													$( this ).dialog( "close" );
													 document.location.href = "logout_expire.php";
												}
											 }
										});
							});
							
							
						}
	
						
						
					}
			}
					
			xhr.open("GET","session_timeout.php",true);
			xhr.send(null);
}
</script>

<!---------------------------------------------------------->	
</head>

<body>
<!---------------------------------------------------------->	
	<div class="main"> <!-- main -->
<!---------------------------------------------------------->	

			<div class="header">
                <div class="balise_titre">Patoche</div>
                <div class="balise_citation">
                &quot;Etre conscient que l'on est ignorant est un grand pas vers le savoir&quot;
                </div>
			</div> 
 
			<div class="banniere"></div>  

<!---------------------------------------------------------->
<?php
/*	include("include_barre_login.php");
	echo '<div id="box_icon">';
	include("debug_connexion_membre.php");
	echo '</div>';
	include("include_menu.php");*/
	
	echo '<div id="box_infos">';
			include("include_menu.php");
			
			echo '<div id="box_icon2">';
			include("connexion_membre.php");
			echo	'</div>';
			
			echo '<div id="box_icon3">';
			include("include_barre_login.php");
			echo	'</div>';

	echo	'</div>';
	$_SESSION['page_active'] = basename (__FILE__ );
?>
		

<!---------------------------------------------------------->	
            <div class="contenu"> <!-- contenu -->
<!---------------------------------------------------------->	
	
			<div class="barre_vide"></div>
			
			<div id="navigation_tournoi">
				<ul id="menu_horiz">
				<li class="tournoi_partie_tag"><a href="partie.php" title="aller à la section">Duel</a></li>
				<li class="tournoi_simulation_tag"><a href="simulation.php" title="aller à la section">Sim</a></li>
				<li class="tournoi_classement_tag_selected"><a href="classement.php" title="aller à la section">ELO</a></li>
				<li class="tournoi_master_tag"><a href="on_chess_master.php" title="aller à la section">Master</a></li>
				<li class="tournoi_liste_joueurs_tag"><a href="joueurs_echec.php" title="aller à la section">Players</a></li>
				<li class="tournoi_stats_tag"><a href="historique.php" title="aller à la section">Games</a></li>
				<li class="tournoi_securite_tag"><a href="admin.php" title="aller à la section">Admin</a></li>
				</ul>
				
			</div>
			
			<div id="bloc_classement_joueur">
	
<?php			
			$sql = "select * from classement where active=1 ORDER by elo desc ";
			$results = mysql_query($sql);
			$number = mysql_num_rows($results);
				
			//echo "<p align=center>$number joueurs en lice.</p><br>";
			echo "<p align=center>Joueurs en lice.</p><br>";
				
			echo "<table border=1 align=center width='80%'><tr>
			<th>ID</th>
			<th>Joueur</th>
			<th>ELO</th>
			<th>Parties</th>	
			<th>Victoires</th>	
			<th>Défaites</th>	
			<th>Match nul</th>
			<th>Efficacité</th>";
				
			$indice = 1;
				
			while($row = mysql_fetch_assoc($results))
			{
					$joueur = $row["joueur"]; 
					$elo = $row["elo"];
					$parties = $row["parties"];
					$prior = $row["prior"];
					$bonus = $row["bonus"];
					
					$wins = $row["wins"];
					$losses = $row["losses"];
					$draws = $row["draws"];
					
					$toto = ($wins + 0.5 * $draws) / $parties;
					$toto = $toto * 100;
					$toto = round($toto, 2);
					$toto = $toto ." %";
					
					$oldrating=$row["oldrating"];
					$playerID=$row["id"];
					$rat_increase = $elo - $oldrating;
					
					// si partie < 20 -> italique <EM>texte en italique</EM>
					
					if ($oldrating !=0)
					{
						if ($rat_increase>0)
						{
									
							if($elo > 900 && $parties >= 20)
							{
								echo "	<tr>
									<td align=center>".$indice."</td>";
									
								/*if($parties >= 20) 		
								{	
									echo "<td align=center><a href=\"statistiques_joueurs.php?playerID=$playerID\" title='Statistiques'>".$joueur."</a></td>";
								}		
								else
								{
									echo "<td align=center><a href=\"statistiques_joueurs.php?playerID=$playerID\" title='Statistiques'><em>".$joueur."</em></a></td>";
								}*/
										
								echo "<td align=center><a href=\"statistiques_joueurs.php?playerID=$playerID\" title='Statistiques'>".$joueur."</a></td>";		
								echo "
										<td align=center>".$elo." (+".$rat_increase.")&nbsp;<img src='images/up.png' title='Derniére partie'></td>
										<td align=center>".$parties."</td>
										<td align=center>".$wins."</td>
										<td align=center>".$losses."</td>
										<td align=center>".$draws."</td>
										<td align=center>".$toto."</td>
										</tr>";
							}									
						}	 
			
						else
						{
							
							if($elo > 900 && $parties >= 20)
							{
								echo "	<tr>
										<td align=center>".$indice."</td>";
							
								/*if($parties >= 20) 		
								{		
										echo "<td align=center><a href=\"statistiques_joueurs.php?playerID=$playerID\" title='Statistiques'>".$joueur."</a></td>";
								}
								else
								{
										echo "<td align=center><a href=\"statistiques_joueurs.php?playerID=$playerID\" title='Statistiques'><em>".$joueur."</em></a></td>";
								}*/
								
								echo "<td align=center><a href=\"statistiques_joueurs.php?playerID=$playerID\" title='Statistiques'>".$joueur."</a></td>";
								echo "	<td align=center>".$elo." (".$rat_increase.")&nbsp;<img src='images/down.png' title='Derniére partie'></td>
										<td align=center>".$parties."</td>
										<td align=center>".$wins."</td>
										<td align=center>".$losses."</td>
										<td align=center>".$draws."</td>
										<td align=center>".$toto."</td>
										</tr>";
							}			
						}
					}

					else
					{
		
						echo "	<tr>
								<td align=center>".$indice."</td>";
						if($parties >= 20) 		
						{		
							echo "<td align=center><a href=\"statistiques_joueurs.php?playerID=$playerID\" title='Statistiques'>".$joueur."</a></td>";
						}
						else
						{
							echo "<td align=center><a href=\"statistiques_joueurs.php?playerID=$playerID\" title='Statistiques'><em>".$joueur."</em></a></td>";
						}
						
						echo "	<td align=center>".$elo."</td>
								<td align=center>".$parties."</td>
								<td align=center>".$wins."</td>
								<td align=center>".$losses."</td>
								<td align=center>".$draws."</td>
								<td align=center>".$toto."</td>
								</tr>";
					}
					
					$indice = $indice + 1;
					
			} 	

			echo "</table>";
			
			mysql_close();
?>

			</td>
			</tr>
			</table>
				
			<div id="message_expiration" style="display: none">
			<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			La session a expiré. veuillez vous reconnecter.
			</p>
			</div>
		
			</div>

			<br/>
			<br/>
			<br/>
			<br/>
			<br/>

<!---------------------------------------------------------->	
<?php			
    include('include_pied_page.php');
	include('include_publicite.php');
?>
<!---------------------------------------------------------->	
			</div>  <!-- contenu -->
<!---------------------------------------------------------->	
	</div>   <!-- main -->
<!---------------------------------------------------------->	

	<script type="text/javascript">
		call_update();
	</script>

</body>
</html>
