Files
intaleq_v3_pure_php/Admin/v2/security/audit_logs.php
2026-05-10 01:48:58 +03:00

44 lines
1.5 KiB
PHP

<?php
// Admin/v2/security/audit_logs.php
require_once __DIR__ . '/../../../connect.php';
// تم التحقق من صحة التوكن في connect.php مسبقاً، لذا المستخدم مسجل دخول كأدمن صالح.
try {
$stmt = $con->prepare("
SELECT
l.id, l.admin_id, e.name as admin_name, l.action, l.table_name, l.record_id, l.details, l.created_at
FROM admin_audit_log l
LEFT JOIN employee e ON l.admin_id = e.id
ORDER BY l.created_at DESC
LIMIT 100
");
$tableExists = $con->query("SHOW TABLES LIKE 'admin_audit_log'")->rowCount() > 0;
if (!$tableExists) {
echo json_encode([
'status' => 'success',
'message' => 'Audit log table not found.',
'data' => []
]);
exit;
}
$stmt->execute();
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
// تسجيل عدد السجلات في ملف لوج للفحص
$count = count($logs);
file_put_contents(__DIR__ . '/fetch_debug.txt', "[" . date('Y-m-d H:i:s') . "] Fetching Logs. Count: $count. User: $user_id\n", FILE_APPEND);
// توحيد الاستجابة مع دالة jsonSuccess الموجودة في helpers.php
// والتي تضع البيانات داخل مفتاح message
jsonSuccess($logs);
} catch (Exception $e) {
file_put_contents(__DIR__ . '/fetch_debug.txt', "Error: " . $e->getMessage() . "\n", FILE_APPEND);
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
?>