<?php
session_start();
echo "=== DEBUG SESSION ===\n";
echo "Session ID: " . session_id() . "\n";
echo "Is session active: " . (session_status() === PHP_SESSION_ACTIVE ? 'YES' : 'NO') . "\n";
echo "Session data: " . json_encode($_SESSION, JSON_PRETTY_PRINT) . "\n";

echo "\n=== AUTH CHECKS ===\n";
if (isset($_SESSION['user'])) {
    $user = $_SESSION['user'];
    echo "User exists in session: YES\n";
    echo "Username: " . ($user['username'] ?? 'N/A') . "\n";
    echo "Role name: " . ($user['role_name'] ?? 'N/A') . "\n";
    echo "Is admin: " . ($user['is_admin'] ?? false ? 'YES' : 'NO') . "\n";
    echo "Has role: " . ($user['has_role'] ?? false ? 'YES' : 'NO') . "\n";
} else {
    echo "User exists in session: NO\n";
}

echo "Authenticated: " . (isset($_SESSION['authenticated']) && $_SESSION['authenticated'] ? 'YES' : 'NO') . "\n";
echo "Last activity: " . ($_SESSION['last_activity'] ?? 'N/A') . "\n";
?>