<?php
include('source_connexion.php');

$login_search = $_POST["login"];
$hote_search = $_POST["hote"];
$ip_search = $_POST['ip'];

echo "<br /><h4><center>Recherche d'une connection</center></h4><br /><form action=\"#\" method=\"post\" name=\"form1\" target=\"_parent\">
  <table width=\"618\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
    <tr style =\"background-color:#222222;\">
    	<td align=\"center\">Du joueur :  <input name=\"login\" type=\"text\" id=\"login\" value=\"$login_search\"></td>
    </tr>
    <tr>
    	<td align=\"center\"><b>OU</b> de l'hote :  <input name=\"hote\" type=\"text\" id=\"hote\" value=\"$hote_search\"></td>
    </tr>
	<tr style =\"background-color:#222222;\">
    	<td align=\"center\"><b>OU</b> de l'IP :  <input name=\"ip\" type=\"text\" id=\"ip\" value=\"$ip_search\"></td>
    </tr>
    <tr>
      <td align=\"center\"><input type=\"submit\" name=\"Submit\" value=\"Rechercher\"></td>
    </tr>
  </table>
</form><br />";

if(empty($login_search) && empty($hote_search) && empty($ip_search)) {
	exit;
}elseif(!empty($login_search)) {
	$query="SELECT id FROM matgraph_users WHERE id=idjoueur AND login='".addslashes($login_search)."'";
	$sql=mysql_query($query) or die('Erreur MySQL : '.$query.'</br>'.mysql_error());
	list($id)=mysql_fetch_array($sql);
	$req = "SELECT * FROM matgraph_ip WHERE idlogin = '".$id."' ORDER BY date_connexion DESC";
	$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$num = mysql_num_rows($res);
	echo "<center>Vous avez obtenu $num résultat(s) à votre recherche :</center><br/><br/>";
	echo "<table width=\"618\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
	  <tr style =\"background-color:#222222;\">
	  	<td align=\"center\"><b>Date : </b></td>
	  	<td align=\"center\"><b>Browser : </b></td>
	  	<td align=\"center\"><b>Hote : </b></td>
		<td align=\"center\"><b>IP : </b></td>
	  </tr>";
	if ( $num > 0 ) {
	  $i=1;
	  while ( $row = mysql_fetch_array($res) ) {
	  		$navigateur=new browser($row['browser']);
			echo"<tr";
			// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
			echo">
				<td align=\"center\">$row[date_connexion]</td>
				<td align=\"center\">".$navigateur->Name." ".$navigateur->Version." sur ".$navigateur->Platform."</td>
				<td align=\"center\">$row[hote]</td>
				<td align=\"center\">$row[ip]</td>
		  </tr>";
			$i++;  
		}
	}
	echo"</table>";
}elseif(!empty($ip_search)){
	$req = "SELECT * FROM matgraph_ip WHERE ip = '".addslashes($ip_search)."' ORDER BY date_connexion DESC";
	$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$num = mysql_num_rows($res);
	echo"<center>Vous avez obtenu $num résultat(s) à votre recherche :</center><br/><br/>";
	echo"<table width=\"618\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
	  <tr style =\"background-color:#222222;\">
	  	<td align=\"center\"><b>Joueur : </b></td>
	  	<td align=\"center\"><b>Date : </b></td>
	  	<td align=\"center\"><b>Browser : </b></td>
		<td align=\"center\"><b>IP : </b></td>
	  </tr>";
	if ( $num > 0 ) {
	$i=1;
	  While ( $row = mysql_fetch_array($res) ) {
	  		$navigateur=new browser($row['browser']);
			$sql2 = "SELECT login FROM matgraph_users WHERE id='".$row['idlogin']."'";
			$res2 = mysql_query($sql2)or die('Erreur MySQL<br>'.$sql2.'<br>'.mysql_error());
			$row2 = mysql_fetch_array($res2);
			echo"<tr";
			// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
			echo">
				<td align=\"center\">".$row2['login']."</td>
				<td align=\"center\">".$row['date_connexion']."</td>
				<td align=\"center\">".$navigateur->Name." ".$navigateur->Version." sur ".$navigateur->Platform."</td>
				<td align=\"center\">".$row['ip']."</td>
		  </tr>";
			$i++;  
		}
	}
	echo"
	</table>";
}else{
	$req = "SELECT * FROM matgraph_ip WHERE hote = '".addslashes($hote_search)."' ORDER BY date_connexion DESC";
	$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$num = mysql_num_rows($res);
	echo"<center>Vous avez obtenu $num résultat(s) à votre recherche :</center><br/><br/>";
	echo"<table width=\"618\" border=\"0\" align=\"center\" cellspacing=\"0\" cellpadding=\"2\" bordercolor=\"#000000\" style=\"font-family:trebuchet ms,sans-serif; font-size: 9pt ;\">
	  <tr style =\"background-color:#222222;\">
	  	<td align=\"center\"><b>Joueur : </b></td>
	  	<td align=\"center\"><b>Date : </b></td>
	  	<td align=\"center\"><b>Browser : </b></td>
		<td align=\"center\"><b>IP : </b></td>
	  </tr>";
	if ( $num > 0 ) {
	$i=1;
	  While ( $row = mysql_fetch_array($res) ) {
	  		$navigateur=new browser($row['browser']);
			$sql2 = "SELECT login FROM matgraph_users WHERE id='$row[idlogin]'";
			$res2 = mysql_query($sql2)or die('erreur sql<br>'.$sql2.'<br>'.mysql_error());
			$row2 = mysql_fetch_array($res2);
			echo"<tr";
			// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
			echo">
				<td align=\"center\">$row2[login]</td>
				<td align=\"center\">$row[date_connexion]</td>
				<td align=\"center\">".$navigateur->Name." ".$navigateur->Version." sur ".$navigateur->Platform."</td>
				<td align=\"center\">$row[ip]</td>
		  </tr>";
			$i++;  
		}
	}
	echo"
	</table>";
}
echo "<br/><br/>";
?>