commit a32bed95dc9050e0a4276eda74030bd61a8ac715 Author: younes.ouaz Date: Sat Nov 1 21:47:32 2025 +0100 Initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ac3211e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM php:8.2-apache +LABEL authors="youyou" + +COPY . /var/www/html +WORKDIR /var/www/html + +RUN docker-php-ext-install pdo pdo_mysql + +EXPOSE 80 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..d555b9f --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# Projet CMS Simplifié + +### Technologies utilisées + +Ce projet a été construit avec les technologies suivantes : + +![HTML5](https://img.shields.io/badge/HTML5-E34F26?style=for-the-badge&logo=html5&logoColor=white) +![CSS3](https://img.shields.io/badge/CSS3-1572B6?style=for-the-badge&logo=css3&logoColor=white) +![PHP](https://img.shields.io/badge/PHP-777BB4?style=for-the-badge&logo=php&logoColor=white) +![MySQL](https://img.shields.io/badge/MySQL-4479A1?style=for-the-badge&logo=mysql&logoColor=white) + +## Lancement des dockers MySql et Php + +### Création d'un réseau pour que les services docker puissent communiquer + +```bash +docker network create -d bridge CMS-bridge +``` + +### Build BDD + +Builder la BDD MySql avec le Dockerfile présent dans le répertoire bdd + +```bash +docker build -t cms_mysql . +``` + +Lancer l'image créée en le connectant au réseau précédemment créé + +```bash +docker run -d --name CMS_mysql -p 3306:3306 --network=CMS-bridge cms_mysql:latest +``` + +### Build PHP-Apache + +Builder PHP Apache avec le Dockerfile présent à la racine du projet + +```bash +docker build -t cms_php . +``` + +Lancer l'image créée en le connectant au réseau précédemment créé + +```bash +docker run -d --name CMS_php -p 8080:80 --network=CMS-bridge cms_php:latest +``` + +Pour éviter de lancer les commandes à chaque fois, un script launch-dockers.sh a executer en 'sudo' est disponible. + + + + diff --git a/admin/add.php b/admin/add.php new file mode 100644 index 0000000..aa11be8 --- /dev/null +++ b/admin/add.php @@ -0,0 +1,47 @@ +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; + } +} +?> + + + + + Ajouter un article + + + +

Ajouter un article

+ +

+ +
+
+
+ + Annuler +
+ + \ No newline at end of file diff --git a/admin/board.php b/admin/board.php new file mode 100644 index 0000000..de18238 --- /dev/null +++ b/admin/board.php @@ -0,0 +1,28 @@ +query('SELECT * FROM articles ORDER BY date_creation DESC'); +$articles = $stmt->fetchAll(); +?> + + +Admin - Tableau de bord + +

Tableau de bord

+Ajouter un article | Se déconnecter + + + + + + + + + +
IDTitreActions
+Modifier | +Supprimer +
+ + \ No newline at end of file diff --git a/admin/delete.php b/admin/delete.php new file mode 100644 index 0000000..e266b05 --- /dev/null +++ b/admin/delete.php @@ -0,0 +1,44 @@ +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; +} +?> + + + + + Supprimer l'article + + + +

Supprimer l'article

+

Êtes-vous sûr de vouloir supprimer : ?

+
+ + Annuler +
+ + \ No newline at end of file diff --git a/admin/login.php b/admin/login.php new file mode 100644 index 0000000..f225ad0 --- /dev/null +++ b/admin/login.php @@ -0,0 +1,36 @@ + + + + + + Connexion + + + + +

Connexion

+
+
+
+ +
+

+ + + diff --git a/admin/logout.php b/admin/logout.php new file mode 100644 index 0000000..9fb0689 --- /dev/null +++ b/admin/logout.php @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/admin/modif.php b/admin/modif.php new file mode 100644 index 0000000..50d2e17 --- /dev/null +++ b/admin/modif.php @@ -0,0 +1,57 @@ +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; + } +} +?> + + + + + Modifier l'article + + + +

Modifier l'article

+ +

