egroupware/phpgwapi/inc/class.error.inc.php

115 lines
3.0 KiB
PHP
Raw Normal View History

2001-08-05 08:48:42 +02:00
<?php
/**************************************************************************\
* phpGroupWare - eventlog *
* http://www.phpgroupware.org *
* This application written by jerry westrick <jerry@westrick.com> *
* -------------------------------------------- *
* 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. *
\**************************************************************************/
/* $Id$ */
class error
{
/***************************\
* Instance Variables... *
\***************************/
var $severity = 'E';
var $code = 'Unknown';
var $msg = 'Unknown error';
var $parms = array();
var $ismsg = 0;
var $timestamp;
2001-08-08 09:21:29 +02:00
var $fname;
var $line;
var $app;
2001-08-15 18:30:16 +02:00
2001-08-05 08:48:42 +02:00
var $public_functions = array();
// Translate Message into Language
function langmsg()
{
2001-12-28 06:32:59 +01:00
return lang($this->msg,$this->parms);
}
2001-08-05 08:48:42 +02:00
2001-08-08 09:21:29 +02:00
function error($parms)
2001-08-05 08:48:42 +02:00
{
2001-08-08 09:21:29 +02:00
if ($parms == '')
{
return;
2001-08-15 18:30:16 +02:00
}
$etext = $parms['text'];
$parray = Array();
for($counter=1;$counter<=10;$counter++)
{
$str = 'p_'.$counter;
if(isset($parms[$str]) && !empty($parms[$str]))
{
$parray[$counter] = $parms[$str];
}
else
{
$str = 'p'.$counter;
if(isset($parms[$str]) && !empty($parms[$str]))
{
$parray[$counter] = $parms[$str];
}
}
}
2001-08-08 09:21:29 +02:00
$fname = $parms['file'];
$line = $parms['line'];
2001-08-16 04:57:29 +02:00
if (eregi('([DIWEF])-([[:alnum:]]*)\, (.*)',$etext,$match))
2001-08-05 08:48:42 +02:00
{
$this->severity = strtoupper($match[1]);
$this->code = $match[2];
$this->msg = trim($match[3]);
}
else
{
$this->msg = trim($etext);
}
@reset($parray);
while( list($key,$val) = each( $parray ) )
{
$this->msg = preg_replace( "/%$key/", "'".$val."'", $this->msg );
}
@reset($parray);
2001-08-05 08:48:42 +02:00
$this->timestamp = time();
2001-12-28 06:32:59 +01:00
$this->parms = $parray;
$this->ismsg = $parms['ismsg'];
$this->fname = $fname;
$this->line = $line;
$this->app = $GLOBALS['phpgw_info']['flags']['currentapp'];
2001-08-15 18:30:16 +02:00
2001-12-28 06:32:59 +01:00
if (!$this->fname or !$this->line)
2001-08-08 09:21:29 +02:00
{
2001-09-23 21:33:39 +02:00
$GLOBALS['phpgw']->log->error(array(
2001-08-15 18:30:16 +02:00
'text'=>'W-PGMERR, Programmer failed to pass __FILE__ and/or __LINE__ in next log message',
'file'=>__FILE__,'line'=>__LINE__
));
2001-08-08 09:21:29 +02:00
}
2001-08-15 18:30:16 +02:00
2001-09-23 21:33:39 +02:00
$GLOBALS['phpgw']->log->errorstack[] = $this;
2001-08-05 08:48:42 +02:00
if ($this->severity == 'F')
{
// This is it... Don't return
2001-08-08 09:21:29 +02:00
// do rollback!
2001-08-05 08:48:42 +02:00
// Hmmm this only works if UI!!!!
// What Do we do if it's a SOAP/XML?
echo "<Center>";
echo "<h1>Fatal Error</h1>";
echo "<h2>Error Stack</h2>";
2001-09-23 21:33:39 +02:00
echo $GLOBALS['phpgw']->log->astable();
2001-08-05 08:48:42 +02:00
echo "</center>";
// Commit stack to log
2001-09-23 21:33:39 +02:00
$GLOBALS['phpgw']->log->commit();
$GLOBALS['phpgw']->common->phpgw_exit(True);
2001-08-05 08:48:42 +02:00
}
}
}