<?php
if (session_status() === PHP_SESSION_NONE) session_start();

require_once __DIR__ . '/functions.php'; // Ajout pour avoir checkPermission

if (!isset($_SESSION['user_id'])) {
    header('Location: index.php');
    exit;
}

require_once __DIR__ . '/../config/database.php';
$pdo = getPDO();
$stmt = $pdo->prepare("SELECT id FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
if (!$stmt->fetch()) {
    session_destroy();
    header('Location: index.php');
    exit;
}