commit 1525b28f60960bf8a49042cb20cc676acf9adc84 Author: fassara.cisse Date: Sun Nov 2 14:12:16 2025 +0100 AJOUT CMS diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/CMS-BTS-Ciel.iml b/.idea/CMS-BTS-Ciel.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/CMS-BTS-Ciel.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..31e1ebc --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1d1b251 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0f39774 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM php:8.2-apache +LABEL authors="matthieulmr" + +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..223322c --- /dev/null +++ b/README.md @@ -0,0 +1,48 @@ +# 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. \ No newline at end of file diff --git a/admin/add.php b/admin/add.php new file mode 100644 index 0000000..ae0c18e --- /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..b3a00fa --- /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..9529b2c --- /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..2df4c8a --- /dev/null +++ b/admin/login.php @@ -0,0 +1,27 @@ + + + +Connexion + +

Connexion

+
+
+
+ +
+

+ + \ No newline at end of file diff --git a/admin/logout.php b/admin/logout.php new file mode 100644 index 0000000..e88eee5 --- /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..de513c0 --- /dev/null +++ b/admin/modif.php @@ -0,0 +1,114 @@ +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 +
+ + +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..0f022e6 --- /dev/null +++ b/assets/style.css @@ -0,0 +1,32 @@ +body { + font-family: Arial, sans-serif; + line-height: 1.6; + margin: 0; + padding: 20px; + background-color: #000b69; + 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 #fa5a5a; + border-radius: 5px; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05); +} \ No newline at end of file diff --git a/bdd/Dockerfile b/bdd/Dockerfile new file mode 100644 index 0000000..22e35ab --- /dev/null +++ b/bdd/Dockerfile @@ -0,0 +1,8 @@ +FROM mysql +LABEL authors="matthieulmr" + +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..6eac57e --- /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$12$6IBnlTULcgd0kJ6pbSrzheGh2ZUYUJzfI.7tiC4R9zyfCUvmf1f4K'); \ No newline at end of file diff --git a/include/auth.php b/include/auth.php new file mode 100644 index 0000000..d4cbfbc --- /dev/null +++ b/include/auth.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..2393bc9 --- /dev/null +++ b/index.php @@ -0,0 +1,41 @@ +query('SELECT * FROM articles ORDER BY date_creation DESC LIMIT 10'); +$articles = $stmt->fetchAll(); +?> + + + + + Accueil - CMS Simplifié + + + +
+ +
+ +
+

Articles récents

+ +

Aucun article n'a encore été publié.

+ + + + + +
+ + + + \ 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