<?php
ob_start();
header('Content-Type: text/plain; charset=utf-8');
header("HTTP/1.0 200 OK");
register_shutdown_function(function() {
    $size = ob_get_length();
    header('Content-Length: ' . $size);
    ob_end_flush();
});


require_once 'config/database.php';

$site_id = isset($_REQUEST['site_id']) ? trim($_REQUEST['site_id']) : '';

if (empty($site_id)) {
    echo "ERR|SiteID manquant";
    exit;
}

try {
    $stmt = $pdo->prepare("SELECT code_utilisateur, NomPrenom FROM Utilisateurs WHERE SiteID = ? AND role = 'Guichetier' ORDER BY NomPrenom ASC");
    $stmt->execute([$site_id]);
    $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    $output = [];
    foreach ($results as $row) {
        $output[] = $row['code_utilisateur'] . "|" . $row['NomPrenom'];
    }
    echo implode("\n", $output);
} catch (Exception $e) {
    echo "ERR|Erreur BDD";
}
?>
