<?php
if(isset($_GET['maj'])){
$req = "SELECT id FROM matgraph_multi WHERE ((alerte_multi*2 + connection_multi) > 3) AND ((envoi1 + envoi2) > 0)";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
	While ( $row = mysql_fetch_array($res) ) {
		$req2 = "SELECT * FROM matgraph_multiencours WHERE idmulti=$row[id] limit 1";
		$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
		$num2 = mysql_num_rows($res2);
		if ( $num2 == 0 ) {
			$requete = "INSERT INTO matgraph_multiencours VALUES ('', '$row[id]')";
			$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
		}
	}
}
}
echo "<script type=\"text/javascript\">
function aff_div(id){
	var div_aff=document.getElementById(id);
	var a_href_aff = document.getElementById('a'+id);
	if(div_aff.style.display=='none'){
		div_aff.style.display='block';
		document.getElementById('a'+id).value='-';
	}else{
		div_aff.style.display='none';
		document.getElementById('a'+id).value='+';
	};
};
</script>";
echo"<table width=\"400\" border=\"1\" bgcolor=\"#000000\" align=\"center\">";
echo"<tr>
    <td>Joueur1</td>
    <td>Joueur2</td>
    <td>Ressource1</td>
    <td>Ressource2</td>
    <td>Envoi1</td>
    <td>Envoi2</td>
    <td>Alerte multi</td>
    <td>Connection multi</td>
    <td>Nbre ban</td>
    <td>Nbre passer</td>
    <td>Lien multi</td>
	<td>Action</td>
  </tr>";
