Browse Source

Maj document default pj

stany.ferer 1 year ago
parent
commit
38218e6a17

+ 1 - 0
conf.inc.php

@@ -10,6 +10,7 @@ define("DIR_PHP_VIEWS_PAGE", DOCUMENT_ROOT . "core/views/pages/");
 define("DIR_PHP_LAYOUTS", DOCUMENT_ROOT . "core/controllers/");
 define("DIR_PHP_SUBMIT", DOCUMENT_ROOT . "core/submit/");
 define("DIR_PHP_LIBS", DOCUMENT_ROOT . "core/libs/");
+define("DIR_PHP_JAVASCRIPT", DOCUMENT_ROOT . "core/javascript/");
 define("DIR_DATAS_JSONDATA", DOCUMENT_ROOT . "core/json/");
 define("DIR_DATAS", DOCUMENT_DATAS . "datas/");
 define("DIR_DATAS_JSON", DOCUMENT_DATAS . "datas/json/");

+ 22 - 11
core/class/core.class.php

@@ -28,12 +28,16 @@ class core
         }
     }
 
-    public static function ifFiles(string $_string)
+    public static function ifFiles(string $_string = NULL)
     {
-        if (isset($_FILES[$_string]) AND $_FILES[$_string]["size"] > 0) {
-            return TRUE;
+        if ($_string == NULL) {
+            return (empty($_FILES)) ? FALSE : TRUE;
         } else {
-            return FALSE;
+            if (isset($_FILES[$_string]) AND $_FILES[$_string]["size"] > 0) {
+                return TRUE;
+            } else {
+                return FALSE;
+            }
         }
     }
 
@@ -391,18 +395,21 @@ class core
         }
     }
 
-    public static function convertBytes($val, $type_val = "o", $type_wanted = "Mo")
+    public static function convertBytes(float $val, string $type_val = "o", string $type_wanted = "Mo", bool $_float = FALSE)
     {
         $tab_val = array("o", "ko", "Mo", "Go", "To", "Po", "Eo");
         if (!(in_array($type_val, $tab_val) && in_array($type_wanted, $tab_val)))
             return 0;
         $tab = array_flip($tab_val);
         $diff = $tab[$type_val] - $tab[$type_wanted];
+
+        $type_wanted_print = $_float == FALSE ? $type_wanted : NULL;
+
         if ($diff > 0)
-            return round(($val * pow(1024, $diff)), 2) . $type_wanted;
+            return round(($val * pow(1024, $diff)), 2) . $type_wanted_print;
         if ($diff < 0)
-            return round(($val / pow(1024, -$diff)), 2) . $type_wanted;
-        return round(($val), 2) . $type_wanted;
+            return round(($val / pow(1024, -$diff)), 2) . $type_wanted_print;
+        return round(($val), 2) . $type_wanted_print;
     }
 
     public static function getSizeDataBase(){
@@ -414,7 +421,11 @@ class core
         return db::single();
     }
 
-    public static function progressBarWarning(float $_num, float $_max, string $_label){
+    public static function progressBarWarning(float $_num, float $_max, string $_label, string $_icon){
+        $changeUnit = 1073741824;
+        $valueUnitNum = $_num >= $changeUnit ? "Go" : "Mo";
+        $valueUnitMax = $_max >= $changeUnit ? "Go" : "Mo";
+
         $pourcentage = number_format(($_num / $_max) * 100, 2);
         if($pourcentage < 50){
             $infos = ["color" => "bg-success"];
@@ -424,8 +435,8 @@ class core
             $infos = ["color" => "bg-danger"];
         }
 
-        echo '  <div class="mb-3" style="margin:10px 0;">
-                    <label class="form-label" style=""><i class="bi bi-hdd-fill" style="font-size:20px;"></i> '.$_label.' [' . core::convertBytes($_num, "o", "Go") . ' / ' . core::convertBytes($_max, "o", "Go") . ']</label>
+        echo '  <div class="mb-3" style="margin:10px 0; padding:20px; border-bottom: 1px solid #dee2e6;">
+                    <label class="form-label" style=""><i class="'.$_icon.'" style="font-size:18px; margin:4px;"></i> <span style="font-weight: bold;">'.$_label.'</span> [' . core::convertBytes($_num, "o", $valueUnitNum) . ' / ' . core::convertBytes($_max, "o", $valueUnitMax) . ']</label>
                     <div class="progress" role="progressbar" aria-label="Success example" aria-valuenow="'.$pourcentage.'" aria-valuemin="0" aria-valuemax="100">
                     <div class="progress-bar '.$infos["color"].'" style="width: '.$pourcentage.'%">'.$pourcentage.'%</div>
                     </div>

+ 10 - 1
core/class/db.class.php

@@ -50,7 +50,16 @@ class db
 
     public static function execute()
     {
-        return self::$stmt->execute();
+        if(core::isDebug()){
+            ob_start();
+            $return = self::$stmt->execute();
+            self::$stmt->debugDumpParams();
+            $debugOutput = ob_get_clean();
+            debug::logSession($debugOutput);
+            return $return;
+        } else {
+            return self::$stmt->execute();
+        }
     }
 
     public static function resultset()

+ 43 - 0
core/class/debug.class.php

@@ -158,6 +158,25 @@ class debug
         }
     }
 
