3 * FusionForge base error class
5 * Copyright 1999-2001, VA Linux Systems, Inc.
7 * This file is part of FusionForge. FusionForge is free software;
8 * you can redistribute it and/or modify it under the terms of the
9 * GNU General Public License as published by the Free Software
10 * Foundation; either version 2 of the Licence, or (at your option)
13 * FusionForge is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 define('ERROR__NO_ERROR', 0);
24 define('ERROR__UNCLASSIFIED_ERROR', 1);
25 define('ERROR__PERMISSION_DENIED_ERROR', 2);
26 define('ERROR__INVALID_EMAIL_ERROR', 3);
27 define('ERROR__ON_UPDATE_ERROR', 4);
28 define('ERROR__GROUPID_ERROR', 5);
29 define('ERROR__MISSING_PARAMS_ERROR', 6);
32 * Error handling utility class
38 * The current error state.
40 * @var bool $error_state.
45 * The current error message(s).
47 * @var string $error_message.
52 * The current error code
54 * @var int $error_code.
59 * Error() - Constructor.
60 * Constructor for the Error class.
61 * Sets the error state to false.
66 $this->error_state=false;
67 $this->error_code=ERROR__NO_ERROR;
71 * setError() - Sets the error string.
72 * Set the error string $error_message to the value of $string
73 * and enable the $error_state flag.
75 * @param string $string The error string to set.
76 * @param int $code The error code
79 function setError($string, $code=ERROR__UNCLASSIFIED_ERROR) {
80 $this->error_state=true;
81 $this->error_message=$string;
82 $this->error_code=$code;
87 * clearError() - Clear the current error.
88 * Clear the current error string and disable the $error_state flag.
90 function clearError() {
91 $this->error_state=false;
92 $this->error_code=ERROR__NO_ERROR;
93 $this->error_message='';
97 * getErrorMessage() - Retrieve the error message string.
98 * Returns the value of $error_message.
100 * @return string The current error message string.
102 function getErrorMessage() {
103 if ($this->error_state) {
104 return $this->error_message;
111 * isError() - Determines the current error state.
112 * This function returns the current value of $error_state.
114 * @return bool The boolean error status.
117 return $this->error_state;
121 * setPermissionDeniedError() - sets a Permission Denied error
122 * retrieves the localized error string for Permission Denied and calls exit_error()
124 function setPermissionDeniedError(){
125 $this->setError(_('Permission denied.'), ERROR__PERMISSION_DENIED_ERROR);
129 * isPermissionDeniedError() - Determines if it is a permission denied error
133 function isPermissionDeniedError(){
134 return ($this->error_code == ERROR__PERMISSION_DENIED_ERROR);
138 * setInvalidEmailError() - sets a Invalid Email error
139 * retrieves the localized error string for Invalid Email and calls exit_error()
141 function setInvalidEmailError($adr=false){
142 $e = _('Invalid Email Address');
144 $e .= " '" . htmlspecialchars($adr) . "'";
145 else if ($adr !== false)
146 $e .= ' ' . _('(none given)');
147 $this->setError($e, ERROR__INVALID_EMAIL_ERROR);
151 * isInvalidEmailError() - Determines if it is an invalid email error
155 function isInvalidEmailError(){
156 return ($this->error_code == ERROR__INVALID_EMAIL_ERROR);
160 * setOnUpdateError() - sets an On Update Error
161 * retrieves the localized error string for On Update
163 * @param string $result The db result to be written.
166 function setOnUpdateError($result=""){
167 $this->setError(sprintf(_('Error On Update: %s'), $result), ERROR__ON_UPDATE_ERROR);
171 * isOnUpdateError() - Determines if it is an on update error
175 function isOnUpdateError(){
176 return ($this->error_code == ERROR__ON_UPDATE_ERROR);
180 * setGroupIdError() - sets an Group ID Error
181 * retrieves the localized error string for Group ID
183 function setGroupIdError(){
184 $this->setError(_('group_id in db result does not match Group Object'), ERROR__GROUPID_ERROR);
189 * isGroupIdError() - Determines if it is a group ID error
193 function isGroupIdError(){
194 return ($this->error_code == ERROR__GROUPID_ERROR);
198 * setMissingParamsError() - sets an Group ID Error
199 * retrieves the localized error string for missing params
201 * @param string $param The name of the missing parameter
204 function setMissingParamsError($param=''){
206 $param = _(': ') . $param;
208 $this->setError(_('Missing Required Parameters').$param, ERROR__MISSING_PARAMS_ERROR);
212 * isMissingParamsError() - Determines if it is a missing params error
216 function isMissingParamsError(){
217 return ($this->error_code == ERROR__MISSING_PARAMS_ERROR);
224 // c-file-style: "bsd"