prepare(' SELECT p.id, p.title, p.status, p.tags, p.description, p.image_url, p.markdown, p.link_url, p.created_at, pp.pdf_filename FROM projects p LEFT JOIN project_pdfs pp ON pp.project_id = p.id ORDER BY p.id DESC '); // Execution de la requête SQL $stmt->execute(); // Retourne toutes les données collectés dans un ARRAY return $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { // En cas d'erreur die("Erreur de connexion à la base de donnée portfolio :".$e->getMessage()); return []; } } // Fonction qui permet de récupérer les projets par id et donc de modifier une xp en particulier en ciblant l'id function recupererProjetParId($id) { global $dbh; try { // Même principe que listeProjets() : le PDF est joint pour son nom de fichier // uniquement, jamais son contenu binaire $stmt = $dbh->prepare(' SELECT p.id, p.title, p.status, p.tags, p.description, p.image_url, p.markdown, p.link_url, p.created_at, pp.pdf_filename FROM projects p LEFT JOIN project_pdfs pp ON pp.project_id = p.id WHERE p.id = :id '); $stmt->bindValue(':id', $id, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC); // En cas d'erreur retourner false et envoyer un message d'erreur avec l'erreur } catch (PDOException $e) { die("Erreur de connexion à la base de donnée portfolio :" . $e->getMessage()); return false; } } // Fonction qui va afficher les projets function afficherProjets() { // Récupération de la liste des projets $projets = listeProjets(); // Ajout de la class pour la liste des projets FUTUR CSS echo '
'; // Pour chaque projet dans le ARRAY foreach ($projets as $projet) { // On récupère le titre, la description et l'image et le tableau avec les tags $id = (int) $projet['id']; $titre = htmlspecialchars($projet['title']); $description = nl2br(htmlspecialchars($projet['description'])); $image = htmlspecialchars($projet['image_url']); $status = htmlspecialchars($projet['status'] ?? ''); $markdown = trim($projet['markdown'] ?? ''); $lien = trim($projet['link_url'] ?? ''); $pdf = trim($projet['pdf_filename'] ?? ''); $tags = []; // S'il y a des tags alors on les sépares grâce à la virgule que l'user à ajouté dans le champs (tags1,tags2,etcc...) if (!empty($projet['tags'])) { $tags = array_filter(array_map('trim', explode(',', $projet['tags']))); } echo '
'; // Si la donnée avec l'image n'est pas null alors on l'affiche if (!empty($image)) { echo '
'; echo 'Image du projet ' . $titre . ''; if (!empty($status)) { echo '
' . $status . '
'; } echo '
'; } // Ajout de la class project-content et du titre echo '
'; echo '

' . $titre . '

'; // Si les tags ne sont pas vides alors afficher if (!empty($tags)) { echo '
'; foreach ($tags as $tag) { echo '' . htmlspecialchars($tag) . ''; } echo '
'; } // Ajout de la description et fin des classes echo '

' . $description . '

'; // Indicateur de page détaillée : markdown > PDF > lien externe > rien // Le lien rend toute la carte cliquable (voir CSS .card-link) if ($markdown !== '') { echo ' Voir la page détaillée'; } elseif ($pdf !== '') { echo ' Voir le PDF'; } elseif ($lien !== '') { echo ' Voir le lien externe'; } else { echo ' Pas de page détaillée'; } echo '
'; echo '
'; } echo '
'; } // Fonction identique à celle en haut mais ajout de bouton function afficherProjetsAdmin() { $projets = listeProjets(); echo '
'; foreach ($projets as $projet) { $id = (int) $projet['id']; $titre = htmlspecialchars($projet['title']); $description = nl2br(htmlspecialchars($projet['description'])); $image = htmlspecialchars($projet['image_url']); $status = htmlspecialchars($projet['status'] ?? ''); $tags = []; if (!empty($projet['tags'])) { $tags = array_filter(array_map('trim', explode(',', $projet['tags']))); } echo '
'; if (!empty($image)) { echo '
'; echo 'Image du projet ' . $titre . ''; if (!empty($status)) { echo '
' . $status . '
'; } echo '
'; } echo '
'; echo '

' . $titre . '

'; if (!empty($tags)) { echo '
'; foreach ($tags as $tag) { echo '' . htmlspecialchars($tag) . ''; } echo '
'; } echo '

' . $description . '

'; // Boutons qui vont permettrent la modification / Suppresion echo '
'; echo 'Modifier'; echo 'Supprimer'; echo '
'; echo '
'; echo '
'; } echo '
'; }