Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
325 richard 1
<?php 
2
/***************************************************************************
3
 *   Copyright (C) 2006 by phpSysInfo - A PHP System Information Script    *
4
 *   http://phpsysinfo.sourceforge.net/                                    *
5
 *                                                                         *
6
 *   This program is free software; you can redistribute it and/or modify  *
7
 *   it under the terms of the GNU General Public License as published by  *
8
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 *   (at your option) any later version.                                   *
10
 *                                                                         *
11
 *   This program is distributed in the hope that it will be useful,       *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
14
 *   GNU General Public License for more details.                          *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU General Public License     *
17
 *   along with this program; if not, write to the                         *
18
 *   Free Software Foundation, Inc.,                                       *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
20
 ***************************************************************************/
21
 
22
// $Id: class.error.inc.php,v 1.9 2007/02/11 15:57:17 bigmichi1 Exp $
23
 
24
class Error {
25
 
26
	// Array which holds the error messages
27
	var $arrErrorList 	= array();
28
	// current number of errors encountered
29
	var $errors 		= 0;
30
 
31
	/**
32
	*
33
	*  addError()
34
	*  
35
	*  @param	strCommand	string		Command, which cause the Error
36
	*  @param	strMessage	string		additional Message, to describe the Error
37
	*  @param	intLine		integer		on which line the Error occours
38
	*  @param	strFile		string		in which File the Error occours
39
	*
40
	*  @return	-
41
	*
42
	**/
43
	function addError( $strCommand, $strMessage, $intLine, $strFile ) {
44
		$this->arrErrorList[$this->errors]['command'] = $strCommand;
45
		$this->arrErrorList[$this->errors]['message'] = $strMessage;
46
		$this->arrErrorList[$this->errors]['line']    = $intLine;
47
		$this->arrErrorList[$this->errors]['file']    = basename( $strFile );
48
		$this->errors++;
49
	}
50
 
51
	/**
52
	*
53
	*  addWarning()
54
	*
55
	*  @param	strMessage	string		Warning message to display
56
	*
57
	*  @return	-
58
	*
59
	**/
60
	function addWarning( $strMessage ) {
61
		$this->arrErrorList[$this->errors]['command'] = "WARN";
62
		$this->arrErrorList[$this->errors]['message'] = $strMessage;
63
		$this->errors++;
64
	}
65
 
66
	/**
67
	*
68
	* ErrorsAsHTML()
69
	*
70
	* @param	-
71
	*
72
	* @return	string		string which contains a HTML table which can be used to echo out the errors
73
	*
74
	**/
75
	function ErrorsAsHTML() {
76
		$strHTMLString = "";
77
		$strWARNString = "";
78
		$strHTMLhead = "<table width=\"100%\" border=\"0\">\n"
79
				. "\t<tr>\n"
80
				. "\t\t<td><font size=\"-1\"><b>File</b></font></td>\n"
81
				. "\t\t<td><font size=\"-1\"><b>Line</b></font></td>\n"
82
				. "\t\t<td><font size=\"-1\"><b>Command</b></font></td>\n"
83
				. "\t\t<td><font size=\"-1\"><b>Message</b></font></td>\n"
84
				. "\t</tr>\n";
85
		$strHTMLfoot = "</table>\n";
86
 
87
		if( $this->errors > 0 ) {
88
			foreach( $this->arrErrorList as $arrLine ) {
89
				if( $arrLine['command'] == "WARN" ) {
90
					$strWARNString .= "<font size=\"-1\"><b>WARNING: " . str_replace( "\n", "<br>", htmlspecialchars( $arrLine['message'] ) ) . "</b></font><br>\n";
91
				} else {
92
					$strHTMLString .= "\t<tr>\n"
93
							. "\t\t<td><font size=\"-1\">" . htmlspecialchars( $arrLine['file'] ) . "</font></td>\n"
94
							. "\t\t<td><font size=\"-1\">" . $arrLine['line'] . "</font></td>\n"
95
							. "\t\t<td><font size=\"-1\">" . htmlspecialchars( $arrLine['command'] ) . "</font></td>\n"
96
							. "\t\t<td><font size=\"-1\">" . str_replace( "\n", "<br>", htmlspecialchars( $arrLine['message'] ) ) . "</font></td>\n"
97
							. "\t</tr>\n";
98
				}
99
			}
100
		}
101
 
102
		if( !empty( $strHTMLString ) ) {
103
			$strHTMLString = $strWARNString . $strHTMLhead . $strHTMLString . $strHTMLfoot;
104
		} else {
105
			$strHTMLString = $strWARNString;
106
		}
107
 
108
		return $strHTMLString;
109
	}
110
 
111
	/**
112
	*
113
	* ErrorsExist()
114
	*
115
	* @param	-
116
	*
117
	* @return 	true	there are errors logged
118
	*		false	no errors logged
119
	*
120
	**/
121
	function ErrorsExist() {
122
		if( $this->errors > 0 ) {
123
			return true;
124
		} else {
125
			return false;
126
		}
127
	}
128
}
129
?>