gestionBanc.php 2.35 KB
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"/>
		<title>Gestion des bancs</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'])=="admin"){
				$identifiant = $_SESSION['identifiant'];
			}else{
				echo "<meta http-equiv=\"refresh\" content=\"0;url=index.html\">";
			}
			include("connexion.php");
			$requete = "SELECT * FROM banc";
			$exec_requete = mysqli_query($db,$requete);
			$banc = mysqli_fetch_all($exec_requete);
			$requete = "SELECT count(*) FROM banc";
			$exec_requete = mysqli_query($db,$requete);
			$nb_banc = mysqli_fetch_all($exec_requete);
			$nouv_banc = $nb_banc[0][0]+1;
			/* Affichage des appareils */
			echo "<table class='table table-striped'>";
			echo "<thead>";
			echo "<tr>";
			echo "<th>Banc</th>";
			echo "<th>Nombre d'appareil</th>";
			echo "<th></th>";
			echo "</tr>";
			echo "</thead>";
			echo "<tbody>";
			foreach($banc as $value){
				echo "<tr>";
				echo "<td>".$value[0]."</td>";
				$requete = "SELECT count(*) FROM equipement WHERE num=$value[0]";
				$exec_requete = mysqli_query($db,$requete);
				$reponse = mysqli_fetch_all($exec_requete);
				echo "<td>".$reponse[0][0]."</td>";
				echo "<td>";
				if($value[0]==$nouv_banc-1){
					echo "<form method='POST' action='supprBanc.php?banc=".$value[0]."'><button class='btn-lg btn-danger' type='submit'>Supprimer le banc</button></form>";
				}
				echo "</td>";
				echo "</tr>";
			}
			/* Ajout appareil */
			echo "<form method='POST' action='ajoutBanc.php?banc=$nouv_banc'>";
			echo "<tr>";
			echo "<td>$nouv_banc</td>";
			echo "<td></td>";
			echo "<td><button class='btn-lg btn-success' type='submit'>Ajouter le banc</button></td>";
			echo "</tr>";
			echo "</tbody>";
			echo "</table>";	
			echo "</form>";
			mysqli_close($db);
		?>
	</body>
</html>