+    public static function logSession($_message, $_mark = NULL)
+    {        
+        $mark = "<div class='debug-head-console'>";
+        $mark .= ($_mark != NULL) ? "<div style='font-weight: bold;'>". $_mark . "</div>" : NULL;
+        $mark .= self::getTraces();
+        $mark .= "</div>";
+        if($_message != NULL) {
+            if(is_array($_message)){
+                self::setSession($mark ."<div class='debug-console'>" . self::arrayToString($_message) . "</div>");
+            } elseif(is_object($_message)){
+                self::setSession($mark ."<div class='debug-console'>" . self::objectToString($_message) . "</div>");
+            } elseif($mark != NULL){
+                self::setSession($mark ."<div class='debug-console' style='color:blue;'>" . $_message . "</div>");
+            } else {
+                self::setSession($_message);
+            }
+        }
+    }
+
     public static function renderLogs()
     {
         //if (!empty(self::$logs)) {
@@ -176,6 +195,12 @@ class debug
                 echo ($log != NULL) ? "<div class='debug-renderLogs-print'>".nl2br($log)."</div>" : NULL;
             }
 
+            if(self::ifSession()){
+                foreach (self::getSession() as $logSession) {
+                    echo ($log != NULL) ? "<div class='debug-renderLogs-print'>".nl2br($logSession)."</div>" : NULL;
+                }
+            }
+
             echo "</div>";
 
             echo "
@@ -243,4 +268,22 @@ class debug
             echo "<a href=\"#\"><span class=\"badge toggle-logs\" style=\"background-color:orange; color:black; margin:5px;\">MODE DEBUG SUBMIT</span></a>";
         } 
     }
+
+    public static function setSession($_data){
+        $_SESSION["DEBUG"][] = $_data;
+    }
+
+    public static function getSession(){
+        $return = $_SESSION["DEBUG"];
+        self::resetSession();
+        return $return;
+    }
+
+    public static function ifSession(){
+        return empty($_SESSION["DEBUG"]) ? FALSE : TRUE;
+    }
+
+    public static function resetSession(){
+        unset($_SESSION["DEBUG"]);
+    }
 }

+ 64 - 30
core/class/document.class.php

@@ -74,15 +74,19 @@ class document
         return db::single()["id"];
     }
 
-    private static function addFile(float $_idDocument, string $_idFile)
+    private static function addFile(float $_idDocument, string $_idFile, int $_principal = NULL)
     {
-        db::query("INSERT INTO " . DB_T_DOCUMENT_FILES . " (id_documents, id_files) VALUES (:id_documents, :id_files)");
+        db::query("INSERT INTO " . DB_T_DOCUMENT_FILES . " (id_documents, id_files, principal) VALUES (:id_documents, :id_files, :principal)");
         db::bind(':id_documents', $_idDocument);
         db::bind(':id_files', $_idFile);
+        db::bind(':principal', $_principal);
         try {
             db::execute();
             return TRUE;
         } catch (Exception $ex) {
+            echo "error";
+            echo $ex;
+            exit();
             return FALSE;
         }
     }
@@ -168,7 +172,7 @@ class document
             }
 
             try {
-                self::addFile($lastId, $idFile);
+                self::addFile($lastId, $idFile, 1);
             } catch (Exception $ex) {
                 alert::recError("Erreur à l'enregistrement de la liaison : " . $idFile);
                 if(core::isDebug()) { alert::recError("Stack : " . $ex); }
@@ -211,7 +215,7 @@ class document
                 }
 
                 try {
-                    self::addFile(core::getPost("id"), $idFile);
+                    self::addFile(core::getPost("id"), $idFile, 0);
                 } catch (Exception $ex) {
                     alert::recError("Erreur à l'enregistrement de la liaison : " . $idFile);
                     return FALSE;
@@ -224,6 +228,10 @@ class document
                 }
             }
 
+            if(core::getPost("default-attachement")){
+                self::principalFile(core::getPost("id"), core::getPost("default-attachement"));
+            }
+
             try { 
                 $tagsUser = tags::textToId(core::getPost("tagsUser"), 1);
                 self::addTags(core::getPost("id"), $tagsUser, 1);
@@ -290,10 +298,6 @@ class document
         }
     }
 
