SaeDEV2.2/php/evenement.php

123 lines
4.8 KiB
PHP
Raw Permalink Normal View History

<?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) {
2024-06-16 10:48:38 +02:00
mysqli_query($db, "INSERT INTO evenement VALUES(1, 'Ceremonie d ouverture des JO','Cérémonie', 'Tour Eiffel', '2024-07-26', 'debut des JO', 0)");
mysqli_query($db, "INSERT INTO evenement VALUES(2, 'match d ouverture Football','Football', 'Stade des Princes', '2024-07-27', 'premier match de foot', 0)");
mysqli_query($db, "INSERT INTO evenement VALUES(3, 'course d ouverture','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>
<?php
if (isset($_SESSION['login'])) {
echo " <a href='../' class='categorie'>Page d'accueil</a>";
echo " <a href='profil.php'><img class='profil' src='https://dwarves.iut-fbleau.fr/~ghouar-t/SaeDEV2.2/img/photo-profil.png' alt='profil'></a>";
echo "<a href='deconnexion.php' class='categorie'>Déconnexion</a>";
}
else {
echo "<a href='../' class='categorie'>Page d'accueil</a>";
echo "<a href='connexion.php' class='categorie'>Connexion</a>";
echo "<a href='inscription.php' class='categorie'>Inscription</a>";
}
?>
</nav>
</header>
2024-06-16 17:25:25 +02:00
2024-06-16 15:02:27 +02:00
<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>
2024-06-16 10:48:38 +02:00
<table class="Event">
<thead>
<tr>
2024-06-16 10:48:38 +02:00
<br><th scope="col"><a href="?order_by=Nom&order_dir=<?php echo $order_by == 'Nom' && $order_dir == 'ASC' ? 'DESC' : 'ASC'; ?>">Nom</a></th>
<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)) {
2024-06-16 15:02:27 +02:00
echo "<tr> <td scope='row'><a href='event.php?id=".$row['id']."'><br>".$row['Nom']."</td><td><br>".$row['Sport']."</td><td><br>".$row['Lieux']."</td><td><br>".$row['Date']."</td><td><br>".$row['NbInscrit']."</td></tr>";
}
?>
</tbody>
</table>
2024-06-16 17:25:25 +02:00
<?php
if (isset($_SESSION['role'])) {
if ($_SESSION['role']=='organizer') {
echo "<br><a href='creer_event.php' class='categorie'>Créer un évènement</a>";
2024-06-16 17:25:25 +02:00
}
}
?>
</div>
<footer>
<?php require_once('footer.php'); ?>
</footer>
</body>
</html>