Bladeren bron

Mode debug Submit

stany.ferer 1 jaar geleden
bovenliggende
commit
bc9f01798d

+ 1 - 0
conf.inc.php

@@ -87,6 +87,7 @@ define("EMEMARGEMENT_END", 1800); // Possibilité de s'émarger 1800 secondes so
 define("BACKUP_LIMIT", 15); // nombre de backup max
 define("FILE_MAINTENANCE", ".lock-maintenance");
 define("FILE_DEBUG", ".active-debug");
+define("FILE_DEBUG_SUBMIT", ".active-debug-submit");
 
 // Email
 define("EMAIL_SMTP_HOST", "ssl0.ovh.net");

+ 23 - 10
core/class/core.class.php

@@ -2,21 +2,29 @@
 
 class core
 {
-    public static function ifGet(string $_string)
+    public static function ifGet(string $_string = NULL)
     {
-        if (isset($_GET[$_string])) {
-            return TRUE;
+        if($_string == NULL){
+            return (empty($_GET)) ? FALSE : TRUE;
         } else {
-            return FALSE;
+            if (isset($_GET[$_string])) {
+                return TRUE;
+            } else {
+                return FALSE;
+            }
         }
     }
 
-    public static function ifPost(string $_string)
+    public static function ifPost(string $_string = NULL)
     {
-        if (isset($_POST[$_string])) {
-            return TRUE;
+        if($_string == NULL){
+            return (empty($_POST)) ? FALSE : TRUE;
         } else {
-            return FALSE;
+            if (isset($_POST[$_string])) {
+                return TRUE;
+            } else {
+                return FALSE;
+            }
         }
     }
 
@@ -80,9 +88,14 @@ class core
         return FALSE;
     }
 
-    public static function checkboxSelecter(bool $_val)
+    public static function checkboxSelecter(bool $_val, $_echo = 1)
     {
-        echo ($_val == TRUE) ? "checked" : "";
+        $tmp = ($_val == TRUE) ? "checked" : "";
+        if($_echo == 1){
+            echo $tmp;
+        } else {
+            return $tmp;
+        }
     }
 
     public static function getAllConfig()

+ 27 - 1
core/class/debug.class.php

@@ -7,6 +7,22 @@ class debug
     private static $startTime;
     private static $closeTime;
 
+    public static function addFileSubmit()
+    {
+        $myfile = fopen(DOCUMENT_ROOT . FILE_DEBUG_SUBMIT, "w");
+        fclose($myfile);
+    }
+
+    public static function removeFileSubmit()
+    {
+        unlink(DOCUMENT_ROOT . FILE_DEBUG_SUBMIT);
+    }
+
+    public static function isSubmit()
+    {
+        return (file_exists(DOCUMENT_ROOT . FILE_DEBUG_SUBMIT)) ? TRUE : FALSE;
+    }
+    
     public static function includeDebug()
     {
         if (core::isDebug()) {
@@ -145,11 +161,16 @@ class debug
     public static function renderLogs()
     {
         //if (!empty(self::$logs)) {
+
             echo "<div id='debugger-logs'>";
 
             echo "<div class='debug-renderLogs-header'>";
-            echo "PHP ". phpversion() . " | " . number_format(self::$closeTime, 4) . " secondes";
+            echo "PHP ". phpversion() . " | " . number_format(self::$closeTime, 4) . " secondes ";
             echo "</div>";
+            echo "<div class=\"form-check form-switch\">
+                <input class=\"form-check-input\" type=\"checkbox\" id=\"checkIsSubmit\" " . core::checkboxSelecter(self::isSubmit(), 0) . " >
+                <label class=\"form-check-label\" for=\"checkIsSubmit\">Intercepter la validation</label>
+            </div>";
 
             foreach (self::$logs as $log) {
                 echo ($log != NULL) ? "<div class='debug-renderLogs-print'>".nl2br($log)."</div>" : NULL;
@@ -160,6 +181,11 @@ class debug
             echo "
             <script>
                 $(document).ready(function() {
+
+                    $('#checkIsSubmit').on('change', function() {
+                        window.location.href = '/submit.php?from=parametres-debug-submit-activation&actif=' + $('#checkIsSubmit').prop('checked');
+                    });
+            
                     $('#toggle-logs').click(function() {
                         $('#debugger-logs').slideToggle();
                     });

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

@@ -0,0 +1,13 @@
+<?php
+if(core::ifGet("actif")){
+    if(core::getGet("actif") == "true"){
+        debug::addFileSubmit();
+        alert::recSuccess("Le mode debug submit est activé");
+    } else {
+        debug::removeFileSubmit();
+        alert::recSuccess("Le mode debug submit est déactivé");
+    }
+}
+
+header("Location: " . $_SERVER['HTTP_REFERER']);
+exit();

+ 7 - 1
core/views/_cms.nav.php

@@ -25,11 +25,17 @@
     } else {
         $titleDebug = "";
     }
+
+    if(debug::isSubmit()){
+        $titleDebugSubmit = "<a href=\"#\" id='toggle-logs'><span class=\"badge\" style=\"background-color:red; margin-left:5px;\">MODE DEBUG SUBMIT</span></a>";
+    } else {
+        $titleDebugSubmit = "";
+    }
     
 ?>
 <header class="navbar sticky-top <?php echo $classHead ?> navbar-expand-sm navbar-dark flex-md-nowrap p-0 shadow">
     <div class="container-fluid">
-        <a href="/" style="box-shadow: none;" class="navbar-brand <?php echo $classHead ?>">CSE Invent : CMS</a><?php echo $titleEnvironnement . $titleMaintenance . $titleDebug; ?>
+        <a href="/" style="box-shadow: none;" class="navbar-brand <?php echo $classHead ?>">CSE Invent : CMS</a><?php echo $titleEnvironnement . $titleMaintenance . $titleDebug . $titleDebugSubmit; ?>
         <div id="navbarCollapse" class="collapse navbar-collapse p-0">
             <ul class="nav navbar-nav ms-auto">
                 <li class="nav-item dropdown">

+ 5 - 0
public-cms/submit.php

@@ -8,4 +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());
+    exit();
+}
+
 get::submit();