discourse-legacysite-perl/site/retailers/rating/classes/error.class.php
2024-06-17 22:42:14 +10:00

258 lines
8.0 KiB
PHP

<?php
//////////////////////////////////////////////////////////////////////////////
// Error Class
//============================================================================
// Dependencies:
//----------------------------------------------------------------------------
// none
//============================================================================
// Modification History:
//----------------------------------------------------------------------------
// 2006-11-04: Created
//////////////////////////////////////////////////////////////////////////////
class Error
{
## CONSTANT VARIABLES
## END CONSTANT VARIABLES
## PUBLIC VARIABLES
## END PUBLIC VARIABLES
## PRIVATE VARIABLES
private static $title;
private static $type;
private static $description;
private static $datetime;
private static $numErrors;
private static $numWarnings;
## END PRIVATE VARIABLES
## CONSTRUCTOR
## END CONSTRUCTOR
## DECONSTRUCTOR
## END DECONSTRUCTOR
## PUBLIC METHODS
// Initialize the Variables
// Does not return anything, but acts like a constructor for Static classes
public static function Initialize()
{
self::$title = array();
self::$type = array();
self::$description = array();
self::$datetime = array();
self::$numErrors = 0;
self::$numWarnings = 0;
}
// DeInitialize the Variables
// Does not return anything, but acts like a destructor for Static classes
public static function DeInitialize()
{
self::$title = null;
self::$type = null;
self::$description = null;
self::$datetime = null;
self::$numErrors = null;
self::$numWarnings = null;
}
// Log Error Method (receives Name and Description)
// Returns true or false depending on if the logging of the error was successful
public static function LogError($varTitle, $varDescription)
{
// Check Parameters
if (strlen(trim($varTitle)) != 0 && strlen(trim($varDescription)) != 0)
{
array_push(self::$title, $varTitle);
array_push(self::$type, "ERROR");
array_push(self::$description, $varDescription);
array_push(self::$datetime, date("m/d/Y H:i:s"));
self::$numErrors++;
return true;
}
return false;
}
// Show Error Messages
// Returns the Error Message Output (in HTML format)
public static function ShowErrorMessages()
{
$output = "";
// Check to see if 1 error occurred or more than one.
if (self::$numErrors > 0)
{
if (self::$numErrors > 1)
{
$error = "ERRORS";
}
else
{
$error = "ERROR";
}
// Loop through Error Messages
for ($i = 0; $i < sizeof(self::$title); $i++)
{
if (self::$type[$i] == "ERROR")
{
// Output each individual Error
$output .= " <div class=\"divErrorTitle\">\r\n" .
" " . self::$title[$i] . "\r\n" .
" <span class=\"spnErrorDateTime\">at " . self::$datetime[$i] . "</span>\r\n" .
" </div>\r\n" .
" <div class=\"divErrorDesc\">" . self::$description[$i] . "<br /><br /></div>\r\n";
}
}
// Write Error Template Output
$output = "<div class=\"divErrorBox\">\r\n" .
" <div class=\"divErrorBoxTitle\"><img src=\"icons/24-em-cross.png\" align=\"left\" /> {$error}:</div>\r\n" .
" <div class=\"divErrors\">\r\n" . $output . "\r\n </div>\r\n" .
"</div>\r\n";
}
// Return the Error Message Output
return $output;
}
// Retrieve Last Error
// Returns the title and description of the last error in an array
public static function RetrieveLastError()
{
$output = array();
// Check to see if 1 error occurred or more than one.
if (self::$numErrors > 0)
{
for ($i = sizeof(self::$title) - 1; $i >= 0; $i++)
{
if (self::$type[$i] == "ERROR")
{
array_push($output, self::$title[$i]);
array_push($output, self::$description[$i]);
break;
}
}
}
return $output;
}
// Clear Errors
// Returns nothing
public static function ClearErrors()
{
self::$numErrors = 0;
for ($i = 0; $i < sizeof(self::$type); $i++)
{
if (self::$type[$i] == "ERROR")
{
self::$title[$i] = null;
self::$type[$i] = null;
self::$description[$i] = null;
self::$datetime[$i] = null;
}
}
}
// Has Errors
// Returns true or false on whether errors exist
public static function HasErrors()
{
if (self::$numErrors > 0)
{
return true;
}
return false;
}
// Log Warning Method (receives Name and Description)
// Returns true or false depending on if logging the warning was successful
public static function LogWarning($varTitle, $varDescription)
{
// Check Parameters
if (strlen(trim($varTitle)) != 0 && strlen(trim($varDescription)) != 0)
{
array_push(self::$title, $varTitle);
array_push(self::$type, "WARNING");
array_push(self::$description, $varDescription);
array_push(self::$datetime, date("m/d/Y H:i:s"));
self::$numWarnings++;
return true;
}
return false;
}
// Show Warning Messages
// Returns the Warning Message Output (in HTML format)
public static function ShowWarningMessages()
{
$output = "";
// Check to see if 1 warning occurred or more than one.
if (self::$numWarnings > 0)
{
if (self::$numWarnings > 1)
{
$warning = "WARNINGS";
}
else
{
$warning = "WARNING";
}
// Loop through Warning Messages
for ($i = 0; $i < sizeof(self::$title); $i++)
{
if (self::$type[$i] == "WARNING")
{
// Output each individual Warning
$output .= " <div class=\"divWarningTitle\">\r\n" .
" " . self::$title[$i] . "\r\n" .
" <span class=\"spnWarningDateTime\">at " . self::$datetime[$i] . "</span>\r\n" .
" </div>\r\n" .
" <div class=\"divWarningDesc\">" . self::$description[$i] . "<br /><br /></div>\r\n";
}
}
// Write Warning Template Output
$output = "<div id=\"divWarningBox\">\r\n" .
" <div id=\"divWarningBoxTitle\"><img src=\"designs/icons/24-message-warn.png\" align=\"left\" /> {$warning}:</div>\r\n" .
" <div id=\"divWarnings\">\r\n" . $output . "\r\n </div>\r\n" .
"</div>\r\n";
}
// Return the Warning Message Output
return $output;
}
// Has Warnings
// Returns true or false on whether there are any Warnings
public static function HasWarnings()
{
if (self::$numWarnings > 0)
{
return true;
}
return false;
}
## END PUBLIC METHODS
## PRIVATE METHODS
## END PRIVATE METHODS
## PROTECTED METHODS
## END PROTECTED METHODS
}
?>