<?php
	session_start();
	
	$_SESSION['database']="public";
	
	if($_SESSION['database']=="local")
	  {
	     $db_host    = "localhost";
	     $db_user   = "root";
	     $db_pass   = "";
     	     $db_name   = "boutique";

	 }
	
	if($_SESSION['database']=="public")
	  {
  	     $db_host    = "sql2";
   	     $db_user   = "analogde";
 	     $db_pass   = "rainbow";
    	     //$db_type   = "mysql";
	     $db_name   = "analogde";
	 }
	 
     	 $connexion = mysql_connect($db_host,$db_user,$db_pass); 
   	 mysql_select_db($db_name, $connexion);

	 $email = $_GET['email'];
	 $id = $_GET['id'];

	 $requete = "SELECT commande,livraison,reglement,total_ttc,total_ht,frais_livraison FROM commandes WHERE id='$id' ";
	 $result = mysql_query($requete);
	 $data_cmd = mysql_fetch_array($result);
	 
	 $requete = "SELECT email,nom,prenom,adresse,complement,telephone,civilite,cp,ville FROM clients WHERE email='$email' ";
	 $result = mysql_query($requete);
	 $data_client = mysql_fetch_array($result);
	 
	 // 0  TF785
	 // 1  XXX789
	 // 2  lave_linge Bosh XXX789
	 // 3  washer
	 // 4  4
	 // 5  1200.00
	 // 6  1100.00
	 //XV37K09-REF456-lave_linge Brandt REF456-washer-2-549.00-645.00
	 
	 $articles = explode("-" , $data_cmd['commande']);
     	 $nb_articles = count($articles)/7; 
	 
	 $requete = "SELECT * FROM commandes WHERE email='$email' ";
 	 $result = mysql_query($requete);
	 
	 $ptr = 0;
	
	 while($row = mysql_fetch_assoc($result))
	      {
   		$id_cmd[$ptr] = $row["id"];
	        $ptr = $ptr + 1;
              }
	 
?>	 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Administration - Patrice Delpy</title>

<link rel="stylesheet" href="default.css" type="text/css">

</head>

<body>

<div id="header"><h1>Administration</h1>
<div class="membre">Vous êtes connecté en tant qu'<b>admin</b></div>
</div>

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

		<br>
		<table cellspacing="1" cellpadding="2" border="0" bgcolor="#D5D5D5" width="75%" style="margin-bottom: 0px" align="center">
		<tr bgcolor="#F1F3F5">
		<td colspan="7" align="left"><div class="heading">Edition commande</div></td>
		</tr>
		<tr bgcolor="#E8E5DE">
		<th colspan="7" align="left">Client</th>
		</tr>

		<tr bgcolor="#ffffff">
		<td colspan="7">
  		<table width="100%">
		<tr>
		<td valign="top"  align="left">
		<b class="blue"><?php echo $data_client['civilite']. " " .$data_client['prenom']. " "  .$data_client['nom']  ; ?></b>
		</td>
			
		<td align="left">
		<b>Email</b> : <?php echo $data_client['email']; ?> <br />
		<b>T&egrave;l</b> : <?php echo $data_client['telephone']; ?> <br />
<!--		<b>Portable</b> : <?php echo $data_client['telephone']; ?> <br /><br />  -->
		</td>
		</tr>
		
		<tr>
		<th align="left">Adresse de facturation</th>
		<th align="left">Adresse de livraison</th>
		</tr>
		  
		<tr>
		<td align="left">
		<?php echo $data_client['civilite']. " " .$data_client['prenom']. " "  .$data_client['nom']  ; ?>
		<br />
		<?php echo $data_client['adresse']; ?><br />
		
		<?php 
			if($data_client['complement'] != "")
		          { echo $data_client['complement'];
		            echo "<br/>";
			  }	
		
		?>
		<?php echo $data_client['cp']. " " .$data_client['ville']; ?>   <br />
		France
		</td>
		
		<td align="left">
		<?php echo $data_client['civilite']. " " .$data_client['prenom']. " "  .$data_client['nom']  ; ?>
		<br />
		<?php echo $data_client['adresse']; ?><br />
		
		<?php 
			if($data_client['complement'] != "")
		          { echo $data_client['complement'];
		            echo "<br/>";
			  }	
		?>
		<?php echo $data_client['cp']. " " .$data_client['ville']; ?>   <br />
		France
		</td>
		</tr>
		</table>

		</td>
		</tr>
		
		  
		<tr bgcolor="#e8e5de">
		<th colspan="7" align="left">Detail de la comande</th>
		</tr>

		<tr bgcolor="#f3f1ed">
		<th align="center">Référence</th>
		<th align="center">Article</th>
		<th align="center">Prix unitaire TTC</th>
		<th align="center">Prix unitaire HT</th>
		<th align="center">Taxe</th>
		<th align="center">Qte</th>
		<th align="center">Total</th>
		</tr>
