<?php
declare(strict_types=1);
require_once __DIR__ . "/../config/database.php";
require_once __DIR__ . "/../includes/auth.php";
requireAuth();
$q = trim($_GET["q"] ?? "");
$sql = "SELECT nom, specialite, email FROM formateurs";
$params = [];
if ($q !== "") {
    $sql .= " WHERE nom LIKE :q OR specialite LIKE :q OR email LIKE :q";
    $params["q"] = "%{$q}%";
}
$sql .= " ORDER BY nom";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$rows = $stmt->fetchAll();
?>
<!doctype html><html lang="fr"><head><meta charset="utf-8"><title>Formateurs</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 formateurs</h2>
<table><tr><th>Nom</th><th>Specialite</th><th>Email</th></tr>
<?php foreach ($rows as $r): ?><tr><td><?= htmlspecialchars($r["nom"]) ?></td><td><?= htmlspecialchars($r["specialite"]) ?></td><td><?= htmlspecialchars($r["email"]) ?></td></tr><?php endforeach; ?>
</table>
<script>window.print()</script>
</body></html>
