Premier commit
This commit is contained in:
26
article.php
Normal file
26
article.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
require_once __DIR__ . '/includes/header.php';
|
||||||
|
|
||||||
|
if (!isset($_GET['id'])) {
|
||||||
|
http_response_code(404);
|
||||||
|
echo "<h2>404 - Article non trouvé</h2>";
|
||||||
|
require_once __DIR__ . '/includes/footer.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = (int) $_GET['id'];
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id = ?");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
$article = $stmt->fetch();
|
||||||
|
|
||||||
|
if (!$article) {
|
||||||
|
http_response_code(404);
|
||||||
|
echo "<h2>404 - Article non trouvé</h2>";
|
||||||
|
} else {
|
||||||
|
echo "<h2>{$article['titre']}</h2>";
|
||||||
|
echo "<p>{$article['contenu']}</p>";
|
||||||
|
echo "<small>Publié le {$article['date_creation']}</small>";
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once __DIR__ . '/includes/footer.php';
|
||||||
22
css/style.css
Normal file
22
css/style.css
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
margin: 40px;
|
||||||
|
background: #f9f9f9;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
header, footer {
|
||||||
|
text-align: center;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: #007bff;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
form input, form textarea {
|
||||||
|
width: 100%;
|
||||||
|
padding: 8px;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
26
dashboard.php
Normal file
26
dashboard.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
require_once __DIR__ . '/includes/header.php';
|
||||||
|
|
||||||
|
if (!isset($_SESSION['user'])) {
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "<h2>Bienvenue, {$_SESSION['user']} !</h2>";
|
||||||
|
echo "<p><a href='ajouter.php'>➕ Ajouter un article</a> | <a href='logout.php'>🚪 Déconnexion</a></p>";
|
||||||
|
|
||||||
|
$stmt = $pdo->query("SELECT * FROM articles ORDER BY date_creation DESC");
|
||||||
|
echo "<h3>Vos articles :</h3>";
|
||||||
|
echo "<ul>";
|
||||||
|
while ($row = $stmt->fetch()) {
|
||||||
|
echo "<li>
|
||||||
|
<strong>{$row['titre']}</strong>
|
||||||
|
[<a href='modifier.php?id={$row['id']}'>Modifier</a>]
|
||||||
|
[<a href='supprimer.php?id={$row['id']}'>Supprimer</a>]
|
||||||
|
</li>";
|
||||||
|
}
|
||||||
|
echo "</ul>";
|
||||||
|
|
||||||
|
require_once __DIR__ . '/includes/footer.php';
|
||||||
35
docker-compose.yaml
Normal file
35
docker-compose.yaml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: mysql:8.0
|
||||||
|
container_name: cms_db
|
||||||
|
restart: unless-stopped
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: rootpassword
|
||||||
|
MYSQL_DATABASE: cms
|
||||||
|
MYSQL_USER: cmsuser
|
||||||
|
MYSQL_PASSWORD: cmspassword
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/mysql
|
||||||
|
- ./sql:/docker-entrypoint-initdb.d:ro # exécutera les .sql à l'initialisation
|
||||||
|
ports:
|
||||||
|
- "3306:3306"
|
||||||
|
|
||||||
|
web:
|
||||||
|
image: php:8.2-apache
|
||||||
|
container_name: cms_web
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
volumes:
|
||||||
|
- ./src:/var/www/html
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
|
environment:
|
||||||
|
DB_HOST: db
|
||||||
|
DB_NAME: cms
|
||||||
|
DB_USER: cmsuser
|
||||||
|
DB_PASS: cmspassword
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
18
index.php
Normal file
18
index.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#<?php
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
require_once __DIR__ . '/includes/header.php';
|
||||||
|
|
||||||
|
$stmt = $pdo->query("SELECT id, titre, SUBSTRING(contenu, 1, 150) AS extrait, date_creation
|
||||||
|
FROM articles ORDER BY date_creation DESC LIMIT 10");
|
||||||
|
|
||||||
|
echo "<h2>Derniers articles</h2>";
|
||||||
|
|
||||||
|
while ($row = $stmt->fetch()) {
|
||||||
|
echo "<article>";
|
||||||
|
echo "<h3><a href='article.php?id={$row['id']}'>{$row['titre']}</a></h3>";
|
||||||
|
echo "<p>{$row['extrait']}...</p>";
|
||||||
|
echo "<small>Publié le {$row['date_creation']}</small>";
|
||||||
|
echo "</article><hr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once __DIR__ . '/includes/footer.php';
|
||||||
35
login.php
Normal file
35
login.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
require_once __DIR__ . '/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: dashboard.php");
|
||||||
|
exit;
|
||||||
|
} else {
|
||||||
|
echo "<p style='color:red;'>Identifiants incorrects</p>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h2>Connexion administrateur</h2>
|
||||||
|
<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 __DIR__ . '/includes/footer.php'; ?>
|
||||||
5
logout.php
Normal file
5
logout.php
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
session_destroy();
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
40
modifier.php
Normal file
40
modifier.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
require_once __DIR__ . '/includes/header.php';
|
||||||
|
|
||||||
|
if (!isset($_SESSION['user'])) {
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $_GET['id'] ?? null;
|
||||||
|
if (!$id) {
|
||||||
|
echo "ID manquant.";
|
||||||
|
require_once __DIR__ . '/includes/footer.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$titre = $_POST['titre'];
|
||||||
|
$contenu = $_POST['contenu'];
|
||||||
|
$stmt = $pdo->prepare("UPDATE articles SET titre=?, contenu=? WHERE id=?");
|
||||||
|
$stmt->execute([$titre, $contenu, $id]);
|
||||||
|
echo "<p>✅ Article mis à jour !</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare("SELECT * FROM articles WHERE id=?");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
$article = $stmt->fetch();
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h2>Modifier un 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="8" cols="50" required><?= htmlspecialchars($article['contenu']) ?></textarea><br><br>
|
||||||
|
<input type="submit" value="Mettre à jour">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||||
29
src/ajouter.php
Normal file
29
src/ajouter.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
require_once __DIR__ . '/includes/header.php';
|
||||||
|
|
||||||
|
if (!isset($_SESSION['user'])) {
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
$titre = $_POST['titre'];
|
||||||
|
$contenu = $_POST['contenu'];
|
||||||
|
$stmt = $pdo->prepare("INSERT INTO articles (titre, contenu, date_creation) VALUES (?, ?, NOW())");
|
||||||
|
$stmt->execute([$titre, $contenu]);
|
||||||
|
echo "<p>✅ Article ajouté !</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="8" cols="50" required></textarea><br><br>
|
||||||
|
<input type="submit" value="Publier">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||||
23
src/includes/db.php
Normal file
23
src/includes/db.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
// Connexion PDO à la base MySQL (depuis PHP exécuté sur ta machine)
|
||||||
|
|
||||||
|
$host = '127.0.0.1'; // ou 'localhost'
|
||||||
|
$port = 3306;
|
||||||
|
$db = 'cms';
|
||||||
|
$user = 'cmsuser';
|
||||||
|
$pass = 'cmspassword';
|
||||||
|
$charset = 'utf8mb4';
|
||||||
|
|
||||||
|
$dsn = "mysql:host=$host;port=$port;dbname=$db;charset=$charset";
|
||||||
|
|
||||||
|
$options = [
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$pdo = new PDO($dsn, $user, $pass, $options);
|
||||||
|
// echo "Connexion réussie !"; // tu peux tester si tu veux
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
die("Erreur de connexion : " . $e->getMessage());
|
||||||
|
}
|
||||||
6
src/includes/footer.php
Normal file
6
src/includes/footer.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<hr>
|
||||||
|
<footer>
|
||||||
|
<p>© <?= date('Y') ?> - CMS Simplifié</p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
16
src/includes/header.php
Normal file
16
src/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="css/style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>📰 CMS Simplifié</h1>
|
||||||
|
<nav>
|
||||||
|
<a href="index.php">Accueil</a> |
|
||||||
|
<a href="login.php">Admin</a>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<hr>
|
||||||
2
src/test.php
Normal file
2
src/test.php
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<?php
|
||||||
|
echo "OK, PHP tourne";
|
||||||
3
src/test_connexion.php
Normal file
3
src/test_connexion.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
echo "✅ Connexion réussie à la base CMS !";
|
||||||
22
src/test_utilisateurs.php
Normal file
22
src/test_utilisateurs.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
|
||||||
|
try {
|
||||||
|
// On récupère tous les utilisateurs
|
||||||
|
$stmt = $pdo->query("SELECT id, login FROM utilisateur");
|
||||||
|
|
||||||
|
$users = $stmt->fetchAll();
|
||||||
|
|
||||||
|
if (count($users) > 0) {
|
||||||
|
echo "<h2>👤 Liste des utilisateurs :</h2>";
|
||||||
|
echo "<ul>";
|
||||||
|
foreach ($users as $user) {
|
||||||
|
echo "<li>ID : {$user['id']} — Login : {$user['login']}</li>";
|
||||||
|
}
|
||||||
|
echo "</ul>";
|
||||||
|
} else {
|
||||||
|
echo "⚠️ Aucun utilisateur trouvé dans la table.";
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "❌ Erreur SQL : " . $e->getMessage();
|
||||||
|
}
|
||||||
34
supprimer.php
Normal file
34
supprimer.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
require_once __DIR__ . '/includes/db.php';
|
||||||
|
require_once __DIR__ . '/includes/header.php';
|
||||||
|
|
||||||
|
if (!isset($_SESSION['user'])) {
|
||||||
|
header("Location: login.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $_GET['id'] ?? null;
|
||||||
|
if (!$id) {
|
||||||
|
echo "ID manquant.";
|
||||||
|
require_once __DIR__ . '/includes/footer.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['confirm'])) {
|
||||||
|
$stmt = $pdo->prepare("DELETE FROM articles WHERE id=?");
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
echo "<p>✅ Article supprimé.</p><p><a href='dashboard.php'>Retour au tableau de bord</a></p>";
|
||||||
|
require_once __DIR__ . '/includes/footer.php';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<h2>Supprimer l’article</h2>
|
||||||
|
<p>Es-tu sûr de vouloir supprimer cet article ?</p>
|
||||||
|
<form method="post">
|
||||||
|
<input type="submit" name="confirm" value="Oui, supprimer">
|
||||||
|
<a href="dashboard.php">Annuler</a>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|
||||||
Reference in New Issue
Block a user