<?php
/**************************************************************************
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
@Authors: Ryan Thompson(hide@address.com)
***************************************************************************/
/*$Id: class.error.php,v 1.13 2004/05/31 03:55:13 rthomp Exp $*/
class error
{
var $error_id;
var $buffer = FALSE;
var $message;
var $language = 'en_ca';
var $display;
var $debug_status;
/*!
@function user_error()
@author Ryan Thompson
@abstract Returns a user based error (i.e. Failed login)
@version 0.1
@params ???
@return ???
@since 03-11-2003
*/
function user_error()
{
}
/*!
@function debug()
@author Ryan Thompson
@abstract If Debug is enabled return system errors can record to log to
@version 0.1
@params ???
@return ???
@since 03-11-2003
@note All debug errors is debug enabled will kill script
*/
function debug($error_type, $data = NULL)
{
GLOBAL $O;
//Why twice??
if($this->debug_status == FALSE)
{
switch($error_type)
{
case 'sql':
print("There was an error while trying to access the database");
break;
default:
print("Error executing Program. The script will continue but may not function properly.");
break;
}
return;
}
$error_data = debug_backtrace();
$error_count = count($error_data);
foreach($error_data AS $key => $value)
{
echo "<br />";
echo "Running Backtrace....";
echo "<br />";
echo "Function: ". $value['function'];
echo "<br />";
echo "{$value['file']}({$value['line']})";
echo "<br />";
foreach($value as $h => $i)
{
echo $h . ' => '. $i;
echo "<br />";
}
$this->debug_args($value['args']);
echo "<br />";
}
exit();
}
/*!
@function debug_args()
@author Ryan Thompson
@abstract A recursively called function to display function arguments in backtrace
@version 0.1
@params ???
@return ???
@since 03-11-2003
*/
function debug_args($args)
{
foreach($args AS $id => $arg)
{
if(is_array($arg))
{
$this->debug_args($arg);
} else {
echo "<pre>";
echo "\t". $id;
echo "\t". $arg;
echo "</pre>";
}
}
return;
}
function get_message($error_id, $string_replace = '', $replace_with = '')
{
GLOBAL $lang, $db;
$this->error_id = $error_id;
$this->language = $lang->user_language;
$sql = "SELECT * FROM o_text WHERE id_text='$error_id' AND language='". $this->language ."'";
$db->query($sql);
$db->fetch_results();
$this->message = $db->record['messages'];
if($string_replace != '')
{
$this->message = str_replace($string_replace, $replace_with, $this->message);
}
$buffered = $this->create_message($this->message);
return $buffered;
}
function create_message($msg)
{
$this->display = "<table width=\"500\" style=\"border: 1px solid black\" align=\"center\">";
$this->display .= "<tr><td id=\"error\">\n";
$this->display .= "<b>Error: ". $this->error_id ."</b><br>". $msg;
$this->display .= "</td></tr></table>";
$this->buffer = TRUE;
return $this->buffer;
}
function display($die = FALSE)
{
$this->buffer = FALSE;
if($die)
{
$this->display .= die();
}
return $this->display;
}
}