* * -------------------------------------------- * * 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... * \***************************/ var $errorstack = array(); var $public_functions = array('message', 'error', 'iserror', 'severity', 'commit', 'clearstack', 'astable', ); 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); } 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,''); } function write($etext,$p0='',$p1='',$p2='',$p3='',$p4='',$p5='',$p6='',$p7='',$p8='',$p9='') { $parms = array($p0,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9); $save = $this->errorstack; $this->$errorstack = array(); CreateObject('phpgwapi.error',$etext,$parms,1); $this->commit(); $this->errorstack = $save; } function iserror($ecode) { $errorstack = $this->errorstack; reset($errorstack); while(list(,$err)=each($errorstack)) { if ($ecode == $err->code) { return true; } } return false; } function severity() { $max = 'I'; $errorstack = $this->errorstack; reset($errorstack); while(list(,$err)=each($errorstack)) { switch($err->severity) { case 'F': return 'F'; break; case 'E': $max = 'E'; break; case 'W': if ($max == 'I') { $max = 'W'; } break; } } return $max; } function commit() { global $phpgw, $phpgw_info; $db = $phpgw->db; $db->lock('phpgw_log'); $db->query ("insert into phpgw_log (log_date, log_user, log_app, log_severity) values " ."('". $phpgw->db->to_timestamp(time() ) ."','".$phpgw->session->account_id ."','".$phpgw_info['flags']['currentapp']."'" .",'".$this->severity()."'" .")" ,__LINE__,__FILE__); $db->query('select max(log_id) lid from phpgw_log'); $db->next_record(); $log_id = $db->f('lid'); $db->unlock(); $errorstack = $this->errorstack; for ($i = 0; $i < count($errorstack); $i++) { $err = $errorstack[$i]; $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) values " ."(" . $log_id ."," . $i .", '" . $phpgw->db->to_timestamp($err->timestamp ) ."', '". $err->severity . "'" .", '". $err->code . "'" .", '". $err->msg . "'" .", '". addslashes(implode('|',$err->parms)). "'" .")" ,__LINE__,__FILE__); }; unset ($errorstack); unset ($this->errorstack); $this->errorstack = array(); } 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; } function astable() { global $phpgw; $html = "
\n"; $html .= "\n"; $html .= "\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\n"; $errorstack = $this->errorstack; for ($i = 0; $i < count($errorstack); $i++) { $err = $errorstack[$i]; switch ($err->severity) { case 'I': $color = 'C0FFC0'; break; case 'W': $color = 'FFFFC0'; break; case 'E': $color = 'FFC0C0'; break; case 'F': $color = 'FF0909'; break; } $html .= "\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\t\n"; $html .= "\t\n"; }; $html .= "
NoDateAppSError CodeMsg
".$i."".$phpgw->common->show_date($err->timestamp)."".$phpgw_info['flags']['currentapp']."  ".$err->severity."".$err->code."".$err->langmsg()."
\n"; $html .= "
\n"; return $html; } }