gestionReservation.php 4.69 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];
				$mois = $explosion_date[1];
				$annee = $explosion_date[0];
				if($jour<10){
					$jour = "0$jour";	
					$txtDate = "$annee-$mois-$jour";
				}
				if($mois<10){
					$mois = "0$mois";
					$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>";

			$explosion_date = explode("-",$txtDate);
			$jour = $explosion_date[2];
			$mois = $explosion_date[1];
			$annee = $explosion_date[0];
			$actualDate = date("Y-m-d");
			$new = explode("-",$actualDate);
			$new_jour = $new[2];
			$new_mois = $new[1];
			$new_annee = $new[0];

			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 */
				$requete = "SELECT login FROM reservation WHERE jour='$txtDate' AND numero=$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($new_annee>$annee || ($new_annee>=$annee && $new_mois>=$mois && $new_jour>$jour)){
					echo "<td><form method='POST' action=''><button disabled class='btn-lg btn-outline-info' type='submit'>Date déjà passée</button></form>";
				}else if($reponse==null){
					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>";
				}else if($reponse[0][0]=="admin"){
					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>";
				}else{
					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>";
				}
				echo "</tr>";
			}
			echo "</tbody>";
			echo "</table>";	
			echo "</form>";
			mysqli_close($db);
		?>
		</div>
	</body>
</html>