Commit 87d5afd9dd7ababf9a9ab0a8ac156eab9b6c8195

Authored by lwadbled
1 parent 9de9bb41

feat(*): verification disponibilité créneaux + bouton accès au banc selon créneau et heure actuelle

... ... @@ -33,8 +33,8 @@ create table reservation
33 33 personne char(8) REFERENCES utilisateur,
34 34 HEUREDEBUT char(5),
35 35 HEUREFIN char(5),
36   - UNIQUE(moment,personne),
37   - PRIMARY KEY(reserve,moment));
  36 + /*UNIQUE(moment,HEUREDEBUT),*/
  37 + PRIMARY KEY(reserve,moment,HEUREDEBUT));
38 38  
39 39 /* Insertions des donnees dans la BDD */
40 40  
... ...
html/ajoutReservation.php
... ... @@ -48,7 +48,7 @@
48 48  
49 49 $requete = "INSERT INTO reservation VALUES($banc,'$date','$login','$heure','$heurefin')";
50 50 $exec_requete = mysqli_query($db,$requete);
51   -
  51 + echo "<meta http-equiv=\"refresh\" content=\"0;url=mesReservations.php\">";
52 52 }else{
53 53 echo "Pas marché";
54 54 }
... ...
html/dispoCreneau.php 0 → 100644
... ... @@ -0,0 +1,15 @@
  1 +<?php
  2 + if(isset($_POST['date']) && isset($_POST['banc'])){
  3 + $date=$_POST['date'];
  4 + $banc=$_POST['banc'];
  5 + include("connexion.php");
  6 + $requete = "SELECT HEUREDEBUT FROM reservation WHERE
  7 + moment = '$date' AND reserve = $banc";
  8 + $exec_requete = mysqli_query($db,$requete);
  9 + $reponse = mysqli_fetch_all($exec_requete);
  10 + foreach($reponse as $value){
  11 + echo $value[0]."-";
  12 + }
  13 + mysqli_close($db);
  14 + }
  15 +?>
... ...
html/login.php
... ... @@ -21,6 +21,7 @@ if(isset($_POST[&#39;identifiant&#39;]) &amp;&amp; isset($_POST[&#39;mdp&#39;])){
21 21 //header('Location : index.html');
22 22 }
23 23 }else{
  24 + /* Ne devrait pas pouvoir arriver mais j'ajoute une double sécurité */
24 25 echo "<meta http-equiv=\"refresh\" content=\"0;url=index.html\">";
25 26 //header('Location : index.html');
26 27 }
... ...
html/menu.php
... ... @@ -22,10 +22,11 @@
22 22 echo "<meta http-equiv=\"refresh\" content=\"0;url=index.html\">";
23 23 //header('Location : index.html');
24 24 }
25   - }
26   - if(isset($_SESSION['identifiant'])){
  25 + }elseif(isset($_SESSION['identifiant'])){
27 26 $identifiant = $_SESSION['identifiant'];
28 27 echo "Bonjour $identifiant, vous êtes connecté<br>";
  28 + }else{
  29 + echo "<meta http-equiv=\"refresh\" content=\"0;url=index.html\">";
29 30 }
30 31 ?>
31 32 <form method="POST" action="menu.php?deconnexion=true">
... ...
html/mesReservations.php
... ... @@ -14,13 +14,14 @@
14 14 </head>
15 15 <body>
16 16 <form method="POST" action="menu.php">
17   - <button class="btn-lg btn-success" type="submit">Retour au menu</button>
  17 + <button class="btn-lg btn-secondary" type="submit">Retour au menu</button>
