From 0cc9abb92fd44ccdf15090ab5368c3e2a1884e77 Mon Sep 17 00:00:00 2001 From: Esteban Date: Fri, 5 Jun 2026 16:43:04 +0200 Subject: [PATCH] Ajout de la modifications des XP/Projets en admin (fonctionnel) --- functions/listProject.php | 72 +++++++++++++++++++++++++- functions/listXP.php | 74 ++++++++++++++++++++++++++- pages/admin.php | 104 ++++++++++++++++++++++++-------------- pages/projects.php | 4 ++ pages/xp.php | 5 ++ scripts/removeProject.php | 31 ++++++++++++ scripts/removeXP.php | 31 ++++++++++++ scripts/updateProject.php | 47 +++++++++++++++++ scripts/updateXP.php | 54 ++++++++++++++++++++ styles/primary_css.css | 39 +++++++++++++- 10 files changed, 419 insertions(+), 42 deletions(-) create mode 100644 scripts/removeProject.php create mode 100644 scripts/removeXP.php create mode 100644 scripts/updateProject.php create mode 100644 scripts/updateXP.php diff --git a/functions/listProject.php b/functions/listProject.php index 42422e7..daa1983 100644 --- a/functions/listProject.php +++ b/functions/listProject.php @@ -11,7 +11,7 @@ function listeProjets() { // Essayer try { // Requête SQL qui récupère titre, tags, description, image_url - $stmt = $dbh->prepare('SELECT title, tags, description, image_url FROM projects'); + $stmt = $dbh->prepare('SELECT id, title, tags, description, image_url FROM projects ORDER BY id DESC'); // Execution de la requête SQL $stmt->execute(); // Retourne toutes les données collectés dans un ARRAY @@ -22,6 +22,22 @@ function listeProjets() { } } +// 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 { + $stmt = $dbh->prepare('SELECT id, title, tags, description, image_url FROM projects WHERE 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 @@ -74,4 +90,56 @@ function afficherProjets() { } echo ''; -} \ No newline at end of file +} + +// 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']); + $tags = []; + + if (!empty($projet['tags'])) { + $tags = array_filter(array_map('trim', explode(',', $projet['tags']))); + } + + echo '
'; + + if (!empty($image)) { + echo '
'; + echo 'Image du projet ' . $titre . ''; + 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 '
'; +} + diff --git a/functions/listXP.php b/functions/listXP.php index 2b4f3b5..c09de54 100644 --- a/functions/listXP.php +++ b/functions/listXP.php @@ -14,7 +14,7 @@ function listeXP() { // Essayer try { // Requête SQL qui récupère titre, type, tags, description, durée, image_url - $stmt = $dbh->prepare('SELECT title, xptype, tags, description, duration, image_url FROM experiences ORDER BY id DESC'); + $stmt = $dbh->prepare('SELECT id, title, xptype, tags, description, duration, image_url FROM experiences ORDER BY id DESC'); // Execution de la requête SQL $stmt->execute(); // Retourne toutes les données collectés dans un ARRAY @@ -25,6 +25,23 @@ function listeXP() { } } +// Fonction qui permet de récupérer les experiences par id et donc de modifier une xp en particulier en ciblant l'id +function recupererXPParId($id) { + global $dbh; + + try { + // Préparation de la requête préparée + $stmt = $dbh->prepare('SELECT id, title, xptype, tags, description, duration, image_url FROM experiences WHERE id = :id'); + $stmt->bindValue(':id', $id, PDO::PARAM_INT); + $stmt->execute(); + return $stmt->fetch(PDO::FETCH_ASSOC); + // En cas d'erreur => renvoyer un message avec l'erreur + } catch (PDOException $e) { + die("Erreur de connexion à la base de donnée portfolio :" . $e->getMessage()); + // Retourner false en cas d'eerreur + return false; + } +} // Fonction qui va afficher les experiences function afficherXP() { @@ -91,5 +108,60 @@ function afficherXP() { } + echo ''; +} + +// Fonction identique à celle en haut mais ajout de bouton +function afficherXPAdmin() { + $experiences = listeXP(); + + echo '
'; + + foreach ($experiences as $experience) { + $id = (int) $experience['id']; + $titre = htmlspecialchars($experience['title']); + $xptype = htmlspecialchars($experience['xptype']); + $description = nl2br(htmlspecialchars($experience['description'])); + $duration = htmlspecialchars($experience['duration']); + $image = htmlspecialchars($experience['image_url']); + $tags = []; + + if (!empty($experience['tags'])) { + $tags = array_filter(array_map('trim', explode(',', $experience['tags']))); + } + + echo '
'; + + if (!empty($image)) { + echo '
'; + echo 'Image de l experience ' . $titre . ''; + echo '
'; + } + + echo '
'; + echo '

' . $titre . '

'; + echo '

Type : ' . $xptype . '

'; + echo '

Durée : ' . $duration . '

'; + + 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 '
'; } \ No newline at end of file diff --git a/pages/admin.php b/pages/admin.php index 4bfe899..1e3f9ab 100644 --- a/pages/admin.php +++ b/pages/admin.php @@ -5,82 +5,112 @@ require_once('./../elements/header.php'); // Ajout de la base de donnée require_once '../functions/databaseConnection.php'; +require_once('../functions/listProject.php'); +require_once('../functions/listXP.php'); + + // L'utilisateur doit être administrateur if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') { header('Location: ../pages/home.php'); exit; } +// On met les variables à null ici pour éviter qu'il garde les options en premier chargement +$projetAModifier = null; +$xpAModifier = null; + + +// Si on modifie XP ou Projets +if (isset($_GET['edit_project']) && is_numeric($_GET['edit_project'])) { + $projetAModifier = recupererProjetParId((int) $_GET['edit_project']); +} +if (isset($_GET['edit_xp']) && is_numeric($_GET['edit_xp'])) { + $xpAModifier = recupererXPParId((int) $_GET['edit_xp']); +} + // Page du panneau d'administration ?> - $message

"; } ?> +
-

Nouveau projet

+

-
+ + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + +
-
+ +
-

Nouvelle expérience

+

-
+ + + + + - + - - - + + - - + + - + - - - + + - - - - - + + +
-
\ No newline at end of file +
+ +
+ + en gros on pourra supprimer, et modifier à la vollée sans aller dans la bdd +?> +

Gérer les projets

+ +

Gérer les experiences

+ \ No newline at end of file diff --git a/pages/projects.php b/pages/projects.php index 74e6bad..7e7314b 100644 --- a/pages/projects.php +++ b/pages/projects.php @@ -6,6 +6,10 @@ // On ajoute le header require_once('../elements/header.php'); +// Ajout d'un message indiquant si l'utilisateur est admin qu'il peut modifier ces projets +if (isset($_SESSION['role']) && $_SESSION['role'] === 'admin') { + echo "

Vous êtes administrateur, vous pouvez modifier les projets ici.

"; +} // Affichages des projets ?> diff --git a/pages/xp.php b/pages/xp.php index df8ca4f..c6f1703 100644 --- a/pages/xp.php +++ b/pages/xp.php @@ -5,6 +5,11 @@ // On ajoute le header require_once('../elements/header.php'); +// Ajout d'un message indiquant si l'utilisateur est admin qu'il peut modifier ces expériences +if (isset($_SESSION['role']) && $_SESSION['role'] === 'admin') { + echo "

Vous êtes administrateur, vous pouvez modifier les experiences ici.

"; +} + // Affichages des projets ?> diff --git a/scripts/removeProject.php b/scripts/removeProject.php new file mode 100644 index 0000000..9dd4c15 --- /dev/null +++ b/scripts/removeProject.php @@ -0,0 +1,31 @@ +prepare('DELETE FROM projects WHERE id = :id'); + $stmt->bindValue(':id', $id, PDO::PARAM_INT); + $stmt->execute(); // Sinon on renvoie l'erreur +} catch (PDOException $e) { + die("Erreur lors de la suppression du projet :" . $e->getMessage()); +} +// On renvoie l'utilisateur sur admin.php +header('Location: ../pages/admin.php'); +exit; \ No newline at end of file diff --git a/scripts/removeXP.php b/scripts/removeXP.php new file mode 100644 index 0000000..6949a7a --- /dev/null +++ b/scripts/removeXP.php @@ -0,0 +1,31 @@ +prepare('DELETE FROM experiences WHERE id = :id'); + $stmt->bindValue(':id', $id, PDO::PARAM_INT); + $stmt->execute(); // Sinon on renvoie l'erreur +} catch (PDOException $e) { + die("Erreur lors de la suppression de l experience :" . $e->getMessage()); +} +// On renvoie l'utilisateur sur admin.php +header('Location: ../pages/admin.php'); +exit; \ No newline at end of file diff --git a/scripts/updateProject.php b/scripts/updateProject.php new file mode 100644 index 0000000..5458127 --- /dev/null +++ b/scripts/updateProject.php @@ -0,0 +1,47 @@ +prepare(' + UPDATE projects + SET title = :title, tags = :tags, description = :description, image_url = :image_url + WHERE id = :id + '); + $stmt->bindValue(':title', $title, PDO::PARAM_STR); + $stmt->bindValue(':tags', $tags, PDO::PARAM_STR); + $stmt->bindValue(':description', $description, PDO::PARAM_STR); + $stmt->bindValue(':image_url', $imageurl, PDO::PARAM_STR); + $stmt->bindValue(':id', $id, PDO::PARAM_INT); + $stmt->execute(); // Sinon on renvoie l'erreur +} catch (PDOException $e) { + die("Erreur lors de la modification du projet :" . $e->getMessage()); +} +// On renvoie l'utilisateur sur admin.php +header('Location: ../pages/admin.php'); +exit; \ No newline at end of file diff --git a/scripts/updateXP.php b/scripts/updateXP.php new file mode 100644 index 0000000..618a1a6 --- /dev/null +++ b/scripts/updateXP.php @@ -0,0 +1,54 @@ +prepare(' + UPDATE experiences + SET title = :title, xptype = :xptype, tags = :tags, description = :description, duration = :duration, image_url = :image_url + WHERE id = :id + '); + $stmt->bindValue(':title', $title, PDO::PARAM_STR); + $stmt->bindValue(':xptype', $xptype, PDO::PARAM_STR); + $stmt->bindValue(':tags', $tags, PDO::PARAM_STR); + $stmt->bindValue(':description', $description, PDO::PARAM_STR); + $stmt->bindValue(':duration', $duration, PDO::PARAM_STR); + $stmt->bindValue(':image_url', $imageurl, PDO::PARAM_STR); + $stmt->bindValue(':id', $id, PDO::PARAM_INT); + $stmt->execute(); // Sinon on renvoie l'erreur +} catch (PDOException $e) { + die("Erreur lors de la modification de l experience :" . $e->getMessage()); +} +// On renvoie l'utilisateur sur admin.php +header('Location: ../pages/admin.php'); +exit; \ No newline at end of file diff --git a/styles/primary_css.css b/styles/primary_css.css index b46fabd..0853663 100644 --- a/styles/primary_css.css +++ b/styles/primary_css.css @@ -38,6 +38,11 @@ nav a { border-radius: 8px; } +nav a:hover { + background-color: #1a1a24; + color: white; +} + /* ---- PAGE LOGIN ---- */ /* Centre la carte au milieu de la page */ @@ -117,7 +122,7 @@ nav a { .project-container { display: flex; justify-content: center; - padding: 40px 20px; + padding: 10px 20px; } .project-form-card { @@ -126,10 +131,12 @@ nav a { border-radius: 12px; padding: 30px; width: 800px; + max-width: 100%; } .project-header h2 { margin-top: 0; + margin-bottom: 20px; font-size: 20px; display: flex; align-items: center; @@ -173,10 +180,12 @@ nav a { border-radius: 6px; color: white; padding: 12px; + margin-bottom: 16px; box-sizing: border-box; } -.project-card textarea { +/* Correction ici : project-form-card au lieu de project-card */ +.project-form-card textarea { min-height: 100px; resize: vertical; } @@ -278,4 +287,30 @@ nav a { border-radius: 999px; font-size: 13px; font-weight: bold; +} + +/* ---- Panel admin ---- */ + +.admin-actions { + display: flex; + gap: 12px; + margin-top: 20px; + flex-wrap: wrap; +} + +.admin-actions .btn-submit { + display: inline-block; + text-decoration: none; +} + +.btn-edit { + background-color: #6c63ff; +} + +.btn-delete { + background-color: #a12c2f; +} + +.btn-delete:hover { + background-color: #7e2023; } \ No newline at end of file