<?php
require_once '../app/db.php';

function logAudit($module, $action, $reference_id = null) {

    if (!isset($_SESSION['admin_id'])) return;

    global $pdo;

    $stmt = $pdo->prepare("
        INSERT INTO audit_logs
        (admin_id, admin_name, action, module, reference_id, ip_address)
        VALUES (?, ?, ?, ?, ?, ?)
    ");

    $stmt->execute([
        $_SESSION['admin_id'],
        $_SESSION['admin_name'],
        $action,
        $module,
        $reference_id,
        $_SERVER['REMOTE_ADDR']
    ]);
}
