From 5581277ea98bc7aafc9d2933ab24398937951b55 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 10 May 2026 02:14:46 +0300 Subject: [PATCH] add new featurs like realtime 2026-5-10-21 --- Admin/v2/security/audit_logs.php | 33 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/Admin/v2/security/audit_logs.php b/Admin/v2/security/audit_logs.php index 79279fe..bad329a 100644 --- a/Admin/v2/security/audit_logs.php +++ b/Admin/v2/security/audit_logs.php @@ -10,11 +10,12 @@ if (!is_dir($logDir)) @mkdir($logDir, 0777, true); try { require_once __DIR__ . '/../../../connect.php'; - @file_put_contents($debugFile, " → connect.php OK. user_id=$user_id | role=$role\n", FILE_APPEND); + require_once __DIR__ . '/../../../encrypt_decrypt.php'; // جلب الـ EncryptionHelper + @file_put_contents($debugFile, " → connect.php & encryption OK. user_id=$user_id | role=$role\n", FILE_APPEND); } catch (Exception $e) { - @file_put_contents($debugFile, " → connect.php FAILED: " . $e->getMessage() . "\n", FILE_APPEND); + @file_put_contents($debugFile, " → Loading FAILED: " . $e->getMessage() . "\n", FILE_APPEND); http_response_code(500); - echo json_encode(['status' => 'failure', 'message' => 'connect failed: ' . $e->getMessage()]); + echo json_encode(['status' => 'failure', 'message' => 'loading failed: ' . $e->getMessage()]); exit; } @@ -25,26 +26,34 @@ if ($role !== 'super_admin' && $role !== 'admin') { } try { - $tableExists = $con->query("SHOW TABLES LIKE 'admin_audit_log'")->rowCount() > 0; - - if (!$tableExists) { - @file_put_contents($debugFile, " → Table NOT FOUND\n", FILE_APPEND); - jsonSuccess([], 'Audit log table not found'); - } - - // إضافة COLLATE لحل تعارض الترميز بين جدول admin_audit_log و employee + // استعلام لجلب السجلات مع محاولة جلب الاسم من جدول الموظفين أو جدول المشرفين $stmt = $con->prepare(" SELECT l.id, l.admin_id, l.action, l.table_name, l.record_id, l.details, l.created_at, - e.name as admin_name + COALESCE(e.name, au.username, au.email) as admin_name_raw FROM admin_audit_log l LEFT JOIN employee e ON l.admin_id COLLATE utf8mb4_general_ci = e.id COLLATE utf8mb4_general_ci + LEFT JOIN admin_users au ON l.admin_id COLLATE utf8mb4_general_ci = au.id COLLATE utf8mb4_general_ci + OR l.admin_id COLLATE utf8mb4_general_ci = au.username COLLATE utf8mb4_general_ci ORDER BY l.created_at DESC LIMIT 100 "); $stmt->execute(); $logs = $stmt->fetchAll(PDO::FETCH_ASSOC); + // معالجة البيانات: فك تشفير الأسماء إذا كانت مشفرة + foreach ($logs as &$log) { + $rawName = $log['admin_name_raw']; + if (!empty($rawName)) { + // محاولة فك التشفير + $decrypted = $encryptionHelper->decryptData($rawName); + $log['admin_name'] = ($decrypted !== false) ? $decrypted : $rawName; + } else { + $log['admin_name'] = 'أدمن غير معروف'; + } + unset($log['admin_name_raw']); + } + $count = count($logs); @file_put_contents($debugFile, " → SUCCESS: fetched $count logs\n", FILE_APPEND);