Browse Source

Clean Code

stany.ferer 2 years ago
parent
commit
768eb1def8

+ 24 - 0
core/class/alert.class.php

@@ -10,6 +10,14 @@ class alert
         array_push($_SESSION["alert"]["success"], $_string);
     }
 
+    public static function recWarning(string $_string)
+    {
+        if (empty($_SESSION["alert"]["warning"])) {
+            $_SESSION["alert"]["warning"] = array();
+        }
+        array_push($_SESSION["alert"]["warning"], $_string);
+    }
+
     public static function recError(string $_string)
     {
         if (empty($_SESSION["alert"]["error"])) {
@@ -32,6 +40,15 @@ class alert
         }
     }
 
+    public static function getWarning()
+    {
+        if (!empty($_SESSION["alert"]["warning"])) {
+            return $_SESSION["alert"]["warning"];
+        } else {
+            return FALSE;
+        }
+    }
+
     public static function getError()
     {
         if (!empty($_SESSION["alert"]["error"])) {
@@ -103,6 +120,13 @@ class alert
                 self::printToast($style, $icon, $texte);
             }
 
+            if (self::getWarning()) {
+                $style = 'background:#fff3cd;';
+                $icon = '<span data-feather="alert-circle" style="color:orange;"></span> <strong style="color:orange; margin-left:5px;" class="mr-auto">Attention</strong>';
+                $texte = self::getWarning();
+                self::printToast($style, $icon, $texte);
+            }
+
             if (self::getError()) {
                 $style = 'background:#f8d7da;';
                 $icon = '<span data-feather="alert-triangle" style="color:red;"></span> <strong style="color:red; margin-left:5px;" class="mr-auto">Erreur</strong>';

+ 91 - 4
core/class/event.class.php

@@ -31,6 +31,95 @@ class event
         }
     }
 
