Browse Source

Tirage au sort

stany.ferer 2 years ago
parent
commit
cf271c2235

+ 0 - 2
core/class/event.class.php

@@ -211,8 +211,6 @@ class event
         return db::resultset();
     }
 
-
-
     public static function checkEvenementBySalarie(string $_md5)
     {
 

+ 13 - 0
core/class/json.class.php

@@ -29,6 +29,9 @@ class json extends db
                 case "salaries-proweb":
                     return self::create_salariesProweb();
                     break;
+                case "lotterys":
+                    return self::create_lotterys();
+                    break;
             }
         } else {
             return 0;
@@ -114,6 +117,16 @@ class json extends db
         }
     }
 
+    private static function create_lotterys()
+    {
+        $row = lottery::getLotterys();
+        if (file_put_contents(DIR_DATAS_JSON . "lotterys.json", json_encode($row))) {
+            return 1;
+        } else {
+            return 0;
+        }
+    }
+
     private static function create_users()
     {
         $row = user::getUsers();

+ 157 - 0
core/class/lottery.class.php

@@ -0,0 +1,157 @@
+<?php
+
+class lottery
+{
+    public static function getLotterys()
+    {
+        db::query("SELECT "
+            . "" . DB_T_LOTTERY . ".id, "
+            . "" . DB_T_LOTTERY . ".md5, "
+            . "" . DB_T_LOTTERY . ".titre, "
+            . "" . DB_T_LOTTERY . ".description, "
+            . "" . DB_T_LOTTERY . ".sortDate, "
+            . "COUNT(" . DB_T_LOTTERY_INSCRITS . ".login) AS m_inscrits, "
+            . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 1, 1, 0)) AS m_eligible, "
+            . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 0, 1, 0)) AS m_ineligible, "
+            . "COUNT(" . DB_T_LOTTERY_INSCRITS . ".selected) AS m_selected, "
+            . "" . DB_T_LOTTERY . ".cree, "
+            . "" . DB_T_LOTTERY . ".maj, "
+            . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user' "
+            . "FROM " . DB_T_LOTTERY . " "
+            . "LEFT JOIN " . DB_T_LOTTERY_INSCRITS . " ON " . DB_T_LOTTERY_INSCRITS . ".id_lottery = " . DB_T_LOTTERY . ".id "
+            . "INNER JOIN " . DB_T_USER . " ON " . DB_T_LOTTERY . ".id_user = " . DB_T_USER . ".id "
+            . "GROUP BY 1");
+        return db::resultset();
+    }
+
+    public static function getInscription(int $_id){
+        db::query("SELECT "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_lottery, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_salarie, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_presta, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_dossier, "
+                . "IF(" . DB_T_SALARIES . ".actif = 1, 'ACTIF', IF(" . DB_T_SALARIES . ".actif = 0, 'INACTIF', 'ABSENT')) AS actif , "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".login) AS login, "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".prenom) AS prenom, "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".nom) AS nom, "
+                . "IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 1, 'OUI', 'NON') AS valide, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".selected, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".cree, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_user, "
+                . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom ) AS admin, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".cree "
+                . "FROM " . DB_T_LOTTERY_INSCRITS . " "
+                . "INNER JOIN " . DB_T_USER . " ON " . DB_T_LOTTERY_INSCRITS . ".id_user = " . DB_T_USER . ".id "
+                . "LEFT JOIN " . DB_T_SALARIES . " ON " . DB_T_LOTTERY_INSCRITS . ".id_salarie = " . DB_T_SALARIES . ".id "
+                . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery");
+        db::bind(':id_lottery', $_id);
+        return db::resultset();
+    }
+
+    public static function getWinners(int $_id){
+        db::query("SELECT "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_salarie, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_dossier, "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".login) AS login, "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".prenom) AS prenom, "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".nom) AS nom, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".selected "
+                . "FROM " . DB_T_LOTTERY_INSCRITS . " "
+                . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery AND " . DB_T_LOTTERY_INSCRITS . ".selected IS NOT NULL");
+        db::bind(':id_lottery', $_id);
+        return db::resultset();
+    }
+
+    public static function getCloture(int $_id){
+        db::query("SELECT "
+                . DB_T_LOTTERY . ".sortDate, "
+                . DB_T_LOTTERY . ".sortNb, "
+                . "CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'sortBy' "
+                . "FROM " . DB_T_LOTTERY . " "
+                . "INNER JOIN " . DB_T_USER . " ON " . DB_T_LOTTERY . ".id_user = " . DB_T_USER . ".id "
+                . "WHERE " . DB_T_LOTTERY . ".id = :id");
+        db::bind(':id', $_id);
+        return db::single();
+    }
+
+    public static function getSortInscription(int $_id, int $_sort = 0)
+    {
+        if($_sort == 0){
+            $sqlSort = "";
+        } else {
+            $sqlSort = " ORDER BY RAND() LIMIT " . $_sort;
+        }
+        
+        db::query("SELECT "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_lottery, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_salarie, "
+                . "" . DB_T_LOTTERY_INSCRITS . ".id_dossier, "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".login) AS login, "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".prenom) AS prenom, "
+                . "UCASE(" . DB_T_LOTTERY_INSCRITS . ".nom) AS nom "
+                . "FROM " . DB_T_LOTTERY_INSCRITS . " "
+                . "INNER JOIN " . DB_T_SALARIES . " ON " . DB_T_LOTTERY_INSCRITS . ".id_salarie = " . DB_T_SALARIES . ".id "
+                . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery AND " . DB_T_SALARIES . ".actif = 1" . $sqlSort);
+        db::bind(':id_lottery', $_id);
+        return db::resultset();
+    }
+
+    public static function setSortLottery(int $_idDossier)
+    {
+        db::query("UPDATE " . DB_T_LOTTERY_INSCRITS . " "
+                . "SET " . DB_T_LOTTERY_INSCRITS . ".selected = CURRENT_TIMESTAMP() "
+                . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_dossier = :id_dossier");
+        db::bind(':id_dossier', $_idDossier);
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            alert::recError("ERREUR TECHNIQUE : Au niveau de l'écriture en base de données lors du tirage au sort");
+            return FALSE;
+        }
+    }
+
+    public static function setDateLottery(int $_id, int $_nb)
+    {
+        db::query("UPDATE " . DB_T_LOTTERY . " "
+                . "SET " . DB_T_LOTTERY . ".sortDate = CURRENT_TIMESTAMP(), "
+                . DB_T_LOTTERY . ".sortNb = :sortNb, "
+                . DB_T_LOTTERY . ".sortBy = :sortBy "
+                . "WHERE " . DB_T_LOTTERY . ".id = :id");
+        db::bind(':sortNb', $_nb);
+        db::bind(':sortBy', session::getId());
+        db::bind(':id', $_id);
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            alert::recError("ERREUR TECHNIQUE : Au niveau de l'écriture en base de données lors de la datation");
+            return FALSE;
+        }
+    }
+
+    public static function getInscriptionData(int $_id)
+    {
+        db::query("SELECT "
+        . "COUNT(" . DB_T_LOTTERY_INSCRITS . ".login) AS inscrits, "
+        . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 1, 1, 0)) AS eligible, "
+        . "SUM(IF(" . DB_T_LOTTERY_INSCRITS . ".valide = 0, 1, 0)) AS ineligible "
+        . "FROM " . DB_T_LOTTERY_INSCRITS . " "
+        . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery");
+        db::bind(':id_lottery', $_id);
+        return db::single();
+    }
+
+    public static function getFiche(int $_id)
+    {
+        db::query("SELECT * FROM " . DB_T_LOTTERY . " WHERE id = :id");
+        db::bind(':id', $_id);
+        return db::single();
+    }
+
+    public static function lastLottery()
+    {
+        db::query("SELECT MAX(id) AS id FROM " . DB_T_LOTTERY);
+        return db::single()["id"];
+    }
+}

