(root)/shared-errorhandler.php - Rev 440
Rev 280 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file is part of Travelsized CMS
* A content management system with modules, based on wiki syntax
*
* Author: Dan Jensen <admin@leinir.dk>
* Copyright 2003/2004
*
* This program 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.
*
* The GNU General Public License is available at: http://www.gnu.org/copyleft/
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* Prints a variable using print_r, and wrapping it up in pre (so as to be easily viewable in a web browser without viewing the source)
*
* @param mixed var Any variable you wish to show
*
* @return void
*/
function printstuff
( $var )
{
echo "<pre>";
print_r($var);
echo "</pre>";
}
/**
* Class designed to handle and present errors...
*/
class errorHandler
{
var $errors; ///< @var string The list containing errors
var $handled = false; ///< @var boolean Wether errors exist or not
var $url; ///< @var string The URL to return to
/**
* Constructor
*
* @param string url The URL to return to (where the Back button should point to)
*/
function errorHandler
( $url )
{
$this->errors = array();
$this->url = $url;
}
/**
* Takes output from a function describing the error...
*
* @param string errorName Name of the error
* @param string errorDescription Description of the error, or true if the error is not an error
* Use this distinction to handle return values from functions
*
* @return mixed Returns the errorDescription
*/
function handle
( $errorName, $errorDescription )
{
if( is_string( $errorDescription ) )
{
$this->errors[$errorName] = $errorDescription;
$this->handled = true;
}
else if( $errorDescription === false )
{
$this->errors[$errorName] = i18n
("An unknown error occured");
$this->handled = true;
}
return $errorDescription;
}
/**
* Renders the errors to present them to the user
*
* @return string The rendered error descriptions
*/
function render
()
{
if( count( $this->errors ) > 0 )
{
if( count( $this->errors ) == 1 )
$renderedErrors = "
<div class=\"errorhandler\">
<a class=\"command errorhandler-command\" href=\"{$this->url}\">[" . i18n
( "Back" ) . "]</a>
<h6 class=\"errorhandler-title\">" . i18n
("The following error occured:") . "</h6>";
else
$renderedErrors = "
<div class=\"errorhandler\">
<a class=\"command errorhandler-command\" href=\"{$this->url}\">[" . i18n
( "Back" ) . "]</a>
<h6 class=\"errorhandler-title\">" . i18n
("The following errors occured:") . "</h6>";
foreach( $this->errors as $errorName => $errorDescription )
$renderedErrors .= "
<div class=\"errorhandler-error\">
<p class=\"errorhandler-name\">$errorName</p>
<p class=\"errorhandler-description\">$errorDescription</p>
</div>";
$renderedErrors .= "
</div>";
}
return $renderedErrors;
}
}
?>