<?php
		$ptr = 0;

                for($i=0;$i<$nb_articles;$i++)
	           { 
	         	
		   	 	// 0  TF785
			 	// 1  XXX789
			 	// 2  lave_linge Bosh XXX789
			 	// 3  washer
			 	// 4  4
			 	// 5  1200.00
			 	// 6  1100.00
			 	//XV37K09-REF456-lave_linge Brandt REF456-washer-2-549.00-645.00
	         	
				$idx1 = $ptr +1;       // reference
				$idx2 = $ptr +2;       // article
				$idx3 = $ptr +3;       // table
				$idx4 = $ptr +4;       // qte	
				$idx5 = $ptr +5;       // ttc
				$idx6 = $ptr +6;       // ht
				
				$requete = "SELECT * FROM $articles[$idx3] WHERE reference='$articles[$idx1]' ";
				$result = mysql_query($requete);
	 			$data = mysql_fetch_array($result);
				
				$tva = $data['tva'];
				$total_ligne = $articles[$idx4] * $articles[$idx5];
				
				echo "
						<tr bgcolor=\"#ffffff\">
				  		<td align=\"left\" nowrap=\"nowrap\">$articles[$idx1]</td>
						<td align=\"left\" nowrap=\"nowrap\">$articles[$idx2]</td>
						<td align=\"right\" nowrap=\"nowrap\">$articles[$idx5] &nbsp;€</td>
						<td align=\"right\" nowrap=\"nowrap\">$articles[$idx6] &nbsp;€</td>
						<td align=\"center\" nowrap=\"nowrap\">$tva</td>
						<td align=\"center\" nowrap=\"nowrap\">$articles[$idx4]</td>
<!--						<td align=\"center\" nowrap=\"nowrap\"><b class=\"green\">100</b></td>  -->
						<td align=\"right\" nowrap=\"nowrap\">$total_ligne &nbsp;€</td>
						</tr>  ";
						$ptr = $ptr + 7;										
			 }
			  
			  $total = $data_cmd['total_ttc'] + $data_cmd['frais_livraison'];
?>              
              
              	<tr bgcolor="#e8e5de">
	      	<th colspan="7" align="left">Sous Total TTC:  <?php echo "           " .$data_cmd['total_ttc'];  ?> &nbsp;&euro; </th>
	      	</tr>
			
		<tr bgcolor="#e8e5de">
	      	<th colspan="7" align="left">Sous Total HT:  <?php echo "           " .$data_cmd['total_ht'];  ?> &nbsp;&euro; </th>
	      	</tr>	
			  
	      	<tr bgcolor="#e8e5de">
	      	<th colspan="7" align="left">Frais livraison:  <?php echo "           " .$data_cmd['frais_livraison'];  ?> &nbsp;&euro; </th>
	      	</tr>
			  	
	      	<tr bgcolor="#e8e5de">
	      	<th colspan="7" align="left">Mode de livraison:  <?php echo "           " .$data_cmd['livraison'];  ?> </th>
	      	</tr>			  				  
              
              	<tr bgcolor="#e8e5de">
      		<th colspan="7" align="left"> Total:  <?php echo "           " .$total;  ?> &nbsp;&euro; </th>
	      	</tr>
              
		<tr bgcolor="#ffffff">
	      	<td colspan="6" align="left">

	       	<form action="" method="POST" name="formulaire_commande">
		<input name="C1" value="CL" type="hidden">
		<input name="C2" value="CO" type="hidden">
		<input name="C3" value="update_status" type="hidden">
		<input name="IDO" value="9" type="hidden">
		<input name="IDC" value="2236" type="hidden">

		<br>Status actuel : <b class="green">Commande en attente de paiement</b><br><br>
		Changer de status : 
		
		<select name="etat" size="1">
		<option selected="selected" value="XX">-- [ Choisissez un nouveau status ] --</option>
		<option value="CL">Commande annul�e</option>
		<option value="CS">Commande en attente -&gt; rupture de stock</option>
		<option value="CC">Commande en cours de préparation</option>
		<option value="CV">Commande validée</option>
		<option value="CT">Commande en cours de livraison</option>
		<option value="CL">Commande livrée</option>
		</select>&nbsp;&nbsp;

		<input name="modifier_etat" value="Valider le changement de status" type="submit" />
		<br>
		<br>
		</form>

		</td>
		<td align="center" valign="middle">
	  	Paiement choisit : <br> <?php echo $data_cmd['reglement'];  ?><br /><br />
<!--	  	<img src="./images/CR.png" alt="CR" title="Contre remboursement" /><br /><br />Contre remboursement  -->
                  <!--
                  <a href="../facture.php?IDC=168&IDO=10" target="_blank"><img src="./images/print1.jpg" title="Afficher la facture" /></a><br />
				  [ <a href="../facture.php?IDC=168&IDO=10" target="_blank">Afficher la facture</a> ]
                  -->

		</td>
		</tr>
		</table>

		</body>
		</html>