+    public static function add()
+    {
+        db::query("INSERT INTO " . DB_T_EVENTS . " (md5, titre, description, startDate, endDate, type_emargement, type_inscription, actif, id_user) VALUES (:md5, :titre, :description, :startDate, :endDate, :type_emargement, :type_inscription, :actif, :id_user)");
+
+        db::bind(':md5', md5(time().rand(1000000000, 9999999999)));
+        db::bind(':titre', core::getPost("titre"));
+        db::bind(':description', core::getPost("description"));
+        db::bind(':startDate', core::getPost("startDate"));
+        db::bind(':endDate', core::getPost("endDate"));
+        db::bind(':type_emargement', core::getPost("type_emargement"));
+        db::bind(':type_inscription', core::getPost("type_inscription"));
+        db::bind(':actif', core::getPost("actif"));
+        db::bind(':id_user', session::getId());
+        
+        try {
+                db::execute();
+                return TRUE;
+            } catch (Exception $ex) {
+                return FALSE;
+            }
+    }
+
+    public static function update()
+    {
+        db::query("UPDATE " . DB_T_EVENTS . " SET "
+                . "titre = :titre, "
+                . "description = :description, "
+                . "startDate = :startDate, "
+                . "endDate = :endDate, "
+                . "type_emargement = :type_emargement, "
+                . "type_inscription = :type_inscription, "
+                . "actif = :actif, "
+                . "id_user = :id_user "
+                . "WHERE id = :id");
+        
+        db::bind(':titre', core::getPost("titre"));
+        db::bind(':description', core::getPost("description"));
+        db::bind(':startDate', core::getPost("startDate"));
+        db::bind(':endDate', core::getPost("endDate"));
+        db::bind(':type_emargement', core::getPost("type_emargement"));
+        db::bind(':type_inscription', core::getPost("type_inscription"));
+        db::bind(':actif', core::getPost("actif"));
+        db::bind(':id_user', session::getId());
+        db::bind(':id', core::getPost("id"));
+        
+        try {
+                db::execute();
+                return TRUE;
+            } catch (Exception $ex) {
+                return FALSE;
+            }
+    }
+
+    public static function subscribe(int $_salarie = NULL)
+    {
+        if($_salarie == NULL){
+            $salarie = core::getPost("salarie");
+        } else {
+            $salarie = $_salarie;
+        }
+        
+        db::query("INSERT INTO " . DB_T_EVENTS_INSCRITS . " (id_evenement, id_salarie, sel, id_user) VALUES (:id_evenement, :id_salarie, :sel, :id_user)");
+        db::bind(':sel', md5(core::getPost("event")."-".time().rand(100000000000000, 999999999999999)));
+        db::bind(':id_evenement', core::getPost("event"));
+        db::bind(':id_salarie', $salarie);
+        db::bind(':id_user', session::getId());
+
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+    public static function unsubscribe()
+    {
+        db::query("DELETE FROM " . DB_T_EVENTS_INSCRITS . " WHERE id_evenement = :id_evenement AND id_salarie = :id_salarie");
+        db::bind(':id_evenement', core::getPost("event"));
+        db::bind(':id_salarie', core::getPost("salarie"));
+
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
     public static function getEvents()
     {
         db::query("SELECT "
@@ -211,6 +300,8 @@ class event
         return db::resultset();
     }
 
+
+
     public static function checkEvenementBySalarie(string $_md5)
     {
 
@@ -250,9 +341,6 @@ class event
         db::bind(':md5', $_md5);
         $evenement = db::single();
 
-        // print_r($inscription); echo "<br />";
-        // print_r($evenement); echo "<br />";
-
         if ($salarie["id"] == NULL) {
             $return["result"] = FALSE;
             $return["description"] = "Vous n'êtes pas un salarié rattaché à notre CSE";
@@ -316,7 +404,6 @@ class event
 
     public static function emargementEvenementByQRCode()
     {
-
         $idSalarie = core::getGet("s");
         $md5Evenement = core::getGet("e");
         $key = core::getGet("k");

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

@@ -97,6 +97,117 @@ class lottery
         return db::resultset();
     }
 
+    public static function insert()
+    {
+        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();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+    public static function update()
+    {
+        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();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+    public static function insertInscription(array $_lottery)
+    {
+        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
+            )");
+        db::bind(':id_lottery', core::getPost("lottery"));
+        db::bind(':id_salarie', $_lottery["id_salarie"]);
+        db::bind(':id_presta', $_lottery["id_presta"]);
+        db::bind(':id_dossier', $_lottery["id_dossier"]);
+        db::bind(':login', $_lottery["login"]);
+        db::bind(':prenom', $_lottery["prenom"]);
+        db::bind(':nom', $_lottery["nom"]);
+        db::bind(':valide', $_lottery["valide"]);
+        db::bind(':id_user', session::getId());
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
+    public static function updateInscription(array $_lottery)
+    {
+        db::query("UPDATE " . DB_T_LOTTERY_INSCRITS . " "
+                . "SET " . DB_T_LOTTERY_INSCRITS . ".login = :login, "
+                . DB_T_LOTTERY_INSCRITS . ".prenom = :prenom, "
+                . DB_T_LOTTERY_INSCRITS . ".nom = :nom, "
+                . DB_T_LOTTERY_INSCRITS . ".valide = :valide, "
+                . DB_T_LOTTERY_INSCRITS . ".id_user = :id_user, "
+                . DB_T_LOTTERY_INSCRITS . ".id_salarie = :id_salarie "
+                . "WHERE " . DB_T_LOTTERY_INSCRITS . ".id_dossier = :id_dossier AND " . DB_T_LOTTERY_INSCRITS . ".id_lottery = :id_lottery");
+        
+        db::bind(':login', $_lottery["login"]);
+        db::bind(':prenom', $_lottery["prenom"]);
+        db::bind(':nom', $_lottery["nom"]);
+        db::bind(':valide', $_lottery["valide"]);
+        db::bind(':id_user', session::getId());
+        db::bind(':id_salarie', $_lottery["id_salarie"]);
+        db::bind(':id_dossier', $_lottery["id_dossier"]);
+        db::bind(':id_lottery', core::getPost("lottery"));
+        db::bind(':id_user', session::getId());
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
     public static function setSortLottery(int $_idDossier)
     {
         db::query("UPDATE " . DB_T_LOTTERY_INSCRITS . " "
@@ -169,4 +280,11 @@ class lottery
         db::query("SELECT MAX(id) AS id FROM " . DB_T_LOTTERY);
         return db::single()["id"];
     }
+
+    public static function searchDossier(int $_id)
+    {
+        db::query("SELECT id_lottery FROM " . DB_T_LOTTERY_INSCRITS. " WHERE id_dossier = :id_dossier");
+        db::bind(':id_dossier', $_id);
+        return db::single()["id_lottery"];
+    }
 }

+ 16 - 57
core/submit/cms.evenement.php

@@ -1,64 +1,23 @@
 <?php
 
 if(core::getPost("id") == "add"){
-    
-    db::query("INSERT INTO " . DB_T_EVENTS . " (md5, titre, description, startDate, endDate, type_emargement, type_inscription, actif, id_user) VALUES (:md5, :titre, :description, :startDate, :endDate, :type_emargement, :type_inscription, :actif, :id_user)");
-
-    db::bind(':md5', md5(time().rand(1000000000, 9999999999)));
-    db::bind(':titre', core::getPost("titre"));
-    db::bind(':description', core::getPost("description"));
-    db::bind(':startDate', core::getPost("startDate"));
-    db::bind(':endDate', core::getPost("endDate"));
-    db::bind(':type_emargement', core::getPost("type_emargement"));
-    db::bind(':type_inscription', core::getPost("type_inscription"));
-    db::bind(':actif', core::getPost("actif"));
-    db::bind(':id_user', session::getId());
-    
-    
-    try {
-            db::execute();
-            alert::recSuccess("L'évènement a bien été créé");
-        } catch (Exception $ex) {
-            alert::recError("Erreur lors de l'enregistrement de l'évènement");
-            header("Location: /add-evenement.html");
-            exit();
-        }
-    
-    header("Location: /evenement-" . event::lastEvenement().".html");
-    exit();
-    
+    if(event::add() == TRUE) {
+        alert::recSuccess("L'évènement a bien été créé");
+        header("Location: /evenement-" . event::lastEvenement().".html");
+        exit();
+    } else {
+        alert::recError("Erreur lors de l'enregistrement de l'évènement");
+        header("Location: /add-evenement.html");
+        exit();
+    }
 } else {
-    
-        db::query("UPDATE " . DB_T_EVENTS . " SET "
-                . "titre = :titre, "
-                . "description = :description, "
-                . "startDate = :startDate, "
-                . "endDate = :endDate, "
-                . "type_emargement = :type_emargement, "
-                . "type_inscription = :type_inscription, "
-                . "actif = :actif, "
-                . "id_user = :id_user "
-                . "WHERE id = :id");
-        
-        db::bind(':titre', core::getPost("titre"));
-        db::bind(':description', core::getPost("description"));
-        db::bind(':startDate', core::getPost("startDate"));
-        db::bind(':endDate', core::getPost("endDate"));
-        db::bind(':type_emargement', core::getPost("type_emargement"));
-        db::bind(':type_inscription', core::getPost("type_inscription"));
-        db::bind(':actif', core::getPost("actif"));
-        db::bind(':id_user', session::getId());
-        db::bind(':id', core::getPost("id"));
-        
-        try {
-            db::execute();
-            alert::recSuccess("L'évènement a bien été modifié");
-        } catch (Exception $ex) {
-            alert::recError("Erreur lors de la modification de l'évènement");
-            header("Location: /evenement-" . core::getPost("id").".html");
-            exit();
-        }
-
+    if(event::update() == TRUE) {
+        alert::recSuccess("L'évènement a bien été modifié");
+        header("Location: /evenement-" . core::getPost("id").".html");
+        exit();
+    } else {
+        alert::recError("Erreur lors de la modification de l'évènement");
         header("Location: /evenement-" . core::getPost("id").".html");
         exit();
     }
+}

+ 6 - 8
core/submit/cms.event-deinscription.php

@@ -1,14 +1,12 @@
 <?php
 
 if(core::ifPost("event") AND core::ifPost("from")){
-    
-    db::query("DELETE FROM " . DB_T_EVENTS_INSCRITS . " WHERE id_evenement = :id_evenement AND id_salarie = :id_salarie");
-    db::bind(':id_evenement', core::getPost("event"));
-    db::bind(':id_salarie', core::getPost("salarie"));
-    db::execute();
-    
-    alert::recSuccess("Désinscription de ". core::getPost("texte"));
-    alert::recTab("inscrits-tab");
+    if(event::unsubscribe() == TRUE) {
+        alert::recSuccess("Désinscription de ". core::getPost("texte"));
+        alert::recTab("inscrits-tab");
+    } else {
+        alert::recError("ERREUR : Désinscription de ". core::getPost("texte"));
+    }
     
     header("Location: /evenement-" . core::getPost("event").".html");
     exit();

+ 2 - 8
core/submit/cms.event-import-inscription.php

@@ -47,15 +47,9 @@ if (core::ifPost("from") AND core::getPost("from") == "event-import-inscription"
                     $salarie = salaries::get_salarieByLoginId($ligne[0]);
                     $titreEvenement = event::getInscriptionEvenementById(core::getPost("event"), $salarie["id"])["titre"];
                     if(empty($titreEvenement) AND isset($salarie["id"])){
-                        db::query("INSERT INTO " . DB_T_EVENTS_INSCRITS . " (id_evenement, id_salarie, sel, id_user) VALUES (:id_evenement, :id_salarie, :sel, :id_user)");
-                        db::bind(':sel', md5(core::getPost("event")."-".time().rand(100000000000000, 999999999999999)));
-                        db::bind(':id_evenement', core::getPost("event"));
-                        db::bind(':id_salarie', $salarie["id"]);
-                        db::bind(':id_user', session::getId());
-                        try {
-                            db::execute();
+                        if(event::subscribe($salarie["id"]) == TRUE){
                             alert::recSuccess("Inscription de " . $salarie["prenom"] . " " . $salarie["nom"]);
-                        } catch (Exception $ex) {
+                        } else {
                             alert::recError($salarie["prenom"] . " " . $salarie["nom"] . " n'a pas pu être importé");
                         }
                     } elseif(empty($salarie["id"])){

+ 6 - 9
core/submit/cms.event-inscription.php

@@ -2,15 +2,12 @@
 
 if(core::ifPost("event") AND core::ifPost("salarie")){
     
-    db::query("INSERT INTO " . DB_T_EVENTS_INSCRITS . " (id_evenement, id_salarie, sel, id_user) VALUES (:id_evenement, :id_salarie, :sel, :id_user)");
-    db::bind(':sel', md5(core::getPost("event")."-".time().rand(100000000000000, 999999999999999)));
-    db::bind(':id_evenement', core::getPost("event"));
-    db::bind(':id_salarie', core::getPost("salarie"));
-    db::bind(':id_user', session::getId());
-    db::execute();
-    
-    alert::recSuccess("Inscription de ". core::getPost("texte"));
-    alert::recTab("salaries-tab");
+    if(event::subscribe() == TRUE){
+        alert::recSuccess("Inscription de ". core::getPost("texte"));
+        alert::recTab("salaries-tab");
+    } else {
+        alert::recError("ERRREUR : Inscription de ". core::getPost("texte"));
+    }
     
     header("Location: /evenement-" . core::getPost("event").".html");
     exit();

+ 0 - 2
core/submit/cms.login.php

@@ -1,11 +1,9 @@
 <?php
 
 if (core::ifPost("from") AND core::getPost("from") == "login") {
-
     user::connect(core::getPost());
     header("Location: /");
     exit();
-
 } else {
     header('HTTP/1.0 401 Unauthorized');
     exit();

+ 37 - 61
core/submit/cms.lottery-import-inscription.php

@@ -55,74 +55,50 @@ if (core::ifPost("from") AND core::getPost("from") == "lottery-import-inscriptio
                     $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"];
+                        $temp["id_salarie"] = $salarie["id"];
+                        $temp["id_presta"] = $ligne[0];
+                        $temp["id_dossier"] = $ligne[1];
+                        $temp["login"] = $salarie["loginId"];
+                        $temp["prenom"] = $salarie["prenom"];
+                        $temp["nom"] = $salarie["nom"];
+                        $temp["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;
+                        $temp["id_salarie"] = NULL;
+                        $temp["id_presta"] = $ligne[0];
+                        $temp["id_dossier"] = $ligne[1];
+                        $temp["login"] = $ligne[2];
+                        $temp["prenom"] = $ligne[3];
+                        $temp["nom"] = $ligne[4];
+                        $temp["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); 
+                    $verifDossierLottery = lottery::searchDossier($temp["id_dossier"]);
+                    if($verifDossierLottery != core::getPost("lottery")){
+                        alert::recError("ERREUR TECHNIQUE : ". $temp["prenom"] . " " . $temp["nom"] . " est déjà inscrit sur un autre tirage au sort");
+                    }
+                    else if($verifDossierLottery == NULL){
+                        if(lottery::insertInscription($temp) == TRUE){
+                            if($temp["valide"] == 1) { 
+                                alert::recSuccess("Inscription éligible de " . $temp["prenom"] . " " . $temp["nom"]); 
+                            } else {
+                                alert::recWarning("Inscription non éligible de " . $temp["prenom"] . " " . $temp["nom"]); 
+                            }
                         } else {
-                            alert::recError("Inscription non éligible de " . $tmp_prenom . " " . $tmp_nom); 
+                            alert::recError("ERREUR TECHNIQUE : ".$temp["prenom"] . " " . $temp["nom"] . " n'a pas pu être importé");
+                        }
+                    }
+                    else{
+                        if(lottery::updateInscription($temp) == TRUE){
+                            if($temp["valide"] == 1) { 
+                                alert::recSuccess("Mise à jour de l'inscription de " . $temp["prenom"] . " " . $temp["nom"]); 
+                            } else {
+                                alert::recWarning("Mise à jour de l'inscription non éligible de " . $temp["prenom"] . " " . $temp["nom"]); 
+                            }
+                        } else {
+                            alert::recError("ERREUR TECHNIQUE : Mise à jour de l'inscription de " . $temp["prenom"] . " " . $temp["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");

+ 16 - 44
core/submit/cms.lottery.php

@@ -1,51 +1,23 @@
 <?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();
-    
+    if(lottery::insert() == TRUE){
+        alert::recSuccess("Le tirage au sort a bien été créé");
+        header("Location: /lottery-" . lottery::lastLottery().".html");
+        exit();
+    } else {
+        alert::recError("Erreur lors de l'enregistrement du tirage au sort");
+        header("Location: /add-lottery.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();
-        }
-
+    if(lottery::update() == TRUE){
+        alert::recSuccess("Le tirage au sort a bien été modifié");
         header("Location: /lottery-" . core::getPost("id").".html");
         exit();
-
+    } else {
+        alert::recError("Erreur lors de la modification le tirage au sort");
+        header("Location: /lottery-" . core::getPost("id").".html");
+        exit();
+    }
 }

+ 0 - 1
core/submit/cms.parametres-add-backup.php

@@ -5,7 +5,6 @@ if (core::ifGet("from")) {
     file::cleanFilesByOrder(DIR_BACKUP, BACKUP_LIMIT);
     header("Location: /parametres.html");
     exit();
-
 } else {
     header('HTTP/1.0 401 Unauthorized');
     exit();

+ 75 - 34
core/views/pages/cms.lottery-inscrits.php

@@ -1,45 +1,86 @@
+<?php
+$lottery = lottery::getFiche(core::getGet("id"));
+$dataLottery = lottery::getInscriptionData(core::getGet("id"));
+?>
 <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"><span data-feather="download"></span> 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 
-    $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 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="/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">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>
-<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">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> 
 
 <script>
-    function selectDossier(value) { 
+    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) { 
+
+    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>

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

@@ -1,44 +1,7 @@
 <?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">

+ 10 - 3
core/views/pages/cms.lottery.php

@@ -13,6 +13,7 @@ if (core::getGet("id") == NULL) {
     $badgeCSS = " font-size:0.4em; margin-top:-5px;";
         
     $titre = "[#" . $lottery["id"] . "] " . $lottery["titre"];
+    $dataLottery = lottery::getInscriptionData(core::getGet("id"));
 }
 
 $tab_fiche = $tab_inscrits = $tab_winners = "false";
@@ -76,11 +77,14 @@ if(alert::ifTab()){
 <?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> 
+<?php 
+    if($dataLottery["inscrits"] > 0) {
+?>   
         <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 } ?>
+<?php } } ?>
     </ul>
 <br />
 
@@ -93,10 +97,13 @@ if(alert::ifTab()){
     <div id="tab-inscrits"<?php if($tab_inscrits == "false"){ echo ' style="display: none;"'; } ?>>
         <?php get::page("lottery-inscrits") ?>
     </div>
+<?php 
+    if($dataLottery["inscrits"] > 0) {
+?>
     <div id="tab-winners"<?php if($tab_winners == "false"){ echo ' style="display: none;"'; } ?>>
         <?php get::page("lottery-winners") ?>
     </div> 
-<?php } ?>
+<?php } } ?>
     
 </div>