<?php
/**
 * Admin helper — admin işlemlerini logla
 */

function admin_log(string $action, ?int $targetId = null, ?string $details = null): void
{
    $adminId = (int)($_SESSION['user_id'] ?? 0);
    $ip = $_SERVER['REMOTE_ADDR'] ?? null;
    DB::execute(
        "INSERT INTO admin_log (admin_id, target_id, action, details, ip, created_at)
         VALUES (:a, :t, :ac, :d, :ip, :tm)",
        [
            ':a'  => $adminId,
            ':t'  => $targetId,
            ':ac' => $action,
            ':d'  => $details,
            ':ip' => $ip,
            ':tm' => time(),
        ]
    );
}
