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

$login_ajout = $_POST["login"];
$jour = $_POST["jour"];
$heure = $_POST["heure"];
$minute = $_POST["minute"];
$fin = $_POST["fin"];
$motif = $_POST["motif"];


$req = 'SELECT * FROM matgraph_users WHERE login = "'.$login_ajout.'"';
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
	$requete = 'INSERT INTO matgraph_banni VALUES ("", "'.$login_ajout.'", "'.$jour.'", "'.$heure.'", "'.$minute.'", "'.$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 = "'.$login_ajout.'"';
	$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
	
	$req2 = "SELECT id FROM matgraph_users WHERE login = '".$login_ajout."' 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($login_ajout)." | ".addslashes($jour)."j ".addslashes($heure)."h ".addslashes($minute)."m | ".addslashes($fin)." | ".addslashes($motif)."'
					)";
	$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
}
else
{
	echo '<script language=javascript> alert (" '.$login_ajout.' introuvable ");</script>';
}
echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("ban.php");
-->
</script>';

?>