<?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'); 

$nom_rechercher = $_POST["nom_rechercher"];
$type = $_POST["type"];

$form ="<br><br><form action=\"rechercher.php\" method=\"post\" name=\"form1\" 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 width=\"264\">Rechercher : 
      <input name=\"nom_rechercher\" type=\"text\" id=\"nom_rechercher\">      </td>
      <td width=\"265\">Dans :
        <select name=\"type\">
          <option value=\"joueur\">Nom du joueur</option>
          <option value=\"planete\">Nom de la plan&egrave;te</option>
          <option value=\"ally\">Nom de l'alliance</option>
          <option value=\"tag\">Tag de l'alliance</option>
              </select></td>
      <td width=\"81\"><input type=\"submit\" name=\"Submit\" value=\"Rechercher\"></td>
    </tr>
  </table>
</form>";

if(empty($nom_rechercher) || $nom_rechercher == "&#36" || $nom_rechercher == " " || $nom_rechercher == " " || $nom_rechercher == "_" || ereg("%",$nom_rechercher) || strlen($nom_rechercher) < 3)
{
echo"$form"; 
echo"Recherche sans résultat. <br><br>";
exit;
}

if($type == "joueur") {
echo"$form";
$req = "SELECT id,ally,login,planete,galaxi,system,position,pts,vacance,date FROM matgraph_users WHERE id=idjoueur AND login LIKE '".addslashes($nom_rechercher)."%' AND galaxi > 0 ORDER by login ASC limit 30";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
echo"Vous avez obtenu $num résultat(s) à votre recherche :<br><br>";
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 align=\"center\" height=\"40\"><b>Nom : </b></td>
    <td align=\"center\"><b>Planète mère : </b></td>
	<td align=\"center\" width=\"100\"><b>Message : </b></td>
  </tr>";
if ( $num > 0 ) {
$i=1;
  While ( $row = mysql_fetch_array($res) ) {
$ally =""; 
$sql21 = "SELECT tag FROM matgraph_ally WHERE id='$row[ally]'";
$res21 = db_mysql_Query($sql21)or die('erreur sql<br>'.$sql21.'<br>'.mysql_error());
$num21 = mysql_num_rows($res21);
if ($num21 > 0 AND $row[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;
$idform2 = $row[galaxi].$i;
$login1 =" <font color="; 
	if(rand(0,1) == 0) { 
		$login1 .="\n"; 
	} 
	$login1 .="\"FFFFFF\">".$row['login']."";
    include('limite_pts.php');
    if(($New_pts > $row['pts']*3.0001) && ($row['pts'] < $limite_pts) && $row['login']!=$_SESSION['login']) {
      $login1 =" <font color"; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .="="; 
	  if(rand(0,1) == 0) { 
	  		$login1 .=" \n"; 
	  } 
	  $login1 .="\"00CC00\""; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .=">".$row['login']; 
    }elseif(($New_pts < $row['pts']/3.0001) && ($New_pts < $limite_pts)) {
      $login1 =" <font color"; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .="="; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .="\"990000\">".$row['login']; 
    }elseif($row["vacance"] != "0000-00-00 00:00:00") {
      $login1 =" <font color="; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } $login1 .="\"0099FF\""; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .=">".$row['login'];
    }
    for ($j=1;$j<=rand(0,10);$j++){
       if(rand(0,1) == 0) {
    			$login1.=$brouille;
    		}
    }   
    $login1.= "</font>";
    $brouille1 = "<!-- ".$login1." -->";
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $row['date'], $thetime);
    $time1 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
    
    $diftemps1 = time() - $time1;
    $difheure1 = $diftemps1 / 3600;
    if(($difheure1 > (24*7*4)) && $row['login']!=$_SESSION['login']) {
      $login1.= "<font color=\"FF0000\"> \"AFK";
      for ($j=1;$j<=rand(0,10);$j++){
      	$login1.= "\n";
      	if(rand(0,1) == 0) {
      		$login1.= " ";
      	}
      }
      $login1.= "\"</font>";
    }else {
      if(($difheure1 > (24*7*2)) && $row['login']!=$_SESSION['login']) 
        $login1.= " \"afk\""; 
    }
echo"<tr";
// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
	echo">
	<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> $login1</td></form>
    <td align=\"center\">$row[planete] [$row[galaxi]:$row[system]:$row[position]]</td>
	<form name=\"$idform2\" method=\"post\" action=\"mp_envoi.php\" target=\"_parent\">  
  <input name=\"idreceveur\" type=\"hidden\" value=\"$row[id]\">
  <input name=\"loginreceveur\" type=\"hidden\" value=\"$row[login]\">
  <input name=\"galaxi\" type=\"hidden\" value=\"$row[galaxi]\">
  <input name=\"system\" type=\"hidden\" value=\"$row[system]\">
  <input name=\"position\" type=\"hidden\" value=\"$row[position]\">
  <td width=\"100\" align=\"center\"><div align=\"center\"><input type=\"image\" src=\"imgs/msg.gif\" Style=\"border:0px solid #7E7E7E;\"></div></td></form>
  </tr>";
$i++;  
}}
  
echo"</table>";
}

