seeddms-code/op/op.Download.php

271 lines
9.8 KiB
PHP
Raw Normal View History

<?php
// MyDMS. Document Management System
// Copyright (C) 2002-2005 Markus Westphal
// Copyright (C) 2006-2008 Malcolm Cowe
// Copyright (C) 2010 Matteo Lucarelli
2016-08-09 05:34:30 +00:00
// Copyright (C) 2010-2016 Uwe Steinmann
//
// 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; either version 2 of the License, or
// (at your option) any later version.
//
// 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; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include("../inc/inc.Settings.php");
include("../inc/inc.LogInit.php");
include("../inc/inc.Language.php");
include("../inc/inc.Utils.php");
include("../inc/inc.Init.php");
include("../inc/inc.Extension.php");
2010-10-29 13:19:51 +00:00
include("../inc/inc.DBInit.php");
include("../inc/inc.ClassUI.php");
include("../inc/inc.ClassController.php");
include("../inc/inc.Authentication.php");
$tmp = explode('.', basename($_SERVER['SCRIPT_FILENAME']));
$controller = Controller::factory($tmp[1], array('dms'=>$dms, 'user'=>$user));
2016-08-11 10:05:26 +00:00
$accessop = new SeedDMS_AccessOperation($dms, $user, $settings);
if (!$accessop->check_controller_access($controller, $_POST)) {
UI::exitError(getMLText("document_title", array("documentname" => "")),getMLText("access_denied"));
}
2016-08-11 20:56:12 +00:00
if (isset($_GET["version"])) { /* {{{ */
2010-10-29 13:19:51 +00:00
// document download
if (!isset($_GET["documentid"]) || !is_numeric($_GET["documentid"]) || intval($_GET["documentid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
2010-10-29 13:19:51 +00:00
}
$documentid = $_GET["documentid"];
$document = $dms->getDocument($documentid);
if (!is_object($document)) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
$folder = $document->getFolder();
$docPathHTML = getFolderPathHTML($folder, true). " / <a href=\"../out/out.ViewDocument.php?documentid=".$documentid."\">".$document->getName()."</a>";
if ($document->getAccessMode($user) < M_READ) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied"));
}
if (!is_numeric($_GET["version"]) || intval($_GET["version"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version"));
}
$version = $_GET["version"];
2010-10-29 13:19:51 +00:00
$content = $document->getContentByVersion($version);
if (!is_object($content)) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version"));
}
$controller->setParam('content', $content);
2016-08-11 20:56:12 +00:00
$controller->version();
2010-10-29 13:19:51 +00:00
2016-08-11 20:56:12 +00:00
} /* }}} */
elseif (isset($_GET["file"])) { /* {{{ */
2010-10-29 13:19:51 +00:00
// file download
if (!isset($_GET["documentid"]) || !is_numeric($_GET["documentid"]) || intval($_GET["documentid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
2010-10-29 13:19:51 +00:00
}
$documentid = $_GET["documentid"];
$document = $dms->getDocument($documentid);
if (!is_object($document)) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
$folder = $document->getFolder();
$docPathHTML = getFolderPathHTML($folder, true). " / <a href=\"../out/out.ViewDocument.php?documentid=".$documentid."\">".$document->getName()."</a>";
if ($document->getAccessMode($user) < M_READ) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied"));
}
if (!is_numeric($_GET["file"]) || intval($_GET["file"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_file_id"));
}
$fileid = $_GET["file"];
$file = $document->getDocumentFile($fileid);
if (!is_object($file)) {
UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_file_id"));
}
$controller->setParam('file', $file);
$controller->setParam('type', 'file');
$controller->run();
2016-08-11 20:56:12 +00:00
} /* }}} */
elseif (isset($_GET["arkname"])) { /* {{{ */
$filename = basename($_GET["arkname"]);
2010-10-29 13:19:51 +00:00
// backup download
if (!$user->isAdmin()) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
2010-10-29 13:19:51 +00:00
}
2016-02-15 15:56:23 +00:00
if (!isset($filename)) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_id"));
2010-10-29 13:19:51 +00:00
}
2016-08-11 20:56:12 +00:00
if($settings->_backupDir && file_exists($settings->_backupDir))
$basedir = $settings->_backupDir;
else
$basedir = $settings->_contentDir;
if (!file_exists($basedir.$filename) ) {
2016-02-15 15:56:23 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("missing_file"));
}
2016-08-11 20:56:12 +00:00
$controller->setParam('basedir', $basedir);
$controller->setParam('file', $filename);
$controller->archive();
} /* }}} */
elseif (isset($_GET["logname"])) { /* {{{ */
$filename = basename($_GET["logname"]);
2010-10-29 13:19:51 +00:00
// log download
if (!$user->isAdmin()) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
2010-10-29 13:19:51 +00:00
}
2016-02-15 15:56:23 +00:00
if (!isset($filename)) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_id"));
2010-10-29 13:19:51 +00:00
}
2016-02-15 15:56:23 +00:00
if (!file_exists($settings->_contentDir.$filename) ) {
UI::exitError(getMLText("admin_tools"),getMLText("missing_file"));
}
2016-08-11 20:56:12 +00:00
$controller->setParam('file', $filename);
$controller->setParam('basedir', $settings->_contentDir);
$controller->log();
2016-08-11 20:56:12 +00:00
} /* }}} */
elseif (isset($_GET["vfile"])) { /* {{{ */
2010-10-29 13:19:51 +00:00
// versioning info download
$documentid = $_GET["documentid"];
$document = $dms->getDocument($documentid);
if (!is_object($document)) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
2010-10-29 13:19:51 +00:00
}
// update infos
createVersionigFile($document);
header("Content-Type: text/plain");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($dms->contentDir.$document->getDir().$settings->_versioningFileName )."\"");
$efilename = rawurlencode($settings->_versioningFileName);
header("Content-Disposition: attachment; filename=\"". $efilename . "\"");
header("Cache-Control: must-revalidate");
2010-10-29 13:19:51 +00:00
sendFile($dms->contentDir . $document->getDir() .$settings->_versioningFileName);
2010-10-29 13:19:51 +00:00
2016-08-11 20:56:12 +00:00
} /* }}} */
elseif (isset($_GET["dumpname"])) { /* {{{ */
$filename = basename($_GET["dumpname"]);
2010-10-29 13:19:51 +00:00
// dump file download
if (!$user->isAdmin()) {
UI::exitError(getMLText("admin_tools"),getMLText("access_denied"));
2010-10-29 13:19:51 +00:00
}
2016-02-15 15:56:23 +00:00
if (!isset($filename)) {
UI::exitError(getMLText("admin_tools"),getMLText("unknown_id"));
2010-10-29 13:19:51 +00:00
}
2016-08-11 20:56:12 +00:00
if($settings->_backupDir && file_exists($settings->_backupDir))
$basedir = $settings->_backupDir;
else
$basedir = $settings->_contentDir;
if (!file_exists($basedir.$filename) ) {
2016-02-15 15:56:23 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("missing_file"));
}
2016-08-11 20:56:12 +00:00
$controller->setParam('basedir', $basedir);
$controller->setParam('file', $filename);
$controller->sqldump();
} /* }}} */
elseif (isset($_GET["reviewlogid"])) { /* {{{ */
2015-06-12 06:59:36 +00:00
if (!isset($_GET["documentid"]) || !is_numeric($_GET["documentid"]) || intval($_GET["documentid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
if (!isset($_GET["reviewlogid"]) || !is_numeric($_GET["reviewlogid"]) || intval($_GET["reviewlogid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("invalid_reviewlog_id"));
}
$documentid = $_GET["documentid"];
$document = $dms->getDocument($documentid);
if (!is_object($document)) {
UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("invalid_doc_id"));
}
if ($document->getAccessMode($user) < M_READ) {
UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("access_denied"));
}
2016-08-11 20:56:12 +00:00
$controller->setParam('document', $document);
$controller->setParam('reviewlogid', (int) $_GET['reviewlogid']);
$controller->setParam('type', 'review');
$controller->run();
switch($controller->getErrorNo()) {
case 1:
2016-02-15 15:56:23 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("missing_file"));
2016-08-11 20:56:12 +00:00
break;
2015-06-12 06:59:36 +00:00
}
2016-08-11 20:56:12 +00:00
} /* }}} */
elseif (isset($_GET["approvelogid"])) { /* {{{ */
2015-06-12 06:59:36 +00:00
if (!isset($_GET["documentid"]) || !is_numeric($_GET["documentid"]) || intval($_GET["documentid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id"));
}
if (!isset($_GET["approvelogid"]) || !is_numeric($_GET["approvelogid"]) || intval($_GET["approvelogid"])<1) {
UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("invalid_approvelog_id"));
}
$documentid = $_GET["documentid"];
$document = $dms->getDocument($documentid);
if (!is_object($document)) {
UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("invalid_doc_id"));
}
if ($document->getAccessMode($user) < M_READ) {
UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("access_denied"));
}
2016-08-11 20:56:12 +00:00
$controller->setParam('document', $document);
$controller->setParam('reviewlogid', (int) $_GET['approvelogid']);
$controller->setParam('type', 'approval');
$controller->run();
switch($controller->getErrorNo()) {
case 1:
2016-02-15 15:56:23 +00:00
UI::exitError(getMLText("admin_tools"),getMLText("missing_file"));
2016-08-11 20:56:12 +00:00
break;
2015-06-12 06:59:36 +00:00
}
2016-08-11 20:56:12 +00:00
} /* }}} */
2010-10-29 13:19:51 +00:00
add_log_line();
exit();