18 18 </form>
19 19 <?php
20 20 session_start();
21 21 if(isset($_SESSION['identifiant'])){
22 22 $identifiant = $_SESSION['identifiant'];
23   - echo "Bonjour $identifiant, vous êtes connecté<br>";
  23 + }else{
  24 + echo "<meta http-equiv=\"refresh\" content=\"0;url=index.html\">";
24 25 }
25 26 include("connexion.php");
26 27 $requete = "SELECT count(*) FROM reservation WHERE
... ... @@ -29,29 +30,47 @@
29 30 $reponse = mysqli_fetch_array($exec_requete);
30 31 $count = $reponse['count(*)'];
31 32 if($count == 0){
32   - echo "Aucun banc d'essai n'a ete reservé";
  33 + echo "Aucun banc d'essai n'a été réservé";
33 34 }else{
34   - echo "Vos reservations : <br>";
  35 + echo "<div class='px-4 py-4 my-5 text-center'>";
  36 + echo "Vos reservations ($identifiant) : <br>";
  37 + echo "</div>";
35 38 $requete = "SELECT * FROM reservation WHERE
36 39 personne = '".$identifiant."'";
37 40 $exec_requete = mysqli_query($db,$requete);
38 41 $reponse = mysqli_fetch_all($exec_requete);
39 42 foreach($reponse as $creneau){
40   - echo "<div>";
  43 + echo "<div class='px-4 py-4 my-5 text-center border-top'>";
41 44 echo "Banc : $creneau[0] | Date : $creneau[1] $creneau[3]-$creneau[4]";
42 45 echo "<form method='POST' action='supprReservation.php?banc=$creneau[0]&moment=$creneau[1]&personne=$identifiant&heuredebut=$creneau[3]&heurefin=$creneau[4]'>";
43   - echo "<button class='btn-lg btn-success' type='submit'>Supprimer la reservation</button>";
  46 + echo "<button class='btn-lg btn-danger' type='submit'>Supprimer la reservation</button>";
  47 + echo "</form>";
  48 + /* Utilisation pour accès aux reservations */
  49 + echo "<form method='POST' action='main.php'>";
  50 + date_default_timezone_set('Europe/Paris');
  51 + $ActualDate = date("d/m/Y",time());
  52 + if($ActualDate==$creneau[1]){
  53 + $ActualHour = date("h:i",time());
  54 + $Periode = date("a",time());
  55 + if($Periode=="pm"){
  56 + $newHour = explode(":",$ActualHour);
  57 + $Heure = $newHour[0]+12;
  58 + $ActualHour = "".$Heure.":".$newHour[1];
  59 + }
  60 + if(!($creneau[3]<=$ActualHour && $ActualHour<$creneau[4])){
  61 + echo "<button class='btn-lg btn-outline-success' type='submit' disabled ";
  62 + }else{
  63 + echo "<button class='btn-lg btn-success' type='submit'";
  64 + }
  65 + }else{
  66 + echo "<button class='btn-lg btn-outline-success' type='submit' disabled ";
  67 + }
  68 + echo ">Acceder au banc</button>";
44 69 echo "</form>";
45 70 echo "</div>";
46 71 }
47 72 }
48 73 mysqli_close($db);
49   - /* Utilisation pour accès aux reservations
50   - date_default_timezone_set('Europe/Paris');
51   - $ActualDate = date("d/m/Y",time());
52   - $ActualHour = date("h:i",time());
53   - $Periode = date("a",time());
54   - echo "Vrai date : ".$ActualDate." / Vrai heure = ".$ActualHour.$Periode."<br>"; */
55 74 ?>
56 75 </body>
57 76 </html>
... ...
html/reservation.php
... ... @@ -14,6 +14,12 @@
14 14 </head>
15 15 <body>
16 16 <?php
  17 + session_start();
  18 + if(isset($_SESSION['identifiant'])){
  19 + $identifiant = $_SESSION['identifiant'];
  20 + }else{
  21 + echo "<meta http-equiv=\"refresh\" content=\"0;url=index.html\">";
  22 + }
17 23 include("connexion.php");
18 24 $requete = "SELECT * FROM banc ORDER BY numero";
19 25 $exec_requete = mysqli_query($db,$requete);
... ... @@ -21,16 +27,16 @@
21 27 mysqli_close($db);
22 28 ?>
23 29 <form method="POST" action="menu.php">
24   - <button class="btn-lg btn-success" type="submit">Retour au menu</button>
  30 + <button class="btn-lg btn-secondary" type="submit">Retour au menu</button>
25 31 </form>
26 32 <form method="POST" action="ajoutReservation.php">
27 33 <div>
28   - <input type="date" name="txtDate" id="txtDate" onclick="minimum();" required>
  34 + <input type="date" name="txtDate" id="txtDate" onclick="minimum();" onchange="dispo_creneau();" required>
29 35 </div>
30 36  
31 37 <div>
32 38 Banc choisi :
33   - <select class="form-select" name="banc" id="banc" required>
  39 + <select class="form-select" name="banc" id="banc" onchange="dispo_creneau();" required>