if($type == "planete") {
echo"$form";
$req = "SELECT id,idjoueur,ally,login,planete,galaxi,system,position,pts,vacance,date FROM matgraph_users WHERE planete LIKE '".addslashes($nom_rechercher)."%' AND galaxi > 0 ORDER by login ASC limit 30";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
echo"Vous avez obtenu $num résultat(s) à votre recherche :<br><br>";
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 align=\"center\"><b>Planète : </b></td>
    <td align=\"center\" height=\"40\"><b>Nom : </b></td>
	<td align=\"center\" width=\"100\"><b>Message : </b></td>
  </tr>";
if ( $num > 0 ) {
$i=1;
  While ( $row = mysql_fetch_array($res) ) {
  
$sql22 = "SELECT ally FROM matgraph_users WHERE id='$row[idjoueur]'";
$res22 = db_mysql_Query($sql22)or die('erreur sql<br>'.$sql22.'<br>'.mysql_error());
$row22 = mysql_fetch_array($res22);
$ally =""; 
$sql21 = "SELECT tag FROM matgraph_ally WHERE id='$row22[ally]'";
$res21 = db_mysql_Query($sql21)or die('erreur sql<br>'.$sql21.'<br>'.mysql_error());
$num21 = mysql_num_rows($res21);
if ($num21 > 0 AND $row22[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;
$idform2 = $row[galaxi].$i;
$login1 =" <font color="; 
	if(rand(0,1) == 0) { 
		$login1 .="\n"; 
	} 
	$login1 .="\"FFFFFF\">".$row['login']."";
    include('limite_pts.php');
    if(($New_pts > $row['pts']*3.0001) && ($row['pts'] < $limite_pts) && $row['login']!=$_SESSION['login']) {
      $login1 =" <font color"; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .="="; 
	  if(rand(0,1) == 0) { 
	  		$login1 .=" \n"; 
	  } 
	  $login1 .="\"00CC00\""; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .=">".$row['login']; 
    }elseif(($New_pts < $row['pts']/3.0001) && ($New_pts < $limite_pts)) {
      $login1 =" <font color"; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .="="; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .="\"990000\">".$row['login']; 
    }elseif($row["vacance"] != "0000-00-00 00:00:00") {
      $login1 =" <font color="; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } $login1 .="\"0099FF\""; 
	  if(rand(0,1) == 0) { 
	  		$login1 .="\n"; 
	  } 
	  $login1 .=">".$row['login'];
    }
    for ($j=1;$j<=rand(0,10);$j++){
       if(rand(0,1) == 0) {
    			$login1.=$brouille;
    		}
    }   
    $login1.= "</font>";
    $brouille1 = "<!-- ".$login1." -->";
    ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $row['date'], $thetime);
    $time1 = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);
    
    $diftemps1 = time() - $time1;
    $difheure1 = $diftemps1 / 3600;
    if(($difheure1 > (24*7*4)) && $row['login']!=$_SESSION['login']) {
      $login1.= "<font color=\"FF0000\"> \"AFK";
      for ($j=1;$j<=rand(0,10);$j++){
      	$login1.= "\n";
      	if(rand(0,1) == 0) {
      		$login1.= " ";
      	}
      }
      $login1.= "\"</font>";
    }else {
      if(($difheure1 > (24*7*2)) && $row['login']!=$_SESSION['login']) 
        $login1.= " \"afk\""; 
    }
echo"<tr";
// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
	echo">
	<td align=\"center\">$row[planete] [$row[galaxi]:$row[system]:$row[position]]</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> $login1</td></form>
   <form name=\"$idform2\" method=\"post\" action=\"mp_envoi.php\" target=\"_parent\">  
  <input name=\"idreceveur\" type=\"hidden\" value=\"$row[id]\">
  <input name=\"loginreceveur\" type=\"hidden\" value=\"$row[login]\">
  <input name=\"galaxi\" type=\"hidden\" value=\"$row[galaxi]\">
  <input name=\"system\" type=\"hidden\" value=\"$row[system]\">
  <input name=\"position\" type=\"hidden\" value=\"$row[position]\">
  <td width=\"100\" align=\"center\"><div align=\"center\"><input type=\"image\" src=\"imgs/msg.gif\" Style=\"border:0px solid #7E7E7E;\"></div></td></form>
  </tr>";
$i++;  
}}
  
