Electronic documents are all well and good - but when you work onthem collaboratively, they can end up being more difficult to handle thanordinary pieces of paper. Multiple versions, competing standards, accesspermissions and revision history tracking are just some of the issues thatarise in a paperless office. This article discusses building and deployinga document management system across your network - and also teachesbeginnners a little bit about designing Web-based applications with PHP andmySQL in the process.
Finally, we come to "delete.php", which takes care of removing a document from the file system and the database.
<?
// checks and includes
// query to ensure that the logged-in user is the owner of this file and
the file is not checked out
$connection = mysql_connect($hostname, $user, $pass) or die ("Unable to
connect!");
$query = "SELECT status FROM data WHERE id = '$id' AND owner =
'$SESSION_UID' AND status = '0'";
$result = mysql_db_query($database, $query, $connection) or die ("Error in
query: $query. " . mysql_error());
// error check
// all ok, proceed!
mysql_free_result($result);
// delete from db
$query = "DELETE FROM data WHERE id = '$id'";
$result = mysql_db_query($database, $query, $connection) or die ("Error in
query: $query. " . mysql_error());
$query = "DELETE FROM perms WHERE fid = '$id'";
$result = mysql_db_query($database, $query, $connection) or die ("Error in
query: $query. " . mysql_error());
$query = "DELETE FROM log WHERE id = '$id'";
$result = mysql_db_query($database, $query, $connection) or die ("Error in
query: $query. " . mysql_error());
// delete from directory
$filename = $id . ".dat";
unlink($dataDir . $filename);
// clean up and back to main page
mysql_close($connection);
$message = "Document successfully deleted";
header("Location: out.php?message=$message");
?>
Nothing too complex here - verify that the file can be
deleted, DELETE all records containing the file ID from the various tables, delete the file (this will fail if your Web server doesn't have the right permissions) and go back to the main page.
At this point, I've built the foundation for the system, although I have not yet addressed the scripts which actually take care of checking documents in and out. That, together with an explanation of how I plan to implement the revision history mechanism and the search feature, will be addressed in the second part of this article. Download the code, play with it, send me your thoughts/flames/savings...and come back next time for more!
This article copyright Melonfire 2001. All rights reserved.