<?php include('partie1_admin2.php'); ?>

<div id="toute_off" align="center">
<?php 
if (isset($_GET['id']))
{
	$chaiz=addslashes($_GET['chaiz']);
	$id=addslashes($_GET['id']);
	
	if ($chaiz=='image')
	{
		$num=addslashes($_GET['num']);
		$page_prec='afficher_element.php?chaiz=dossier&id='.$num.'';
	}
	else
	{
		$page_prec='admin_element.php?chaiz='.$chaiz;
	}
	
	switch ($chaiz)
	{
		case 'produit': $num_champ='id_prod'; $det='Ce Produit'; $aff='Produit';
		break;
		case 'actualite': $num_champ='id_actu'; $det='Cette Actualité'; $aff='Réalisation';
		break;
		case 'magasin': $num_champ='id_mag'; $det='Cet Magasin'; $aff='Magasin';
		break;
		case 'contact': $num_champ='id_contact';  $det='Ce Contact'; $aff='Message';
		break;
		case 'commande': $num_champ='id_commande';  $det='Cette Commande'; $aff='Commande';
		break;
		case 'client': $num_champ='id_client';  $det='Ce Client'; $aff='Client';
		break;
		default: header ('Location: administration.php?anh_san=paray_ci');
	}

?>
    <div class="page"> Fiche de Suppression</div>
        
    <div class="cov_off" style="border-radius:15px; margin-bottom:20px;">
        <div align="center" class="menu_off">
			Voulez-vous supprimer <?php echo $det; ?> ?
        </div>
        <form role="form" method="post" action="">
        <input type="submit" class="btn btn-default" value="Oui" name="valider"> <a href="<?php echo $page_prec; ?>">Non</a>
        </form>
        
        <?php
		if (isset($_POST['valider']))
		{
			switch ($chaiz)
			{
				case 'magasin':
				$sql = 'SELECT * FROM '.$chaiz.' WHERE '.$num_champ.'='.$id.'';
				$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
				$data =$reponse->fetch();
				unlink ($data['img_mag']);
				break;
				case 'actualite':
				$sql = 'SELECT * FROM '.$chaiz.' WHERE '.$num_champ.'='.$id.'';
				$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
				$data =$reponse->fetch();
				if ($data['img_actu']!='upload/img_actu225.jpg')
				{
					unlink ($data['img_actu']);
				}
				break;
				case 'produit':
				$sql = 'SELECT * FROM '.$chaiz.' WHERE '.$num_champ.'='.$id.'';
				$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
				$data =$reponse->fetch();
				unlink ($data['img_prod']);
				break;
			}
			
			$req='DELETE FROM '.$chaiz.'
			WHERE '.$num_champ.'='.$id.'';
			$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
			echo '<div style=" font-size:18px; text-align:center; color:green;"><img src="img/vert.png" width="20"> '.$chaiz.' supprimé avec succès </div>';
		?> 
<script type="text/javascript">window.setTimeout("location=('<?php echo $page_prec; ?>');",2000);</script>
		<?php
		}
		?>
     </div>   
</div>

<table border="0" align="center"><tr>
    <td class="bouton_design">
    <a href="administration.php?anh_san=paray_ci">Accueil Panneau</a></td>
</tr></table>
<?php 
}
else
{
	header ('Location: administration.php?anh_san=paray_ci');
}
?>
</body>
</html>