Commit bd6717624263777f0485652a92b575a024280680
1 parent
b0df6b4d
Flatten code to make it more readable, and use the abstract storage
system to handle document downloading in some cases (to be completed). git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3597 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
58 additions
and
48 deletions
presentation/lookAndFeel/knowledgeTree/documentmanagement/downloadBL.php
| ... | ... | @@ -38,56 +38,66 @@ require_once("$default->fileSystemRoot/lib/documentmanagement/DocumentTransactio |
| 38 | 38 | require_once("$default->fileSystemRoot/lib/documentmanagement/Document.inc"); |
| 39 | 39 | require_once("$default->fileSystemRoot/lib/visualpatterns/PatternCustom.inc"); |
| 40 | 40 | |
| 41 | +require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); | |
| 42 | +$oStorage =& KTStorageManagerUtil::getSingleton(); | |
| 43 | + | |
| 41 | 44 | // start the session for a download- workaround for the IE SSL bug |
| 42 | -if (checkSession(true)) { | |
| 43 | - if (isset($fDocumentID)) { | |
| 44 | - $oDocument = Document::get($fDocumentID); | |
| 45 | - if (Permission::userHasDocumentReadPermission($oDocument)) { | |
| 46 | - if (isset($fForInlineView)) { | |
| 47 | - $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Inline view", VIEW); | |
| 48 | - $oDocumentTransaction->create(); | |
| 49 | - PhysicalDocumentManager::inlineViewPhysicalDocument($fDocumentID); | |
| 50 | - } else { | |
| 51 | - //if the user has document read permission, perform the download | |
| 52 | - if (isset($fVersion)) { | |
| 53 | - // we're downloading an old version of the document | |
| 54 | - $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document version $fVersion downloaded", DOWNLOAD); | |
| 55 | - $oDocumentTransaction->create(); | |
| 56 | - | |
| 57 | - // if the document is currently checked out, and we're the version we're downloading | |
| 58 | - // is the same as the current version, then download the current version of the document | |
| 59 | - if ($oDocument->getIsCheckedOut() && ($fVersion == $oDocument->getVersion())) { | |
| 60 | - PhysicalDocumentManager::downloadPhysicalDocument($fDocumentID); | |
| 61 | - } else { | |
| 62 | - PhysicalDocumentManager::downloadVersionedPhysicalDocument($fDocumentID, $fVersion); | |
| 63 | - } | |
| 64 | - } else { | |
| 65 | - // download the current version | |
| 66 | - $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document downloaded", DOWNLOAD); | |
| 67 | - $oDocumentTransaction->create(); | |
| 68 | - PhysicalDocumentManager::downloadPhysicalDocument($fDocumentID); | |
| 69 | - } | |
| 70 | - exit; | |
| 71 | - } | |
| 72 | - } else { | |
| 73 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 74 | - $oPatternCustom = new PatternCustom(); | |
| 75 | - if ($oDocument) { | |
| 76 | - $oPatternCustom->setHtml("<a href=\"" . generateControllerLink("browse", "fFolderID=" . $oDocument->getFolderID()) . "\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\" /></a>\n"); | |
| 77 | - } else { | |
| 78 | - $oPatternCustom->setHtml("<a href=\"javascript:history.go(-1)\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\" /></a>\n"); | |
| 79 | - } | |
| 80 | - $main->setErrorMessage(_("Either you do not have permission to view this document, or the document you have chosen no longer exists on the file system.")); | |
| 81 | - $main->setCentralPayload($oPatternCustom); | |
| 82 | - $main->render(); | |
| 83 | - } | |
| 45 | +if (!checkSession(true)) { | |
| 46 | + exit(0); | |
| 47 | +} | |
| 48 | + | |
| 49 | +if (!isset($fDocumentID)) { | |
| 50 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 51 | + $oPatternCustom = new PatternCustom(); | |
| 52 | + $oPatternCustom->setHtml("<a href=\"javascript:history.go(-1)\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\" /></a>\n"); | |
| 53 | + $main->setErrorMessage(_("You have not chosen a document to view")); | |
| 54 | + $main->setCentralPayload($oPatternCustom); | |
| 55 | + $main->render(); | |
| 56 | + exit(0); | |
| 57 | +} | |
| 58 | + | |
| 59 | +$oDocument = Document::get($fDocumentID); | |
| 60 | +if (!Permission::userHasDocumentReadPermission($oDocument)) { | |
| 61 | + require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 62 | + $oPatternCustom = new PatternCustom(); | |
| 63 | + if ($oDocument) { | |
| 64 | + $oPatternCustom->setHtml("<a href=\"" . generateControllerLink("browse", "fFolderID=" . $oDocument->getFolderID()) . "\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\" /></a>\n"); | |
| 84 | 65 | } else { |
| 85 | - require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); | |
| 86 | - $oPatternCustom = new PatternCustom(); | |
| 87 | 66 | $oPatternCustom->setHtml("<a href=\"javascript:history.go(-1)\"><img src=\"" . KTHtml::getBackButton() . "\" border=\"0\" /></a>\n"); |
| 88 | - $main->setErrorMessage(_("You have not chosen a document to view")); | |
| 89 | - $main->setCentralPayload($oPatternCustom); | |
| 90 | - $main->render(); | |
| 91 | 67 | } |
| 92 | -} | |
| 68 | + $main->setErrorMessage(_("Either you do not have permission to view this document, or the document you have chosen no longer exists on the file system.")); | |
| 69 | + $main->setCentralPayload($oPatternCustom); | |
| 70 | + $main->render(); | |
| 71 | + exit(0); | |
| 72 | +} | |
| 73 | + | |
| 74 | +if (isset($fForInlineView)) { | |
| 75 | + $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Inline view", VIEW); | |
| 76 | + $oDocumentTransaction->create(); | |
| 77 | + PhysicalDocumentManager::inlineViewPhysicalDocument($fDocumentID); | |
| 78 | + exit(0); | |
| 79 | +} | |
| 80 | + | |
| 81 | +//if the user has document read permission, perform the download | |
| 82 | +if (isset($fVersion)) { | |
| 83 | + // we're downloading an old version of the document | |
| 84 | + $oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document version $fVersion downloaded", DOWNLOAD); | |
| 85 | + $oDocumentTransaction->create(); | |
| 86 | + | |
| 87 | + // if the document is currently checked out, and we're the version we're downloading | |
| 88 | + // is the same as the current version, then download the current version of the document | |
| 89 | + if ($oDocument->getIsCheckedOut() && ($fVersion == $oDocument->getVersion())) { | |
| 90 | + $oStorage->download($oDocument); | |
| 91 | + } else { | |
| 92 | + PhysicalDocumentManager::downloadVersionedPhysicalDocument($fDocumentID, $fVersion); | |
| 93 | + } | |
| 94 | + exit(0); | |
| 95 | +} | |
| 96 | + | |
| 97 | +// download the current version | |
| 98 | +$oDocumentTransaction = & new DocumentTransaction($fDocumentID, "Document downloaded", DOWNLOAD); | |
| 99 | +$oDocumentTransaction->create(); | |
| 100 | +$oStorage->download($oDocument); | |
| 101 | +exit(0); | |
| 102 | + | |
| 93 | 103 | ?> | ... | ... |