1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
| <?php
session_start(); // Sert à démarrer une session.
//*******************************************INITIALISATION DES VARIABLE***********************************************
//----------------------
if(!isset($_SESSION['total'])) /* $_SESSION[] -> tableau global contenant toutes les variables de sessions pour la session courante*/
$_SESSION['total']=0;
//----------------------
if(!isset($_GET['ajoutPanier']))
$ajoutPanier=""; // Init de ajoutPanier.
else $ajoutPanier=$_GET['ajoutPanier']; // On récup la valeur de ajoutPanier qui est passée par URL.
//----------------------
if(!isset($_GET['modifPanier']))
$modifPanier=""; // Init de modifPanier.
else $modifPanier=$_GET['modifPanier'];
//----------------------
if(!isset($_GET['suppPanier']))
$suppPanier=""; // Init de suppPanier.
else $suppPanier=$_GET['suppPanier'];
//----------------------
if(!isset($_GET['enregistreCommande']))
$enregistreCommande=""; // Init de enregistreCommande.
else $enregistreCommande=$_GET['enregistreCommande'];
//----------------------
if(!isset($_GET['article']))
$article=""; // Init de article.
else $article=$_GET['article'];
//----------------------
if(isset($_SESSION['liste']))
$liste=$_SESSION['liste']; // $Liste prend les valeurs de la liste contenue dans la variable de session.
//**************************************FIN DE INITIALISATION DES VARIABLE*********************************************
?>
<?php
//**********************************UTILISATION DES PARAMETRES DE CONNEXION DE LA BDD**********************************
require_once('../Connections/ConnexionBoutique.php');
?>
<?php
mysql_select_db($database_ConnexionBoutique, $ConnexionBoutique); // Sélectionne une base de données MySQL
//*******************************************SCRIPT AJOUT PANIER******************************************************
if ($ajoutPanier=="AJOUTER")
{
$reference=$_GET['reference'];
$nb=1; // La quantité par défaut est égale à 1.
$prix=$_GET['prix'];
$liste[]=array($reference,$nb,$prix,$prix); // Création d'un tableau dynamique.
$_SESSION['liste']=$liste;
}
//*******************************************SCRIPT MODIF PANIER******************************************************
if($modifPanier=="ACTUALISER")
{
for($i=0;$i<count($liste);$i++)
{
$nbi='nb'.$i; // Concaténation
$list[$i][1]=$_GET["$nbi"]; // recup du nombre d'article dans la liste
$liste[$i][3]=$liste[$i][1]*$liste[$i][2]; // prixArticle=nbre*prixUnitaire
}
$_SESSION['liste']=$liste; // mAj de la liste
}
//*******************************************SCRIPT SUPP PANIER*******************************************************
if($suppPanier=="SUPPRIMER")
{
for($i=0;$i<count($liste);$i++)
{
if($article==$i)
array_splice($liste,$i,1); // Suppression de l'article.
}
$_SESSION['liste']=$liste; // mAj de la liste
}
//*****************************************SCRIPT ENREGISTRER CMDE****************************************************
if($enregistreCommande=="COMMANDER")
{
if(!isset($_GET['action'])) // Si la variable action n'a pas encore de valeur, alors
$_SESSION['action']="ENREGISTRER"; // Mémorisation de l'action dans une variable de session avec la valeur //"ENREGISTRER"
// header("Location: commande.php"); //Ne fonctionne pas, je ne sais pas pourquoi, donc j'utilise le javascript // suivant:
// On redirige automatiquement l'utilisateur vers la fiche pour commander:
echo '<script language="Javascript">
<!--
document.location.replace("commande.php");
// -->
</script>';
}
?>
<!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"><!-- InstanceBegin template="/Templates/Modele Public.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
</head>
<body>
<div align="center"><img src="../images/bandeauapublic.GIF" width="650" height="156" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="rect" coords="6,114,156,157" href="catalogue.php" />
<area shape="rect" coords="187,115,299,155" href="panier.php" />
<area shape="rect" coords="316,114,495,159" href="commande.php" /><area shape="rect" coords="529,114,642,160" href="../Administrateur/index.php" />
</map></div>
<table width="912" height="94" border="0" align="center">
<tr><!-- InstanceBeginEditable name="regionPublicModifiable" -->
<th scope="col">
<?php
if(isset($liste)) //affiche le tableau que s'il y a au moins un article.
{
?>
<form id="formulairePanier" name="formulairePanier" method="get" action="panier.php">
<table width="802" border="2">
<tr>
<th width="188" scope="col">Référence</th>
<th width="158" scope="col">Quantité</th>
<th width="182" scope="col">Prix</th>
<th width="244" scope="col">Supprimer</th>
</tr>
<?php
$total=0.00; // Initialisation du total de la commande à 0.
for($i=0;$i<count($liste);$i++)
{ // Déf. de la requête SQL afin de récupérer les informations de l'article stockées dans la BDD
// La requete suiv. prend tous les champs de la table articles en fonction de la référence de chaque article:
$query_rsPanier="select * from articles where reference='".$liste[$i][0]."'"; // dimx=$i : Les articles / //dimy=0: reference
$rsPanier=mysql_query($query_rsPanier, $ConnexionBoutique);
$row_rsPanier=mysql_fetch_assoc($rsPanier); // Retourne un tableau associatif qui contient la ligne lue dans le // résultat $rsPanier
?>
<tr>
<td><div align="center">
<?php
echo $row_rsPanier['nom']
?></div></td>
<td><label>
<div align="center">
<select name="nb<?php echo $i ?>" id="nb" > <!-- Affiche nb0, nb1, nb2, etc.-->
<!-- value indique la valeur envoyée au serveur si cette option est choisie -->
<option value="1" <?php if($liste[$i][1]==1) echo "SELECTED"; ?>>1</option>
<option value="2" <?php if($liste[$i][1]==2) echo "SELECTED"; ?>>2</option>
<option value="3" <?php if($liste[$i][1]==3) echo "SELECTED"; ?>>3</option>
</select>
</div>
</label></td>
<td><div align="center">
<?php
echo $row_rsPanier['prix']
?>
</div></td>
<td><div align="center">
<a href="panier.php?suppPanier=SUPPRIMER&article=<?php echo $i ?>">
<img src="../images/Next.gif" width="20" height="12" /></div></td>
</tr>
<?php
$total+=$row_rsPanier['prix'] * $liste[$i][1];
} // FIN DU BLOC FOR
$_SESSION['total']=$total; // Mémorise le total dans la session.
?>
<tr>
<td> </td>
<td> </td>
<td><div align="center">TOTAL: <?php echo $total ?> Euros </div></td>
<td> </td>
</tr>
</table>
<p>
<label>
<input type="submit" name="modifPanier" value="ACTUALISER" />
</label>
<label>
<input type="submit" name="enregistreCommande" value="COMMANDER" />
</label>
</p>
</form>
<?php } else { ?>
<p align="center"><strong><font size="4" face="Verdana, Arial, Helvetica, sans-serif">Votre panier est vide</font></strong></p>
</th>
<?php
} // FIN DU TEST isset($liste)
?>
<!-- InstanceEndEditable --></tr>
</table>
<div align="center"><img src="../images/BarreBasPublic.GIF" width="649" height="18" />
</div>
</body>
<!-- InstanceEnd --></html> |
Partager