echo"</table>";
}

if($type == "ally") {
echo"$form";
$req = "SELECT id,tag,nom,pts_ally FROM matgraph_ally WHERE nom LIKE '".addslashes($nom_rechercher)."%' ORDER by nom ASC limit 30";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
echo"Vous avez obtenu $num résultat(s) à votre recherche :<br><br>";
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 align=\"center\"><b>Nom : </b></td>
    <td align=\"center\" height=\"40\"><b>Tag : </b></td>
	<td align=\"center\"><b>Nombres de membres : </b></td>
	<td align=\"center\"><b>Nombres de points : </b></td>
  </tr>";
if ( $num > 0 ) {
$i=1;
  While ( $row = mysql_fetch_array($res) ) {

$pts = number_format($row[pts_ally] / 1000, 0, ',', ' ');

$req33 = "SELECT id FROM matgraph_users WHERE ally='$row[id]'";
$res33 = db_mysql_Query($req33) or die('Erreur SQL! <br>'.$req33.'<br>'.mysql_error());
$num33 = mysql_num_rows($res33);

$ally =""; 
$sql21 = "SELECT tag FROM matgraph_ally WHERE id='$row[id]'";
$res21 = db_mysql_Query($sql21)or die('erreur sql<br>'.$sql21.'<br>'.mysql_error());
$num21 = mysql_num_rows($res21);
if ($num21 > 0 AND $row[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\">$row[nom]</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\"><a href=\"#\" target=\"_parent\" Onclick=\"document.getElementById('$idform').submit()\">$plan1</a></td></form>
	<td align=\"center\">$num33</td>
	<td align=\"center\">$pts</td>

  </tr>";
$i++;  
}}
  
echo"</table>";
}

if($type == "tag") {
echo"$form";
$req = "SELECT id,tag,nom,pts_ally FROM matgraph_ally WHERE tag LIKE '".addslashes($nom_rechercher)."%' ORDER by tag ASC limit 30";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
echo"Vous avez obtenu $num résultat(s) à votre recherche :<br><br>";
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 align=\"center\" height=\"40\"><b>Tag : </b></td>
    <td align=\"center\"><b>Nom : </b></td>
    <td align=\"center\"><b>Nombres de membres : </b></td>
	<td align=\"center\"><b>Nombres de points : </b></td>
  </tr>";
if ( $num > 0 ) {
$i=1;
  While ( $row = mysql_fetch_array($res) ) {

$pts = number_format($row[pts_ally] / 1000, 0, ',', ' ');

$req33 = "SELECT id FROM matgraph_users WHERE ally='$row[id]'";
$res33 = db_mysql_Query($req33) or die('Erreur SQL! <br>'.$req33.'<br>'.mysql_error());
$num33 = mysql_num_rows($res33);

$ally =""; 
$sql21 = "SELECT tag FROM matgraph_ally WHERE id='$row[id]'";
$res21 = db_mysql_Query($sql21)or die('erreur sql<br>'.$sql21.'<br>'.mysql_error());
$num21 = mysql_num_rows($res21);
if ($num21 > 0 AND $row[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">
	<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\"><a href=\"#\" target=\"_parent\" Onclick=\"document.getElementById('$idform').submit()\">$plan1</a></td></form>
	<td align=\"center\">$row[nom]</td>
	<td align=\"center\">$num33</td>
	<td align=\"center\">$pts</td>

  </tr>";
$i++;  
}}
  
echo"</table>";
}
?>