phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] api/errorhandler.inc.php, 1.1.2.1


From: nomail
Subject: [Phpgroupware-cvs] api/errorhandler.inc.php, 1.1.2.1
Date: Thu, 20 May 2004 14:40:06 -0000

Update of /api
Added Files:
        Branch: proposal-branch
          errorhandler.inc.php

date: 2004/04/16 20:59:49;  author: seek3r;  state: Exp;  lines: +227 -0

Log Message:
bringing savannah cvs back up to date with what we were doing on our private 
cvs server. We will not be doing dev from this cvs tree
=====================================================================
No syntax errors detected in -
=====================================================================
<?php

/************************************************************************/
/*                               PhpWerx                                */
/*                         errorhandler.inc.php                         */
/*                             0.1-electron                             */
/*                                                                      */
/* Copyright (c) 2002                                                   */
/* by Dan Cech (address@hidden)                                      */
/* http://www.phpwerx.net                                               */
/*                                                                      */
/* This library defines the error handling functions                    */
/*                                                                      */
/* This library is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public License as       */
/* published by the Free Software Foundation; either version 2.1 of the */
/* License, or (at your option) any later version.                      */
/*                                                                      */
/* This library is distributed in the hope that it will be useful, but  */
/* WITHOUT ANY WARRANTY; without even the implied warranty of           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    */
/* Lesser General Public License for more details.                      */
/*                                                                      */
/* You should have received a copy of the GNU Lesser General Public     */
/* License along with this library; if not, write to the Free Software  */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 */
/* USA                                                                  */
/************************************************************************/

