<?php
include ('logue.php'); 
include ('entete2.php');
include ('entete.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>";


$nom_rechercher = $_POST["nom_rechercher"];
$ip_rechercher = $_POST["ip_rechercher"];
$recherche_doublon = $_POST["recherche_doublon"];


$form ="<br><br>
  <table width=\"618\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
<form action=\"ip.php\" method=\"post\" name=\"form1\" target=\"_parent\">
    <tr style =\"background-color:#222222;\">
      <td width=\"264\">Nom du joueur : 
      <input name=\"nom_rechercher\" type=\"text\" id=\"nom_rechercher\" value=\"$nom_rechercher\">      </td>
      <td width=\"265\">
      </td>
      <td width=\"81\"><input type=\"submit\" name=\"Submit\" value=\"Rechercher\"></td>
    </tr>
   </form><form action=\"ip.php\" method=\"post\" name=\"form1\" target=\"_parent\">
   <tr style =\"background-color:#222222;\">
      <td width=\"264\">Adresse IP : 
      <!--<input name=\"ip_rechercher\" type=\"text\" id=\"ip_rechercher\" value=\"$ip_rechercher\">-->
      <TEXTAREA name=\"ip_rechercher\" rows=3 COLS=40>$ip_rechercher</TEXTAREA> 
      
            </td>
      <td width=\"265\">
      </td>
      <td width=\"81\"><input type=\"submit\" name=\"Submit\" value=\"Rechercher\"></td>
    </tr>
    </form>
    
    <form action=\"ip.php\" method=\"post\" name=\"form1\" target=\"_parent\">
   <tr style =\"background-color:#222222;\">
      <td width=\"264\">
      <input name=\"recherche_doublon\" type=\"hidden\" value=\"oui\" id=\"recherche_doublon\">      </td>
      <td width=\"265\">
      </td>
      <td width=\"81\"><input type=\"submit\" name=\"Submit\" value=\"Rechercher les doublons\"></td>
    </tr>
    </form>
  </table>
";
echo"$form"; 
//or empty($nom_rechercher2)
if(!empty($nom_rechercher) ) {
$req = "SELECT i.ip, u.id, u.login, lc.date FROM matgraph_login_connexion lc, matgraph_users u,matgraph_login_ip i WHERE lc.ext_id_ip = i.id and lc.idjoueur = u.id and u.login = '$nom_rechercher' and u.id=u.idjoueur ";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
echo "Liste des adresses IP de <font color=yellow>$nom_rechercher</font> ($num) :<br>";
  While ( $row = mysql_fetch_array($res) ) {
    echo  " - ".$row["ip"]." => ". $row["date"]."<br>";
    /*$req2 = "SELECT i.ip, lc.date,u.login,lc.idjoueur FROM matgraph_login_connexion lc, matgraph_users u,matgraph_login_ip i WHERE lc.ext_id_ip = i.id and lc.idjoueur != ". $row["id"]." and i.ip LIKE '".$row["ip"]."'  and u.id=u.idjoueur";
    $res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
    $num2 = mysql_num_rows($res2);
    While ( $row2 = mysql_fetch_array($res2) ) {
      echo  " <font color=red>--MULTI--</font>>  ".$row2["login"]." => ". $row2["date"]." sur ".$row2["ip"]."<br>";
    }
    */
    
  } 
 }


if(!empty($ip_rechercher) ) {
$ip_rechercher2 = explode("\n",$ip_rechercher);

foreach ($ip_rechercher2 as $ip_rechercher3){
$ip_rechercher3=trim($ip_rechercher3);
if ($ip_rechercher3!=""){
$req = "SELECT i.ip, u.id, u.login, lc.date FROM matgraph_login_connexion lc, matgraph_users u,matgraph_login_ip i WHERE lc.ext_id_ip = i.id and lc.idjoueur = u.id and i.ip = '$ip_rechercher3' and u.id=u.idjoueur ";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
echo "<br><br>Liste des joueurs avec l'adresse IP <font color=yellow>$ip_rechercher3</font> ($num) :<br>";
  While ( $row = mysql_fetch_array($res) ) {
    echo  " - ".$row["login"]." => ". $row["date"]."<br>";
  }
 }
}
     } 
 if(!empty($recherche_doublon) ) {

echo "pas fini ^^";
/*
$req = "SELECT i.ip, u.id, u.login, lc.date FROM matgraph_login_connexion lc, matgraph_users u,matgraph_login_ip i WHERE lc.ext_id_ip = i.id and lc.idjoueur = u.id and i.ip LIKE '%$ip_rechercher%' and u.id=u.idjoueur ";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
echo "Liste des joueurs avec l'adresse IP <font color=yellow>$ip_rechercher</font> ($num) :<br>";
  While ( $row = mysql_fetch_array($res) ) {
    echo  " - ".$row["login"]." => ". $row["date"]."<br>";
    
    $req2 = "SELECT i.ip, u.id, u.login, lc.date FROM matgraph_login_connexion lc, matgraph_users u,matgraph_login_ip i WHERE lc.ext_id_ip = i.id and lc.idjoueur = u.id and u.login = '$row["login"]' and u.id=u.idjoueur ";
$res2 = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num2 = mysql_num_rows($res);
echo "Liste des adresses IP de <font color=yellow>$nom_rechercher</font> ($num) :<br>";
  While ( $row = mysql_fetch_array($res) ) {
    echo  " - ".$row["ip"]." => ". $row["date"]."<br>";
  }



  }*/
 }
/*
$req = "SELECT id,login FROM matgraph_users WHERE login = '$nom_rechercher' ORDER by login ASC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);

$req = "SELECT id,login FROM matgraph_users WHERE login LIKE '%$nom_rechercher2%' ORDER by login ASC";
$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num2 = mysql_num_rows($res2);

if ( $num > 0 && $num2 > 0) {

  While ( $row = mysql_fetch_array($res) ) {
    $sqlvar.="joueur1 ='".$row[id]."' or ";  
  }
  While ( $row2 = mysql_fetch_array($res2) ) {
    $sqlvar.="joueur2 ='".$row2[id]."' or ";
  }
  $req = "SELECT m.date, l.login , l2.login as login2 FROM matgraph_atkbabel m,matgraph_users l,matgraph_users l2 WHERE l.id=m.joueur2 AND l2.id=m.joueur1 AND (".$sqlvar."0) and (".$sqlvar."0)";
  $res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
  echo mysql_num_rows($res) ." attaque(s) par le rayon de babel :<br>";
  While ( $row = mysql_fetch_array($res) ) {
    echo  "<font color=yellow>".$row["login2"]."</font> sur <font color=yellow>".$row["login"]."</font> => ". $row["date"]."<br>";
  }
  
  $req = "SELECT m.date, l.login, l2.login as login2 FROM matgraph_atkflotte m,matgraph_users l,matgraph_users l2 WHERE l.id=m.joueur2 AND l2.id=m.joueur1 AND (".$sqlvar."0) and (".$sqlvar."0)";
  $res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
  echo "<br>".mysql_num_rows($res)." attaque(s) par vaisseaux :<br>";
  While ( $row = mysql_fetch_array($res) ) {
    echo  "<font color=yellow>".$row["login2"]."</font> sur <font color=yellow>".$row["login"]."</font> => ". $row["date"]."<br>";
  }
  
  $req = "SELECT m.date, l.login, l2.login as login2  FROM matgraph_atkporte m,matgraph_users l,matgraph_users l2 WHERE l.id=m.joueur2 AND l2.id=m.joueur1 AND (".$sqlvar."0) and (".$sqlvar."0)";
  $res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
  echo "<br>".mysql_num_rows($res)." attaque(s) la porte des étoiles :<br>";
  While ( $row = mysql_fetch_array($res) ) {
    echo  "<font color=yellow>".$row["login2"]."</font> sur <font color=yellow>".$row["login"]."</font> => ". $row["date"]."<br>";
  }  
}
 */
?>
