ajout des premiers fichiers
This commit is contained in:
parent
bbadd146df
commit
2b3976481a
46
db.sql
Normal file
46
db.sql
Normal file
@ -0,0 +1,46 @@
|
||||
-- Création de la base de données
|
||||
CREATE DATABASE IF NOT EXISTS pizzeria_it CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- Utilisation de la base de données
|
||||
USE pizzeria_it;
|
||||
|
||||
-- Création de la table users
|
||||
CREATE TABLE users (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
username VARCHAR(50) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
role ENUM('admin', 'chef', 'cook', 'waiter') NOT NULL,
|
||||
status ENUM('active', 'inactive') DEFAULT 'active',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO users (username, password, role, status)
|
||||
VALUES ('admin', '$2y$10$KbQi6nJESXwvMdN5RqZsruu/P1PnkkIzKjzwNlPRe7ghRuVJozr.u', 'admin', 'active');
|
||||
|
||||
-- Création de l'utilisateur SQL "pizzeria" avec le mot de passe "pizzeria"
|
||||
CREATE USER 'pizzeria'@'localhost' IDENTIFIED BY 'pizzeria';
|
||||
|
||||
-- Accorder tous les privilèges sur la base de données "pizzeria_it" à l'utilisateur "pizzeria"
|
||||
GRANT ALL PRIVILEGES ON pizzeria_it.* TO 'pizzeria'@'localhost';
|
||||
|
||||
-- Appliquer les changements
|
||||
FLUSH PRIVILEGES;
|
||||
|
||||
CREATE TABLE os (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
operating_system VARCHAR(255) NOT NULL,
|
||||
version VARCHAR(50) NOT NULL,
|
||||
architecture VARCHAR(50) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO os (operating_system, version, architecture)
|
||||
VALUES ('debian', '12', 'amd64');
|
||||
|
||||
CREATE TABLE language (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(50) NOT NULL UNIQUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
INSERT INTO language (name) VALUES ('bash');
|
17
db_con.php
Normal file
17
db_con.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// Informations de connexion
|
||||
$host = 'localhost';
|
||||
$dbname = 'pizzeria_it';
|
||||
$username = 'pizzeria'; // Remplacez par votre nom d'utilisateur MySQL
|
||||
$password = 'pizzeria'; // Remplacez par votre mot de passe MySQL
|
||||
|
||||
try {
|
||||
// Création de la connexion PDO
|
||||
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
|
||||
// Configuration des options PDO
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
// Gestion des erreurs de connexion
|
||||
die("Database connection failed: " . $e->getMessage());
|
||||
}
|
27
delete_os.php
Normal file
27
delete_os.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php'; // 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;
|
||||
}
|
||||
|
||||
// Supprimer l'OS par ID
|
||||
if (isset($_GET['id'])) {
|
||||
$os_id = $_GET['id'];
|
||||
$stmt = $pdo->prepare("DELETE FROM os WHERE id = ?");
|
||||
$stmt->execute([$os_id]);
|
||||
}
|
||||
|
||||
// Rediriger vers la gestion des OS
|
||||
header("Location: os_management.php");
|
||||
exit;
|
70
edit_os.php
Normal file
70
edit_os.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php'; // 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;
|
||||
}
|
||||
|
||||
// Récupérer l'OS par ID
|
||||
if (isset($_GET['id'])) {
|
||||
$os_id = $_GET['id'];
|
||||
$stmt = $pdo->prepare("SELECT * FROM os WHERE id = ?");
|
||||
$stmt->execute([$os_id]);
|
||||
$os = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$os) {
|
||||
echo "Système d'exploitation non trouvé.";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Gérer la mise à jour de l'OS
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$operating_system = $_POST['operating_system'];
|
||||
$version = $_POST['version'];
|
||||
$architecture = $_POST['architecture'];
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE os SET operating_system = ?, version = ?, architecture = ? WHERE id = ?");
|
||||
$stmt->execute([$operating_system, $version, $architecture, $os_id]);
|
||||
|
||||
header("Location: os_management.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Modifier Système d'Exploitation</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Modifier Système d'Exploitation</h1>
|
||||
<form action="edit_os.php?id=<?php echo $os['id']; ?>" method="POST">
|
||||
<label for="operating_system">Système d'Exploitation :</label>
|
||||
<input type="text" id="operating_system" name="operating_system" value="<?php echo htmlspecialchars($os['operating_system']); ?>" required>
|
||||
<br>
|
||||
<label for="version">Version :</label>
|
||||
<input type="text" id="version" name="version" value="<?php echo htmlspecialchars($os['version']); ?>" required>
|
||||
<br>
|
||||
<label for="architecture">Architecture :</label>
|
||||
<input type="text" id="architecture" name="architecture" value="<?php echo htmlspecialchars($os['architecture']); ?>" required>
|
||||
<br>
|
||||
<button type="submit">Mettre à jour</button>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
<a href="os_management.php">Retour à la gestion des OS</a>
|
||||
</body>
|
||||
</html>
|
71
edit_user.php
Normal file
71
edit_user.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php';
|
||||
|
||||
// Vérifie si l'utilisateur est admin
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Récupération des informations de l'utilisateur
|
||||
if (isset($_GET['id'])) {
|
||||
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
|
||||
$stmt->execute([$_GET['id']]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
if (!$user) {
|
||||
die("User not found.");
|
||||
}
|
||||
}
|
||||
|
||||
// Mise à jour de l'utilisateur
|
||||
if (isset($_POST['update_user'])) {
|
||||
$user_id = $_POST['user_id'];
|
||||
$username = $_POST['username'];
|
||||
$password = !empty($_POST['password']) ? password_hash($_POST['password'], PASSWORD_DEFAULT) : $user['password'];
|
||||
$role = $_POST['role'];
|
||||
$status = $_POST['status'];
|
||||
|
||||
$stmt = $pdo->prepare("UPDATE users SET username = ?, password = ?, role = ?, status = ? WHERE id = ?");
|
||||
$stmt->execute([$username, $password, $role, $status, $user_id]);
|
||||
|
||||
header("Location: manage_users.php");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Edit User</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Edit User</h2>
|
||||
<form action="edit_user.php?id=<?= $user['id'] ?>" method="post">
|
||||
<input type="hidden" name="user_id" value="<?= $user['id'] ?>">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username" value="<?= htmlspecialchars($user['username']) ?>" required>
|
||||
<br>
|
||||
<label for="password">New Password (leave blank to keep current password):</label>
|
||||
<input type="password" id="password" name="password">
|
||||
<br>
|
||||
<label for="role">Role:</label>
|
||||
<select id="role" name="role" required>
|
||||
<option value="admin" <?= $user['role'] == 'admin' ? 'selected' : '' ?>>Admin</option>
|
||||
<option value="chef" <?= $user['role'] == 'chef' ? 'selected' : '' ?>>Chef</option>
|
||||
<option value="cook" <?= $user['role'] == 'cook' ? 'selected' : '' ?>>Cook</option>
|
||||
<option value="waiter" <?= $user['role'] == 'waiter' ? 'selected' : '' ?>>Waiter</option>
|
||||
</select>
|
||||
<br>
|
||||
<label for="status">Status:</label>
|
||||
<select id="status" name="status" required>
|
||||
<option value="active" <?= $user['status'] == 'active' ? 'selected' : '' ?>>Active</option>
|
||||
<option value="inactive" <?= $user['status'] == 'inactive' ? 'selected' : '' ?>>Inactive</option>
|
||||
</select>
|
||||
<br>
|
||||
<button type="submit" name="update_user">Update User</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
5
generate_hash.php
Normal file
5
generate_hash.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
$password = 'admin'; // Remplacez par le mot de passe que vous souhaitez hacher
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
echo $hashedPassword;
|
||||
?>
|
53
index.php
Normal file
53
index.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php';
|
||||
|
||||
$error = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$username = $_POST['username'];
|
||||
$password = $_POST['password'];
|
||||
|
||||
// Préparation de la requête pour obtenir l'utilisateur
|
||||
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username AND status = 'active'");
|
||||
$stmt->execute([':username' => $username]);
|
||||
$user = $stmt->fetch();
|
||||
|
||||
// Vérification du mot de passe
|
||||
if ($user && password_verify($password, $user['password'])) {
|
||||
// Enregistrement des informations dans la session
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['username'] = $user['username'];
|
||||
$_SESSION['role'] = $user['role'];
|
||||
|
||||
// Redirection vers main.php
|
||||
header("Location: main.php");
|
||||
exit;
|
||||
} else {
|
||||
$error = 'Invalid username or password';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Login</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Login</h2>
|
||||
<?php if ($error): ?>
|
||||
<p style="color: red;"><?= htmlspecialchars($error) ?></p>
|
||||
<?php endif; ?>
|
||||
<form action="index.php" method="post">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
<br>
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
<br>
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
91
language_management.php
Normal file
91
language_management.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php'; // Assurez-vous que db_con.php est inclus pour 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 langage
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_language'])) {
|
||||
$language_name = $_POST['language_name'];
|
||||
$stmt = $pdo->prepare("INSERT INTO language (name) VALUES (:name)");
|
||||
$stmt->execute(['name' => $language_name]);
|
||||
}
|
||||
|
||||
// Modifier un langage
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_language'])) {
|
||||
$language_id = $_POST['language_id'];
|
||||
$language_name = $_POST['language_name'];
|
||||
$stmt = $pdo->prepare("UPDATE language SET name = :name WHERE id = :id");
|
||||
$stmt->execute(['name' => $language_name, 'id' => $language_id]);
|
||||
}
|
||||
|
||||
// Supprimer un langage
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_language'])) {
|
||||
$language_id = $_POST['language_id'];
|
||||
$stmt = $pdo->prepare("DELETE FROM language WHERE id = :id");
|
||||
$stmt->execute(['id' => $language_id]);
|
||||
}
|
||||
|
||||
// Récupérer tous les langages
|
||||
$stmt = $pdo->query("SELECT * FROM language");
|
||||
$languages = $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 Languages</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Manage Programming Languages</h1>
|
||||
|
||||
<!-- Formulaire pour ajouter un langage -->
|
||||
<h2>Add Language</h2>
|
||||
<form method="POST">
|
||||
<input type="text" name="language_name" required placeholder="Language Name">
|
||||
<button type="submit" name="add_language">Add</button>
|
||||
</form>
|
||||
|
||||
<h2>Existing Languages</h2>
|
||||
<table>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<?php foreach ($languages as $language): ?>
|
||||
<tr>
|
||||
<td><?php echo htmlspecialchars($language['id']); ?></td>
|
||||
<td><?php echo htmlspecialchars($language['name']); ?></td>
|
||||
<td>
|
||||
<!-- Formulaire pour modifier un langage -->
|
||||
<form method="POST" style="display:inline;">
|
||||
<input type="hidden" name="language_id" value="<?php echo $language['id']; ?>">
|
||||
<input type="text" name="language_name" value="<?php echo htmlspecialchars($language['name']); ?>" required>
|
||||
<button type="submit" name="edit_language">Edit</button>
|
||||
</form>
|
||||
<!-- Formulaire pour supprimer un langage -->
|
||||
<form method="POST" style="display:inline;">
|
||||
<input type="hidden" name="language_id" value="<?php echo $language['id']; ?>">
|
||||
<button type="submit" name="delete_language" onclick="return confirm('Are you sure you want to delete this language?');">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<a href="main.php">Retour à la page principale</a>
|
||||
</body>
|
||||
</html>
|
10
logout.php
Normal file
10
logout.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
// Détruire toutes les données de session
|
||||
$_SESSION = [];
|
||||
session_destroy(); // Détruire la session
|
||||
|
||||
// Rediriger vers la page de connexion
|
||||
header("Location: index.php");
|
||||
exit;
|
37
main.php
Normal file
37
main.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php'; // Assurez-vous que db_con.php est inclus pour 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'];
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Main Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Bienvenue, <?php echo htmlspecialchars($_SESSION['username']); ?></h1>
|
||||
|
||||
<!-- Lien de déconnexion -->
|
||||
<a href="logout.php">Déconnexion</a>
|
||||
|
||||
<?php if ($role === 'admin' || $role === 'chef'): ?>
|
||||
<a href="os_management.php">Gérer les systèmes d'exploitation</a>
|
||||
<a href="language_management.php">Manage Programming Languages</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($role === 'admin'): ?>
|
||||
<a href="user_management.php">Gérer les utilisateurs</a>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
83
os_management.php
Normal file
83
os_management.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php'; // 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;
|
||||
}
|
||||
|
||||
// Gérer l'insertion d'un nouvel OS
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_os'])) {
|
||||
$operating_system = $_POST['operating_system'];
|
||||
$version = $_POST['version'];
|
||||
$architecture = $_POST['architecture'];
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO os (operating_system, version, architecture) VALUES (?, ?, ?)");
|
||||
$stmt->execute([$operating_system, $version, $architecture]);
|
||||
}
|
||||
|
||||
// Récupérer tous les systèmes d'exploitation
|
||||
$stmt = $pdo->query("SELECT * FROM os");
|
||||
$os_list = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Gestion des Systèmes d'Exploitation</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Gestion des Systèmes d'Exploitation</h1>
|
||||
|
||||
<h2>Ajouter un Système d'Exploitation</h2>
|
||||
<form action="os_management.php" method="POST">
|
||||
<label for="operating_system">Système d'Exploitation :</label>
|
||||
<input type="text" id="operating_system" name="operating_system" required>
|
||||
<br>
|
||||
<label for="version">Version :</label>
|
||||
<input type="text" id="version" name="version" required>
|
||||
<br>
|
||||
<label for="architecture">Architecture :</label>
|
||||
<input type="text" id="architecture" name="architecture" required>
|
||||
<br>
|
||||
<button type="submit" name="add_os">Ajouter OS</button>
|
||||
</form>
|
||||
|
||||
<h2>Liste des Systèmes d'Exploitation</h2>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Système d'Exploitation</th>
|
||||
<th>Version</th>
|
||||
<th>Architecture</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<?php foreach ($os_list as $os): ?>
|
||||
<tr>
|
||||
<td><?php echo $os['id']; ?></td>
|
||||
<td><?php echo htmlspecialchars($os['operating_system']); ?></td>
|
||||
<td><?php echo htmlspecialchars($os['version']); ?></td>
|
||||
<td><?php echo htmlspecialchars($os['architecture']); ?></td>
|
||||
<td>
|
||||
<a href="edit_os.php?id=<?php echo $os['id']; ?>">Modifier</a>
|
||||
<a href="delete_os.php?id=<?php echo $os['id']; ?>" onclick="return confirm('Êtes-vous sûr de vouloir supprimer cet OS ?');">Supprimer</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<a href="main.php">Retour à la page principale</a>
|
||||
</body>
|
||||
</html>
|
94
user_management.php
Normal file
94
user_management.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'db_con.php';
|
||||
|
||||
// Vérifie si l'utilisateur est admin
|
||||
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Ajout d'un utilisateur
|
||||
if (isset($_POST['add_user'])) {
|
||||
$username = $_POST['username'];
|
||||
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
||||
$role = $_POST['role'];
|
||||
$status = $_POST['status'];
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO users (username, password, role, status) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$username, $password, $role, $status]);
|
||||
}
|
||||
|
||||
// Suppression d'un utilisateur
|
||||
if (isset($_POST['delete_user'])) {
|
||||
$user_id = $_POST['user_id'];
|
||||
$stmt = $pdo->prepare("DELETE FROM users WHERE id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
}
|
||||
|
||||
// Récupération des utilisateurs pour affichage
|
||||
$users = $pdo->query("SELECT * FROM users")->fetchAll(PDO::FETCH_ASSOC);
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>User Management</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>User Management</h2>
|
||||
|
||||
<!-- Formulaire d'ajout d'un nouvel utilisateur -->
|
||||
<h3>Add New User</h3>
|
||||
<form action="user_management.php" method="post">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
<br>
|
||||
<label for="password">Password:</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
<br>
|
||||
<label for="role">Role:</label>
|
||||
<select id="role" name="role" required>
|
||||
<option value="admin">Admin</option>
|
||||
<option value="chef">Chef</option>
|
||||
<option value="cook">Cook</option>
|
||||
<option value="waiter">Waiter</option>
|
||||
</select>
|
||||
<br>
|
||||
<label for="status">Status:</label>
|
||||
<select id="status" name="status" required>
|
||||
<option value="active">Active</option>
|
||||
<option value="inactive">Inactive</option>
|
||||
</select>
|
||||
<br>
|
||||
<button type="submit" name="add_user">Add User</button>
|
||||
</form>
|
||||
|
||||
<!-- Affichage des utilisateurs existants -->
|
||||
<h3>Existing Users</h3>
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th>Username</th>
|
||||
<th>Role</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
<?php foreach ($users as $user): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($user['username']) ?></td>
|
||||
<td><?= htmlspecialchars($user['role']) ?></td>
|
||||
<td><?= htmlspecialchars($user['status']) ?></td>
|
||||
<td>
|
||||
<form action="user_management.php" method="post" style="display:inline;">
|
||||
<input type="hidden" name="user_id" value="<?= $user['id'] ?>">
|
||||
<button type="submit" name="delete_user" onclick="return confirm('Are you sure you want to delete this user?')">Delete</button>
|
||||
</form>
|
||||
<a href="edit_user.php?id=<?= $user['id'] ?>">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<a href="main.php">Retour à la page principale</a>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user