// user defined error handling function
function phpgw_error_handler($errno,$errmsg,$file,$line,$vars=NULL)
{
        // error type strings
        $errtype = array(
                E_ERROR                         => 'Error',
                E_WARNING                       => 'Warning',
                E_PARSE                         => 'Parsing Error',
                E_NOTICE                        => 'Notice',
                E_CORE_ERROR            => 'Core Error',
                E_CORE_WARNING          => 'Core Warning',
                E_COMPILE_ERROR         => 'Compile Error',
                E_COMPILE_WARNING       => 'Compile Warning',
                E_USER_ERROR            => 'User Error',
                E_USER_WARNING          => 'User Warning',
                E_USER_NOTICE           => 'User Notice'
        );
        
        // timestamp for the error entry
        $timestamp = gmdate('U');
        
        // trim whitespace from error message
        $errmsg = trim($errmsg);
        
        // display error message if appropriate
        if ($errno & error_reporting())
        {
                if (@is_object($GLOBALS['msgbox']))
                {
                        switch ($errno)
                        {
                                case E_COMPILE_ERROR:
                                case E_PARSE:
                                        $type = 'fatal';
                                        break;
                                case E_CORE_ERROR:
                                case E_COMPILE_ERROR:
                                case E_USER_ERROR:
                                case E_ERROR:
                                        $type = 'error';
                                        break;
                                case E_WARNING:
                                case E_CORE_WARNING:
                                case E_USER_WARNING:
                                        $type = 'warning';
                                        break;
                                case E_NOTICE:
                                case E_USER_NOTICE:
                                        $type = 'notice';
                                        break;
                                default:
                                        $type = 'unknown';
                        }
                        
                        $GLOBALS['msgbox']->add($errmsg, $type, NOTSET, $line, 
$file);
                }
                else
                {
                        //define('PHPGW_FINISHED', true);
                        echo '<b>'.$errtype[$errno].'</b>: '.$errmsg."<br />\n";
                        if ($errno & (E_COMPILE_ERROR | E_PARSE | E_USER_ERROR))
                        {
                                echo 'Error on line '.$line.' of file 
'.$file."<br />\n";
                        }
                }
        }
        
        if (@isset($GLOBALS['phpgw_data']['errconf']))
        {
                $errconf = $GLOBALS['phpgw_data']['errconf'];
                
                // make up XML formatted error entry
                $err = '<error>'."\n"
                         . '    <datetime>'.date("Y-m-d H:i:s 
(T)",$timestamp).'</datetime>'."\n"
                         . '    <errornum>'.$errno.'</errornum>'."\n"
                         . '    
<errortype>'.$errtype[$errno].'</errortype>'."\n"
                         . '    <errormsg>'.$errmsg.'</errormsg>'."\n"
                         . '    <scriptname>'.$filename.'</scriptname>'."\n"
                         . '    <linenum>'.$linenum.'</linenum>'."\n"
                         . '</error>'."\n";
                
                // save to the error log
                if ($errno & (int)$errconf['err_log'])
                {
                        // if database is available
                        if (@is_object($GLOBALS['phpgw']->db))
                        {
                                $err_details = array(
                                        'timestamp'             => 
$GLOBALS['phpgw']->db->quote ($timestamp),
                                        'errornum'              => 
$GLOBALS['phpgw']->db->quote ($errno),
                                        'errormsg'              => 
$GLOBALS['phpgw']->db->quote ($errmsg),
                                        'scriptname'    => 
$GLOBALS['phpgw']->db->quote ($file),
                                        'linenum'               => 
$GLOBALS['phpgw']->db->quote ($line)
                                );
                                
                                // write to error table
                                $sql = 'INSERT INTO '.$errconf['log_table']
                                         . ' 
('.implode(',',array_keys($err_details)).')'
                                         . ' VALUES 
('.implode(',',$err_details).')';
                                $rs = $GLOBALS['phpgw']->db->Execute($sql);
                        }
                        
                        // if database not available or failed
                        switch (TRUE)
                        {
                                case !isset($rs):
                                case !is_object($rs):
                                        // write to log file
                                        @error_log($err,3,$errconf['log_file']);
                        }
                }
                
                // e-mail if there is a critical error
                if ($errno & (int)$errconf['err_email'])
                {
                        @mail($errconf['log_email'], 'Critical 
'.$errtype[$errno], $err);
                }
        }
        
        // exit on fatal errors
        //if ($errno & (E_COMPILE_ERROR | E_PARSE | E_USER_ERROR))
        if ($errno & (E_COMPILE_ERROR | E_PARSE))
        {
                exit(1);
        }
}

// report all errors for debugging
// error_reporting (E_ALL);

// report all errors and warnings, but not notices
if (@isset($GLOBALS['phpgw_data']['errconf']['err_report']))
{
        error_reporting ((int)$GLOBALS['phpgw_data']['errconf']['err_report']);
}

// use custom error handler
set_error_handler ('phpgw_error_handler');

// ADOdb Error Handling
define('ADODB_ERROR_HANDLER_TYPE',E_USER_ERROR);
define('ADODB_ERROR_HANDLER','adodb_error_handler');

/**
* Default Error Handler. This will be called with the following params
*
* @param $dbms          the RDBMS you are connecting to
* @param $fn            the name of the calling function (in uppercase)
* @param $errno         the native error number from the database
* @param $errmsg        the native error msg from the database
* @param $p1            $fn specific parameter - see below
* @param $p2            $fn specific parameter - see below
* @param $thisConn      $current connection object - can be false if no 
connection object created
*/
function adodb_error_handler($dbms,$fn,$errno,$errmsg,$p1,$p2,&$thisConnection)
{
        $s = $dbms.' error: ['.$errno.': '.$errmsg.'] in ';
        
        switch($fn) {
                case 'EXECUTE':
                        $sql = $p1;
                        $inputparams = $p2;
                        $s .= $fn.'("'.$sql.'")';
                        break;
                case 'PCONNECT':
                case 'CONNECT':
                        $host = $p1;
                        $database = $p2;
                        $s .= $fn.'('.$host.',"****","****",'.$database.')';
                        break;
                default:
                        $s .= $fn.'('.$p1.','.$p2.')';
        }
        
        if (!function_exists('debug_backtrace'))
        {
                trigger_error($s,ADODB_ERROR_HANDLER_TYPE);
                return;
        }
        
        $backtrace = debug_backtrace();
        
        foreach ($backtrace as $trace_item)
        {
                if ($trace_item['function'] != 'adodb_error_handler' && 
strpos($trace_item['class'],'adodb') === FALSE)
                {
                        break;
                }
                
                $item = $trace_item;
        }
        
        
phpgw_error_handler(ADODB_ERROR_HANDLER_TYPE,$s,$item['file'],$item['line']);
}

/*
 * end of script
 */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]