Nouvelle version complète (remplacement total)
This commit is contained in:
BIN
public/.DS_Store
vendored
Normal file
BIN
public/.DS_Store
vendored
Normal file
Binary file not shown.
34
public/add.php
Normal file
34
public/add.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../includes/db.php';
|
||||
require_once '../includes/header.php';
|
||||
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$titre = $_POST['titre'] ?? '';
|
||||
$contenu = $_POST['contenu'] ?? '';
|
||||
|
||||
if ($titre && $contenu) {
|
||||
$stmt = $pdo->prepare("INSERT INTO articles (titre, contenu, date_creation) VALUES (?, ?, NOW())");
|
||||
$stmt->execute([$titre, $contenu]);
|
||||
echo "<p>Article ajouté avec succès.</p>";
|
||||
} else {
|
||||
echo "<p style='color:red;'>Veuillez remplir tous les champs.</p>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>Ajouter un article</h2>
|
||||
<form method="post">
|
||||
<label>Titre :</label><br>
|
||||
<input type="text" name="titre" required><br><br>
|
||||
<label>Contenu :</label><br>
|
||||
<textarea name="contenu" rows="5" required></textarea><br><br>
|
||||
<input type="submit" value="Ajouter">
|
||||
</form>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
22
public/admin.php
Normal file
22
public/admin.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../includes/db.php';
|
||||
require_once '../includes/header.php';
|
||||
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>Tableau de bord</h2>
|
||||
<p>Bienvenue, <?= htmlspecialchars($_SESSION['user']) ?> !</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="add.php">Ajouter un article</a></li>
|
||||
<li><a href="edit.php">Modifier un article</a></li>
|
||||
<li><a href="delete.php">Supprimer un article</a></li>
|
||||
<li><a href="index.php">Voir les articles</a></li>
|
||||
</ul>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
30
public/article.php
Normal file
30
public/article.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
require_once '../includes/db.php';
|
||||
require_once '../includes/header.php';
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
|
||||
if (!$id || !is_numeric($id)) {
|
||||
echo "<p>Article introuvable (404)</p>";
|
||||
require_once '../includes/footer.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$article = $stmt->fetch();
|
||||
|
||||
if (!$article) {
|
||||
echo "<p>Article introuvable (404)</p>";
|
||||
require_once '../includes/footer.php';
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<article>
|
||||
<h2><?= htmlspecialchars($article['titre']) ?></h2>
|
||||
<p><?= nl2br(htmlspecialchars($article['contenu'])) ?></p>
|
||||
<small>Publié le <?= $article['date_creation'] ?></small>
|
||||
</article>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
|
||||
50
public/edit.php
Normal file
50
public/edit.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../includes/db.php';
|
||||
require_once '../includes/header.php';
|
||||
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id || !is_numeric($id)) {
|
||||
echo "<p>Article introuvable (404)</p>";
|
||||
require_once '../includes/footer.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$article = $stmt->fetch();
|
||||
|
||||
if (!$article) {
|
||||
echo "<p>Article introuvable (404)</p>";
|
||||
require_once '../includes/footer.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$titre = $_POST['titre'] ?? '';
|
||||
$contenu = $_POST['contenu'] ?? '';
|
||||
if ($titre && $contenu) {
|
||||
$stmt = $pdo->prepare("UPDATE articles SET titre=?, contenu=? WHERE id=?");
|
||||
$stmt->execute([$titre, $contenu, $id]);
|
||||
echo "<p>Article mis à jour avec succès.</p>";
|
||||
} else {
|
||||
echo "<p style='color:red;'>Veuillez remplir tous les champs.</p>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>Modifier l'article</h2>
|
||||
<form method="post">
|
||||
<label>Titre :</label><br>
|
||||
<input type="text" name="titre" value="<?= htmlspecialchars($article['titre']) ?>" required><br><br>
|
||||
<label>Contenu :</label><br>
|
||||
<textarea name="contenu" rows="5" required><?= htmlspecialchars($article['contenu']) ?></textarea><br><br>
|
||||
<input type="submit" value="Modifier">
|
||||
</form>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
34
public/login.php
Normal file
34
public/login.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../includes/db.php';
|
||||
require_once '../includes/header.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$login = $_POST['login'] ?? '';
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM utilisateur WHERE login = ?");
|
||||
$stmt->execute([$login]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['user'] = $user['login'];
|
||||
header("Location: admin.php");
|
||||
exit;
|
||||
} else {
|
||||
$error = "Identifiants incorrects";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<h2>Connexion administrateur</h2>
|
||||
<?php if (!empty($error)) echo "<p style='color:red;'>$error</p>"; ?>
|
||||
<form method="post">
|
||||
<label>Login :</label><br>
|
||||
<input type="text" name="login" required><br><br>
|
||||
<label>Mot de passe :</label><br>
|
||||
<input type="password" name="password" required><br><br>
|
||||
<input type="submit" value="Se connecter">
|
||||
</form>
|
||||
|
||||
<?php require_once '../includes/footer.php'; ?>
|
||||
7
public/logout.php
Normal file
7
public/logout.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header("Location: login.php");
|
||||
exit;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user