<?php
    json::create("events");

    $jsonTarget = "/json.php?file=events";
    if(debug::isFile("debug")){
        debug::log(debug::getBadge($jsonTarget, "OUVRIR LE JSON : ".$jsonTarget), "JSON chargé en arrière plan");
    } 
?>

<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
<h2 class="bd-title" id="content">
    <span>Listes des évènements</span>
</h2>
<?php if(access::ifAccesss("add-evenement")){ ?>
<div class="fix-container-button-nav">
    <a href="/add-evenement.html"><button type="submit" class="btn btn-outline-success btn-sm"><?php icon::getFont(["icon" => "bi bi-file-earmark-plus"]) ?> Ajouter un évènement</button></a>
</div>
<?php } ?>
</header>
<?php   
        echo core::filAriane(array(
            "current" => "Listes des évènements", 
            "arbo" => array( 
                "Evènements" => NULL,
                "Listes des évènements" => "/evenements.html")
        )); 
?>
<div>
    <table
        id="table"
        class="table-striped table-hover table-sm" 
        data-page-size="25"
        data-toggle="table"
        data-show-columns="true"
        data-search="true"
        data-buttons-align="left"
        data-pagination="true"
        data-filter-control="true"
        data-flat="true"
        data-sort-name="cree"
        data-sort-order="desc"
        data-url="<?php echo $jsonTarget ?>">
        <thead>
            <tr>
                <th data-sortable="true" data-field="id" data-filter-control="input" data-width="15">#</th>
                <th data-sortable="true" data-field="titre" data-filter-control="input">Titre</th>
                <th data-sortable="true" data-field="startDate" data-filter-control="input" data-width="160">Date de démarrage</th>
                <th data-sortable="true" data-field="m_inscrit" data-filter-control="input" data-width="50">Nb. Présent</th>
                <th data-sortable="true" data-field="m_global" data-filter-control="input" data-width="50">Nb. Inscrit</th>
                <th data-sortable="true" data-field="endDate" data-filter-control="select" data-width="160">Date de fin</th>
                <th data-sortable="true" data-field="type_inscription" data-filter-control="select" data-width="100">Accès</th>
                <th data-sortable="true" data-field="type_emargement" data-filter-control="select" data-width="150">Mode d'émargement</th>
                <th data-sortable="true" data-field="actif" data-filter-control="input" data-width="30">Actif</th>
                <th data-sortable="true" data-field="cree" data-filter-control="input" data-width="160">Créé le</th>
                <th data-field="id" data-formatter="selectFormatter" data-width="60"></th>
            </tr>
        </thead>
    </table> 
</div>

<script>
    function selectFormatter(value, row) { 
        return '<a href="/evenement-' + row.id + '.html"><button type="submit" class="btn btn-outline-primary btn-sm">Ouvrir</button></a>';
    }
</script>
