<?php

session_start();

	$nb_articles = count($_SESSION['panier']['id']);

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml" lang="fr"><head>
  

<title>Panier virtuel - Achat en ligne  </title>
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">

<link rel="stylesheet" href="gb_styles.css" media="screen,projection" type="text/css">
<link rel="stylesheet" href="gabarit_gps.css" type="text/css">
<link rel="stylesheet" href="style_new.css" type="text/css">
<link rel="stylesheet" href="top_gps.css" type="text/css">
<link rel="stylesheet" href="top.css" type="text/css">
<link rel="stylesheet" href="shopping_cart.css" type="text/css">
<link rel="SHORTCUT ICON" href="http://www.webdistrib.com/favicon.ico">

</head>

<body>

		

<script type="text/javascript">

function request(parametre) {
	
	var XHR = null;

		if(window.XMLHttpRequest) // Firefox
			XHR = new XMLHttpRequest();
		else if(window.ActiveXObject) // Internet Explorer
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
		else { // XMLHttpRequest non supporté par le navigateur
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		return;
		}

		if(XHR != null){
		document.getElementById('div1').innerHTML  ="Patientez...";
		}

		// envoie de la requête, methode plus url
		XHR.open('POST','demo2.php', true);
		// header et des paramètres
		XHR.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		
		//XHR.send('var=123');
		XHR.send(parametre);

		// on guette les changements d'état de l'objet
		XHR.onreadystatechange = function attente() 
		                           {
						// l'état est à 4, requête reçu !
						if(XHR.readyState == 4)
						  {
							if(XHR.status == 200)
							  { // ecriture de la réponse
							    document.getElementById('div1').innerHTML = XHR.responseText;
			                                  }
		                                  }
		                           }

		// le travail est terminé	
		return;
}


function update_qte(id, val)
 {
 	
 	var valeur = document.getElementById(id).value;
	//alert("Contenu: " + valeur + " item");
 	quantite = parseInt(valeur) + parseInt(val);
	if (quantite < 1) { quantite = 1; }
	if (quantite > 99) { quantite = 99; }
 	document.getElementById(id).value=quantite;
 	

	var element = "prix0";
	prix = document.getElementById(element).value
	//alert("Prix: " + prix + " item");
	
	somme = prix * quantite;
	
	//alert("Tarif: " + somme + " euros");
	
	// rafraichir
	
	//header("Location: dev_panfffier.php");
	//location.reload() ; 
	//window.location.replace("dev_panier.php");
	parametre = 'var=quantite';
	//xhr.send("var="+quantite);
	//request("qte="+quantite);
	//request("index="+id);
	
	data="index="+id+"&qte="+quantite;
	request(data);
	//data="val_1="+arg1+"&val_2="+arg2+"&val_3="+arg3;



}


function doOnChangeQty(id)
 {
	
	var quantite = document.getElementById(id).value;
	if(quantite < 1) 
	  { quantite = 1; }
 	document.getElementById(id).value=quantite;
	
	//alert("Contenu: " + quantite );
	
	data="index="+id+"&qte="+quantite;
	request(data);
}


</script>





<div id="pagewidth">
<div id="header">
<div id="infoscontact"></div>
</div>


<div id="wrapper" class="clearfix">
<form name="form_panier" method="post" action="panier.php">
<div class="TxtOrange"><a href="../home.php" class="TxtOrange">Accueil</a> » 
<a href="shopping_cart.php" class="TxtOrange">Panier</a>
</div>

<div class="btntop" align="right">
</div>
<div id="shoppingcartlisting">
<input id="nbProducts" name="nbProducts" value="2" type="hidden">
<input id="nbProducts2" name="nbProducts2" value="2" type="hidden">


<?php

			
			
				print_r($_POST);   
  
  
				  if($_POST['qte']==123)
    				{ echo "POST";}

			if(!isset($_POST['qte']) )
			 {
 				echo '<body onLoad="alert(\'Securité...\')">'; 
				//$_SESSION['panier']['qte'][0]=$_POST['qte'];
			 }


			if($_POST['qte'] != 0)
			{ 	$_SESSION['panier']['qte'][$_POST['index']]=$_POST['qte'];

			}	
			
			

			if(!isset($_SESSION['panier']))
			 {
    				/* Initialisation du panier */
    				/*$_SESSION['panier'] = array();
    				/* Subdivision du panier */
    				/*$_SESSION['panier']['id'] = array();
    				$_SESSION['panier']['qte'] = array();
    				$_SESSION['panier']['designation'] = array();
    				$_SESSION['panier']['prix_ttc'] = array();
    				$_SESSION['panier']['prix_ht'] = array();*/
			}
 	
		  
		   	$action = $_GET[action]; 
		   	
		   	if($action == "plus")
		          { echo '<body onLoad="alert(\'Plus\')">'; 
		            $_SESSION['panier']['qte'][$_GET[indice]] = $_SESSION['panier']['qte'][$_GET[indice]]+1;
			    $_GET[action] ="";
	
		          }
		   	
		   	if($action == "moins")
		          { echo '<body onLoad="alert(\'Plus\')">'; 
		            $_SESSION['panier']['qte'][$_GET[indice]] = $_SESSION['panier']['qte'][$_GET[indice]]-1;
             		    if($_SESSION['panier']['qte'][$_GET[indice]] == 0)	
                            {  echo '<body onLoad="alert(\'Aucun article\')">'; 
                            	$action = "efface";
			    }
		          }
		   	
		   	
			 if($action == "efface")
		           {    echo "efface";	
		                $indice =  $_GET[indice];  
		         	array_splice($_SESSION['panier']['id'], $indice, 1);
			 	array_splice($_SESSION['panier']['designation'], $indice, 1);
			 	array_splice($_SESSION['panier']['qte'], $indice, 1);
			 	array_splice($_SESSION['panier']['prix_ttc'], $indice, 1);
			 	array_splice($_SESSION['panier']['prix_ht'], $indice, 1);
			 	print_r($_SESSION['panier']);   
			 	$nb_articles = count($_SESSION['panier']['id']);
			 	//echo "Nombres articles:" .$nb_articles;
			 	if($nb_articles == 0)
			   	{  $display = "0";
			   	}
			 	else {
				        $display = "1";
				      }    
		           }
		           
		           if($_GET['valide'] == "ok") 
		             {
 				echo '<body onLoad="alert(\'Securité...\')">'; 
			     }	

