<?php

	session_start();
	
	$_SESSION['database']="local";
	
	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);
	 
	 //$id = 10;
	 //$email = "patrice.delpy@sfr.fr";

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

	 $requete = "SELECT commande,livraison,reglement,total_ttc,total_ht 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);
	 
	 $articles = explode("," , $data_cmd['commande']);
     	 $nb_articles = count($articles)/5; 
	 
	 $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;
	    		     }
	 
	 //print_r($id_cmd);
	 //print_r($articles);
	 
	 //echo $data_client['total_ttc'];
 	 //echo $data_client['total_ht'];
	 
	 
?>	 


<!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 - shop001</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>

			<table style="margin-bottom: 0px;" width="75%" align="center" bgcolor="#d5d5d5" border="0" cellpadding="2" cellspacing="1">
			<tbody><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%">
			  <tbody><tr>
				<td valign="top" width="25%" align="left">
				  <b class="blue"><?php echo $data_client['civilite']. " " .$data_client['prenom']. " "  .$data_client['nom']  ; ?></b><br><br>
				  <b>Email</b> : <?php echo $data_client['email']; ?> <br>
				  <b>Tèl</b> : <?php echo $data_client['telephone']; ?> <br>
				  <b>Portable</b> : 
				</td>
				<td valign="top" width="25%" align="left">
				<b>Adresse :</b><br>
				<?php echo $data_client['adresse']; ?><br>
				<?php echo $data_client['complement']; ?><br>
                <?php echo $data_client['cp']. " " .$data_client['ville']; ?>   <br>
				France
				</td>
				<td width="50%" align="left">
				  <b>Commantaire client</b> :<br>
				  <p style="color: rgb(128, 128, 255);">nada</p>
				</td>
			  </tr>
			</tbody></table>

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

		  <tr bgcolor="#f3f1ed">
			<th width="20%" align="center">Référence</th>
			<th align="center">Article</th>
			<th width="10%" align="center">Prix unitaire</th>
			<th width="5%" align="center">Qte</th>
			<th width="5%" align="center">Stock</th>
			<th width="10%" align="center">Total</th>
		  </tr>
          

<?php

//Array ( [0] => P-221 [1] => lave_linge [2] => 1 [3] => 714.2 [4] => VV3474 [5] => lave_linge [6] => 1 [7] => 551.5 ) 
//P-221,lave_linge , 1, 714.2, VV3474,lave_linge , 3, 551.5
//F478,lave-vaiselle , 5, 419.5, 499, Plasma, TV,2, 928.89, 1125, Laptop Sony, 2, 401.1, 449
//Camescope,video , 1, 619.5, 799


		  $ptr = 0;

          for($i=0;$i<$nb_articles;$i++)
	         { 
				$idx1 = $ptr;          // reference
				$idx2 = $ptr +1;       // table
				$idx3 = $ptr +2;       // qte	
				$idx4 = $ptr +3;       // ttc
				$idx5 = $ptr +4;       // ht
				
				
				//$articles[$idx1] = trim($articles[$idx1]);
				//$articles[$idx2] = trim($articles[$idx2]);
				//$articles[$idx3] = trim($articles[$idx3]);
				//$articles[$idx4] = trim($articles[$idx4]);
				
				$total_ligne = $articles[$idx3] * $articles[$idx4];
				
				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[$idx4] &nbsp;€</td>
							<td align=\"center\" nowrap=\"nowrap\">$articles[$idx3]</td>
							<td align=\"center\" nowrap=\"nowrap\"><b class=\"green\">100</b></td>
							<td align=\"right\" nowrap=\"nowrap\">$total_ligne &nbsp;€</td>
							</tr>  ";
				$ptr = $ptr + 5;										
										
			 }
			  
?>              
             
              
              
              
              <tr bgcolor="#e8e5de">
				<th colspan="6" align="left">Total  </th>
                
               
			  </tr>
              
              
              <tr bgcolor="#e8e5de">
				<th colspan="6" align="left">Actions</th>
			  </tr>
              

			  <tr bgcolor="#ffffff">
				<td colspan="6" align="left">

				  <form action="" method="POST" name="formOrder">
					<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="orderStatus" size="1"><option selected="selected" value="XX">-- [ Choisissez un nouveau status ] --</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="modifOrderStatus" value="Valider le changement de status" type="submit" />
<br><br>
				  </form>

			

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



</body>
</html>