غير مصرح لك بالوصول لهذه الصفحة.'; require_once __DIR__ . '/includes/footer.php'; exit; } $error = ''; $success = ''; // Handle actions if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; $username = $_POST['username'] ?? ''; $full_name = $_POST['full_name'] ?? ''; $role = $_POST['role'] ?? 'staff'; $password = $_POST['password'] ?? ''; $id = $_POST['id'] ?? 0; if ($username && $full_name) { try { if ($action === 'add') { if (!$password) { $error = 'يرجى إدخال كلمة المرور للمستخدم الجديد'; } else { $hashed_password = password_hash($password, PASSWORD_DEFAULT); $stmt = db()->prepare("INSERT INTO users (username, full_name, role, password) VALUES (?, ?, ?, ?)"); $stmt->execute([$username, $full_name, $role, $hashed_password]); $success = 'تمت إضافة المستخدم بنجاح'; } } elseif ($action === 'edit') { if ($password) { $hashed_password = password_hash($password, PASSWORD_DEFAULT); $stmt = db()->prepare("UPDATE users SET username = ?, full_name = ?, role = ?, password = ? WHERE id = ?"); $stmt->execute([$username, $full_name, $role, $hashed_password, $id]); } else { $stmt = db()->prepare("UPDATE users SET username = ?, full_name = ?, role = ? WHERE id = ?"); $stmt->execute([$username, $full_name, $role, $id]); } $success = 'تم تحديث بيانات المستخدم بنجاح'; } } catch (PDOException $e) { if ($e->getCode() == 23000) { $error = 'اسم المستخدم موجود مسبقاً'; } else { $error = 'حدث خطأ: ' . $e->getMessage(); } } } else { $error = 'يرجى ملء الحقول المطلوبة'; } } // Delete action if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) { $id = $_GET['id']; if ($id == $_SESSION['user_id']) { $error = 'لا يمكنك حذف حسابك الحالي'; } else { $stmt = db()->prepare("DELETE FROM users WHERE id = ?"); $stmt->execute([$id]); $success = 'تم حذف المستخدم بنجاح'; } } $users = db()->query("SELECT * FROM users ORDER BY created_at DESC")->fetchAll(); // Handle Deep Link for Edit $deepLinkData = null; if (isset($_GET['action']) && $_GET['action'] === 'edit' && isset($_GET['id'])) { $stmt = db()->prepare("SELECT * FROM users WHERE id = ?"); $stmt->execute([$_GET['id']]); $deepLinkData = $stmt->fetch(); } ?>

إدارة المستخدمين

اسم المستخدم الاسم الكامل الصلاحية تاريخ الإنشاء الإجراءات