<?php
require 'db.php';
require 'functions.php';
requireRole(['admin']);

$action = cleanInput($_POST['action'] ?? $_GET['action'] ?? '');

try {
    if ($action === 'list') {
        $rows = $pdo->query("SELECT createdat, entitytype, entityid, action, actionbyrole, remarks
            FROM activitylog WHERE isdeleted = 0 ORDER BY id DESC LIMIT 2000")->fetchAll();
        jsonOut(true, '', $rows);
    }
    jsonOut(false, 'Invalid action');
} catch (Exception $e) {
    logDebug('[ajax_admin_auditlog] ' . $e->getMessage());
    jsonOut(false, 'Failed to load audit log');
}
