Browse Source

Add gestion des Tags

stany.ferer 1 year ago
parent
commit
d000428aeb

+ 3 - 0
core/class/icon.class.php

@@ -85,6 +85,9 @@ class icon
             case 'parametres':
                 return "bi bi-gear-fill";
                 break;
+            case 'tags':
+                return "bi bi-tags-fill";
+                break;
             default:
                 return $_type;
                 break;

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

@@ -43,6 +43,19 @@ class tags
         }
     }
 
+    public static function maj(float $_id, string $_tag) {
+        db::query("UPDATE " . DB_T_TAGS . " SET label = :label WHERE id = :id; ");
+        db::bind(':label', $_tag);
+        db::bind(':id', $_id);
+
+        try {
+            db::execute();
+            return TRUE;
+        } catch (Exception $ex) {
+            return FALSE;
+        }
+    }
+
     static public function findAndCreate(string $_tags, float $_idTag = 2){
         $find = [];
         $tmp = explode(",", $_tags);
@@ -135,4 +148,5 @@ class tags
         }
         return FALSE;
     }
+
 }

+ 1 - 1
core/submit/cms.parametres-reset-datas.php

@@ -1,6 +1,6 @@
 <?php
 
-if((ENVIRONNEMENT == "DEV" OR ENVIRONNEMENT == "R7" OR ENVIRONNEMENT == "PREPROD")) {
+if((ENVIRONNEMENT != "PROD")) {
     core::resetDatas();
 
     historique::recRef("/parametres.html");

+ 20 - 0
core/submit/cms.tag-change.php

@@ -0,0 +1,20 @@
+<?php
+
+if (core::ifPost("from")) {
+
+    tags::maj(core::getPost("id"), core::getPost("value"));
+
+    historique::recRef("/tags.html");
+    historique::add(array(
+        "idType" => historique::getIdRef("ACTION"),
+        "idUser" => session::getId(),
+        "idPage" => historique::getIdRef("/tags.html"),
+        "log" => "Modification du tag : " . core::getPost("value")
+    ));
+
+    header("Location: /tags.html");
+    exit();
+} else {
+    header('HTTP/1.0 401 Unauthorized');
+    exit();
+}

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

@@ -68,12 +68,13 @@
                 core::elementMenuLink("pratique", "https://sender.cse-invent.com", "SendPortal CSE");
             echo '</ul>';
 
-            $temp_accordion = array("user", "parametres", "parametre-users", "parametre-teams", "historique");
+            $temp_accordion = array("user", "parametres", "parametre-users", "parametre-teams", "tags", "historique");
             (in_array(core::getGet("p"), $temp_accordion) or get::isDefautMenu($temp_accordion)) ? $_show = "show" : $_show = NULL;
                 core::elementMenuH6("parametres", "Administration", NULL, "col-admin");
             echo '<ul class="collapse ' . $_show . ' list-unstyled" id="col-admin" data-parent="#accordion">';
                 core::elementMenu("parametre-users", "/parametre-users.html", "Admin : Utilisateurs");
                 core::elementMenu("parametre-teams", "/parametre-teams.html", "Admin : Groupes & Droits");
+                core::elementMenu("tags", "/tags.html", "Admin : Tags");
                 core::elementMenu("historique", "/historique.html", "Admin : Historique");
                 core::elementMenu("parametres", "/parametres.html", "Admin : Paramètres");
             echo '</ul>';

+ 1 - 1
core/views/pages/cms.parametres-debug.php

@@ -7,7 +7,7 @@
                     <a href="/submit.php?from=parametres-json-refresh" onclick="return confirm('Etes-vous certain de vouloir réinitialiser les JSON ?')"><button type="button" class="btn btn-warning">Réinitialisation des JSON</button></a>
                 </div>
         </td>
-        <?php if (session::getType() == 1 and (ENVIRONNEMENT == "DEV" OR ENVIRONNEMENT == "R7" OR ENVIRONNEMENT == "PREPROD")) { ?>
+        <?php if (session::getType() == 1 AND (ENVIRONNEMENT != "PROD")) { ?>
         <td>
             <h4>Outils de débug</h4>
             <div class="element-parametres">

+ 5 - 5
core/views/pages/cms.parametres-restore.php

@@ -6,7 +6,7 @@
 ?>
 <div style="margin-top:20px;">
 
-    <a href="/submit.php?from=parametres-add-backup" style="position:absolute; right:25px; margin-top:-60px;">
+    <a href="/submit.php?from=parametres-add-backup" style="position:absolute; right:25px; margin-top:-60px;" onclick="loading()">
         <button type="submit" class="btn btn-outline-success btn-sm">
         <?php icon::getFont(["icon" => "bi bi-file-earmark-plus"]) ?> Créer un nouveau backup</button>
     </a>
@@ -34,7 +34,7 @@
 
 <script>
     function downloadFile(value, row) {
-        return '<form method="post" action="/submit.php">\n\
+        return '<form method="post" action="/submit.php" onsubmit="loading()">\n\
         <input type="hidden" name="from" value="parametres-download-backup-zip">\n\
         <input type="hidden" name="file" value="' + row.file + '">\n\
         <button type="submit" style="border:none; background:none;" title="Télécharger le fichier : ' + row.file + '">' + row.file + '</button>\n\
@@ -45,7 +45,7 @@
     <?php
         if(!core::isDebug()) { ?>
             if(index == 0){
-                return '<form method="post" action="/submit.php">\n\
+                return '<form method="post" action="/submit.php" onsubmit="loading()">\n\
                 <input type="hidden" name="from" value="parametres-restore-backup-zip">\n\
                 <input type="hidden" name="file" value="' + row.file + '">\n\
                 <button type="submit" onclick="return confirm(\'Etes-vous certain de vouloir restaurer cette dernière version (données et fichiers) ? Les données actuelles seront perdues.\')" class="btn btn-outline-danger btn-sm">Restaurer</button>\n\
@@ -55,7 +55,7 @@
             }
         <?php 
         } else { ?>
-                return '<form method="post" action="/submit.php">\n\
+                return '<form method="post" action="/submit.php" onsubmit="loading()">\n\
                 <input type="hidden" name="from" value="parametres-restore-backup-zip">\n\
                 <input type="hidden" name="file" value="' + row.file + '">\n\
                 <button type="submit" onclick="return confirm(\'Etes-vous certain de vouloir restaurer cette dernière version (données et fichiers) ? Les données actuelles seront perdues.\')" class="btn btn-outline-danger btn-sm">Restaurer</button>\n\
@@ -65,7 +65,7 @@
 
     function deleteBackup(value, row, index) {
         if(index != 0){
-            return '<form method="post" action="/submit.php">\n\
+            return '<form method="post" action="/submit.php" onsubmit="loading()">\n\
             <input type="hidden" name="from" value="parametres-delete-backup-zip">\n\
             <input type="hidden" name="file" value="' + row.file + '">\n\
             <button type="submit" onclick="return confirm(\'Etes-vous certain de vouloir supprimer ce backup?\')" class="btn btn-outline-warning btn-sm">Supprimer</button>\n\

+ 9 - 0
core/views/pages/cms.parametres.php

@@ -44,6 +44,15 @@ echo core::filAriane(array(
 
 <script>
 $(document).ready(function(){
+
+    var fragment = window.location.hash;
+    var tmpOnglet = fragment ? fragment.substring(1) : '';
+    var onglet = "#" + tmpOnglet;
+
+    if (tmpOnglet !== "" && $(onglet).length) {
+        $('#tab-parametres a[href="' + onglet + '"]').tab('show');
+    }
+
     $("#tab-parametres a").click(function(){
         $(this).tab('show');
     });

+ 58 - 0
core/views/pages/cms.tags.php

@@ -0,0 +1,58 @@
+<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
+    <h2 class="bd-title" id="content">
+        <span>Administration : Tags</span>
+    </h2>
+</header>
+<?php
+echo core::filAriane(array(
+    "current" => "Tags",
+    "arbo" => array(
+        "Administration" => NULL,
+        "Tags" => "/tags.html"
+    )
+));
+
+?>
+
+<table class="table">
+    <thead>
+        <tr>
+            <th scope="col">#</th>
+            <th scope="col">Tags</th>
+            <th scope="col"></th>
+        </tr>
+    </thead>
+    <tbody>
+<?php 
+    foreach (tags::getAll(2) as $value) {
+        echo "  <tr>
+                    <th scope=\"row\">" . $value["id"] . "</th>
+                    <td><input type=\"email\" class=\"form-control\" id=\"tags-".$value["id"]."\" value=\"" . $value["label"] . "\"></td>
+                    <td><button type=\"button\" class=\"btn btn-primary\" onclick=\"majTags(".$value["id"].");\">Modifier</button></td>
+                </tr>";
+    }
+?>
+    </tbody>
+</table>
+
+<script>
+    function majTags(id){
+        $.ajax({
+            url: '/submit.php',
+            type: 'POST',
+            data: {
+                from: "tag-change",
+                id: id,
+                value: $('#tags-'+id).val()
+            },
+            success: function(response) {
+                $("#printToastSuccessTxt").html("Le tag vient d'être mis à jour");
+                $("#printToastSuccess").toast('show');
+            },
+            error: function(xhr, status, error) {
+                $("#printToastErrorTxt").html("Le tag n'a pas été mis à jour");
+                $("#printToastError").toast('show');
+            }
+        });
+    }
+</script>