34 40 <?php
35 41 foreach($reponse as $value){
36 42 echo '<option value="'.$value[0].'">'.$value[0].'</option>';
... ... @@ -42,30 +48,30 @@
42 48 <div>
43 49 Heure de début du créneau :
44 50 <select class="form-select" name="heure" id="heure" onchange='calcul_fin();' required>
45   - <option value="0" selected> 00h00 </option>
46   - <option value="1"> 01h00 </option>
47   - <option value="2"> 02h00 </option>
48   - <option value="3"> 03h00 </option>
49   - <option value="4"> 04h00 </option>
50   - <option value="5"> 05h00 </option>
51   - <option value="6"> 06h00 </option>
52   - <option value="7"> 07h00 </option>
53   - <option value="8"> 08h00 </option>
54   - <option value="9"> 09h00 </option>
55   - <option value="10"> 10h00 </option>
56   - <option value="11"> 11h00 </option>
57   - <option value="12"> 12h00 </option>
58   - <option value="13"> 13h00 </option>
59   - <option value="14"> 14h00 </option>
60   - <option value="15"> 15h00 </option>
61   - <option value="16"> 16h00 </option>
62   - <option value="17"> 17h00 </option>
63   - <option value="18"> 18h00 </option>
64   - <option value="19"> 19h00 </option>
65   - <option value="20"> 20h00 </option>
66   - <option value="21"> 21h00 </option>
67   - <option value="22"> 22h00 </option>
68   - <option value="23"> 23h00 </option>
  51 + <option value="0" id="0" selected> 00h00 </option>
  52 + <option value="1" id="1"> 01h00 </option>
  53 + <option value="2" id="2"> 02h00 </option>
  54 + <option value="3" id="3"> 03h00 </option>
  55 + <option value="4" id="4"> 04h00 </option>
  56 + <option value="5" id="5"> 05h00 </option>
  57 + <option value="6" id="6"> 06h00 </option>
  58 + <option value="7" id="7"> 07h00 </option>
  59 + <option value="8" id="8"> 08h00 </option>
  60 + <option value="9" id="9"> 09h00 </option>
  61 + <option value="10" id="10"> 10h00 </option>
  62 + <option value="11" id="11"> 11h00 </option>
  63 + <option value="12" id="12"> 12h00 </option>
  64 + <option value="13" id="13"> 13h00 </option>
  65 + <option value="14" id="14"> 14h00 </option>
  66 + <option value="15" id="15"> 15h00 </option>
  67 + <option value="16" id="16"> 16h00 </option>
  68 + <option value="17" id="17"> 17h00 </option>
  69 + <option value="18" id="18"> 18h00 </option>
  70 + <option value="19" id="19"> 19h00 </option>
  71 + <option value="20" id="20"> 20h00 </option>
  72 + <option value="21" id="21"> 21h00 </option>
  73 + <option value="22" id="22"> 22h00 </option>
  74 + <option value="23" id="23"> 23h00 </option>
69 75 </select>
70 76 </div>
71 77  
... ... @@ -74,7 +80,7 @@
74 80 </div>
75 81  
76 82 <div>
77   - <button class="btn-lg btn-primary" type="submit">Reserver</button>
  83 + <button class="btn-lg btn-success" type="submit">Reserver</button>
78 84 </div>
79 85 </form>
80 86  
... ... @@ -90,7 +96,6 @@
90 96 day='0'+day.toString();
91 97  
92 98 var minDate=year.toString()+'-'+month+'-'+day;
93   - console.log(minDate);
94 99 var txtdate=document.getElementById('txtDate');
95 100 txtdate.min=minDate;
96 101 }
... ... @@ -106,6 +111,47 @@
106 111 var h=valeur.toString();
107 112 lafin.textContent=h+"h00";
108 113 }
  114 + function dispo_creneau(){
  115 + var txtDate = document.getElementById('txtDate');
  116 + var newBanc = document.getElementById('banc');
  117 + var realBanc = newBanc.value;
  118 + var valDate = txtDate.value.split("-");
  119 + var year = valDate[0];
  120 + var month = valDate[1];
  121 + var day = valDate[2];
  122 + var realDate = day+"/"+month+"/"+year;
  123 + var xhttp = new XMLHttpRequest();
  124 + var params = "date="+realDate+"&banc="+realBanc;
  125 + console.log(params);
  126 + xhttp.onreadystatechange=function(){
  127 + if(xhttp.readyState==4){
  128 + // Si requete faite, on modifie les horaires non dispo
  129 + var elemId;
  130 + var texte=xhttp.responseText.split("-");
  131 + if(texte.length>1){
  132 + for(var i=0;i<texte.length-1;i++){
  133 + if(texte[i][0]==0){
  134 + elemId=texte[i][1];
  135 + }else{
  136 + elemId=texte[i][0]+texte[i][1];
  137 + }
  138 + var chgt = document.getElementById(elemId);
  139 + chgt.disabled=true;
  140 + chgt.style.color="red";
  141 + }
  142 + }else{
  143 + for(var i=0;i<24;i++){
  144 + var chgt = document.getElementById(i);
  145 + chgt.disabled=false;
  146 + chgt.style.color="black";
  147 + }
  148 + }
  149 + }
  150 + }
  151 + xhttp.open('POST','dispoCreneau.php',true);
  152 + xhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  153 + xhttp.send(params);
  154 + }
109 155 </script>
110 156 </body>
111 157 </html>
... ...