Commit 5c59a0380d8e7d84b5d5ddd8a4d213837edb4e6d

Authored by Michael Joseph
1 parent ccb9c363

added checks and ability to move old document versions

fixes #2679


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@2302 c91229c3-7414-0410-bfa2-8a42b809f60b
presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentBL.php
... ... @@ -38,7 +38,8 @@ if (checkSession()) {
38 38 if (isset($fForMove)) {
39 39 if ($fConfirmed) {
40 40 //we're trying to move a document
41   - $oDocument = & Document::get($fDocumentID);
  41 + $oDocument = & Document::get($fDocumentID);
  42 + $oFolder = & Folder::get($fFolderID);
42 43 $iOldFolderID = $oDocument->getFolderID();
43 44 if (Permission::userHasDocumentWritePermission($fDocumentID) && Permission::userHasFolderWritePermission($fFolderID)) {
44 45 //if the user has both document and folder write permissions
... ... @@ -47,10 +48,10 @@ if (checkSession()) {
47 48 //put the document in the new folder
48 49 $oDocument->setFolderID($fFolderID);
49 50 if ($oDocument->update(true)) {
50   - //get the new document path
51   - $sNewDocumentFileSystemPath = Folder::getFolderPath($oDocument->getFolderID()) . $oDocument->getFileName();
  51 + //get the old document path
  52 + $sOldDocumentFileSystemPath = Folder::getFolderPath($iOldFolderID) . $oDocument->getFileName();
52 53 //move the document on the file system
53   - if (PhysicalDocumentManager::move($sOldDocumentFileSystemPath, $sNewDocumentFileSystemPath)) {
  54 + if (PhysicalDocumentManager::moveDocument($sOldDocumentFileSystemPath, $oDocument, $oFolder)) {
54 55  
55 56 // fire subscription alerts for the moved document (and the folder its in)
56 57 $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("MovedDocument"),
... ... @@ -105,18 +106,27 @@ if (checkSession()) {
105 106 $main->render();
106 107 }
107 108 } else {
108   - // display confirmation page
109 109 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
110 110 $oPatternCustom = & new PatternCustom();
111   - $oPatternCustom->setHtml(getConfirmationPage($fFolderID, $fDocumentID));
112   - $main->setCentralPayload($oPatternCustom);
113   - $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fDocumentID=$fDocumentID&fFolderID=$fFolderID");
  111 +
  112 + $oDocument= Document::get($fDocumentID);
  113 + // check that there is no filename collision in the destination directory
  114 + $sNewDocumentFileSystemPath = Folder::getFolderPath($fFolderID) . $oDocument->getFileName();
  115 + if (!file_exists($sNewDocumentFileSystemPath)) {
  116 + // display confirmation page
  117 + $oPatternCustom->setHtml(getConfirmationPage($fFolderID, $fDocumentID));
  118 + } else {
  119 + // filename collision
  120 + $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentID, "This folder already contains a document of the same name. Please choose another directory"));
  121 + }
  122 + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fDocumentID=$fDocumentID&fFolderID=$fFolderID");
  123 + $main->setCentralPayload($oPatternCustom);
114 124 $main->render();
115 125 }
116 126 } else {
117 127 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
118 128 $oPatternCustom = & new PatternCustom();
119   - $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentID));
  129 + $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentID));
120 130 $main->setCentralPayload($oPatternCustom);
121 131 $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fDocumentID=$fDocumentID&fFolderID=$fFolderID");
122 132 $main->render();
... ...
presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentUI.inc
... ... @@ -25,10 +25,14 @@ function getConfirmationPage($iFolderID, $iDocumentID) {
25 25 }
26 26  
27 27  
28   -function getPage($iFolderID, $iDocumentID) {
  28 +function getPage($iFolderID, $iDocumentID, $sErrorMessage = "") {
29 29 global $default;
30 30 $sToRender = renderHeading("Move Document");
31 31 $sToRender .= "<table>\n";
  32 + if ($sErrorMessage) {
  33 + $sToRender .= "<tr><td><font color=\"red\">$sErrorMessage</font></td></tr>";
  34 + }
  35 + $sToRender .= "<tr><td>Move document " . Document::getDocumentDisplayPath($iDocumentID) . " to:</td></tr>";
32 36 $sToRender .= "<tr>\n";
33 37 $sToRender .= "<td>" . renderFolderPath($iFolderID, "/control.php?action=moveDocument&fDocumentID=$iDocumentID") . "</td>\n";
34 38 $sToRender .= "</tr>\n";
... ...