code != RackTablesError::NOT_AUTHENTICATED)
{
// in debug mode, dump backtrace instead of standard page
// NOT_AUTHENTICATED exception does not need debugging, so it is skipped
printGenericException ($this);
return;
}
header ('Content-Type: text/html; charset=UTF-8');
echo ''."\n";
echo ''."\n";
echo "
This system requires authentication. You should use a username and a password.
');
break;
case self::MISCONFIGURED:
case self::INTERNAL:
case self::DB_WRITE_FAILED:
$this->genHTMLPage ($msgheader[$this->code], $msgbody[$this->code]);
break;
default:
throw new RackTablesError ('Dispatching error, unknown code ' . $this->code, RackTablesError::INTERNAL);
}
}
}
class EntityNotFoundException extends RackTablesError
{
function __construct ($realm, $id)
{
parent::__construct ("Record '${realm}'#'${id}' does not exist");
}
public function dispatch()
{
global $debug_mode;
if ($debug_mode)
{
printGenericException ($this);
return;
}
showError ($this->message);
redirectUser (buildRedirectURL ('index', 'default'));
}
}
class ERetryNeeded extends RackTablesError
{
function __construct ($message)
{
$this->code = parent::INTERNAL;
parent::__construct ($message);
}
}
class InvalidArgException extends RackTablesError
{
// derive an instance of InvalidRequestArgException
function newIRAE ($argname = NULL)
{
if ($argname === NULL)
return new InvalidRequestArgException ($this->name, $this->value, $this->reason);
return new InvalidRequestArgException ($argname, $_REQUEST[$argname], $this->reason);
}
function __construct ($name, $value, $reason = NULL)
{
$message = 'Argument \'' . self::formatString ($name) . '\'' .
' of value ' . self::formatString (var_export ($value, TRUE), 200) .
' is invalid' . (is_null ($reason) ? '' : ' (' . self::formatString ($reason, 100) . ')') .
'.';
parent::__construct ($message, parent::INTERNAL);
$this->name = $name;
$this->value = $value;
$this->reason = $reason;
}
}
// this simplifies construction and helps in catching "soft"
// errors (invalid input from the user)
class InvalidRequestArgException extends InvalidArgException
{
public function dispatch()
{
RackTablesError::genHTMLPage ('Assertion failed', '
Assertion failed
' . $this->message);
}
}
// this wraps certain known PDO errors and is caught in process.php
// as a "soft" error
class RTDatabaseError extends RackTablesError
{
public function dispatch()
{
RackTablesError::genHTMLPage ('Database soft error', '
Database soft error
' . $this->message);
}
}
// gateway failure is a common case of a "soft" error, some functions do catch this
class RTGatewayError extends RackTablesError
{
public function dispatch()
{
RackTablesError::genHTMLPage ('Gateway error', '
Gateway error
' . $this->message);
}
}
# "Permission denied" is a very common case, which in some situations is
# treated as a "soft" error.
class RTPermissionDenied extends RackTablesError
{
public function dispatch()
{
global $pageno, $tabno,
$user_given_tags,
$target_given_tags,
$auto_tags,
$expl_tags,
$impl_tags;
header ('Content-Type: text/html; charset=UTF-8');
echo '' . "\n";
echo '' . "\n";
echo "RackTables: access denied\n";
printPageHeaders();
echo '';
echo "
\n";
echo '';
}
}
class RackCodeError extends RackTablesError
{
protected $lineno;
function __construct ($message, $lineno = 'unknown')
{
# RackCodeError without a catch-block is very likely an internal error
parent::__construct ($message, self::INTERNAL);
$this->lineno = $lineno;
}
public function dispatch()
{
parent::genHTMLPage ('RackCode error', '
RackCode error on line ' . $this->lineno . '
' . $this->message);
}
}
// Whether there is a failure to produce a normal image, this class will emit one
// of the hardcoded last-resort images without the dependency on PHP-GD.
class RTImageError extends RackTablesError
{
protected $imgbin;
function __construct ($subject = NULL)
{
$map = array
(
'pbar_error' => IMG_100x10_PBAR_ERROR,
'pbar_php_gd_error' => IMG_100x10_PHP_GD_NA,
'pbar_arg_error' => IMG_100x10_ARG_ERROR,
'rack_php_gd_error' => IMG_45x90_PHP_GD_NA,
'rack_not_found' => IMG_45x90_RACK_NOT_FOUND,
'rack_arg_error' => IMG_45x90_MALF_REQ,
'access_denied' => IMG_1x1_BLACK,
);
$this->imgbin = base64_decode (array_fetch ($map, $subject, IMG_76x17_ERROR));
}
public function dispatch()
{
header ('Content-Type: image/png');
echo $this->imgbin;
}
}
function dumpArray ($arr)
{
echo '