<?php
include ('suppression.php');
if(isset($_GET['p']) && $_GET['p']=='supprimer'){
	$id = $_POST["id"];

	$sql = "SELECT * FROM matgraph_banni WHERE id = $id";
	$res = mysql_query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
	$row = mysql_fetch_array($res);

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

	$sql4 = "DELETE FROM matgraph_banni WHERE id = $id";
	$res4 = mysql_query($sql4)or die('erreur sql<br/>'.$sql4.'<br/>'.mysql_error());
}elseif(isset($_GET['p']) && $_GET['p']=='ajouter'){
	$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"<div align='center'><br/><center><h4>Bannissement des joueurs</h4></center><br/><table width=\"659\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr style =\"background-color:#222222;\">
    <td><div align=\"center\"><b>Login</b></div></td>
    <td><div align=\"center\"><b>Temps</b></div></td>
    <td><div align=\"center\"><b>Fin</b></div></td>
    <td><div align=\"center\"><b>Motif</b></div></td>
	<td><div align=\"center\"><b>Del</b></div></td>
  </tr>";
  
$req = "SELECT * FROM matgraph_banni ORDER by date DESC";
$res = mysql_query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
  $i=1;
  While ( $row = mysql_fetch_array($res) ) {
	echo"<tr";
	// gère le quadrillage du tableau
			if (($i/2) == ceil($i/2))
			{
				echo' style ="background-color:#111111;"' ;
			}
	echo">
    <td><div align=\"center\">$row[login]</div></td>
    <td><div align=\"center\">$row[jour] j $row[heure] h $row[minute] min</div></td>
    <td><div align=\"center\">$row[date]</div></td>
    <td><div align=\"center\">$row[motif]</div></td>
	<form name=\"suprimer\" method=\"post\" action=\"index.php?action=ban&p=supprimer\" target=\"_parent\"><td align=\"center\">
           <input type=\"hidden\" name=\"id\" value=\"$row[id]\">
          <input type=\"image\" src=\"../imgs/del.gif\" Style=\"border:0px solid #7E7E7E;\" width=\"25\">
                  </td></form>
  </tr>";
  $i++;
  }
}
  
echo"</table>";

echo"<br><br><div align='center'><table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  <tr style =\"background-color:#222222;\"><form name=\"ban_ajout\" method=\"post\" action=\"index.php?action=ban&p=ajouter\">
  <tr><td>login : </td><td><input type=\"text\" name=\"login\"></td></tr>
  <tr><td>nombre de jours : </td><td><input type=\"text\" name=\"jour\"></td></tr>
  <tr><td>nombre de heures : </td><td><input type=\"text\" name=\"heure\"></td></tr>
  <tr><td>nombre de minutes : </td><td><input type=\"text\" name=\"minute\"></td></tr>
  <tr><td>Date Fin : </td><td><input type=\"text\" name=\"fin\" value=\"".strftime("%Y-%m-%d %H:%M:%S", time())."\"></td></tr>
  <tr><td>Motif : </td><td><input type=\"text\" name=\"motif\" value=\"\"></td></tr>
  <tr><td colspan=\"2\" align=\"center\"><br><input type=\"submit\" name=\"Submit\" value=\"Ajouter\" Style=\"border:1px solid #7E7E7E;\"></td></tr>
</form>
</table><br/>";

?>
