From a232fc60a3f4c95c9f981efa47479d1a96d93542 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Wed, 1 Apr 2026 03:59:27 +0000 Subject: [PATCH] Autosave: 20260401-035926 --- admin_users.php | 249 ++++++++++++++++++++++++++++++++++++++++++++ queue_bootstrap.php | 11 +- 2 files changed, 258 insertions(+), 2 deletions(-) create mode 100644 admin_users.php diff --git a/admin_users.php b/admin_users.php new file mode 100644 index 0000000..0e24fef --- /dev/null +++ b/admin_users.php @@ -0,0 +1,249 @@ +prepare("INSERT INTO users (username, password) VALUES (:username, :password)"); + $stmt->execute(['username' => $username, 'password' => $hash]); + $success = qh_t('User created successfully.', 'تم إنشاء المستخدم بنجاح.'); + } catch (PDOException $e) { + if ($e->getCode() == 23000) { + $error = qh_t('Username already exists.', 'اسم المستخدم موجود مسبقاً.'); + } else { + $error = qh_t('Failed to create user.', 'فشل في إنشاء المستخدم.'); + } + } + } + } elseif ($action === 'update_user') { + $id = (int)($_POST['id'] ?? 0); + $username = trim($_POST['username'] ?? ''); + $password = $_POST['password'] ?? ''; + + if ($id <= 0 || $username === '') { + $error = qh_t('Invalid user data.', 'بيانات المستخدم غير صالحة.'); + } else { + try { + if ($password !== '') { + $hash = password_hash($password, PASSWORD_DEFAULT); + $stmt = $pdo->prepare("UPDATE users SET username = :username, password = :password WHERE id = :id"); + $stmt->execute(['username' => $username, 'password' => $hash, 'id' => $id]); + } else { + $stmt = $pdo->prepare("UPDATE users SET username = :username WHERE id = :id"); + $stmt->execute(['username' => $username, 'id' => $id]); + } + $success = qh_t('User updated successfully.', 'تم تحديث المستخدم بنجاح.'); + } catch (PDOException $e) { + if ($e->getCode() == 23000) { + $error = qh_t('Username already exists.', 'اسم المستخدم موجود مسبقاً.'); + } else { + $error = qh_t('Failed to update user.', 'فشل في تحديث المستخدم.'); + } + } + } + } elseif ($action === 'delete_user') { + $id = (int)($_POST['id'] ?? 0); + + // Prevent deleting the last user + $count = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn(); + if ($count <= 1) { + $error = qh_t('Cannot delete the last user in the system.', 'لا يمكن حذف آخر مستخدم في النظام.'); + } elseif ($id > 0) { + $stmt = $pdo->prepare("DELETE FROM users WHERE id = :id"); + $stmt->execute(['id' => $id]); + $success = qh_t('User deleted successfully.', 'تم حذف المستخدم بنجاح.'); + } + } +} + +try { + $users = $pdo->query("SELECT id, username, created_at FROM users ORDER BY id ASC")->fetchAll(); +} catch (PDOException $e) { + if ($e->getCode() == '42S02') { + $pdo->exec("CREATE TABLE IF NOT EXISTS users (id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL UNIQUE, password VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci"); + $users = []; + $error = qh_t('Users table was missing and has been created.', 'كان جدول المستخدمين مفقوداً وتم إنشاؤه.'); + } else { + throw $e; + } +} +$stats = qh_admin_stats(); + +qh_page_start( + 'admin', + qh_t('System Users', 'مستخدمو النظام'), + qh_t('Manage system users and access.', 'إدارة مستخدمي النظام وصلاحيات الوصول.') +); +?> +
+
+ + +
+
+
+

+

+
+ +
+ + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
ID
# + + 1): ?> +
+ + + +
+ +
+ +
+
+
+
+
+
+
+ + + + + + + + + qh_t('Manage clinic codes, routing, and order.', 'إدارة رموز العيادات والمسار والترتيب.'), 'icon' => 'clinic', ], + 'admin_users.php' => [ + 'label' => qh_t('Users', 'المستخدمون'), + 'description' => qh_t('Manage system users and access.', 'إدارة مستخدمي النظام وصلاحيات الوصول.'), + 'icon' => 'users', + ], 'admin_doctors.php' => [ 'label' => qh_t('Doctors', 'الأطباء'), 'description' => qh_t('Manage doctors, rooms, and assignments.', 'إدارة الأطباء والغرف والتعيينات.'), @@ -467,6 +472,7 @@ function qh_admin_sidebar_icon(string $icon): string 'hospital' => '', 'clinic' => '', 'doctor' => '', + 'users' => '', default => '', }; } @@ -621,6 +627,7 @@ function qh_render_nav(string $activePage): void 'reception' => ['href' => qh_url('reception.php'), 'label' => qh_t('Reception', 'الاستقبال')], 'nursing' => ['href' => qh_url('nursing.php'), 'label' => qh_t('Nursing', 'التمريض')], 'doctor' => ['href' => qh_url('doctor.php'), 'label' => qh_t('Doctor', 'الطبيب')], + 'users' => ['href' => qh_url('admin_users.php'), 'label' => qh_t('Users', 'المستخدمون')], 'display' => ['href' => qh_url('display.php'), 'label' => qh_t('Display', 'الشاشة')], ]; @@ -1345,7 +1352,7 @@ function qh_doctor_handle_request(): void $stmt->execute(['ticket_id' => $ticketId]); qh_set_flash('success', qh_t('Visit marked as completed.', 'تم إنهاء الزيارة.')); } elseif ($action === 'refer_ticket') { - $referToDoctorId = (int) ( emote_POST['refer_to_doctor_id'] ?? 0); + $referToDoctorId = (int) ($_POST["refer_to_doctor_id"] ?? 0); if ($referToDoctorId <= 0 || $referToDoctorId === $doctorId) { throw new InvalidArgumentException(qh_t('Please select a valid doctor to refer the patient to.', 'يرجى اختيار طبيب صالح لتحويل المريض إليه.')); }