From 3bfa6c85d3beadf7202be0558c94595cdc399258 Mon Sep 17 00:00:00 2001 From: seek3r Date: Thu, 14 Feb 2002 18:57:11 +0000 Subject: [PATCH] extending print_debug() to be able to trap the data and toss it into a database as an option --- header.inc.php.template | 1 + phpgwapi/inc/functions.inc.php | 52 ++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/header.inc.php.template b/header.inc.php.template index 1ce39d0dcd..6cca34f2ff 100644 --- a/header.inc.php.template +++ b/header.inc.php.template @@ -94,6 +94,7 @@ define('DEBUG_API', False); define('DEBUG_DATATYPES', True); define('DEBUG_LEVEL', 3); + define('DEBUG_OUTPUT', 2); /* 1 = screen, 2 = DB (not supported with PHP3). For both use 3. */ /**************************************************************************\ * Do not edit these lines * diff --git a/phpgwapi/inc/functions.inc.php b/phpgwapi/inc/functions.inc.php index 9d8e882fc3..6ee82faaf7 100644 --- a/phpgwapi/inc/functions.inc.php +++ b/phpgwapi/inc/functions.inc.php @@ -72,8 +72,12 @@ */ function print_debug($message,$var = 'messageonly',$part = 'app', $level = 3) { - if (($part == 'app' && DEBUG_APP == True) || ($part == 'api' && DEBUG_API == True)) + if (($part == 'app' && EXP_DEBUG_APP == True) || ($part == 'api' && DEBUG_API == True)) { + if (!defined('DEBUG_OUTPUT')) + { + define('DEBUG_OUTPUT', 1); + } if ($level >= DEBUG_LEVEL) { if (!is_array($var)) @@ -82,27 +86,54 @@ { if (!DEBUG_DATATYPES) { - echo "$message\n$var
\n"; + $output = "$message\n$var"; } else { - echo "$message\n$var is a ".gettype($var)."
\n"; + $output = "$message\n$var is a ".gettype($var); } } else { - echo "$message
\n"; + $output = $message; } + + /* Bit 1 means to output to screen */ + if (!!(DEBUG_OUTPUT & 1)) + { + echo "$output
\n"; + } + /* Bit 2 means to output to sql */ + if (!!(DEBUG_OUTPUT & 2)) + { + /* Need to flesh this out still. I dont have a table to dump this in yet.*/ + /* So the SQL statement will go here*/ + } + + /* Example of how this can be extended to output to other locations as well. This example uses a COM object */ + /* + if (!!(DEBUG_OUTPUT & 32)) + { + $obj_debug = new COM('Some_COM_App.Class','localhost'); + if (is_object($obj_debug)) + { + $DebugMessage_return = $obj_debug->DebugMessage($output); + } + } + */ } else { + if (floor(phpversion()) > 3 && !!(DEBUG_OUTPUT & 2)) + { + ob_start(); + } echo "
\n$message\n";
 					print_r($var);
 					if (DEBUG_DATATYPES)
 					{
 						while(list($key, $value) = each($var))
 						{
-							//echo 'Array['.$key.'] is a '.gettype($var[$key])."\n";
 							if (is_array($value))
 							{
 								$vartypes[$key] = print_debug_subarray($value);
@@ -116,6 +147,17 @@
 						print_r($vartypes);
 					}
 					echo "\n
\n";
+					if (floor(phpversion()) > 3 && !!(DEBUG_OUTPUT & 2))
+					{
+						$output .= ob_get_contents();
+						ob_end_clean();
+						/* Need to flesh this out still. I dont have a table to dump this in yet.*/
+						/* So the SQL statement will go here*/
+						if (!!(DEBUG_OUTPUT & 1))
+						{
+							echo "$output
\n"; + } + } } } }