<?php include('partie1_admin2.php'); ?>
<?php 
if (isset($_GET['id']))
{
	$id=addslashes($_GET['id']);
	$chaiz=addslashes($_GET['chaiz']);
	
	switch ($chaiz)
	{
		case 'client': $sql = 'SELECT * FROM '.$chaiz.' WHERE id_client='.$id.'';
			  $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
			  $data =$reponse->fetch();
			  $aff='Client: '.($data[1]).' '.($data[2]).'';
?>
<div id="toute_off" align="center">
    <div class="page"> <?php echo $aff;?></div>
        
    <div class="cov_off" style="border-radius:15px; margin-bottom:20px;">
        	<table border="0" width="100%">
			<tr>
                <td class="menu_off">Nom</td>
                <td class="menu_off"><?php echo ''.($data[1]);?></td>
            </tr>
			<tr>
                <td class="menu_off">Prénoms</td>
                <td class="menu_off"><?php echo ''.($data[2]);?></td>
            </tr>
			<tr>
                <td class="menu_off">Nombre de Commande</td>
                <td class="menu_off">
					<?php
					$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 $data2[0];
					?>
                </td>
            </tr>
			<tr>
                <td class="menu_off">Adresse</td>
                <td class="menu_off"><?php echo ''.($data[3]);?></td>
            </tr>
			<tr>
                <td class="menu_off">Ville</td>
                <td class="menu_off"><?php echo ''.($data[4]);?></td>
            </tr>
			<tr>
                <td class="menu_off">Mail</td>
                <td class="menu_off"><?php echo ''.($data[5]);?></td>
            </tr>
			<tr>
                <td class="menu_off">N° Téléphone</td>
                <td class="menu_off"><?php echo ''.($data[6]);?></td>
            </tr>
            <tr>
                <td class="menu_off">Date de mise en ligne</td>
                <td class="menu_off"><?php echo date("d", strtotime($data['date_client'])).'-'.date("m", strtotime($data['date_client'])).'-'.date("Y", strtotime($data['date_client']));?></td>
            </tr>
            </table>
    </div>
    <div class="but_prec">
        <a href="admin_element.php?chaiz=<?php echo $chaiz;?>">Pr&eacute;c&eacute;dent</a>
    </div>
</div>
<?php
		break;

		case 'commande': $sql = 'SELECT * FROM '.$chaiz.', client WHERE client.id_client=commande.id_client AND id_commande='.$id.'';
			  $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
			  $data =$reponse->fetch();
			  $aff='Commande N°'.($data[0]).': '.$data[1].'<br> '.$data['montant_commande'].' Fcfa';
?>
<div id="toute_off" align="center" style="width:950px;">
    <div class="page"> <?php echo $aff;?></div>
        
    <div class="cov_off" style="border-radius:15px; margin-bottom:20px; width:910px;">
        	<table border="0" width="100%">
			<tr align="center" class="tete_tab">
                <td class="menu_off" colspan="2">Infos du client de la commande N°<?php echo $id;?></td>
            </tr>
			<tr>
                <td class="menu_off">Nom du Client</td>
                <td class="menu_off"><?php echo ''.($data['nom_client']);?></td>
            </tr>
			<tr>
                <td class="menu_off">Prénoms du Client</td>
                <td class="menu_off"><?php echo ''.($data['prenom_client']);?></td>
            </tr>
			<tr>
                <td class="menu_off">Mail du Client</td>
                <td class="menu_off"><?php echo ''.($data['mail_client']);?></td>
            </tr>
			<tr>
                <td class="menu_off">N° Téléphone du Client</td>
                <td class="menu_off"><?php echo ''.($data['tel_client']);?></td>
            </tr>
			<tr>
                <td class="menu_off">Adresse du Client</td>
                <td class="menu_off"><?php echo ''.($data['adresse_client']);?></td>
            </tr>
			<tr align="center" class="tete_tab">
                <td class="menu_off" colspan="2">Infos commande N°<?php echo $id;?></td>
            </tr>
			<tr>
                <td class="menu_off">Etat de la Commande</td>
                <td class="menu_off">
                	<form name="form1" action="" method="post">
                    
                    	<select name="etat">
                            <option value="attente" <?php if($data['etat_commande']=='attente') echo "selected"; ?>>En attente</option>
                            <option value="livrée" <?php if($data['etat_commande']=='livrée') echo "selected"; ?>>Livrée</option>
                            <option value="annulée" <?php if($data['etat_commande']=='annulée') echo "selected"; ?>>Annulée</option>
                        </select>
                        <input type="submit" value="Modifier l'Etat" name="valider">
                    </form>
                    <?php 
					if (isset($_POST['valider']))
					{
						$etat=addslashes($_POST['etat']);
						$req='UPDATE commande SET etat_commande="'.$etat.'" WHERE id_commande='.$id.'';
						$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
						echo '<font style="text-align:center; color:green;"><img src="img/vert.png" width="20"> L\'état de la commande a bien été modifié</font>';
						?> 
		<script type="text/javascript">window.setTimeout("location=('');",2000);</script>
						<?php
					}
					?>
                </td>
            </tr>
	
			<tr>
                <td class="menu_off">Adresse de Livraison</td>
                <td class="menu_off"><?php echo ''.($data['adresse_livraison']);?></td>
            </tr>
			<tr>
                <td class="menu_off">Article de la Commande</td>
                <td class="menu_off">
					<table width="99%" border="1" cellspacing="0">
                    	<tr>
                        	<td>Image</td>
                        	<td>Désignation</td>
                        	<td>Quantité</td>
                        	<td>Prix Unitaire</td>
                        	<td>Prix Total</td>
                        </tr>
					<?php
				
						$mt_tot=0;
					$sql3 = 'SELECT *
					FROM commande, commande_produit,produit
					WHERE commande_produit.id_commande=commande.id_commande AND produit.id=commande_produit.id_produit AND commande.id_commande='.$id.'';
					$reponse3=$bdd-> query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
					while ($data3 =$reponse3->fetch())
					{
					
                    ?>
                    	<tr>
                			<td>
                            	<img src="../../uploads/<?php echo $data3['img_produit']; ?>" width="80" height="60">
								
                            </td>
                			<td>
                            	<?php echo $data3['libelle']; ?>
                            </td>
                			<td>
                            	<?php echo $data3['quantite']; ?>
                            </td>
                			<td>
                            	<?php echo $data3['prix_produit']; ?>
                            </td>
                			<td>
                            	<?php echo $data3['prix_produit']*$data3['quantite']; $mt_tot+=$data3['prix_produit']*$data3['quantite']; ?>
                            </td>
                        </tr>
                    <?php 
					}
						
					?>
                    	<tr class="tete_tab">
                        	<td colspan="3">Prix Total de la commande</td>
                        	<td></td>
                        	<td colspan="2"><?php echo $data['montant_commande']; ?></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td class="menu_off">Date de la Commande</td>
                <td class="menu_off"><?php echo date("d", strtotime($data['date_client'])).'-'.date("m", strtotime($data['date_client'])).'-'.date("Y", strtotime($data['date_client']));?></td>
            </tr>
            </table>
    </div>

    <div class="but_prec">
        <a href="administration_suite.php">Pr&eacute;c&eacute;dent</a>
    </div>
</div>
<?php
		break;

		case 'produit': $sql = 'SELECT * FROM '.$chaiz.' WHERE id_prod='.$id.'';
			  $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
			  $data =$reponse->fetch();
			  $aff='Produit: '.($data[1]).'';
?>
<div id="toute_off" align="center">
    <div class="page"> <?php echo $aff;?></div>
    <div align="right"><a href="ajouter_element.php?chaiz=<?php echo $chaiz; ?>" class="myButton">Ajouter</a></div>    
        
    <div class="cov_off" style="border-radius:15px; margin-bottom:20px;">
        	<table border="0" width="100%">
			<tr>
                <td class="menu_off" width="36%">Nom</td>
                <td class="menu_off"><?php echo ''.($data[1]);?></td>
            </tr>
            <tr>
                <td class="menu_off">Description</td>
                <td class="menu_off"><?php echo ($data[2]);?></td>
            </tr>
            <tr>
                <td class="menu_off">Ancien Prix</td>
                <td class="menu_off"><?php echo ($data[4]);?></td>
            </tr>
            <tr>
                <td class="menu_off">Nouveau Prix</td>
                <td class="menu_off"><?php echo ($data[5]);?></td>
            </tr>
            <tr>
                <td class="menu_off">Image</td>
                <td class="menu_off"><img src="../../uploads/<?php echo ($data['img_prod']);?>" width="300"></td>
            </tr>
            <tr>
                <td class="menu_off">Date de mise en ligne</td>
                <td class="menu_off"><?php echo date("d", strtotime($data['date_prod'])).'-'.date("m", strtotime($data['date_prod'])).'-'.date("Y", strtotime($data['date_prod']));?></td>
            </tr>
            </table>
    </div>
    <div class="but_prec">
        <a href="admin_element.php?chaiz=<?php echo $chaiz;?>">Pr&eacute;c&eacute;dent</a>
    </div>
    <div class="but_prec">
        <a href="modifier_element.php?id=<?php echo ($data[0]);?>&chaiz=<?php echo $chaiz; ?>">Modifier</a>
    </div>
</div>
<?php
		break;

		case 'contact': $sql = 'SELECT * FROM '.$chaiz.' WHERE id_contact='.$id.'';
			$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
			$data =$reponse->fetch();
			$aff='Message de: '.($data[1]).' '.($data[2]);
?>
<div id="toute_off" align="center">
    <div class="page"> <?php echo $aff;?></div>
        
    <div class="cov_off" style="border-radius:15px; margin-bottom:20px;">
        	<table border="0" width="100%">
			<tr>
                <td class="menu_off" width="25%">Nom</td>
                <td class="menu_off"><?php echo ($data[1]);?></td>
            </tr>
            <tr>
                <td class="menu_off">Prénoms</td>
                <td class="menu_off"><?php echo ($data[2]);?></td>
            </tr>
            <tr>
                <td class="menu_off">N&deg;T&eacute;l&eacute;phone</td>
                <td class="menu_off"><?php echo ($data[3]);?></td>
            </tr>
            <tr>
                <td class="menu_off">Email</td>
                <td class="menu_off"><?php echo ($data[4]);?></td>
            </tr>
			<tr>
                <td class="menu_off">Son Message</td>
                <td class="menu_off"><?php echo ($data[5]);?></td>
            </tr>
             <tr>
                <td class="menu_off">Date d'envoie</td>
                <td class="menu_off"><?php echo ($data[6]);?></td>
            </tr>
            </table>
    </div>
    <div class="but_prec">
        <a href="admin_element.php?chaiz=<?php echo $chaiz;?>">Pr&eacute;c&eacute;dent</a>
    </div>
</div>

    <?php 		
		break;
		
		default: header ('Location: administration.php?anh_san=paray_ci');
}
?>

<table border="0" align="center"><tr>
    <td class="bouton_design">
    </td>
    <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>