ajout des premiers fichiers
This commit is contained in:
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>
|
||||
Reference in New Issue
Block a user