In this concluding article, explore the scripts which add andremove timesheet entries to the system, and get a crash course instatistics by using these entries to generate useful resource allocationand usage reports.
The last script - another extremely simple one - is the error handler, "error.php". If you look at the source code, you'll notice many links to this script, each one passing it a cryptic error code via the $ec variable. Very simply, "error.php" intercepts the variable and converts it to a human-readable error message, which is then displayed to the user.
<?
// error.php - displays error messages based on error code $ec
// includes
include("config.php");
include("functions.php");
switch ($ec)
{
// login failure
case 0:
$message = "There was an error logging you in. <a href=index.html>Please
try again.</a>";
break;
// session problem
case 1:
$message = "There was an authentication error. Please <a
href=index.html>log in</a> again.";
break;
// bad datestamp
case 2:
$message = "You selected an invalid date range. Please <a href=menu.php>try
again</a>.";
break;
// default action
default:
$message = "There was an error performing the requested action. Please <a
href=index.html>log in</a> again.";
break;
}
?>
<html>
<head>
<basefont face="Verdana">
<style type="text/css">
TD {font-family: Verdana; font-size: smaller}
</style>
</head>
<body bgcolor="White">
<? $title="Error!"; ?>
<? include("header.inc.php"); ?>
<? echo $message; ?>
<? include("footer.inc.php"); ?>
</body>
</html>
Here's what it looks like.
Simple and elegant - not to mention flexible. Found a new error? No problem - assign it an error code and let "error.php" know.