-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.php
122 lines (111 loc) · 2.89 KB
/
client.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
<script src="js/select.js"></script>
<body onload="init()">
<?php
// NOTE
// Charger une 1er fois la list des produits pour eviter de la charger a chaque fois !
$bdd = new PDO('mysql:host=localhost;dbname=serveur;charset=utf8', 'root', 'password');
session_start();
if (!isset($_SESSION['id']))
$_SESSION['id'] = 0;
if (!isset($_SESSION['list']))
$_SESSION['list'] = Array();
date_default_timezone_set('UTC');
if (isset($_GET['type']))
{
if ($_GET['type'] == "cancel")
{
if (isset($_SESSION['list'][$_GET['id']]))
if ($_SESSION['list'][$_GET['id']] > 0)
{
$_SESSION['list'][$_GET['id']] -= 1;
if ($_SESSION['list'][$_GET['id']] == 0)
unset($_SESSION['list'][$_GET['id']]);
}
}
else if ($_GET['type'] == "buy")
{
$res = $bdd->query('SELECT * FROM produits WHERE id='.$_GET['id'])->fetch();
if (!isset($_SESSION['list'][$_GET['id']]))
$_SESSION['list'][$_GET['id']] = 0;
if ($res['nbr'] > $_SESSION['list'][$_GET['id']])
$_SESSION['list'][$_GET['id']] += 1;
}
else if ($_GET['type'] == "categorie")
{
$_SESSION['id'] = $_GET['id'];
}
else if ($_GET['type'] == "clear")
{
$_SESSION['list'] = Array();
}
else if ($_GET['type'] == "confirme")
{
header('Location: index.php?page=valide');
/*
$reponse = $bdd->query('INSERT INTO ticket(list, prix_total, date, id_user) VALUES (' \
.serialize($_SESSION['list']) \
.(42) \
.date("Y-m-d H:i:s") \
.$_SESSION['id_use'].')');
*/
// Bon javoue que la requet est degueulasse !
// et qu'il faudrait utiliser prepare
// Mais bon il est 3H et il y en a qui bosse :D
}
}
$cat = $_SESSION['id'];
?>
<div id="list">
<?php
foreach ($_SESSION['list'] as $id => $value)
{
try {
$reponse = $bdd->query('SELECT * FROM produits WHERE id='.$id);
while ($res = $reponse->fetch())
{
echo "<div class='produit' id=".$res['id'].">";
echo "<img src='".$res['img']."'></img>";
echo $value;
echo "</div>";
}
} catch (Exception $e) {
echo "Et merde ...";
}
}
?>
<div id="action">
<input id="buy" type="button" value ="buy !" />
<input id="clear" type="button" value="clear" />
</div>
</div>
<div id="buy_zone">
<div id="categories">
<?php
$reponse = $bdd->query('SELECT * FROM categorie');
while ($res = $reponse->fetch())
{
echo "<div>";
echo "<img class='categorie' id=".$res['id']." src='".$res['img']."'></img>";
echo "</div>";
}
?>
</div>
<div id="produits">
tata
<?php
$reponse = $bdd->query('SELECT * FROM produits WHERE id_categorie='.$cat);
echo "<div>";
while ($res = $reponse->fetch())
{
if ($res['nbr'] > 0 && $res['see'])
if ($res['nbr'] < $res['nbr_limit'])
echo "<div class='produit lowQuantity' id=".$res['id'].">";
else
echo "<div class='produit' id=".$res['id'].">";
echo "<img src='".$res['img']."'></img>";
echo "</div>";
}
echo "</div>";
?>
</div>
</body>