The first part of this article discussed the basic design andarchitecture for an intranet document management system. In this concludingpart, get to the good stuff with a discussion of the "check in" and "checkout" process, and add a simple search engine to the system.
The last script - and the simplest - 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");
switch ($ec)
{
// login failure
case 0:
$message = "There was an error logging you in. <a href=start.html>Please
try again.</a>";
break;
// session problem
case 1:
$message = "Please <a href=start.html>log in</a> again.";
break;
// malformed variable/failed query
case 2:
$message = "There was an error performing the requested action. Please <a
href=start.html>log in</a> again.";
break;
// file not uploaded
case 11:
$message = "Please upload a valid document.";
break;
// rights not assigned
case 12:
$message = "You must assign view/modify rights to at least one user.";
break;
// illegal file type
case 13:
$message = "That file type is not currently supported.<p>Please upload a
document conforming to any of the following file types:<br><ul align=left>";
foreach($allowedFileTypes as $this)
{
$message .= "<li>$this";
}
$message .= "</ul>";
break;
default:
$message = "There was an error performing the requested action. Please <a
href=start.html>log in</a> again.";
break;
}
?>
<html>
<head>
<basefont face="Verdana">
</head>
<body bgcolor="White">
<p>
<? echo $message; ?>
</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.
This article copyright Melonfire 2001. All rights reserved.