소스 검색

Fixe error

stany.ferer 3 달 전
부모
커밋
769066e396
3개의 변경된 파일77개의 추가작업 그리고 63개의 파일을 삭제
  1. 40 33
      core/class/core.class.php
  2. 20 18
      core/views/pages/cms.document.php
  3. 17 12
      core/views/pages/cms.proweb-export-csv.php

+ 40 - 33
core/class/core.class.php

@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Classe `core`
  *
@@ -23,7 +24,7 @@ class core
      */
     public static function ifGet(?string $_string = NULL)
     {
-        if($_string == NULL){
+        if ($_string == NULL) {
             return (empty($_GET)) ? FALSE : TRUE;
         } else {
             if (isset($_GET[$_string])) {
@@ -42,7 +43,7 @@ class core
      */
     public static function ifPost(?string $_string = NULL)
     {
-        if($_string == NULL){
+        if ($_string == NULL) {
             return (empty($_POST)) ? FALSE : TRUE;
         } else {
             if (isset($_POST[$_string])) {
@@ -64,7 +65,7 @@ class core
         if ($_string == NULL) {
             return (empty($_FILES)) ? FALSE : TRUE;
         } else {
-            if (isset($_FILES[$_string]) AND $_FILES[$_string]["size"] > 0) {
+            if (isset($_FILES[$_string]) and $_FILES[$_string]["size"] > 0) {
                 return TRUE;
             } else {
                 return FALSE;
@@ -159,7 +160,7 @@ class core
     public static function checkboxSelecter(bool $_val, $_echo = 1)
     {
         $tmp = ($_val == TRUE) ? "checked" : "";
-        if($_echo == 1){
+        if ($_echo == 1) {
             echo $tmp;
         } else {
             return $tmp;
@@ -315,12 +316,13 @@ class core
      * @param float $_amount Le montant à formater.
      * @return string Le montant formaté en euros.
      */
-    public static  function formatEuro($_amount) {
+    public static  function formatEuro($_amount)
+    {
         $amount = (float)$_amount;
         $formattedAmount = number_format($amount, 2, ',', ' ');
         return $formattedAmount . ' €';
     }
-    
+
 
     /**
      * Vérifie si une chaîne ne contient que des caractères alphabétiques.
@@ -411,17 +413,16 @@ class core
         foreach ($_arbo["arbo"] as $label => $lien) {
             if ($_arbo["current"] == $label) {
                 $return .= '<li class="breadcrumb-item active" aria-current="page"';
-                if(isset($_arbo["refresh-json"])){
-                    $return .= 'title="Cliquez ici pour rafraichir les données Json" onclick="return confirm(\'Voulez-vous rafraichir les données Json?\')" id="json-refresh"><a href="#" style="text-decoration:none;">' .icon::getFont(["icon" => "bi bi-arrow-clockwise"]) . ' ';
+                if (isset($_arbo["refresh-json"])) {
+                    $return .= 'title="Cliquez ici pour rafraichir les données Json" onclick="return confirm(\'Voulez-vous rafraichir les données Json?\')" id="json-refresh"><a href="#" style="text-decoration:none;">' . icon::getFont(["icon" => "bi bi-arrow-clockwise"]) . ' ';
                 } else {
                     $return .= '>';
                 }
                 $return .= $label;
-                if(isset($_arbo["refresh-json"])){
+                if (isset($_arbo["refresh-json"])) {
                     $return .= '</a>';
                 }
                 $return .= '</li>';
-
             } elseif ($lien == NULL) {
                 $return .= '<li class="breadcrumb-item">' . $label . '</li>';
             } else {
@@ -432,7 +433,7 @@ class core
         $return .= '</ol>';
         $return .= '</nav>';
 
-        if(isset($_arbo["refresh-json"])){
+        if (isset($_arbo["refresh-json"])) {
             $return .= "<script>
                 $('#json-refresh').on('click', function() {
                     $.ajax({
@@ -597,11 +598,11 @@ class core
     /**
      * Imprime une option sélectionnée dans un formulaire.
      *
-     * @param string|null $_string La valeur de l'option.
      * @param mixed $_value La valeur à comparer.
+     * @param string|null $_string La valeur de l'option.
      * @return void
      */
-    public static function printFormSelectOption(?string $_string = NULL, $_value)
+    public static function printFormSelectOption($_value, ?string $_string = NULL)
     {
         if ($_string != NULL and $_string == $_value) {
             echo " selected";
@@ -665,12 +666,13 @@ class core
      *
      * @return array Les informations sur la taille de la base de données.
      */
-    public static function getSizeDataBase(){
+    public static function getSizeDataBase()
+    {
         db::query("SELECT
                     table_schema AS nameDB, 
                     ROUND(SUM( data_length + index_length ) / 1024 / 1024, 2) AS moDB 
                     FROM information_schema.TABLES
-                    WHERE TABLE_SCHEMA = '".DB_NAME."'");
+                    WHERE TABLE_SCHEMA = '" . DB_NAME . "'");
         return db::single();
     }
 
@@ -683,24 +685,25 @@ class core
      * @param string $_icon L'icône à afficher.
      * @return void
      */
-    public static function progressBarWarning(float $_num, float $_max, string $_label, string $_icon){
+    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){
+        if ($pourcentage < 50) {
             $infos = ["color" => "bg-success"];
-        } elseif($pourcentage < 75){
+        } elseif ($pourcentage < 75) {
             $infos = ["color" => "bg-warning"];
         } else {
             $infos = ["color" => "bg-danger"];
         }
 
         echo '  <div class="mb-3" style="margin:10px 0;">
-                    <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>
+                    <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>
                 </div>';
     }
@@ -711,7 +714,8 @@ class core
      * @param bool $_alerte Indique si l'alerte doit être affichée.
      * @return string|null Le code HTML du badge ou NULL.
      */
-    static public function printBadgeGeneral(bool $_alerte){
+    static public function printBadgeGeneral(bool $_alerte)
+    {
         return $_alerte == TRUE ? '<span class="position-absolute start-100 translate-middle p-1 bg-danger border border-light rounded-circle"></span>' : NULL;
     }
 
@@ -724,7 +728,7 @@ class core
     {
         $return = [];
         $return["DOC"] = document::badgeAlert();
-        
+
         if ($return["DOC"] != NULL) {
             $return["ALERTE"] = TRUE;
         } else {
@@ -739,16 +743,17 @@ class core
      * @param array $_navInfos Les informations de navigation.
      * @return void
      */
-    static public function menu(array $_navInfos){
+    static public function menu(array $_navInfos)
+    {
         $badge = self::ifbadge();
-        echo '<a href="/" style="box-shadow: none; background-color:'. $_navInfos["color"] .';" class="navbar-brand">' . $_navInfos["title"] . '</a>' . debug::getBadges();
+        echo '<a href="/" style="box-shadow: none; background-color:' . $_navInfos["color"] . ';" class="navbar-brand">' . $_navInfos["title"] . '</a>' . debug::getBadges();
         echo '<div id="navbarCollapse" class="collapse navbar-collapse p-0">';
         echo '<ul class="nav navbar-nav ms-auto">';
         echo '<li class="nav-item dropdown">';
         echo '<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">' . session::getName() . self::printBadgeGeneral($badge["ALERTE"]) . '</a>';
         echo '<div class="dropdown-menu dropdown-menu-end">';
         echo '<a href="/user.html" class="dropdown-item">Mon profil</a>';
-        if((access::ifAccesss("documents") AND session::getType() == 5) OR session::getType() == 1){ // Membre du bureau ou Admin
+        if ((access::ifAccesss("documents") and session::getType() == 5) or session::getType() == 1) { // Membre du bureau ou Admin
             $nb = $badge["DOC"] > 0 ? '<span class="position-absolute badge rounded-pill bg-danger" style="right:-10px; margin-top:-10px;">' . $badge["DOC"] . '</span>' : NULL;
             echo '<a href="/documents-my-assign.html" class="dropdown-item">Vos assignations' . $nb . '</a>';
             echo '<a href="/alertes-emails.html" class="dropdown-item">Vos règles d\'alertes</a>';
@@ -766,9 +771,10 @@ class core
      *
      * @return string L'adresse IP de l'utilisateur.
      */
-    static public function getUserIP() {
+    static public function getUserIP()
+    {
         $ip = 'Inconnue';
-    
+
         if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
             // IP partagée par un proxy
             $ip = $_SERVER['HTTP_CLIENT_IP'];
@@ -779,12 +785,12 @@ class core
             // IP du client directement connectée au serveur
             $ip = $_SERVER['REMOTE_ADDR'];
         }
-    
+
         // Nettoyage des IPs multiples dans le cas de 'HTTP_X_FORWARDED_FOR'
         if (strpos($ip, ',') !== false) {
             $ip = explode(',', $ip)[0];
         }
-    
+
         return $ip;
     }
 
@@ -794,8 +800,9 @@ class core
      * @param array|null $_array Le tableau à aplatir (optionnel).
      * @return array|null Le tableau aplati ou NULL.
      */
-    static public function extractArrayInArray(?array $_array = NULL){
-        if($_array != NULL){
+    static public function extractArrayInArray(?array $_array = NULL)
+    {
+        if ($_array != NULL) {
             foreach ($_array as $item) {
                 foreach ($item as $key => $value) {
                     $flattened[$key] = $value;
@@ -804,7 +811,7 @@ class core
         } else {
             $flattened = NULL;
         }
-        
+
         return $flattened;
     }
 }

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

@@ -37,14 +37,14 @@ $userTags = user::getUser(session::getId())["tags"];
     <h2 class="bd-title" id="content">
         <span><?php echo $titre ?></span>
     </h2>
-    <?php 
+    <?php
     if (isset($document["id"]) and access::ifAccesss("add-document")) {
-        ?>
-            <div class="fix-container-button-nav">
-                <a href="/submit.php?from=document-delete&id=<?php echo $document["id"] ?>" style="color: #dc3545; text-decoration:none;" onclick="return confirm('Voulez-vous supprimer ce document ?')"><button type="submit" class="btn btn-outline-danger btn-sm"><?php icon::getFont(["icon" => "bi-trash-fill"]) ?></i> Supprimer</button></a>
-            </div>
-        <?php
-        }
+    ?>
+        <div class="fix-container-button-nav">
+            <a href="/submit.php?from=document-delete&id=<?php echo $document["id"] ?>" style="color: #dc3545; text-decoration:none;" onclick="return confirm('Voulez-vous supprimer ce document ?')"><button type="submit" class="btn btn-outline-danger btn-sm"><?php icon::getFont(["icon" => "bi-trash-fill"]) ?></i> Supprimer</button></a>
+        </div>
+    <?php
+    }
     ?>
 </header>
 <?php
@@ -93,16 +93,16 @@ echo core::filAriane(array(
             <div class="form-group">
                 <label>Type de document</label>
                 <select id="id_type" name="id_type" class="form-select" <?php if (!access::ifAccesss("add-document")) {
-                                                                echo "disabled";
-                                                            } ?> required>
+                                                                            echo "disabled";
+                                                                        } ?> required>
                     <option value=""></option>
-                    <option value="1" <?php core::printFormSelectOption($_type_document, 1) ?>><?php echo $_label_type_document[1] ?></option>
-                    <option value="2" <?php core::printFormSelectOption($_type_document, 2) ?>><?php echo $_label_type_document[2] ?></option>
+                    <option value="1" <?php core::printFormSelectOption(1, $_type_document) ?>><?php echo $_label_type_document[1] ?></option>
+                    <option value="2" <?php core::printFormSelectOption(2, $_type_document) ?>><?php echo $_label_type_document[2] ?></option>
                     <?php if (!access::ifLimitAccessException("salaire")) { ?>
-                        <option value="3" <?php core::printFormSelectOption($_type_document, 3) ?>><?php echo $_label_type_document[3] ?></option>
+                        <option value="3" <?php core::printFormSelectOption(3, $_type_document) ?>><?php echo $_label_type_document[3] ?></option>
                     <?php } ?>
-                    <option value="4" <?php core::printFormSelectOption($_type_document, 4) ?>><?php echo $_label_type_document[4] ?></option>
-                    <option value="0" <?php core::printFormSelectOption($_type_document, 0) ?>><?php echo $_label_type_document[0] ?></option>
+                    <option value="4" <?php core::printFormSelectOption(4, $_type_document) ?>><?php echo $_label_type_document[4] ?></option>
+                    <option value="0" <?php core::printFormSelectOption(0, $_type_document) ?>><?php echo $_label_type_document[0] ?></option>
                 </select>
             </div>
             <br />
@@ -111,7 +111,9 @@ echo core::filAriane(array(
             $_client = (isset($document["id_client"])) ? $document["id_client"] : NULL;
             $_all_clients = clients::getAll();
             ?>
-            <div class="form-group" id="client-section"<?php if($_type_document != 1 AND $_type_document != 0){ echo 'style=" display: none;"'; } ?>>
+            <div class="form-group" id="client-section" <?php if ($_type_document != 1 and $_type_document != 0) {
+                                                            echo 'style=" display: none;"';
+                                                        } ?>>
                 <label>Lié à</label>
                 <select name="id_client" id="id_client" class="form-select">
                     <option value=""></option>
@@ -175,8 +177,8 @@ echo core::filAriane(array(
             <div class="form-group">
                 <label>Rapprochement comptable</label>
                 <input type="text" class="form-control" value="<?php core::printFormValue($_rapprochement) ?>" name="rapprochement" placeholder="" <?php if (!access::ifAccesss("add-document")) {
-                                                                                                                                                echo "readonly";
-                                                                                                                                            } ?>>
+                                                                                                                                                        echo "readonly";
+                                                                                                                                                    } ?>>
             </div>
             <br />
 
@@ -247,4 +249,4 @@ echo core::filAriane(array(
 <?php
     }
     get::javascript("document");
-?>
+?>

+ 17 - 12
core/views/pages/cms.proweb-export-csv.php

@@ -6,12 +6,12 @@ if ($lastExcelForSFTP = salaries::lastExcelForSFTP()) {
 }
 json::create("host");
 
-    $jsonTarget1 = "/json.php?jsonData=proweb-transfert-sftp";
-    $jsonTarget2 = "/json.php?jsonData=proweb-transfert-local";
-    if(debug::isFile("debug")){
-        debug::log(debug::getBadge($jsonTarget1, "OUVRIR LE JSON : ".$jsonTarget1), "JSON chargé en arrière plan");
-        debug::log(debug::getBadge($jsonTarget2, "OUVRIR LE JSON : ".$jsonTarget2), "JSON chargé en arrière plan");
-    } 
+$jsonTarget1 = "/json.php?jsonData=proweb-transfert-sftp";
+$jsonTarget2 = "/json.php?jsonData=proweb-transfert-local";
+if (debug::isFile("debug")) {
+    debug::log(debug::getBadge($jsonTarget1, "OUVRIR LE JSON : " . $jsonTarget1), "JSON chargé en arrière plan");
+    debug::log(debug::getBadge($jsonTarget2, "OUVRIR LE JSON : " . $jsonTarget2), "JSON chargé en arrière plan");
+}
 ?>
 
 <header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
@@ -181,13 +181,17 @@ if (salaries::ifSubmitLastForSFTP()) {
 <script>
     $(document).ready(function() {
         $.ajax('/json.php', {
-            type: 'GET', // http method
+            type: 'GET',
             data: {
                 jsonData: 'proweb-transfert-test-connexion'
-            }, // data to submit
+            },
+            dataType: 'json',
             success: function(data, status, xhr) {
-                var json = $.parseJSON(data);
-                if (json == "OK") {
+                console.log("success", data);
+                if (
+                    data === "OK" ||
+                    (Array.isArray(data) && data.includes("OK"))
+                ) {
                     $('#testConnexionSFTP').val("Opérationnel");
                     $('#testConnexionSFTP').addClass("is-valid");
                     $('#testConnexionSFTP').css("background-color", "#d4edda");
@@ -199,8 +203,9 @@ if (salaries::ifSubmitLastForSFTP()) {
                     $('#testConnexionSFTP').css("color", "red");
                 }
             },
-            error: function() {
-                $('#testConnexionSFTP').val("En erreur");
+            error: function(xhr, status, error) {
+                console.log("error", xhr.responseText);
+                $('#testConnexionSFTP').val("En erreur lors de la requête");
                 $('#testConnexionSFTP').addClass("is-invalid");
                 $('#testConnexionSFTP').css("background-color", "#f8d7da");
                 $('#testConnexionSFTP').css("color", "red");