Add document manager, and update tableeditor to allow setting of a downloadlink for documents

This commit is contained in:
james 2007-10-31 20:00:23 +00:00
parent c92736229c
commit 1cc99b4ef9
6 changed files with 113 additions and 6 deletions

View File

@ -0,0 +1,34 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2007 James Grant <james@lightbox.org>
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, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
require("../common.inc.php");
auth_required('admin');
$q=mysql_query("SELECT * FROM documents WHERE id='".$_GET['id']."'");
if($r=mysql_fetch_object($q))
{
header("Content-type: ".trim(exec("file -bi ../data/documents/$r->filename")));
header("Content-disposition: inline; filename=$r->filename");
header("Content-length: ".filesize("../data/documents/$r->filename"));
readfile("../data/documents/$r->filename");
}
?>

53
admin/documents.php Normal file
View File

@ -0,0 +1,53 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2007 James Grant <james@lightbox.org>
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, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
require("../common.inc.php");
require("../tableeditor.class.php");
//make sure storage folder exists
if(!file_exists("../data/documents"))
mkdir("../data/documents");
if(!file_exists("../data/documents/.htaccess"))
file_put_contents("../data/documents/.htaccess","Order Deny,Allow\r\nDeny From All\r\n");
auth_required('admin');
send_header("Internal Document Manager");
$editor=new TableEditor("documents",
array("date"=>"Date",
"title"=>"Document Title",
"sel_category"=>"Category",
"filename"=>"Filename",
)
);
$editor->setPrimaryKey("id");
$editor->setUploadPath("../data/documents");
$editor->setDefaultSortField("sel_category,date");
$editor->setRecordType("Document");
$editor->setFieldDefaultValue("date",date("Y-m-d"));
$editor->setDownloadLink("documentdownloader.php");
$editor->execute();
send_footer();
?>

View File

@ -39,6 +39,7 @@
if($config['tours_enable'] == 'yes') {
echo "<a href=\"tours_manager.php\">".i18n("Tour Management")."</a> <br />";
}
echo "<a href=\"documents.php\">".i18n("Internal Document Management")."</a> <br />";
echo "<hr />";
echo "<a href=\"winners.php\">".i18n("Enter Winning Projects")."</a> <br />";
echo "<a href=\"cwsfregister.php\">".i18n("One-Click CWSF Registration")."</a> <br />";

View File

@ -1 +1 @@
53
54

8
db/db.update.54.sql Normal file
View File

@ -0,0 +1,8 @@
CREATE TABLE `documents` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`date` DATE NOT NULL ,
`title` VARCHAR( 128 ) NOT NULL ,
`sel_category` VARCHAR( 128 ) NOT NULL ,
`filename` VARCHAR( 128 ) DEFAULT NULL ,
PRIMARY KEY ( `id` )
) TYPE = MYISAM ;

View File

@ -302,6 +302,10 @@ class TableEditor
{
$this->uploadPath=$p;
}
function setDownloadLink($l)
{
$this->downloadLink=$l;
}
function setYearSelectRange($min,$max)
{
@ -1110,14 +1114,21 @@ class TableEditor
else if(substr($f,0,8)=="filename" && $this->uploadPath)
{
echo "<td valign=\"top\">";
//only show a link to the file if the upload path is inside the document root
if(strstr(realpath($this->uploadPath),$_SERVER['DOCUMENT_ROOT']) && file_exists($this->uploadPath."/".$editdata[$f]))
{
echo "<A href=\"{$this->uploadPath}/{$r->$f}\">{$r->$f}</a>";
if($this->downloadLink) {
$pk=$this->primaryKey;
echo "<a href=\"{$this->downloadLink}?{$pk}={$r->$pk}\">{$r->$f}</a>";
}
else
{
echo $r->$f;
//only show a link to the file if the upload path is inside the document root
if(strstr(realpath($this->uploadPath),$_SERVER['DOCUMENT_ROOT']) && file_exists($this->uploadPath."/".$editdata[$f]))
{
echo "<A href=\"{$this->uploadPath}/{$r->$f}\">{$r->$f}</a>";
}
else
{
echo $r->$f;
}
}
echo "</td>";
}