<?php
    $lottery = lottery::getFiche(core::getGet("id"));
    $dataLottery = lottery::getInscriptionData(core::getGet("id"));

    $jsonTarget = "/json.php?jsonData=lottery-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
    if ($lottery["sortDate"] == NULL) {
    ?>
        <a href="/?p=lottery-upload-excel&id=<?php echo core::getGet("id") ?>"><button type="submit" class="btn btn-outline-success btn-sm"><?php icon::getFont(["icon" => "bi bi-box-arrow-down"]) ?> Importer les inscrits</button></a>
    <?php } ?>
</div>
<?php 
    if($dataLottery["inscrits"] > 0) {
?>
<div class="card text-center">
    <div class="card-header" style="font-size: 1.3em;">
        Informations sur les inscrits
    </div>
    <div class="card-body">
        <div class="row">
            <div class="col">
                <label style="color: gray;">Nombre d'inscrits</label>
                <input type="text" value="<?php
                                            if (isset($dataLottery["inscrits"])) {
                                                echo $dataLottery["inscrits"];
                                            }
                                            ?>" class="form-control text-center" disabled>
            </div>
            <div class="col">
                <label style="color: gray;">Eligible(s)</label>
                <input type="text" value="<?php
                                            if (isset($dataLottery["eligible"])) {
                                                echo $dataLottery["eligible"];
                                            } else { echo "0";}
                                            ?>" style="background-color:#d4edda; color:green;" class="form-control text-center" disabled>
            </div>
            <div class="col">
                <label style="color: gray;">Non éligible(s)</label>
                <input type="text" value="<?php
                                            if (isset($dataLottery["ineligible"])) {
                                                echo $dataLottery["ineligible"];
                                            } else { echo "0";}
                                            ?>" style="background-color:#f8d7da; color:red;" class="form-control text-center" disabled>
            </div>
        </div>
    </div>
</div>
<br />
<?php 
    }
?>
<div class="card text-center">
    <div class="card-header" style="font-size: 1.3em;">
        Liste des inscrits
    </div>
    <div class="card-body">

        <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="id_presta" data-width="50" data-formatter="selectPrestation">Prestation</th>
                    <th data-sortable="true" data-field="id_dossier" data-filter-control="input" data-width="50" data-formatter="selectDossier">Dossier</th>
                    <th data-sortable="true" data-field="id_salarie" data-filter-control="input" data-width="50">Id Salarié</th>
                    <th data-sortable="true" data-field="actif" data-filter-control="select" data-width="50">Base RH</th>
                    <th data-sortable="true" data-field="valide" data-filter-control="select" data-width="50">Eligible</th>
                    <th data-sortable="true" data-field="login" data-filter-control="input" data-width="150">Login</th>
                    <th data-sortable="true" data-field="prenom" data-filter-control="input" data-width="150">Prénom</th>
                    <th data-sortable="true" data-field="nom" data-filter-control="input" data-width="150">Nom</th>
                    <th data-sortable="true" data-field="lieu" data-filter-control="input" data-width="175">Rattachement</th>
                    <th data-sortable="true" data-field="admin" data-filter-control="select">Chargé par</th>
                    <th data-sortable="true" data-field="cree" data-width="175">Le</th>
                </tr>
            </thead>
        </table>
    </div>
</div>

<script>
    function selectDossier(value) {
        return '<a href="https://www.cse-invent.com/gestion/prestations/dossiers/' + value + '/edit?pagesize=20&page=1" target="_blank"><button type="submit" class="btn btn-outline-primary btn-sm">' + value + '</button></a>';
    }

    function selectPrestation(value, row) {
        return '<a href="https://www.cse-invent.com/gestion/prestations/' + value + '/edit?search=avance&page=1&pagesize=20" target="_blank"><button type="submit" class="btn btn-outline-primary btn-sm">' + value + '</button></a>';
    }
</script>