if(isset($_POST['login']) && $_POST['login']!=''){
	$req = "SELECT * FROM matgraph_users WHERE login='".$_POST['login']."' AND id=idjoueur LIMIT 1";
	$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$row=mysql_fetch_array($res);
	
	$req2 = "SELECT * FROM matgraph_multi WHERE joueur1 = '".$row['id']."' OR joueur2 = '".$row['id']."'";
	$res = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
	$num = mysql_num_rows($res);
}else{
	$req = "SELECT * FROM matgraph_multiencours WHERE idmulti != '1'";
	$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
	$num = mysql_num_rows($res);
}
if ( $num > 0 ) {
	While ( $row = mysql_fetch_array($res) ) {

		$req2 = "SELECT * FROM matgraph_multi WHERE id='$row[idmulti]'";
		$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
		$row2 = mysql_fetch_array($res2);
		
		$req3 = "SELECT pts,login FROM matgraph_users WHERE id='$row2[joueur1]'";
		$res3 = mysql_query($req3) or die('Erreur SQL! <br>'.$req3.'<br>'.mysql_error());
		$row3 = mysql_fetch_array($res3);
		
		$req4 = "SELECT pts,login FROM matgraph_users WHERE id='$row2[joueur2]'";
		$res4 = mysql_query($req4) or die('Erreur SQL! <br>'.$req4.'<br>'.mysql_error());
		$row4 = mysql_fetch_array($res4);
		
		//autoriser
			$req_autoriser = "SELECT * FROM matgraph_autoriser WHERE joueur1 = '".addslashes($row3[login])."' AND joueur2 = '".addslashes($row4[login])."'";
			$req_autoriser2 = "SELECT * FROM matgraph_autoriser WHERE joueur1 = '".addslashes($row4[login])."' AND joueur2 = '".addslashes($row3[login])."'";
			$res_autoriser = mysql_query($req_autoriser) or die('Erreur SQL! <br>'.$req_autoriser.'<br>'.mysql_error());
			$res_autoriser2 = mysql_query($req_autoriser2) or die('Erreur SQL! <br>'.$req_autoriser2.'<br>'.mysql_error());
			$num_autoriser = mysql_num_rows($res_autoriser) + mysql_num_rows($res_autoriser2) ;
		
		
		UNSET ($push);
		if(!empty($row2)) {
			if(($row2[ressources1]*10 < $row2[ressources2]) &&  $row3[pts] > $row4[pts] )
			{
				$push = "choper";
			}
			if(($row2[ressources1]*10 > $row2[ressources2]) &&  $row3[pts] < $row4[pts] )
			{
				$push = "choper";
			}
			
			if($num_autoriser > 0)
			{
				echo"<tr>
				<td>"; if($push == "choper") { echo"<font color=\"CC0099\">PUSH : </font>";} echo"<font color=\"00CC00\">$row3[login]</font></td>
				<td><font color=\"00CC00\">$row4[login]</font></td>
				<td><font color=\"FF0000\">$row2[ressources1]</font></td>
				<td><font color=\"FF0000\">$row2[ressources2]</font></td>
				<td>$row2[envoi1]</td>
				<td>$row2[envoi2]</td>
				<td>$row2[alerte_multi]</td>
				<td>$row2[connection_multi]</td>
				<td>$row2[nbre_ban]</td>
				<td>$row2[nbre_passer]</td>
				<td>$row2[lien_multi]</td>
				<td><input style=\"color: #5596bf; ; background-color: black ; border: 1px solid silver;\" type=\"button\" id=\"aaff_multi".$row2['id']."\" onclick=\"aff_div('aff_multi".$row2['id']."');\" value=\"+\" /></td>
			</tr><tr>
				<td colspan=\"12\">
					<div id=\"aff_multi".$row2['id']."\" style=\"display:none;\">
						<form name=\"rep\" method=\"post\" action=\"multi_oublier.php\" target=\"_parent\">
							<input type=\"hidden\" name=\"id\" value=\"$row[id]\">
							<input type=\"submit\" name=\"Submit\" value=\"Oublier\" Style=\"border:1px solid #7E7E7E;\">
						</form>
						<form name=\"rep\" method=\"post\" action=\"multi_ban.php\" target=\"_parent\">
							<input type=\"hidden\" name=\"id\" value=\"$row[id]\">
		    				<input type=\"text\" name=\"nbre_jour\" value=\"0\" maxlength=\"4\">
		    				<input type=\"text\" name=\"motif\" value=\"Multi $row4[login] et $row3[login]\">
		    				<input type=\"submit\" name=\"Submit\" value=\"Bannir\" Style=\"border:1px solid #7E7E7E;\">
						</form>
					</div>
				</td>
				</tr>";
			}
			else
			{
				echo"<tr>
				<td>"; if($push == "choper") { echo"<font color=\"CC0099\">PUSH : </font>";} echo"$row3[login]</td>
				<td>$row4[login]</td>
				<td>$row2[ressources1]</td>
				<td>$row2[ressources2]</td>
				<td>$row2[envoi1]</td>
				<td>$row2[envoi2]</td>
				<td>$row2[alerte_multi]</td>
				<td>$row2[connection_multi]</td>
				<td>$row2[nbre_ban]</td>
				<td>$row2[nbre_passer]</td>
				<td>$row2[lien_multi]</td>
				<td><input style=\"color: #5596bf; ; background-color: black ; border: 1px solid silver;\" type=\"button\" id=\"aaff_multi".$row2['id']."\" onclick=\"aff_div('aff_multi".$row2['id']."');\" value=\"+\" /></td>
			</tr><tr>
				<td style=\"border:0px;\">
				</td>
				<td colspan=\"11\" style=\"border:0px;\">
					<div id=\"aff_multi".$row2['id']."\" style=\"display:none;border:1px solid #FFFFFF;\">
						<form name=\"rep_oublier".$row2['id']."\" method=\"post\" action=\"multi_oublier.php\" target=\"_parent\">
							<input type=\"hidden\" name=\"id\" value=\"$row[id]\">
							&nbsp;Oublier ce multi : <input type=\"submit\" name=\"Submit\" value=\"Oublier\" Style=\"border:1px solid #7E7E7E;\">
						</form>
						<form name=\"rep_bannir".$row2['id']."\" method=\"post\" action=\"multi_ban.php\" target=\"_parent\">
							<input type=\"hidden\" name=\"id\" value=\"$row[id]\">
		    				<br/>&nbsp;Bannir le multi : <input type=\"text\" name=\"nbre_jour\" value=\"0\" maxlength=\"4\" style=\"width:150px;\">
		    				<input type=\"text\" name=\"motif\" value=\"Multi $row4[login] et $row3[login]\">
		    				<input type=\"submit\" name=\"Submit\" value=\"Bannir\" Style=\"border:1px solid #7E7E7E;\">
						</form>
						<br/>
					</div>
				</td>
				</tr>";
			}
		}
	}
}
echo"</table> 
<br><br>
<form name=\"rep\" method=\"post\" action=\"\" target=\"_parent\">
Login : <input type=\"text\" name=\"login\" value=\"\" maxlength=\"20\">
<input type=\"submit\" name=\"Submit\" value=\"Chercher\" Style=\"border:1px solid #7E7E7E;\">
</form>
<br><br><center><a href=\"".$PHP_SELF."?action=multi_comptes&amp;maj\">Mettre a jour</a><br><br>";


?>