<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);

if (core::ifGet("from") AND core::getGet("from") == "event-export-inscription") {

    $row = event::getInscription(core::getGet("id"));
    $tmpList = 'inscripts-evenement-' . core::getGet("id") . '.csv';

    $csv = fopen(DIR_TEMP . $tmpList , 'w'); 
    fputcsv($csv, array(
        "id", 
        "loginId",
        "idLocal", 
        "dateNaissance",
        "jourEntree", 
        "nom", 
        "prenom", 
        "sexe", 
        "contrat", 
        "lieu", 
        "actif", 
        "id_evenement", 
        "present"), 
        ";");

    foreach ($row as $fields) {
        fputcsv($csv, $fields, ";");
    }

    fclose($csv);

    header('Content-type: application/octet-stream;');
    header('Content-Transfer-Encoding: base64');
    header('Content-Disposition: attachment; filename="'.$tmpList.'"');
    readfile(DIR_TEMP . $tmpList);

    unlink(DIR_TEMP.$tmpList);

} else {
    header('HTTP/1.0 401 Unauthorized');
    exit();
}