From 67eb418c74a09c507d2d31116d465ce0f142e1c5 Mon Sep 17 00:00:00 2001 From: jeremy Date: Thu, 31 Oct 2024 12:52:27 +0100 Subject: [PATCH] ajout de la gestion des types d'ingredients --- db.sql | 13 +++++ ingredient_types_management.php | 97 +++++++++++++++++++++++++++++++++ main.php | 1 + 3 files changed, 111 insertions(+) create mode 100644 ingredient_types_management.php diff --git a/db.sql b/db.sql index ba6f3b6..2e1639f 100644 --- a/db.sql +++ b/db.sql @@ -54,3 +54,16 @@ CREATE TABLE clients ( INSERT INTO clients (name, client_code) VALUES ('Example Client', 'ABC'); + +CREATE TABLE ingredients_types ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(50) NOT NULL UNIQUE, + description TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + + +INSERT INTO ingredients_types (name, description) VALUES +('Spice', 'Used to add flavor to recipes'), +('Sauce', 'Liquid or semi-liquid substance served with food'), +('Topping', 'Additional items used to enhance dishes'); diff --git a/ingredient_types_management.php b/ingredient_types_management.php new file mode 100644 index 0000000..09a439a --- /dev/null +++ b/ingredient_types_management.php @@ -0,0 +1,97 @@ +prepare("INSERT INTO ingredients_types (name, description) VALUES (:name, :description)"); + $stmt->execute(['name' => $name, 'description' => $description]); +} + +// Modifier un type d'ingrédient +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_ingredient_type'])) { + $id = $_POST['id']; + $name = $_POST['name']; + $description = $_POST['description']; + $stmt = $pdo->prepare("UPDATE ingredients_types SET name = :name, description = :description WHERE id = :id"); + $stmt->execute(['name' => $name, 'description' => $description, 'id' => $id]); +} + +// Supprimer un type d'ingrédient +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_ingredient_type'])) { + $id = $_POST['id']; + $stmt = $pdo->prepare("DELETE FROM ingredients_types WHERE id = :id"); + $stmt->execute(['id' => $id]); +} + +// Récupérer tous les types d'ingrédients +$stmt = $pdo->query("SELECT * FROM ingredients_types"); +$ingredient_types = $stmt->fetchAll(); +?> + + + + + + + Manage Ingredient Types + + +

Manage Ingredient Types

+ + +

Add Ingredient Type

+
+ + + +
+ +

Existing Ingredient Types

+ + + + + + + + + + + + + + + +
IDNameDescriptionActions
+ +
+ + + + +
+ +
+ + +
+
+Retour à la page principale + + diff --git a/main.php b/main.php index 62cca30..e752fd0 100644 --- a/main.php +++ b/main.php @@ -29,6 +29,7 @@ $role = $_SESSION['role']; Gérer les systèmes d'exploitation Manage Programming Languages Manage Clients + Manage Ingredient Types