add new featurs like realtime 2026-5-10-21
This commit is contained in:
@@ -10,11 +10,12 @@ if (!is_dir($logDir)) @mkdir($logDir, 0777, true);
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
require_once __DIR__ . '/../../../connect.php';
|
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) {
|
} 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);
|
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;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,26 +26,34 @@ if ($role !== 'super_admin' && $role !== 'admin') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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("
|
$stmt = $con->prepare("
|
||||||
SELECT
|
SELECT
|
||||||
l.id, l.admin_id, l.action, l.table_name, l.record_id, l.details, l.created_at,
|
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
|
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 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
|
ORDER BY l.created_at DESC
|
||||||
LIMIT 100
|
LIMIT 100
|
||||||
");
|
");
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
$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);
|
$count = count($logs);
|
||||||
@file_put_contents($debugFile, " → SUCCESS: fetched $count logs\n", FILE_APPEND);
|
@file_put_contents($debugFile, " → SUCCESS: fetched $count logs\n", FILE_APPEND);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user