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

Revision 7673, 4.8 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

  • 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            $errorstack_count = count($errorstack);
95                        for ($i = 0; $i < $errorstack_count; ++$i)
96                        {
97                                $err = $errorstack[$i];
98                                $db->query("insert into phpgw_log_msg "
99                                        . "(log_msg_seq_no, log_msg_date, "
100                                        . "log_msg_severity, log_msg_code, log_msg_msg, log_msg_parms) values "
101                                        . "(" . $i
102                                        . ", '" . $GLOBALS['phpgw']->db->to_timestamp($err->timestamp)
103                                        . "', '". $err->severity . "'"
104                                        . ", '". $err->code      . "'"
105                                        . ", '". $err->msg       . "'"
106                                        . ", '". addslashes(implode('|',$err->parms)). "'"
107                                        . ")",__LINE__,__FILE__);
108                        }
109                        unset ($errorstack);
110                        unset ($this->errorstack);
111                        $this->errorstack = array();
112                }
113
114                function clearstack()
115                {
116                        $new = array();
117                        reset($this->errorstack);
118            $errorstack_count = count($this->errorstack);
119                        for ($i = 0; $i < $errorstack_count; ++$i)
120                        {
121                                $err = $this->errorstack[$i];
122                                if ($err->ismsg)
123                                {
124                                        $new[] = $err;
125                                }
126                        }
127                        unset ($this->errorstack);
128                        $this->errorstack = $new;
129                }
130
131                function astable()
132                {
133                        $html  = "<center>\n";
134                        $html .= "<table width=\"98%\">\n";
135                        $html .= "\t<tr bgcolor=\"D3DCFF\">\n";
136                        $html .= "\t\t<td width=\"2%\">No</td>\n";
137                        $html .= "\t\t<td width=\"16%\">Date</td>\n";
138                        $html .= "\t\t<td width=\"15%\">App</td>\n";
139                        $html .= "\t\t<td align=\"center\", width=\"2%\">S</td>\n";
140                        $html .= "\t\t<td width=\"10%\">Error Code</td>\n";
141                        $html .= "\t\t<td >Msg</td>\n";
142                        $html .= "\t</tr>\n";
143
144                        $errorstack = $this->errorstack;
145            $errorstack_count = count($errorstack);
146                        for ($i = 0; $i < $errorstack_count; ++$i)
147                        {
148                                $err = $errorstack[$i];
149                                switch ($err->severity)
150                                {
151                                        case 'I':
152                                                $color = 'C0FFC0';
153                                                break;
154                                        case 'W':
155                                                $color = 'FFFFC0';
156                                                break;
157                                        case 'E':
158                                                $color = 'FFC0C0';
159                                                break;
160                                        case 'F':
161                                                $color = 'FF0909';
162                                                break;
163                                }
164
165                                $html .= "\t<tr bgcolor=".'"'.$color.'"'.">\n";
166                                $html .= "\t\t<td align=center>".$i."</td>\n";
167                                $html .= "\t\t<td>".$GLOBALS['phpgw']->common->show_date($err->timestamp)."</td>\n";
168                                $html .= "\t\t<td>".$GLOBALS['phpgw_info']['flags']['currentapp']."&nbsp </td>\n";
169                                $html .= "\t\t<td align=center>".$err->severity."</td>\n";
170                                $html .= "\t\t<td>".$err->code."</td>\n";
171                                $html .= "\t\t<td>".$err->langmsg()."</td>\n";
172                                $html .= "\t</tr>\n";
173                        }
174                        $html .= "</table>\n";
175                        $html .= "</center>\n";
176
177                        return $html;
178                }
179        }
Note: See TracBrowser for help on using the repository browser.