[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 08/13: Development : new tools for debugging
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 08/13: Development : new tools for debugging in the new class \Noalyss\Dbg (dbg.php); |
Date: |
Sun, 16 Oct 2022 17:26:14 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 50dcb029ffca8da4a78e500a79d8c39c595725f0
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun Oct 16 23:09:43 2022 +0200
Development : new tools for debugging in the new class \Noalyss\Dbg
(dbg.php);
---
html/admin-noalyss.php | 1 +
html/do.php | 6 +-
html/user_login.php | 6 +-
include/admin_repo.inc.php | 2 +-
include/audit_log.php | 1 +
include/category_card.inc.php | 2 +-
include/class/dossier.class.php | 4 +-
include/constant.php | 5 +-
include/lib/ac_common.php | 70 +------------
include/lib/dbg.php | 122 ++++++++++++++++++++++
include/modele.inc.php | 1 +
include/restore.inc.php | 1 +
include/template/acc_ledger-input_extra_info.php | 2 +-
include/template/card_multiple_display_option.php | 3 +-
include/template/mobile-display_menu.php | 5 +-
include/upgrade-core.php | 2 +-
include/upgrade-plugin.php | 2 +-
include/upgrade-template.php | 2 +-
include/upgrade.inc.php | 2 +-
include/user.inc.php | 1 +
20 files changed, 154 insertions(+), 86 deletions(-)
diff --git a/html/admin-noalyss.php b/html/admin-noalyss.php
index d5046f813..4965c7676 100644
--- a/html/admin-noalyss.php
+++ b/html/admin-noalyss.php
@@ -31,6 +31,7 @@ if (file_exists("../include/config.inc.php") ) {
define ('ALLOWED',1);
define ('ALLOWED_ADMIN',1);
require_once '../include/constant.php';
+ \Noalyss\Dbg::echo_file(__FILE__);
require_once NOALYSS_INCLUDE.'/admin_repo.inc.php';
} else {
// Redirect to install file , if this file exists then
diff --git a/html/do.php b/html/do.php
index 8fa3c80d8..4c72f0d45 100644
--- a/html/do.php
+++ b/html/do.php
@@ -81,9 +81,9 @@ if ( DEBUGNOALYSS > 1 ) {
/**
* Debug Design
*/
- debug_show_size();
- debug_show_request();
- debug_show_global();
+ \Noalyss\Dbg::display_size();
+ \Noalyss\Dbg::display_request();
+ \Noalyss\Dbg::display_global();
} //<--- if DEBUG
$g_parameter=new Noalyss_Parameter_Folder($cn);
diff --git a/html/user_login.php b/html/user_login.php
index cb8a396b7..ef8079bd0 100644
--- a/html/user_login.php
+++ b/html/user_login.php
@@ -65,9 +65,9 @@ if ( DEBUGNOALYSS > 1 ) {
/**
* Debug Design
*/
- debug_show_size();
- debug_show_request();
- debug_show_global();
+ \Noalyss\Dbg::display_size();
+ \Noalyss\Dbg::display_request();
+ \Noalyss\Dbg::display_global();
} //<--- if DEBUG
$ac=new Database();
$hi=new HttpInput();
diff --git a/include/admin_repo.inc.php b/include/admin_repo.inc.php
index ae9b3294c..a28b845fa 100644
--- a/include/admin_repo.inc.php
+++ b/include/admin_repo.inc.php
@@ -23,7 +23,7 @@
*/
if ( ! defined ('ALLOWED')) { die (_('Non autorisé'));}
if ( ! defined ('ALLOWED_ADMIN')) { die (_('Non autorisé'));}
-
+\Noalyss\Dbg::echo_file(__FILE__);
include_once NOALYSS_INCLUDE."/class/user.class.php";
require_once NOALYSS_INCLUDE."/lib/user_common.php";
include_once NOALYSS_INCLUDE."/lib/ac_common.php";
diff --git a/include/audit_log.php b/include/audit_log.php
index 4dc2a7f63..b4c480e25 100644
--- a/include/audit_log.php
+++ b/include/audit_log.php
@@ -23,6 +23,7 @@
* \brief let you see the list of the connexion
*/
if ( !defined ('ALLOWED')) die('Forbidden');
+\Noalyss\Dbg::echo_file(__FILE__);
?>
<DIV class="content">
<span class="notice"><?=_("100 dernières connexions")?></span>
diff --git a/include/category_card.inc.php b/include/category_card.inc.php
index 018adecd0..0806239c6 100644
--- a/include/category_card.inc.php
+++ b/include/category_card.inc.php
@@ -28,7 +28,7 @@
*/
if (!defined('ALLOWED'))
die('Appel direct ne sont pas permis');
-if ( DEBUGNOALYSS > 1 ) { echo __FILE__;}
+NoalyssDbg::echo_file(__FILE__);
global $http;
$str_dossier=Dossier::get();
diff --git a/include/class/dossier.class.php b/include/class/dossier.class.php
index d666a0a0b..5ae2c17c2 100644
--- a/include/class/dossier.class.php
+++ b/include/class/dossier.class.php
@@ -292,7 +292,7 @@ class Dossier
}
/**
- * connect to folder and give to admin. the profile Admin(builtin)
+ * @brief connect to folder and give to admin. the profile Admin(builtin)
* @param int $p_id dossier::id()
*/
static function synchro_admin($p_id)
@@ -331,7 +331,7 @@ class Dossier
}
}
/**
- * Upgrade check if the folder ACCOUNT_REPOSITORY needs to be upgrade
thanks the variable DBVERSIONREPO
+ * @brief Upgrade check if the folder ACCOUNT_REPOSITORY needs to be
upgrade thanks the variable DBVERSIONREPO
* and run all the SQL script named ac-upgradeX.sql from the folder
noalyss/include/sql/patch
* until X equal DBVERSIONREPO-1
* After it will call the function apply_patch, remove_inexistant_user and
clean_orphan_log for each folder
diff --git a/include/constant.php b/include/constant.php
index 0fec75759..4353f3926 100644
--- a/include/constant.php
+++ b/include/constant.php
@@ -40,6 +40,7 @@ $g_template_dir = $dirname . "/template";
if (file_exists($dirname . '/config.inc.php')) require_once $dirname .
'/config.inc.php';
if (!defined("NOALYSS_HOME")) define("NOALYSS_HOME", dirname($dirname) .
"/html");
+if (!defined("NOALYSS_BASE")) define("NOALYSS_BASE", dirname($dirname) );
if (!defined("NOALYSS_PLUGIN")) define("NOALYSS_PLUGIN", $g_ext_dir);
if (!defined("NOALYSS_INCLUDE")) define("NOALYSS_INCLUDE", $g_include_dir);
if (!defined("NOALYSS_TEMPLATE")) define("NOALYSS_TEMPLATE", $g_template_dir);
@@ -360,6 +361,7 @@ if (!defined("DEFAULT_SERVER_VIDEO_CONF")) {
function noalyss_class_autoloader($class)
{
$class = strtolower($class);
+
foreach (array("class","lib","database") as $path) {
if ( file_exists(NOALYSS_INCLUDE.'/'.$path.'/'.$class.'.class.php')) {
require_once NOALYSS_INCLUDE.'/'.$path.'/'.$class.'.class.php';
@@ -385,7 +387,8 @@ function noalyss_class_autoloader($class)
"ismallbutton" => "lib/ibutton.class.php",
"inputswitch" => "lib/input_switch.class.php",
"noalyss\mobile" => "class/mobile.class.php",
- "htmlinput" => "lib/html_input.class.php"
+ "htmlinput" => "lib/html_input.class.php",
+ "noalyss\dbg"=>"lib/dbg.php"
);
if (isset ($aClass[$class])) {
require_once NOALYSS_INCLUDE . "/" . $aClass[$class];
diff --git a/include/lib/ac_common.php b/include/lib/ac_common.php
index 2c2fbafaf..a440354dd 100644
--- a/include/lib/ac_common.php
+++ b/include/lib/ac_common.php
@@ -168,13 +168,10 @@ function nbm($p_number,$p_dec = 2)
function echo_error($p_log, $p_line="", $p_message="")
{
- echo "ERREUR :" . $p_log . " " . $p_line . " " . $p_message;
- $fdebug = fopen($_ENV['TMP'] . DIRECTORY_SEPARATOR . "noalyss_error.log",
"a+");
- if ($fdebug != null)
- {
- fwrite($fdebug, date("Ymd H:i:s") . $p_log . " " . $p_line . " " .
$p_message . "\n");
- fclose($fdebug);
- }
+ $msg="ERREUR :" . $p_log . " " . $p_line . " " . $p_message;
+ echo $msg;
+ syslog(LOG_ERR,$msg);
+
}
/**
@@ -1179,11 +1176,7 @@ function display_menu($p_menuid)
$array=compute_variable($file[0]['me_parameter']);
put_global($array);
}
- if ( DEBUGNOALYSS == 2)
- {
- echo $file[0]['me_file']," param : ",$file[0]['me_parameter']
;
-
- }
+ \Noalyss\Dbg::echo_var(1,$file[0]['me_file']."
".$file[0]['me_parameter']);
/*
* Log the file we input to put in the folder test-noalyss for
replaying it
*/
@@ -1683,58 +1676,5 @@ function linkTo($p_url)
return $p_url;
}
}
-function debug_show_size()
-{
- echo <<<EOF
-<div class="d-block d-sm-none " style="background-color:lightblue">Xtra
Small</div>
-<div class="d-none d-sm-block d-md-none d-lg-none d-xl-none "
style="background-color:red">Small</div>
-<div class="d-none d-md-block d-lg-none "
style="background-color:orangered">Medium</div>
-<div class="d-none d-lg-block d-xl-none "
style="background-color:orange">Large</div>
-<div class="d-none d-xl-block " style="background-color:wheat">X Large</div>
-EOF;
-}
-/**
- * @brief for development , show request (POST, GET)
- * @return void
- */
- function debug_show_request() {
- $id=uniqid("debug");
- $title=\HtmlInput::title_box(_("REQUEST"),$id,"hide");
- ?>
- <div class=" col-10 inner_box" style="display:none" id="<?=$id?>">
- <?=$title?>
-
- <h2 style="margin-top:100px"> Memory Usage
- <?php echo round(memory_get_usage()/1024.0,2) . " kb \n"; ?>
- </h2>
- $_POST
- <pre><?php echo print_r($_POST)?></pre>
- $_GET
- <pre><?=print_r($_GET)?></pre>
- $_REQUEST
- <pre><?=print_r($_REQUEST)?></pre>
- <?=\HtmlInput::button_hide($id)?>
- </div>
- <input type="button" onclick="document.getElementById('<?=$id?>').show();"
value="Show request">
- <?php
-}
-/**
- * @brief for development , show GLOBAL and SESSION
- * @return void
- */
- function debug_show_global() {
- $id=uniqid("debug");
- $title=\HtmlInput::title_box(_("GLOBALS"),$id,"hide");
- ?>
- <div class=" col-10 inner_box" style="display:none" id="<?=$id?>">
- <?=$title?>
- $GLOBALS
- <pre><?=print_r($GLOBALS)?></pre>
-
- <?=\HtmlInput::button_hide($id)?>
- </div>
- <input type="button" onclick="document.getElementById('<?=$id?>').show();"
value="Show session">
- <?php
-}
diff --git a/include/lib/dbg.php b/include/lib/dbg.php
new file mode 100644
index 000000000..03232c897
--- /dev/null
+++ b/include/lib/dbg.php
@@ -0,0 +1,122 @@
+<?php
+
+namespace Noalyss;
+
+class Dbg
+{
+ public static function echo_var($n_level, $msg)
+ {
+ if (DEBUGNOALYSS > $n_level) {
+ echo '<span style="font-size:12px;color:orangered">';
+ $type = gettype($msg);
+ if (in_array($type, ["string", "integer", "double"])) {
+ echo $msg;
+ } else {
+
+ echo "<pre>DBG";
+ var_export($msg);
+ echo '</pre>';
+ }
+ echo '</span>';
+ }
+ }
+
+ public static function echo_file($msg)
+ {
+ if (DEBUGNOALYSS > 1) {
+ echo '<span style="font-size:12px;color:brown">';
+ echo "[FILE: $msg]";
+
+ echo '</span>';
+ }
+ }
+
+ static function display_size()
+ {
+ echo <<<EOF
+<div class="d-block d-sm-none " style="background-color:lightblue">Xtra
Small</div>
+<div class="d-none d-sm-block d-md-none d-lg-none d-xl-none "
style="background-color:red">Small</div>
+<div class="d-none d-md-block d-lg-none "
style="background-color:orangered">Medium</div>
+<div class="d-none d-lg-block d-xl-none "
style="background-color:orange">Large</div>
+<div class="d-none d-xl-block " style="background-color:wheat">X Large</div>
+EOF;
+ }
+
+ /**
+ * @brief for development , show request (POST, GET)
+ * @return void
+ */
+ static function display_request()
+ {
+ $id = uniqid("debug");
+ $title = \HtmlInput::title_box(_("REQUEST"), $id, "hide");
+ ?>
+ <div class=" col-10 inner_box" style="display:none" id="<?= $id ?>">
+ <?= $title ?>
+
+ <h2 style="margin-top:100px"> Memory Usage
+ <?php echo round(memory_get_usage() / 1024.0, 2) . " kb \n"; ?>
+ </h2>
+ $_POST
+ <pre><?php echo print_r($_POST) ?></pre>
+ $_GET
+ <pre><?= print_r($_GET) ?></pre>
+ $_REQUEST
+ <pre><?= print_r($_REQUEST) ?></pre>
+ <?= \HtmlInput::button_hide($id) ?>
+ </div>
+ <input type="button" onclick="document.getElementById('<?= $id
?>').show();" value="Show request">
+ <?php
+ }
+
+ /**
+ * @brief for development , show GLOBAL and SESSION
+ * @return void
+ */
+ static function display_global()
+ {
+ $id = uniqid("debug");
+ $title = \HtmlInput::title_box(_("GLOBALS"), $id, "hide");
+ ?>
+ <div class=" col-10 inner_box" style="display:none" id="<?= $id ?>">
+ <?= $title ?>
+ $GLOBALS
+ <pre><?= print_r($GLOBALS) ?></pre>
+
+ <?= \HtmlInput::button_hide($id) ?>
+ </div>
+ <input type="button" onclick="document.getElementById('<?= $id
?>').show();" value="Show session">
+ <?php
+ }
+
+ /**
+ * @brief Show a icon to display large information on demand, when you
click it , the content will be showned
+ * @param string $p_title title of the dialog box
+ * @param mixed $msg var_export of the msg
+ * @return string HTML to display
+ */
+ public static function hidden_info($p_title,$msg)
+ {
+ $id=uniqid("debug");
+ $title=\HtmlInput::title_box($p_title,"$id"."_infodiv","hide");
+ $content=var_export($msg,true);
+
+ $button_close=\HtmlInput::button_hide("$id"."_infodiv");
+ $r=<<<EOF
+<div id="{$id}_infodiv" style="display: none;background:rgba(234, 221, 114,
0.66);color:black;font-size:80%;width:auto;">
+{$title}
+<div>
+<pre>
+ {$content}
+
+</pre>
+</div>
+{$button_close}
+</div>
+<a href="javascript:void(0)" onclick="$('{$id}_infodiv').show()">🕶</a>
+
+EOF;
+ return $r;
+ }
+}
+?>
\ No newline at end of file
diff --git a/include/modele.inc.php b/include/modele.inc.php
index 56f787e96..37ad0d242 100644
--- a/include/modele.inc.php
+++ b/include/modele.inc.php
@@ -27,6 +27,7 @@
*
*/
if ( !defined ('ALLOWED')) die('Forbidden');
+\Noalyss\Dbg::echo_file(__FILE__);
$http=new HttpInput();
$sa = $http->request("sa", "string", 'list');
if (isset($_POST['upd']) &&
diff --git a/include/restore.inc.php b/include/restore.inc.php
index 7d4aeca94..c62550a16 100644
--- a/include/restore.inc.php
+++ b/include/restore.inc.php
@@ -19,6 +19,7 @@
// Copyright Author Dany De Bontridder danydb@aevalys.eu
if ( !defined ('ALLOWED')) die('Forbidden');
+\Noalyss\Dbg::echo_file(__FILE__);
$http=new HttpInput();
/*!\file
* \brief restaure a database
diff --git a/include/template/acc_ledger-input_extra_info.php
b/include/template/acc_ledger-input_extra_info.php
index a4f45d379..9cd54d33d 100644
--- a/include/template/acc_ledger-input_extra_info.php
+++ b/include/template/acc_ledger-input_extra_info.php
@@ -21,7 +21,7 @@
if (!defined('ALLOWED'))
die('Appel direct ne sont pas permis');
-if (DEBUGNOALYSS>1) { echo __FILE__;}
+\Noalyss\Dbg::echo_file(__FILE__);
/**
* @file
* @brief display supplemental information to save when entering an operation
of
diff --git a/include/template/card_multiple_display_option.php
b/include/template/card_multiple_display_option.php
index 9e37e481a..79687bb2d 100644
--- a/include/template/card_multiple_display_option.php
+++ b/include/template/card_multiple_display_option.php
@@ -34,10 +34,11 @@ if (!defined('ALLOWED'))
* - $a_option.ap_id (-1 if option for this contact doesn't
exist)
* @see Card_Multiple
*/
+\Noalyss\Dbg::echo_file(__FILE__);
?>
<h3 class="info" style="margin:1px">
<?=$aIdentity['name']." ".$aIdentity['first_name']."
".$aIdentity['qcode']?>
-</h2>
+</h3>
<form method="POST" onsubmit="save_linked_card_option(this);return false">
<input type="hidden" name="op" value="card">
<input type="hidden" name="op2" value="save_card_option">
diff --git a/include/template/mobile-display_menu.php
b/include/template/mobile-display_menu.php
index 1017c061b..b586bc70f 100644
--- a/include/template/mobile-display_menu.php
+++ b/include/template/mobile-display_menu.php
@@ -25,10 +25,7 @@ if (!defined('ALLOWED'))
* @file
* @brief show the mobile menu
*/
-if (DEBUGNOALYSS>1)
-{
- echo __FILE__;
-};
+\Noalyss\Dbg::dbgecho_file(__FILE__);
?>
<img src="<?=NOALYSS_URL?>/image/logo9000.png" width="100%"
style="position:absolute;top:0px;left:0px;z-index:-1;opacity: 11%">
<div id="mobile_module" >
diff --git a/include/upgrade-core.php b/include/upgrade-core.php
index bf11fbb94..b9f4cab79 100644
--- a/include/upgrade-core.php
+++ b/include/upgrade-core.php
@@ -21,7 +21,7 @@
if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
if ( ! defined ('ALLOWED_ADMIN')) { die (_('Non autorisé'));}
-
+\Noalyss\Dbg::echo_file(__FILE__);
global $version_noalyss;
/**
* @file
diff --git a/include/upgrade-plugin.php b/include/upgrade-plugin.php
index 092281cc4..a902b186e 100644
--- a/include/upgrade-plugin.php
+++ b/include/upgrade-plugin.php
@@ -25,7 +25,7 @@ if (!defined('ALLOWED_ADMIN'))
die(_('Non autorisé'));
}
-
+\Noalyss\Dbg::echo_file(__FILE__);
/**
* @file
diff --git a/include/upgrade-template.php b/include/upgrade-template.php
index f109f15d1..0dec1b405 100644
--- a/include/upgrade-template.php
+++ b/include/upgrade-template.php
@@ -24,7 +24,7 @@ if (!defined('ALLOWED_ADMIN'))
{
die(_('Non autorisé'));
}
-
+\Noalyss\Dbg::echo_file(__FILE__);
$package_repository=new Package_Repository();
$xml=$package_repository->getContent();
diff --git a/include/upgrade.inc.php b/include/upgrade.inc.php
index 3b79dfed9..dc2c1495f 100644
--- a/include/upgrade.inc.php
+++ b/include/upgrade.inc.php
@@ -25,7 +25,7 @@
*/
if (!defined('ALLOWED')) die('Appel direct ne sont pas permis');
if ( ! defined ('ALLOWED_ADMIN')) { die (_('Non autorisé'));}
-
+\Noalyss\Dbg::echo_file(__FILE__);
$http=new HttpInput();
$menu=array(
diff --git a/include/user.inc.php b/include/user.inc.php
index 7cb024572..af1e3ed9e 100644
--- a/include/user.inc.php
+++ b/include/user.inc.php
@@ -28,6 +28,7 @@ if ( !defined ('ALLOWED')) die('Forbidden');
*/
$http=new HttpInput();
echo '<div class="content" >';
+\Noalyss\Dbg::echo_file(__FILE__);
/******************************************************/
// Add user
/******************************************************/
- [Noalyss-commit] [noalyss] branch master updated (e133e0ca8 -> 75d59f1b5), Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 02/13: Cosmetic, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 11/13: - Override the function __toString to comply with xdebug - function Card_Property::input ; the build of the HtmlInput is done is a separated function Card_Property::build_input to ease the override of the input function, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 09/13: New Icon_Action for hidding or showing a DIV, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 12/13: Development : tools for debugging, add button for the $_REQUEST and correct a bug in dbg.php, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 13/13: merge, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 01/13: Improve DEBUG, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 05/13: add magic function toString, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 06/13: typo, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 08/13: Development : new tools for debugging in the new class \Noalyss\Dbg (dbg.php);,
Dany De Bontridder <=
- [Noalyss-commit] [noalyss] 10/13: - Override the function __toString to comply with xdebug - Correct bug in input_switch.class.php when there is several input_switch - FicheDef the insertAttribut can have an order, usefull when installing new category + attribute, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 04/13: Cosmetic : warning, Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 07/13: Task #0001755: Dans Administration - dossier - «Sauvegarde» et non «Backup», Dany De Bontridder, 2022/10/16
- [Noalyss-commit] [noalyss] 03/13: Code cleaning pg_fetch_array, Dany De Bontridder, 2022/10/16