Quellcode durchsuchen

Dynamic Alert and valid files

stany.ferer vor 1 Jahr
Ursprung
Commit
7d8a20229a

+ 36 - 31
core/class/alert.class.php

@@ -78,8 +78,11 @@ class alert
         return (empty($_SESSION["alert"]["tab"])) ? FALSE : TRUE;
     }
 
-    public static function printAlert(array $_array)
+    public static function printAlert(?array $_array = NULL)
     {
+        if($_array == NULL){
+            return NULL;
+        }
         $return = NULL;
         foreach ($_array as $value) {
             $return .= "<div>" . $value . "</div>";
@@ -100,43 +103,45 @@ class alert
         return (in_array($_string, $_SESSION["alert"]["input"])) ? TRUE : FALSE;
     }
 
-    private static function printToast(string $_style, string $_icon, array $_texte)
+    private static function printToast(string $_idAlert, string $_style, string $_icon, ?array $_texte = NULL)
     {
-        echo '  <div class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="1500" style="margin-top:10px; ' . $_style . '">
-                    <div class="toast-header">' . $_icon . '</div><div class="toast-body">' . self::printAlert($_texte) . '</div>
+        $text = ($_texte != NULL) ? self::printAlert($_texte) : NULL;
+        
+        echo '  <div  id="' . $_idAlert . '" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="1500" style="margin-top:10px; ' . $_style . '">
+                    <div class="toast-header">' . $_icon . '</div><div class="toast-body" id="' . $_idAlert . 'Txt">' . $text . '</div>
                 </div>';
     }
 
     public static function show()
     {
         historique::recordLogs();
-        
-        if (self::getSuccess() or self::getWarning() or self::getError()) {
-
-            echo '<div aria-live="polite" aria-atomic="true" class="position-fixed bottom-0 right-0 p-3"  style="z-index: 5; right: 5px; bottom: 0;">';
-
-            if (self::getSuccess()) {
-                $style = 'background:#d4edda;';
-                $icon = '<span data-feather="info" style="color:green;"></span> <strong style="color:green; margin-left:5px;" class="mr-auto">Succès</strong>';
-                $texte = self::getSuccess();
-                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>';
-                $texte = self::getError();
-                self::printToast($style, $icon, $texte);
-            }
-            echo '</div>';
-        }
+
+        echo '<div class="position-fixed bottom-0 right-0 p-3" style="z-index: 5; right: 5px; bottom: 0;">'; 
+
+        $idAlert = "printToastSuccess";
+        $texte1 = (self::getSuccess()) ?  self::getSuccess() : NULL;
+        $style = 'background:#d4edda;';
+        $icon = '<span data-feather="info" style="color:green;"></span> <strong style="color:green; margin-left:5px;" class="mr-auto">Succès</strong>';
+        self::printToast($idAlert, $style, $icon, $texte1);
+
+        $idAlert = "printToastWarning";
+        $texte2 = (self::getWarning()) ?  self::getWarning() : NULL;
+        $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>';
+        self::printToast($idAlert, $style, $icon, $texte2);
+
+        $idAlert = "printToastError";
+        $texte3 = (self::getError()) ?  self::getError() : NULL;
+        $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>';
+        self::printToast($idAlert, $style, $icon, $texte3);
+
+        echo '</div>';
+
+        echo ($texte1 == NULL) ?  '' : '<script>$("#printToastSuccess").toast("show");</script>';
+        echo ($texte2 == NULL) ?  '' : '<script>$("#printToastWarning").toast("show");</script>';
+        echo ($texte3 == NULL) ?  '' : '<script>$("#printToastError").toast("show");</script>';
+
         self::destroyAlert();
     }
 

+ 4 - 2
core/class/button.class.php

@@ -12,7 +12,8 @@ class button
             "cancel" => "Annuler",
             "type" => "submit",
             "class" => "btn btn-primary btn-lg",
-            "style" => "width: 100%"
+            "style" => "width: 100%",
+            "add" => ""
         );
 
         if($_array != NULL){
@@ -25,6 +26,7 @@ class button
             (!empty($_array["class"])) ? $config["class"] = $_array["class"] : NULL;
             (!empty($_array["style"])) ? $config["style"] = $_array["style"] : NULL;
             (!empty($_array["id"])) ? $config["id"] = $_array["id"] : NULL;
+            (!empty($_array["add"])) ? $config["add"] = $_array["add"] : NULL;
         }
         
         $print = "<input ";
