1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
<?php
/**
* A very base error class.
*
* Provides a basic uniform API for setting and testing error conditions and
* error messages.
*
* @version $Id: Error.class 3315 2004-09-12 17:42:26Z gsmet $
* @author Tim Perdue <tperdue@valnux.com>
* @date 2000-08-28
*
* This file is part of GForge.
*
* GForge is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GForge is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GForge; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
define('ERROR__NO_ERROR', 0);
define('ERROR__UNCLASSIFIED_ERROR', 1);
define('ERROR__PERMISSION_DENIED_ERROR', 2);
define('ERROR__INVALID_EMAIL_ERROR', 3);
define('ERROR__ON_UPDATE_ERROR', 4);
define('ERROR__GROUPID_ERROR', 5);
define('ERROR__MISSING_PARAMS_ERROR', 6);
class Error {
/**
* The current error state.
*
* @var bool $error_state.
*/
var $error_state;
/**
* The current error message(s).
*
* @var string $error_message.
*/
var $error_message;
/**
* The current error code
*
* @var int $error_code.
*/
var $error_code;
/**
* Error() - Constructor.
* Constructor for the Error class.
* Sets the error state to false.
*
*/
function Error() {
//nothing
$this->error_state=false;
$this->error_code=ERROR__NO_ERROR;
}
/**
* setError() - Sets the error string.
* Set the error string $error_message to the value of $string
* and enable the $error_state flag.
*
* @param string The error string to set.
* @param int The error code
*/
function setError($string, $code=ERROR__UNCLASSIFIED_ERROR) {
$this->error_state=true;
$this->error_message=$string;
$this->error_code=$code;
}
/**
* clearError() - Clear the current error.
* Clear the current error string and disable the $error_state flag.
*
*/
function clearError() {
$this->error_state=false;
$this->error_code=ERROR__NO_ERROR;
$this->error_message='';
}
/**
* getErrorMessage() - Retrieve the error message string.
* Returns the value of $error_message.
*
* @return $error_message The current error message string.
*
*/
function getErrorMessage() {
if ($this->error_state) {
return $this->error_message;
} else {
return 'No Error';
}
}
/**
* isError() - Determines the current error state.
* This function returns the current value of $error_state.
*
* @return $error_state The boolean error status.
*
*/
function isError() {
return $this->error_state;
}
/**
* setPermissionDeniedError() - sets a Permission Denied error
* retrieves the localized error string for Permission Denied and calls exit_error()
*
*
*/
function setPermissionDeniedError(){
global $Language;
$this->setError($Language->getText('general','permdenied'), ERROR__PERMISSION_DENIED_ERROR);
}
/**
* isPermissionDeniedError() - Determines if it is a permission denied error
*
* @return boolean
*/
function isPermissionDeniedError(){
return ($this->error_code == ERROR__PERMISSION_DENIED_ERROR);
}
/**
* setInvalidEmailError() - sets a Invalid Email error
* retrieves the localized error string for Invalid Email and calls exit_error()
*/
function setInvalidEmailError(){
global $Language;
$this->setError($Language->getText('general','invalid_email'), ERROR__INVALID_EMAIL_ERROR);
}
/**
* isInvalidEmailError() - Determines if it is an invalid email error
*
* @return boolean
*/
function isInvalidEmailError(){
return ($this->error_code == ERROR__INVALID_EMAIL_ERROR);
}
/**
* setOnUpdateError() - sets an On Update Error
* retrieves the localized error string for On Update
*
* @param string The db result to be written.
*
*/
function setOnUpdateError($result=""){
global $Language;
$this->setError($Language->getText('general','error_on_update',$result), ERROR__ON_UPDATE_ERROR);
}
/**
* isOnUpdateError() - Determines if it is an on update error
*
* @return boolean
*/
function isOnUpdateError(){
return ($this->error_code == ERROR__ON_UPDATE_ERROR);
}
/**
* setGroupIdError() - sets an Group ID Error
* retrieves the localized error string for Group ID
*/
function setGroupIdError(){
global $Language;
$this->setError($Language->getText('general','error_group_id'), ERROR__GROUPID_ERROR);
}
/**
* isGroupIdError() - Determines if it is a group ID error
*
* @return boolean
*/
function isGroupIdError(){
return ($this->error_code == ERROR__GROUPID_ERROR);
}
/**
* setMissingParamsError() - sets an Group ID Error
* retrieves the localized error string for missing pparams
*/
function setMissingParamsError(){
global $Language;
$this->setError($Language->getText('general','error_missing_params'), ERROR__MISSING_PARAMS_ERROR);
}
/**
* isMissingParamsError() - Determines if it is a missing params error
*
* @return boolean
*/
function isMissingParamsError(){
return ($this->error_code == ERROR__MISSING_PARAMS_ERROR);
}
}
?>
|