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

Revision 2, 4.7 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 - log                                                         *
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 log
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($etext,$p0='',$p1='',$p2='',$p3='',$p4='',$p5='',$p6='',$p7='',$p8='',$p9='')
31                {
32                        $parms = array($p0,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9);
33                        CreateObject('phpgwapi.error',$etext,$parms,1);
34                }
35
36                function error($etext,$p0='',$p1='',$p2='',$p3='',$p4='',$p5='',$p6='',$p7='',$p8='',$p9='')
37                {
38                        $parms = array($p0,$p1,$p2,$p3,$p4,$p5,$p6,$p7,$p8,$p9);
39                        CreateObject('phpgwapi.error',$etext,$parms,false);
40                }
41
42                function iserror($ecode)
43                {
44                        $errorstack = $this->errorstack;
45                        reset($errorstack);
46                        while(list(,$err)=each($errorstack))
47                        {
48                                if ($ecode == $err->code)
49                                {
50                                        return true;
51                                }
52                        }
53                        return false;
54                }
55
56                function severity()
57                {
58                        $max = 'I';
59                        $errorstack = $this->errorstack;
60                        reset($errorstack);
61                        while(list(,$err)=each($errorstack))
62                        {
63                                switch($err->severity)
64                                {
65                                        case 'F':
66                                                return 'F';
67                                                break;
68                                        case 'E':
69                                                $max = 'E';
70                                                break;
71                                        case 'W':
72                                        if ($max == 'I')
73                                        {
74                                                $max = 'W';
75                                        }
76                                        break;
77                                }
78                        }
79                        return $max;
80                }
81
82                function commit()
83                {
84                        $db = $GLOBALS['phpgw']->db;
85                        $db->query("insert into phpgw_log (log_date, log_user, log_app, log_severity) values "
86                                ."('". $GLOBALS['phpgw']->db->to_timestamp(time())
87                                ."','".$GLOBALS['phpgw']->session->account_id
88                                ."','".$GLOBALS['phpgw_info']['flags']['currentapp']."'"
89                                .",'".$this->severity()."'"
90                                .")"
91                                ,__LINE__,__FILE__);
92
93                        $errorstack = $this->errorstack;
94                        for ($i = 0; $i < count($errorstack); $i++)
95                        {
96                                $err = $errorstack[$i];
97                                $db->query("insert into phpgw_log_msg "
98                                        . "(log_msg_seq_no, log_msg_date, "
99                                        . "log_msg_severity, log_msg_code, log_msg_msg, log_msg_parms) values "
100                                        . "(" . $i
101                                        . ", '" . $GLOBALS['phpgw']->db->to_timestamp($err->timestamp)
102                                        . "', '". $err->severity . "'"
103                                        . ", '". $err->code      . "'"
104                                        . ", '". $err->msg       . "'"
105                                        . ", '". addslashes(implode('|',$err->parms)). "'"
106                                        . ")",__LINE__,__FILE__);
107                        }
108                        unset ($errorstack);
109                        unset ($this->errorstack);
110                        $this->errorstack = array();
111                }
112
113                function clearstack()
114                {
115                        $new = array();
116                        reset($this->errorstack);
117                        for ($i = 0; $i < count($this->errorstack); $i++)
118                        {
119                                $err = $this->errorstack[$i];
120                                if ($err->ismsg)
121                                {
122                                        $new[] = $err;
123                                }
124                        }
125                        unset ($this->errorstack);
126                        $this->errorstack = $new;
127                }
128
129                function astable()
130                {
131                        $html  = "<center>\n";
132                        $html .= "<table width=\"98%\">\n";
133                        $html .= "\t<tr bgcolor=\"D3DCFF\">\n";
134                        $html .= "\t\t<td width=\"2%\">No</td>\n";
135                        $html .= "\t\t<td width=\"16%\">Date</td>\n";
136                        $html .= "\t\t<td width=\"15%\">App</td>\n";
137                        $html .= "\t\t<td align=\"center\", width=\"2%\">S</td>\n";
138                        $html .= "\t\t<td width=\"10%\">Error Code</td>\n";
139                        $html .= "\t\t<td >Msg</td>\n";
140                        $html .= "\t</tr>\n";
141
142                        $errorstack = $this->errorstack;
143                        for ($i = 0; $i < count($errorstack); $i++)
144                        {
145                                $err = $errorstack[$i];
146                                switch ($err->severity)
147                                {
148                                        case 'I':
149                                                $color = 'C0FFC0';
150                                                break;
151                                        case 'W':
152                                                $color = 'FFFFC0';
153                                                break;
154                                        case 'E':
155                                                $color = 'FFC0C0';
156                                                break;
157                                        case 'F':
158                                                $color = 'FF0909';
159                                                break;
160                                }
161
162                                $html .= "\t<tr bgcolor=".'"'.$color.'"'.">\n";
163                                $html .= "\t\t<td align=center>".$i."</td>\n";
164                                $html .= "\t\t<td>".$GLOBALS['phpgw']->common->show_date($err->timestamp)."</td>\n";
165                                $html .= "\t\t<td>".$GLOBALS['phpgw_info']['flags']['currentapp']."&nbsp </td>\n";
166                                $html .= "\t\t<td align=center>".$err->severity."</td>\n";
167                                $html .= "\t\t<td>".$err->code."</td>\n";
168                                $html .= "\t\t<td>".$err->langmsg()."</td>\n";
169                                $html .= "\t</tr>\n";
170                        }
171                        $html .= "</table>\n";
172                        $html .= "</center>\n";
173
174                        return $html;
175                }
176        }
Note: See TracBrowser for help on using the repository browser.