ajout de la gestion des types d'ingredients

This commit is contained in:
jeremy 2024-10-31 12:52:27 +01:00
parent 59e0189251
commit 67eb418c74
3 changed files with 111 additions and 0 deletions

13
db.sql
View File

@ -54,3 +54,16 @@ CREATE TABLE clients (
INSERT INTO clients (name, client_code) VALUES ('Example Client', 'ABC'); 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');

View File

@ -0,0 +1,97 @@
<?php
session_start();
require 'db_con.php'; // Inclure la connexion à la base de données
// Vérifiez si l'utilisateur est connecté
if (!isset($_SESSION['user_id'])) {
header("Location: index.php");
exit;
}
// Vérifiez le rôle de l'utilisateur
$role = $_SESSION['role'];
if ($role !== 'admin' && $role !== 'chef') {
header("Location: main.php");
exit;
}
// Ajouter un type d'ingrédient
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_ingredient_type'])) {
$name = $_POST['name'];
$description = $_POST['description'];
$stmt = $pdo->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();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Ingredient Types</title>
</head>
<body>
<h1>Manage Ingredient Types</h1>
<!-- Formulaire pour ajouter un type d'ingrédient -->
<h2>Add Ingredient Type</h2>
<form method="POST">
<input type="text" name="name" required placeholder="Ingredient Type Name">
<input type="text" name="description" placeholder="Description">
<button type="submit" name="add_ingredient_type">Add</button>
</form>
<h2>Existing Ingredient Types</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Actions</th>
</tr>
<?php foreach ($ingredient_types as $type): ?>
<tr>
<td><?php echo htmlspecialchars($type['id']); ?></td>
<td><?php echo htmlspecialchars($type['name']); ?></td>
<td><?php echo htmlspecialchars($type['description']); ?></td>
<td>
<!-- Formulaire pour modifier un type d'ingrédient -->
<form method="POST" style="display:inline;">
<input type="hidden" name="id" value="<?php echo $type['id']; ?>">
<input type="text" name="name" value="<?php echo htmlspecialchars($type['name']); ?>" required>
<input type="text" name="description" value="<?php echo htmlspecialchars($type['description']); ?>">
<button type="submit" name="edit_ingredient_type">Edit</button>
</form>
<!-- Formulaire pour supprimer un type d'ingrédient -->
<form method="POST" style="display:inline;">
<input type="hidden" name="id" value="<?php echo $type['id']; ?>">
<button type="submit" name="delete_ingredient_type" onclick="return confirm('Are you sure you want to delete this ingredient type?');">Delete</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</table>
<a href="main.php">Retour à la page principale</a>
</body>
</html>

View File

@ -29,6 +29,7 @@ $role = $_SESSION['role'];
<a href="os_management.php">Gérer les systèmes d'exploitation</a> <a href="os_management.php">Gérer les systèmes d'exploitation</a>
<a href="language_management.php">Manage Programming Languages</a> <a href="language_management.php">Manage Programming Languages</a>
<a href="client_management.php">Manage Clients</a> <a href="client_management.php">Manage Clients</a>
<a href="ingredient_types_management.php">Manage Ingredient Types</a>
<?php endif; ?> <?php endif; ?>
<?php if ($role === 'admin'): ?> <?php if ($role === 'admin'): ?>