<?php
// system_log_helper.php
header('Content-Type: text/html; charset=utf-8');

require_once 'db.php';
require_once 'auth.php'; // session vs.

function system_log($action, $details = '')
{
    global $pdo;

    // Oturum varsa kullanıcı ID’si
    $userId = $_SESSION['user']['id'] ?? null;

    $ip        = $_SERVER['REMOTE_ADDR']     ?? '';
    $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';

    $stmt = $pdo->prepare("
        INSERT INTO system_logs (user_id, ip_address, user_agent, action, details)
        VALUES (?, ?, ?, ?, ?)
    ");
    $stmt->execute([
        $userId,
        $ip,
        $userAgent,
        $action,
        $details
    ]);
}
