add new featurs like realtime 2026-5-10-6
This commit is contained in:
46
Admin/v2/security/audit_logs.php
Normal file
46
Admin/v2/security/audit_logs.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
// Admin/v2/security/audit_logs.php
|
||||||
|
require_once __DIR__ . '/../../../connect.php';
|
||||||
|
|
||||||
|
if ($role !== 'super_admin') {
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode(['error' => 'Unauthorized access. Super Admin only.']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// جلب سجل العمليات
|
||||||
|
// ملاحظة: يتطلب وجود جدول admin_audit_log
|
||||||
|
$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. Please create it using the provided SQL.',
|
||||||
|
'data' => []
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt->execute();
|
||||||
|
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => $logs
|
||||||
|
]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
http_response_code(500);
|
||||||
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
||||||
|
}
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user