Commit b12775c289e32e6864560dae954794acfe44b6ef
1 parent
ceef8241
fix(): resolution probleme BDD + correction affichage des reservations deja passées
Showing
9 changed files
with
45 additions
and
36 deletions
Show diff stats
bdd.sql
@@ -4,11 +4,11 @@ | @@ -4,11 +4,11 @@ | ||
4 | 4 | ||
5 | /* Suppression des tables si elles existent */ | 5 | /* Suppression des tables si elles existent */ |
6 | 6 | ||
7 | -drop table if exists utilisateur ; | ||
8 | -drop table if exists creneau ; | ||
9 | -drop table if exists banc ; | ||
10 | -drop table if exists equipement ; | ||
11 | drop table if exists reservation ; | 7 | drop table if exists reservation ; |
8 | +drop table if exists equipement ; | ||
9 | +drop table if exists banc ; | ||
10 | +drop table if exists creneau ; | ||
11 | +drop table if exists utilisateur ; | ||
12 | 12 | ||
13 | /* Creation des tables pour l'interface Web */ | 13 | /* Creation des tables pour l'interface Web */ |
14 | 14 | ||
@@ -17,32 +17,32 @@ create table utilisateur | @@ -17,32 +17,32 @@ create table utilisateur | ||
17 | MDP char(20)); | 17 | MDP char(20)); |
18 | 18 | ||
19 | create table creneau | 19 | create table creneau |
20 | - (JOUR char(10) PRIMARY KEY); | 20 | + (JOUR date PRIMARY KEY); |
21 | 21 | ||
22 | create table banc | 22 | create table banc |
23 | (NUMERO int PRIMARY KEY); | 23 | (NUMERO int PRIMARY KEY); |
24 | 24 | ||
25 | create table equipement | 25 | create table equipement |
26 | - (num int REFERENCES banc, | 26 | + (numero int REFERENCES banc, |
27 | IP char(15) PRIMARY KEY, | 27 | IP char(15) PRIMARY KEY, |
28 | NOM char(50), | 28 | NOM char(50), |
29 | TYPE char(30)); | 29 | TYPE char(30)); |
30 | 30 | ||
31 | create table reservation | 31 | create table reservation |
32 | - (reserve int REFERENCES banc, | ||
33 | - moment char(10) REFERENCES creneau, | ||
34 | - personne char(8) REFERENCES utilisateur, | 32 | + (numero int REFERENCES banc, |
33 | + jour date REFERENCES creneau, | ||
34 | + login char(8) REFERENCES utilisateur, | ||
35 | HEUREDEBUT char(5), | 35 | HEUREDEBUT char(5), |
36 | HEUREFIN char(5), | 36 | HEUREFIN char(5), |
37 | /*UNIQUE(moment,HEUREDEBUT),*/ | 37 | /*UNIQUE(moment,HEUREDEBUT),*/ |
38 | - PRIMARY KEY(reserve,moment,HEUREDEBUT)); | 38 | + PRIMARY KEY(numero,jour,HEUREDEBUT)); |
39 | 39 | ||
40 | /* Insertions des donnees dans la BDD */ | 40 | /* Insertions des donnees dans la BDD */ |
41 | 41 | ||
42 | insert into utilisateur values ('lwadbled','Louis'); | 42 | insert into utilisateur values ('lwadbled','Louis'); |
43 | insert into utilisateur values ('admin','glopglop'); | 43 | insert into utilisateur values ('admin','glopglop'); |
44 | 44 | ||
45 | -/* insert into creneau values ('01/12/2021'); */ | 45 | +insert into creneau values (01/12/2021); |
46 | 46 | ||
47 | insert into banc values (1); | 47 | insert into banc values (1); |
48 | 48 |
html/ajoutReservation.php
@@ -25,12 +25,12 @@ | @@ -25,12 +25,12 @@ | ||
25 | $banc = $_POST['banc']; | 25 | $banc = $_POST['banc']; |
26 | $heure = $_POST['heure']; | 26 | $heure = $_POST['heure']; |
27 | echo "date = ".$date." // banc = ".$banc." // heure = ".$heure."<br>" ; | 27 | echo "date = ".$date." // banc = ".$banc." // heure = ".$heure."<br>" ; |
28 | - $explosion = explode('-',$date); | 28 | + /*$explosion = explode('-',$date); |
29 | $annee = $explosion[0]; | 29 | $annee = $explosion[0]; |
30 | $mois = $explosion[1]; | 30 | $mois = $explosion[1]; |
31 | $jour = $explosion[2]; | 31 | $jour = $explosion[2]; |
32 | $date = $jour."/".$mois."/".$annee; | 32 | $date = $jour."/".$mois."/".$annee; |
33 | - echo "New date = ".$date."<br>"; | 33 | + echo "New date = ".$date."<br>";*/ |
34 | $heurefin = (int)$heure + 1; | 34 | $heurefin = (int)$heure + 1; |
35 | if($heurefin==24){ | 35 | if($heurefin==24){ |
36 | $heurefin = 0; | 36 | $heurefin = 0; |
@@ -46,6 +46,9 @@ | @@ -46,6 +46,9 @@ | ||
46 | echo "Heure = ".$heure."<br>"; | 46 | echo "Heure = ".$heure."<br>"; |
47 | echo "Heure de fin = ".$heurefin."<br>"; | 47 | echo "Heure de fin = ".$heurefin."<br>"; |
48 | 48 | ||
49 | + $requete = "INSERT INTO creneau VALUES('$date')"; | ||
50 | + $exec_requete = mysqli_query($db,$requete); | ||
51 | + | ||
49 | $requete = "INSERT INTO reservation VALUES($banc,'$date','$login','$heure','$heurefin')"; | 52 | $requete = "INSERT INTO reservation VALUES($banc,'$date','$login','$heure','$heurefin')"; |
50 | $exec_requete = mysqli_query($db,$requete); | 53 | $exec_requete = mysqli_query($db,$requete); |
51 | echo "<meta http-equiv=\"refresh\" content=\"0;url=mesReservations.php\">"; | 54 | echo "<meta http-equiv=\"refresh\" content=\"0;url=mesReservations.php\">"; |
@@ -53,10 +56,10 @@ | @@ -53,10 +56,10 @@ | ||
53 | $date = $_GET['txtDate']; | 56 | $date = $_GET['txtDate']; |
54 | $banc = $_GET['banc']; | 57 | $banc = $_GET['banc']; |
55 | $heure = $_GET['heure']; | 58 | $heure = $_GET['heure']; |
56 | - $requete = "INSERT INTO reservation VALUES($banc,'$date','$login','$heure','$heurefin')"; | ||
57 | - $exec_requete = mysqli_query($db,$requete); | ||
58 | $requete = "INSERT INTO creneau VALUES('$date')"; | 59 | $requete = "INSERT INTO creneau VALUES('$date')"; |
59 | $exec_requete = mysqli_query($db,$requete); | 60 | $exec_requete = mysqli_query($db,$requete); |
61 | + $requete = "INSERT INTO reservation VALUES($banc,'$date','$login','$heure','$heurefin')"; | ||
62 | + $exec_requete = mysqli_query($db,$requete); | ||
60 | echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionReservation.php\">"; | 63 | echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionReservation.php\">"; |
61 | }else{ | 64 | }else{ |
62 | //echo "L'ajout n'a pas fonctionné"; | 65 | //echo "L'ajout n'a pas fonctionné"; |
html/dispoCreneau.php
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | $banc=$_POST['banc']; | 4 | $banc=$_POST['banc']; |
5 | include("connexion.php"); | 5 | include("connexion.php"); |
6 | $requete = "SELECT HEUREDEBUT FROM reservation WHERE | 6 | $requete = "SELECT HEUREDEBUT FROM reservation WHERE |
7 | - moment = '$date' AND reserve = $banc"; | 7 | + jour = '$date' AND numero = $banc"; |
8 | $exec_requete = mysqli_query($db,$requete); | 8 | $exec_requete = mysqli_query($db,$requete); |
9 | $reponse = mysqli_fetch_all($exec_requete); | 9 | $reponse = mysqli_fetch_all($exec_requete); |
10 | foreach($reponse as $value){ | 10 | foreach($reponse as $value){ |
html/gestionBanc.php
@@ -44,7 +44,7 @@ | @@ -44,7 +44,7 @@ | ||
44 | foreach($banc as $value){ | 44 | foreach($banc as $value){ |
45 | echo "<tr>"; | 45 | echo "<tr>"; |
46 | echo "<td>".$value[0]."</td>"; | 46 | echo "<td>".$value[0]."</td>"; |
47 | - $requete = "SELECT count(*) FROM equipement WHERE num=$value[0]"; | 47 | + $requete = "SELECT count(*) FROM equipement WHERE numero=$value[0]"; |
48 | $exec_requete = mysqli_query($db,$requete); | 48 | $exec_requete = mysqli_query($db,$requete); |
49 | $reponse = mysqli_fetch_all($exec_requete); | 49 | $reponse = mysqli_fetch_all($exec_requete); |
50 | echo "<td>".$reponse[0][0]."</td>"; | 50 | echo "<td>".$reponse[0][0]."</td>"; |
html/gestionReservation.php
@@ -47,7 +47,6 @@ | @@ -47,7 +47,6 @@ | ||
47 | $txtDate = "$annee-$mois-$jour"; | 47 | $txtDate = "$annee-$mois-$jour"; |
48 | } | 48 | } |
49 | } | 49 | } |
50 | - echo $txtDate; | ||
51 | ?> | 50 | ?> |
52 | 51 | ||
53 | <form method="POST" action="gestionReservation.php"> | 52 | <form method="POST" action="gestionReservation.php"> |
@@ -86,6 +85,17 @@ | @@ -86,6 +85,17 @@ | ||
86 | echo "</tr>"; | 85 | echo "</tr>"; |
87 | echo "</thead>"; | 86 | echo "</thead>"; |
88 | echo "<tbody>"; | 87 | echo "<tbody>"; |
88 | + | ||
89 | + $explosion_date = explode("-",$txtDate); | ||
90 | + $jour = $explosion_date[2]; | ||
91 | + $mois = $explosion_date[1]; | ||
92 | + $annee = $explosion_date[0]; | ||
93 | + $actualDate = date("Y-m-d"); | ||
94 | + $new = explode("-",$actualDate); | ||
95 | + $new_jour = $new[2]; | ||
96 | + $new_mois = $new[1]; | ||
97 | + $new_annee = $new[0]; | ||
98 | + | ||
89 | for($i=0;$i<24;$i++){ | 99 | for($i=0;$i<24;$i++){ |
90 | if($i<10){ | 100 | if($i<10){ |
91 | $heure = "0".$i.":00"; | 101 | $heure = "0".$i.":00"; |
@@ -95,14 +105,7 @@ | @@ -95,14 +105,7 @@ | ||
95 | echo "<tr>"; | 105 | echo "<tr>"; |
96 | echo "<td>$heure</td>"; | 106 | echo "<td>$heure</td>"; |
97 | /* Requete pour connaitre l'utilisateur reservant le creneau s'il y en a un */ | 107 | /* Requete pour connaitre l'utilisateur reservant le creneau s'il y en a un */ |
98 | - /* Reecriture de la date */ | ||
99 | - $explosion_date = explode("-",$txtDate); | ||
100 | - $jour = $explosion_date[2]; | ||
101 | - $mois = $explosion_date[1]; | ||
102 | - $annee = $explosion_date[0]; | ||
103 | - $new_date = "$jour/$mois/$annee"; | ||
104 | - /* Fin reecriture date */ | ||
105 | - $requete = "SELECT personne FROM reservation WHERE moment='$new_date' AND reserve=$banc AND HEUREDEBUT='$heure'"; | 108 | + $requete = "SELECT login FROM reservation WHERE jour='$txtDate' AND numero=$banc AND HEUREDEBUT='$heure'"; |
106 | $exec_requete = mysqli_query($db,$requete); | 109 | $exec_requete = mysqli_query($db,$requete); |
107 | $reponse = mysqli_fetch_all($exec_requete); | 110 | $reponse = mysqli_fetch_all($exec_requete); |
108 | if($reponse!=null){ | 111 | if($reponse!=null){ |
@@ -111,12 +114,14 @@ | @@ -111,12 +114,14 @@ | ||
111 | }else{ | 114 | }else{ |
112 | echo "<td></td>"; | 115 | echo "<td></td>"; |
113 | } | 116 | } |
114 | - if($reponse==null){ | ||
115 | - echo "<td><form method='POST' action='ajoutReservation.php?txtDate=$new_date&banc=$banc&heure=$heure'><button class='btn-lg btn-danger' type='submit'>Bloquer le créneau</button></form>"; | 117 | + if($new_annee>$annee || ($new_annee>=$annee && $new_mois>=$mois && $new_jour>$jour)){ |
118 | + echo "<td><form method='POST' action=''><button disabled class='btn-lg btn-outline-info' type='submit'>Date déjà passée</button></form>"; | ||
119 | + }else if($reponse==null){ | ||
120 | + echo "<td><form method='POST' action='ajoutReservation.php?txtDate=$txtDate&banc=$banc&heure=$heure'><button class='btn-lg btn-danger' type='submit'>Bloquer le créneau</button></form>"; | ||
116 | }else if($reponse[0][0]=="admin"){ | 121 | }else if($reponse[0][0]=="admin"){ |
117 | - echo "<td><form method='POST' action='supprReservation.php?banc=$banc&moment=$new_date&personne=$personne&heuredebut=$heure'><button class='btn-lg btn-success' type='submit'>Débloquer le créneau</button></form>"; | 122 | + echo "<td><form method='POST' action='supprReservation.php?banc=$banc&moment=$txtDate&personne=$personne&heuredebut=$heure'><button class='btn-lg btn-success' type='submit'>Débloquer le créneau</button></form>"; |
118 | }else{ | 123 | }else{ |
119 | - echo "<td><form method='POST' action='supprReservation.php?banc=$banc&moment=$new_date&personne=$personne&heuredebut=$heure'><button class='btn-lg btn-warning' type='submit'>Supprimer la réservation</button></form>"; | 124 | + echo "<td><form method='POST' action='supprReservation.php?banc=$banc&moment=$txtDate&personne=$personne&heuredebut=$heure'><button class='btn-lg btn-warning' type='submit'>Supprimer la réservation</button></form>"; |
120 | } | 125 | } |
121 | echo "</tr>"; | 126 | echo "</tr>"; |
122 | } | 127 | } |
html/mesReservations.php
@@ -25,7 +25,7 @@ | @@ -25,7 +25,7 @@ | ||
25 | } | 25 | } |
26 | include("connexion.php"); | 26 | include("connexion.php"); |
27 | $requete = "SELECT count(*) FROM reservation WHERE | 27 | $requete = "SELECT count(*) FROM reservation WHERE |
28 | - personne = '".$identifiant."'"; | 28 | + login = '".$identifiant."'"; |
29 | $exec_requete = mysqli_query($db,$requete); | 29 | $exec_requete = mysqli_query($db,$requete); |
30 | $reponse = mysqli_fetch_array($exec_requete); | 30 | $reponse = mysqli_fetch_array($exec_requete); |
31 | $count = $reponse['count(*)']; | 31 | $count = $reponse['count(*)']; |
@@ -35,8 +35,9 @@ | @@ -35,8 +35,9 @@ | ||
35 | echo "<div class='px-4 py-4 my-5 text-center'>"; | 35 | echo "<div class='px-4 py-4 my-5 text-center'>"; |
36 | echo "Vos reservations ($identifiant) : <br>"; | 36 | echo "Vos reservations ($identifiant) : <br>"; |
37 | echo "</div>"; | 37 | echo "</div>"; |
38 | + $actualDate = date("Y-m-d"); | ||
38 | $requete = "SELECT * FROM reservation WHERE | 39 | $requete = "SELECT * FROM reservation WHERE |
39 | - personne = '".$identifiant."'"; | 40 | + login = '".$identifiant."' AND jour >= '$actualDate'"; |
40 | $exec_requete = mysqli_query($db,$requete); | 41 | $exec_requete = mysqli_query($db,$requete); |
41 | $reponse = mysqli_fetch_all($exec_requete); | 42 | $reponse = mysqli_fetch_all($exec_requete); |
42 | foreach($reponse as $creneau){ | 43 | foreach($reponse as $creneau){ |
@@ -49,7 +50,7 @@ | @@ -49,7 +50,7 @@ | ||
49 | echo "<form method='POST' action='main.php'>"; | 50 | echo "<form method='POST' action='main.php'>"; |
50 | echo "<input type='hidden' name='heure' value='$creneau[3]'>"; | 51 | echo "<input type='hidden' name='heure' value='$creneau[3]'>"; |
51 | date_default_timezone_set('Europe/Paris'); | 52 | date_default_timezone_set('Europe/Paris'); |
52 | - $ActualDate = date("d/m/Y",time()); | 53 | + $ActualDate = date("Y-m-d",time()); |
53 | if($ActualDate==$creneau[1]){ | 54 | if($ActualDate==$creneau[1]){ |
54 | $ActualHour = date("h:i",time()); | 55 | $ActualHour = date("h:i",time()); |
55 | $Periode = date("a",time()); | 56 | $Periode = date("a",time()); |
html/supprAppareil.php
@@ -7,7 +7,7 @@ if(isset($_GET['ip'])){ | @@ -7,7 +7,7 @@ if(isset($_GET['ip'])){ | ||
7 | $requete = "DELETE FROM equipement WHERE | 7 | $requete = "DELETE FROM equipement WHERE |
8 | ip='$ip'"; | 8 | ip='$ip'"; |
9 | $exec_requete = mysqli_query($db,$requete); | 9 | $exec_requete = mysqli_query($db,$requete); |
10 | - $reponse = mysqli_fetch_array($exec_requete); | 10 | + //$reponse = mysqli_fetch_array($exec_requete); |
11 | echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionAppareil.php\">"; | 11 | echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionAppareil.php\">"; |
12 | mysqli_close($db); | 12 | mysqli_close($db); |
13 | } | 13 | } |
html/supprBanc.php
@@ -6,7 +6,7 @@ if(isset($_GET['banc'])){ | @@ -6,7 +6,7 @@ if(isset($_GET['banc'])){ | ||
6 | $requete = "DELETE FROM banc WHERE | 6 | $requete = "DELETE FROM banc WHERE |
7 | numero=$banc"; | 7 | numero=$banc"; |
8 | $exec_requete = mysqli_query($db,$requete); | 8 | $exec_requete = mysqli_query($db,$requete); |
9 | - $reponse = mysqli_fetch_array($exec_requete); | 9 | + //$reponse = mysqli_fetch_array($exec_requete); |
10 | echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionBanc.php\">"; | 10 | echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionBanc.php\">"; |
11 | mysqli_close($db); | 11 | mysqli_close($db); |
12 | } | 12 | } |
html/supprReservation.php
@@ -12,7 +12,7 @@ if(isset($_GET['banc']) && isset($_GET['moment']) && isset($_GET['personne']) && | @@ -12,7 +12,7 @@ if(isset($_GET['banc']) && isset($_GET['moment']) && isset($_GET['personne']) && | ||
12 | echo "Banc = $banc moment = $moment personne = $personne heuredebut = $heuredebut"; | 12 | echo "Banc = $banc moment = $moment personne = $personne heuredebut = $heuredebut"; |
13 | include("connexion.php"); | 13 | include("connexion.php"); |
14 | $requete = "DELETE FROM reservation WHERE | 14 | $requete = "DELETE FROM reservation WHERE |
15 | - reserve=$banc and moment='$moment' and personne = '$personne' and heuredebut='$heuredebut'"; | 15 | + numero=$banc and jour='$moment' and login = '$personne' and heuredebut='$heuredebut'"; |
16 | $exec_requete = mysqli_query($db,$requete); | 16 | $exec_requete = mysqli_query($db,$requete); |
17 | //$reponse = mysqli_fetch_array($exec_requete); | 17 | //$reponse = mysqli_fetch_array($exec_requete); |
18 | if($identifiant=="admin"){ | 18 | if($identifiant=="admin"){ |