@@ -37,7 +39,7 @@ class button
         $print .= 'data-confirm-button-confirm="' . $config["confirm"] .'" ';
         $print .= 'data-confirm-button-cancel="' . $config["cancel"] .'" ';
         if(!empty($_array["id"])) { $print .= 'id="' . $config["id"] .'" '; }
-        $print .= ">";
+        $print .= ' ' . $config["add"] .'>';
 
         echo $print;
     }

+ 1 - 0
core/class/core.class.php

@@ -183,6 +183,7 @@ class core
 
     public static function print_r(array $_array, int $_exit = NULL)
     {
+        echo "<div>".debug::getTraces() . "</div>";
         echo "<pre>";
         print_r($_array);
         echo "</pre>";

+ 2 - 2
core/class/document.class.php

@@ -184,8 +184,8 @@ class document
 
     public static function update()
     {
-        if(core::ifFiles("attachement-document") == TRUE){
-            $file = core::getFiles("attachement-document");
+        if(core::ifFiles("attachement-document") == TRUE){ 
+            $file = core::getFiles("attachement-document"); 
             $md5 = md5_file($file["tmp_name"]);
         } 
         if(isset($md5) AND file::findM5($md5) == TRUE){

+ 11 - 1
core/class/json.class.php

@@ -196,9 +196,19 @@ class json extends db
         db::query("SELECT 
         " . DB_T_DOCUMENTS . ".id, 
         " . DB_T_DOCUMENTS . ".titre, 
-        " . DB_T_DOCUMENTS . ".date, 
+        " . DB_T_DOCUMENTS . ".date,        
         " . DB_T_DOCUMENTS . ".deadline, 
         " . DB_T_DOCUMENTS . ".description, 
+          ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ') 
+            FROM  " . DB_T_DOCUMENT_TAGS . " 
+            INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags
+            WHERE id_documents = " . DB_T_DOCUMENTS . ".id AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = 2 
+            ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer) AS tags, 
+           ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ') 
+            FROM  " . DB_T_DOCUMENT_TAGS . " 
+            INNER JOIN " . DB_T_TAGS . " ON " . DB_T_TAGS . ".id = " . DB_T_DOCUMENT_TAGS . ".id_tags
+            WHERE id_documents = " . DB_T_DOCUMENTS . ".id AND " . DB_T_DOCUMENT_TAGS . ".id_type_tags = 1 
+            ORDER BY " . DB_T_DOCUMENT_TAGS . ".creer) AS assign, 
         IF(" . DB_T_DOCUMENTS . ".id_user_done IS NOT NULL, 'Traité', 'Non traité') AS done, 
         " . DB_T_TYPE_DOCUMENT . ".label, 
         CONCAT (" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS 'user'

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

@@ -17,7 +17,6 @@
 <script>
     $(document).ready(function(){
         feather.replace();
-        $('.toast').toast('show');
     });
     
     function loading(){

+ 10 - 3
core/views/pages/cms.compte-upload.php

@@ -23,13 +23,13 @@
     <div class="file-drop-area">
         <span class="choose-file-button">Choisissez votre fichier CSV</span>
         <span class="file-message">ou déposez le dans cette zone</span>
-        <input id="compte-upload" class="import-excel" name="compte-upload" type="file" onchange="dargAndDrop()">
+        <input id="compte-upload" class="import-excel" name="compte-upload" type="file" onchange="dargAndDrop()" accept=".csv">
     </div>
     <br />
     <?php button::confirm(
         array(
             "value" => "Charger le dernier CSV émanant du ".$banque["label"]." de Crédit Mutuel",
-            "text" => "Vérifiez que le CSV correspond au bon compte. Le compte de destination est ".$banque["label"]." (N°".$banque["compte"].")" 
+            "text" => "Vérifiez que le CSV correspond au bon compte. Le compte de destination est ".$banque["label"]." (N°".$banque["compte"].")"
         )
     ) ?>
 </form>
@@ -37,6 +37,13 @@
 <script>
     function dargAndDrop(){    
         var fileName = $("#compte-upload").val().split('\\').pop();
-        $(".file-message").text($(".file-message").text().replace("ou déposez le dans cette zone", "Fichier prêt à être chargé : "+fileName));
+        var ext = fileName.split('.').pop();
+        if(ext!=="csv"){
+            $("#printToastErrorTxt").html("Seuls les fichiers CSV sont acceptés");
+            $("#printToastError").toast('show');
+            $('#attachement-document').val("");
+        } else {
+            $(".file-message").text($(".file-message").text().replace("ou déposez le dans cette zone", "Fichier prêt à être chargé : "+fileName));
+        }
     }
 </script>

+ 6 - 15
core/views/pages/cms.document.php

@@ -136,7 +136,7 @@ if (isset($document["id"])) {
 
             <?php if (isset($files[0]["id"])) { ?>
 
-                <div style="border:1px #CCCCCC solid; background-color:#F6F6F6; padding:20px;">
+                <div style="border:1px #CCCCCC solid; background-color:#F6F6F6; padding:20px; border-radius:.375rem;">
 
                 <?php if (isset($document) and tags::compareUserDocument($userTags, $document["tagsUser"]) == TRUE) {
                     $checkDone = (isset($document["id_user_done"])) ? " disabled" : NULL;
@@ -152,7 +152,6 @@ if (isset($document["id"])) {
                 <?php } ?>
                 
                 <?php document::printAttachement($files); ?>
-                    <div id="error-type-file" class="alert alert-danger" style="display:none;"></div>
                     <div class="file-drop-area">
                         <span class="choose-file-button">Ajouter une pièce jointe</span>
                         <span class="file-message">ou drag & drop</span>
@@ -161,12 +160,10 @@ if (isset($document["id"])) {
                 </div>
                 <br />
             <?php } ?>
-
         </div>
 
         <div class="col">
             <?php if (empty($files[0]["id"])) { ?>
-                <div id="error-type-file" class="alert alert-danger" style="display:none;"></div>
                 <div class="file-drop-area" style="margin-top:22px;" id="file-document-import">
                     <span class="choose-file-button">Choisissez votre document</span>
                     <span class="file-message">ou drag & drop</span>
@@ -220,12 +217,9 @@ if (isset($document["id"])) {
         var fileName = $("#document-import").val().split('\\').pop();
         var ext = fileName.split('.').pop();
         if(ext!=="pdf" && ext!=="png" && ext!=="jpg"){
-            $("#error-type-file").html("Seuls les fichiers PDF, JPG et PNG sont acceptés").fadeIn(400, function() {
-                setTimeout(function() {
-                    $("#error-type-file").fadeOut(1000);
-                }, 2000);
-            });
-            $('#document-import').val("");
+            $("#printToastErrorTxt").html("Seuls les fichiers PDF, JPG et PNG sont acceptés");
+            $("#printToastError").toast('show');
+            $('#attachement-document').val("");
         } else {
             $(".file-message").text($(".file-message").text().replace("ou drag & drop", fileName));
         }
@@ -235,11 +229,8 @@ if (isset($document["id"])) {
         var fileName = $("#attachement-document").val().split('\\').pop();
         var ext = fileName.split('.').pop();
         if(ext!=="pdf" && ext!=="png" && ext!=="jpg"){
-            $("#error-type-file").html("Seuls les fichiers PDF, JPG et PNG sont acceptés").fadeIn(400, function() {
-                setTimeout(function() {
-                    $("#error-type-file").fadeOut(1000);
-                }, 2000);
-            });
+            $("#printToastErrorTxt").html("Seuls les fichiers PDF, JPG et PNG sont acceptés");
+            $("#printToastError").toast('show');
             $('#attachement-document').val("");
         } else {
             $(".file-message").text($(".file-message").text().replace("ou drag & drop", fileName));

+ 4 - 5
core/views/pages/cms.documents.php

@@ -44,13 +44,12 @@
         <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" data-width="250">Titre</th>
+                <th data-sortable="true" data-field="titre" data-filter-control="input">Titre</th>
                 <th data-sortable="true" data-field="label" data-filter-control="select" data-width="200">Type</th>
                 <th data-sortable="true" data-field="date" data-filter-control="input" data-width="110">Date</th>
-                <th data-sortable="true" data-field="deadeline" data-filter-control="input" data-width="110">Echéance</th>
-                <th data-sortable="true" data-field="name" data-filter-control="input" data-width="350">Fichier</th>
-                <th data-sortable="true" data-field="size" data-filter-control="input" data-width="50">Taille</th>
-                <th data-sortable="true" data-field="tagsUser" data-filter-control="input">Attribution</th>
+                <th data-sortable="true" data-field="deadline" data-filter-control="input" data-width="110">Echéance</th>
+                <th data-sortable="true" data-field="tags" data-filter-control="input" data-width="200">Tags</th>
+                <th data-sortable="true" data-field="assign" data-filter-control="input" data-width="200">Attribution</th>
                 <th data-sortable="true" data-field="user" data-filter-control="input" data-width="120">Créé par</th>
                 <th data-sortable="true" data-field="done" data-filter-control="select" data-width="50">Statut</th>
                 <th data-field="id" data-formatter="selectFormatter" data-width="60"></th>

+ 9 - 2
core/views/pages/cms.proweb-salaries-upload.php

@@ -25,7 +25,7 @@
     <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="proweb-import-salaries" class="import-excel" name="proweb-import-salaries" type="file" onchange="dargAndDrop()">
+        <input id="proweb-import-salaries" class="import-excel" name="proweb-import-salaries" type="file" onchange="dargAndDrop()" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
     </div>
     <br />
     <input class="btn btn-primary btn-lg" style="width: 100%" type="submit" value="Charger le fichier de la base ProWeb">
@@ -34,6 +34,13 @@
 <script>
     function dargAndDrop(){    
         var fileName = $("#proweb-import-salaries").val().split('\\').pop();
-        $(".file-message").text($(".file-message").text().replace("ou déposez le dans cette zone", "Fichier prêt à être chargé : "+fileName));
+        var ext = fileName.split('.').pop();
+        if(ext!=="xlsx"){
+            $("#printToastErrorTxt").html("Seuls les fichiers XLSX sont acceptés");
+            $("#printToastError").toast('show');
+            $('#attachement-document').val("");
+        } else {
+            $(".file-message").text($(".file-message").text().replace("ou déposez le dans cette zone", "Fichier prêt à être chargé : "+fileName));
+        }
     }
 </script>

+ 10 - 3
core/views/pages/cms.rh-upload-excel.php

@@ -25,7 +25,7 @@
     <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 class="import-excel" name="rh-import-excel" type="file" onchange="dargAndDrop()">
+        <input class="import-excel" name="rh-import-excel" type="file" onchange="dargAndDrop()" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
     </div>
     <br />
     <input class="btn btn-outline-primary btn-lg" style="width: 100%" type="submit" value="Charger le fichier de la base RH">
@@ -35,6 +35,13 @@
     function dargAndDrop(){
         
         var fileName = $(".import-excel").val().split('\\').pop();
-        $(".file-message").text($(".file-message").text().replace("ou déposez le dans cette zone", "Fichier prêt à être chargé : "+fileName));
+        var ext = fileName.split('.').pop();
+        if(ext!=="xlsx"){
+            $("#printToastErrorTxt").html("Seuls les fichiers XLSX sont acceptés");
+            $("#printToastError").toast('show');
+            $('#attachement-document').val("");
+        } else {
+            $(".file-message").text($(".file-message").text().replace("ou déposez le dans cette zone", "Fichier prêt à être chargé : "+fileName));
+        }
     }
-</script>
+</script>