<?php
    $jsonTarget = "/json.php?jsonData=event-inscrits&id=".core::getGet("id");
    if(debug::isFile("debug")){
        debug::log(debug::getBadge($jsonTarget, "OUVRIR LE JSON : ".$jsonTarget), "JSON chargé en arrière plan");
    } 
?>
<div style="float:right; margin-top: -60px;">
<?php 
    $evenement = event::getFiche(core::getGet("id"));
    if($evenement["type_inscription"] == 1){
?>
    <a href="/?p=evenement-inscription-upload&id=<?php echo core::getGet("id") ?>"><button type="submit" class="btn btn-outline-success btn-sm"><?php icon::getFont(["icon" => "bi bi-file-earmark-plus"]) ?> Importer un fichier Excel</button></a>
<?php } ?>
    <a href="/submit.php?from=event-export-inscription&id=<?php echo core::getGet("id") ?>"><button type="submit" class="btn btn-outline-primary btn-sm"><?php icon::getFont(["icon" => "bi bi-box-arrow-down"]) ?> Extraire en CSV</button></a>
</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-url="<?php echo $jsonTarget ?>">
    <thead>
        <tr>
            <th data-sortable="true" data-field="idLocal" data-filter-control="input" data-width="100">Matricule</th>
            <th data-sortable="true" data-field="loginId" data-filter-control="input" data-width="100">Identifiant</th>
            <th data-sortable="true" data-field="dateNaissance" data-filter-control="input" data-width="90">Naissances</th>
            <th data-sortable="true" data-field="nom" data-filter-control="input">Nom</th>
            <th data-sortable="true" data-field="prenom" data-filter-control="input">Prénom</th>
            <th data-sortable="true" data-field="sexe" data-filter-control="select" data-width="40">Sexe</th>
            <th data-sortable="true" data-field="lieu" data-filter-control="select" data-width="160">Localité</th>
            <th data-sortable="true" data-field="contrat" data-filter-control="select" data-width="40">Contrat</th>
            <th data-sortable="true" data-field="actif" data-filter-control="select" data-width="40">Actif</th>
            <th data-sortable="true" data-field="present" data-filter-control="select">Emargement</th>
            <th data-field="id" data-formatter="emarger">Réaliser</th>
            <th data-field="id" data-formatter="desinscrire"></th>
        </tr>
    </thead>
</table> 

<script>
        function desinscrire(value, row) { 
<?php if(ENVIRONNEMENT != "DEV") { ?>            
            if(row.present === null){
<?php } ?>
                return '<form method="post" action="/submit.php">\n\
                <input type="hidden" name="from" value="event-deinscription">\n\
                <input type="hidden" name="texte" value="' + row.prenom + ' ' + row.nom + '">\n\
                <input type="hidden" name="event" value="' + <?php echo core::getGet("id") ?> + '">\n\
                <input type="hidden" name="salarie" value="' + row.id + '">\n\
                <button type="submit" onclick="return confirm(\'Etes-vous certain de vouloir désinscrire ' + row.prenom + ' ' + row.nom + ' ?\')" class="btn btn-outline-danger btn-sm">Annuler</button>\n\
                </form>'; 
<?php if(ENVIRONNEMENT != "DEV") { ?>
            } else {
                return '<button class="btn btn-outline-secondary btn-sm" disabled="">Validé</button>';
            }
<?php } ?>
        }
        function emarger(value, row) { 
            if(row.present === null){
                return '<form method="post" action="/submit.php">\n\
                    <input type="hidden" name="from" value="event-emarge-by-admin">\n\
                    <input type="hidden" name="texte" value="' + row.prenom + ' ' + row.nom + '">\n\
                    <input type="hidden" name="event" value="' + <?php echo core::getGet("id") ?> + '">\n\
                    <input type="hidden" name="salarie" value="' + row.id + '">\n\
                    <button type="submit" onclick="return confirm(\'Etes-vous certain de vouloir émarger ' + row.prenom + ' ' + row.nom + ' à sa place ?\')" class="btn btn-outline-warning btn-sm">Emarger</button>\n\
                    </form>'; 
            } else {
                if(row.nameAdminPresent === null){
                    if(row.sexe === "M"){
                        return 'Par le salarié';
                    } else {
                        return 'Par la salariée'; 
                    }
                } else {
                    return row.nameAdminPresent;
                }
                
            }
        }
</script>