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

$id = $_POST["id"];

$sql4 = "SELECT * FROM matgraph_avertissement WHERE id=$id";
$res4 = mysql_query($sql4)or die('erreur sql<br>'.$sql4.'<br>'.mysql_error());
$row4 = mysql_fetch_array($res4);   

$req = 'SELECT idjoueur FROM matgraph_users WHERE login = "'.$row4[login].'" limit 1';
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res);

$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 = 1;
  	}
  	if($row2['or_on'] != 0)
  	{
  		$or_on = 1;
  	}
  	if($row2['exfer_on'] != 0)
  	{
  		$exfer_on = 1;
  	}
  	if($row2['exor_on'] != 0)
  	{
  		$exor_on = 1;
  	}
  	if($row2['ada_on'] != 0)
  	{
  		$ada_on = 1;
  	}
  	if($row2['ura_on'] != 0)
  	{
  		$ura_on = 1;
  	}

		$sql4 = "INSERT INTO `matgraph_logadmin` ( `id` , `mdj` , `date` , `action` )
						VALUES (
						'', '".$login."', now(), 'Supr averto | ".addslashes($row4['login'])." | ".addslashes($row4['jour'])."j ".addslashes($row4['heure'])."h ".addslashes($row4['minute'])."m | ".addslashes($row4['date'])."'
						)";
		$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=0 WHERE idjoueur='$row2[id]'";
		$resultat = mysql_query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
	}  
}


$sql4 = "DELETE FROM matgraph_avertissement 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("avertissement.php");
-->
</script>';
  
?>