<?php
session_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once 'config.php';
require_once 'functions.php';

echo "<pre style='background:#111;color:#0f0;padding:20px;'>";
echo "Step 1: session OK — user_id=" . ($_SESSION['user_id'] ?? 'VIDE') . "\n";

requireLogin();
echo "Step 2: requireLogin OK\n";

$userId = (int)$_SESSION['user_id'];
$user = getConnectedUser($pdo);
echo "Step 3: getConnectedUser OK — " . ($user ? $user['username'] : 'NULL') . "\n";

$circleId = $_SESSION['circle_id'] ?? 1;
echo "Step 4: circleId=$circleId\n";

try {
    $cStmt = $pdo->prepare("SELECT name, invite_code, oracle_id FROM circles WHERE id = ?");
    $cStmt->execute([$circleId]);
    $circle = $cStmt->fetch();
    echo "Step 5: circle WITH oracle_id OK — " . ($circle ? $circle['name'] : 'NULL') . "\n";
} catch (Exception $e) {
    echo "Step 5: ERROR oracle_id — " . $e->getMessage() . "\n";
    $cStmt = $pdo->prepare("SELECT name, invite_code FROM circles WHERE id = ?");
    $cStmt->execute([$circleId]);
    $circle = $cStmt->fetch();
    echo "Step 5b: circle WITHOUT oracle_id OK — " . ($circle ? $circle['name'] : 'NULL') . "\n";
}

echo "Step 6: isAdmin=" . (isAdmin($user) ? 'TRUE' : 'FALSE') . "\n";

// Test colonnes users
$cols = $pdo->query("SHOW COLUMNS FROM users")->fetchAll(PDO::FETCH_COLUMN);
echo "Step 7: colonnes users = " . implode(', ', $cols) . "\n";

// Test include header
echo "Step 8: Avant include header.php\n";
include 'header.php';
echo "Step 9: Après include header.php\n";

echo "</pre>";
?>
