-
Notifications
You must be signed in to change notification settings - Fork 0
/
booking.php
69 lines (58 loc) · 2.25 KB
/
booking.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
<?php
session_start();
require_once('./libs/config.php');
require_once('./libs/utils.php');
require_once('./src/models/Booking.php');
require_once('./src/models/BookingManager.php');
// Initialisation des variables
$errors = [];
$messages = [];
$capacity = [];
$manager = new BookingManager();
// On vérifie que le formulaire a bien été soumis
if (!empty($_POST)) {
// Vérification si les champs sont définis et NON vides
if (
isset($_POST['name']) && !empty($_POST['name'])
&& isset($_POST['date']) && !empty($_POST['date'])
&& isset($_POST['seat']) && !empty($_POST['seat'])
&& isset($_POST['hour']) && !empty($_POST['hour'])
&& isset($_POST['allergies'])
) {
// On nettoie les données envoyées
$date = strip_tags($_POST['date']);
$seat = strip_tags($_POST['seat']);
$name = strip_tags($_POST['name']);
$hour = strip_tags($_POST['hour']);
$allergies = strip_tags($_POST['allergies']);
// Vérification de la capacité en couverts
$capacity = $manager->getCapacity($date);
if ($seat > $capacity) {
$errors[] = 'Pas assez de couverts disponibles à cette date';
} else {
$newBooking = new Booking();
$newBooking->setDate($date);
$newBooking->setSeat($seat);
$newBooking->setName($name);
$newBooking->setHour($hour);
$newBooking->setAllergies($allergies);
if (is_client() || is_admin()) {
$clientId = $_SESSION['user']['id'];
} else {
$clientId = null;
}
$newBooking->setUserId($clientId);
// Enregistrement de la réservation en BDD
$manager->addBooking($newBooking);
// Pour afficher les places disponibles juste APRÈS une réservation
if (isset($_POST['date']) && !empty($_POST['date'])) {
$capacity = $manager->getCapacity($_POST['date']);
}
// Message de confirmation de la réservation
$messages[] = 'Merci pour votre réservation, à bientôt !';
}
} else {
$errors[] = 'Le formulaire est incomplet';
}
}
require_once('./templates/booking/booking.php');