<?php

defined('WikyBlog') or die("Not an entry point...");

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//		showError2
//
includeFile('tool/errorClass.php');

function showError2($errno, $errmsg, $filename, $linenum, $vars){
	global $localHost,$serverName1, $errorEmail;
	static $warned = false;
	static $num = 0;
	$err = '';
	
	// for functions prepended with @ symbol to suppress errors
	if($errno === 0){
		return;
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//		New Error Handling!
	//
	
	$errortype = 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",
							E_STRICT			=> "Runtime Notice"
							);
							
	//	1)	Which errors
	$excludeErrors = array(E_NOTICE);
	//$criticalErrors = array(E_ERROR,E_PARSE,E_CORE_ERROR,E_COMPILE_ERROR);	//Execution is halted
	//	code never makes it this far for these errors
	
	if( in_array($errno, $excludeErrors) ){
		return;
	}

	//	2)	Make Error Message with Array
	if($num==0){
		if( isset($_SESSION['username']) ){
			$array['User Tracking']['UserName'] = $_SESSION['username'];
		}else{
			$array['User Tracking']['UserName'] = 'Anonymous';
		}
		$_SERVER += array('HTTP_REFERER'=>'','REQUEST_METHOD'=>'','REQUEST_URI'=>'','SERVER_NAME'=>'','HTTP_USER_AGENT'=>'','HTTP_COOKIE'=>'','REMOTE_ADDR'=>'');
		$array['User Tracking']['REMOTE Addr'] = $_SERVER['REMOTE_ADDR'];
		$array['User Tracking']['HTTP Cookie'] = $_SERVER['HTTP_COOKIE'];
		$array['User Tracking']['HTTP User Agent'] = $_SERVER['HTTP_USER_AGENT'];
		$array['User Tracking']['HTTP_HOST'] = $_SERVER['HTTP_HOST'];
		$array['User Tracking']['User Request'] = $_SERVER['REQUEST_URI'];
		$array['User Tracking']['Request Method'] = $_SERVER['REQUEST_METHOD'];
		$array['User Tracking']['Posted Values'] = $_POST;
		$array['User Tracking']['HTTP Referrer'] = $_SERVER['HTTP_REFERER'];//
	}

	$array['Standard Info:'.$num]['ErrorType'] = $errortype[$errno] . ' :: ErrorNum '.$errno;;
	$array['Standard Info:'.$num]['ErrorMsg'] = $errmsg;
	$array['Standard Info:'.$num]['ScriptName'] = $filename;
	$array['Standard Info:'.$num]['ScriptLineNum'] = $linenum;
	if( mysql_errno() ){
		$array['Standard Info:'.$num]['Mysql Error '.mysql_errno()] = mysql_error();
	}
	
	//$array['Context'] = $vars;
	//$array['Server Variable'] = $_SERVER;
	
	//	2)	Log
	$err .= showArray($array);
	wbError::save($err,$num);
	$num++;
	
	
	//	3)	Display?
	$message = '';
	if( isAdmin(false) ){
		$message = '<br/>'.wbLinks::admin('ErrorLog','View the Error Log');
	}

	
	if( $warned === false){
		message('ERROR_OCCURED',$message);
		$warned = true;
	}
}


