Ajout de la modifications des XP/Projets en admin (fonctionnel)
This commit is contained in:
@@ -11,7 +11,7 @@ function listeProjets() {
|
|||||||
// Essayer
|
// Essayer
|
||||||
try {
|
try {
|
||||||
// Requête SQL qui récupère titre, tags, description, image_url
|
// 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
|
// Execution de la requête SQL
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
// Retourne toutes les données collectés dans un ARRAY
|
// 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
|
// Fonction qui va afficher les projets
|
||||||
function afficherProjets() {
|
function afficherProjets() {
|
||||||
// Récupération de la liste des projets
|
// Récupération de la liste des projets
|
||||||
@@ -75,3 +91,55 @@ function afficherProjets() {
|
|||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fonction identique à celle en haut mais ajout de bouton
|
||||||
|
function afficherProjetsAdmin() {
|
||||||
|
$projets = listeProjets();
|
||||||
|
|
||||||
|
echo '<div class="projects-list">';
|
||||||
|
|
||||||
|
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 '<article class="project-card">';
|
||||||
|
|
||||||
|
if (!empty($image)) {
|
||||||
|
echo '<div class="project-banner">';
|
||||||
|
echo '<img src="' . $image . '" alt="Image du projet ' . $titre . '">';
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<div class="project-content">';
|
||||||
|
echo '<h2>' . $titre . '</h2>';
|
||||||
|
|
||||||
|
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 qui vont permettrent la modification / Suppresion
|
||||||
|
echo '<div class="admin-actions">';
|
||||||
|
echo '<a class="btn-submit btn-edit" href="./admin.php?edit_project=' . $id . '">Modifier</a>';
|
||||||
|
echo '<a class="btn-submit btn-delete" href="../scripts/removeProject.php?id=' . $id . '" onclick="return confirm(\'Voulez-vous vraiment supprimer ce projet ?\');">Supprimer</a>';
|
||||||
|
echo '</div>';
|
||||||
|
|
||||||
|
echo '</div>';
|
||||||
|
echo '</article>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+73
-1
@@ -14,7 +14,7 @@ function listeXP() {
|
|||||||
// Essayer
|
// Essayer
|
||||||
try {
|
try {
|
||||||
// Requête SQL qui récupère titre, type, tags, description, durée, image_url
|
// 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
|
// Execution de la requête SQL
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
// Retourne toutes les données collectés dans un ARRAY
|
// 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
|
// Fonction qui va afficher les experiences
|
||||||
function afficherXP() {
|
function afficherXP() {
|
||||||
@@ -91,5 +108,60 @@ function afficherXP() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fonction identique à celle en haut mais ajout de bouton
|
||||||
|
function afficherXPAdmin() {
|
||||||
|
$experiences = listeXP();
|
||||||
|
|
||||||
|
echo '<div class="projects-list">';
|
||||||
|
|
||||||
|
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 '<article class="project-card">';
|
||||||
|
|
||||||
|
if (!empty($image)) {
|
||||||
|
echo '<div class="project-banner">';
|
||||||
|
echo '<img src="' . $image . '" alt="Image de l experience ' . $titre . '">';
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '<div class="project-content">';
|
||||||
|
echo '<h2>' . $titre . '</h2>';
|
||||||
|
echo '<p><strong>Type :</strong> ' . $xptype . '</p>';
|
||||||
|
echo '<p><strong>Durée :</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 qui vont permettrent la modification / Suppresion
|
||||||
|
echo '<div class="admin-actions">';
|
||||||
|
echo '<a class="btn-submit btn-edit" href="./admin.php?edit_xp=' . $id . '">Modifier</a>';
|
||||||
|
echo '<a class="btn-submit btn-delete" href="../scripts/removeXP.php?id=' . $id . '" onclick="return confirm(\'Voulez-vous vraiment supprimer cette expérience ?\');">Supprimer</a>';
|
||||||
|
echo '</div>';
|
||||||
|
|
||||||
|
echo '</div>';
|
||||||
|
echo '</article>';
|
||||||
|
}
|
||||||
|
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
+58
-28
@@ -5,82 +5,112 @@ require_once('./../elements/header.php');
|
|||||||
// Ajout de la base de donnée
|
// Ajout de la base de donnée
|
||||||
require_once '../functions/databaseConnection.php';
|
require_once '../functions/databaseConnection.php';
|
||||||
|
|
||||||
|
require_once('../functions/listProject.php');
|
||||||
|
require_once('../functions/listXP.php');
|
||||||
|
|
||||||
|
|
||||||
// L'utilisateur doit être administrateur
|
// L'utilisateur doit être administrateur
|
||||||
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
||||||
header('Location: ../pages/home.php');
|
header('Location: ../pages/home.php');
|
||||||
exit;
|
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
|
// Page du panneau d'administration
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<?php if (isset($message)) { echo "<p style='color: white; text-align: center;'>$message</p>"; } ?>
|
<div class="admin-forms">
|
||||||
|
|
||||||
<!-- Formulaire de création de projet -->
|
<!-- Formulaire de création de projet -->
|
||||||
<div class="project-container">
|
<div class="project-container">
|
||||||
<div class="project-form-card">
|
<div class="project-form-card">
|
||||||
|
|
||||||
<div class="project-header">
|
<div class="project-header">
|
||||||
<h2>Nouveau projet</h2>
|
<h2><?php echo $projetAModifier ? 'Modifier le projet' : 'Nouveau projet'; ?></h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- en envoie les données à addProject.php -->
|
<!-- en envoie les données à addProject.php -->
|
||||||
<form method="POST" action="../scripts/addProject.php">
|
<form method="POST" action="<?php echo $projetAModifier ? '../scripts/updateProject.php' : '../scripts/addProject.php'; ?>">
|
||||||
|
|
||||||
<label>Titre *</label>
|
<?php if ($projetAModifier): ?>
|
||||||
<input type="text" name="title" required>
|
<input type="hidden" name="id" value="<?php echo (int) $projetAModifier['id']; ?>">
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<label>Tags (virgules)</label>
|
<label>Titre *</label>
|
||||||
<input type="text" name="tags">
|
<input type="text" name="title" required value="<?php echo $projetAModifier ? htmlspecialchars($projetAModifier['title']) : ''; ?>">
|
||||||
|
|
||||||
<label>Description *</label>
|
<label>Tags (virgules)</label>
|
||||||
<textarea name="description" required></textarea>
|
<input type="text" name="tags" value="<?php echo $projetAModifier ? htmlspecialchars($projetAModifier['tags']) : ''; ?>">
|
||||||
|
|
||||||
<label>Lien de l'image *</label>
|
<label>Description *</label>
|
||||||
<!-- URL Pour un potentiel Lien image/CDN -->
|
<textarea name="description" required><?php echo $projetAModifier ? htmlspecialchars($projetAModifier['description']) : ''; ?></textarea>
|
||||||
<input type="url" name="image_url" placeholder="https://..." required>
|
|
||||||
|
|
||||||
<!-- Le bouton qui déclenche le PHP en haut de page -->
|
<label>Lien de l'image *</label>
|
||||||
<input type="submit" name="submit_project" value="+ Ajouter le projet" class="btn-submit">
|
<input type="url" name="imageurl" placeholder="https://..." required value="<?php echo $projetAModifier ? htmlspecialchars($projetAModifier['image_url']) : ''; ?>">
|
||||||
|
|
||||||
|
<input type="submit" name="submitproject" value="<?php echo $projetAModifier ? 'Modifier le projet' : '+ Ajouter le projet'; ?>" class="btn-submit">
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="project-container">
|
<!-- Formulaire de création d'expérience -->
|
||||||
|
<div class="project-container">
|
||||||
<div class="project-form-card">
|
<div class="project-form-card">
|
||||||
|
|
||||||
<div class="project-header">
|
<div class="project-header">
|
||||||
<h2>Nouvelle expérience</h2>
|
<h2><?php echo $xpAModifier ? 'Modifier l\'experience' : 'Nouvelle expérience'; ?></h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- en envoie les données à addXP.php -->
|
<!-- en envoie les données à addXP.php -->
|
||||||
<form method="POST" action="../scripts/addXP.php">
|
<form method="POST" action="<?php echo $xpAModifier ? '../scripts/updateXP.php' : '../scripts/addXP.php'; ?>">
|
||||||
|
|
||||||
|
<?php if ($xpAModifier): ?>
|
||||||
|
<input type="hidden" name="id" value="<?php echo (int) $xpAModifier['id']; ?>">
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<label>Titre *</label>
|
<label>Titre *</label>
|
||||||
<input type="text" name="title" required>
|
<input type="text" name="title" required value="<?php echo $xpAModifier ? htmlspecialchars($xpAModifier['title']) : ''; ?>">
|
||||||
|
|
||||||
<!-- type : stage alternance ou autre -->
|
|
||||||
<label>Type *</label>
|
<label>Type *</label>
|
||||||
<textarea name="xptype" required></textarea>
|
<textarea name="xptype" required><?php echo $xpAModifier ? htmlspecialchars($xpAModifier['xptype']) : ''; ?></textarea>
|
||||||
|
|
||||||
<label>Tags (virgules)</label>
|
<label>Tags (virgules)</label>
|
||||||
<input type="text" name="tags">
|
<input type="text" name="tags" value="<?php echo $xpAModifier ? htmlspecialchars($xpAModifier['tags']) : ''; ?>">
|
||||||
|
|
||||||
<label>Description *</label>
|
<label>Description *</label>
|
||||||
<textarea name="description" required></textarea>
|
<textarea name="description" required><?php echo $xpAModifier ? htmlspecialchars($xpAModifier['description']) : ''; ?></textarea>
|
||||||
|
|
||||||
<!-- durée par exemple date - 2 semaines -->
|
|
||||||
<label>Durée *</label>
|
<label>Durée *</label>
|
||||||
<textarea name="duration" required></textarea>
|
<textarea name="duration" required><?php echo $xpAModifier ? htmlspecialchars($xpAModifier['duration']) : ''; ?></textarea>
|
||||||
|
|
||||||
<label>Lien de l'image *</label>
|
<label>Lien de l'image *</label>
|
||||||
<!-- URL Pour un potentiel Lien image/CDN -->
|
<input type="url" name="imageurl" placeholder="https://..." required value="<?php echo $xpAModifier ? htmlspecialchars($xpAModifier['image_url']) : ''; ?>">
|
||||||
<input type="url" name="image_url" placeholder="https://..." required>
|
|
||||||
|
|
||||||
<!-- Le bouton qui déclenche le PHP en haut de page -->
|
<input type="submit" name="submitxp" value="<?php echo $xpAModifier ? 'Modifier l\'experience' : '+ Ajouter l\'experience'; ?>" class="btn-submit">
|
||||||
<input type="submit" name="submit_xp" value="+ Ajouter l'experience" class="btn-submit">
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
// Liste des projets / xps => en gros on pourra supprimer, et modifier à la vollée sans aller dans la bdd
|
||||||
|
?>
|
||||||
|
<h2 class="projects-title">Gérer les projets</h2>
|
||||||
|
<?php afficherProjetsAdmin(); ?>
|
||||||
|
<h2 class="projects-title">Gérer les experiences</h2>
|
||||||
|
<?php afficherXPAdmin(); ?>
|
||||||
@@ -6,6 +6,10 @@
|
|||||||
// On ajoute le header
|
// On ajoute le header
|
||||||
require_once('../elements/header.php');
|
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 "<p style='color: white; text-align: center;'>Vous êtes administrateur, vous pouvez modifier les projets <a href='/admin.php'>ici</a>.</p>";
|
||||||
|
}
|
||||||
// Affichages des projets
|
// Affichages des projets
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
// On ajoute le header
|
// On ajoute le header
|
||||||
require_once('../elements/header.php');
|
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 "<p style='color: white; text-align: center;'>Vous êtes administrateur, vous pouvez modifier les experiences <a href='/admin.php'>ici</a>.</p>";
|
||||||
|
}
|
||||||
|
|
||||||
// Affichages des projets
|
// Affichages des projets
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
// On démarre la session
|
||||||
|
session_start();
|
||||||
|
// On ajoute la DB
|
||||||
|
require_once('../functions/databaseConnection.php');
|
||||||
|
|
||||||
|
// Si l'utilisateur n'est pas admin il ne peut pas executer le reste du script
|
||||||
|
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
||||||
|
header('Location: ../pages/home.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//L'id doit être collecté sinon l'utilisateur ne peux pas executer le reste du script
|
||||||
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||||
|
header('Location: ../pages/admin.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On collecte l'id et on le met en variable locale
|
||||||
|
$id = (int) $_GET['id'];
|
||||||
|
|
||||||
|
try { // On essaie d'executer une requête qui est préparée
|
||||||
|
$stmt = $dbh->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;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
// On démarre la session
|
||||||
|
session_start();
|
||||||
|
// On ajoute la DB
|
||||||
|
require_once('../functions/databaseConnection.php');
|
||||||
|
|
||||||
|
// Si l'utilisateur n'est pas admin il ne peut pas executer le reste du script
|
||||||
|
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
||||||
|
header('Location: ../pages/home.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//L'id doit être collecté sinon l'utilisateur ne peux pas executer le reste du script
|
||||||
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||||
|
header('Location: ../pages/admin.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On collecte l'id et on le met en variable locale
|
||||||
|
$id = (int) $_GET['id'];
|
||||||
|
|
||||||
|
try { // On essaie d'executer une requête qui est préparée
|
||||||
|
$stmt = $dbh->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;
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
// On démarre la session
|
||||||
|
session_start();
|
||||||
|
// On ajoute la DB
|
||||||
|
require_once('../functions/databaseConnection.php');
|
||||||
|
|
||||||
|
// Si l'utilisateur n'est pas admin il ne peut pas executer le reste du script
|
||||||
|
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
||||||
|
header('Location: ../pages/home.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( // Si les champs sont vides on renvoie vers admin.php
|
||||||
|
!isset($_POST['id']) || !is_numeric($_POST['id']) ||
|
||||||
|
empty($_POST['title']) ||
|
||||||
|
empty($_POST['description']) ||
|
||||||
|
empty($_POST['imageurl'])
|
||||||
|
) {
|
||||||
|
header('Location: ../pages/admin.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// On récupère les données pour les mettres en variables locales
|
||||||
|
$id = (int) $_POST['id'];
|
||||||
|
$title = trim($_POST['title']);
|
||||||
|
$tags = trim($_POST['tags'] ?? '');
|
||||||
|
$description = trim($_POST['description']);
|
||||||
|
$imageurl = trim($_POST['imageurl']);
|
||||||
|
|
||||||
|
try { // On essaie d'executer une requête qui est préparée
|
||||||
|
$stmt = $dbh->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;
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
// On démarre la session
|
||||||
|
session_start();
|
||||||
|
// On ajoute la DB
|
||||||
|
require_once('../functions/databaseConnection.php');
|
||||||
|
|
||||||
|
// Si l'utilisateur n'est pas admin il ne peut pas executer le reste du script
|
||||||
|
if (!isset($_SESSION['role']) || $_SESSION['role'] !== 'admin') {
|
||||||
|
header('Location: ../pages/home.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si le formulaire à un champ vide
|
||||||
|
if (
|
||||||
|
!isset($_POST['id']) || !is_numeric($_POST['id']) ||
|
||||||
|
empty($_POST['title']) ||
|
||||||
|
empty($_POST['xptype']) ||
|
||||||
|
empty($_POST['description']) ||
|
||||||
|
empty($_POST['duration']) ||
|
||||||
|
empty($_POST['imageurl'])
|
||||||
|
) { // On renvoie sur admin.php
|
||||||
|
header('Location: ../pages/admin.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
//On récupère les données pour les mettres en variables locales
|
||||||
|
$id = (int) $_POST['id'];
|
||||||
|
$title = trim($_POST['title']);
|
||||||
|
$xptype = trim($_POST['xptype']);
|
||||||
|
$tags = trim($_POST['tags'] ?? '');
|
||||||
|
$description = trim($_POST['description']);
|
||||||
|
$duration = trim($_POST['duration']);
|
||||||
|
$imageurl = trim($_POST['imageurl']);
|
||||||
|
|
||||||
|
try { // On essaie d'executer une requête qui est préparée
|
||||||
|
$stmt = $dbh->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;
|
||||||
+37
-2
@@ -38,6 +38,11 @@ nav a {
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nav a:hover {
|
||||||
|
background-color: #1a1a24;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
/* ---- PAGE LOGIN ---- */
|
/* ---- PAGE LOGIN ---- */
|
||||||
|
|
||||||
/* Centre la carte au milieu de la page */
|
/* Centre la carte au milieu de la page */
|
||||||
@@ -117,7 +122,7 @@ nav a {
|
|||||||
.project-container {
|
.project-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 40px 20px;
|
padding: 10px 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.project-form-card {
|
.project-form-card {
|
||||||
@@ -126,10 +131,12 @@ nav a {
|
|||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
padding: 30px;
|
padding: 30px;
|
||||||
width: 800px;
|
width: 800px;
|
||||||
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.project-header h2 {
|
.project-header h2 {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
margin-bottom: 20px;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -173,10 +180,12 @@ nav a {
|
|||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
|
margin-bottom: 16px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
.project-card textarea {
|
/* Correction ici : project-form-card au lieu de project-card */
|
||||||
|
.project-form-card textarea {
|
||||||
min-height: 100px;
|
min-height: 100px;
|
||||||
resize: vertical;
|
resize: vertical;
|
||||||
}
|
}
|
||||||
@@ -279,3 +288,29 @@ nav a {
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
font-weight: bold;
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user