<?php
$pageTitle = 'Activity Logs';
require_once __DIR__ . '/../../app/includes/header.php';
require_admin();
$logs = db()->query('SELECT l.*, u.name, u.email FROM activity_logs l LEFT JOIN users u ON u.id = l.user_id ORDER BY l.id DESC LIMIT 300')->fetchAll();
?>
<div class="page-head"><div><h1>Activity Logs</h1><p>Recent security and application events.</p></div></div>
<div class="card app-card"><div class="table-responsive"><table class="table align-middle mb-0">
<thead><tr><th>Date</th><th>User</th><th>Action</th><th>Description</th><th>IP</th><th>User Agent</th></tr></thead><tbody>
<?php foreach ($logs as $log): ?><tr>
    <td><?= e($log['created_at']) ?></td>
    <td><?= e($log['name'] ?: 'System') ?><div class="small text-muted"><?= e($log['email'] ?? '') ?></div></td>
    <td><?= e($log['action']) ?></td><td><?= e($log['description']) ?></td><td><?= e($log['ip_address'] ?? '') ?></td><td class="small"><?= e($log['user_agent'] ?? '') ?></td>
</tr><?php endforeach; ?>
<?php if (!$logs): ?><tr><td colspan="6" class="text-center text-muted py-4">No activity logs found.</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php require_once __DIR__ . '/../../app/includes/footer.php'; ?>
