117 lines
3.7 KiB
PHP
117 lines
3.7 KiB
PHP
<?php
|
|
|
|
// Ajout de connexion a la bdd
|
|
require_once('../functions/databaseConnection.php');
|
|
|
|
// Fonction qui va faire une requête SQL afin de collecter toutes les écoles / formations
|
|
// Retourne un tableau vide si la table n'existe pas encore (pas de die() pour que la page
|
|
// Expériences continue de fonctionner tant que le script SQL n'a pas été exécuté)
|
|
function listeEcoles() {
|
|
global $dbh;
|
|
|
|
try {
|
|
$stmt = $dbh->prepare('SELECT id, title, status, tags, description, duration, image_url FROM schools ORDER BY id DESC');
|
|
$stmt->execute();
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
// Fonction qui permet de récupérer une école par id (pour la modification dans le panel Admin)
|
|
function recupererEcoleParId($id) {
|
|
global $dbh;
|
|
|
|
try {
|
|
$stmt = $dbh->prepare('SELECT id, title, status, tags, description, duration, image_url FROM schools WHERE id = :id');
|
|
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
return $stmt->fetch(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// Fonction interne qui affiche une carte école (utilisée par la page publique et le panel admin)
|
|
function afficherEcoleCard($ecole, $admin = false) {
|
|
$id = (int) $ecole['id'];
|
|
$titre = htmlspecialchars($ecole['title']);
|
|
$description = nl2br(htmlspecialchars($ecole['description']));
|
|
$duration = htmlspecialchars($ecole['duration']);
|
|
$image = htmlspecialchars($ecole['image_url']);
|
|
$status = htmlspecialchars($ecole['status'] ?? '');
|
|
$tags = [];
|
|
|
|
// S'il y a des tags alors on les sépares grâce à la virgule (tags1,tags2,etc...)
|
|
if (!empty($ecole['tags'])) {
|
|
$tags = array_filter(array_map('trim', explode(',', $ecole['tags'])));
|
|
}
|
|
|
|
echo '<article class="project-card">';
|
|
|
|
// Si la donnée avec l'image n'est pas null alors on l'affiche
|
|
if (!empty($image)) {
|
|
echo '<div class="project-banner">';
|
|
echo '<img src="' . $image . '" alt="Image de l ecole ' . $titre . '">';
|
|
|
|
if (!empty($status)) {
|
|
echo '<div class="project-state">' . $status . '</div>';
|
|
}
|
|
|
|
echo '</div>';
|
|
}
|
|
|
|
echo '<div class="project-content">';
|
|
echo '<h2>' . $titre . '</h2>';
|
|
|
|
echo '<p><strong>Période :</strong> ' . $duration . '</p>';
|
|
|
|
if (!empty($tags)) {
|
|
echo '<div class="project-tags">';
|
|
foreach ($tags as $tag) {
|
|
echo '<span class="tag">' . htmlspecialchars($tag) . '</span>';
|
|
}
|
|
echo '</div>';
|
|
}
|
|
|
|
echo '<p>' . $description . '</p>';
|
|
|
|
// Boutons de modification / suppression pour le panel admin
|
|
if ($admin) {
|
|
echo '<div class="admin-actions">';
|
|
echo '<a class="btn-submit btn-edit" href="./admin.php?edit_school=' . $id . '">Modifier</a>';
|
|
echo '<a class="btn-submit btn-delete" href="../scripts/removeSchool.php?id=' . $id . '" onclick="return confirm(\'Voulez-vous vraiment supprimer cette école ?\');">Supprimer</a>';
|
|
echo '</div>';
|
|
}
|
|
|
|
echo '</div>';
|
|
echo '</article>';
|
|
}
|
|
|
|
// Fonction qui va afficher les écoles sur la page publique
|
|
function afficherEcoles() {
|
|
$ecoles = listeEcoles();
|
|
|
|
// Si la table est vide ou n'existe pas encore on n'affiche rien
|
|
if (empty($ecoles)) {
|
|
return;
|
|
}
|
|
|
|
echo '<div class="projects-list">';
|
|
foreach ($ecoles as $ecole) {
|
|
afficherEcoleCard($ecole, false);
|
|
}
|
|
echo '</div>';
|
|
}
|
|
|
|
// Fonction identique à celle en haut mais ajout de boutons pour le panel admin
|
|
function afficherEcolesAdmin() {
|
|
$ecoles = listeEcoles();
|
|
|
|
echo '<div class="projects-list">';
|
|
foreach ($ecoles as $ecole) {
|
|
afficherEcoleCard($ecole, true);
|
|
}
|
|
echo '</div>';
|
|
}
|