<?php
/*
Simple:Press Forum
Installer/Upgrader Error Handler
$LastChangedDate: 2010-01-14 01:56:13 +0000 (Thu, 14 Jan 2010) $
$Rev: 3242 $
*/

if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) {
	die('Access Denied');
}

function sf_install_error($errno, $errstr, $errfile, $errline)
{
	$logfile = dirname(__FILE__).'/install-error.log';
	$uselog = is_writable($logfile);

    # timestamp for the error entry.
    $dt = date('Y-m-d H:i:s (T)');

    $stop = false;

    # Give the error level a name
    # Set a switch indicating whether the error level should make the script exit
    switch ($errno) {
        case E_NOTICE:
        case E_USER_NOTICE:
            $error_msg = 'Notice';
            break;

        case E_WARNING:
        case E_USER_WARNING:
            $error_msg = 'Warning';
            break;

        case E_STRICT:
            $error_msg = 'Strict';
            break;

        case E_ERROR:
        case E_USER_ERROR:
            $error_msg = 'Install Error: (Fatal) ';
            $stop = true;
            break;

        # Handle the possibility of other, unknown problems
        default:
            $error_msg = 'Install Error: (Unknown) ';
            $stop = true;
            break;
    }

	$error_msg.= "[$errno] [$dt] $errstr on line $errline in file $errfile \n";

	if($uselog)
	{
		error_log($error_msg, 3, dirname(__FILE__).'/install-error.log');
	}

	if ($stop == true)
	{
		echo $error_msg;
		die();
	}
	return;
}

$old_error_handler = set_error_handler('sf_install_error');

?>