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

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


$req = 'SELECT idjoueur FROM matgraph_users WHERE login = "'.$login_ajout.'" limit 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) ) {
	$requete = 'INSERT INTO matgraph_avertissement VALUES ("", "'.$login_ajout.'", "'.$jour.'", "'.$heure.'", "'.$minute.'", "'.$fin.'")';
	$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
	
	$req2 = "SELECT id,fer_on,or_on,exfer_on,exor_on,ada_on,ura_on FROM matgraph_users WHERE idjoueur = $row[idjoueur] ORDER by id ASC";
	$res2 = mysql_query($req2) or die('Erreur SQL! <br>'.$req2.'<br>'.mysql_error());
	$num2 = mysql_num_rows($res2);
	if ( $num2 > 0 ) {
	  While ( $row2 = mysql_fetch_array($res2) ) {
	  	$fer_on = 0;
	  	$or_on = 0;
	  	$exfer_on = 0;
	  	$exor_on = 0;
	  	$ada_on = 0;
	  	$ura_on = 0;
	  	if($row2['fer_on'] != 0)
	  	{
	  		$fer_on = 0.75;
	  	}
	  	if($row2['or_on'] != 0)
	  	{
	  		$or_on = 0.75;
	  	}
	  	if($row2['exfer_on'] != 0)
	  	{
	  		$exfer_on = 0.75;
	  	}
	  	if($row2['exor_on'] != 0)
	  	{
	  		$exor_on = 0.75;
	  	}
	  	if($row2['ada_on'] != 0)
	  	{
	  		$ada_on = 0.75;
	  	}
	  	if($row2['ura_on'] != 0)
	  	{
	  		$ura_on = 0.75;
	  	}
	  	
			$sql4 = "INSERT INTO `matgraph_logadmin` ( `id` , `mdj` , `date` , `action` )
							VALUES (
							'', '".$login."', now(), 'Ajout averto | ".addslashes($login_ajout)." | ".addslashes($jour)."j ".addslashes($heure)."h ".addslashes($minute)."m | ".addslashes($fin)."'
							)";
			$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
			
	  	$requete = "UPDATE matgraph_users SET fer_on=$fer_on,or_on=$or_on,exfer_on=$exfer_on,exor_on=$exor_on,ada_on=$ada_on,ura_on=ura_on,techrare_moinsressource=1 WHERE id='$row2[id]'";
			$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
		}  
	}
}
}
else
{
	echo '<script language=javascript> alert (" '.$login_ajout.' introuvable ");</script>';
}
echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("avertissement.php");
-->
</script>';

?>