Commit b12775c289e32e6864560dae954794acfe44b6ef

Authored by lwadbled
1 parent ceef8241

fix(): resolution probleme BDD + correction affichage des reservations deja passées

... ... @@ -4,11 +4,11 @@
4 4  
5 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 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 13 /* Creation des tables pour l'interface Web */
14 14  
... ... @@ -17,32 +17,32 @@ create table utilisateur
17 17 MDP char(20));
18 18  
19 19 create table creneau
20   - (JOUR char(10) PRIMARY KEY);
  20 + (JOUR date PRIMARY KEY);
21 21  
22 22 create table banc
23 23 (NUMERO int PRIMARY KEY);
24 24  
25 25 create table equipement
26   - (num int REFERENCES banc,
  26 + (numero int REFERENCES banc,
27 27 IP char(15) PRIMARY KEY,
28 28 NOM char(50),
29 29 TYPE char(30));
30 30  
31 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 35 HEUREDEBUT char(5),
36 36 HEUREFIN char(5),
37 37 /*UNIQUE(moment,HEUREDEBUT),*/
38   - PRIMARY KEY(reserve,moment,HEUREDEBUT));
  38 + PRIMARY KEY(numero,jour,HEUREDEBUT));
39 39  
40 40 /* Insertions des donnees dans la BDD */
41 41  
42 42 insert into utilisateur values ('lwadbled','Louis');
43 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 47 insert into banc values (1);
48 48  
... ...
html/ajoutReservation.php
... ... @@ -25,12 +25,12 @@
25 25 $banc = $_POST['banc'];
26 26 $heure = $_POST['heure'];
27 27 echo "date = ".$date." // banc = ".$banc." // heure = ".$heure."<br>" ;
28   - $explosion = explode('-',$date);
  28 + /*$explosion = explode('-',$date);
29 29 $annee = $explosion[0];
30 30 $mois = $explosion[1];
31 31 $jour = $explosion[2];
32 32 $date = $jour."/".$mois."/".$annee;
33   - echo "New date = ".$date."<br>";
  33 + echo "New date = ".$date."<br>";*/