+ +
+
+
+ + Annuler +
+ + \ No newline at end of file diff --git a/article.php b/article.php new file mode 100644 index 0000000..4cb2653 --- /dev/null +++ b/article.php @@ -0,0 +1,17 @@ +prepare('SELECT * FROM articles WHERE id = ?'); +$stmt->execute([$id]); +$article = $stmt->fetch(); +if (!$article) { http_response_code(404); die('

404 - Article introuvable

'); } +?> + + +<?= htmlspecialchars($article['titre']) ?> + +

+

+Retour + + \ No newline at end of file diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..c7fe2bb --- /dev/null +++ b/assets/style.css @@ -0,0 +1,66 @@ +body { + font-family: Arial, sans-serif; + line-height: 1.6; + margin: 0; + padding: 20px; + background-color: #f4f4f4; + color: #333; +} + +header { + background: #333; + color: #fff; + padding: 10px 0; + text-align: center; + margin-bottom: 20px; +} + +h1 { + color: #444; + border-bottom: 2px solid #ccc; + padding-bottom: 10px; + margin-top: 0; +} + +article { + background: #fff; + padding: 15px; + margin-bottom: 15px; + border: 1px solid #ddd; + border-radius: 5px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); +} + +article h2 a { + color: #007BFF; + text-decoration: none; +} + +article h2 a:hover { + text-decoration: underline; +} + +table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; +} + +table th, table td { + padding: 10px; + border: 1px solid #ccc; + text-align: left; +} + +table th { + background-color: #e2e2e2; +} + +.error { + color: red; + font-weight: bold; + border: 1px solid red; + padding: 10px; + background: #ffe6e6; + border-radius: 5px; +} \ No newline at end of file diff --git a/bdd/Dockerfile b/bdd/Dockerfile new file mode 100644 index 0000000..2d4f3ad --- /dev/null +++ b/bdd/Dockerfile @@ -0,0 +1,8 @@ +FROM mysql +LABEL authors="youyou" + +ENV MYSQL_ROOT_PASSWORD='passwordRoot' + +COPY ./init.sql /docker-entrypoint-initdb.d/ + +EXPOSE 3306 \ No newline at end of file diff --git a/bdd/init.sql b/bdd/init.sql new file mode 100644 index 0000000..9bacfb3 --- /dev/null +++ b/bdd/init.sql @@ -0,0 +1,20 @@ +CREATE DATABASE IF NOT EXISTS cms_simpli CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +USE cms_simpli; + +CREATE TABLE utilisateur ( +id INT AUTO_INCREMENT PRIMARY KEY, +login VARCHAR(50) UNIQUE NOT NULL, +password VARCHAR(255) NOT NULL +); + + +CREATE TABLE articles ( +id INT AUTO_INCREMENT PRIMARY KEY, +titre VARCHAR(255) NOT NULL, +contenu TEXT NOT NULL, +date_creation DATETIME DEFAULT CURRENT_TIMESTAMP +); + + +INSERT INTO utilisateur (login, password) VALUES ('admin', '$2y$10$OVqu798zF7FF36HER0nZ9uOJ5tuuTR.kwPK2GTiqlPPYzR2szGzB6'); \ No newline at end of file diff --git a/include/authenticator.php b/include/authenticator.php new file mode 100644 index 0000000..d4cbfbc --- /dev/null +++ b/include/authenticator.php @@ -0,0 +1,32 @@ +prepare('SELECT * FROM utilisateur WHERE login = ?'); +$stmt->execute([$login]); +$user = $stmt->fetch(); + + +if ($user && password_verify($password, $user['password'])) { +$_SESSION['user'] = $user['login']; +return true; +} +return false; +} + + +function requireLogin() { +if (!isLogged()) { +header('Location: login.php'); +exit; +} +} +?> \ No newline at end of file diff --git a/include/db.php b/include/db.php new file mode 100644 index 0000000..af1be05 --- /dev/null +++ b/include/db.php @@ -0,0 +1,13 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch (PDOException $e) { + die('Erreur de connexion : ' . $e->getMessage()); +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..385a36b --- /dev/null +++ b/index.php @@ -0,0 +1,42 @@ +query('SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10'); +$articles = $stmt->fetchAll(); +?> + + + + + + Accueil - CMS + + + +
+ +
+ +
+

Articles

+ +

CHEF ATTEND JE TROUVE L'INSPI POUR la SUITE

+ + + + + +
+ + + + \ No newline at end of file diff --git a/launch-dockers.sh b/launch-dockers.sh new file mode 100644 index 0000000..e1eb597 --- /dev/null +++ b/launch-dockers.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +docker stop CMS_mysql + +docker stop CMS_php + +docker rm CMS_mysql + +docker rm CMS_php + +docker network rm CMS-bridge + +docker network create -d bridge CMS-bridge + +cd bdd + +docker build -t cms_mysql . + +docker run -d --name CMS_mysql -p 3306:3306 --network=CMS-bridge cms_mysql:latest + +cd .. + +docker build -t cms_php . + +docker run -d --name CMS_php -p 8080:80 --network=CMS-bridge cms_php:latest