Update: 2026-06-12 20:40:40

This commit is contained in:
Hamza-Ayed
2026-06-12 20:40:40 +03:00
parent 305ae01d52
commit f907212c57
294 changed files with 3592 additions and 3581 deletions

View File

@@ -0,0 +1,54 @@
<?php
/**
* Admin/Staff/activate.php
* تفعيل الحسابات المعلقة للمشرفين (Admins) وموظفي خدمة العملاء (Service) من قبل المشرف العام
*/
require_once __DIR__ . '/../../core/bootstrap.php';
require_once __DIR__ . '/../../functions.php';
$userId = filterRequest('user_id');
$type = filterRequest('type'); // 'admin' or 'service'
if (empty($userId) || empty($type)) {
jsonError("رقم المستخدم ونوع الحساب مطلوبان.");
exit;
}
try {
$con = Database::get('main');
// التحقق من صلاحية المشرف العام (Super Admin أو Admin فقط)
$jwtService = new JwtService($redis);
$auth = $jwtService->authenticate();
$authRole = $auth->role ?? '';
if ($authRole !== 'super_admin' && $authRole !== 'admin') {
jsonError("غير مصرح لك. فقط المشرف العام يمكنه تفعيل الحسابات.");
exit;
}
if ($type === 'admin') {
$stmt = $con->prepare("UPDATE adminUser SET status = 'active' WHERE id = :id AND status = 'pending'");
$stmt->execute([':id' => $userId]);
if ($stmt->rowCount() > 0) {
printSuccess(["message" => "تم تفعيل حساب المشرف بنجاح."]);
} else {
jsonError("لم يتم العثور على حساب مشرف معلق بهذا المعرف.");
}
} elseif ($type === 'service') {
$stmt = $con->prepare("UPDATE users SET status = 'approved' WHERE id = :id AND status = 'pending' AND user_type = 'service'");
$stmt->execute([':id' => $userId]);
if ($stmt->rowCount() > 0) {
printSuccess(["message" => "تم تفعيل حساب موظف الخدمة بنجاح."]);
} else {
jsonError("لم يتم العثور على حساب موظف خدمة معلق بهذا المعرف.");
}
} else {
jsonError("نوع حساب غير صالح.");
}
} catch (Exception $e) {
error_log("[Staff Activate Error] " . $e->getMessage());
jsonError("خطأ في السيرفر: " . $e->getMessage());
}
exit();

View File

@@ -7,15 +7,14 @@ require_once __DIR__ . '/../../core/bootstrap.php';
$con = Database::get('main');
// التحقق من الصلاحيات: فقط المشرفين يمكنهم الإضافة
// إذا لم يكن هناك أي مدير في النظام، نسمح// تم تعطيل التحقق للسماح بإعادة التهيئة في مرحلة التطوير
// $count = $con->query("SELECT COUNT(*) FROM adminUser")->fetchColumn();
// if ($count > 0) die("Access Denied: Admin already initialized.");
// $auth = JwtService::authenticate($redis);
// if ($auth['role'] !== 'super_admin' && $auth['role'] !== 'admin') {
// jsonError("Unauthorized. Only Admins can add staff.");
// exit;
// }
// التحقق من الصلاحيات: فقط المشرفين (super_admin أو admin) يمكنهم الإضافة
$jwtService = new JwtService($redis);
$auth = $jwtService->authenticate();
$authRole = $auth->role ?? '';
if ($authRole !== 'super_admin' && $authRole !== 'admin') {
jsonError("غير مصرح لك. فقط المشرفون يمكنهم إضافة موظفين.");
exit;
}
$name = filterRequest("name");
$phone = filterRequest("phone");
@@ -47,14 +46,20 @@ try {
if ($role === 'admin') {
// الإضافة لجدول المديرين
$sql = "INSERT INTO adminUser (id, fingerprint, fingerprint_hash, name, password, role, created_at)
VALUES (:id, :fp, :fp_hash, :name, :pass, :role, NOW())";
// التأكد من وجود عمود phone في الجدول (كإجراء احترازي لتجنب الأخطاء إذا لم يكن موجوداً)
try {
$con->exec("ALTER TABLE adminUser ADD COLUMN phone VARCHAR(255) NULL AFTER name");
} catch (Exception $e) { /* العمود موجود مسبقاً */ }
$sql = "INSERT INTO adminUser (id, fingerprint, fingerprint_hash, name, phone, password, role, created_at)
VALUES (:id, :fp, :fp_hash, :name, :phone, :pass, :role, NOW())";
$stmt = $con->prepare($sql);
$stmt->execute([
':id' => $uniqueId,
':fp' => $encFp,
':fp_hash' => $fpHash,
':name' => $encName,
':phone' => $encPhone,
':pass' => $hashedPassword,
':role' => $role
]);

View File

@@ -0,0 +1,42 @@
<?php
/**
* Admin/Staff/pending.php
* جلب الحسابات المعلقة للإداريين والخدمة
*/
require_once __DIR__ . '/../../core/bootstrap.php';
require_once __DIR__ . '/../../functions.php';
try {
$con = Database::get('main');
// جلب الإداريين المعلقين
$stmt1 = $con->query("SELECT id, name, phone, role, created_at, 'admin' as type FROM adminUser WHERE status = 'pending'");
$admins = $stmt1->fetchAll(PDO::FETCH_ASSOC);
// فك التشفير للأسماء والأرقام للإداريين
foreach ($admins as &$admin) {
$admin['name'] = $encryptionHelper->decryptData($admin['name']) ?: $admin['name'];
$admin['phone'] = $encryptionHelper->decryptData($admin['phone']) ?: $admin['phone'];
}
// جلب موظفي الخدمة المعلقين
$stmt2 = $con->query("SELECT id, first_name, last_name, phone, user_type as role, created_at, 'service' as type FROM users WHERE status = 'pending' AND user_type = 'service'");
$services = $stmt2->fetchAll(PDO::FETCH_ASSOC);
// فك التشفير لموظفي الخدمة
foreach ($services as &$service) {
$service['name'] = trim(($encryptionHelper->decryptData($service['first_name']) ?: $service['first_name']) . ' ' . ($encryptionHelper->decryptData($service['last_name']) ?: $service['last_name']));
$service['phone'] = $encryptionHelper->decryptData($service['phone']) ?: $service['phone'];
}
$allPending = array_merge($admins, $services);
printSuccess([
"data" => $allPending
]);
} catch (Exception $e) {
error_log("[Staff Pending Error] " . $e->getMessage());
jsonError("خطأ في السيرفر: " . $e->getMessage());
}
exit();