-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanier.php
136 lines (112 loc) · 4.5 KB
/
panier.php
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
<?php
require_once'functions/check-cookies.php';
require_once'functions/fonctions-panier.php';
$erreur = false;
if(!isset($_SESSION['first_name'])){
echo "<script>alert(\"Veuillez vous connecter pour ajouter un élément à votre panier !\")</script>";
}
else
{
$action = (isset($_POST['action'])? $_POST['action']: (isset($_GET['action'])? $_GET['action']:null )) ;
if($action !== null)
{
if(!in_array($action,array('ajout', 'suppression', 'refresh', 'Valider')))
$erreur=true;
//récuperation des variables en POST ou GET
$l = (isset($_POST['l'])? $_POST['l']: (isset($_GET['l'])? $_GET['l']:null )) ;
$p = (isset($_POST['p'])? $_POST['p']: (isset($_GET['p'])? $_GET['p']:null )) ;
$q = (isset($_POST['q'])? $_POST['q']: (isset($_GET['q'])? $_GET['q']:null )) ;
$id = (isset($_POST['id'])? $_POST['id']: (isset($_GET['id'])? $_GET['id']:null )) ;
//Suppression des espaces verticaux
$l = preg_replace('#\v#', '',$l);
//On verifie que $p soit un float
$p = floatval($p);
//On traite $q qui peut etre un entier simple ou un tableau d'entier
if (is_array($q)){
$QteArticle = array();
$i=0;
foreach ($q as $contenu){
$QteArticle[$i++] = intval($contenu);
}
}
else
$q = intval($q);
}
if (!$erreur){
switch($action){
Case "ajout":
addArticle($l,$q,$p,$id);
break;
Case "suppression":
deleteArticle($l);
break;
Case "refresh" :
for ($i = 0 ; $i < count($QteArticle) ; $i++)
{
modifyArticleQty($_SESSION['cart']['productName'][$i],round($QteArticle[$i]));
}
break;
Case "Valider":
validateTransaction();
echo'<div class="alert alert-success">
<strong>Commande effectuée!</strong> Vous servez informé de sa validation dans les plus brefs délais.
</div>';
break;
Default:
break;
}
}
echo '<?xml version="1.0" encoding="utf-8"?>';?>
<!DOCTYPE html>
<html lang="fr">
<head>
<title>Votre panier</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<form method="post" action="panier.php">
<table style="width: 600px">
<tr>
<td colspan="4">Votre panier</td>
</tr>
<tr>
<td>Libellé</td>
<td>Quantité</td>
<td>Prix Unitaire</td>
<td>Action</td>
</tr>
<?php
if (createCart())
{
$nbArticles=count($_SESSION['cart']['productName']);
if ($nbArticles <= 0)
echo "<tr><td>Votre panier est vide </ td></tr>";
else
{
for ($i=0 ;$i < $nbArticles ; $i++)
{
echo "<tr>";
echo "<td>".htmlspecialchars($_SESSION['cart']['productName'][$i])."</ td>";
echo "<td><input type=\"text\" size=\"4\" name=\"q[]\" value=\"".htmlspecialchars($_SESSION['cart']['productQty'][$i])."\"/></td>";
echo "<td>".htmlspecialchars($_SESSION['cart']['productPrice'][$i])."</td>";
echo "<td><a href=\"".htmlspecialchars("panier.php?action=suppression&l=".rawurlencode($_SESSION['cart']['productName'][$i]))."\"><span class=\" glyphicon glyphicon-remove\"></span></a></td>";
echo "</tr>";
}
echo "<tr><td colspan=\"2\"> </td>";
echo "<td colspan=\"2\">";
echo "Total : ".globalPrice();
echo "</td></tr>";
echo "<tr><td colspan=\"4\">";
echo "<input type=\"submit\" value=\"Rafraichir\"/>";
echo "<input type=\"hidden\" name=\"action\" value=\"refresh\"/>";
echo "<input type=\"submit\" name=\"action\" value=\"Valider\"/>";
echo "</td></tr>";
}
}
?>
</table>
</form>
</body>
</html>
<?php } ?>