<?php include('partie1_admin2.php')?>
<?php 
if (isset($_GET['chaiz']))
{
	$chaiz=addslashes($_GET['chaiz']);
	switch ($chaiz)
	{
		case 'produit': $sql = 'SELECT *
			  FROM '.$chaiz.'
			  ORDER BY date_prod DESC';
			  $aff='Gestionnaire des Produits';
			  $enreg='Produit(s) enrégistré(s)';			  
		break;
		case 'client': $sql = 'SELECT *
			  FROM '.$chaiz.'
			  ORDER BY id_client DESC';
			  $aff='Gestionnaire des Clients';
			  $enreg='Client(s) enrégistré(s)';			  
		break;
		case 'commande': $sql = 'SELECT *
			  FROM '.$chaiz.', client
			  WHERE commande.id_client=client.id_client
			  ORDER BY date_commande DESC';
			  $aff='Gestionnaire des Commandes';
			  $enreg='Commande(s) enrégistré(s)';			  
		break;
		default: header ('Location: administration.php?anh_san=paray_ci');
	}
?>
<div id="toute_off" align="center">
  <div class="page"> 
  <?php echo $aff;
  $sql2 = 'SELECT  COUNT(*) as nbr FROM '.$chaiz.'';
  $reponse2=$bdd->query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
  $data2 =$reponse2->fetch();
  ?>
  </div>
   <?php if ($chaiz!='contact' and $chaiz!='client' and $chaiz!='commande')
   {
	?>
    <div align="right">
    	<a href="ajouter_element.php?chaiz=<?php echo $chaiz; ?>" class="myButton">Ajouter</a>
    </div>
    <?php
   }
   else
   {
		echo '<br>';
   }
	if ($data2[0]==0)
	{
		echo '<div style="font-size:19px; text-align:center; color:red;"><img src="img/rouge.png" width="20">Pas de '.$enreg.' </div>';
		
		echo '<div class="but_prec">
   				<a href="administration.php?anh_san=paray_ci">Précédent</a>
			  </div>';
	}
	else
	{
	?>
    <div class="nbr_inscri">
    	Il y a actuellement 
        <font class="nbr">
			<?php echo $data2[0].' '.$enreg;?>
        </font>
    </div>

    <div class="cov_off" style="border-radius:15px;">
        <div align="center"> <div style="text-align:center; font-size:19px; margin-top:-10px;"></div>
        	<table border="0" width="100%">
            <?php
			if ($chaiz=='client')
			{
				echo '
				<tr align="center">
					<td>Nom & Prénoms</td>
					<td>Nombre de Commande</td>
					<td>Supression</td>
					<td>Date</td>
				</tr>';
			}
			if ($chaiz=='commande')
			{
				echo '
			';
			}
			$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
			while ($data =$reponse->fetch())
			{
				switch ($chaiz)
				{
					case 'produit': echo '<tr>
					<td class="menu_off" width="55%" title="Consulter"><a href="afficher_element.php?id='.$data[0].'&chaiz='.$chaiz.'"> <img src="../../uploads/'.$data['img_prod'].'" width="120" style="margin:0px 10px 0px 0px; float:left;"> '.($data[1]).'</a></td>
					<td class="menu_off" width="15%"><a href="modifier_element.php?id='.$data[0].'&chaiz='.$chaiz.'">Modifier</a></td>
					<td class="menu_off" width="15%"><a href="supprimer_element.php?id='.$data[0].'&chaiz='.$chaiz.'">Supprimer</a></td>
					<td class="menu_off" width="15%">'. date("d", strtotime($data['date_prod'])).'-'.date("m", strtotime($data['date_prod'])).'-'.date("Y", strtotime($data['date_prod'])).'</td>
					</tr>';
					break;
					case 'client':
					$sql2 = 'SELECT COUNT(*) FROM commande WHERE id_client='.$data[0].'';
					$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
					$data2 =$reponse2->fetch();
					echo '<tr>
					<td class="menu_off" width="35%" title="Consulter"><a href="afficher_element.php?id='.$data[0].'&chaiz='.$chaiz.'"> '.($data[1]).' '.($data[2]).'</a></td>
					<td class="menu_off" width="25%" align="center">'.$data2['0'].'</td>
					<td class="menu_off" width="15%" align="center"><a href="supprimer_element.php?id='.$data[0].'&chaiz='.$chaiz.'">Supprimer</a></td>
					<td class="menu_off" width="15%" align="center">'. date("d", strtotime($data['date_client'])).'-'.date("m", strtotime($data['date_client'])).'-'.date("Y", strtotime($data['date_client'])).'</td>
					</tr>';
					break;
					case 'commande': echo '<tr>
					<td class="menu_off" width="10%" title="Consulter">N° '.($data[0]).'<a href="afficher_element.php?id='.$data[0].'&chaiz='.$chaiz.'"><img src="img/plus.png" class="plus_info"></a></td>
					<td class="menu_off" width="30%" title="Consulter">'.$data['nom_client'].' '.$data['prenom_client'].'</td>
					<td class="menu_off" width="15%">'.$data[1].'</td>
					<td class="menu_off" width="15%"><a href="supprimer_element.php?id='.$data[0].'&chaiz='.$chaiz.'">Supprimer</a></td>
					<td class="menu_off" width="15%">'. date("d", strtotime($data['date_commande'])).'-'.date("m", strtotime($data['date_commande'])).'-'.date("Y", strtotime($data['date_commande'])).'</td>
					</tr>';
					break;
					case 'contact': echo '<tr>';
					echo '<td class="menu_off" width="55%" title="Consulter"><a href="afficher_element.php?id='.$data[0].'&chaiz='.$chaiz.'">'.($data[1]).' '.($data[2]).'</a></td>
					<td class="menu_off" width="20%"><a href="supprimer_element.php?id='.$data[0].'&chaiz='.$chaiz.'">Supprimer</a></td>
					<td class="menu_off" width="25%">'. date("d", strtotime($data['date_contact'])).'-'.date("m", strtotime($data['date_contact'])).'-'.date("Y", strtotime($data['date_contact'])).'</td>
					</tr>';
					break;
					default: header ('Location: administration.php?anh_san=paray_ci');
				}
			}
			?>
            </table>
        </div>
    	<div class="but_prec" style="display:none;">
   			<a href="administration.php">Pr&eacute;c&eacute;dent</a>
		</div>
</div>
</div>

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