<?php
    $jsonTarget = "/json.php?file=excel-proweb";
    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>Proweb : Historique des Excels</span>
    </h2>
    <div class="fix-container-button-nav">
        <a href="proweb-salaries-upload.html"><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>
        <a href="https://www.cse-invent.com/gestion/beneficiaire/od/export-etat/124/excel?type=EtatListe_od" target="_blank"><button type="submit" class="btn btn-outline-secondary btn-sm"><?php icon::getFont(["icon" => "bi bi-link-45deg"]) ?> Exporter tous les salariés depuis Proweb</button></a>
    </div>
</header>
<?php   
        echo core::filAriane(array(
            "current" => "Historique des Excels", 
            "arbo" => array( 
                "Proweb" => NULL,
                "Historique des Excels" => "/proweb-historique-excel.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="cree" data-filter-control="input" data-width="160">Charger le</th>
                <th data-sortable="true" data-field="dateData" data-filter-control="input">Datation des données</th>
                <th data-formatter="downloadFileLocal" data-sortable="true" data-field="name" data-filter-control="input">Fichier</th>
                <th data-sortable="true" data-field="nbSalaries" data-filter-control="input" data-width="60">Nb. Salariés</th>
                <th data-sortable="true" data-field="size" data-width-unit="Ko" data-width="40">Poids</th>
                <th data-sortable="true" data-field="md5" data-filter-control="input" data-width="60">Md5</th>
                <th data-sortable="true" data-field="user" data-filter-control="select" data-width="180">Chargé par</th>
                <th data-field="id" data-formatter="deleteFile"></th>
            </tr>
        </thead>
    </table> 
</div>

<script>
    function downloadFileLocal(value, row) { 
        return '<form method="post" action="/submit.php">\n\
        <input type="hidden" name="from" value="file-download">\n\
        <input type="hidden" name="file" value="' + row.name + '">\n\
        <input type="hidden" name="md5" value="' + row.md5 + '">\n\
        <button type="submit" style="border:none; background:none;" title="Télécharger le fichier : ' + row.name + '">' + row.name + '</button>\n\
        </form>'; 
    }
    
    function deleteFile(value, row) { 
        return '<form onSubmit="return confirm(\'Voulez-vous supprimer le fichier ' + row.name + ' ?\')" method="post" action="/submit.php">\n\
        <input type="hidden" name="from" value="proweb-delete-excel">\n\
        <input type="hidden" name="file" value="' + row.name + '">\n\
        <input type="hidden" name="id" value="' + row.id + '">\n\
        <button type="submit" class="btn btn-outline-danger btn-sm">Supprimer</button>\n\
        </form>'; 
    }
</script>