first commit
This commit is contained in:
59
admin/add.php
Normal file
59
admin/add.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
requireLogin();
|
||||
|
||||
$errors = [];
|
||||
$titre = '';
|
||||
$contenu = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$titre = trim($_POST['titre'] ?? '');
|
||||
$contenu = trim($_POST['contenu'] ?? '');
|
||||
|
||||
if ($titre === '' || $contenu === '') {
|
||||
$errors[] = 'Tous les champs sont obligatoires.';
|
||||
} else {
|
||||
$stmt = $pdo->prepare('INSERT INTO articles (titre, contenu, date_creation) VALUES (:titre, :contenu, :date)');
|
||||
$stmt->execute([
|
||||
':titre' => $titre,
|
||||
':contenu' => $contenu,
|
||||
':date' => date('Y-m-d H:i:s'),
|
||||
]);
|
||||
header('Location:board.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ajouter un article</title>
|
||||
<link rel="stylesheet" href="../assets/add.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Ajouter un article</h1>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<?php foreach ($errors as $e): ?>
|
||||
<p class="error"><?= htmlspecialchars($e) ?></p>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<form method="post">
|
||||
<label>Titre
|
||||
<input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required>
|
||||
</label>
|
||||
<label>Contenu
|
||||
<textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea>
|
||||
</label>
|
||||
<div style="display:flex; gap:10px; justify-content:center;">
|
||||
<button type="submit">Publier</button>
|
||||
<a href="board.php">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
42
admin/board.php
Normal file
42
admin/board.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
requireLogin();
|
||||
$stmt = $pdo->query('SELECT * FROM articles ORDER BY date_creation DESC');
|
||||
$articles = $stmt->fetchAll();
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head><meta charset="UTF-8"><title>Admin - Tableau de bord</title></head>
|
||||
<link rel="stylesheet" href="../assets/board.css">
|
||||
<body>
|
||||
<header>
|
||||
<h1>Tableau de bord</h1>
|
||||
<div class="header-buttons">
|
||||
<a href="add.php" class="btn">Ajouter un article</a>
|
||||
<a href="logout.php" class="btn">Se déconnecter</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<table>
|
||||
<tr><th>ID</th><th>Titre</th><th>Actions</th></tr>
|
||||
<?php foreach ($articles as $a): ?>
|
||||
<tr>
|
||||
<td><?= $a['id'] ?></td>
|
||||
<td><?= htmlspecialchars($a['titre']) ?></td>
|
||||
<td>
|
||||
<a href="modif.php?id=<?= $a['id'] ?>" class="btn">Modifier</a>
|
||||
<a href="delete.php?id=<?= $a['id'] ?>" class="btn">Supprimer</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<p>© <?= date('Y') ?> CMS. Tous droits réservés par Abd'R.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
54
admin/delete.php
Normal file
54
admin/delete.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
requireLogin();
|
||||
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
header('Location:board.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare('SELECT id, titre FROM articles WHERE id = :id');
|
||||
$stmt->execute([':id' => $id]);
|
||||
$article = $stmt->fetch();
|
||||
if (!$article) {
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (isset($_POST['confirm']) && $_POST['confirm'] === 'yes') {
|
||||
$d = $pdo->prepare('DELETE FROM articles WHERE id = :id');
|
||||
$d->execute([':id' => $id]);
|
||||
}
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Supprimer l'article</title>
|
||||
<link rel="stylesheet" href="../assets/delete.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>Supprimer l'article</header>
|
||||
|
||||
<main>
|
||||
<p>Êtes-vous sûr de vouloir supprimer : <strong><?= htmlspecialchars($article['titre']) ?></strong> ?</p>
|
||||
<form method="post">
|
||||
<div class="form-buttons">
|
||||
<button type="submit" name="confirm" value="yes">Oui, supprimer</button>
|
||||
<a href="board.php" class="btn">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
38
admin/login.php
Normal file
38
admin/login.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
|
||||
$error = '';
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if (checkLogin($pdo, $_POST['login'], $_POST['password'])) {
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
} else {
|
||||
$error = 'Identifiants incorrects';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Connexion</title>
|
||||
<link rel="stylesheet" href="../assets/login.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav>
|
||||
<a href="../index.php">Accueil</a>
|
||||
</nav>
|
||||
<main>
|
||||
<h1>Connexion</h1>
|
||||
<form method="post">
|
||||
<input type="text" name="login" placeholder="Login" required><br>
|
||||
<input type="password" name="password" placeholder="Mot de passe" required><br>
|
||||
<button type="submit">Se connecter</button>
|
||||
</form>
|
||||
</main>
|
||||
<p class="error"><?= $error ?></p>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
19
admin/logout.php
Normal file
19
admin/logout.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require '../include/authenticator.php';
|
||||
|
||||
$_SESSION = [];
|
||||
|
||||
if (!function_exists('logout_user')) {
|
||||
$_SESSION = [];
|
||||
if (ini_get('session.use_cookies')) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000,
|
||||
$params['path'], $params['domain'], $params['secure'], $params['httponly']);
|
||||
}
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
header('Location: ../index.php');
|
||||
exit;
|
||||
?>
|
||||
|
||||
73
admin/modif.php
Normal file
73
admin/modif.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
global $pdo;
|
||||
require '../include/db.php';
|
||||
require '../include/authenticator.php';
|
||||
requireLogin();
|
||||
|
||||
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
||||
if ($id <= 0) {
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare('SELECT * FROM articles WHERE id = :id');
|
||||
$stmt->execute([':id' => $id]);
|
||||
$article = $stmt->fetch();
|
||||
if (!$article) {
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
$titre = $article['titre'];
|
||||
$contenu = $article['contenu'];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$titre = trim($_POST['titre'] ?? '');
|
||||
$contenu = trim($_POST['contenu'] ?? '');
|
||||
if ($titre === '' || $contenu === '') {
|
||||
$errors[] = 'Tous les champs sont obligatoires.';
|
||||
} else {
|
||||
$u = $pdo->prepare('UPDATE articles SET titre = :titre, contenu = :contenu WHERE id = :id');
|
||||
$u->execute([':titre' => $titre, ':contenu' => $contenu, ':id' => $id]);
|
||||
header('Location: board.php');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Modifier l'article</title>
|
||||
<link rel="stylesheet" href="../assets/modif.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>Modifier l'article</header>
|
||||
|
||||
<section class="form-section">
|
||||
<main>
|
||||
<?php foreach ($errors as $e): ?>
|
||||
<p class="error"><?= htmlspecialchars($e) ?></p>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<form method="post">
|
||||
<label>Titre
|
||||
<input type="text" name="titre" value="<?= htmlspecialchars($titre) ?>" required>
|
||||
</label>
|
||||
<label>Contenu
|
||||
<textarea name="contenu" rows="10" required><?= htmlspecialchars($contenu) ?></textarea>
|
||||
</label>
|
||||
<div class="form-buttons">
|
||||
<button type="submit">Enregistrer</button>
|
||||
<a href="board.php" class="btn">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user