forked from ghouar-t/SaeDEV2.2
104 lines
3.9 KiB
PHP
104 lines
3.9 KiB
PHP
<?php
|
|
// Informations de connexion à la base de données
|
|
require_once 'common.php';
|
|
session_start();
|
|
$db = initDatabase();
|
|
|
|
// Initialisation des événements si la table est vide
|
|
$event = "SELECT * FROM evenement";
|
|
if (mysqli_num_rows(mysqli_query($db, $event)) == 0) {
|
|
mysqli_query($db, "INSERT INTO evenement VALUES(1, 'Ceremonie d ouverture des JO', 'Tour Eiffel', '2024-07-26', 'debut des JO', 0)");
|
|
mysqli_query($db, "INSERT INTO evenement VALUES(2, 'Football', 'Stade des Princes', '2024-07-27', 'premier match de foot', 0)");
|
|
mysqli_query($db, "INSERT INTO evenement VALUES(3, 'Natation', 'Piscine Olympique', '2024-07-27', 'premiere course', 0)");
|
|
$event = mysqli_query($db, "SELECT * FROM evenement");
|
|
}
|
|
|
|
// Construction de la requête dynamique
|
|
$query = "SELECT * FROM evenement WHERE 1=1";
|
|
$params = [];
|
|
$types = "";
|
|
|
|
if (!empty($_GET['sport'])) {
|
|
$query .= " AND Sport = ?";
|
|
$params[] = $_GET['sport'];
|
|
$types .= "s";
|
|
}
|
|
|
|
if (!empty($_GET['date'])) {
|
|
$query .= " AND Date = ?";
|
|
$params[] = $_GET['date'];
|
|
$types .= "s";
|
|
}
|
|
|
|
if (!empty($_GET['lieu'])) {
|
|
$query .= " AND Lieux = ?";
|
|
$params[] = $_GET['lieu'];
|
|
$types .= "s";
|
|
}
|
|
|
|
// Ajout de l'ordre de tri
|
|
$order_by = $_GET['order_by'] ?? 'Sport';
|
|
$order_dir = $_GET['order_dir'] ?? 'ASC';
|
|
$query .= " ORDER BY $order_by $order_dir";
|
|
|
|
// Préparation de la requête
|
|
$stmt = mysqli_prepare($db, $query);
|
|
if ($params) {
|
|
mysqli_stmt_bind_param($stmt, $types, ...$params);
|
|
}
|
|
mysqli_stmt_execute($stmt);
|
|
$event = mysqli_stmt_get_result($stmt);
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<link rel="icon" href="../img/jo2024.jpg">
|
|
<link rel="stylesheet" href="../css/style.css">
|
|
<title>Évènements - Jeux Olympiques</title>
|
|
</head>
|
|
<body>
|
|
<header>
|
|
<h1 class='Hello'>Liste des Évènements</h1>
|
|
<nav>
|
|
<a href="../" class="categorie">Page d'accueil</a>
|
|
<a href='profil.php'><img class='profil' src='https://dwarves.iut-fbleau.fr/~ghouar-t/SaeDEV2.2/img/photo-profil.png' alt='profil'></a>
|
|
<a href='deconnexion.php' class='categorie'>Déconnexion</a>
|
|
</nav>
|
|
</header>
|
|
<div class="ListeEvenement">
|
|
<div>
|
|
<h2>Liste des Évenements :</h2>
|
|
<form action="" method="GET">
|
|
<div>
|
|
<input name="sport" type="text" id="sport" placeholder="Chercher un sport ..." value="<?php echo htmlspecialchars($_GET['sport'] ?? '', ENT_QUOTES); ?>">
|
|
<input name="lieu" type="text" id="lieu" placeholder="Cherche par un lieu ..." value="<?php echo htmlspecialchars($_GET['lieu'] ?? '', ENT_QUOTES); ?>">
|
|
<input name="date" type="date" id="date" placeholder="Cherche par une date ..." value="<?php echo htmlspecialchars($_GET['date'] ?? '', ENT_QUOTES); ?>">
|
|
<button type="submit">Chercher</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col"><a href="?order_by=Sport&order_dir=<?php echo $order_by == 'Sport' && $order_dir == 'ASC' ? 'DESC' : 'ASC'; ?>">Sport</a></th>
|
|
<th scope="col"><a href="?order_by=Lieux&order_dir=<?php echo $order_by == 'Lieux' && $order_dir == 'ASC' ? 'DESC' : 'ASC'; ?>">Lieux de l'évènement</a></th>
|
|
<th scope="col"><a href="?order_by=Date&order_dir=<?php echo $order_by == 'Date' && $order_dir == 'ASC' ? 'DESC' : 'ASC'; ?>">Date</a></th>
|
|
<th scope="col"><a href="?order_by=NbInscrit&order_dir=<?php echo $order_by == 'NbInscrit' && $order_dir == 'ASC' ? 'DESC' : 'ASC'; ?>">Nombre de Participant</a></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
while ($row = mysqli_fetch_assoc($event)) {
|
|
echo "<tr> <td>".$row['Sport']."</td><td>".$row['Lieux']."</td><td>".$row['Date']."</td><td>".$row['NbInscrit']."</td></tr>";
|
|
}
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<footer>
|
|
<?php require_once('footer.php'); ?>
|
|
</footer>
|
|
</body>
|
|
</html>
|