-    static public function getList(){
-        
-    }
-
     static public function get(float $_id){
         db::query("SELECT "
             . "" . DB_T_DOCUMENTS . ".id, "
@@ -352,7 +356,8 @@ class document
             . "" . DB_T_FILES . ".size, "
             . "" . DB_T_FILES . ".creer, "
             . "" . DB_T_FILES . ".id_user, "
-            . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS user "
+            . "CONCAT(" . DB_T_USER . ".prenom, ' ', " . DB_T_USER . ".nom) AS user, "
+            . "" . DB_T_DOCUMENT_FILES . ".principal "
             . "FROM " . DB_T_DOCUMENT_FILES . " "
             . "INNER JOIN " . DB_T_FILES . " ON " . DB_T_FILES . ".id = " . DB_T_DOCUMENT_FILES . ".id_files "
             . "INNER JOIN " . DB_T_USER . " ON " . DB_T_USER . ".id = " . DB_T_FILES . ".id_user "
@@ -362,12 +367,38 @@ class document
         $tmp = db::resultset();
 
         if(isset($tmp[0])){
-            return $tmp;
+            foreach ($tmp as $file) {
+                if($file["principal"] == TRUE){
+                    $return["principal"] = $file;
+                } else {
+                    $return[] = $file;
+                }
+            }
+
+            if(empty($return["principal"])){
+                $return["principal"] = $return[0];
+                self::principalFile($_idDocument, $return["principal"]["id"]);
+                unset($return[0]);
+            }
+            return $return;
         } else {
             return NULL;
         }
     }
 
+    static public function principalFile(float $_idDocument, string $_idFile){
+        db::query("UPDATE " . DB_T_DOCUMENT_FILES . " SET principal = :principal WHERE id_documents = :id_documents");
+        db::bind(':principal', 0);
+        db::bind(':id_documents', $_idDocument);
+        db::execute();
+
+        db::query("UPDATE " . DB_T_DOCUMENT_FILES . " SET principal = :principal WHERE id_documents = :id_documents AND id_files = :id_files");
+        db::bind(':principal', 1);
+        db::bind(':id_documents', $_idDocument);
+        db::bind(':id_files', $_idFile);
+        db::execute();
+    }
+
     static public function getAssignMe(){
 
         $tags = user::getIdTags(session::getId());
@@ -388,12 +419,12 @@ class document
         " . DB_T_DOCUMENTS . ".deadline, 
         " . DB_T_DOCUMENTS . ".description, 
         " . DB_T_DOCUMENTS . ".montant, 
-          ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ') 
+            ( 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 ', ') 
+            ( 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 
@@ -408,26 +439,29 @@ class document
     }
 
     static public function printAttachement(array $_attachs){
+        $principal = $_attachs["principal"];
         echo '<ol class="list-group list-group-numbered">';
-        foreach ($_attachs as $key => $attach) {
-                echo '<li class="list-group-item d-flex justify-content-between align-items-start" id="attach-'.$attach["id"].'">
+        echo '  <li class="list-group-item d-flex justify-content-between align-items-start" id="attach-'.$principal["id"].'">
                     <div class="ms-2 me-auto">
-                        <div><span class="fw-bold">'.$attach["name"].'</span> ('.core::convertBytes($attach["size"]).')</div>
-                        Chargé le '.core::convertDate($attach["creer"]).' par '.$attach["user"].'
-                        <div id="select-attach-'.$attach["id"].'" style="color:red;"></div>
-                    </div>';
-                if($key == 0){ 
-                    echo '
-                            <button type="button" class="btn btn btn-outline-primary" onclick="window.open(\'/document.php?id=' . $attach["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
-                        ';
-                } else {
-                    echo '<div class="btn-group">
-                        <button type="button" class="btn btn btn-outline-primary" onclick="window.open(\'/document.php?id=' . $attach["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
-                        <button type="button" class="btn btn-outline-danger" onclick="deleteAttachment(\''.$attach["id"].'\')" id="button-attach-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-trash"]) . '</button>
-                    </div>';
-                }
-                echo '</li>';
-                    
+                        <div><span class="fw-bold">'.$principal["name"].'</span> ('.core::convertBytes($principal["size"]).')</div>
+                        Chargé le '.core::convertDate($principal["creer"]).' par '.$principal["user"].'
+                        <div id="select-attach-'.$principal["id"].'" style="color:red;"></div>
+                    </div><button type="button" class="btn btn btn-outline-secondary" onclick="window.open(\'/document.php?id=' . $principal["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
+                </li>';
+        foreach ($_attachs as $key => $attach) {
+                if($key != "principal"){
+                    echo '  <li class="list-group-item d-flex justify-content-between align-items-start" id="attach-'.$attach["id"].'">
+                                <div class="ms-2 me-auto">
+                                    <div><span class="fw-bold">'.$attach["name"].'</span> ('.core::convertBytes($attach["size"]).')</div>
+                                    Chargé le '.core::convertDate($attach["creer"]).' par '.$attach["user"].'
+                                    <div id="select-attach-'.$attach["id"].'"></div>
+                                </div><div class="btn-group">
+                                    <button type="button" class="btn btn btn-outline-secondary" onclick="window.open(\'/document.php?id=' . $attach["id"] . '\', \'_blank\')">' . icon::getFont(["icon" => "bi bi-eye-fill"]) . '</button>
+                                    <button type="button" class="btn btn btn-outline-primary" onclick="defaultAttachment(\''.$attach["id"].'\')" id="button-default-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-paperclip"]) . '</button>
+                                    <button type="button" class="btn btn-outline-danger" onclick="deleteAttachment(\''.$attach["id"].'\')" id="button-delete-'.$attach["id"].'">' . icon::getFont(["icon" => "bi bi-trash"]) . '</button>
+                                </div>
+                            </li>';
+                }          
         }
         echo '</ol><br />';
     }

