Téléverser les fichiers vers "admin"
This commit is contained in:
51
admin/ajouter.php
Normal file
51
admin/ajouter.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
// Vérifie BIEN que l'admin est connecté
|
||||
if (!isset($_SESSION['admin'])) {
|
||||
header('Location: connexion.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$titre = trim($_POST['titre']);
|
||||
$contenu = trim($_POST['contenu']);
|
||||
|
||||
if (!empty($titre) && !empty($contenu)) {
|
||||
$stmt = $pdo->prepare("INSERT INTO articles (titre, contenu, date_creation) VALUES (?, ?, NOW())");
|
||||
$stmt->execute([$titre, $contenu]);
|
||||
$message = "Article ajouté t'inquete";
|
||||
} else {
|
||||
$message = "Veuillez bien remplir le champs svp";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<link rel="stylesheet" href="../style.css">
|
||||
<meta charset="UTF-8">
|
||||
<title>Ajouter un article</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Ajouter un article</h2>
|
||||
<a href="tabledebord.php">← Retour au tableau de bord</a>
|
||||
<hr>
|
||||
|
||||
<form method="post">
|
||||
<label>Titre :</label><br>
|
||||
<input type="text" name="titre" required><br><br>
|
||||
|
||||
<label>Contenu :</label><br>
|
||||
<textarea name="contenu" rows="6" cols="50" required></textarea><br><br>
|
||||
|
||||
<button type="submit">Ajouter</button>
|
||||
</form>
|
||||
|
||||
<p style="color:green;"><?= $message ?></p>
|
||||
</body>
|
||||
</html>
|
||||
41
admin/connexion.php
Normal file
41
admin/connexion.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$login = trim($_POST['login']);
|
||||
$password = trim($_POST['password']);
|
||||
|
||||
$stmt = $pdo->prepare("SELECT * FROM utilisateur WHERE login = ?");
|
||||
$stmt->execute([$login]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['admin'] = $user['login'];
|
||||
header('Location: tabledebord.php');
|
||||
exit;
|
||||
} else {
|
||||
$message = "Identifiants incorrects";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<link rel="stylesheet" href="../style.css">
|
||||
<meta charset="UTF-8">
|
||||
<title>Connexion Administrateur</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Connexion Administrateur</h2>
|
||||
<form method="post">
|
||||
<input type="text" name="login" placeholder="Login" required><br><br>
|
||||
<input type="password" name="password" placeholder="Mot de passe" required><br><br>
|
||||
<button type="submit">Se connecter</button>
|
||||
</form>
|
||||
<p style="color:red;"><?= htmlentities($message) ?></p>
|
||||
</body>
|
||||
</html>
|
||||
64
admin/modifier.php
Normal file
64
admin/modifier.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
if (!isset($_SESSION['admin'])) {
|
||||
header('Location: connexion.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) {
|
||||
header('Location: tabledebord.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Récupère modifié//
|
||||
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$article = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$article) {
|
||||
die("Article introuvable !");
|
||||
}
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$titre = trim($_POST['titre']);
|
||||
$contenu = trim($_POST['contenu']);
|
||||
|
||||
if (!empty($titre) && !empty($contenu)) {
|
||||
$update = $pdo->prepare("UPDATE articles SET titre = ?, contenu = ? WHERE id = ?");
|
||||
$update->execute([$titre, $contenu, $id]);
|
||||
$message = "Article modifié";
|
||||
} else {
|
||||
$message = "Tous les champs sont obligatoires.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Modifier un article</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Modifier l’article</h2>
|
||||
<a href="tabledebord.php">← Retour</a>
|
||||
<hr>
|
||||
|
||||
<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="6" cols="50" required><?= htmlspecialchars($article['contenu']) ?></textarea><br><br>
|
||||
|
||||
<button type="submit">Enregistrer les modifications</button>
|
||||
</form>
|
||||
|
||||
<p style="color:green;"><?= $message ?></p>
|
||||
</body>
|
||||
</html>
|
||||
18
admin/supprimer.php
Normal file
18
admin/supprimer.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
if (!isset($_SESSION['admin'])) {
|
||||
header('Location: connexion.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = $_GET['id'] ?? null;
|
||||
if ($id) {
|
||||
$stmt = $pdo->prepare("DELETE FROM articles WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
}
|
||||
|
||||
header('Location: tabledebord.php');
|
||||
exit;
|
||||
?>
|
||||
45
admin/tabledebord.php
Normal file
45
admin/tabledebord.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
// Vérifie que l'admin est connecté
|
||||
if (!isset($_SESSION['admin'])) {
|
||||
header('Location: connexion.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
// recupere tout les articles
|
||||
$stmt = $pdo->query("SELECT * FROM articles ORDER BY date_creation DESC");
|
||||
$articles = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<link rel="stylesheet" href="../style.css">
|
||||
<meta charset="UTF-8">
|
||||
<title>Tableau de bord</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Bienvenue, <?= $_SESSION['admin'] ?> 👋</h2>
|
||||
<a href="ajouter.php">➕ Ajouter un article</a> |
|
||||
<a href="deconnexion.php">🚪 Se déconnecter</a>
|
||||
<hr>
|
||||
|
||||
<h3>Liste des articles</h3>
|
||||
<table border="1" cellpadding="5">
|
||||
<tr><th>ID</th><th>Titre</th><th>Date</th><th>Actions</th></tr>
|
||||
<?php foreach ($articles as $a): ?>
|
||||
<tr>
|
||||
<td><?= $a['id'] ?></td>
|
||||
<td><?= htmlspecialchars($a['titre']) ?></td>
|
||||
<td><?= $a['date_creation'] ?></td>
|
||||
<td>
|
||||
<a href="modifier.php?id=<?= $a['id'] ?>">Modifier</a> |
|
||||
<a href="supprimer.php?id=<?= $a['id'] ?>">Supprimer</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user