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 The error string to set.
76 * @param int The error code
78 function setError($string, $code=ERROR__UNCLASSIFIED_ERROR) {
79 $this->error_state=true;
80 $this->error_message=$string;
81 $this->error_code=$code;
86 * clearError() - Clear the current error.
87 * 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 $error_message The current error message string.
103 function getErrorMessage() {
104 if ($this->error_state) {
105 return $this->error_message;
112 * isError() - Determines the current error state.
113 * This function returns the current value of $error_state.
115 * @return $error_state The boolean error status.
119 return $this->error_state;
124 * setPermissionDeniedError() - sets a Permission Denied error
125 * retrieves the localized error string for Permission Denied and calls exit_error()
129 function setPermissionDeniedError(){
130 $this->setError(_('Permission denied.'), ERROR__PERMISSION_DENIED_ERROR);
134 * isPermissionDeniedError() - Determines if it is a permission denied error
138 function isPermissionDeniedError(){
139 return ($this->error_code == ERROR__PERMISSION_DENIED_ERROR);
143 * setInvalidEmailError() - sets a Invalid Email error
144 * retrieves the localized error string for Invalid Email and calls exit_error()
146 function setInvalidEmailError($adr=false){
147 $e = _('Invalid Email Address');
149 $e .= " '" . htmlspecialchars($adr) . "'";
150 else if ($adr !== false)
151 $e .= ' ' . _('(none given)');
152 $this->setError($e, ERROR__INVALID_EMAIL_ERROR);
156 * isInvalidEmailError() - Determines if it is an invalid email error
160 function isInvalidEmailError(){
161 return ($this->error_code == ERROR__INVALID_EMAIL_ERROR);
165 * setOnUpdateError() - sets an On Update Error
166 * retrieves the localized error string for On Update
168 * @param string The db result to be written.
171 function setOnUpdateError($result=""){
172 $this->setError(sprintf(_('Error On Update: %s'), $result), ERROR__ON_UPDATE_ERROR);
176 * isOnUpdateError() - Determines if it is an on update error
180 function isOnUpdateError(){
181 return ($this->error_code == ERROR__ON_UPDATE_ERROR);
185 * setGroupIdError() - sets an Group ID Error
186 * retrieves the localized error string for Group ID
188 function setGroupIdError(){
189 $this->setError(_('Group_id in db result does not match Group Object'), ERROR__GROUPID_ERROR);
194 * isGroupIdError() - Determines if it is a group ID error
198 function isGroupIdError(){
199 return ($this->error_code == ERROR__GROUPID_ERROR);
203 * setMissingParamsError() - sets an Group ID Error
204 * retrieves the localized error string for missing pparams
206 * @param string The name of the missing parameter
209 function setMissingParamsError($param=''){
211 $param = ': ' . $param;
213 $this->setError(_('Missing Parameters').$param, ERROR__MISSING_PARAMS_ERROR);
217 * isMissingParamsError() - Determines if it is a missing params error
221 function isMissingParamsError(){
222 return ($this->error_code == ERROR__MISSING_PARAMS_ERROR);
229 // c-file-style: "bsd"