Browse Source

Add config logs historique

stany.ferer 2 years ago
parent
commit
ea144b7a38

+ 1 - 0
conf.inc.php

@@ -19,6 +19,7 @@ define("DIR_TEMP", DOCUMENT_ROOT . "tmp/");
 
 define("SFTP_LOCAL", DOCUMENT_ROOT . "datas/sftp/");
 
+define("DB_T_CONFIG", "config");
 define("DB_T_USER", "user");
 define("DB_T_USER_TYPE", "user_type");
 define("DB_T_SALARIES", "salaries");

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

@@ -46,6 +46,39 @@ class core
         }
     }
 
+    public static function checkboxSelecter(bool $_val){
+        echo ($_val == TRUE) ? "checked" : "";
+    }
+
+    public static function getAllConfig(){
+        db::query("SELECT "
+        . "" . DB_T_CONFIG . ".name, "
+        . "" . DB_T_CONFIG . ".value "
+        . "FROM " . DB_T_CONFIG);
+        return db::resultset();
+    }
+
+    public static function getConfig(string $_name){
+        db::query("SELECT value FROM " . DB_T_CONFIG . " WHERE name = :name");
+        db::bind(':name', $_name);
+        return db::single()["value"];
+    }
+
+    public static function updateConfig(string $_name, int $_value){
+        db::query("UPDATE " . DB_T_CONFIG . " SET "
+                . "value = :value "
+                . "WHERE name = :name");
+        db::bind(':value', $_value);
+        db::bind(':name', $_name);
+        
+        try {
+                db::execute();
+                return TRUE;
+            } catch (Exception $ex) {
+                return FALSE;
+            }
+    }
+
     public static function cleanAccent(string $_data)
     {
         $search  = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ');
@@ -217,10 +250,6 @@ class core
         return (file_exists(DOCUMENT_ROOT . FILE_DEBUG)) ? TRUE : FALSE;
     }
 
-    public static function checkboxSelecter(bool $_val){
-        echo ($_val == TRUE) ? "checked" : "";
-    }
-
     public static function resetDatas()
     {
         db::query("TRUNCATE " . DB_T_TEMP_SALARIES);

+ 3 - 3
core/class/historique.class.php

@@ -95,7 +95,7 @@ class historique
         if(session::isConnect() AND (alert::getSuccess() OR alert::getWarning() OR alert::getError())){
             $log = NULL;
 
-            if(alert::getSuccess()){
+            if(alert::getSuccess() AND core::getConfig("LOG_SUCCESS") == 1){
                 foreach (alert::getSuccess() as $value) { 
                     $log .= $value . "\r\n";
                 }
@@ -108,7 +108,7 @@ class historique
                 ));
             }
             
-            if(alert::getWarning()){
+            if(alert::getWarning() AND core::getConfig("LOG_WARNING") == 1){
                 foreach (alert::getWarning() as $value) { 
                     $log .= $value . "\r\n";
                 }
@@ -121,7 +121,7 @@ class historique
                 ));
             }
 
-            if(alert::getError()){
+            if(alert::getError() AND core::getConfig("LOG_ERROR") == 1){
                 foreach (alert::getError() as $value) { 
                     $log .= $value . "\r\n";
                 }

+ 22 - 0
core/submit/cms.parametres-config.php

@@ -0,0 +1,22 @@
+<?php
+
+if(core::ifGet("name") AND core::ifGet("value")){
+    if(core::getGet("value") == "true"){
+        if(core::updateConfig(core::getGet("name"), 1) == TRUE){
+            alert::recSuccess(core::getGet("name") . " est activé");
+            echo json_encode(array("1"));
+        } else {
+            alert::recError("Activation de " . core::getGet("name") . " en erreur");
+        }
+    } else {
+        if(core::updateConfig(core::getGet("name"), 0) == TRUE){
+            alert::recSuccess(core::getGet("name") . " est désactivé");
+            echo json_encode(array("0"));
+        } else {
+            alert::recError("Désactivation de " . core::getGet("name") . " en erreur");
+        }
+    }
+}
+
+header("Location: /parametres.html");
+exit();

+ 0 - 2
core/submit/cms.parametres-debug-activation.php

@@ -2,11 +2,9 @@
 if(core::ifGet("actif")){
     if(core::getGet("actif") == "true"){
         core::addFileDebug();
-        echo json_encode(array("1"));
         alert::recSuccess("Le mode debug est activé");
     } else {
         core::removeFileDebug();
-        echo json_encode(array("0"));
         alert::recSuccess("Le mode debug est déactivé");
     }
 }

+ 35 - 2
core/views/pages/cms.parametres-general.php

@@ -1,6 +1,9 @@
 <?php
-$checkMaintenance = core::isMaintenance();
-$checkDebug = core::isDebug();
+    $checkMaintenance = core::isMaintenance();
+    $checkDebug = core::isDebug();
+    $checkLogSuccess = core::getConfig("LOG_SUCCESS");
+    $checkLogWarning = core::getConfig("LOG_WARNING");
+    $checkLogError = core::getConfig("LOG_ERROR");
 ?>
 
 <h4>Général</h4>
@@ -8,11 +11,29 @@ $checkDebug = core::isDebug();
     <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) ?>>
+    <label class="form-check-label" for="checkLogSuccess">Historiser les actions réalisées avec succès</label>
+</div>
+
+<div class="element-parametres form-check form-switch">
+    <input class="form-check-input" type="checkbox" role="switch" id="checkLogWarning" <?php core::checkboxSelecter($checkLogWarning) ?>>
+    <label class="form-check-label" for="checkLogWarning">Historiser les actions réalisées avec Warning</label>
+</div>
+
+
+<div class="element-parametres form-check form-switch">
+    <input class="form-check-input" type="checkbox" role="switch" id="checkLogError" <?php core::checkboxSelecter($checkLogError) ?>>
+    <label class="form-check-label" for="checkLogError">Historiser les actions en erreur</label>
+</div>
+
 <?php if (session::accessUserByType(1) and session::getId() == 1 and (ENVIRONNEMENT == "DEV" or ENVIRONNEMENT == "PREPROD")) { ?>
 
     <h4>Développement</h4>
@@ -51,6 +72,18 @@ $checkDebug = core::isDebug();
             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');
+        });
+
+        $('#checkLogWarning').on('change', function() {
+            window.location.href = "/submit.php?from=parametres-config&name=LOG_WARNING&value=" + $("#checkLogWarning").prop('checked');
+        });
+
+        $('#checkLogError').on('change', function() {
+            window.location.href = "/submit.php?from=parametres-config&name=LOG_ERROR&value=" + $("#checkLogError").prop('checked');
+        });
+
         $('#modalPHPInfo').on('show.bs.modal', function() {
             $(this).find('.modal-body').css({
                 width: 'auto', //probably not needed