Files

338 lines
9.5 KiB
PHP
Executable File

<?php
session_start();
//pour annulation du panier
$action=$HTTP_GET_VARS["action"];
//pour avoir un mini historique de la navigation et revenir sur les dernieres pages visitées
$idfamille=$HTTP_GET_VARS["idfamille"];
$idcateg=$HTTP_GET_VARS["idcateg"];
$page=$HTTP_GET_VARS["page"];
$edu=$_GET['edu'];
if ($edu!='')
echo "edu : ",$edu;
if (!$page) $page=$HTTP_POST_VARS["page"];
if (!$idfamille) $idfamille=$HTTP_POST_VARS["idfamille"];
if (!$idcateg) $idcateg=$HTTP_POST_VARS["idcateg"];
//si modification des quantité dans le panier
$produit=$HTTP_POST_VARS["produit"]; // id du produit dont la qtt a ete modifiee
$nb=$HTTP_POST_VARS["nb"]; // qtt du produit nouvellement insérée
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #FFFFFF;
}
a:hover {
text-decoration: underline;
color: #FFFFFF;
}
a:active {
text-decoration: none;
color: #FFFFFF;
}
.style1 {font-size: x-small}
.style2 {font-size: xx-small}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}
//-->
</script>
<link href="../style.css" rel="stylesheet" type="text/css">
</head>
<body class="bgcolor" text="white">
<?php
session_unregister("prixlig");
//si on reçoit nb alors modification de la qtt
if ($nb)
{
$qtecmd[$nb]=$qtt;
session_register("qtecmd[$nb]");
}
// print "qte commndé : $qtecmde";
/* ANNULE COMMANDE */
if ($action=="annule")
{
$i=0;
do
{
$prod[$i]="";
$qtecmd[$i]="";
session_unregister("prod[$i]");
session_unregister("qtecmd[$i]");
$i++;
} while ($i <= $compt);
$compt=0;
session_unregister("compt");
print "<br><h3><b><div align=center>Votre panier est vide</b></h3></div>";
}
else
{
if ($action!="annule")
{
if ($action=="valide")
{
/* VALID COMMANDE */
// INSERER ICI LE CODE POUR AJOUTER DANS LA BASE DE DONNEE
// 1- Client deja connecte : on a donc deja idcli et donc on fait un insert
// 2- Client pas connecte mais deja membre -> connection -> insert
// 3- Client pas connecte et pas membre -> inscription -> insert
if (isset($_SESSION['idcli']))
{
// CAS 1
// print "Client $idcli connecte";
}
}
if (!isset($_SESSION['compt']))
{
session_register("compt");
session_register("prod");
session_register("qtecmd");
}
?>
<table align="center">
<tr align="center">
<td colspan=7>
<h3><b> Produits commandes </b></h3>
<br>&nbsp
</td>
</tr>
<?php
// tant que i est inférieur au nombre de produit dans le panier ($compt)
$i=0;
do
{
require("../connexion.php");
$conn = mysql_connect($host, $user, $password);
mysql_select_db($bdd) or die("Impossible d'ouvrir la base de donnee $bdd");
//récupération des infos sur le produit
$requete4 = "select idprod,denomination,coef,pathphotobassedef from produit where idprod='$prod[$i]'";
$result4=mysql_query($requete4) or die ("Erreur SQL :$requete2<br>".mysql_error()."...");
while ($ligne4=mysql_fetch_row($result4))
{
$idprod=$ligne4[0];
$denomination=$ligne4[1];
$coef=$ligne4[2];
$photo=$ligne4[3];
}
// requete de récupération des prix du produit + incrémentation d'un compteur pour savoir le nombre de prix
$requete2 = "select idprix,prix,marge,qteprod from prix where idprod='$idprod' order by qteprod desc";
$result2=mysql_query($requete2) or die ("Erreur SQL :$requete2<br>".mysql_error()."...");
$h=0;
while ($ligne1 = mysql_fetch_row($result2))
{
$idprix[$h]=$ligne1[0];
$testprix[$h]=$ligne1[1];
$marge[$h]=$ligne1[2];
$qteprod[$h]=$ligne1[3];
//ici on teste marge : si le champsr est renseigné alors le prix est une URL -> on lit le résultat de l'url
if ($marge[$h])
{
$prix[$h]="http://crossover.codeweavers.com/vendor_price_query.php?user=tallagrand@airtria.fr;sku=".$testprix[$h];
$hwnd=fopen($prix[$h],"r");
$prix[$h] = fread($hwnd, 100);
fclose($hwnd);
if($edu=='on'){
$prix[$h]=$prix[$h]-$prix[$h]*0.3;
$prix[$h] = ($prix[$h] + ($prix[$h] * $marge[$h] / 100));}
else
$prix[$h] = ($prix[$h] + ($prix[$h] * $marge[$h] / 100));
} else {
$prix[$h] = $testprix[$h];
}
$h++;
}
$h--;
// on met le nb de prix du produit dans une variable appelé nbprix
$nbprix=$h;
// Modification du prix en fct du client prix = prix x (1 - coef du prod x(valeur de points / 100))
//on récupère d' adord la valuer de point du client
$req = "select vp from client where idcli='$idcli'";
$res = mysql_query($req) or die ("Erreur sql:$req<br>".mysql_error()."...");
while ($ligneres=mysql_fetch_row($res))
{
$vp=$ligneres[0];
}
// si l'id du produit est égal a l'id du produit dont la qtt a ete modifiée alors la quantité de produit commandée = $qtt (valeur insérée dans le formulaire)
if ($prod[$i]==$produit)
{
$qtecmd[$i]=$qtt;
session_register("qtecmd[$i]");
print "qtecmd[$i] = $qtecmd[$i]<br></br>";
}
?>
<tr align="center">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><img src="../images/esp.png" width="108" height="17"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr align="center" bordercolor="1">
<td colspan="5"><table width="200" border="1">
<tr align="center" bordercolor="1">
<td><a href="#" onClick="MM_openBrWindow('zoomprod.php?idprod=<?php print $idprod?>&idcateg=<?php print $idcateg?>&idfamille=<?php print $idfamille?>','Zoom','width=270,height=350')"><br>
<img src="../images/<?php print $photo?>" alt="zoom" width=75 height=75 border="0"/><br>
<br>
</a> </td>
<td> <img src="../images/esp.png" width="108" height="17"><br> <?php print $denomination?><br>
<img src="../images/esp.png" width="108" height="17"> </td>
<td>
<img src="../images/esp.png" width="177" height="9"><br>
<table>
<form name="fairien">
<tr align=center >
<td colspan=3><table border=0 align="center">
<tr align="center" >
<td colspan=3> <span class="style2"><b>
<?php
// Affichage des prix
for ($j=0;$j<=$nbprix;$j++)
{
$prix[$j]= $prix[$j] * (1 - $coef * ($vp / 100));
?>
Prix pour <?php print $qteprod[$j]?> produit(s) : <?php print round($prix[$j],2)?> € ht<br>
<?php
}
?>
</span></td>
</tr>
</table> </td>
</tr>
</form>
</table></td>
<td>
<img src="../images/esp.png" width="246" height="17"><br>
<?php
//qtecmde=nb de produit commandé
$qtecmde=$qtecmd[$i];
?>
<form name="f1" action="panier.php" method="POST">
<input type="hidden" name="page" value="<?php print $page?>"/>
<input type="hidden" name="idfamille" value="<?php print $idfamille?>"/>
<input type="hidden" name="idcateg" value="<?php print $idcateg?>"/>
<input type="hidden" name="produit" value="<?php print $idprod?>"/>
<span class="style1"> Qtt</span>
<input type="text" name="qtt" size=4 value="<?php print $qtecmd[$i]?>"/>
<input type="hidden" name"nb" value="<?php print $i?>"/>
<input type=submit name=f1 value="Modifier"/>
</form></td>
<td>
<img src="../images/esp.png" width="81" height="10"><br>
<?php
// calcul du prix
for ($r=0;$r<=$nbprix;$r++)
{
while ($qtecmde>=$qteprod[$r])
{
$prixligne[$i]+=$prix[$r];
$prixligne[$i]=round($prixligne[$i],2);
$qtecmde = $qtecmde - $qteprod[$r];
}
}
print $prixligne[$i];
$prixlignes[$i]=$prixligne[$i];
session_register('prixlignes');
$prixtot += $prixligne[$i];
?>
</td>
</tr>
</table></td>
</tr>
<br><br>
<?php
$i++;
}
while ($i <= $compt);
?>
<tr>
<td colspan=5>
<div align="center">
</div>
</td>
</tr>
</table>
<table width="200" border="0" align="center">
<tr>
<td><div align="center"><b>Prix Total : <br>
<?php print $prixtot?></b> </div></td>
</tr>
</table>
<br><br>
<div align="center">
<?php
if ( !isset($_SESSION['idcli']) )
{
?>
<a href="../membres/login.php?page=<?php print $page?>&idprod=<?php print $idprod?>&idcateg=<?php print $idcateg?>&idfamille=<?php print $idfamille?>">Valider la commande</a>&nbsp&nbsp
<?php
} else {
?>
<a href="validpanier.php?prixtot=<?php print $prixtot?>&page=<?php print $page?>&idprod=<?php print $idprod?>&idcateg=<?php print $idcateg?>&idfamille=<?php print $idfamille?>">Valider la commande</a>&nbsp&nbsp
<?php
}
?>
<a href="panier.php?action=annule&page=<?php print $page?>&idprod=<?php print $idprod?>&idcateg=<?php print $idcateg?>&idfamille=<?php print $idfamille?>">Annuler la commande</a>
</div>
<div align="center">
<b>
<a href="panier.php?edu=on">Mettre au tarif éducation </a><a href="panier.php?edu=off"> Mettre au tarif normal</a>
</div>
<?php
}
}
?>
<br><br>
<div align=center>
<a href="index.php?idprod=<?php print "$idprod";?>&idcateg=<?php print $idcateg?>&idfamille=<?php print $idfamille?>">retour</a>
</div>
</body>
</html>