<?php
include ('logue.php'); 
include ('entete2.php');
include ('entete.php');
include ('ressource.php');

echo"
<style>
input {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
textarea {
border:1px solid #7E7E7E;
background-color:#000000;
font-family:'trebuchet ms',sans-serif;
color:white;
}
select, option {
background-color:#000000;
color:white;
}
</style>
<STYLE TYPE=text/css>
.Style1 {color: #0000FF}
.Style2 {color: #FF0000}
</STYLE>";
echo"<div align=\"center\"><form name=\"colo\" method=\"post\" action=\"colonie.php\" target=\"_parent\">
<table align=\"center\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
   <tr>
     <td width=\"100\" rowspan=\"2\" valign=\"middle\">
       <div align=\"center\">
         <input name=\"page\" value=\"" . $PHP_SELF . "\" type=\"hidden\" id=\"page\">
         <select name=\"idcolo\" onchange=submit()>";
include ('colo2.php'); 


	
$pts = $_POST["pts"];
$page = intval($_POST["page"]);

if(empty($pts)) {
$pts="pts"; }
if(empty($page)) {
$page=0; }


echo"<form name=\"stat\" id=\"stat\" method=\"post\" action=\"stat.php\" target=\"_parent\">
  <table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
    <tr style =\"background-color:#222222;\">
      <td>Classement par : </td>
      <td><select name=\"pts\">
        <option value=\"pts\"";
if($pts == "pts") {echo" selected"; }
		echo">Classement G&eacute;n&eacute;ral</option>
		<option value=\"pts_ally\"";
if($pts == "pts_ally") {echo" selected"; }
		echo">Classement Alliances</option>
        <option value=\"pts_flotte\"";
if($pts == "pts_flotte") {echo" selected"; }
		echo">Classement Flotte</option>
        <option value=\"pts_bats\"";
if($pts == "pts_bats") {echo" selected"; }
		echo">Classement Batiments</option>
        <option value=\"pts_tech\"";
if($pts == "pts_tech") {echo" selected"; }
		echo">Classement Technologies</option>
        <option value=\"pts_def\"";
if($pts == "pts_def") {echo" selected"; }
		echo">Classement D&eacute;fense</option>		
            </select><select name=\"page\">";
	
$reqtotal = "SELECT COUNT(id) FROM matgraph_users WHERE id=idjoueur AND galaxi > 0";
$restotal = mysql_query($reqtotal) or die('Erreur SQL! <br>'.$reqtotal.'<br>'.mysql_error());
$numtotal = mysql_result($restotal,0)+1;	

for ($i = 0; $i <= $numtotal; $i+=100) {
   echo" <option value=\"".$i."\""; if ($page == $i) { echo" selected"; } echo">Top ". ($i + 100) ."</option>";
}

echo"</select><input type=\"submit\" name=\"Submit\" value=\"Voir\"></td>
    </tr>
  </table>
</form>";

//sécu

	
if ((preg_match("/union/i", $page)) || (preg_match("/select/i", $page)) || (preg_match("/update/i", $page)) )
{
exit;
}

if ((preg_match("/union/i", $pts)) || (preg_match("/select/i", $pts)) || (preg_match("/update/i", $pts)) )
{
exit;
}

if($pts != "pts" && $pts != "pts_ally" && $pts != "pts_flotte" && $pts != "pts_bats" && $pts != "pts_tech" && $pts != "pts_def") {
	exit;
}

if($pts == "pts_ally") {
$req5 = "SELECT ally FROM matgraph_users WHERE id=$idlogin ORDER by id ASC";
$res5 = mysql_query($req5) or die('Erreur SQL! <br>'.$req5.'<br>'.mysql_error());
$row5 = mysql_fetch_array($res5);
echo"<table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
  <tr style =\"background-color:#222222;\">
    <td width=\"69\" height=\"30\" align=\"center\"><b>Classement</b></td>
    <td width=\"319\" height=\"30\" align=\"center\"><b>Nom</b></td>
	<td width=\"60\" height=\"30\" align=\"center\"><b>Membres</b></td>
    <td width=\"60\" height=\"30\" align=\"center\"><b>Points</b></td>
	<td width=\"60\" height=\"30\" align=\"center\"><b>Ratio</b></td>
  </tr>";
$req = "SELECT id,nom,tag,$pts FROM matgraph_ally WHERE $pts != 0 ORDER BY $pts DESC limit $page,100";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 )
{
  $i=1;
  
  While ( $row = mysql_fetch_array($res) ) {
$req4 = "SELECT id FROM matgraph_users WHERE ally='$row[id]' AND id=idjoueur ORDER by id ASC";
$res4 = mysql_query($req4) or die('Erreur SQL! <br>'.$req4.'<br>'.mysql_error());
$num4 = mysql_num_rows($res4);

$i2=number_format($i, 0, ',', ' ') ; 
$pts2 = number_format(floor($row[$pts] / 1000), 0, ',', ' ') ; 
$lire = "lire";
$idform = $lire.$i;
if( $num4 != 0 ) {
	$ratio = number_format(($row[$pts] / 1000) / $num4, 2, ',', ' ') ;
} else {
	$ratio = 0;
}
echo"<tr";
// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
	echo">
    <td align=\"center\">$i2</td>
	<form name=\"$idform\" id=\"$idform\" method=\"post\" action=\"ally_voir.php\" target=\"_blank\" width=\"618\">
	<input type=\"hidden\" name=\"id\" value=\"$row[id]\">
    <td align=\"center\"";if($row[id] == $row5[ally]) {echo' style ="background-color:#006633;"' ; }
	echo"><a href=\"#\" target=\"_parent\" Onclick=\"document.getElementById('$idform').submit()\"><font color=\"FF9933\">[$row[tag]]</font></a> $row[nom]</font></td></form>
	<td align=\"center\">$num4</td>
    <td align=\"center\">$pts2</td>
	<td align=\"center\">$ratio</td>
  </tr>";
  $i++;}
}
  
echo"</table>";
exit; }

echo"<table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
  <tr style =\"background-color:#222222;\">
    <td width=\"69\" height=\"30\" align=\"center\"><b>Classement</b></td>
    <td width=\"222\" height=\"30\" align=\"center\"><b>Login</b></td>
    <td width=\"319\" height=\"30\" align=\"center\"><b>Nombre de points</b></td>
  </tr>";
$req = "SELECT id,ally,login,$pts FROM matgraph_users WHERE id=idjoueur AND galaxi > 0 ORDER BY $pts DESC limit $page,100";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 )
{
  $i= $page + 1;
  
  While ( $row = mysql_fetch_array($res) ) {

if($row[id] !== "1")
{
  
$i2=number_format($i, 0, ',', ' ') ; 
$pts2 = number_format(floor($row[$pts] / 1000), 0, ',', ' ') ; 
$ally =""; 
$sql21 = "SELECT tag FROM matgraph_ally WHERE id='$row[ally]'";
$res21 = mysql_query($sql21)or die('erreur sql<br>'.$sql21.'<br>'.mysql_error());
$num21 = mysql_num_rows($res21);
if ($num21 > 0 AND $row1[ally] !== "no") {
  While ( $row21 = mysql_fetch_array($res21) ) {
$ally ="$row21[tag]";
}}
$plan1 = "";
if (!empty($ally) )
  $plan1.="<font color=\"FF9933\">[$ally]</font>";
$lire = "lire";
$idform = $lire.$i;
echo"<tr";
// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
	echo">
    <td align=\"center\"";if($row[id] == $idlogin) {echo' style ="background-color:#006633;"' ; }
	echo">$i2</td>
	<form name=\"$idform\" id=\"$idform\" method=\"post\" action=\"ally_voir.php\" target=\"_blank\" width=\"618\">
	<input type=\"hidden\" name=\"id\" value=\"$row[ally]\">
    <td align=\"center\"><a href=\"#\" target=\"_parent\" Onclick=\"document.getElementById('$idform').submit()\">$plan1</a> ";
	
	if($row[id] == "1") {echo "<font color=\"CC66CC\">"; }  echo" $row[login]</td></form>
    <td align=\"center\">"; if ($row[$pts] == "0") {echo"<font color=\"222222\">$pts2</font>"; } else { echo"$pts2"; } echo"</td>
  </tr>";
  $i++;
}  
  }
}
  
//echo"</table><br><div align=\"center\"><font color=\"CC66CC\">Admin : A attaquer à vos risques et périls ! Hahaha :D </font>";
?>