<?php
// LogController
requireRole(['admin']);
$db     = Database::getInstance();
$limit  = 100;
$offset = (int)($_GET['offset'] ?? 0);
$module = sanitize($_GET['module'] ?? '');
$where  = $module ? 'WHERE al.module = ?' : '';
$params = $module ? [$module] : [];
$stmt   = $db->prepare("SELECT al.*, u.officer_name FROM activity_logs al LEFT JOIN users u ON al.user_id = u.user_id $where ORDER BY al.created_at DESC LIMIT $limit OFFSET $offset");
$stmt->execute($params);
$logs   = $stmt->fetchAll();
$total  = $db->prepare("SELECT COUNT(*) FROM activity_logs $where");
$total->execute($params);
$total  = $total->fetchColumn();
$modules = $db->query("SELECT DISTINCT module FROM activity_logs ORDER BY module")->fetchAll(PDO::FETCH_COLUMN);
include __DIR__ . '/../views/admin/logs.php';
