[2] | 1 | <?php |
---|
| 2 | /**************************************************************************\ |
---|
| 3 | * eGroupWare - errorlog * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * This application written by jerry westrick <jerry@westrick.com> * |
---|
| 6 | * -------------------------------------------- * |
---|
| 7 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 8 | * under the terms of the GNU General Public License as published by the * |
---|
| 9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 10 | * option) any later version. * |
---|
| 11 | \**************************************************************************/ |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | class errorlog |
---|
| 15 | { |
---|
| 16 | /***************************\ |
---|
| 17 | * Instance Variables... * |
---|
| 18 | \***************************/ |
---|
| 19 | var $errorstack = array(); |
---|
| 20 | var $public_functions = array( |
---|
| 21 | 'message', |
---|
| 22 | 'error', |
---|
| 23 | 'iserror', |
---|
| 24 | 'severity', |
---|
| 25 | 'commit', |
---|
| 26 | 'clearstack', |
---|
| 27 | 'astable' |
---|
| 28 | ); |
---|
| 29 | |
---|
| 30 | function message($parms) |
---|
| 31 | { |
---|
| 32 | $parms['ismsg']=1; |
---|
| 33 | CreateObject('phpgwapi.error',$parms); |
---|
| 34 | return true; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | function error($parms) |
---|
| 38 | { |
---|
| 39 | $parms['ismsg']=0; |
---|
| 40 | CreateObject('phpgwapi.error',$parms); |
---|
| 41 | return true; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | function write($parms) |
---|
| 45 | { |
---|
| 46 | $parms['ismsg']=0; |
---|
| 47 | $save = $this->errorstack; |
---|
[189] | 48 | $this->errorstack = array(); |
---|
[2] | 49 | CreateObject('phpgwapi.error',$parms); |
---|
| 50 | $this->commit(); |
---|
| 51 | $this->errorstack = $save; |
---|
| 52 | return true; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | function iserror($parms) |
---|
| 56 | { |
---|
| 57 | $ecode = $parms['code']; |
---|
| 58 | $errorstack = $this->errorstack; |
---|
| 59 | reset($errorstack); |
---|
| 60 | while(list(,$err)=each($errorstack)) |
---|
| 61 | { |
---|
| 62 | if ($ecode == $err->code) |
---|
| 63 | { |
---|
| 64 | return true; |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | return false; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | function severity() |
---|
| 71 | { |
---|
| 72 | $max = 'D'; |
---|
| 73 | $errorstack = $this->errorstack; |
---|
| 74 | reset($errorstack); |
---|
| 75 | while(list(,$err)=each($errorstack)) |
---|
| 76 | { |
---|
| 77 | switch($err->severity) |
---|
| 78 | { |
---|
| 79 | case 'F': |
---|
| 80 | return 'F'; |
---|
| 81 | break; |
---|
| 82 | case 'E': |
---|
| 83 | $max = 'E'; |
---|
| 84 | break; |
---|
| 85 | case 'W': |
---|
| 86 | if ($max != 'E') |
---|
| 87 | { |
---|
| 88 | $max = 'W'; |
---|
| 89 | } |
---|
| 90 | break; |
---|
| 91 | case 'I': |
---|
| 92 | if ($max == 'D') |
---|
| 93 | { |
---|
| 94 | $max = 'I'; |
---|
| 95 | } |
---|
| 96 | break; |
---|
| 97 | default: |
---|
| 98 | break; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | return $max; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | function commit() |
---|
| 105 | { |
---|
[370] | 106 | // jakjr: where I disable the log event. |
---|
| 107 | return true; |
---|
[2] | 108 | $db = $GLOBALS['phpgw']->db; |
---|
| 109 | // $db->lock('phpgw_log'); |
---|
| 110 | $db->query("insert into phpgw_log (log_date, log_user, log_app, log_severity) values " |
---|
| 111 | ."('". $GLOBALS['phpgw']->db->to_timestamp(time()) |
---|
| 112 | ."','".(int)$GLOBALS['phpgw']->session->account_id |
---|
| 113 | ."','".$GLOBALS['phpgw_info']['flags']['currentapp']."'" |
---|
| 114 | .",'".$this->severity()."'" |
---|
| 115 | .")" |
---|
| 116 | ,__LINE__,__FILE__ |
---|
| 117 | ); |
---|
| 118 | |
---|
| 119 | $log_id = $db->get_last_insert_id('phpgw_log','log_id'); |
---|
| 120 | // $db->query('select max(log_id) as lid from phpgw_log'); |
---|
| 121 | // $db->next_record(); |
---|
| 122 | // $log_id = $db->f('lid'); |
---|
| 123 | // $db->unlock(); |
---|
| 124 | |
---|
| 125 | $errorstack = $this->errorstack; |
---|
[7673] | 126 | $errorstack_count = count($errorstack); |
---|
| 127 | for ($i = 0; $i < $errorstack_count; ++$i) |
---|
[2] | 128 | { |
---|
| 129 | $err = $errorstack[$i]; |
---|
| 130 | $db->query("insert into phpgw_log_msg " |
---|
| 131 | ."(Log_msg_log_id, log_msg_seq_no, log_msg_date, log_msg_severity, " |
---|
| 132 | ."log_msg_code, log_msg_msg, log_msg_parms, log_msg_file, log_msg_line) values " |
---|
| 133 | ."(" . $log_id |
---|
| 134 | ."," . $i |
---|
| 135 | .", '" . $GLOBALS['phpgw']->db->to_timestamp($err->timestamp) |
---|
| 136 | ."', '". $err->severity . "'" |
---|
| 137 | .", '". $err->code . "'" |
---|
| 138 | .", '". $db->db_addslashes($err->msg) . "'" |
---|
| 139 | .", '". $db->db_addslashes((count($err->parms) > 1?implode('|',$err->parms):$err->parms[1])). "'" |
---|
| 140 | .", '". $err->fname . "'" |
---|
| 141 | .", " . (int)$err->line |
---|
| 142 | .")" |
---|
| 143 | ,__LINE__,__FILE__ |
---|
| 144 | ); |
---|
| 145 | } |
---|
| 146 | unset ($errorstack); |
---|
| 147 | unset ($this->errorstack); |
---|
| 148 | $this->errorstack = array(); |
---|
| 149 | return true; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | function clearstack() |
---|
| 153 | { |
---|
| 154 | $new = array(); |
---|
| 155 | reset($this->errorstack); |
---|
[7673] | 156 | $errorstack_count = count($this->errorstack); |
---|
| 157 | for ($i = 0; $i < $errorstack_count; ++$i) |
---|
[2] | 158 | { |
---|
| 159 | $err = $this->errorstack[$i]; |
---|
| 160 | if ($err->ismsg) |
---|
| 161 | { |
---|
| 162 | $new[] = $err; |
---|
| 163 | }; |
---|
| 164 | } |
---|
| 165 | unset ($this->errorstack); |
---|
| 166 | $this->errorstack = $new; |
---|
| 167 | return true; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | function astable() |
---|
| 171 | { |
---|
| 172 | $html = "<center>\n"; |
---|
| 173 | $html .= "<table width=\"98%\">\n"; |
---|
| 174 | $html .= "\t<tr bgcolor=\"D3DCFF\">\n"; |
---|
| 175 | $html .= "\t\t<td width=\"2%\">No</td>\n"; |
---|
| 176 | $html .= "\t\t<td width=\"16%\">Date</td>\n"; |
---|
| 177 | $html .= "\t\t<td width=\"15%\">App</td>\n"; |
---|
| 178 | $html .= "\t\t<td align=\"center\", width=\"2%\">S</td>\n"; |
---|
| 179 | $html .= "\t\t<td width=\"10%\">Error Code</td>\n"; |
---|
| 180 | $html .= "\t\t<td >Msg</td>\n"; |
---|
| 181 | $html .= "\t\t<td >File</td>\n"; |
---|
| 182 | $html .= "\t\t<td >Line</td>\n"; |
---|
| 183 | $html .= "\t</tr>\n"; |
---|
| 184 | |
---|
| 185 | $errorstack = $this->errorstack; |
---|
[7673] | 186 | $errorstack_count = count($errorstack); |
---|
| 187 | for ($i = 0; $i < $errorstack_count; ++$i) |
---|
[2] | 188 | { |
---|
| 189 | $err = $errorstack[$i]; |
---|
| 190 | switch ($err->severity) |
---|
| 191 | { |
---|
| 192 | case 'D': $color = 'D3DCFF'; break; |
---|
| 193 | case 'I': $color = 'C0FFC0'; break; |
---|
| 194 | case 'W': $color = 'FFFFC0'; break; |
---|
| 195 | case 'E': $color = 'FFC0C0'; break; |
---|
| 196 | case 'F': $color = 'FF0909'; break; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | $html .= "\t<tr bgcolor=".'"'.$color.'"'.">\n"; |
---|
| 200 | $html .= "\t\t<td align=center>".$i."</td>\n"; |
---|
| 201 | $html .= "\t\t<td>".$GLOBALS['phpgw']->common->show_date($err->timestamp)."</td>\n"; |
---|
| 202 | $html .= "\t\t<td>".$err->app."  </td>\n"; |
---|
| 203 | $html .= "\t\t<td align=center>".$err->severity."</td>\n"; |
---|
| 204 | $html .= "\t\t<td>".$err->code."</td>\n"; |
---|
| 205 | $html .= "\t\t<td>".$err->langmsg()."</td>\n"; |
---|
| 206 | $html .= "\t\t<td>".$err->fname."</td>\n"; |
---|
| 207 | $html .= "\t\t<td>".$err->line."</td>\n"; |
---|
| 208 | $html .= "\t</tr>\n"; |
---|
| 209 | } |
---|
| 210 | $html .= "</table>\n"; |
---|
| 211 | $html .= "</center>\n"; |
---|
| 212 | |
---|
| 213 | return $html; |
---|
| 214 | } |
---|
| 215 | } |
---|