+ 9 - 0
core/json/cms.lottery-inscrits.php

@@ -0,0 +1,9 @@
+<?php 
+
+$row = lottery::getInscription(core::getGet("id"));
+if (!empty($row)) {
+    echo json_encode($row);
+    exit();
+} else {
+    exit();
+}

+ 9 - 0
core/json/cms.lottery-winners.php

@@ -0,0 +1,9 @@
+<?php 
+
+$row = lottery::getWinners(core::getGet("id"));
+if (!empty($row)) {
+    echo json_encode($row);
+    exit();
+} else {
+    exit();
+}

+ 115 - 0
core/submit/cms.lottery-import-inscription.php

@@ -0,0 +1,115 @@
+<?php
+
+if (core::ifPost("from") AND core::getPost("from") == "lottery-import-inscription") {
+
+    if(lottery::getCloture(core::getPost("lottery"))["sortDate"] != NULL){
+        alert::recError("Action annulée car le tirage au sort a déjà été réalisé.");
+        header("Location: /lottery-".core::getPost("lottery").".html");
+        exit();
+    }
+
+    if (isset($_FILES[core::getPost("from")]['error']) AND $_FILES[core::getPost("from")]['error'] > 0) {
+
+        switch ($_FILES[core::getPost("from")]['error']) {
+            case 1: // UPLOAD_ERR_INI_SIZE
+                alert::recError("Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !");
+                break;
+            case 2: // UPLOAD_ERR_FORM_SIZE
+                alert::recError("Le fichier dépasse la limite autorisée dans le formulaire HTML !");
+                break;
+            case 3: // UPLOAD_ERR_PARTIAL
+                alert::recError("L'envoi du fichier a été interrompu pendant le transfert !");
+                break;
+            case 4: // UPLOAD_ERR_NO_FILE
+                alert::recError("Vous n'avez pas chargé de fichier");
+                break;
+        }
+    } elseif ($_FILES[core::getPost("from")]['type'] != "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
+        alert::recError("Seuls les fichiers Excel au format xlsx sont acceptés (".$_FILES[core::getPost("from")]['type'].")");
+        header("Location: /lottery-".core::getPost("lottery").".html");
+        exit();
+    } else {
+
+        if (file_exists($_FILES[core::getPost("from")]['tmp_name'])) {
+
+            $simpleXLSX = new simpleXLSX();
+            $xlsx = $simpleXLSX->parse($_FILES[core::getPost("from")]['tmp_name']);
+            $returnXlsx = $xlsx->rows();
+
+            if(     $returnXlsx[0][0] != "prest_id" 
+                    OR $returnXlsx[0][1] != "doss_id" 
+                    OR $returnXlsx[0][2] != "od_matricule"
+                    OR $returnXlsx[0][3] != "od_prenom"
+                    OR $returnXlsx[0][4] != "od_nom"
+                    OR $returnXlsx[0][5] != "od_email_prof"
+                    ){ echo "error";
+                alert::recError("Le fichier " . $_FILES[core::getPost("from")]['name'] . " n'est pas un fichier d'inscription à un tirage au sort.");
+                header("Location: /lottery-".core::getPost("lottery").".html");
+                exit();
+            }
+
+            $nbSalaries = count($returnXlsx) - 1;
+            
+            foreach ($returnXlsx as $key => $ligne) {   
+                if($key > 0){
+                    $salarie = salaries::get_salarieByLoginId(strtoupper($ligne[2]));
+
+                    if(isset($salarie["id"])){
+                        $tmp_id_salarie = $salarie["id"];
+                        $tmp_id_presta = $ligne[0];
+                        $tmp_id_dossier = $ligne[1];
+                        $tmp_login = $salarie["loginId"];
+                        $tmp_prenom = $salarie["prenom"];
+                        $tmp_nom = $salarie["nom"];
+                        $tmp_valide = $salarie["actif"];
+                    } else {
+                        $tmp_id_salarie = NULL;
+                        $tmp_id_presta = $ligne[0];
+                        $tmp_id_dossier = $ligne[1];
+                        $tmp_login = $ligne[2];
+                        $tmp_prenom = $ligne[3];
+                        $tmp_nom = $ligne[4];
+                        $tmp_valide = 0;
+                    }
+
+                    db::query("INSERT INTO " . DB_T_LOTTERY_INSCRITS . " 
+                        (id_lottery, id_salarie, id_presta, id_dossier, login, prenom, nom, valide, id_user) 
+                        VALUES (:id_lottery, :id_salarie, :id_presta, :id_dossier, :login, :prenom, :nom, :valide, :id_user) 
+                        ON DUPLICATE KEY UPDATE id_salarie = :id_salarie, login = :login, prenom = :prenom, nom = :nom, valide = :valide");
+                    db::bind(':id_lottery', core::getPost("lottery"));
+                    db::bind(':id_salarie', $tmp_id_salarie);
+                    db::bind(':id_presta', $tmp_id_presta);
+                    db::bind(':id_dossier', $tmp_id_dossier);
+                    db::bind(':login', $tmp_login);
+                    db::bind(':prenom', $tmp_prenom);
+                    db::bind(':nom', $tmp_nom);
+                    db::bind(':valide', $tmp_valide);
+                    db::bind(':id_user', session::getId());
+                    try {
+                        db::execute();
+                        if($tmp_valide == 1) { 
+                            alert::recSuccess("Inscription éligible de " . $tmp_prenom . " " . $tmp_nom); 
+                        } else {
+                            alert::recError("Inscription non éligible de " . $tmp_prenom . " " . $tmp_nom); 
+                        }
+                    } catch (Exception $ex) {
+                        alert::recError("ERREUR TECHNIQUE : ".$tmp_prenom . " " . $tmp_nom . " n'a pas pu être importé");
+                    }
+                }
+
+            }
+            
+            header("Location: /lottery-".core::getPost("lottery").".html");
+            exit();
+        } else {
+            alert::recError("Erreur lors du chargement du fichier : " . $_FILES[core::getPost("from")]['name']);
+        }
+    }
+
+    header("Location: /lottery-".core::getPost("lottery").".html");
+    exit();
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}
+

+ 23 - 0
core/submit/cms.lottery-winners.php

@@ -0,0 +1,23 @@
+<?php
+
+if (core::ifPost("from") AND core::getPost("from") == "lottery-winners") {
+
+    $tirageAuSort = lottery::getSortInscription(core::getPost("lottery"), core::getPost("nb_winners"));
+
+    foreach ($tirageAuSort as $value) {
+        if(lottery::setSortLottery($value["id_dossier"]) == TRUE){
+            alert::recSuccess($value["prenom"] . " " . $value["nom"] . " vient d'être tiré au sort."); 
+        }
+    }
+
+    if(lottery::setDateLottery(core::getPost("lottery"), core::getPost("nb_winners")) == TRUE){
+        alert::recSuccess("Le tirage au sort est terminé."); 
+    }
+
+    header("Location: /lottery-".core::getPost("lottery").".html");
+    exit();
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}
+

+ 51 - 0
core/submit/cms.lottery.php

@@ -0,0 +1,51 @@
+<?php
+
+if(core::getPost("id") == "add"){
+    
+    db::query("INSERT INTO " . DB_T_LOTTERY . " (md5, titre, description, id_user) VALUES (:md5, :titre, :description, :id_user)");
+
+    db::bind(':md5', md5(time().rand(1000000000, 9999999999)));
+    db::bind(':titre', core::getPost("titre"));
+    db::bind(':description', core::getPost("description"));
+    db::bind(':id_user', session::getId());
+    
+    try {
+            db::execute();
+            alert::recSuccess("Le tirage au sort a bien été créé");
+        } catch (Exception $ex) {
+            alert::recError("Erreur lors de l'enregistrement du tirage au sort");
+            header("Location: /add-lottery.html");
+            exit();
+        }
+    
+    header("Location: /lottery-" . lottery::lastLottery().".html");
+    exit();
+    
+} else {
+    
+        db::query("UPDATE " . DB_T_LOTTERY . " SET "
+                . "titre = :titre, "
+                . "description = :description, "
+                . "sortDate = :sortDate, "
+                . "id_user = :id_user "
+                . "WHERE id = :id");
+        
+        db::bind(':titre', core::getPost("titre"));
+        db::bind(':description', core::getPost("description"));
+        db::bind(':sortDate', core::getPost("sortDate"));
+        db::bind(':id_user', session::getId());
+        db::bind(':id', core::getPost("id"));
+        
+        try {
+            db::execute();
+            alert::recSuccess("Le tirage au sort a bien été modifié");
+        } catch (Exception $ex) {
+            alert::recError("Erreur lors de la modification le tirage au sort");
+            header("Location: /lottery-" . core::getPost("id").".html");
+            exit();
+        }
+
+        header("Location: /lottery-" . core::getPost("id").".html");
+        exit();
+
+}

+ 3 - 3
core/views/_cms.foot.php

@@ -1,7 +1,7 @@
     
     
     </main>
-  </div>
+    </div>
 </div>
 
 <script src="libs/bootstrap/assets/dist/js/bootstrap.bundle.min.js" type="text/javascript"></script>
@@ -16,8 +16,8 @@
 
 <script>
     $(document).ready(function(){
-       feather.replace();
-       $('.toast').toast('show');
+        feather.replace();
+        $('.toast').toast('show');
     });
     
     function loading(){

+ 1 - 0
core/views/_cms.menu.php

@@ -26,6 +26,7 @@
                 if(session::accessUserByType(1)){ 
                     core::elementMenuH6("Evènements");
                     core::elementMenu("evenements", "/evenements.html", "Listes des évènements", "calendar");
+                    core::elementMenu("lotterys", "/lotterys.html", "Listes des tirages au sort", "zap");
                 }
                 
                 if(session::accessUserByType(1)){ 

+ 0 - 1
core/views/pages/cms.evenement-inscrits.php

@@ -19,7 +19,6 @@
     data-pagination="true"
     data-filter-control="true"
     data-flat="true"
-    data-search="true"
     data-url="/json.php?jsonData=event-inscrits&id=<?php echo core::getGet("id") ?>">
     <thead>
         <tr>

+ 0 - 1
core/views/pages/cms.evenement-salaries.php

@@ -15,7 +15,6 @@ if(core::ifGet("id")){
     data-pagination="true"
     data-filter-control="true"
     data-flat="true"
-    data-search="true"
     data-url="/json.php?jsonData=event-salaries&id=<?php echo core::getGet("id") ?>">
     <thead>
         <tr>

+ 0 - 1
core/views/pages/cms.evenements.php

@@ -28,7 +28,6 @@
         data-pagination="true"
         data-filter-control="true"
         data-flat="true"
-        data-search="true"
         data-sort-name="cree"
         data-sort-order="desc"
         data-url="/json.php?file=events">

+ 46 - 0
core/views/pages/cms.lottery-fiche.php

@@ -0,0 +1,46 @@
+<?php
+if(core::ifGet("add")) {
+    $id_form = '<input type="hidden" name="id" value="add">';
+    $submit = "Ajouter un tirage au sort";
+} else {
+    $databaseLottery = new lottery();
+    $lottery = $databaseLottery->getFiche(core::getGet("id"));
+    $submit = "Modifier ce tirage au sort";
+    $id_form = '<input type="hidden" name="id" value="' . $lottery["id"] . '">';
+}
+
+?>
+
+<br />
+
+<form method="post" action="/submit.php">
+
+    <input type="hidden" name="from" value="lottery">
+    
+    <?php
+        echo $id_form;
+    ?>
+
+    <div class="form-group">
+        <label>Titre</label>
+        <input type="text" class="form-control" value="<?php
+        if (isset($lottery["titre"])) {
+            echo $lottery["titre"];
+        }
+        ?>" name="titre" placeholder="" required>
+    </div>
+    <br />
+
+    <div class="form-group">
+        <label>Description</label>
+        <textarea class="form-control" name="description" style="height:100%;"><?php
+        if (isset($lottery["description"])) {
+            echo $lottery["description"];
+        }
+        ?></textarea>
+    </div>
+    <br />
+    
+    <input class="btn btn-primary btn-lg" style="width: 100%" type="submit" value="<?php echo $submit ?>">
+    
+</form>

+ 44 - 0
core/views/pages/cms.lottery-inscrits.php

@@ -0,0 +1,44 @@
+<div style="float:right; margin-top: -60px;">
+<?php 
+    $lottery = lottery::getFiche(core::getGet("id"));
+    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"><span data-feather="download"></span> Importer les inscrits</button></a>
+<?php } ?>
+</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="/json.php?jsonData=lottery-inscrits&id=<?php echo core::getGet("id") ?>">
+    <thead>
+        <tr>
+            <th data-sortable="true" data-field="id_presta" data-width="50" data-formatter="selectPrestation">Id Prestation</th>
+            <th data-sortable="true" data-field="id_dossier" data-filter-control="input" data-width="50" data-formatter="selectDossier">Id 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">Base RH</th>
+            <th data-sortable="true" data-field="valide" data-filter-control="select">Eligible</th>
+            <th data-sortable="true" data-field="login" data-filter-control="input">Login</th>
+            <th data-sortable="true" data-field="prenom" data-filter-control="input">Prénom</th>
+            <th data-sortable="true" data-field="nom" data-filter-control="input">Nom</th>
+            <th data-sortable="true" data-field="admin" data-filter-control="select">Chargé par</th>
+            <th data-sortable="true" data-field="cree">Le</th>
+        </tr>
+    </thead>
+</table> 
+
+<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>

+ 43 - 0
core/views/pages/cms.lottery-upload-excel.php

@@ -0,0 +1,43 @@
+<?php 
+    $lottery = lottery::getFiche(core::getGet("id"))["sortDate"];
+    if($lottery["sortDate"] != NULL){
+        alert::recError("Action annulée car le tirage au sort a déjà été réalisé.");
+        echo '<script>window.location.replace("/lottery-'.core::getGet("id").'.html");</script>';
+        exit();
+    }
+?>
+<link rel="stylesheet" href="css/dragAndDrop.css">
+
+<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
+    <h2 class="bd-title" id="content">
+        <span>Tirage au sort : Importer un fichier Excel</span>
+    </h2>
+</header>
+<?php   
+        echo core::filAriane(array(
+            "current" => "Importer un fichier Excel", 
+            "arbo" => array( 
+                "Tirage au sort" => NULL,
+                "[#" . $lottery["id"] . "] " . $lottery["titre"] => "/lottery-" . core::getGet("id") . ".html",
+                "Importer un fichier Excel" => NULL)
+        )); 
+?>
+<br />
+<form action="/submit.php" method="post" enctype="multipart/form-data" onsubmit="loading()">
+    <input type="hidden" name="from" value="lottery-import-inscription"> 
+    <input type="hidden" name="lottery" value="<?php echo $lottery["id"] ?>">
+    <div class="file-drop-area">
+        <span class="choose-file-button">Choisissez votre fichier Excel (XLSX)</span>
+        <span class="file-message">ou déposez le dans cette zone</span>
+        <input id="lottery-import-inscription" class="import-excel" name="lottery-import-inscription" type="file" onchange="dargAndDrop()">
+    </div>
+    <br />
+    <input class="btn btn-primary btn-lg" style="width: 100%" type="submit" value="Charger le fichier excel">
+</form>
+
+<script>
+    function dargAndDrop(){    
+        var fileName = $("#lottery-import-inscription").val().split('\\').pop();
+        $(".file-message").text($(".file-message").text().replace("ou déposez le dans cette zone", "Fichier prêt à être chargé : "+fileName));
+    }
+</script>

+ 138 - 0
core/views/pages/cms.lottery-winners.php

@@ -0,0 +1,138 @@
+<?php
+$dataLottery = lottery::getInscriptionData(core::getGet("id"));
+$sortLottery = lottery::getCloture(core::getGet("id"));
+?>
+<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"];
+                                            }
+                                            ?>" 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"];
+                                            }
+                                            ?>" style="background-color:#f8d7da; color:red;" class="form-control text-center" disabled>
+            </div>
+        </div>
+    </div>
+</div>
+
+<br />
+
+<?php
+if($sortLottery["sortDate"] == NULL) {
+?>
+<div class="card text-center">
+    <div class="card-header" style="font-size: 1.3em;">
+    Combien de personnes doivent être tirées au sort ?
+    </div>
+    <div class="card-body">
+
+        <form method="post" action="/submit.php">
+
+            <input type="hidden" name="from" value="lottery-winners">
+            <input type="hidden" name="lottery" value="<?php echo core::getGet("id") ?>">
+
+            <div class="form-group">
+                <label>Saisissez un nombre entre 1 et <?php echo $dataLottery["eligible"] ?></label>
+                <input type="number" pattern="\d*" min="1" max="<?php echo $dataLottery["eligible"] ?>" style="font-size:30px" value="" class="form-control text-center" name="nb_winners" required>
+            </div>
+            <br />
+            
+            <input class="btn btn-primary btn-lg" style="width: 100%" type="submit" value="Tirer au sort">
+
+        </form>
+    </div>
+</div>
+<?php
+} else {
+?>
+<div class="card text-center" style="border-color:green;">
+    <div class="card-header" style="font-size: 1.3em; background-color:#d4edda; color:green;">
+    Résultat du tirage au sort
+    </div>
+    <div class="card-body">
+        <div class="row">
+            <div class="col">
+                <label style="color: gray;">Date du tirage au sort</label>
+                <input type="text" value="<?php
+                                            if (isset($sortLottery["sortDate"])) {
+                                                echo $sortLottery["sortDate"];
+                                            }
+                                            ?>" class="form-control text-center" disabled>
+            </div>
+            <div class="col">
+                <label style="color: gray;">Réalisé par</label>
+                <input type="text" value="<?php
+                                            if (isset($sortLottery["sortBy"])) {
+                                                echo $sortLottery["sortBy"];
+                                            }
+                                            ?>" class="form-control text-center" disabled>
+            </div>
+            <div class="col">
+                <label style="color: gray;">Paramètre</label>
+                <input type="text" value="<?php
+                                            if (isset($sortLottery["sortNb"])) {
+                                                if($sortLottery["sortNb"] > 1){ echo $sortLottery["sortNb"] . " gagnants"; }
+                                                else { echo $sortLottery["sortNb"] . " gagnant"; }
+                                            }
+                                            ?>" class="form-control text-center" disabled>
+            </div>
+        </div>
+        <br />
+        <table
+            id="table"
+            class="table-striped table-hover table-sm" 
+            data-page-size="25"
+            data-toggle="table"
+            data-buttons-align="left"
+            data-pagination="true"
+            data-filter-control="true"
+            data-flat="true"
+            data-url="/json.php?jsonData=lottery-winners&id=<?php echo core::getGet("id") ?>">
+            <thead>
+                <tr>
+                    <th data-sortable="true" data-field="id_dossier" data-filter-control="input" data-width="50" data-formatter="selectDossier">Id 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="login" data-filter-control="input">Login</th>
+                    <th data-sortable="true" data-field="prenom" data-filter-control="input">Prénom</th>
+                    <th data-sortable="true" data-field="nom" data-filter-control="input">Nom</th>
+                    <th data-sortable="true" data-field="selected">Date du tirage</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>
+
+<?php
+}
+?>

