dernier modif
This commit is contained in:
48
README.md
48
README.md
@@ -46,3 +46,51 @@ docker run -d --name CMS_php -p 8080:80 --network=CMS-bridge cms_php:latest
|
|||||||
```
|
```
|
||||||
|
|
||||||
Pour éviter de lancer les commandes à chaque fois, un script launch-dockers.sh a executer en 'sudo' est disponible.
|
Pour éviter de lancer les commandes à chaque fois, un script launch-dockers.sh a executer en 'sudo' est disponible.
|
||||||
|
# Projet CMS Simplifié
|
||||||
|
|
||||||
|
### Technologies utilisées
|
||||||
|
|
||||||
|
Ce projet a été construit avec les technologies suivantes :
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
## Lancement des dockers MySql et Php
|
||||||
|
|
||||||
|
### Création d'un réseau pour que les services docker puissent communiquer
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker network create -d bridge CMS-bridge
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build BDD
|
||||||
|
|
||||||
|
Builder la BDD MySql avec le Dockerfile présent dans le répertoire bdd
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t cms_mysql .
|
||||||
|
```
|
||||||
|
|
||||||
|
Lancer l'image créée en le connectant au réseau précédemment créé
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d --name CMS_mysql -p 3306:3306 --network=CMS-bridge cms_mysql:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build PHP-Apache
|
||||||
|
|
||||||
|
Builder PHP Apache avec le Dockerfile présent à la racine du projet
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker build -t cms_php .
|
||||||
|
```
|
||||||
|
|
||||||
|
Lancer l'image créée en le connectant au réseau précédemment créé
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d --name CMS_php -p 8080:80 --network=CMS-bridge cms_php:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour éviter de lancer les commandes à chaque fois, un script launch-dockers.sh a executer en 'sudo' est disponible.
|
||||||
@@ -1,43 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// Page pour ajouter un nouvel article dans le CMS
|
||||||
|
|
||||||
require '../include/auth.php';
|
require '../include/auth.php';
|
||||||
require '../include/db.php';
|
require '../include/db.php';
|
||||||
requireLogin();
|
|
||||||
|
|
||||||
|
requireLogin(); // Vérifie que l'utilisateur est connecté
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
$titre = '';
|
$titre = '';
|
||||||
$contenu = '';
|
$contenu = '';
|
||||||
|
|
||||||
// Vérifie si le formulaire a été soumis en méthode
|
// Traitement du formulaire à la soumission
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$titre = trim($_POST['titre'] ?? '');
|
$titre = trim($_POST['titre'] ?? '');
|
||||||
$contenu = trim($_POST['contenu'] ?? '');
|
$contenu = trim($_POST['contenu'] ?? '');
|
||||||
|
|
||||||
|
// Vérification des champs obligatoires
|
||||||
if ($titre === '' || $contenu === '') {
|
if ($titre === '' || $contenu === '') {
|
||||||
$errors[] = 'Tous les champs sont obligatoires.';
|
$errors[] = 'Tous les champs sont obligatoires.';
|
||||||
} else {
|
} else {
|
||||||
|
// Insertion sécurisée dans la base de données
|
||||||
$stmt = $pdo->prepare('INSERT INTO articles (titre, contenu, date_creation) VALUES (:titre, :contenu, :date)');
|
$stmt = $pdo->prepare(
|
||||||
|
'INSERT INTO articles (titre, contenu, date_creation) VALUES (:titre, :contenu, :date)'
|
||||||
|
);
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
':titre' => $titre,
|
':titre' => $titre,
|
||||||
':contenu' => $contenu,
|
':contenu' => $contenu,
|
||||||
':date' => date('Y-m-d H:i:s'),
|
':date' => date('Y-m-d H:i:s'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Redirection vers le tableau de bord après ajout
|
||||||
header('Location: board.php');
|
header('Location: board.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="UTF-8">
|
||||||
<title>Ajouter un article</title>
|
<title>Ajouter un article</title>
|
||||||
<link rel="stylesheet" href="styleajouter.css">
|
<link rel="stylesheet" href="styleajouter.css">
|
||||||
</head>
|
</head>
|
||||||
@@ -45,23 +47,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
<h1>Ajouter un article</h1>
|
<h1>Ajouter un article</h1>
|
||||||
|
|
||||||
|
<!-- Affichage des erreurs -->
|
||||||
<?php foreach ($errors as $e): ?>
|
<?php foreach ($errors as $e): ?>
|
||||||
<p class="error"><?= htmlspecialchars($e) ?></p>
|
<p class="error"><?= htmlspecialchars($e) ?></p>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<!-- Formulaire d'ajout -->
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<label>Titre<br>
|
<label>Titre<br>
|
||||||
<input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required>
|
<input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required>
|
||||||
</label><br>
|
</label>
|
||||||
|
|
||||||
<label>Contenu<br>
|
<label>Contenu<br>
|
||||||
<textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea>
|
<textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea>
|
||||||
</label><br>
|
</label>
|
||||||
|
|
||||||
<button type="submit">Publier de la publication</button>
|
<button type="submit">Publier</button>
|
||||||
<a href="dashboard.php">Annuler de l'anulation</a>
|
<a href="board.php">Annuler</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// Tableau de bord : liste des articles pour l'utilisateur connecté
|
||||||
|
|
||||||
require '../include/auth.php';
|
require '../include/auth.php';
|
||||||
require '../include/db.php';
|
require '../include/db.php';
|
||||||
requireLogin();
|
|
||||||
|
requireLogin(); // Vérifie si l'utilisateur est connecté
|
||||||
|
|
||||||
|
// Récupère tous les articles, triés par date de création descendante
|
||||||
$stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC');
|
$stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC');
|
||||||
$articles = $stmt->fetchAll();
|
$articles = $stmt->fetchAll();
|
||||||
?>
|
?>
|
||||||
<!-- Page Du Tableau de board -->
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr" dir="ltr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Tableau de Bord</title>
|
<title>Tableau de Bord</title>
|
||||||
@@ -15,31 +20,28 @@ $articles = $stmt->fetchAll();
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<!-- Header avec info utilisateur et déconnexion -->
|
||||||
<header>
|
<header>
|
||||||
<h1>Tableau de Bord de bordination</h1>
|
<h1>Tableau de Bord</h1>
|
||||||
<p>
|
<p>
|
||||||
Connecté en tant que
|
Connecté en tant que
|
||||||
<?php
|
<?= htmlspecialchars($_SESSION['user'] ?? 'Invité') ?>
|
||||||
echo htmlspecialchars($_SESSION['user_login'] ?? 'Invité');
|
|
||||||
?>
|
|
||||||
<!-- retourne a la page de deconnexion -->
|
|
||||||
| <a href="logout.php">Se déconnecter</a>
|
| <a href="logout.php">Se déconnecter</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<!-- Page pour ajouter un article -->
|
<!-- Section pour ajouter un article -->
|
||||||
<h2>Gestion des articles</h2>
|
<h2>Gestion des articles</h2>
|
||||||
<a href="ajouter.php">Ajouter un nouvel article</a>
|
<a href="ajouter.php">Ajouter un nouvel article</a>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<!-- Liste des articles existants -->
|
||||||
<h3>Vos articles publiés</h3>
|
<h3>Vos articles publiés</h3>
|
||||||
|
<table>
|
||||||
<table border="1">
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
@@ -51,13 +53,12 @@ $articles = $stmt->fetchAll();
|
|||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($articles as $article) : ?>
|
<?php foreach ($articles as $article) : ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?php echo $article['id']; ?></td>
|
<td><?= $article['id'] ?></td>
|
||||||
<td><?php echo htmlspecialchars($article['titre']); ?></td>
|
<td><?= htmlspecialchars($article['titre']) ?></td>
|
||||||
<td><?php echo $article['date_creation']; ?></td>
|
<td><?= $article['date_creation'] ?></td>
|
||||||
<td>
|
<td>
|
||||||
<a href="modifier.php?id=<?php echo $article['id']; ?>">Modifier</a>
|
<a href="modifier.php?id=<?= $article['id'] ?>">Modifier</a> |
|
||||||
|
|
<a href="supprimer.php?id=<?= $article['id'] ?>">Supprimer</a>
|
||||||
<a href="supprimer.php?id=<?php echo $article['id']; ?>">Supprimer</a>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
@@ -67,3 +68,4 @@ $articles = $stmt->fetchAll();
|
|||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
@@ -1,14 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
require '../include/db.php';
|
// Fichier de connexion utilisateur
|
||||||
require '../include/auth.php';
|
|
||||||
|
|
||||||
$error = '';
|
require '../include/db.php'; // Connexion à la base
|
||||||
|
require '../include/auth.php'; // Fonctions d'authentification
|
||||||
|
|
||||||
|
$error = ''; // Message d'erreur
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$login = isset($_POST['login']) ? $_POST['login'] : '';
|
// Récupération sécurisée des données du formulaire
|
||||||
$password = isset($_POST['password']) ? $_POST['password'] : '';
|
$login = $_POST['login'] ?? '';
|
||||||
|
$password = $_POST['password'] ?? '';
|
||||||
|
|
||||||
|
// Vérification des identifiants
|
||||||
if (checkLogin($pdo, $login, $password)) {
|
if (checkLogin($pdo, $login, $password)) {
|
||||||
|
// Connexion réussie → redirection vers le tableau de bord
|
||||||
header('Location: board.php');
|
header('Location: board.php');
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
@@ -25,16 +30,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
<link rel="stylesheet" href="stylelog.css">
|
<link rel="stylesheet" href="stylelog.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>Connexion</h1>
|
<h1>Connexion</h1>
|
||||||
|
|
||||||
|
<!-- Formulaire de connexion -->
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<input type="text" name="login" placeholder="Login" required><br>
|
<input type="text" name="login" placeholder="Login" required><br>
|
||||||
<input type="password" name="password" placeholder="Mot de passe" required><br>
|
<input type="password" name="password" placeholder="Mot de passe" required><br>
|
||||||
<button type="submit">Se connecter</button>
|
<button type="submit">Se connecter</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<!-- Affichage du message d'erreur si nécessaire -->
|
||||||
<?php if ($error): ?>
|
<?php if ($error): ?>
|
||||||
<p style="color:red;"><?= htmlspecialchars($error) ?></p>
|
<p class="error"><?= htmlspecialchars($error) ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// Fichier pour déconnecter l'utilisateur et supprimer la session
|
||||||
|
|
||||||
session_start(); // Démarrer la session
|
session_start(); // Démarrer la session en cours
|
||||||
|
|
||||||
|
|
||||||
|
// Vider toutes les variables de session
|
||||||
$_SESSION = [];
|
$_SESSION = [];
|
||||||
|
|
||||||
|
// Supprimer le cookie de session si nécessaire
|
||||||
if (ini_get('session.use_cookies')) {
|
if (ini_get('session.use_cookies')) {
|
||||||
$params = session_get_cookie_params();
|
$params = session_get_cookie_params();
|
||||||
setcookie(
|
setcookie(
|
||||||
session_name(),
|
session_name(), // Nom du cookie de session
|
||||||
'',
|
'', // Valeur vide
|
||||||
time() - 42000,
|
time() - 42000, // Date passée pour suppression
|
||||||
$params['path'],
|
$params['path'],
|
||||||
$params['domain'],
|
$params['domain'],
|
||||||
$params['secure'],
|
$params['secure'],
|
||||||
@@ -19,9 +20,9 @@ if (ini_get('session.use_cookies')) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Détruire la session côté serveur
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
|
||||||
|
// Redirection vers la page d'accueil
|
||||||
header('Location: ../index.php');
|
header('Location: ../index.php');
|
||||||
exit;
|
exit;
|
||||||
?>
|
|
||||||
|
|||||||
@@ -1,62 +1,62 @@
|
|||||||
<?php
|
<?php
|
||||||
// Page pour modifier un article
|
// Page pour modifier un article existant
|
||||||
|
|
||||||
|
|
||||||
global $pdo;
|
|
||||||
require '../include/auth.php';
|
require '../include/auth.php';
|
||||||
require '../include/db.php';
|
require '../include/db.php';
|
||||||
requireLogin();
|
|
||||||
|
|
||||||
|
requireLogin(); // Vérifie que l'utilisateur est connecté
|
||||||
|
|
||||||
|
// Récupération de l'id de l'article depuis l'URL
|
||||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||||
|
|
||||||
// Id est pas valide on retourne au tableau
|
// Si l'id n'est pas valide, retour au tableau de bord
|
||||||
if ($id <= 0) {
|
if ($id <= 0) {
|
||||||
header('Location: dashboard.php');
|
header('Location: board.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Récupération de l'article
|
||||||
$stmt = $pdo->prepare('SELECT * FROM articles WHERE id = :id');
|
$stmt = $pdo->prepare('SELECT * FROM articles WHERE id = :id');
|
||||||
$stmt->execute([':id' => $id]);
|
$stmt->execute([':id' => $id]);
|
||||||
$article = $stmt->fetch();
|
$article = $stmt->fetch();
|
||||||
|
|
||||||
// Article est pas valide on retourne au tableau
|
// Si l'article n'existe pas, retour au tableau de bord
|
||||||
if (!$article) {
|
if (!$article) {
|
||||||
header('Location: dashboard.php');
|
header('Location: board.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
$titre = $article['titre'];
|
$titre = $article['titre'];
|
||||||
$contenu = $article['contenu'];
|
$contenu = $article['contenu'];
|
||||||
|
|
||||||
|
// Traitement du formulaire à la soumission
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$titre = trim($_POST['titre'] ?? '');
|
$titre = trim($_POST['titre'] ?? '');
|
||||||
$contenu = trim($_POST['contenu'] ?? '');
|
$contenu = trim($_POST['contenu'] ?? '');
|
||||||
|
|
||||||
|
// Vérification des champs obligatoires
|
||||||
if ($titre === '' || $contenu === '') {
|
if ($titre === '' || $contenu === '') {
|
||||||
$errors[] = 'Tous les champs sont obligatoires.';
|
$errors[] = 'Tous les champs sont obligatoires.';
|
||||||
} else {
|
} else {
|
||||||
|
// Mise à jour sécurisée dans la base de données
|
||||||
$u = $pdo->prepare('UPDATE articles SET titre = :titre, contenu = :contenu WHERE id = :id');
|
$stmt = $pdo->prepare(
|
||||||
$u->execute([
|
'UPDATE articles SET titre = :titre, contenu = :contenu WHERE id = :id'
|
||||||
|
);
|
||||||
|
$stmt->execute([
|
||||||
':titre' => $titre,
|
':titre' => $titre,
|
||||||
':contenu' => $contenu,
|
':contenu' => $contenu,
|
||||||
':id' => $id
|
':id' => $id
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Redirection vers le tableau de bord après modification
|
||||||
header('Location: dashboard.php');
|
header('Location: board.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
@@ -67,21 +67,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
<h1>Modifier l'article</h1>
|
<h1>Modifier l'article</h1>
|
||||||
|
|
||||||
|
<!-- Affichage des erreurs -->
|
||||||
<?php foreach ($errors as $e): ?>
|
<?php foreach ($errors as $e): ?>
|
||||||
<p class="error"><?= htmlspecialchars($e) ?></p>
|
<p class="error"><?= htmlspecialchars($e) ?></p>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
>
|
<!-- Formulaire de modification -->
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<label>Un Titre Quoi<br>
|
<label>Titre<br>
|
||||||
<input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required>
|
<input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required>
|
||||||
</label><br>
|
</label>
|
||||||
|
|
||||||
<label>Contenu<br>
|
<label>Contenu<br>
|
||||||
<textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea>
|
<textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea>
|
||||||
</label><br>
|
</label>
|
||||||
|
|
||||||
<button type="submit">Enregistrer</button>
|
<button type="submit">Enregistrer</button>
|
||||||
<a href="dashboard.php">Annuler</a>
|
<a href="board.php">Annuler</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -1,46 +1,46 @@
|
|||||||
<?php
|
<?php
|
||||||
// Page pour supprimer un article
|
// Page pour supprimer un article existant
|
||||||
|
|
||||||
|
|
||||||
require '../include/db.php';
|
require '../include/db.php';
|
||||||
require '../include/auth.php';
|
require '../include/auth.php';
|
||||||
requireLogin();
|
|
||||||
|
requireLogin(); // Vérifie que l'utilisateur est connecté
|
||||||
|
|
||||||
// Récupération de l'id de l'article depuis l'URL
|
// Récupération de l'id de l'article depuis l'URL
|
||||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||||
|
|
||||||
// Si l'id n'est pas valide, retour au tableau
|
// Si l'id n'est pas valide, redirection vers le tableau de bord
|
||||||
if ($id <= 0) {
|
if ($id <= 0) {
|
||||||
header('Location: board.php');
|
header('Location: board.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupérer le titre de l'article pour l'afficher
|
// Récupération du titre de l'article pour l'affichage
|
||||||
$stmt = $pdo->prepare('SELECT id, titre FROM articles WHERE id = :id');
|
$stmt = $pdo->prepare('SELECT id, titre FROM articles WHERE id = :id');
|
||||||
$stmt->execute([':id' => $id]);
|
$stmt->execute([':id' => $id]);
|
||||||
$article = $stmt->fetch();
|
$article = $stmt->fetch();
|
||||||
|
|
||||||
|
// Si l'article n'existe pas, retour au tableau de bord
|
||||||
if (!$article) {
|
if (!$article) {
|
||||||
header('Location: board.php');
|
header('Location: board.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Traitement de la suppression
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
if (isset($_POST['confirm']) && $_POST['confirm'] === 'yes') {
|
if (isset($_POST['confirm']) && $_POST['confirm'] === 'yes') {
|
||||||
|
// Suppression sécurisée de l'article
|
||||||
$d = $pdo->prepare('DELETE FROM articles WHERE id = :id');
|
$stmt = $pdo->prepare('DELETE FROM articles WHERE id = :id');
|
||||||
$d->execute([':id' => $id]);
|
$stmt->execute([':id' => $id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Redirection après suppression ou annulation
|
||||||
header('Location: board.php');
|
header('Location: board.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
@@ -51,14 +51,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
|
|
||||||
<h1>Supprimer l'article</h1>
|
<h1>Supprimer l'article</h1>
|
||||||
|
|
||||||
|
<!-- Confirmation de suppression -->
|
||||||
<p>Êtes-vous sûr de vouloir supprimer : <strong><?= htmlspecialchars($article['titre']) ?></strong> ?</p>
|
<p>Êtes-vous sûr de vouloir supprimer : <strong><?= htmlspecialchars($article['titre']) ?></strong> ?</p>
|
||||||
|
|
||||||
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<button type="submit" name="confirm" value="yes">Oui</button>
|
<button type="submit" name="confirm" value="yes">Oui</button>
|
||||||
<a href="dashboard.php">Annuler</a>
|
<a href="board.php">Annuler</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// Page d'accueil affichant les 10 derniers articles
|
||||||
|
|
||||||
include 'include/db.php';
|
include 'include/db.php';
|
||||||
|
|
||||||
|
// Récupération des 10 derniers articles, triés par date décroissante
|
||||||
$sql = "SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10";
|
$sql = "SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10";
|
||||||
$result = $pdo->query($sql);
|
$result = $pdo->query($sql);
|
||||||
$articles = $result->fetchAll();
|
$articles = $result->fetchAll();
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!-- Page Principal -->
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<html lang="fr">
|
||||||
<head>
|
<head>
|
||||||
@@ -17,8 +19,9 @@ $articles = $result->fetchAll();
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<header>
|
<header>
|
||||||
|
<!-- Menu de navigation -->
|
||||||
<nav>
|
<nav>
|
||||||
<a href="index.php">Un Accueil qui Accueil</a> |
|
<a href="index.php">Accueil</a> |
|
||||||
<a href="admin/connexion.php">Administration</a>
|
<a href="admin/connexion.php">Administration</a>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
@@ -26,24 +29,26 @@ $articles = $result->fetchAll();
|
|||||||
<main>
|
<main>
|
||||||
<h1>Articles Publiés</h1>
|
<h1>Articles Publiés</h1>
|
||||||
|
|
||||||
<?php
|
<?php if (count($articles) === 0): ?>
|
||||||
if (count($articles) == 0) {
|
<p>Aucun article trouvé pour le moment.</p>
|
||||||
echo "<p>Aucun article trouvé pour le moment.</p>";
|
<?php else: ?>
|
||||||
} else {
|
<?php foreach ($articles as $a): ?>
|
||||||
foreach ($articles as $a) {
|
<article>
|
||||||
echo "<article>";
|
<h2>
|
||||||
echo "<h2><a href='article.php?id=" . $a['id'] . "'>" . htmlspecialchars($a['titre']) . "</a></h2>";
|
<a href="article.php?id=<?= $a['id'] ?>">
|
||||||
echo "<small>Publie le " . date("d/m/Y", strtotime($a['date_creation'])) . "</small>";
|
<?= htmlspecialchars($a['titre']) ?>
|
||||||
echo "<p>" . substr(htmlspecialchars($a['contenu']), 0, 200) . "...</p>";
|
</a>
|
||||||
echo "<p><a href='article.php?id=" . $a['id'] . "'>Lire la suite</a></p>";
|
</h2>
|
||||||
echo "</article>";
|
<small>Publié le <?= date("d/m/Y", strtotime($a['date_creation'])) ?></small>
|
||||||
}
|
<p><?= htmlspecialchars(substr($a['contenu'], 0, 200)) ?>...</p>
|
||||||
}
|
<p><a href="article.php?id=<?= $a['id'] ?>">Lire la suite</a></p>
|
||||||
?>
|
</article>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
<p>© <?php echo date("Y"); ?> - Un CMS simple et efficace</p>
|
<p>© <?= date("Y") ?> - Un CMS simple et efficace</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user