<?php
session_start();
require_once 'config.php';
require_once 'functions.php';

echo "Session user_id: " . ($_SESSION['user_id'] ?? 'VIDE') . "<br>";

requireLogin();
echo "requireLogin OK<br>";

$user = getConnectedUser($pdo);
echo "user: " . ($user['username'] ?? 'NULL') . " admin=" . ($user['admin'] ?? '?') . "<br>";

requireAdmin($user);
echo "requireAdmin OK<br>";

// Test la requête qui plante peut-être
try {
    $trophies = $pdo->query("SELECT * FROM trophy_levels ORDER BY requirement_value ASC")->fetchAll();
    echo "trophy_levels OK: " . count($trophies) . " entrees<br>";
} catch(Exception $e) {
    echo "ERREUR trophy_levels: " . $e->getMessage() . "<br>";
}

echo "<br>=== AVANT INCLUDE HEADER ===<br>";
include 'header.php';
echo "=== APRES HEADER ===<br>";

// Simuler le début du HTML de admin_trophees
echo "<div class='container mt-4'>";
echo "<h5>TEST TROPHEES OK</h5>";

// Test str_starts_with sur icon_path
$testIp = 'emoji:⭐';
echo "str_starts_with test: " . (strpos($testIp, 'emoji:') === 0 ? 'OK' : 'FAIL') . "<br>";

echo "</div>";
include 'footer.php';
?>
