intranet-apei/event.php

146 lines
No EOL
4.6 KiB
PHP

<?php
include("./Assets/functions.php");
$config = json_decode(file_get_contents("./Assets/config.json"), true);
$bdd = connectBDD("localhost", $config["BDD_USER"], $config["BDD_PASSWD"], $config["BDD_NAME"]);
$page = 'Bonnes pratiques';
/* Gestion de la connexion */
session_start();
if (!isset($_SESSION['connected']) || $_SESSION['connected'] == false) {
header('location: login.php');
exit;
}
/* Récupération de l'évènement */
$titre = getEventName($bdd, $_GET['event']);
$images = getEventImages($bdd, $_GET['event']);
$couvertureImg = getEventBigImage($bdd, $_GET['event']);
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Intranet de l'APEI</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="shortcut icon" href="./Assets/Icones/APEIMBGE.jpg" type="image/x-icon">
<link rel="stylesheet" href="./styles-scripts/event.css">
<style>
/* Nettoyage des styles pour éviter les conflits Bootstrap sur le reste de la page */
body {
overflow-x: hidden; /* Sécurité anti-scroll horizontal */
margin: 0;
padding: 0;
}
.custom-grid-container {
width: 100%;
padding: 0 15px; /* Évite que les images collent aux bords de l'écran */
box-sizing: border-box;
}
/* Clearfix pour contenir les éléments en float */
.custom-grid-container::after {
content: "";
display: table;
clear: both;
}
.custom-column {
float: left;
width: 25%;
box-sizing: border-box;
padding: 5px; /* Espacement entre les images */
}
.custom-column img {
width: 100%;
display: block;
margin-bottom: 10px;
}
h1 {
padding: 20px 15px;
margin: 0;
}
</style>
</head>
<body>
<?php include('./Assets/navbar.php'); ?>
<h1><?= htmlspecialchars($titre) ?></h1>
<div class="custom-grid-container">
<?php
$nbColumns = 4;
$rowsPerColumn = 5;
$columns = [];
/**
* Vérifie si une image peut être placée à une position donnée
*/
function canPlace($columns, $col, $row, $imagePath)
{
// Vérifie le dessus
if ($row > 0 && isset($columns[$col][$row - 1]) && $columns[$col][$row - 1] === $imagePath) {
return false;
}
if ($col > 0) {
// Gauche
if (isset($columns[$col - 1][$row]) && $columns[$col - 1][$row] === $imagePath) {
return false;
}
// Diagonale Haut-Gauche
if ($row > 0 && isset($columns[$col - 1][$row - 1]) && $columns[$col - 1][$row - 1] === $imagePath) {
return false;
}
// Diagonale Bas-Gauche
if (isset($columns[$col - 1][$row + 1]) && $columns[$col - 1][$row + 1] === $imagePath) {
return false;
}
}
return true;
}
// Construction de la structure de données
for ($col = 0; $col < $nbColumns; $col++) {
$columns[$col] = [];
for ($row = 0; $row < $rowsPerColumn; $row++) {
shuffle($images);
$placed = false;
foreach ($images as $img) {
if (canPlace($columns, $col, $row, $img['chemin'])) {
$columns[$col][$row] = $img['chemin'];
$placed = true;
break;
}
}
if (!$placed && !empty($images)) {
$columns[$col][$row] = $images[0]['chemin'];
}
}
}
// Affichage manuel sans classes Bootstrap conflictuelles
for ($col = 0; $col < $nbColumns; $col++): ?>
<div class="custom-column">
<?php foreach ($columns[$col] as $imgPath): ?>
<img src="<?= $imgPath ?>" alt="Image évènement">
<?php endforeach; ?>
</div>
<?php endfor; ?>
</div>
<button type="button" class="btn btn-primary" style="position: fixed; bottom: 20px; right: 20px;" onclick="window.location.href='diapo.php?event=<?= $_GET['event'] ?>'">Diaporama</button>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>