<?php
class netsError extends netsFile {
	private $sysErrorClassID='1203';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	public $sysLastMessage='';
	public $sysLastError='';
	public $sysLastException='';
	//-- #More info --
	private $sysErrorMessageSplit='';
	public $sysErrorMessage='';
	//-- #Point --
	public $sPoint_Start='';
	public $sPoint_Now='';
	public $sPoint_Output='';
	
	
	
	public function netsError(){
		$this->netsFile();
		
	}
	
	public function start_Point(){
		$this->sPoint_Start=microtime(true);
		return 0;
	}
	public function now_Point(){
		$this->sPoint_Now=microtime(true);
		$this->sPoint_Output=$this->sPoint_Now-$this->sPoint_Start;
		$this->sPoint_Output=substr($this->sPoint_Output,0,7);
		return 0;
	}
	public function appendError($pSTR,$pType){
		$this->sysErrorMessage.=$pSTR;
		if($pType==0){
			$this->sysErrorMessage.=$this->sysSPLIT8;
			$this->sysErrorMessageSplit=$this->sysSPLIT8;
		}else if($pType==1){
			$this->sysErrorMessage.=$this->sysSPLIT4;
			$this->sysErrorMessageSplit=$this->sysSPLIT4;
		}else if($pType==2){
			$this->sysErrorMessage.=$this->sysSPLIT1;
			$this->sysErrorMessageSplit=$this->sysSPLIT1;
		}else {
			$this->sysErrorMessage.=$this->sysSPLIT8;
			$this->sysErrorMessageSplit=$this->sysSPLIT8;
		}
		
		return 0;
	}
	public function clearError(){
		$this->sysErrorMessage='';
		return 0;
	}
	public function writeError($pPATH,$pType){
		$tmpPATH=$this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['sysErrorPath'].$pPATH;
		$this->sysErrorMessage.=$this->sysErrorMessageSplit;
		if($pType==0){
			$tmpINT=$this->writeFile($tmpPATH,$this->sysErrorMessage);
		}else {
			$tmpINT=$this->appendFile($tmpPATH,$this->sysErrorMessage);
		}
		
		return 0;
	}
	public function exitError(){
		exit ($this->sysErrorMessage);
	}
	public function echoError(){
		echo ($this->sysErrorMessage);
		return 0;
	}
	public function getError_0($pMessage,$pSMessage,$pCause,$pType){
		//-- ------ #Read error template ------ --
		$tmpError='';
		if($this->sysIsDebug=='0'){
			$tmpSTR=$this->sysFileConfig['sysCoreRoot'].'Config/m_default/File/Error_0.htm';
		}else if($this->sysIsDebug=='1'){
			$tmpSTR=$this->sysFileConfig['sysCoreRoot'].'Config/m_default/File/Upgrade.htm';
		}
		if(is_file($tmpSTR)){
			$tmpError=$this->ReadFile($tmpSTR);
		}else{
			$tmpError='{0}<br />{1}<br />{2}<br />{3}<br />{4}<br />{5}';
		}
		//-- ------ #Make error ------ --
		if($pMessage==''){
			$pMessage='应用程序错误';
		}
		$tmpError=str_replace('{Nets.Charset}',$this->sysCharset,$tmpError);
		$tmpError=str_replace('{Nets.Title}',$pMessage,$tmpError);
		$tmpError=str_replace('{Nets.MetaTitle}',$this->sysFileConfig['sysTitle'],$tmpError);
		$tmpError=str_replace('{Nets.MetaKeyword}',$this->sysFileConfig['sysKeyword'],$tmpError);
		$tmpError=str_replace('{Nets.MetaDescription}',$this->sysFileConfig['sysDescription'],$tmpError);
		
		$tmpError=str_replace('{Nets.Error}',$pSMessage,$tmpError);
		$tmpError=str_replace('{Nets.Cause}',$pCause,$tmpError);
		$tmpError=str_replace('{Nets.Code}',$pType,$tmpError);
		$tmpError=str_replace('{Nets.OtherLink}','',$tmpError);
		
		$tmpError=str_replace('{Nets.HomeLink}','#Here',$tmpError);
		$tmpError=str_replace('{Nets.NetsLink}',$this->sysNetsHome,$tmpError);
		$tmpError=str_replace('{Nets.Version}',$this->sysFileConfig['NetsVersion'],$tmpError);
		
		die ($tmpError);
	}
	function getError($pIndex,$pType){
		$retAR0=array();
		//
		if(isset($this->sysErrorsAR[$pIndex])){
			$retAR0['sumtID']=1;
			$retAR0['sumtContent']=$this->sysErrorsAR[$pIndex];
			$retAR0['sumtSign']=$pIndex;
			$retAR0['sumtType']=$pType;
		}else {
			$retAR0['sumtID']=0;
			$retAR0['sumtContent']=$pIndex;
			$retAR0['sumtSign']=$pIndex;
			$retAR0['sumtType']=$pType;
		}
		return $retAR0;
	}
	
}
//-- ------ #Error ------ --
error_reporting(E_ALL);
set_error_handler('getError');
function getError($errno, $errstr, $errfile, $errline){
	$tmpError=new netsError();
	$tmpSTR='';
	if($errno=='0'){$tmpSTR='';}
	else if($errno=='0'){$tmpSTR='';}
	else {$tmpSTR='未定义错误';}
	$tmpErrorNo=$errno;
	if ($errno==E_ERROR) {
		$tmpErrorNo='E_ERROR';
	}else if ($errno==E_WARNING) {
		$tmpErrorNo='E_WARNING';
	}else if ($errno==E_PARSE) {
		$tmpErrorNo='E_PARSE';
	}else if ($errno==E_NOTICE) {
		$tmpErrorNo='E_NOTICE';
	}else if ($errno==E_CORE_ERROR) {
		$tmpErrorNo='E_CORE_ERROR';
	}else if ($errno==E_CORE_WARNING) {
		$tmpErrorNo='E_CORE_WARNING';
	}else if ($errno==E_COMPILE_ERROR) {
		$tmpErrorNo='E_COMPILE_ERROR';
	}else if ($errno==E_COMPILE_WARNING) {
		$tmpErrorNo='E_COMPILE_WARNING';
	}else if ($errno==E_USER_ERROR) {
		$tmpErrorNo='E_USER_ERROR';
	}else if ($errno==E_USER_WARNING) {
		$tmpErrorNo='E_USER_WARNING';
	}else if ($errno==E_USER_NOTICE) {
		$tmpErrorNo='E_USER_NOTICE';
	}else if ($errno==E_ALL) {
		$tmpErrorNo='E_ALL';
	}else if ($errno==E_STRICT) {
		$tmpErrorNo='E_STRICT';

	}
	$tmpError->getError_0($tmpSTR,$errstr,$errfile.'<br />Line:'.$errline,$errno.' - '.$tmpErrorNo);
}
?>