<?php
declare(strict_types=1);
require_once __DIR__ . "/../config/database.php";
require_once __DIR__ . "/../includes/auth.php";
requireAuth();
$q = trim($_GET["q"] ?? "");
$sql = "SELECT CONCAT(s.nom, ' ', s.prenoms) AS stagiaire, f.titre AS formation, i.date_inscription
FROM inscriptions i
JOIN stagiaires s ON i.stagiaire_id = s.id
JOIN formations f ON i.formation_id = f.id";
$params = [];
if ($q !== "") {
    $sql .= " WHERE s.nom LIKE :q OR s.prenoms LIKE :q OR f.titre LIKE :q OR i.date_inscription LIKE :q";
    $params["q"] = "%{$q}%";
}
$sql .= " ORDER BY i.date_inscription DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$rows = $stmt->fetchAll();
?>
<!doctype html><html lang="fr"><head><meta charset="utf-8"><title>Inscriptions</title><style>body{font-family:Arial}table{width:100%;border-collapse:collapse}th,td{border:1px solid #999;padding:8px;text-align:left}</style></head><body>
<h2>Liste des inscriptions</h2>
<table><tr><th>Apprenant</th><th>Formation</th><th>Date</th></tr>
<?php foreach ($rows as $r): ?><tr><td><?= htmlspecialchars($r["stagiaire"]) ?></td><td><?= htmlspecialchars($r["formation"]) ?></td><td><?= htmlspecialchars($r["date_inscription"]) ?></td></tr><?php endforeach; ?>
</table>
<script>window.print()</script>
</body></html>