+ 138 - 0
core/views/pages/cms.lottery.php

@@ -0,0 +1,138 @@
+<?php
+
+
+if (core::getGet("id") == NULL) {
+    $titre = "Ajouter un tirage au sort";
+} else {
+    $lottery = lottery::getFiche(core::getGet("id"));
+    if(empty($lottery["id"])){
+        get::page("unknow");
+        exit();
+    }
+    
+    $badgeCSS = " font-size:0.4em; margin-top:-5px;";
+        
+    $titre = "[#" . $lottery["id"] . "] " . $lottery["titre"];
+}
+
+$tab_fiche = $tab_inscrits = $tab_winners = "false";
+
+if(alert::ifTab()){
+
+    switch (alert::getTab()) {
+        case "inscrits-tab":
+            $tab_inscrits = "true";
+            break;
+        case "winners-tab":
+            $tab_winners = "true";
+            break;
+        default:
+            $tab_fiche = "true";
+            break;
+    }
+    
+} else {
+    $tab_fiche = "true";
+}
+
+?>
+
+<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
+
+    <div class="row" style="width:100%;">
+        <div class="col-11">
+            <h2 class="bd-title" id="content">
+                <?php echo $titre ?>
+            </h2>
+        </div>
+        <?php if(isset($user["id"]) AND session::getId() != $user["id"]){ ?>
+            <div style="float:right; margin: -30px;">
+                <a href="/submit.php?from=lottery-delete&id=<?php echo $lottery["id"] ?>" onclick="return confirm('Voulez-vous supprimer ce tirage au sort ?')" style="position: absolute; right: 0; margin: 0 40px 0 0;"><button type="submit" class="btn btn-outline-danger btn-sm"><span data-feather="trash-2"></span> Supprimer</button></a>
+            </div>
+        <?php } ?>
+    </div>
+</header>
+<?php 
+        if(core::ifGet("add")) {
+            $labelFil = "Ajouter un tirage au sort";
+            $lienFil = "/?p=lottery&add=1";
+        } else {
+            $labelFil = "[#" . $lottery["id"] . "] " . $lottery["titre"];
+            $lienFil = "/lottery-".core::getGet("id").".html";
+        }
+        echo core::filAriane(array(
+            "current" => $labelFil, 
+            "arbo" => array( 
+                "Tirage au sort" => NULL,
+                "Listes des tirages au sort" => "/lotterys.html",
+                $labelFil => $lienFil)
+        )); 
+?>
+<br />
+    <ul class="nav nav-tabs" id="event-fiche" role="tablist">
+        <li class="nav-item">
+            <a class="nav-link<?php if($tab_fiche == "true"){ echo ' active'; } if(empty($lottery["id"])){ echo " disabled"; } ?>" data-toggle="tab" id="fiche-tab" role="tab" aria-selected="<?php echo $tab_fiche ?>">Fiche du tirage au sort</a>
+        </li>
+<?php if(isset($lottery["id"])){ ?>
+        <li class="nav-item">
+            <a class="nav-link<?php if($tab_inscrits == "true"){ echo ' active'; } if(empty($lottery["id"])){ echo " disabled"; } ?>" data-toggle="tab" id="inscrits-tab" role="tab" aria-selected="<?php echo $tab_inscrits ?>">Inscriptions</a>
+        </li>    
+        <li class="nav-item">
+            <a class="nav-link<?php if($tab_winners == "true"){ echo ' active'; } if(empty($lottery["id"])){ echo " disabled"; } ?>" data-toggle="tab" id="winners-tab" role="tab" aria-selected="<?php echo $tab_winners ?>">Tirage au sort</a>
+        </li>
+<?php } ?>
+    </ul>
+<br />
+
+<div class="tab-content">
+
+    <div id="tab-fiche"<?php if($tab_fiche == "false"){ echo ' style="display: none;"'; } ?>> 
+        <?php get::page("lottery-fiche") ?> 
+    </div>
+<?php if(isset($lottery["id"])){ ?>
+    <div id="tab-inscrits"<?php if($tab_inscrits == "false"){ echo ' style="display: none;"'; } ?>>
+        <?php get::page("lottery-inscrits") ?>
+    </div>
+    <div id="tab-winners"<?php if($tab_winners == "false"){ echo ' style="display: none;"'; } ?>>
+        <?php get::page("lottery-winners") ?>
+    </div> 
+<?php } ?>
+    
+</div>
+
+<script>
+    $(document).ready(function(){
+    
+        $("#fiche-tab").click(function() {
+            $("#tab-fiche").show();
+            $("#tab-inscrits").hide();
+            $("#tab-winners").hide();
+        });
+<?php if(isset($lottery["id"])){ ?>       
+        $("#inscrits-tab").click(function() {
+            $("#tab-fiche").hide();
+            $("#tab-inscrits").show();
+            $("#tab-winners").hide();
+        });    
+        $("#winners-tab").click(function() {
+            $("#tab-fiche").hide();
+            $("#tab-inscrits").hide();
+            $("#tab-winners").show();
+        });
+<?php } ?>
+    })
+    
+    
+</script>
+
+<?php if(isset($lottery["id"]) AND isset($lottery["type_emargement"]) AND $lottery["type_emargement"] != 1){ ?>
+<div class="modal fade" id="QRCodeModal" tabindex="-1" role="dialog" aria-hidden="true">
+    <div class="modal-dialog modal-dialog-centered" role="document">
+        <div class="modal-content">
+            <div class="modal-body">
+                <?php event::getQRCode($lottery["id"], "100%") ?>
+            </div>
+        </div>
+    </div>
+</div>
+<?php } ?>

