first commit
This commit is contained in:
14
README.md
Normal file
14
README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# CMS Simplifié - Mini-Projet Développement Web
|
||||
|
||||
## 1. Installation
|
||||
|
||||
1. Installer un serveur local (XAMPP, WAMP, MAMP ou autre).
|
||||
2. Copier le dossier du projet `Visual_DM` dans le répertoire `htdocs` (ou équivalent).
|
||||
3. Créer la base de données et les tables via le fichier SQL fourni :
|
||||
- Importer `dump_cms_simplifie.sql` dans phpMyAdmin ou via ligne de commande.
|
||||
4. Vérifier le fichier `includes/db.php` et adapter les informations de connexion si nécessaire :
|
||||
```php
|
||||
$host = 'localhost';
|
||||
$dbname = 'cms_simplifie';
|
||||
$user = 'root';
|
||||
$password = '';
|
||||
49
admin/add_article.php
Normal file
49
admin/add_article.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$message = '';
|
||||
|
||||
if (isset($_POST['titre']) && isset($_POST['contenu'])) {
|
||||
$titre = $_POST['titre'];
|
||||
$contenu = $_POST['contenu'];
|
||||
|
||||
$sql = "INSERT INTO articles (titre, contenu, date_creation) VALUES (:titre, :contenu, NOW())";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(':titre', $titre);
|
||||
$stmt->bindParam(':contenu', $contenu);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$message = "Article ajouté avec succès !";
|
||||
} else {
|
||||
$message = "Erreur lors de l'ajout de l'article.";
|
||||
}
|
||||
}
|
||||
|
||||
require '../includes/header.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<h2>Ajouter un article</h2>
|
||||
|
||||
<?php if($message) echo '<p>'.$message.'</p>'; ?>
|
||||
|
||||
<form method="POST">
|
||||
<label>Titre :</label><br>
|
||||
<input type="text" name="titre" required><br><br>
|
||||
|
||||
<label>Contenu :</label><br>
|
||||
<textarea name="contenu" rows="10" cols="50" required></textarea><br><br>
|
||||
|
||||
<button type="submit">Ajouter</button>
|
||||
</form>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
require '../includes/footer.php';
|
||||
?>
|
||||
27
admin/dashboard.php
Normal file
27
admin/dashboard.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
require '../includes/header.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<h2>Tableau de bord</h2>
|
||||
<p>Bienvenue, <?= htmlspecialchars($_SESSION['user_login']); ?> !</p>
|
||||
|
||||
<ul>
|
||||
<li><a href="add_article.php">Ajouter un article</a></li>
|
||||
<li><a href="edit_article.php">Modifier un article</a></li>
|
||||
<li><a href="delete_article.php">Supprimer un article</a></li>
|
||||
<li><a href="logout.php">Se déconnecter</a></li>
|
||||
</ul>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
require '../includes/footer.php';
|
||||
?>
|
||||
61
admin/delete_article.php
Normal file
61
admin/delete_article.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$message = '';
|
||||
$article = null;
|
||||
|
||||
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "SELECT * FROM articles WHERE id = :id";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$article) {
|
||||
die("Article introuvable.");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['confirm']) && $_POST['confirm'] === 'Oui') {
|
||||
$sql = "DELETE FROM articles WHERE id = :id";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$message = "Article supprimé avec succès !";
|
||||
$article = null;
|
||||
} else {
|
||||
$message = "Erreur lors de la suppression.";
|
||||
}
|
||||
}
|
||||
|
||||
require '../includes/header.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<h2>Supprimer un article</h2>
|
||||
|
||||
<?php if($message) echo '<p>'.$message.'</p>'; ?>
|
||||
|
||||
<?php if($article): ?>
|
||||
<p>Voulez-vous vraiment supprimer l'article : "<strong><?= htmlspecialchars($article['titre']) ?></strong>" ?</p>
|
||||
<form method="POST">
|
||||
<button type="submit" name="confirm" value="Oui">Oui</button>
|
||||
<button type="submit" name="confirm" value="Non">Non</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<p>Aucun article sélectionné ou article déjà supprimé.</p>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
require '../includes/footer.php';
|
||||
?>
|
||||
73
admin/edit_article.php
Normal file
73
admin/edit_article.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
session_start();
|
||||
require '../includes/db.php';
|
||||
|
||||
if (!isset($_SESSION['user_id'])) {
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$message = '';
|
||||
$article = null;
|
||||
|
||||
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "SELECT * FROM articles WHERE id = :id";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$article) {
|
||||
die("Article introuvable.");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['titre']) && isset($_POST['contenu'])) {
|
||||
$titre = $_POST['titre'];
|
||||
$contenu = $_POST['contenu'];
|
||||
|
||||
$sql = "UPDATE articles SET titre = :titre, contenu = :contenu WHERE id = :id";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(':titre', $titre);
|
||||
$stmt->bindParam(':contenu', $contenu);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$message = "Article modifié avec succès !";
|
||||
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = :id");
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
} else {
|
||||
$message = "Erreur lors de la modification.";
|
||||
}
|
||||
}
|
||||
|
||||
require '../includes/header.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<h2>Modifier un article</h2>
|
||||
|
||||
<?php if($message) echo '<p>'.$message.'</p>'; ?>
|
||||
|
||||
<?php if($article): ?>
|
||||
<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="10" cols="50" required><?= htmlspecialchars($article['contenu']) ?></textarea><br><br>
|
||||
|
||||
<button type="submit">Modifier</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<p>Aucun article sélectionné.</p>
|
||||
<?php endif; ?>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
require '../includes/footer.php';
|
||||
?>
|
||||
47
admin/login.php
Normal file
47
admin/login.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
require '../includes/db.php';
|
||||
|
||||
if (isset($_POST['login']) && isset($_POST['password'])) {
|
||||
$login = $_POST['login'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
$sql = "SELECT * FROM utilisateur WHERE login = :login";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(':login', $login);
|
||||
$stmt->execute();
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['user_login'] = $user['login'];
|
||||
header('Location: dashboard.php');
|
||||
exit;
|
||||
} else {
|
||||
$error = "Identifiants incorrects.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Connexion Admin</title>
|
||||
<link rel="stylesheet" href="../assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h2>Connexion Administration</h2>
|
||||
|
||||
<?php if(isset($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>
|
||||
<button type="submit">Se connecter</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
10
admin/logout.php
Normal file
10
admin/logout.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
$_SESSION = [];
|
||||
|
||||
session_destroy();
|
||||
|
||||
header('Location: login.php');
|
||||
exit;
|
||||
?>
|
||||
56
assets/css/style.css
Normal file
56
assets/css/style.css
Normal file
@@ -0,0 +1,56 @@
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-color: #f4f4f4;
|
||||
}
|
||||
|
||||
header, footer {
|
||||
background-color: #333;
|
||||
color: white;
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
main {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: #333;
|
||||
}
|
||||
|
||||
article {
|
||||
background-color: white;
|
||||
padding: 15px;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #007BFF;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
form input, form textarea, form button {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
margin-top: 5px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #007BFF;
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
23
dump_cms_simplifie.sql
Normal file
23
dump_cms_simplifie.sql
Normal file
@@ -0,0 +1,23 @@
|
||||
CREATE DATABASE IF NOT EXISTS cms_simplifie;
|
||||
USE cms_simplifie;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS utilisateur (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
login VARCHAR(50) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO utilisateur (login, password)
|
||||
VALUES ('admin', '$2y$10$e0NR8I0sXfJ3R6qU5K4J6.u4TbT2H8bX6u5pL1lN3eWz8yFzNfR9O');
|
||||
|
||||
CREATE TABLE IF NOT EXISTS articles (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
titre VARCHAR(255) NOT NULL,
|
||||
contenu TEXT NOT NULL,
|
||||
date_creation DATETIME NOT NULL
|
||||
);
|
||||
|
||||
INSERT INTO articles (titre, contenu, date_creation)
|
||||
VALUES
|
||||
('Titre Exemple 1', 'Voici un texte d’introduction pour l’article 1...', NOW()),
|
||||
('Titre Exemple 2', 'Voici un texte d’introduction pour l’article 2...', NOW());
|
||||
16
includes/db.php
Normal file
16
includes/db.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
$host = 'localhost';
|
||||
$dbname = 'cms_simplifie';
|
||||
$username = 'root';
|
||||
$password = '';
|
||||
|
||||
try {
|
||||
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
|
||||
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Erreur de connexion à la base de données : " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
6
includes/footer.php
Normal file
6
includes/footer.php
Normal file
@@ -0,0 +1,6 @@
|
||||
</main>
|
||||
<footer>
|
||||
<p>© <?= date('Y') ?> - CMS Simplifié</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
16
includes/header.php
Normal file
16
includes/header.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CMS Simplifié</title>
|
||||
<link rel="stylesheet" href="../assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1>Mon CMS Simplifié</h1>
|
||||
<nav>
|
||||
<a href="../public/index.php">Accueil</a>
|
||||
<a href="../admin/login.php">Administration</a>
|
||||
</nav>
|
||||
</header>
|
||||
<main>
|
||||
13
public/404.php
Normal file
13
public/404.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
require '../includes/header.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<h2>Erreur 404</h2>
|
||||
<p>La page que vous recherchez n’existe pas.</p>
|
||||
<p><a href="index.php">Retour à l’accueil</a></p>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
require '../includes/footer.php';
|
||||
?>
|
||||
28
public/article.php
Normal file
28
public/article.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
require '../includes/header.php';
|
||||
require '../includes/db.php';
|
||||
|
||||
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$sql = "SELECT * FROM articles WHERE id = :id";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
|
||||
$stmt->execute();
|
||||
$article = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($article) {
|
||||
echo "<main>";
|
||||
echo "<h2>" . htmlspecialchars($article['titre']) . "</h2>";
|
||||
echo "<p><em>Publié le " . htmlspecialchars($article['date_creation']) . "</em></p>";
|
||||
echo "<div>" . nl2br(htmlspecialchars($article['contenu'])) . "</div>";
|
||||
echo "</main>";
|
||||
} else {
|
||||
require '404.php';
|
||||
}
|
||||
} else {
|
||||
require '404.php';
|
||||
}
|
||||
|
||||
require '../includes/footer.php';
|
||||
?>
|
||||
32
public/index.php
Normal file
32
public/index.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
include 'includes/header.php';
|
||||
|
||||
include 'includes/db.php';
|
||||
?>
|
||||
|
||||
<main>
|
||||
<h2>Derniers articles</h2>
|
||||
|
||||
<?php
|
||||
$sql = "SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$articles = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($articles) {
|
||||
foreach ($articles as $article) {
|
||||
echo '<article>';
|
||||
echo '<h3>' . htmlspecialchars($article['titre']) . '</h3>';
|
||||
echo '<p>' . substr(htmlspecialchars($article['contenu']), 0, 100) . '...</p>';
|
||||
echo '<a href="article.php?id=' . $article['id'] . '">Lire la suite</a>';
|
||||
echo '</article><hr>';
|
||||
}
|
||||
} else {
|
||||
echo "<p>Aucun article publié pour le moment.</p>";
|
||||
}
|
||||
?>
|
||||
</main>
|
||||
|
||||
<?php
|
||||
include 'includes/footer.php';
|
||||
?>
|
||||
Reference in New Issue
Block a user