From 4e8dc17b325f1d10f6841b5e84c344cc43552d4e Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 19 Dec 2016 14:26:38 +0100 Subject: [PATCH] download links can be created --- inc/inc.ClassAccessOperation.php | 19 +++++ op/op.CreateDownloadLink.php | 70 ++++++++++++++++++ out/out.CreateDownloadLink.php | 72 +++++++++++++++++++ views/bootstrap/class.CreateDownloadLink.php | 76 ++++++++++++++++++++ views/bootstrap/class.ViewDocument.php | 4 ++ 5 files changed, 241 insertions(+) create mode 100644 op/op.CreateDownloadLink.php create mode 100644 out/out.CreateDownloadLink.php create mode 100644 views/bootstrap/class.CreateDownloadLink.php diff --git a/inc/inc.ClassAccessOperation.php b/inc/inc.ClassAccessOperation.php index cd6acdbca..b75a978fc 100644 --- a/inc/inc.ClassAccessOperation.php +++ b/inc/inc.ClassAccessOperation.php @@ -344,6 +344,25 @@ class SeedDMS_AccessOperation { return false; } /* }}} */ + /** + * Check if download link to document version may be created + * + * Creating a download link to a document content is only allowed if the document was not + * obsoleted. There may be other requirements which are not taken into + * account here. + */ + function mayCreateDownloadLink($document) { /* {{{ */ + if(get_class($document) == $this->dms->getClassname('document')) { + if($latestContent = $document->getLatestContent()) { + $status = $latestContent->getStatus(); + if ($status["status"]!=S_OBSOLETE) { + return true; + } + } + } + return false; + } /* }}} */ + /** * Check for access permission on view * diff --git a/op/op.CreateDownloadLink.php b/op/op.CreateDownloadLink.php new file mode 100644 index 000000000..7c6b1c606 --- /dev/null +++ b/op/op.CreateDownloadLink.php @@ -0,0 +1,70 @@ + getMLText("invalid_request_token"))),getMLText("invalid_request_token")); +} + +if (!isset($_POST["documentid"]) || !is_numeric($_POST["documentid"]) || intval($_POST["documentid"])<1) { + UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id")); +} +$documentid = $_POST["documentid"]; +$document = $dms->getDocument($documentid); + +if (!is_object($document)) { + UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id")); +} + +if ($document->getAccessMode($user) < M_READ) { + UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("access_denied")); +} + +if (!isset($_POST["version"]) || !is_numeric($_POST["version"]) || intval($_POST["version"])<1) { + UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version")); +} + +$version_num = $_POST["version"]; +$version = $document->getContentByVersion($version_num); + +if (!is_object($version)) { + UI::exitError(getMLText("document_title", array("documentname" => $document->getName())),getMLText("invalid_version")); +} +$expiration = null; + +if($version->createDownloadLink($user, $expiration)) { + $session->setSplashMsg(array('type'=>'success', 'msg'=>getMLText('splash_create_download_link'))); +} else { + $session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_error_create_download+link'))); +} + +add_log_line("?documentid=".$documentid."&version".$version_num); + +header("Location:../out/out.ViewDocument.php?documentid=".$documentid); + +?> diff --git a/out/out.CreateDownloadLink.php b/out/out.CreateDownloadLink.php new file mode 100644 index 000000000..291fa6e10 --- /dev/null +++ b/out/out.CreateDownloadLink.php @@ -0,0 +1,72 @@ +$dms, 'user'=>$user)); +$accessop = new SeedDMS_AccessOperation($dms, $user, $settings); +if (!$accessop->check_view_access($view, $_GET)) { + UI::exitError(getMLText("document_title", array("documentname" => '')),getMLText("access_denied")); +} + +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")); +} +$document = $dms->getDocument($_GET["documentid"]); + +if (!is_object($document)) { + UI::exitError(getMLText("document_title", array("documentname" => getMLText("invalid_doc_id"))),getMLText("invalid_doc_id")); +} + +if ($document->getAccessMode($user) < M_ALL) { + UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("access_denied")); +} + +if (!isset($_GET["version"]) || !is_numeric($_GET["version"]) || intval($_GET["version"]<1)) { + UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("invalid_version")); +} + +$content = $document->getContentByVersion($_GET["version"]); +if (!is_object($content)) { + UI::exitError(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName()))),getMLText("invalid_version")); +} + +$folder = $document->getFolder(); + +if($view) { + $view->setParam('folder', $folder); + $view->setParam('document', $document); + $view->setParam('version', $content); + $view->setParam('accessobject', $accessop); + $view($_GET); + exit; +} + +?> diff --git a/views/bootstrap/class.CreateDownloadLink.php b/views/bootstrap/class.CreateDownloadLink.php new file mode 100644 index 000000000..df506864a --- /dev/null +++ b/views/bootstrap/class.CreateDownloadLink.php @@ -0,0 +1,76 @@ + + * @copyright Copyright (C) 2002-2005 Markus Westphal, + * 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, + * 2010-2012 Uwe Steinmann + * @version Release: @package_version@ + */ + +/** + * Include parent class + */ +require_once("class.Bootstrap.php"); + +/** + * Class which outputs the html page for CreateDownloadLink view + * + * @category DMS + * @package SeedDMS + * @author Markus Westphal, Malcolm Cowe, Uwe Steinmann + * @copyright Copyright (C) 2002-2005 Markus Westphal, + * 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, + * 2010-2012 Uwe Steinmann + * @version Release: @package_version@ + */ +class SeedDMS_View_CreateDownloadLink extends SeedDMS_Bootstrap_Style { + + function show() { /* {{{ */ + $dms = $this->params['dms']; + $user = $this->params['user']; + $folder = $this->params['folder']; + $transmittals = $this->params['transmittals']; + $content = $this->params['version']; + + $document = $content->getDocument(); + $this->htmlStartPage(getMLText("document_title", array("documentname" => htmlspecialchars($document->getName())))); + $this->globalNavigation(); + $this->contentStart(); + $this->pageNavigation($this->getFolderPathHTML($folder, true, $document), "view_document", $document); + $this->contentHeading(getMLText("create_download_link")); + $this->contentContainerStart(); + +?> +
+ + + + + +
+ +
+ + + + +
+
+
+ +
+ +
+contentContainerEnd(); + $this->contentEnd(); + $this->htmlEndPage(); + } /* }}} */ +} +?> diff --git a/views/bootstrap/class.ViewDocument.php b/views/bootstrap/class.ViewDocument.php index 61633e284..56f207e5d 100644 --- a/views/bootstrap/class.ViewDocument.php +++ b/views/bootstrap/class.ViewDocument.php @@ -647,6 +647,10 @@ class SeedDMS_View_ViewDocument extends SeedDMS_Bootstrap_Style { if($this->check_access('AddToTransmittal')) print "
  • ".$this->html_link('AddToTransmittal', array('documentid'=>$documentid, 'version'=>$latestContent->getVersion()), array(), "".getMLText("add_to_transmittal"), false, true)."
  • "; } + if($this->check_access('CreateDownloadLink')) + if($accessop->mayCreateDownloadLink($document)) { + print "
  • ".$this->html_link('CreateDownloadLink', array('documentid'=>$documentid, 'version'=>$latestContent->getVersion()), array(), "".getMLText("create_download_link"), false, true)."
  • "; + } if($this->check_access('EditComment')) if($accessop->mayEditComment($document)) { print "
  • ".$this->html_link('EditComment', array('documentid'=>$documentid, 'version'=>$latestContent->getVersion()), array(), "".getMLText("edit_comment"), false, true)."
  • ";