<?php
require_once 'db_config.php';
header('Content-Type: text/plain');

$user = $_GET['username'] ?? '';

if (empty($user)) {
    die("ERROR_USER");
}

$db = new Database();
$conn = $db->conn;

$sql = "SELECT u.code_utilisateur, u.NomPrenom, u.NomPrenomAR, u.last_ticket_number, u.SiteID, s.Nom_Site, s.Nom_SiteAR 
        FROM Utilisateurs u 
        LEFT JOIN Sites s ON u.SiteID = s.SiteID 
        WHERE u.code_utilisateur = ?";

$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $user);
$stmt->execute();
$result = $stmt->get_result();

if ($result && $result->num_rows > 0) {
    $row = $result->fetch_assoc();
    echo $row['code_utilisateur'] . ";" . $row['NomPrenom'] . ";" . $row['NomPrenomAR'] . ";" . $row['last_ticket_number'] . ";" . $row['SiteID'] . ";" . $row['Nom_Site'] . ";" . $row['Nom_SiteAR'];
} else {
    echo "ERROR_NOT_FOUND";
}

$db->close();
?>
