<?php
/**
 * Debug Session - Check what's in your current session
 * DELETE THIS FILE AFTER CHECKING!
 */

session_start();

echo "<h1>Session Debug Information</h1>";
echo "<pre>";
echo "Full Session Data:\n";
print_r($_SESSION);
echo "\n\n";

echo "Specific Checks:\n";
echo "- user_id: " . ($_SESSION['user_id'] ?? 'NOT SET') . "\n";
echo "- username: " . ($_SESSION['username'] ?? 'NOT SET') . "\n";
echo "- email: " . ($_SESSION['email'] ?? 'NOT SET') . "\n";
echo "- user_type: " . ($_SESSION['user_type'] ?? 'NOT SET') . "\n";

echo "\n\n";
echo "Database Check:\n";

require_once __DIR__ . '/config/config.php';

if (isset($_SESSION['user_id'])) {
    $db = Database::getInstance();
    $sql = "SELECT id, username, email, user_type FROM users WHERE id = ?";
    $user = $db->fetchOne($sql, [$_SESSION['user_id']]);
    
    if ($user) {
        echo "User in database:\n";
        print_r($user);
        
        echo "\n\nComparison:\n";
        echo "Session has user_type: " . (isset($_SESSION['user_type']) ? 'YES' : 'NO') . "\n";
        echo "Database has user_type: " . ($user['user_type'] ?? 'NULL') . "\n";
        
        if (!isset($_SESSION['user_type']) && isset($user['user_type'])) {
            echo "\n⚠️ PROBLEM FOUND: Session is missing user_type but database has it!\n";
            echo "SOLUTION: Logout and login again, or run update_sessions.php\n";
        }
    }
}

echo "</pre>";

echo "<hr>";
echo "<h2>Quick Fix</h2>";
echo "<p><a href='update_sessions.php' style='background: blue; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px;'>Update Session Now</a></p>";
echo "<p>Or <a href='" . BASE_URL . "/admin/logout'>Logout</a> and login again</p>";
echo "<hr>";
echo "<p style='color: red;'><strong>DELETE THIS FILE (debug_session.php) AFTER CHECKING!</strong></p>";
?>
