<?php
    if(core::ifGet("id")){
        $event = event::getFiche(core::getGet("id"));
    }

    $jsonTarget = "/json.php?jsonData=event-salaries&id=".core::getGet("id");
    if(debug::isFile("debug")){
        debug::log(debug::getBadge($jsonTarget, "OUVRIR LE JSON : ".$jsonTarget), "JSON chargé en arrière plan");
    } 
?>

<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">Sexe</th>
            <th data-sortable="true" data-field="lieu" data-filter-control="select">Localité</th>
            <th data-sortable="true" data-field="contrat" data-filter-control="select">Statut Contrat</th>
            <th data-sortable="true" data-field="actif" data-filter-control="select">Actif</th>
            <?php if(isset($event["type_inscription"]) AND $event["type_inscription"] == 1){ ?>
            <th data-sortable="true" data-field="inscrit" data-filter-control="select">Inscrit</th>
            <?php } ?>
<?php if(isset($event["type_inscription"]) AND $event["type_inscription"] == 1){ ?>
            <th data-field="id" data-formatter="selectFormatterSalarie"></th>
<?php } ?>
        </tr>
    </thead>
</table> 
<?php if(isset($event["type_inscription"]) AND $event["type_inscription"] == 1){ ?>
<script>
        function selectFormatterSalarie(value, row) { 
            if(row.inscrit == 0){
                return '<form method="post" action="/submit.php">\n\
                <input type="hidden" name="texte" value="' + row.prenom + ' ' + row.nom + '">\n\
                <input type="hidden" name="from" value="event-inscription">\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" class="btn btn-outline-primary btn-sm">Inscrire</button>\n\
                </form>'; 
            } else {
                return '<button type="submit" class="btn btn-outline-warning btn-sm" disabled>Inscrit</button>'; 
            } 
        }
</script>
<?php } ?>