3 * FusionForge base error class
5 * Copyright 1999-2001, VA Linux Systems, Inc.
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 define('ERROR__NO_ERROR', 0);
26 define('ERROR__UNCLASSIFIED_ERROR', 1);
27 define('ERROR__PERMISSION_DENIED_ERROR', 2);
28 define('ERROR__INVALID_EMAIL_ERROR', 3);
29 define('ERROR__ON_UPDATE_ERROR', 4);
30 define('ERROR__GROUPID_ERROR', 5);
31 define('ERROR__MISSING_PARAMS_ERROR', 6);
35 * The current error state.
37 * @var bool $error_state.
42 * The current error message(s).
44 * @var string $error_message.
49 * The current error code
51 * @var int $error_code.
56 * Error() - Constructor.
57 * Constructor for the Error class.
58 * Sets the error state to false.
63 $this->error_state=false;
64 $this->error_code=ERROR__NO_ERROR;
68 * setError() - Sets the error string.
69 * Set the error string $error_message to the value of $string
70 * and enable the $error_state flag.
72 * @param string The error string to set.
73 * @param int The error code
75 function setError($string, $code=ERROR__UNCLASSIFIED_ERROR) {
76 $this->error_state=true;
77 $this->error_message=$string;
78 $this->error_code=$code;
82 * clearError() - Clear the current error.
83 * Clear the current error string and disable the $error_state flag.
86 function clearError() {
87 $this->error_state=false;
88 $this->error_code=ERROR__NO_ERROR;
89 $this->error_message='';
93 * getErrorMessage() - Retrieve the error message string.
94 * Returns the value of $error_message.
96 * @return $error_message The current error message string.
99 function getErrorMessage() {
100 if ($this->error_state) {
101 return $this->error_message;
108 * isError() - Determines the current error state.
109 * This function returns the current value of $error_state.
111 * @return $error_state The boolean error status.
115 return $this->error_state;
120 * setPermissionDeniedError() - sets a Permission Denied error
121 * retrieves the localized error string for Permission Denied and calls exit_error()
125 function setPermissionDeniedError(){
126 $this->setError(_('Permission denied.'), ERROR__PERMISSION_DENIED_ERROR);
130 * isPermissionDeniedError() - Determines if it is a permission denied error
134 function isPermissionDeniedError(){
135 return ($this->error_code == ERROR__PERMISSION_DENIED_ERROR);
139 * setInvalidEmailError() - sets a Invalid Email error
140 * retrieves the localized error string for Invalid Email and calls exit_error()
142 function setInvalidEmailError(){
143 $this->setError(_('Invalid Email Address'), ERROR__INVALID_EMAIL_ERROR);
147 * isInvalidEmailError() - Determines if it is an invalid email error
151 function isInvalidEmailError(){
152 return ($this->error_code == ERROR__INVALID_EMAIL_ERROR);
156 * setOnUpdateError() - sets an On Update Error
157 * retrieves the localized error string for On Update
159 * @param string The db result to be written.
162 function setOnUpdateError($result=""){
163 $this->setError(sprintf(_('Error On Update: %s'), $result), ERROR__ON_UPDATE_ERROR);
167 * isOnUpdateError() - Determines if it is an on update error
171 function isOnUpdateError(){
172 return ($this->error_code == ERROR__ON_UPDATE_ERROR);
176 * setGroupIdError() - sets an Group ID Error
177 * retrieves the localized error string for Group ID
179 function setGroupIdError(){
180 $this->setError(_('Group_id in db result does not match Group Object'), ERROR__GROUPID_ERROR);
185 * isGroupIdError() - Determines if it is a group ID error
189 function isGroupIdError(){
190 return ($this->error_code == ERROR__GROUPID_ERROR);
194 * setMissingParamsError() - sets an Group ID Error
195 * retrieves the localized error string for missing pparams
197 * @param string The name of the missing parameter
200 function setMissingParamsError($param=''){
202 $param = ': ' . $param;
204 $this->setError(_('Missing Parameters').$param, ERROR__MISSING_PARAMS_ERROR);
208 * isMissingParamsError() - Determines if it is a missing params error
212 function isMissingParamsError(){
213 return ($this->error_code == ERROR__MISSING_PARAMS_ERROR);
220 // c-file-style: "bsd"