+ 6 - 0
core/class/get.class.php

@@ -60,6 +60,12 @@ class get
         }
     }
 
+    public static function javascript(string $_string){
+        if (file_exists(DIR_PHP_JAVASCRIPT . self::environnement() . $_string . '.php')) {
+            include DIR_PHP_JAVASCRIPT . self::environnement() . $_string . '.php';
+        }
+    }
+
     public static function json()
     {
         if (core::ifGet("file")) {

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

@@ -200,12 +200,12 @@ class json extends db
         " . DB_T_DOCUMENTS . ".deadline, 
         " . DB_T_DOCUMENTS . ".description, 
         " . DB_T_DOCUMENTS . ".montant, 
-          ( SELECT GROUP_CONCAT(" . DB_T_TAGS . ".label SEPARATOR ', ') 
+            ( 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 ', ') 
+            ( 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 

+ 119 - 0
core/javascript/cms.document.php

@@ -0,0 +1,119 @@
+<script>
+    function validateAndSubmit() {
+        const form = document.getElementById('form-document');
+        const requiredFields = form.querySelectorAll('[required]');
+        let allFieldsFilled = true;
+
+        requiredFields.forEach(field => {
+            if (!field.value.trim()) {
+                if (field.name === "document-import") {
+                    const fileDoc = document.getElementById('file-document-import');
+                    fileDoc.style.borderColor = 'red';
+                }
+                allFieldsFilled = false;
+                field.style.borderColor = 'red';
+            } else {
+                field.style.borderColor = '';
+                if (typeof fileDoc !== 'undefined' && fileDoc !== null) {
+                    fileDoc.style.borderColor = '';
+                }
+            }
+        });
+
+        if (allFieldsFilled) {
+            form.submit();
+        }
+    }
+
+    function dargAndDrop() {
+        var fileName = $("#document-import").val().split('\\').pop();
+        var ext = fileName.split('.').pop();
+        if (ext !== "pdf" && ext !== "png" && ext !== "jpg") {
+            $("#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));
+        }
+    }
+
+    function dargAndDropAttachment() {
+        var fileName = $("#attachement-document").val().split('\\').pop();
+        var ext = fileName.split('.').pop();
+        if (ext !== "pdf" && ext !== "png" && ext !== "jpg") {
+            $("#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));
+        }
+    }
+
+    function resetAttachement(id) {
+        $('#attach-' + id).css('background-color', '');
+        $('#select-attach-' + id).html('');
+        $('#button-delete-' + id).html('<?php echo icon::getFont(["icon" => "bi bi-trash"]) ?>');
+        $('#button-default-' + id).html('<?php echo icon::getFont(["icon" => "bi bi-paperclip"]) ?>');
+    }
+
+    function deleteAttachment(id) {
+        if ($('#del-jquery-' + id).length) {
+            $('#attach-' + id).css('background-color', '');
+            $('#select-attach-' + id).css('color', '');
+            $('#select-attach-' + id).html('');
+            $('#button-delete-' + id).html('<?php echo icon::getFont(["icon" => "bi bi-trash"]) ?>');
+        } else {
+            resetAttachement(id);
+            $('#attach-' + id).css('background-color', '#f8d7da');
+            $('#select-attach-' + id).css('color', 'red');
+            $('#select-attach-' + id).html('Cette pièce jointe sera supprimée à la validation du formulaire.<input id="del-jquery-' + id + '" type="hidden" name="delete-attachement[]" value="' + id + '">');
+            $('#button-delete-' + id).html('<?php echo icon::getFont(["icon" => "bi bi-x-square-fill"]) ?>');
+        }
+    }
+
+    function defaultAttachment(id) {
+
+        if ($('#default-jquery-' + id).length) {
+            $('#attach-' + id).css('background-color', '');
+            $('#select-attach-' + id).css('color', '');
+            $('#select-attach-' + id).html('');
+            $('#button-default-' + id).html('<?php echo icon::getFont(["icon" => "bi bi-paperclip"]) ?>');
+        } else {
+            resetAttachement(id);
+
+            $('[data-default="attach"]').css('background-color', '');
+            $('[data-default="select-attach"]').css('color', '');
+            $('[data-default="select-attach"]').html('');
+            $('[data-default="button-default"]').html('<?php echo icon::getFont(["icon" => "bi bi-paperclip"]) ?>');
+
+            $('#attach-' + id).attr('data-default', 'attach');
+            $('#attach-' + id).css('background-color', '#cce5ff');
+            $('#select-attach-' + id).attr('data-default', 'select-attach');
+            $('#select-attach-' + id).css('color', 'blue');
+            $('#select-attach-' + id).html('Cette pièce jointe sera définie à défaut à la validation du formulaire.<input id="default-jquery-' + id + '" type="hidden" name="default-attachement" value="' + id + '">');
+            $('#button-default-' + id).attr('data-default', 'button-default');
+            $('#button-default-' + id).html('<?php echo icon::getFont(["icon" => "bi bi-x-square-fill"]) ?>');
+        }
+    }
+
+    function upperCase(input) {
+        input.value = input.value.toUpperCase();
+    }
+
+    $(document).ready(function() {
+        $('#tagsUser').inputTags({
+            autocomplete: {
+                values: <?php echo tags::getJquery(1) ?>,
+                only: true
+            },
+            max: 3
+        });
+
+        $('#tagsSupplier').inputTags({
+            autocomplete: {
+                values: <?php echo tags::getJquery(2) ?>
+            },
+            max: 3
+        });
+    });
+</script>

+ 3 - 3
core/submit/cms.parametres-debug-activation.php

@@ -15,11 +15,11 @@ if(core::ifGet("actif")){
     } else {
         core::removeFileDebug();
 
-        historique::recRef("/parametres.html");
+        historique::recRef("/parametres.html#parametres-debug");
         historique::add(array(
             "idType" => historique::getIdRef("ACTION"),
             "idUser" => session::getId(),
-            "idPage" => historique::getIdRef("/parametres.html"),
+            "idPage" => historique::getIdRef("/parametres.html#parametres-debug"),
             "log" => "Mode debug : Désactivation"
         ));
 
@@ -27,5 +27,5 @@ if(core::ifGet("actif")){
     }
 }
 
-header("Location: /parametres.html");
+header("Location: /parametres.html#parametres-debug");
 exit();

+ 3 - 3
core/submit/cms.parametres-maintenance-activation.php

@@ -15,11 +15,11 @@ if(core::ifGet("actif")){
     } else {
         core::removeFileMaintenance();
 
-        historique::recRef("/parametres.html");
+        historique::recRef("/parametres.html#parametres-debug");
         historique::add(array(
             "idType" => historique::getIdRef("ACTION"),
             "idUser" => session::getId(),
-            "idPage" => historique::getIdRef("/parametres.html"),
+            "idPage" => historique::getIdRef("/parametres.html#parametres-debug"),
             "log" => "Mode maintenance : Désactivation"
         ));
 
@@ -27,5 +27,5 @@ if(core::ifGet("actif")){
     }
 }
 
-header("Location: /parametres.html");
+header("Location: /parametres.html#parametres-debug");
 exit();

+ 20 - 106
core/views/pages/cms.document.php

@@ -141,25 +141,25 @@ if (isset($document["id"])) {
             </div>
             <br />
 
-            <?php if (isset($files[0]["id"])) { ?>
+            <?php if (isset($files["principal"]["id"])) { ?>
 
                 <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) OR (isset($document["date_done"]))) {
-                    $checkDone = (isset($document["id_user_done"])) ? " disabled" : NULL;
-                    $checkColor = (isset($document["id_user_done"])) ? " style=\"background-color:#d1e7dd;\"" : NULL;
-                    $checkText = (isset($document["id_user_done"])) ? "Document traité par <span style=\"font-weight: bold;\">" . $document["doneUser"] . "</span> le": "Document traité le";
-                    $_dateDone = (isset($document["date_done"])) ? $document["date_done"] : NULL; 
-                    echo '  <div class="form-group">
-                                <label>'.$checkText.'</label>
-                                <input type="date" class="form-control"'.$checkColor.' name="date_done" value="'. core::getFormValue($_dateDone) . '"' . $checkDone .'>
+                    <?php
+
+                    if ((isset($document) and tags::compareUserDocument($userTags, $document["tagsUser"]) == TRUE) or (isset($document["date_done"]))) {
+                        $checkDone = (isset($document["id_user_done"])) ? " disabled" : NULL;
+                        $checkColor = (isset($document["id_user_done"])) ? " style=\"background-color:#d1e7dd;\"" : NULL;
+                        $checkText = (isset($document["id_user_done"])) ? "Document traité par <span style=\"font-weight: bold;\">" . $document["doneUser"] . "</span> le" : "Document traité le";
+                        $_dateDone = (isset($document["date_done"])) ? $document["date_done"] : NULL;
+                        echo '  <div class="form-group">
+                                <label>' . $checkText . '</label>
+                                <input type="date" class="form-control"' . $checkColor . ' name="date_done" value="' . core::getFormValue($_dateDone) . '"' . $checkDone . '>
                                 </div><br />';
-                } 
+                    }
 
-                document::printAttachement($files); 
-                ?>
+                    document::printAttachement($files);
+                    ?>
                     <div class="file-drop-area">
                         <span class="choose-file-button">Ajouter une pièce jointe</span>
                         <span class="file-message">ou drag & drop</span>
@@ -171,7 +171,7 @@ if (isset($document["id"])) {
         </div>
 
         <div class="col">
-            <?php if (empty($files[0]["id"])) { ?>
+            <?php if (empty($files["principal"]["id"])) { ?>
                 <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>
@@ -179,9 +179,9 @@ if (isset($document["id"])) {
                 </div>
                 <br />
             <?php } else {
-                $heigh = (mime_content_type(file::download($files[0]["id"], DIR_DATAS_DOCS)) == "application/pdf") ? "height:110vh;" : NULL;
+                $heigh = (mime_content_type(file::download($files["principal"]["id"], DIR_DATAS_DOCS)) == "application/pdf") ? "height:110vh;" : NULL;
                 echo '  <div style="margin-top:22px;">
-                        <embed src="/document.php?id=' . $files[0]["id"] . '" style="width:100%; margin-top:10px;' . $heigh . '" /></embed>
+                        <embed src="/document.php?id=' . $files["principal"]["id"] . '" style="width:100%; margin-top:10px;' . $heigh . '" /></embed>
                     </div><br />
                     ';
             }
@@ -193,92 +193,6 @@ if (isset($document["id"])) {
     <br /><br />
 </form>
 
-<script>
-    
-    function validateAndSubmit() {
-        const form = document.getElementById('form-document');
-        const requiredFields = form.querySelectorAll('[required]');
-        let allFieldsFilled = true;
-
-        requiredFields.forEach(field => {
-            if (!field.value.trim()) {
-                if (field.name === "document-import") {
-                    const fileDoc = document.getElementById('file-document-import');
-                    fileDoc.style.borderColor = 'red';
-                }
-                allFieldsFilled = false;
-                field.style.borderColor = 'red';
-            } else {
-                field.style.borderColor = '';
-                if (typeof fileDoc !== 'undefined' && fileDoc !== null) {
-                    fileDoc.style.borderColor = '';
-                }
-            }
-        });
-
-        if (allFieldsFilled) {
-            form.submit();
-        }
-    }
-
-    function dargAndDrop() {
-        var fileName = $("#document-import").val().split('\\').pop();
-        var ext = fileName.split('.').pop();
-        if(ext!=="pdf" && ext!=="png" && ext!=="jpg"){
-            $("#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));
-        }
-    }
-
-    function dargAndDropAttachment() {
-        var fileName = $("#attachement-document").val().split('\\').pop();
-        var ext = fileName.split('.').pop();
-        if(ext!=="pdf" && ext!=="png" && ext!=="jpg"){
-            $("#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));
-        }
-    }
-
-    function deleteAttachment(id){ 
-        const elementsCadre = $('#attach-' + id);
-        const elementsAlerte = $('#select-attach-' + id);
-        const elementsButton = $('#button-attach-' + id);
-        if($('#del-jquery-' + id).length) {
-            const elementsRevert = $('#del-jquery-' + id);
-            elementsCadre.css('background-color', '');
-            elementsAlerte.html('');
-            elementsButton.html('<?php echo icon::getFont(["icon" => "bi bi-trash"]) ?>');
-        } else {
-            elementsCadre.css('background-color', '#f8d7da');
-            elementsAlerte.html('Ce document sera supprimé à la validation du formulaire.<input id="del-jquery-' + id + '" type="hidden" name="delete-attachement[]" value="' + id + '">');
-            elementsButton.html('<?php echo icon::getFont(["icon" => "bi bi-x-square-fill"]) ?>');
-        }   
-    }
-
-    function upperCase(input) {
-        input.value = input.value.toUpperCase();
-    }
-
-    $(document).ready(function() {
-        $('#tagsUser').inputTags({
-            autocomplete: {
-                values: <?php echo tags::getJquery(1) ?>,
-                only: true
-            },
-            max: 3
-        });
-
-        $('#tagsSupplier').inputTags({
-            autocomplete: {
-                values: <?php echo tags::getJquery(2) ?>
-            },
-            max: 3
-        });
-    });
-</script>
+<?php
+    get::javascript("document");
+?>

+ 23 - 0
core/views/pages/cms.parametres-debug.php

@@ -1,7 +1,22 @@
+<?php
+    $checkMaintenance = core::isMaintenance();
+    $checkDebug = core::isDebug();
+?>
 <table class="table table-bordered">
 <tbody>
     <tr>
         <td scope="row">
+                <h4>Activation Modes</h4>
+                <div class="element-parametres form-check form-switch">
+                    <input class="form-check-input" type="checkbox" role="switch" id="checkMaintenance" <?php core::checkboxSelecter($checkMaintenance) ?>>
+                    <label class="form-check-label" for="checkMaintenance">Site en mode maintenance (les salariés ne pourront plus faire d'action sur le site)</label>
+                </div>
+
+                <div class="element-parametres form-check form-switch">
+                    <input class="form-check-input" type="checkbox" role="switch" id="checkDebug" <?php core::checkboxSelecter($checkDebug) ?>>
+                    <label class="form-check-label" for="checkDebug">Afficher les erreurs (débug)</label>
+                </div>
+            
                 <h4>Refresh des données</h4>
                 <div class="element-parametres">
                     <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>
@@ -47,5 +62,13 @@
                 'max-height': '100%'
             });
         });
+
+        $('#checkMaintenance').on('change', function() {
+            window.location.href = "/submit.php?from=parametres-maintenance-activation&actif=" + $("#checkMaintenance").prop('checked');
+        });
+
+        $('#checkDebug').on('change', function() {
+            window.location.href = "/submit.php?from=parametres-debug-activation&actif=" + $("#checkDebug").prop('checked');
+        });
     });
 </script>

+ 13 - 47
core/views/pages/cms.parametres-general.php

@@ -1,48 +1,9 @@
 <?php
-    $checkMaintenance = core::isMaintenance();
-    $checkDebug = core::isDebug();
     $checkLogSuccess = core::getConfig("LOG_SUCCESS");
     $checkLogWarning = core::getConfig("LOG_WARNING");
     $checkLogError = core::getConfig("LOG_ERROR");
 ?>
 
-<h4>Espaces disques</h4>
-<?php 
-    $infosDB = core::getSizeDataBase(); 
-?>
-<div>
-    <span class="badge" style="background-color:#28a745; width: 130px;"><?php echo $infosDB["moDB"] ?> Mo</span> <label> <?php echo $infosDB["nameDB"] ?> (Mysql)</label>
-</div>
-<div>
-    <span class="badge" style="background-color:#28a745; width: 130px;"><?php echo core::convertBytes((disk_total_space(DOCUMENT_ROOT) - disk_free_space(DOCUMENT_ROOT)), "o", "Go") . " / " . core::convertBytes(disk_total_space(DOCUMENT_ROOT), "o", "Go") ?></span> <label> Espace ROOT</label>
-</div>
-<div>
-    <span class="badge" style="background-color:#28a745; width: 130px;"><?php echo core::convertBytes((disk_total_space(DOCUMENT_DATAS) - disk_free_space(DOCUMENT_DATAS)), "o", "Go") . " / " . core::convertBytes(disk_total_space(DOCUMENT_DATAS), "o", "Go") ?></span> <label> Espace DATAS</label>
-</div>
-<div>
-    <span class="badge" style="background-color:#17a2b8; width: 130px;"><?php echo core::convertBytes(file::sizeFolder(DIR_BACKUP), "o", "Mo") . " / " . core::convertBytes(disk_total_space(DOCUMENT_DATAS), "o", "Go") ?></span> <label> Dossier Backups</label>
-</div>
-<div>
-    <span class="badge" style="background-color:#17a2b8; width: 130px;"><?php echo core::convertBytes(file::sizeFolder(DOCUMENT_DATAS), "o", "Mo") . " / " . core::convertBytes(disk_total_space(DOCUMENT_DATAS), "o", "Go") ?></span> <label> Dossier Documents</label>
-</div>
-<div>
-    <span class="badge" style="background-color:#17a2b8; width: 130px;"><?php echo core::convertBytes(file::sizeFolder(DIR_DATAS_JSONDATA), "o", "Mo") . " / " . core::convertBytes(disk_total_space(DOCUMENT_ROOT), "o", "Go") ?></span> <label> Dossier Json</label>
-</div>
-<div>
-    <span class="badge" style="background-color:#17a2b8; width: 130px;"><?php echo core::convertBytes(file::sizeFolder(SFTP_LOCAL), "o", "Mo") . " / " . core::convertBytes(disk_total_space(DOCUMENT_ROOT), "o", "Go") ?></span> <label> Dossier SFTP</label>
-</div>
-
-<h4>Général</h4>
-<div class="element-parametres form-check form-switch">
-    <input class="form-check-input" type="checkbox" role="switch" id="checkMaintenance" <?php core::checkboxSelecter($checkMaintenance) ?>>
-    <label class="form-check-label" for="checkMaintenance">Site en mode maintenance (les salariés ne pourront plus faire d'action sur le site)</label>
-</div>
-
-<div class="element-parametres form-check form-switch">
-    <input class="form-check-input" type="checkbox" role="switch" id="checkDebug" <?php core::checkboxSelecter($checkDebug) ?>>
-    <label class="form-check-label" for="checkDebug">Afficher les erreurs (débug)</label>
-</div>
-
 <h4>Historique</h4>
 <div class="element-parametres form-check form-switch">
     <input class="form-check-input" type="checkbox" role="switch" id="checkLogSuccess" <?php core::checkboxSelecter($checkLogSuccess) ?>>
@@ -61,14 +22,6 @@
 
 <script>
     $(document).ready(function() {
-        $('#checkMaintenance').on('change', function() {
-            window.location.href = "/submit.php?from=parametres-maintenance-activation&actif=" + $("#checkMaintenance").prop('checked');
-        });
-
-        $('#checkDebug').on('change', function() {
-            window.location.href = "/submit.php?from=parametres-debug-activation&actif=" + $("#checkDebug").prop('checked');
-        });
-
         $('#checkLogSuccess').on('change', function() {
             window.location.href = "/submit.php?from=parametres-config&name=LOG_SUCCESS&value=" + $("#checkLogSuccess").prop('checked');
         });
@@ -82,3 +35,16 @@
         });
     });
 </script>
+
+<h4>Espaces disques</h4>
+<?php 
+    $infosDB = core::getSizeDataBase();
+    $unGo = 1073741824;
+    core::progressBarWarning(disk_free_space(DOCUMENT_ROOT), disk_total_space(DOCUMENT_ROOT), "Espace ROOT", "bi-pc-display-horizontal");
+    core::progressBarWarning(disk_free_space(DOCUMENT_DATAS), disk_total_space(DOCUMENT_DATAS), "Espace DATAS", "bi-pc-display-horizontal");
+    core::progressBarWarning(core::convertBytes(floatval($infosDB["moDB"]), "Mo", "o", TRUE), $unGo, "Base de donnée Mysql", "bi bi-database-fill");
+    core::progressBarWarning(file::sizeFolder(DIR_BACKUP), disk_free_space(DOCUMENT_DATAS), "Dossier Backups", "bi bi-folder");
+    core::progressBarWarning(file::sizeFolder(DOCUMENT_DATAS), disk_free_space(DOCUMENT_DATAS), "Dossier Documents", "bi bi-folder");
+    core::progressBarWarning(file::sizeFolder(DIR_DATAS_JSONDATA), disk_free_space(DOCUMENT_ROOT), "Dossier Json", "bi bi-folder");
+    core::progressBarWarning(file::sizeFolder(SFTP_LOCAL), disk_free_space(DOCUMENT_ROOT), "Dossier SFTP", "bi bi-folder");
+?>

+ 1 - 1
maj/sql/maj.sql

@@ -1 +1 @@
-
+ALTER TABLE `documents_files` ADD `principal` BOOLEAN NOT NULL DEFAULT FALSE AFTER `id_files`; 

+ 3 - 2
public-cms/submit.php

@@ -8,8 +8,9 @@ require_once "../conf.inc.php";
 require_once DIR_PHP_LAYOUTS . "header.php"; 
 require_once DIR_PHP_LAYOUTS . "cms.session.php";
 
-if(debug::isSubmit() AND core::ifPost()) {
-    core::print_r(core::getPost());
+if(debug::isSubmit() AND ( core::ifPost() OR core::ifFiles()) ) {
+    core::ifPost() ? core::print_r(core::getPost()) : NULL;
+    core::ifFiles() ? core::print_r(core::getFiles()) : NULL;
     exit();
 }