34 34 $heurefin = (int)$heure + 1;
35 35 if($heurefin==24){
36 36 $heurefin = 0;
... ... @@ -46,6 +46,9 @@
46 46 echo "Heure = ".$heure."<br>";
47 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 52 $requete = "INSERT INTO reservation VALUES($banc,'$date','$login','$heure','$heurefin')";
50 53 $exec_requete = mysqli_query($db,$requete);
51 54 echo "<meta http-equiv=\"refresh\" content=\"0;url=mesReservations.php\">";
... ... @@ -53,10 +56,10 @@
53 56 $date = $_GET['txtDate'];
54 57 $banc = $_GET['banc'];
55 58 $heure = $_GET['heure'];
56   - $requete = "INSERT INTO reservation VALUES($banc,'$date','$login','$heure','$heurefin')";
57   - $exec_requete = mysqli_query($db,$requete);
58 59 $requete = "INSERT INTO creneau VALUES('$date')";
59 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 63 echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionReservation.php\">";
61 64 }else{
62 65 //echo "L'ajout n'a pas fonctionné";
... ...
html/dispoCreneau.php
... ... @@ -4,7 +4,7 @@
4 4 $banc=$_POST['banc'];
5 5 include("connexion.php");
6 6 $requete = "SELECT HEUREDEBUT FROM reservation WHERE
7   - moment = '$date' AND reserve = $banc";
  7 + jour = '$date' AND numero = $banc";
8 8 $exec_requete = mysqli_query($db,$requete);
9 9 $reponse = mysqli_fetch_all($exec_requete);
10 10 foreach($reponse as $value){
... ...
html/gestionBanc.php
... ... @@ -44,7 +44,7 @@
44 44 foreach($banc as $value){
45 45 echo "<tr>";
46 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 48 $exec_requete = mysqli_query($db,$requete);
49 49 $reponse = mysqli_fetch_all($exec_requete);
50 50 echo "<td>".$reponse[0][0]."</td>";
... ...
html/gestionReservation.php
... ... @@ -47,7 +47,6 @@
47 47 $txtDate = "$annee-$mois-$jour";
48 48 }
49 49 }
50   - echo $txtDate;
51 50 ?>
52 51  
53 52 <form method="POST" action="gestionReservation.php">
... ... @@ -86,6 +85,17 @@
86 85 echo "</tr>";
87 86 echo "</thead>";
88 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 99 for($i=0;$i<24;$i++){
90 100 if($i<10){
91 101 $heure = "0".$i.":00";
... ... @@ -95,14 +105,7 @@
95 105 echo "<tr>";
96 106 echo "<td>$heure</td>";
97 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 109 $exec_requete = mysqli_query($db,$requete);
107 110 $reponse = mysqli_fetch_all($exec_requete);
108 111 if($reponse!=null){
... ... @@ -111,12 +114,14 @@
111 114 }else{
112 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 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 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 126 echo "</tr>";
122 127 }
... ...
html/mesReservations.php
... ... @@ -25,7 +25,7 @@
25 25 }
26 26 include("connexion.php");
27 27 $requete = "SELECT count(*) FROM reservation WHERE
28   - personne = '".$identifiant."'";
  28 + login = '".$identifiant."'";
29 29 $exec_requete = mysqli_query($db,$requete);
30 30 $reponse = mysqli_fetch_array($exec_requete);
31 31 $count = $reponse['count(*)'];
... ... @@ -35,8 +35,9 @@
35 35 echo "<div class='px-4 py-4 my-5 text-center'>";
36 36 echo "Vos reservations ($identifiant) : <br>";
37 37 echo "</div>";
  38 + $actualDate = date("Y-m-d");
38 39 $requete = "SELECT * FROM reservation WHERE
39   - personne = '".$identifiant."'";
  40 + login = '".$identifiant."' AND jour >= '$actualDate'";
40 41 $exec_requete = mysqli_query($db,$requete);
41 42 $reponse = mysqli_fetch_all($exec_requete);
42 43 foreach($reponse as $creneau){
... ... @@ -49,7 +50,7 @@
49 50 echo "<form method='POST' action='main.php'>";
50 51 echo "<input type='hidden' name='heure' value='$creneau[3]'>";
51 52 date_default_timezone_set('Europe/Paris');
52   - $ActualDate = date("d/m/Y",time());
  53 + $ActualDate = date("Y-m-d",time());
53 54 if($ActualDate==$creneau[1]){
54 55 $ActualHour = date("h:i",time());
55 56 $Periode = date("a",time());
... ...
html/supprAppareil.php
... ... @@ -7,7 +7,7 @@ if(isset($_GET[&#39;ip&#39;])){
7 7 $requete = "DELETE FROM equipement WHERE
8 8 ip='$ip'";
9 9 $exec_requete = mysqli_query($db,$requete);
10   - $reponse = mysqli_fetch_array($exec_requete);
  10 + //$reponse = mysqli_fetch_array($exec_requete);
11 11 echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionAppareil.php\">";
12 12 mysqli_close($db);
13 13 }
... ...
html/supprBanc.php
... ... @@ -6,7 +6,7 @@ if(isset($_GET[&#39;banc&#39;])){
6 6 $requete = "DELETE FROM banc WHERE
7 7 numero=$banc";
8 8 $exec_requete = mysqli_query($db,$requete);
9   - $reponse = mysqli_fetch_array($exec_requete);
  9 + //$reponse = mysqli_fetch_array($exec_requete);
10 10 echo "<meta http-equiv=\"refresh\" content=\"0;url=gestionBanc.php\">";
11 11 mysqli_close($db);
12 12 }
... ...
html/supprReservation.php
... ... @@ -12,7 +12,7 @@ if(isset($_GET[&#39;banc&#39;]) &amp;&amp; isset($_GET[&#39;moment&#39;]) &amp;&amp; isset($_GET[&#39;personne&#39;]) &amp;&amp;
12 12 echo "Banc = $banc moment = $moment personne = $personne heuredebut = $heuredebut";
13 13 include("connexion.php");
14 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 16 $exec_requete = mysqli_query($db,$requete);
17 17 //$reponse = mysqli_fetch_array($exec_requete);
18 18 if($identifiant=="admin"){
... ...