prepare("SELECT id FROM users WHERE username = ?"); $stmt->execute([$username]); if ($stmt->fetch()) { $_SESSION['flash'] = ['type' => 'error', 'title' => 'ผิดพลาด', 'message' => 'ชื่อผู้ใช้นี้มีอยู่ในระบบแล้ว']; } else { $hashed_password = password_hash($password, PASSWORD_BCRYPT); $stmt = $pdo->prepare("INSERT INTO users (username, password, name, role, status) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$username, $hashed_password, $name, $role, $status]); $_SESSION['flash'] = ['type' => 'success', 'title' => 'สำเร็จ', 'message' => 'เพิ่มผู้ใช้งานใหม่เรียบร้อยแล้ว']; } } elseif ($action === 'update_status') { $id = $_POST['id']; $status = $_POST['status']; if ($id != $_SESSION['user_id']) { // prevent deactivating oneself $stmt = $pdo->prepare("UPDATE users SET status = ? WHERE id = ?"); $stmt->execute([$status, $id]); $_SESSION['flash'] = ['type' => 'success', 'title' => 'สำเร็จ', 'message' => 'อัปเดตสถานะเรียบร้อยแล้ว']; } else { $_SESSION['flash'] = ['type' => 'error', 'title' => 'ผิดพลาด', 'message' => 'ไม่สามารถระงับบัญชีของตัวเองได้']; } } header("Location: users.php"); exit; } } // Fetch all users $stmt = $pdo->query("SELECT id, username, name, role, status, created_at FROM users ORDER BY created_at DESC"); $users = $stmt->fetchAll(); require_once 'includes/header.php'; ?>

จัดการผู้ใช้งานระบบ

ชื่อบัญชี ชื่อ-นามสกุล บทบาท สถานะ จัดการ
ผู้ดูแลระบบ ผู้ใช้งาน ใช้งานได้ ระงับการใช้งาน
-