Blame view

html/gestionReservation.php 4.25 KB
5aaa2b1b   lwadbled   feat(gestionReser...
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
70
71
72
73
  <!DOCTYPE html>
  <html>
  	<head>
  		<meta charset="utf-8"/>
  		<title>Gestion des reservations</title>
  		<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css"
  		      rel="stylesheet"
  		      integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x"
  		      crossorigin="anonymous">
  		<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js"
  			integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//E1J19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4"
  			crossorigin="anonymous">
  		</script>
  	</head>
  	<body>
  		<form method="POST" action="menu.php"> 
  			<button class="btn-lg btn-secondary" type="submit">Retour au menu</button>
  		</form>
  		<?php
  			session_start();
  			if(isset($_SESSION['identifiant'])){
  				$identifiant = $_SESSION['identifiant'];
  			}else{
  				echo "<meta http-equiv=\"refresh\" content=\"0;url=index.html\">";
  			}
  			include("connexion.php");
  			$requete = "SELECT * FROM banc ORDER BY numero";
  			$exec_requete = mysqli_query($db,$requete);
  			$reponse = mysqli_fetch_all($exec_requete);
  			if(isset($_POST['txtDate']) && isset($_POST['banc'])){
  				$txtDate = $_POST['txtDate'];
  				$banc = $_POST['banc'];
  			}else{
  				$txtDate = date("Y-n-j");
  				$banc = $reponse[0][0];
  				/* Verification de la syntaxe de la date */
  				$explosion_date = explode("-",$txtDate);
  				$jour = $explosion_date[2];
  				if($jour<10){
  					$jour = "0$jour";
  					$mois = $explosion_date[1];
  					$annee = $explosion_date[0];
  					$txtDate = "$annee-$mois-$jour";
  				}
  			}	
  		?>
  		
  		<form method="POST" action="gestionReservation.php"> 
  			<div class="text-center">
  				<input type="date" name="txtDate" id="txtDate" onchange="this.form.submit();" <?php echo "value=\"$txtDate\""; ?> required>
  			</div>
  
  			<div class="text-center" style="padding-left: 40rem!important; padding-right: 40rem!important;">
  				Banc choisi : 
  				<select class="form-select" name="banc" id="banc" onchange="this.form.submit();" required>
  				<?php
  					foreach($reponse as $value){
  						echo '<option value="'.$value[0].'"';
  						if($banc==$value[0]){
  							echo "selected";
  						}
  						echo '>'.$value[0].'</option>';
  					}	
  				?>
  				</select>
  			</div>
  		</form>	
  		<div class="text-center">
  		<?php
  			$requete = "SELECT * FROM reservation";
  			$exec_requete = mysqli_query($db,$requete);
  			$reponse = mysqli_fetch_all($exec_requete);
  			/* Affichage des reservations */
13809968   lwadbled   fix(gestionReserv...
74
  			/* TODO : Si date déjà passée = Seulement consultation */
5aaa2b1b   lwadbled   feat(gestionReser...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  			echo "<table class='table table-striped'>";
  			echo "<thead>";
  			echo "<tr>";
  			echo "<th>Heure de début</th>";
  			echo "<th>Reservé par</th>";
  			echo "<th></th>";
  			echo "</tr>";
  			echo "</thead>";
  			echo "<tbody>";
  			for($i=0;$i<24;$i++){
  				if($i<10){
  					$heure = "0".$i.":00";
  				}else{
  					$heure = $i.":00";
  				}
  				echo "<tr>";
  				echo "<td>$heure</td>";
  				/* Requete pour connaitre l'utilisateur reservant le creneau s'il y en a un */
  				/* Reecriture de la date */
  				$explosion_date = explode("-",$txtDate);
  				$jour = $explosion_date[2];
  				$mois = $explosion_date[1];
  				$annee = $explosion_date[0];
  				$new_date = "$jour/$mois/$annee";
  				/* Fin reecriture date */
  				$requete = "SELECT personne FROM reservation WHERE moment='$new_date' AND reserve=$banc AND HEUREDEBUT='$heure'";
  				$exec_requete = mysqli_query($db,$requete);
  				$reponse = mysqli_fetch_all($exec_requete);
13809968   lwadbled   fix(gestionReserv...
103
104
  				$personne = $reponse[0][0];
  				echo "<td>$personne</td>";
5aaa2b1b   lwadbled   feat(gestionReser...
105
  				if($reponse[0][0]==""){
13809968   lwadbled   fix(gestionReserv...
106
  					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>";
5aaa2b1b   lwadbled   feat(gestionReser...
107
  				}else if($reponse[0][0]=="admin"){
13809968   lwadbled   fix(gestionReserv...
108
  					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>";
5aaa2b1b   lwadbled   feat(gestionReser...
109
  				}else{
13809968   lwadbled   fix(gestionReserv...
110
  					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>";
5aaa2b1b   lwadbled   feat(gestionReser...
111
112
113
114
115
116
117
118
119
120
121
122
123
  				}
  				echo "</tr>";
  			}
  			echo "</tbody>";
  			echo "</table>";	
  			echo "</form>";
  			mysqli_close($db);
  		?>
  		</div>
  	</body>
  </html>