2001-08-06 18:32:40 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2001-08-15 18:30:16 +02:00
|
|
|
* phpGroupWare - errorlog *
|
2001-08-06 18:32:40 +02:00
|
|
|
* 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 errorlog
|
|
|
|
{
|
|
|
|
/***************************\
|
|
|
|
* Instance Variables... *
|
|
|
|
\***************************/
|
2001-12-28 06:32:59 +01:00
|
|
|
var $errorstack = array();
|
2001-08-15 18:30:16 +02:00
|
|
|
var $public_functions = array(
|
|
|
|
'message',
|
|
|
|
'error',
|
|
|
|
'iserror',
|
|
|
|
'severity',
|
|
|
|
'commit',
|
|
|
|
'clearstack',
|
|
|
|
'astable'
|
|
|
|
);
|
|
|
|
|
2001-08-06 19:53:07 +02:00
|
|
|
function message($parms)
|
2001-08-06 18:32:40 +02:00
|
|
|
{
|
2001-08-08 09:21:29 +02:00
|
|
|
$parms['ismsg']=1;
|
|
|
|
CreateObject('phpgwapi.error',$parms);
|
|
|
|
return true;
|
2001-08-06 18:32:40 +02:00
|
|
|
}
|
2001-08-15 18:30:16 +02:00
|
|
|
|
2001-08-06 19:53:07 +02:00
|
|
|
function error($parms)
|
2001-08-06 18:32:40 +02:00
|
|
|
{
|
2001-08-08 09:21:29 +02:00
|
|
|
$parms['ismsg']=0;
|
|
|
|
CreateObject('phpgwapi.error',$parms);
|
|
|
|
return true;
|
2001-08-06 18:32:40 +02:00
|
|
|
}
|
|
|
|
|
2001-08-06 19:53:07 +02:00
|
|
|
function write($parms)
|
2001-08-06 18:32:40 +02:00
|
|
|
{
|
2001-08-08 09:21:29 +02:00
|
|
|
$parms['ismsg']=0;
|
2001-08-06 18:32:40 +02:00
|
|
|
$save = $this->errorstack;
|
|
|
|
$this->$errorstack = array();
|
2001-08-08 09:21:29 +02:00
|
|
|
CreateObject('phpgwapi.error',$parms);
|
2001-08-06 18:32:40 +02:00
|
|
|
$this->commit();
|
|
|
|
$this->errorstack = $save;
|
2001-08-08 09:21:29 +02:00
|
|
|
return true;
|
2001-08-06 18:32:40 +02:00
|
|
|
}
|
2001-08-15 18:30:16 +02:00
|
|
|
|
2001-08-06 19:53:07 +02:00
|
|
|
function iserror($parms)
|
2001-08-06 18:32:40 +02:00
|
|
|
{
|
2001-08-06 19:53:07 +02:00
|
|
|
$ecode = $parms['code'];
|
2001-08-06 18:32:40 +02:00
|
|
|
$errorstack = $this->errorstack;
|
|
|
|
reset($errorstack);
|
|
|
|
while(list(,$err)=each($errorstack))
|
|
|
|
{
|
|
|
|
if ($ecode == $err->code)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2001-08-15 18:30:16 +02:00
|
|
|
|
2001-08-06 18:32:40 +02:00
|
|
|
function severity()
|
|
|
|
{
|
2001-08-08 09:21:29 +02:00
|
|
|
$max = 'D';
|
2001-08-06 18:32:40 +02:00
|
|
|
$errorstack = $this->errorstack;
|
|
|
|
reset($errorstack);
|
|
|
|
while(list(,$err)=each($errorstack))
|
|
|
|
{
|
|
|
|
switch($err->severity)
|
|
|
|
{
|
2001-08-21 20:34:56 +02:00
|
|
|
case 'F':
|
|
|
|
return 'F';
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
$max = 'E';
|
|
|
|
break;
|
|
|
|
case 'W':
|
|
|
|
if ($max != 'E')
|
|
|
|
{
|
|
|
|
$max = 'W';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
if ($max == 'D')
|
|
|
|
{
|
|
|
|
$max = 'I';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2001-08-06 18:32:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $max;
|
|
|
|
}
|
2001-08-15 18:30:16 +02:00
|
|
|
|
2001-08-06 18:32:40 +02:00
|
|
|
function commit()
|
|
|
|
{
|
2001-09-23 21:33:39 +02:00
|
|
|
$db = $GLOBALS['phpgw']->db;
|
2001-08-08 09:21:29 +02:00
|
|
|
// $db->lock('phpgw_log');
|
2001-12-28 06:32:59 +01:00
|
|
|
$db->query("insert into phpgw_log (log_date, log_user, log_app, log_severity) values "
|
|
|
|
."('". $GLOBALS['phpgw']->db->to_timestamp(time())
|
|
|
|
."','".$GLOBALS['phpgw']->session->account_id
|
|
|
|
."','".$GLOBALS['phpgw_info']['flags']['currentapp']."'"
|
|
|
|
.",'".$this->severity()."'"
|
|
|
|
.")"
|
|
|
|
,__LINE__,__FILE__
|
|
|
|
);
|
2001-08-06 18:32:40 +02:00
|
|
|
|
2001-08-08 09:21:29 +02:00
|
|
|
$log_id = $db->get_last_insert_id('phpgw_log','log_id');
|
2001-08-21 20:34:56 +02:00
|
|
|
// $db->query('select max(log_id) as lid from phpgw_log');
|
2001-08-08 09:21:29 +02:00
|
|
|
// $db->next_record();
|
|
|
|
// $log_id = $db->f('lid');
|
|
|
|
// $db->unlock();
|
2001-08-06 18:32:40 +02:00
|
|
|
|
|
|
|
$errorstack = $this->errorstack;
|
|
|
|
for ($i = 0; $i < count($errorstack); $i++)
|
|
|
|
{
|
|
|
|
$err = $errorstack[$i];
|
2001-12-28 06:32:59 +01:00
|
|
|
$db->query("insert into phpgw_log_msg "
|
|
|
|
."(Log_msg_log_id, log_msg_seq_no, log_msg_date, log_msg_severity, "
|
|
|
|
."log_msg_code, log_msg_msg, log_msg_parms, log_msg_file, log_msg_line) values "
|
|
|
|
."(" . $log_id
|
|
|
|
."," . $i
|
|
|
|
.", '" . $GLOBALS['phpgw']->db->to_timestamp($err->timestamp)
|
|
|
|
."', '". $err->severity . "'"
|
|
|
|
.", '". $err->code . "'"
|
|
|
|
.", '". $db->db_addslashes($err->msg) . "'"
|
2002-01-12 23:12:40 +01:00
|
|
|
.", '". $db->db_addslashes((count($err->parms) > 1?implode('|',$err->parms):$err->parms[1])). "'"
|
2001-12-28 06:32:59 +01:00
|
|
|
.", '". $err->fname . "'"
|
|
|
|
.", " . intval($err->line)
|
|
|
|
.")"
|
|
|
|
,__LINE__,__FILE__
|
|
|
|
);
|
|
|
|
}
|
2001-08-06 18:32:40 +02:00
|
|
|
unset ($errorstack);
|
|
|
|
unset ($this->errorstack);
|
|
|
|
$this->errorstack = array();
|
2001-08-08 09:21:29 +02:00
|
|
|
return true;
|
2001-08-06 18:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function clearstack()
|
|
|
|
{
|
|
|
|
$new = array();
|
|
|
|
reset($this->errorstack);
|
|
|
|
for ($i = 0; $i < count($this->errorstack); $i++)
|
|
|
|
{
|
|
|
|
$err = $this->errorstack[$i];
|
|
|
|
if ($err->ismsg)
|
|
|
|
{
|
|
|
|
$new[] = $err;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
unset ($this->errorstack);
|
|
|
|
$this->errorstack = $new;
|
2001-08-08 09:21:29 +02:00
|
|
|
return true;
|
2001-12-28 06:32:59 +01:00
|
|
|
}
|
2001-08-06 18:32:40 +02:00
|
|
|
|
|
|
|
function astable()
|
|
|
|
{
|
|
|
|
$html = "<center>\n";
|
|
|
|
$html .= "<table width=\"98%\">\n";
|
|
|
|
$html .= "\t<tr bgcolor=\"D3DCFF\">\n";
|
|
|
|
$html .= "\t\t<td width=\"2%\">No</td>\n";
|
|
|
|
$html .= "\t\t<td width=\"16%\">Date</td>\n";
|
|
|
|
$html .= "\t\t<td width=\"15%\">App</td>\n";
|
|
|
|
$html .= "\t\t<td align=\"center\", width=\"2%\">S</td>\n";
|
|
|
|
$html .= "\t\t<td width=\"10%\">Error Code</td>\n";
|
|
|
|
$html .= "\t\t<td >Msg</td>\n";
|
2001-08-08 09:21:29 +02:00
|
|
|
$html .= "\t\t<td >File</td>\n";
|
|
|
|
$html .= "\t\t<td >Line</td>\n";
|
2001-08-06 18:32:40 +02:00
|
|
|
$html .= "\t</tr>\n";
|
2001-08-15 18:30:16 +02:00
|
|
|
|
2001-08-06 18:32:40 +02:00
|
|
|
$errorstack = $this->errorstack;
|
|
|
|
for ($i = 0; $i < count($errorstack); $i++)
|
|
|
|
{
|
|
|
|
$err = $errorstack[$i];
|
|
|
|
switch ($err->severity)
|
|
|
|
{
|
2001-08-08 09:21:29 +02:00
|
|
|
case 'D': $color = 'D3DCFF'; break;
|
2001-08-06 18:32:40 +02:00
|
|
|
case 'I': $color = 'C0FFC0'; break;
|
|
|
|
case 'W': $color = 'FFFFC0'; break;
|
|
|
|
case 'E': $color = 'FFC0C0'; break;
|
|
|
|
case 'F': $color = 'FF0909'; break;
|
|
|
|
}
|
2001-08-15 18:30:16 +02:00
|
|
|
|
2001-08-06 18:32:40 +02:00
|
|
|
$html .= "\t<tr bgcolor=".'"'.$color.'"'.">\n";
|
|
|
|
$html .= "\t\t<td align=center>".$i."</td>\n";
|
2001-09-23 21:33:39 +02:00
|
|
|
$html .= "\t\t<td>".$GLOBALS['phpgw']->common->show_date($err->timestamp)."</td>\n";
|
2001-08-08 09:21:29 +02:00
|
|
|
$html .= "\t\t<td>".$err->app."  </td>\n";
|
2001-08-06 18:32:40 +02:00
|
|
|
$html .= "\t\t<td align=center>".$err->severity."</td>\n";
|
|
|
|
$html .= "\t\t<td>".$err->code."</td>\n";
|
|
|
|
$html .= "\t\t<td>".$err->langmsg()."</td>\n";
|
2001-08-08 09:21:29 +02:00
|
|
|
$html .= "\t\t<td>".$err->fname."</td>\n";
|
|
|
|
$html .= "\t\t<td>".$err->line."</td>\n";
|
2001-08-06 18:32:40 +02:00
|
|
|
$html .= "\t</tr>\n";
|
2001-12-28 06:32:59 +01:00
|
|
|
}
|
2001-08-06 18:32:40 +02:00
|
|
|
$html .= "</table>\n";
|
|
|
|
$html .= "</center>\n";
|
2001-08-15 18:30:16 +02:00
|
|
|
|
2001-08-06 18:32:40 +02:00
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
}
|