-
Notifications
You must be signed in to change notification settings - Fork 0
/
products.php
183 lines (177 loc) · 8.53 KB
/
products.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
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
<?php
session_start();
require "conf.inc.php";
require "functions.php";
if (isConnected() && isActivated() && isFranchisee()) {
include "header.php";
include "navbar.php";
?>
<body>
<div class="col-md-11 mx-auto mt-5">
<button class="btn btn-primary" data-toggle="modal" data-target="#productModal">Ajouter un produit</button>
</div>
<div class="col-md-11 mx-auto mt-5">
<?php
if (isset($_GET["error"])) {
?>
<div class="alert alert-danger">
Des erreurs ont été détectées, le produit n'a donc pas été créé.
</div>
<?php
}
?>
<div class="card">
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th class="text-center">ID</th>
<th class="text-center">Nom</th>
<th class="text-center">Prix</th>
<th class="text-center">Catégorie</th>
<th class="text-center">Ingrédients</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<?php
$pdo = connectDB();
$products = getMyProducts(getMyTruck($_SESSION["email"]));
$queryPrepared = $pdo->prepare("SELECT idCategory, categoryName FROM PRODUCTCATEGORY");
$queryPrepared->execute();
$categories = $queryPrepared->fetchAll(PDO::FETCH_ASSOC);
if ($products != null) {
foreach ($products as $product) { ?>
<tr>
<th class="text-center"><?php echo $product["idProduct"] ?></th>
<td class="text-center"><?php echo $product["productName"] ?></td>
<td class="text-center"><?php echo number_format($product["productPrice"], 2) . " €" ?></td>
<td class="text-center"><?php
if (!empty($product["category"])) {
$category = categoryOfProduct($product["category"]);
echo $category["categoryName"];
} else {
echo "Aucune catégorie saise";
}
?></td>
<td>
<ul>
<?php
$ingredients = allIngredientsFromProduct($product["idProduct"]);
foreach ($ingredients as $ingredient) {
echo "<li>" . $ingredient["ingredientName"] . "</li>";
}
?>
</ul>
</td>
<td class="text-center">
<?php
$status = statusOfProduct($product["idProduct"]);
if (!empty($status))
$status = $status["status"];
if ($status == 19 || empty($status)) {
?>
<a href="./functions/deleteProduct.php?id=<?php echo $product["idProduct"] ?>&status=20"
class="btn btn-warning">
Rendre ce produit indisponible
</a>
<?php
} else { ?>
<a href="./functions/deleteProduct.php?id=<?php echo $product["idProduct"] ?>&status=19"
class="btn btn-success">
Rendre ce produit disponible
</a>
<?php
}
?>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
</div>
</div>
<div class="modal fade" id="productModal" tabindex="-1" role="dialog" aria-labelledby="advantageModalLabel"
aria-hidden="true">
<form method="POST" action="./functions/addProduct.php">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="advantageModalLabel">Ajouter un produit</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="productName">Nom</span>
</div>
<input type="text" class="form-control" placeholder="Nom du produit" name="productName"
aria-label="productName" aria-describedby="productName" required>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="productPrice">Prix</span>
</div>
<input type="number" min="0" step="any" class="form-control" placeholder="Prix"
name="productPrice" aria-label="productPrice" aria-describedby="productPrice" required>
</div>
<?php
$pdo = connectDB();
$queryPrepared = $pdo->prepare("SELECT ingredientName, ingredientCategory, idIngredient
FROM INGREDIENTS, STORE, WAREHOUSES, TRUCKWAREHOUSE, TRUCK
WHERE idIngredient = STORE.ingredient
AND STORE.warehouse = idWarehouse
AND STORE.available = TRUE
AND TRUCKWAREHOUSE.warehouse = idWarehouse
AND TRUCKWAREHOUSE.truck = idTruck
AND truck = :truck
AND warehouseType = 'Camion';");
$truck = getMyTruck($_SESSION["email"]);
$queryPrepared->execute([
":truck" => $truck
]);
$ingredients = $queryPrepared->fetchAll(PDO::FETCH_ASSOC);
foreach ($ingredients as $ingredient) {
?>
<div class="custom-control custom-checkbox mb-3">
<input type="checkbox" class="custom-control-input"
value="<?php echo $ingredient["idIngredient"] ?>" name="ingredients[]"
id="<?php echo $ingredient["ingredientName"] ?>">
<label class="custom-control-label"
for="<?php echo $ingredient["ingredientName"] ?>"><?php echo $ingredient["ingredientName"] ?></label>
</div>
<?php
}
?>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="productCategory">Catégorie</label>
</div>
<select class="custom-select" id="productCategory" name="productCategory">
<option selected value="">Choisir...</option>
<?php
foreach ($categories as $category) {
echo "<option value='" . $category["idCategory"] . "'>" . $category["categoryName"] . "</option>";
}
?>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Enregistrer</button>
</div>
</div>
</div>
</form>
</div>
<?php
include "footer.php";
} else {
header("Location: login.php");
}
?>