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

if (isset($_SESSION['user_id'])) {
    $logoutReason = $_GET['reason'] ?? '';
    if ($logoutReason === 'session_timeout') {
        add_current_user_log($conn, 'Log keluar automatik kerana sesi tamat');
    } elseif ($logoutReason === 'session_warning') {
        add_current_user_log($conn, 'Log keluar dari amaran sesi');
    } else {
        add_current_user_log($conn, 'Log keluar dari sistem');
    }
}

session_unset();
session_destroy();
header('Location: login.php');
exit();
