egroupware/phpgwapi/inc/class.log.inc.php

180 lines
4.8 KiB
PHP
Raw Normal View History

2001-08-05 08:48:42 +02:00
<?php
/**************************************************************************\
2004-05-05 14:06:13 +02:00
* eGroupWare - log *
* http://www.egroupware.org *
2001-08-05 08:48:42 +02:00
* 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 log
{
/***************************\
* Instance Variables... *
\***************************/
2001-10-02 06:38:53 +02:00
var $errorstack = array();
var $public_functions = array(
'message',
'error',
'iserror',
'severity',
'commit',
'clearstack',
'astable'
);
var $log_table = 'egw_log';
var $msg_table = 'egw_log_msg';
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +02:00
function message($etext,$p0='',$p1='',$p2='',$p3='',$p4='',$p5='',$p6='',$p7='',$p8='',$p9='')
{
$parms = array($p0,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9);
CreateObject('phpgwapi.error',$etext,$parms,1);
}
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +02:00
function error($etext,$p0='',$p1='',$p2='',$p3='',$p4='',$p5='',$p6='',$p7='',$p8='',$p9='')
{
$parms = array($p0,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9);
CreateObject('phpgwapi.error',$etext,$parms,false);
}
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +02:00
function iserror($ecode)
{
$errorstack = $this->errorstack;
reset($errorstack);
while(list(,$err)=each($errorstack))
{
if ($ecode == $err->code)
{
return true;
}
}
return false;
}
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +02:00
function severity()
{
$max = 'I';
$errorstack = $this->errorstack;
reset($errorstack);
while(list(,$err)=each($errorstack))
{
switch($err->severity)
{
2001-10-02 06:38:53 +02:00
case 'F':
return 'F';
break;
case 'E':
$max = 'E';
break;
case 'W':
if ($max == 'I')
{
$max = 'W';
}
break;
2001-08-05 08:48:42 +02:00
}
}
return $max;
}
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +02:00
function commit()
{
$db = clone($GLOBALS['egw']->db);
$db->query("insert into $this->log_table (log_date, log_user, log_app, log_severity) values "
."('". $GLOBALS['egw']->db->to_timestamp(time())
."','".$GLOBALS['egw']->session->account_id
."','".$GLOBALS['egw_info']['flags']['currentapp']."'"
2001-10-02 06:38:53 +02:00
.",'".$this->severity()."'"
.")"
,__LINE__,__FILE__);
2001-08-05 08:48:42 +02:00
$errorstack = $this->errorstack;
for ($i = 0; $i < count($errorstack); $i++)
{
$err = $errorstack[$i];
$db->query("insert into $this->msg_table "
2001-10-02 06:38:53 +02:00
. "(log_msg_seq_no, log_msg_date, "
. "log_msg_severity, log_msg_code, log_msg_msg, log_msg_parms) values "
. "(" . $i
. ", '" . $GLOBALS['egw']->db->to_timestamp($err->timestamp)
2001-10-02 06:38:53 +02:00
. "', '". $err->severity . "'"
. ", '". $err->code . "'"
. ", '". $err->msg . "'"
. ", '". addslashes(implode('|',$err->parms)). "'"
. ")",__LINE__,__FILE__);
}
2001-08-05 08:48:42 +02:00
unset ($errorstack);
unset ($this->errorstack);
$this->errorstack = array();
}
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +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;
2001-10-02 06:38:53 +02:00
}
2001-08-05 08:48:42 +02:00
}
unset ($this->errorstack);
$this->errorstack = $new;
2001-10-02 06:38:53 +02:00
}
2001-08-05 08:48:42 +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";
$html .= "\t</tr>\n";
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +02:00
$errorstack = $this->errorstack;
for ($i = 0; $i < count($errorstack); $i++)
{
$err = $errorstack[$i];
switch ($err->severity)
{
2001-10-02 06:38:53 +02:00
case 'I':
$color = 'C0FFC0';
break;
case 'W':
$color = 'FFFFC0';
break;
case 'E':
$color = 'FFC0C0';
break;
case 'F':
$color = 'FF0909';
break;
2001-08-05 08:48:42 +02:00
}
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +02:00
$html .= "\t<tr bgcolor=".'"'.$color.'"'.">\n";
$html .= "\t\t<td align=center>".$i."</td>\n";
$html .= "\t\t<td>".$GLOBALS['egw']->common->show_date($err->timestamp)."</td>\n";
$html .= "\t\t<td>".$GLOBALS['egw_info']['flags']['currentapp']."&nbsp </td>\n";
2001-08-05 08:48:42 +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";
$html .= "\t</tr>\n";
2001-10-02 06:38:53 +02:00
}
2001-08-05 08:48:42 +02:00
$html .= "</table>\n";
$html .= "</center>\n";
2001-10-02 06:38:53 +02:00
2001-08-05 08:48:42 +02:00
return $html;
}
}