[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> class.errorlog.inc.php (source)

   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      /* $Id: class.errorlog.inc.php 21836 2006-06-14 23:46:15Z ralfbecker $ */
  14  
  15      class errorlog
  16      {
  17          /***************************\
  18          *    Instance Variables...   *
  19          \***************************/
  20          var $errorstack = array();
  21          var $public_functions = array(
  22              'message',
  23              'error',
  24              'iserror',
  25              'severity',
  26              'commit',
  27              'clearstack',
  28              'astable'
  29          );
  30          var $log_table = 'egw_log';
  31          var $msg_table = 'egw_log_msg';
  32  
  33  		function message($parms)
  34          {
  35              $parms['ismsg']=1;
  36              CreateObject('phpgwapi.error',$parms);
  37              return true;
  38          }
  39  
  40  		function error($parms)
  41          {
  42              $parms['ismsg']=0;
  43              CreateObject('phpgwapi.error',$parms);
  44              return true;
  45          }
  46  
  47  		function write($parms)
  48          {
  49              $parms['ismsg']=0;
  50              $save = $this->errorstack;
  51              $this->errorstack = array();
  52              CreateObject('phpgwapi.error',$parms);
  53              $this->commit();
  54              $this->errorstack = $save;
  55              return true;
  56          }
  57  
  58  		function iserror($parms)
  59          {
  60              $ecode = $parms['code'];
  61              foreach($this->errorstack as $err)
  62              {
  63                  if ($ecode == $err->code)
  64                  {
  65                      return true;
  66                  }
  67              }
  68              return false;
  69          }
  70  
  71  		function severity()
  72          {
  73              $max = 'D';
  74              foreach($this->errorstack as $err)
  75              {
  76                  switch($err->severity)
  77                  {
  78                      case 'F':
  79                          return 'F';
  80                          break;
  81                      case 'E':
  82                          $max = 'E';
  83                          break;
  84                      case 'W':
  85                          if ($max != 'E') 
  86                          {
  87                              $max = 'W';
  88                          }
  89                          break;
  90                      case 'I':
  91                          if ($max == 'D')
  92                          {
  93                              $max = 'I';
  94                          }
  95                          break;
  96                      default:
  97                          break;
  98                  }
  99              }
 100              return $max;
 101          }
 102  
 103  		function commit()
 104          {
 105              $db = clone($GLOBALS['egw']->db);
 106  
 107              $db->insert($this->log_table,array(
 108                  'log_date' => $GLOBALS['egw']->db->to_timestamp(time()),
 109                  'log_user' => $GLOBALS['egw_info']['user']['account_id'],
 110                  'log_app'  => $GLOBALS['egw_info']['flags']['currentapp'],
 111                  'log_severity' => $this->severity(),
 112              ),false,__LINE__,__FILE__);
 113  
 114              $log_id = $db->get_last_insert_id($this->log_table,'log_id');
 115  
 116              foreach($this->errorstack as $i => $err)
 117              {
 118                  $db->insert($this->msg_table,array(
 119                      'log_msg_log_id' => $log_id,
 120                      'log_msg_seq_no' => $i,
 121                      'log_msg_date'   => $GLOBALS['egw']->db->to_timestamp($err->timestamp),
 122                      'log_msg_severity' => $err->severity,
 123                      'log_msg_code'   => $err->code,
 124                      'log_msg_msg'    => $err->msg,
 125                      'log_msg_parms'  => implode('|',(array)$err->parms),
 126                      'log_msg_file'   => $err->fname,
 127                      'log_msg_line'   => $err->line,
 128                  ),false,__LINE__,__FILE__);
 129              }
 130              $this->errorstack = array();
 131  
 132              return true;
 133          }
 134  
 135  		function clearstack()
 136          {
 137              $new = array();
 138              reset($this->errorstack);
 139              for ($i = 0; $i < count($this->errorstack); $i++)
 140              {
 141                  $err = $this->errorstack[$i];
 142                  if ($err->ismsg)
 143                  {
 144                      $new[] = $err;
 145                  };
 146              }
 147              unset ($this->errorstack);
 148              $this->errorstack = $new;
 149              return true;
 150          }
 151  
 152  		function astable()
 153          {
 154              $html  = "<center>\n";
 155              $html .= "<table width=\"98%\">\n";
 156              $html .= "\t<tr bgcolor=\"D3DCFF\">\n";
 157              $html .= "\t\t<td width=\"2%\">No</td>\n";
 158              $html .= "\t\t<td width=\"16%\">Date</td>\n";
 159              $html .= "\t\t<td width=\"15%\">App</td>\n";
 160              $html .= "\t\t<td align=\"center\", width=\"2%\">S</td>\n";
 161              $html .= "\t\t<td width=\"10%\">Error Code</td>\n";
 162              $html .= "\t\t<td >Msg</td>\n";
 163              $html .= "\t\t<td >File</td>\n";
 164              $html .= "\t\t<td >Line</td>\n";
 165              $html .= "\t</tr>\n";
 166  
 167              $errorstack = $this->errorstack;
 168              for ($i = 0; $i < count($errorstack); $i++)
 169              {
 170                  $err = $errorstack[$i];
 171                  switch ($err->severity)
 172                  {
 173                      case 'D': $color = 'D3DCFF'; break;
 174                      case 'I': $color = 'C0FFC0'; break;
 175                      case 'W': $color = 'FFFFC0'; break;
 176                      case 'E': $color = 'FFC0C0'; break;
 177                      case 'F': $color = 'FF0909'; break;
 178                  }
 179  
 180                  $html .= "\t<tr bgcolor=".'"'.$color.'"'.">\n";
 181                  $html .= "\t\t<td align=center>".$i."</td>\n";
 182                  $html .= "\t\t<td>".$GLOBALS['egw']->common->show_date($err->timestamp)."</td>\n";
 183                  $html .= "\t\t<td>".$err->app."&nbsp </td>\n";
 184                  $html .= "\t\t<td align=center>".$err->severity."</td>\n";
 185                  $html .= "\t\t<td>".$err->code."</td>\n";
 186                  $html .= "\t\t<td>".$err->langmsg()."</td>\n";
 187                  $html .= "\t\t<td>".$err->fname."</td>\n";
 188                  $html .= "\t\t<td>".$err->line."</td>\n";
 189                  $html .= "\t</tr>\n";
 190              }
 191              $html .= "</table>\n";
 192              $html .= "</center>\n";
 193  
 194              return $html;
 195          }
 196      }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7