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,7 +38,8 @@ if (checkSession()) {
38 if (isset($fForMove)) { 38 if (isset($fForMove)) {
39 if ($fConfirmed) { 39 if ($fConfirmed) {
40 //we're trying to move a document 40 //we're trying to move a document
41 - $oDocument = & Document::get($fDocumentID); 41 + $oDocument = & Document::get($fDocumentID);
  42 + $oFolder = & Folder::get($fFolderID);
42 $iOldFolderID = $oDocument->getFolderID(); 43 $iOldFolderID = $oDocument->getFolderID();
43 if (Permission::userHasDocumentWritePermission($fDocumentID) && Permission::userHasFolderWritePermission($fFolderID)) { 44 if (Permission::userHasDocumentWritePermission($fDocumentID) && Permission::userHasFolderWritePermission($fFolderID)) {
44 //if the user has both document and folder write permissions 45 //if the user has both document and folder write permissions
@@ -47,10 +48,10 @@ if (checkSession()) { @@ -47,10 +48,10 @@ if (checkSession()) {
47 //put the document in the new folder 48 //put the document in the new folder
48 $oDocument->setFolderID($fFolderID); 49 $oDocument->setFolderID($fFolderID);
49 if ($oDocument->update(true)) { 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 //move the document on the file system 53 //move the document on the file system
53 - if (PhysicalDocumentManager::move($sOldDocumentFileSystemPath, $sNewDocumentFileSystemPath)) { 54 + if (PhysicalDocumentManager::moveDocument($sOldDocumentFileSystemPath, $oDocument, $oFolder)) {
54 55
55 // fire subscription alerts for the moved document (and the folder its in) 56 // fire subscription alerts for the moved document (and the folder its in)
56 $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("MovedDocument"), 57 $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("MovedDocument"),
@@ -105,18 +106,27 @@ if (checkSession()) { @@ -105,18 +106,27 @@ if (checkSession()) {
105 $main->render(); 106 $main->render();
106 } 107 }
107 } else { 108 } else {
108 - // display confirmation page  
109 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); 109 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
110 $oPatternCustom = & new PatternCustom(); 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 $main->render(); 124 $main->render();
115 } 125 }
116 } else { 126 } else {
117 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); 127 require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc");
118 $oPatternCustom = & new PatternCustom(); 128 $oPatternCustom = & new PatternCustom();
119 - $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentID)); 129 + $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentID));
120 $main->setCentralPayload($oPatternCustom); 130 $main->setCentralPayload($oPatternCustom);
121 $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fDocumentID=$fDocumentID&fFolderID=$fFolderID"); 131 $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fDocumentID=$fDocumentID&fFolderID=$fFolderID");
122 $main->render(); 132 $main->render();
presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentUI.inc
@@ -25,10 +25,14 @@ function getConfirmationPage($iFolderID, $iDocumentID) { @@ -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 global $default; 29 global $default;
30 $sToRender = renderHeading("Move Document"); 30 $sToRender = renderHeading("Move Document");
31 $sToRender .= "<table>\n"; 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 $sToRender .= "<tr>\n"; 36 $sToRender .= "<tr>\n";
33 $sToRender .= "<td>" . renderFolderPath($iFolderID, "/control.php?action=moveDocument&fDocumentID=$iDocumentID") . "</td>\n"; 37 $sToRender .= "<td>" . renderFolderPath($iFolderID, "/control.php?action=moveDocument&fDocumentID=$iDocumentID") . "</td>\n";
34 $sToRender .= "</tr>\n"; 38 $sToRender .= "</tr>\n";