+ 54 - 0
core/views/pages/cms.lotterys.php

@@ -0,0 +1,54 @@
+<?php
+    json::create("lotterys");
+?>
+
+<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 tirages au sort</span>
+    <a href="/?p=lottery&add=1" style="position: absolute; right: 0; margin: 0 40px 0 0;"><button type="submit" class="btn btn-outline-success btn-sm"><span data-feather="plus-square"></span> Ajouter un tirage au sort</button></a>
+</h2>
+</header>
+<?php   
+        echo core::filAriane(array(
+            "current" => "Listes des tirages au sort", 
+            "arbo" => array( 
+                "Tirages au sort" => NULL,
+                "Listes des tirages au sort" => "/lotterys.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="/json.php?file=lotterys">
+        <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="m_inscrits" data-filter-control="input" data-width="50">Nb. Inscrit</th>
+                <th data-sortable="true" data-field="m_eligible" data-filter-control="input" data-width="50">Nb. Eligibles</th>
+                <th data-sortable="true" data-field="m_ineligible" data-filter-control="input" data-width="50">Nb. Non éligibles</th>
+                <th data-sortable="true" data-field="m_selected" data-filter-control="select" data-width="160">Nb. Sélectionnés</th>
+                <th data-sortable="true" data-field="sortDate" data-filter-control="input" data-width="160">Date du tirage au sort</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="/lottery-' + row.id + '.html"><button type="submit" class="btn btn-outline-primary btn-sm">Ouvrir</button></a>';
+    }
+</script>

+ 0 - 1
core/views/pages/cms.proweb-historique-excel.php

@@ -25,7 +25,6 @@
         data-pagination="true"
         data-filter-control="true"
         data-flat="true"
-        data-search="true"
         data-sort-name="cree"
         data-sort-order="desc"
         data-url="/json.php?file=excel-proweb">

+ 0 - 1
core/views/pages/cms.proweb-salaries.php

@@ -29,7 +29,6 @@
         data-pagination="true"
         data-filter-control="true"
         data-flat="true"
-        data-search="true"
         data-show-columns-toggle-all="true"
         data-url="/json.php?file=salaries-proweb">
         <thead>

+ 0 - 1
core/views/pages/cms.rh-historique-excel.php

@@ -29,7 +29,6 @@
         data-pagination="true"
         data-filter-control="true"
         data-flat="true"
-        data-search="true"
         data-sort-name="cree"
         data-sort-order="desc"
         data-url="/json.php?file=excel">

+ 0 - 1
core/views/pages/cms.rh-liste-salaries.php

@@ -28,7 +28,6 @@
         data-pagination="true"
         data-filter-control="true"
         data-flat="true"
-        data-search="true"
         data-url="/json.php?file=salaries">
         <thead>
             <tr>

+ 76 - 26
public-cms/test.php

@@ -1,39 +1,89 @@
 <?php
 session_start();
 
-$_SESSION["debug"] = 1;
-
-require_once "../env.inc.php";
-require_once "../access.inc.php";
-require_once "../conf.inc.php";
-require_once DIR_PHP_LAYOUTS . "header.php";
-
 error_reporting(E_ALL);
 ini_set('display_errors', 1);
 
-core::removeFileMaintenance();
-echo core::isMaintenance();
+$test = 2;
+
+if($test == 1) {
+    define("SFTP_HOST", "home595637013.1and1-data.host");
+    define("SFTP_USER", "u543064336");
+    define("SFTP_PASS", "1wx3c4cdfv6sz");
+    define("SFTP_REMOTE", "/");
+} else {
+    define("SFTP_HOST", "46.105.33.123");
+    define("SFTP_USER", "sftp_35034");
+    define("SFTP_PASS", "4ALSyzu43tDh5hVQ82kL29");
+    define("SFTP_REMOTE", "/import/");
+}
 
-// echo backup::create();
+define("DOCUMENT_ROOT", "/var/www/dev.cms.cse-invent.com/");
+define("SFTP_LOCAL", DOCUMENT_ROOT . "datas/sftp/");
 
-// echo backup::restore("/var/www/dev.cms.cse-invent.com/backups/20230503-124717.zip");
+$authent = "";
 
-/*
-function test($_host) {
-    echo "<div>";
-    echo "<h3>" . $_host . "</h3>";
-    echo "<div>";
+echo SFTP_LOCAL;
+
+///////////////////////////////////////////////////////////////////////////////////////////
+
+function testSFTP(){
     $originalConnectionTimeout = ini_get('default_socket_timeout');
     ini_set('default_socket_timeout', 2);
-    echo (@ssh2_connect($_host, 22, array("hostkey" => "ssh-dsa"))) ? "Connexion OK" : "Connexion KO";
-    ini_set('default_socket_timeout', $originalConnectionTimeout);
-    echo "</div>";
-    echo "</div>";
+    if ($authent = @ssh2_connect(SFTP_HOST, 22)) {
+        ini_set('default_socket_timeout', $originalConnectionTimeout);
+        echo "<div>Accès serveur OK</div>";
+    } else {
+        echo "<div>Accès serveur en erreur</div>";
+    }
+
+    if (@ssh2_auth_password($authent, SFTP_USER, SFTP_PASS)) {
+        echo "<div>Authentification OK</div>";
+    } else {
+        echo "<div>Authentification En erreur</div>";
+    }
+
+    if ($connexion = @ssh2_sftp($authent)) {
+        echo "<div>Connexion OK</div>";
+    } else {
+        echo "<div>Connexion En erreur</div>";
+    }
+
+    $stream = @fopen("ssh2.sftp://" . $connexion . SFTP_REMOTE . "test.txt", "w");
+    if ($stream == FALSE){
+        echo "<div>Impossible d'écrire sur le serveur distant</div>";
+    } else {
+        echo "<div>Succès d'écriture sur le serveur distant</div>";
+    }
+
+    $realpath = @ssh2_sftp_realpath($connexion, SFTP_REMOTE);
+    $dir = "ssh2.sftp://" . $connexion . $realpath;
+    $tempArray = array();
+
+    if (is_dir($dir)) {
+        if ($dh = opendir($dir)) {
+            while (($file = readdir($dh)) !== false) {
+                echo $file;
+                $tempFile = NULL;
+                $realpath = @ssh2_sftp_realpath($connexion, $file);
+                $filetype = filetype($dir . $realpath);
+                $size = sprintf("%.2f", filesize($dir . $realpath));
+
+                if ($filetype != "dir") {
+                    $infos = @ssh2_sftp_stat($connexion, SFTP_REMOTE.$file);
+                    $tempFile["file"] = $file;
+                    print_r($infos);
+                    //$tempFile["size"] = $infos["size"];
+                   // $tempFile["date"] = $infos["atime"];
+                    $tempArray[] = $tempFile;
+                }
+            }
+            closedir($dh);
+        }
+    }
+    print_r($tempArray);
 }
 
-test("46.105.33.123"); // ProWeb
-test("home595637013.1and1-data.host"); // 1and1
-test("test.rebex.net"); // 1and1
-test("itcsubmit.wustl.edu"); // 1and1
-test("demo.wftpserver.com"); // 1and1
-*/
+testSFTP();
+
+