diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentBL.php b/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentBL.php index 8407cf1..5c6e5c9 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentBL.php +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentBL.php @@ -38,7 +38,8 @@ if (checkSession()) { if (isset($fForMove)) { if ($fConfirmed) { //we're trying to move a document - $oDocument = & Document::get($fDocumentID); + $oDocument = & Document::get($fDocumentID); + $oFolder = & Folder::get($fFolderID); $iOldFolderID = $oDocument->getFolderID(); if (Permission::userHasDocumentWritePermission($fDocumentID) && Permission::userHasFolderWritePermission($fFolderID)) { //if the user has both document and folder write permissions @@ -47,10 +48,10 @@ if (checkSession()) { //put the document in the new folder $oDocument->setFolderID($fFolderID); if ($oDocument->update(true)) { - //get the new document path - $sNewDocumentFileSystemPath = Folder::getFolderPath($oDocument->getFolderID()) . $oDocument->getFileName(); + //get the old document path + $sOldDocumentFileSystemPath = Folder::getFolderPath($iOldFolderID) . $oDocument->getFileName(); //move the document on the file system - if (PhysicalDocumentManager::move($sOldDocumentFileSystemPath, $sNewDocumentFileSystemPath)) { + if (PhysicalDocumentManager::moveDocument($sOldDocumentFileSystemPath, $oDocument, $oFolder)) { // fire subscription alerts for the moved document (and the folder its in) $count = SubscriptionEngine::fireSubscription($fDocumentID, SubscriptionConstants::subscriptionAlertType("MovedDocument"), @@ -105,18 +106,27 @@ if (checkSession()) { $main->render(); } } else { - // display confirmation page require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getConfirmationPage($fFolderID, $fDocumentID)); - $main->setCentralPayload($oPatternCustom); - $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fDocumentID=$fDocumentID&fFolderID=$fFolderID"); + + $oDocument= Document::get($fDocumentID); + // check that there is no filename collision in the destination directory + $sNewDocumentFileSystemPath = Folder::getFolderPath($fFolderID) . $oDocument->getFileName(); + if (!file_exists($sNewDocumentFileSystemPath)) { + // display confirmation page + $oPatternCustom->setHtml(getConfirmationPage($fFolderID, $fDocumentID)); + } else { + // filename collision + $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentID, "This folder already contains a document of the same name. Please choose another directory")); + } + $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fDocumentID=$fDocumentID&fFolderID=$fFolderID"); + $main->setCentralPayload($oPatternCustom); $main->render(); } } else { require_once("$default->fileSystemRoot/presentation/webpageTemplate.inc"); $oPatternCustom = & new PatternCustom(); - $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentID)); + $oPatternCustom->setHtml(getPage($fFolderID, $fDocumentID)); $main->setCentralPayload($oPatternCustom); $main->setFormAction($_SERVER["PHP_SELF"] . "?fForMove=1&fDocumentID=$fDocumentID&fFolderID=$fFolderID"); $main->render(); diff --git a/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentUI.inc b/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentUI.inc index b46e759..fe386c2 100644 --- a/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentUI.inc +++ b/presentation/lookAndFeel/knowledgeTree/documentmanagement/moveDocumentUI.inc @@ -25,10 +25,14 @@ function getConfirmationPage($iFolderID, $iDocumentID) { } -function getPage($iFolderID, $iDocumentID) { +function getPage($iFolderID, $iDocumentID, $sErrorMessage = "") { global $default; $sToRender = renderHeading("Move Document"); $sToRender .= "\n"; + if ($sErrorMessage) { + $sToRender .= ""; + } + $sToRender .= ""; $sToRender .= "\n"; $sToRender .= "\n"; $sToRender .= "\n";
$sErrorMessage
Move document " . Document::getDocumentDisplayPath($iDocumentID) . " to:
" . renderFolderPath($iFolderID, "/control.php?action=moveDocument&fDocumentID=$iDocumentID") . "