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

$id = $_POST["id"];
$nbre_jour = $_POST["nbre_jour"];
$motif = $_POST["motif"];


$req = "SELECT * FROM matgraph_multiencours WHERE id=$id";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res);

$requete = "UPDATE matgraph_multi SET connection_multi = 0, alerte_multi = 0, nbre_ban = nbre_ban + 1  WHERE id='$row[idmulti]'";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$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 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 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);


$fin = strftime("%Y-%m-%d %H:%M:%S", time()+ (round(3600*24*$nbre_jour)));

$requete = 'INSERT INTO matgraph_banni VALUES ("", "'.$row3[login].'", "'.$nbre_jour.'", "0", "0", "'.$fin.'", "'.$motif.'")';
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$requete = 'INSERT INTO matgraph_banni VALUES ("", "'.$row4[login].'", "'.$nbre_jour.'", "0", "0", "'.$fin.'", "'.$motif.'")';
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$requete = 'UPDATE matgraph_users SET vacance = "0000-00-00 00:00:00" WHERE login = "'.$row4[login].'" OR login = "'.$row3[login].'"';
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$requete = "UPDATE matgraph_multi SET nbre_ban = nbre_ban + 1 WHERE id=$row[idmulti]";
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$req2 = "SELECT id FROM matgraph_users WHERE login = '".$row3[login]."' AND id=idjoueur ";
$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);
$requete = 'UPDATE matgraph_connexion SET secu = "ban" WHERE idjoueur = "'.$row2['id'].'"';
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$req2 = "SELECT id FROM matgraph_users WHERE login = '".$row4[login]."' AND id=idjoueur ";
$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
$row2 = mysql_fetch_array($res2);
$requete = 'UPDATE matgraph_connexion SET secu = "ban" WHERE idjoueur = "'.$row2['id'].'"';
$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());

$sql4 = "INSERT INTO `matgraph_logadmin` ( `id` , `mdj` , `date` , `action` )
				VALUES (
				'', '".$login."', now(), 'Ajout ban | ".addslashes($row3[login])." | ".addslashes($jour)."j 0h 0m | ".addslashes($fin)." | ".addslashes($motif)."'
				)";
$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());

$sql4 = "INSERT INTO `matgraph_logadmin` ( `id` , `mdj` , `date` , `action` )
				VALUES (
				'', '".$login."', now(), 'Ajout ban | ".addslashes($row4[login])." | ".addslashes($jour)."j 0h 0m | ".addslashes($fin)." | ".addslashes($motif)."'
				)";
$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());

$sql4 = "DELETE FROM matgraph_multiencours WHERE id = $id";
$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());

echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("multi_comptes.php");
-->
</script>';

?>