?>




<div><img src="cart.gif" alt=""> <h1 class="TxtOrange">VOTRE PANIER</h1></div>

<?php
	if($nb_articles != 0)
	  { echo "<div>Votre panier contient "; 
	    echo $nb_articles; 
	    echo " article(s)</div> ";
	  }

	if($nb_articles == 0)
	  { echo "<div>Votre panier est vide </div>";
	  }

?>





<div class="cart">
<div class="cartheader clearfix">
<ul class="ListeHorizontale">
<li class="cartheadercol1">Article</li>
<li class="cartheadercol2">Quantité</li>
<li class="cartheadercol3">Prix unitaire TTC<br>(Eco-participation incluse)</li>
<li class="cartheadercol4">Total</li>
<li class="cartheadercol5">Supprimer</li>
</ul>
</div>

<input type="hidden" id="nb_produits" name="nb_produits" value="<?php echo $nb_articles; ?>" />


<input type="hidden" name="valide" id="valide" value=""> 
	
	
	

<?php



	for($i=0;$i<count($_SESSION['panier']['id']);$i++)
	   { $total+=$_SESSION['panier']['prix_ttc'][$i]*$_SESSION['panier']['qte'][$i];
	     $prix = "prix".$i;
	     $boite ="elem".$i;
?>
		<div class="cartlisting clearfix noLast">
		<ul class="ListeHorizontale">
		<li class="cartlistingcol1">
		<img src="shopping_cart.php_fichiers/m684708.jpg" alt="Moniteur LCD SAMSUNG P2770H 27" (68cm)="" width="60"></li>	
		<li class="cartlistingcol2 TxtRouge">
		<a href="http://www.webdistrib.com/cat/product_info.php?productId=684708" class="txtLibelle">
		<b><?php echo $_SESSION['panier']['designation'][$i]; ?></b></a>
		</li>
		<li class="cartlistingcol3">
		<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td>
		

		<input id="<?php echo $i;  ?>" name="<?php echo $i;  ?>" value="<?php echo $_SESSION['panier']['qte'][$i]; ?>"
		onchange="JavaScript:doOnChangeQty(<?php echo $i; ?>);"	 size="4" type="text">&nbsp;</td>
		<td>
		
		
		<a href="demo2.php" onclick="update_qte(<?php echo $i; ?>,1);return(false)">
		<img src="plus.gif" alt="Ajouter"></a><br>
		
		<a href="javascript:update_qte(<?php echo $i; ?>,-1);">
		<img src="moins.gif" alt="Retirer"></a>
		
		
		</td></tr></tbody></table>
		
		</li>
		<li class="cartlistingcol4 Txt14"><b><?php echo $_SESSION['panier']['prix_ttc'][$i]; ?> &#8364;</b></li>
		
		<input type="hidden" id="<?php echo $prix; ?>" name="<?php echo $prix; ?>" value="<?php echo $_SESSION['panier']['prix_ttc'][$i]; ?>" />

		<li class="cartlistingcol5 Txt14"><b><?php echo $_SESSION['panier']['prix_ttc'][$i]*$_SESSION['panier']['qte'][$i]; ?> &#8364;</b></li>
		<li class="cartlistingcol6">
		
		<a href="dev_panier.php?action=efface&indice=<?php echo $i; ?> " onclick="JavaScript:doOnClickSuppr('1');">
		<img src="del.gif" alt="Supprimer ce produit"></a>
		
	
		</li>
		</ul>
		</div>
		
<?php
	}
	
	
	
?>		




<div class="cartfooter clearfix">
<ul class="ListeHorizontale">
<li class="cartfootercol1"><a href="#" onclick="javascript:window.open('../dynpop/proforma.php','proforma','width=800,height=600');return
 false;"><img src="shopping_cart.php_fichiers/proforma.gif" alt="Facture
 proforma"></a></li>

<li class="cartfootercol2 TxtOrange"><b>TOTAL DE VOTRE COMMANDE : <span 
class="Txt14 TxtRouge"><?php echo $total; ?> &#8364;</span></b></li>
</ul>
</div>
</div></div>
<div align="right">
<br>

<a href="javascript:history.go(-1);">
<img src="btn_addproduct.gif" alt="Continuez vos achats"></a>&nbsp;&nbsp;

<a href="validation_commande.php">
<img src="btn_passorder.gif" alt="Passez votre commande"></a>
</div>
</form>

<div id="div1">affichage du resultat</div>


<br>
</div>


</div>

</body></html>

<?php
// page retour F5
//echo "<script>location.replace('panier.php');</script>";
?>