source: trunk/phpgwapi/inc/class.errorlog.inc.php @ 2

Revision 2, 5.4 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
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;
48                        $this->$errorstack = array();
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                {
106                        $db = $GLOBALS['phpgw']->db;
107//                      $db->lock('phpgw_log');
108                        $db->query("insert into phpgw_log (log_date, log_user, log_app, log_severity) values "
109                                ."('". $GLOBALS['phpgw']->db->to_timestamp(time())
110                                ."','".(int)$GLOBALS['phpgw']->session->account_id
111                                ."','".$GLOBALS['phpgw_info']['flags']['currentapp']."'"
112                                .",'".$this->severity()."'"
113                                .")"
114                                ,__LINE__,__FILE__
115                        );
116
117                        $log_id = $db->get_last_insert_id('phpgw_log','log_id');
118//                      $db->query('select max(log_id) as lid from phpgw_log');
119//                      $db->next_record();
120//                      $log_id = $db->f('lid');
121//                      $db->unlock();
122
123                        $errorstack = $this->errorstack;
124                        for ($i = 0; $i < count($errorstack); $i++)
125                        {
126                                $err = $errorstack[$i];
127                                $db->query("insert into phpgw_log_msg "
128                                        ."(Log_msg_log_id, log_msg_seq_no, log_msg_date, log_msg_severity, "
129                                        ."log_msg_code, log_msg_msg, log_msg_parms, log_msg_file, log_msg_line) values "
130                                        ."(" . $log_id
131                                        ."," . $i
132                                        .", '" . $GLOBALS['phpgw']->db->to_timestamp($err->timestamp)
133                                        ."', '". $err->severity . "'"
134                                        .", '". $err->code . "'"
135                                        .", '". $db->db_addslashes($err->msg) . "'"
136                                        .", '". $db->db_addslashes((count($err->parms) > 1?implode('|',$err->parms):$err->parms[1])). "'"
137                                        .", '". $err->fname . "'"
138                                        .", " . (int)$err->line
139                                        .")"
140                                        ,__LINE__,__FILE__
141                                );
142                        }
143                        unset ($errorstack);
144                        unset ($this->errorstack);
145                        $this->errorstack = array();
146                        return true;
147                }
148
149                function clearstack()
150                {
151                        $new = array();
152                        reset($this->errorstack);
153                        for ($i = 0; $i < count($this->errorstack); $i++)
154                        {
155                                $err = $this->errorstack[$i];
156                                if ($err->ismsg)
157                                {
158                                        $new[] = $err;
159                                };
160                        }
161                        unset ($this->errorstack);
162                        $this->errorstack = $new;
163                        return true;
164                }
165
166                function astable()
167                {
168                        $html  = "<center>\n";
169                        $html .= "<table width=\"98%\">\n";
170                        $html .= "\t<tr bgcolor=\"D3DCFF\">\n";
171                        $html .= "\t\t<td width=\"2%\">No</td>\n";
172                        $html .= "\t\t<td width=\"16%\">Date</td>\n";
173                        $html .= "\t\t<td width=\"15%\">App</td>\n";
174                        $html .= "\t\t<td align=\"center\", width=\"2%\">S</td>\n";
175                        $html .= "\t\t<td width=\"10%\">Error Code</td>\n";
176                        $html .= "\t\t<td >Msg</td>\n";
177                        $html .= "\t\t<td >File</td>\n";
178                        $html .= "\t\t<td >Line</td>\n";
179                        $html .= "\t</tr>\n";
180
181                        $errorstack = $this->errorstack;
182                        for ($i = 0; $i < count($errorstack); $i++)
183                        {
184                                $err = $errorstack[$i];
185                                switch ($err->severity)
186                                {
187                                        case 'D': $color = 'D3DCFF'; break;
188                                        case 'I': $color = 'C0FFC0'; break;
189                                        case 'W': $color = 'FFFFC0'; break;
190                                        case 'E': $color = 'FFC0C0'; break;
191                                        case 'F': $color = 'FF0909'; break;
192                                }
193
194                                $html .= "\t<tr bgcolor=".'"'.$color.'"'.">\n";
195                                $html .= "\t\t<td align=center>".$i."</td>\n";
196                                $html .= "\t\t<td>".$GLOBALS['phpgw']->common->show_date($err->timestamp)."</td>\n";
197                                $html .= "\t\t<td>".$err->app."&nbsp </td>\n";
198                                $html .= "\t\t<td align=center>".$err->severity."</td>\n";
199                                $html .= "\t\t<td>".$err->code."</td>\n";
200                                $html .= "\t\t<td>".$err->langmsg()."</td>\n";
201                                $html .= "\t\t<td>".$err->fname."</td>\n";
202                                $html .= "\t\t<td>".$err->line."</td>\n";
203                                $html .= "\t</tr>\n";
204                        }
205                        $html .= "</table>\n";
206                        $html .= "</center>\n";
207
208                        return $html;
209                }
210        }
Note: See TracBrowser for help on using the repository browser.