38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
require_once '../includes/auth.php';
|
|
require_once '../includes/db.php';
|
|
require_once '../includes/api_helper.php';
|
|
|
|
// Check if user is admin
|
|
if (!isAdmin()) {
|
|
sendJson(403, ['error' => 'Permission denied. Admins only.']);
|
|
}
|
|
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
|
|
function sendJson($statusCode, $data) {
|
|
http_response_code($statusCode);
|
|
header('Content-Type: application/json');
|
|
echo json_encode($data);
|
|
exit();
|
|
}
|
|
|
|
if ($method === 'GET') {
|
|
try {
|
|
$stmt = $pdo->query("
|
|
SELECT al.id, al.user_id, al.action, al.table_name, al.record_id, al.ip_address, al.created_at, u.full_name as user_name
|
|
FROM activity_logs al
|
|
LEFT JOIN users u ON al.user_id = u.id
|
|
ORDER BY al.created_at DESC
|
|
LIMIT 1000
|
|
");
|
|
$logs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
sendJson(200, ['logs' => $logs]);
|
|
} catch (PDOException $e) {
|
|
sendJson(500, ['error' => 'Database error: ' . $e->getMessage()]);
|
|
}
|
|
} else {
|
|
sendJson(405, ['error' => 'Method Not Allowed']);
|
|
}
|
|
?>
|