From df41001821aea37dea9c4c484f0c0a7377ad7c30 Mon Sep 17 00:00:00 2001 From: Erwann Philippe Date: Fri, 6 Mar 2026 17:23:04 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20et=20modification=20des=20racco?= =?UTF-8?q?urcis,=20+=20modifs=20mineurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/functions.php | 82 ++++++++++++---- admin/admin.php | 156 ++++++++++++++++++++++++++++++ admin/createActu.php | 2 +- admin/index.php | 2 +- admin/modifyActuality.php | 2 +- admin/modifyEvent.php | 2 +- admin/modifyGallery.php | 2 +- admin/modifySpecificActuality.php | 2 +- admin/updateShortcut.php | 35 +++++++ styles-scripts/editableCards.js | 73 ++++++++++++++ styles-scripts/index.admin.css | 2 +- 11 files changed, 336 insertions(+), 24 deletions(-) create mode 100644 admin/admin.php create mode 100644 admin/updateShortcut.php create mode 100644 styles-scripts/editableCards.js diff --git a/Assets/functions.php b/Assets/functions.php index 3ef2ad7..8cc18d2 100644 --- a/Assets/functions.php +++ b/Assets/functions.php @@ -21,7 +21,7 @@ function connectBDD($domain, $user, $password, $db) function getActus($bdd, $limit) { - $results = mysqli_query($bdd, "SELECT * FROM actus ORDER BY id DESC LIMIT ".$limit); + $results = mysqli_query($bdd, "SELECT * FROM actus ORDER BY id DESC LIMIT " . $limit); $actus = []; while ($row = mysqli_fetch_assoc($results)) { $actus[] = $row; @@ -189,32 +189,34 @@ function getUserPerms($bdd, $username) return $row ? $row['permissions'] : null; } -function verifyPoids($bdd, $username, $minPoids) { +function verifyPoids($bdd, $username, $minPoids) +{ $sql = "SELECT p.poids FROM utilisateurs u INNER JOIN permissions p ON u.permissions = p.nom WHERE u.username = ?"; - + $stmt = mysqli_prepare($bdd, $sql); - + if ($stmt) { mysqli_stmt_bind_param($stmt, "s", $username); mysqli_stmt_execute($stmt); - + $result = mysqli_stmt_get_result($stmt); $row = mysqli_fetch_assoc($result); - + mysqli_stmt_close($stmt); if ($row) { return (int)$row['poids'] >= (int)$minPoids; } } - + return false; } -function updateEventTitle($bdd, $eventid, $titre){ +function updateEventTitle($bdd, $eventid, $titre) +{ $stmt = mysqli_prepare( $bdd, "UPDATE evenements SET titre = ? WHERE id = ?" @@ -230,7 +232,8 @@ function updateEventTitle($bdd, $eventid, $titre){ return $success; } -function updateEventImage($bdd, $eventId, $image){ +function updateEventImage($bdd, $eventId, $image) +{ $stmt = mysqli_prepare( $bdd, "UPDATE evenements SET couverture = ? WHERE id = ?" @@ -257,7 +260,8 @@ function getSpecificActus($bdd, $id) return $return; } -function updateActuImage($bdd, $actuId, $image){ +function updateActuImage($bdd, $actuId, $image) +{ $stmt = mysqli_prepare( $bdd, "UPDATE actus SET image = ? WHERE id = ?" @@ -273,7 +277,8 @@ function updateActuImage($bdd, $actuId, $image){ return $success; } -function updateActuTitle($bdd, $actuId, $titre){ +function updateActuTitle($bdd, $actuId, $titre) +{ $stmt = mysqli_prepare( $bdd, "UPDATE actus SET titre = ? WHERE id = ?" @@ -289,7 +294,8 @@ function updateActuTitle($bdd, $actuId, $titre){ return $success; } -function updateActuContent($bdd, $actuId, $content){ +function updateActuContent($bdd, $actuId, $content) +{ $stmt = mysqli_prepare( $bdd, "UPDATE actus SET actu = ? WHERE id = ?" @@ -305,7 +311,8 @@ function updateActuContent($bdd, $actuId, $content){ return $success; } -function createEvent($bdd, $titre, $date, $site){ +function createEvent($bdd, $titre, $date, $site) +{ $sql = "INSERT INTO evenements (date, titre, couverture, site_id) VALUES (?, ?, '', ?)"; $req = $bdd->prepare($sql); @@ -314,7 +321,8 @@ function createEvent($bdd, $titre, $date, $site){ return $bdd->insert_id; } -function deleteEvent($bdd, $eventId){ +function deleteEvent($bdd, $eventId) +{ $sql = "DELETE FROM evenements WHERE id = ?"; $req = $bdd->prepare($sql); $req->bind_param("i", $eventId); @@ -322,7 +330,8 @@ function deleteEvent($bdd, $eventId){ return $req->affected_rows > 0; } -function deleteActu($bdd, $eventId){ +function deleteActu($bdd, $eventId) +{ $sql = "DELETE FROM actus WHERE id = ?"; $req = $bdd->prepare($sql); $req->bind_param("i", $eventId); @@ -330,7 +339,8 @@ function deleteActu($bdd, $eventId){ return $req->affected_rows > 0; } -function createActu($bdd, $titre, $actu, $date, $idSite){ +function createActu($bdd, $titre, $actu, $date, $idSite) +{ $stmt = mysqli_prepare( $bdd, @@ -341,4 +351,42 @@ function createActu($bdd, $titre, $actu, $date, $idSite){ $actuId = mysqli_insert_id($bdd); mysqli_stmt_close($stmt); return $actuId; -} \ No newline at end of file +} + +function createShortcut($bdd, $nom, $image, $shortcut) +{ + + $stmt = mysqli_prepare( + $bdd, + "INSERT INTO raccourcis (nom, image, url) VALUES (?, ?, ?)" + ); + mysqli_stmt_bind_param($stmt, "sss", $nom, $image, $shortcut); + mysqli_stmt_execute($stmt); + $actuId = mysqli_insert_id($bdd); + mysqli_stmt_close($stmt); + return $actuId; +} + +function updateRaccourcis($bdd, $idRaccourcis, $nom, $image, $url) +{ + $stmt = mysqli_prepare( + $bdd, + "UPDATE raccourcis SET nom = ?, image = ?, url = ? WHERE id = ?" + ); + mysqli_stmt_bind_param($stmt, "sssi", $nom, $image, $url, $idRaccourcis); + mysqli_stmt_execute($stmt); + $success = mysqli_stmt_affected_rows($stmt) >= 0; + mysqli_stmt_close($stmt); + return $success; +} + +function getSpecificRaccourcis($bdd, $id) +{ + $results = mysqli_query($bdd, "SELECT * FROM `raccourcis` WHERE `id`=" . $id); + $return = []; + + while ($row = mysqli_fetch_assoc($results)) { + $return[] = $row; + } + return $return; +} diff --git a/admin/admin.php b/admin/admin.php new file mode 100644 index 0000000..8bf7461 --- /dev/null +++ b/admin/admin.php @@ -0,0 +1,156 @@ + + + + + + + Gestion Intranet + + + + + + +

Gestion de l'intranet

+ + + +
+ +

Création de raccourcis

+ +
+ + +
+ " + style="width:40px;height:40px;margin-right:10px;cursor:pointer;"> +
+ + +
+ + + +
+
+ +
+ +
+
+ + + + + + + \ No newline at end of file diff --git a/admin/createActu.php b/admin/createActu.php index d2f5517..dea0b4d 100644 --- a/admin/createActu.php +++ b/admin/createActu.php @@ -101,7 +101,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { Actualités diff --git a/admin/index.php b/admin/index.php index 286bbad..b81c2f4 100644 --- a/admin/index.php +++ b/admin/index.php @@ -53,7 +53,7 @@ $uploadDir = "../Photos/INTRANET/"; Actualités diff --git a/admin/modifyActuality.php b/admin/modifyActuality.php index 4fc7e0d..0ebf271 100644 --- a/admin/modifyActuality.php +++ b/admin/modifyActuality.php @@ -51,7 +51,7 @@ $uploadDir = "../Photos/INTRANET/actus/"; Actualités diff --git a/admin/modifyEvent.php b/admin/modifyEvent.php index 312c59b..1538029 100644 --- a/admin/modifyEvent.php +++ b/admin/modifyEvent.php @@ -127,7 +127,7 @@ if (!empty($_POST['new'])) { Actualités diff --git a/admin/modifyGallery.php b/admin/modifyGallery.php index fce6fb6..b54309d 100644 --- a/admin/modifyGallery.php +++ b/admin/modifyGallery.php @@ -121,7 +121,7 @@ while ($row = mysqli_fetch_assoc($result)) { Actualités diff --git a/admin/modifySpecificActuality.php b/admin/modifySpecificActuality.php index de19344..24d5866 100644 --- a/admin/modifySpecificActuality.php +++ b/admin/modifySpecificActuality.php @@ -110,7 +110,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { Actualités diff --git a/admin/updateShortcut.php b/admin/updateShortcut.php new file mode 100644 index 0000000..dd027f3 --- /dev/null +++ b/admin/updateShortcut.php @@ -0,0 +1,35 @@ + { + + el.addEventListener("click", function () { + + const oldValue = this.innerText; + const field = this.dataset.field; + const card = this.closest(".shortcut"); + const id = card.dataset.id; + + const input = document.createElement("input"); + input.value = oldValue; + input.className = "form-control"; + + this.replaceWith(input); + input.focus(); + + input.addEventListener("blur", function () { + + const newValue = this.value; + + fetch("updateShortcut.php", { + method: "POST", + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + id: id, + field: field, + value: newValue + }) + }); + + const span = document.createElement("span"); + span.className = "editable"; + span.dataset.field = field; + span.innerText = newValue; + + input.replaceWith(span); + + }); + + }); + +}); + +document.querySelectorAll(".editable-image").forEach(img => { + + img.addEventListener("click", function () { + + const url = prompt("Nouvelle image (URL ou chemin local):", this.src); + + if (!url) return; + + const card = this.closest(".shortcut"); + const id = card.dataset.id; + + fetch("updateShortcut.php", { + method: "POST", + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + id: id, + field: "image", + value: url + }) + }); + + this.src = url; + + }); + +}); \ No newline at end of file diff --git a/styles-scripts/index.admin.css b/styles-scripts/index.admin.css index 42aa376..8bda2c7 100644 --- a/styles-scripts/index.admin.css +++ b/styles-scripts/index.admin.css @@ -9,6 +9,6 @@ background: #f0f0f0; border: 2px solid #ccc; padding: 20px; - text-align: center; + /* text-align: center; */ border-radius: 8px; } \ No newline at end of file