gestionReservation.php 4.34 KB
<!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']) && $_SESSION['identifiant']=="admin"){
				$identifiant = $_SESSION['identifiant'];
			}else{
				echo "<meta http-equiv=\"refresh\" content=\"0;url=menu.php\">";
			}
			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 */
			/* TODO : Si date déjà passée = Seulement consultation */
			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);
				if($reponse!=null){
					$personne = $reponse[0][0];
					echo "<td>$personne</td>";
				}else{
					echo "<td></td>";
				}
				if($reponse==null){
					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>";
				}else if($reponse[0][0]=="admin"){
					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>";
				}else{
					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>";
				}
				echo "</tr>";
			}
			echo "</tbody>";
			echo "</table>";	
			echo "</form>";
			mysqli_close($db);
		?>
		</div>
	</body>
</html>