Repository navigation
Expand file tree
/
Copy pathcheckDateResaRestaurant.php
More file actions
67 lines (56 loc) · 2.36 KB
/
Copy pathcheckDateResaRestaurant.php
File metadata and controls
67 lines (56 loc) · 2.36 KB
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
<?php
session_start();
require "include/init_twig.php";
include_once("include/_traduction.php");
include_once("include/_connexion.php");
require_once "include/_functions.php";
$pdo = getPDO();
$lang = getLang();
@$email = $_SESSION['email'];
if (isset($_POST['submit'])) {
$fromDate = $_POST['CheckIn'];
$hourResa = $_POST['hourResa'];
$nbPerson = $_POST['nbPerson'];
if (!preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $fromDate)) {
$errorCheck = "Veuillez entrer une date valide (année-mois-jour)";
}
elseif (!$hourResa) {
$errorCheck = "Veuillez choisir l'heure svp'";
}
elseif (!$nbPerson) {
$errorCheck = "Veuillez choisir le nombre de personne svp";
}
// S'il y a des erreur dans le formulaire de recherche de disponibilité, on affiche le message adéquat
if (isset($errorCheck)) {
header("Location: restaurant.php?lang=$lang&errorForm=$errorCheck");
die();
}
// Requête pour vérifier la disponibilité au restaurant
$checkResaRestau = $pdo->query("SELECT * FROM restaurant WHERE capacite >= $nbPerson && idTable NOT IN ( SELECT tableId FROM reservation_restaurant WHERE dateReservation = '$fromDate' && heureResa = '$hourResa')")->fetch();
// Si la requête renvoie 0 resultat, alors on affiche un message
if (!$checkResaRestau) {
$messageCheck = "Désolé, il n'y a pas de disponibilité selon vos critères de recherche";
header("Location: restaurant.php?lang=$lang&message=$messageCheck");
die();
}
//récupérer l'utilisateur actuel s'il est déjà connecté
$client = $pdo->query("SELECT * FROM client WHERE email = '$email'")->fetch();
if ($client) {
$clientId = $client['idClient'];
header("Location: restaurant.php?lang=$lang&clientId=$clientId&idTable=$idTable&fromDate=$fromDate&hourResa=$hourResa&nbPerson=$nbPerson#valideResa");
die();
}
else{
$showBtnResaRestaurant = 0;
$idTable = $checkResaRestau['idTable'];
header("Location: formResaRestaurant.php?lang=$lang&idTable=$idTable&fromDate=$fromDate&hourResa=$hourResa&nbPerson=$nbPerson");
die();
}
}
// Sinon on affiche le formulaire de réservation
// else {
// $idTable = $checkResaRestau['idTable'];
// header("Location: formResaRestaurant.php?lang=$lang&idTable=$idTable&fromDate=$fromDate&hourResa=$hourResa&nbPerson=$nbPerson");
// die();
// }
?>