37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
require_once __DIR__ . '/common.php';
|
|
|
|
api_require_method('GET');
|
|
$staff = api_require_staff();
|
|
api_require_admin_or_permission($staff, 'view_audit_log');
|
|
$pdo = get_db();
|
|
|
|
$page = max(1, (int) ($_GET['page'] ?? 1));
|
|
$perPage = 50;
|
|
$offset = ($page - 1) * $perPage;
|
|
|
|
$total = (int) $pdo->query('SELECT COUNT(*) FROM admin_audit_log')->fetchColumn();
|
|
$stmt = $pdo->prepare(
|
|
'SELECT al.*, s.name AS staff_name FROM admin_audit_log al
|
|
LEFT JOIN staff s ON s.id = al.staff_id
|
|
ORDER BY al.created_at DESC LIMIT ? OFFSET ?'
|
|
);
|
|
$stmt->bindValue(1, $perPage, PDO::PARAM_INT);
|
|
$stmt->bindValue(2, $offset, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
$entries = $stmt->fetchAll();
|
|
|
|
api_json([
|
|
'items' => array_map(fn(array $e) => [
|
|
'id' => (int) $e['id'],
|
|
'staffName' => $e['staff_name'],
|
|
'action' => $e['action'],
|
|
'createdAt' => $e['created_at'],
|
|
], $entries),
|
|
'page' => $page,
|
|
'perPage' => $perPage,
|
|
'total' => $total,
|
|
'hasMore' => $offset + count($entries) < $total,
|
|
]);
|