Browse Source

Delete lottery

stany.ferer 2 years ago
parent
commit
36d7387f1d

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

@@ -111,6 +111,20 @@ class lottery
         }
     }
 
+    public static function deleteLottery(int $_id)
+    {
+        db::query("DELETE FROM " . DB_T_LOTTERY . " WHERE id = :id");
+        db::bind(':id', $_id);
+        return db::execute();
+    }
+
+    public static function deleteInscriptionLottery(int $_id)
+    {
+        db::query("DELETE FROM " . DB_T_LOTTERY_INSCRITS . " WHERE id_lottery = :id_lottery");
+        db::bind(':id_lottery', $_id);
+        return db::execute();
+    }
+
     public static function setDateLottery(int $_id, int $_nb)
     {
         db::query("UPDATE " . DB_T_LOTTERY . " "

+ 11 - 0
core/submit/cms.lottery-delete.php

@@ -0,0 +1,11 @@
+<?php
+
+if(core::ifGet("id")) {
+    lottery::deleteInscriptionLottery(core::getGet("id"));
+    lottery::deleteLottery(core::getGet("id"));
+    json::create("lottery");
+    alert::recSuccess("Le tirage au sort vient d'être supprimé");
+}
+
+header("Location: /lotterys.html");
+exit();

+ 14 - 2
core/views/pages/cms.lottery-fiche.php

@@ -8,9 +8,21 @@ if(core::ifGet("add")) {
     $submit = "Modifier ce tirage au sort";
     $id_form = '<input type="hidden" name="id" value="' . $lottery["id"] . '">';
 }
-
+    if(isset($lottery["id"]) AND $lottery["sortDate"] == NULL){ 
 ?>
-
+    <div style="float:right; margin-top: -60px;">
+        <a href="/submit.php?from=lottery-delete&id=<?php echo $lottery["id"] ?>" style="color: #dc3545; text-decoration:none;" onclick="return confirm('Voulez-vous supprimer ce tirage au sort ?')"><button type="submit" class="btn btn-outline-danger btn-sm"><span data-feather="trash-2"></span> Supprimer</button></a>
+    </div>
+<?php   
+    }
+    if(isset($lottery["id"]) AND $lottery["sortDate"] != NULL){
+        ?>
+            <div style="float:right; margin-top: -60px;">
+                <button class="btn btn-outline-secondary btn-sm" onclick="alert('Ce tirage au sort ne peut plus être supprimé car il a déjà été réalisé.')" >Ce tirage au sort est vérouillé</button>
+            </div>
+        <?php   
+            } 
+        ?>
 <br />
 
 <form method="post" action="/submit.php">