<?PHP
/**
 *
 * (c) 2003 Björn Brockmann
 */

class dedi_debug
{
	var $sql = array();
	var $general = array();
	var $error = array();

	function collect($message, $cat = 'general', $log = false)
	{
		switch($cat)
		{
			case 'general':
				$this -> general[] = $message;
				break;
			case 'sql':
				$this -> sql[] = $message;
				break;
			case 'cache':
				$this -> sql[] = $message;
				break;
			case 'error':
				$this -> error[] = $message;
				break;
			default:
				echo 'Error - debug cat  "'. $cat .'" (message: '. $message .') does not exist!';			
		}
		if ($log) $this->log($message);
	}

	function log($message)
	{
  		global $this_dir;
        if (FALSE == ($fp = @fopen($this_dir.'logs/errorlog.txt', 'a+')))
			$this->collect('<B>Dateifehler:</B> ' . $this_dir . 'logs/errorlog.txt ' , 'error');
		@fputs($fp, $message);
		@fclose($fp);
		
	}
	
	function show()
	{
		global $cfg_dedi;
		
		$to_return ="";
		
		if($cfg_dedi['debug_error'] && ! empty($this -> error['0'])){
			$to_return .= '<b><font color="red">ERROR:</font></b>'."<br>\n";
			$i=1;
			foreach($this -> error as $value){
				$to_return .= '<b>'. $i . '. Query:</b> '. $value . "<br>\n";
				$i++;
			}
		}
		if($cfg_dedi['debug_general'] && ! empty($this -> general['0'])){
			$to_return .= '<br><b>GENERALL:</b>'."<br>\n";
			foreach($this -> general as $value){
				$to_return .= $value . "<br>\n";
			}
		}
		if($cfg_dedi['debug_sql'] && ! empty($this -> sql['0'])){
			$to_return .= '<br><b>SQL:</b>'."<br>\n";
			$i=1;
			foreach($this -> sql as $value){
				$to_return .= '<b>'. $i . '. Query:</b> '. $value . "<br>\n";
				$i++;
			}
		}
		return $to_return;
	}
	

}

?>
