<?php
/*
*(c) 2003 christoph althammer hide@address.com
* http://www.milpa.de
*
* GNU GENERAL PUBLIC LICENSE
* die deutsche Übersetzung der GPL ist zu finden auf www.suse.org.
*
* auth: c. althammer
* date: 2002-10-10
* lc : 2002-10-17
* comm: main
*
*
*/
class Debug {
var $GlobalDebug = false;
var $Mode = "screen"; // screen, popup
function Debug($Message=""){
$Conf = new Conf;
$this->GlobalDebug = $Conf->Debug;
$this->Mode = $Conf->DebugMode;
if (!empty($Message)) $this->Send($Message);
return $GlobalDebug;
}
function Send($Message=""){
if (!$this->GlobalDebug) return false;
$Time = date("d.m.Y H:m:s");
global $PHP_SELF;
$Filename = $PHP_SELF;
switch ($this->Mode){
case "popup": $this->WriteToPopup($Message);
break;
default: $this->WriteOnScreen($Time,$Filename,$Message);
break;
}
return true;
}
function WriteOnScreen($Time="",$Filename="",$Message=""){
echo"<br><span class=debug>[$Time Class:$Classname] $Message</span>";
return true;
}
function WriteToPopup($Message=""){
global $AppDebugger;
$AppDebugger->v($Message);
return true;
}
/*
* YOU ARE NOT ALLOWED TO MODIFY COPYRIGHT INFORMATION
*
*/
function Info(){
$D = date("d.m.Y H:m:s");
$Comment = new Comment("::ExecApplicationEngine(). $D AFW 1.4 (c) 2003 http://www.milpa.de");
return true;
}
function OpenWindow(){
}
}
class Error {
var $HaltOnError = true; // true, false
function Error($Message="",$Classname="",$Filename=""){
$Conf = new Conf;
$this->HaltOnError = $Conf->HaltOnApplicationError;
if (!empty($Message)) $this->Send($Message,$Classname,$Filename);
return $HaltOnError;
}
function Send($Message="",$Classname="",$Filename=""){
$Time = date("d.m.Y H:m:s");
global $PHP_SELF;
if (empty($Filename)) $Filename = $PHP_SELF;
if ($this->HaltOnError == true) {
$this->WriteOnScreen($Time,$Filename,$Classname,$Message);
die();
}
return true;
}
function WriteOnScreen($Time="",$Filename="",$Classname="",$Message=""){
$msg="<br><span size=\"3\" color=\"#330000\">Application halted on Error:[$Time: file:$Filename Class:$Classname] $Message</span>";
echo$msg;
$this->AdminEmail($msg);
return true;
}
function AdminEmail($msg=""){
$Conf= new Conf;
if ($Conf->HaltOnDatabaseError == "email"){
global $PHP_SELF;
$bod="Application Error!\nUrl=$PHP_SELF\n";
$bod.="Sent by AFW 1.4 www.milpa.de\n\n";
$bod.="\n\n";
$bod.=$msg;
mail($Conf->AdminEmail,"AFW Application Error ",$bod);
}
return true;
}
}
/* end of class */
class AppDebug {
var $show = false;
var $depth = 0;
//------------------------------------------
// Format variable recursively based on type
function v2($V,$Name="",$class=false)
{
if ($this->depth > 32) return '<p>Recursive Depth Exceeded</p>';
$this->depth += 1;
$TYPE_COLOR = "RED";
$NAME_COLOR = "BLUE";
$VALUE_COLOR = "BLACK";
$D = "";
$Name = htmlspecialchars($Name);
$type = gettype($V);
if (is_string($V)) {
$V = htmlspecialchars($V);
$D = "<FONT COLOR=$TYPE_COLOR><B>$type: </B></FONT>";
if ($Name!="") $D .= "<FONT COLOR=$NAME_COLOR>$Name</FONT> = ";
$D .= "<FONT COLOR=$VALUE_COLOR>"$V"</FONT>";
} else if (is_object($V)) {
$D .= $this->v2(get_object_vars($V),$Name,get_class($V));
$D = substr($D,0,strlen($D)-4); // get rid of last BR
} else if (is_array($V)) {
if ($class) $t = "Class $class";
else $t = 'Array';
$D = "<FONT COLOR=$TYPE_COLOR><B>$t: </B></FONT>";
if ($Name!="") $D .= " (<FONT COLOR=$NAME_COLOR>$Name</FONT>) ";
$D .= "<FONT COLOR=$VALUE_COLOR><UL>";
foreach($V as $key => $val) {
$D .= $this->v2($val,$key);
}
//$D = substr($D,0,strlen($D)-4); // get rid of last BR
$D .= "</UL></FONT>";
} else {
if ($V === null) $V = 'null';
else if ($V === false) $V = 'false';
else if ($V === true) $V = 'true';
$D = "<FONT COLOR=$TYPE_COLOR><B>$type: </B></FONT>";
if ($Name!="") $D .= "<FONT COLOR=$NAME_COLOR>$Name</FONT> = ";
$D .= "<FONT COLOR=$VALUE_COLOR>$V</FONT>";
}
$D .= "<BR>";
$this->depth -= 1;
return($D);
}
function _show()
{
if (!$this->show) {
global $PHP_SELF;
$file = $PHP_SELF;
$D = "<TABLE SIZE=100% CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD><HR SIZE=1></TD><TD WIDTH=1%><FONT FACE='Verdana,arial' SIZE=1>".date("d.m.Y")." ".date("H:i:s")."</FONT></TD></TR></TABLE>";
?>
<SCRIPT>
DebugWindoww=window.open('',"DEBUGVAR","WIDTH=450,HEIGHT=500,scrollbars=yes,resizable=yes");
if (DebugWindoww) {
DebugWindoww.focus();
DebugWindoww.document.write("<?php echo $D;?>"+'<b>'+window.location.href+'</b></p>');
}
</SCRIPT>
<?php
$this->show = true;
}
}
//---------------------------------
// display message in debug window
function msg($D,$encode=true)
{
$this->_show();
if ($encode) $D = htmlspecialchars($D).'<p>';
$D = str_replace('\\','\\\\',$D);
$D = str_replace('"','\"',$D);
$D = str_replace("\r",' ',$D);
$D = str_replace("\n",' ',$D);
?>
<SCRIPT>
if (DebugWindoww) {
DebugWindoww.document.write("<?php echo $D; ?>");
DebugWindoww.scrollBy(0,100000);
}
</SCRIPT>
<?php
}
//---------------------------------
// display variable in debug window
function v($V,$Name="")
{
$this->_show();
$D = $this->v2($V,$Name);
if (!is_object($V) and !is_array($V)) $D .= '<br>';
$this->msg($D,false);
}
} // AppDebug class
?>