diff --git a/lib/documentmanagement/Document.inc b/lib/documentmanagement/Document.inc index 15220b8..6680cbc 100644 --- a/lib/documentmanagement/Document.inc +++ b/lib/documentmanagement/Document.inc @@ -265,6 +265,19 @@ class Document { return true; } // }}} + + function &getByFilenameAndFolder($sFileName, $iFolderID) { + $sD = KTUtil::getTableName('documents'); + $sDM = KTUtil::getTableName('document_metadata_version'); + $sDC = KTUtil::getTableName('document_content_version'); + $sQuery = "SELECT D.id AS id FROM $sD AS D + LEFT JOIN $sDM AS DM ON D.metadata_version_id = DM.id + LEFT JOIN $sDC AS DC ON DM.content_version_id = DC.id + WHERE DC.filename = ? AND D.folder_id = ?"; + $aParams = array($sFileName, $iFolderID); + $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); + return Document::get($id); + } // {{{ nameExists /** @@ -293,6 +306,19 @@ class Document { } // }}} + function &getByNameAndFolder($sName, $iFolderID) { + $sD = KTUtil::getTableName('documents'); + $sDM = KTUtil::getTableName('document_metadata_version'); + $sDC = KTUtil::getTableName('document_content_version'); + $sQuery = "SELECT D.id AS id FROM $sD AS D + LEFT JOIN $sDM AS DM ON D.metadata_version_id = DM.id + LEFT JOIN $sDC AS DC ON DM.content_version_id = DC.id + WHERE DM.name = ? AND D.folder_id = ?"; + $aParams = array($sName, $iFolderID); + $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); + return Document::get($id); + } + // {{{ getDocumentDisplayPath /** * Static function. diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php index f4ee968..713d944 100644 --- a/lib/documentmanagement/documentutil.inc.php +++ b/lib/documentmanagement/documentutil.inc.php @@ -135,7 +135,7 @@ class KTDocumentUtil { $sTrigger = $aTrigger[0]; $oTrigger = new $sTrigger; $aInfo = array( - "document" => $this->oDocument, + "document" => $oDocument, ); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); @@ -375,11 +375,30 @@ class KTDocumentUtil { // {{{ add function &add($oFolder, $sFilename, $oUser, $aOptions) { if (KTDocumentUtil::fileExists($oFolder, $sFilename)) { - return PEAR::raiseError("Document with that filename already exists in this folder"); + $oDoc = Document::getByFilenameAndFolder($sFilename, $oFolder->getId()); + if (PEAR::isError($oDoc)) { + return PEAR::raiseError(_("Document with that filename already exists in this folder, and appears to be invalid. Please contact the system administrator.")); + } else { + if ($oDoc->getStatusID != LIVE) { + return PEAR::raiseError(_("Document with that filename already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.")); + } else { + return PEAR::raiseError(_("Document with that filename already exists in this folder.")); + } + } } $sName = KTUtil::arrayGet($aOptions, 'description', $sFilename); if (KTDocumentUtil::nameExists($oFolder, $sName)) { - return PEAR::raiseError("Document with that name already exists in this folder"); + $oDoc = Document::getByNameAndFolder($sName, $oFolder->getId()); + if (PEAR::isError($oDoc)) { + return PEAR::raiseError(_("Document with that title already exists in this folder, and appears to be invalid. Please contact the system administrator.")); + } else { + if ($oDoc->getStatusID != LIVE) { + return PEAR::raiseError(_("Document with that title already exists in this folder, but it has been archived or deleted and is still available for restoration. To prevent it being overwritten, you are not allowed to add a document with the same title or filename.")); + } else { + return PEAR::raiseError(_("Document with that title already exists in this folder.")); + } + } + } $oUploadChannel =& KTUploadChannel::getSingleton(); $oUploadChannel->sendMessage(new KTUploadNewFile($sFilename)); diff --git a/lib/templating/smartytemplate.inc.php b/lib/templating/smartytemplate.inc.php index 28c8d90..bd71d95 100644 --- a/lib/templating/smartytemplate.inc.php +++ b/lib/templating/smartytemplate.inc.php @@ -207,7 +207,7 @@ class KTSmartyTemplate extends KTTemplate { foreach ($entities as $oEntity) { $params['values'][] = call_user_func(array(&$oEntity, $idmethod)); if ($method != "none") { - $params['output'][] = call_user_func(array(&$oEntity, $method)); + $params['output'][] = ' ' . call_user_func(array(&$oEntity, $method)); } else { $params['output'][] = null; } diff --git a/plugins/ktcore/folder/BulkImport.php b/plugins/ktcore/folder/BulkImport.php index 44c215e..2cb9fb0 100644 --- a/plugins/ktcore/folder/BulkImport.php +++ b/plugins/ktcore/folder/BulkImport.php @@ -22,6 +22,14 @@ class KTBulkImportFolderAction extends KTFolderAction { return _('Bulk import'); } + function getInfo() { + if (!Permission::userIsSystemAdministrator($this->oUser->getId())) { + return null; + + } + return parent::getInfo(); + } + function do_main() { $this->oPage->setBreadcrumbDetails(_("bulk import")); $oTemplate =& $this->oValidator->validateTemplate('ktcore/folder/bulkImport'); diff --git a/plugins/ktcore/folder/addDocument.php b/plugins/ktcore/folder/addDocument.php index 57d26fe..16af31f 100644 --- a/plugins/ktcore/folder/addDocument.php +++ b/plugins/ktcore/folder/addDocument.php @@ -92,6 +92,8 @@ class KTFolderAddDocumentAction extends KTFolderAction { $sTitle = $this->oValidator->validateString($_REQUEST['title'], $aErrorOptions); $iFolderId = $this->oFolder->getId(); + /* + // this is now done in ::add if (Document::fileExists(basename($aFile['name']), $iFolderId)) { $this->errorRedirectToMain(_('There is already a file with that filename in this folder.'), sprintf('fFolderId=%d', $this->oFolder->getId())); exit(0); @@ -101,6 +103,7 @@ class KTFolderAddDocumentAction extends KTFolderAction { $this->errorRedirectToMain(_('There is already a file with that title in this folder.'), sprintf('fFolderId=%d', $this->oFolder->getId())); exit(0); } + */ $matches = array(); $aFields = array(); diff --git a/plugins/ktstandard/KTSubscriptions.php b/plugins/ktstandard/KTSubscriptions.php index 2f61785..d6c9f06 100644 --- a/plugins/ktstandard/KTSubscriptions.php +++ b/plugins/ktstandard/KTSubscriptions.php @@ -284,14 +284,14 @@ class KTFolderSubscriptionAction extends KTFolderAction { function do_main() { $iSubscriptionType = SubscriptionEvent::subTypes('Folder'); if (Subscription::exists($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType)) { - $_SESSION['KTErrorMessage'][] = _("You are already subscribed to that document"); + $_SESSION['KTErrorMessage'][] = _("You are already subscribed to that folder"); } else { $oSubscription = new Subscription($this->oUser->getId(), $this->oFolder->getId(), $iSubscriptionType); $res = $oSubscription->create(); if ($res) { - $_SESSION['KTInfoMessage'][] = _("You have been subscribed to this document"); + $_SESSION['KTInfoMessage'][] = _("You have been subscribed to this folder"); } else { - $_SESSION['KTErrorMessage'][] = _("There was a problem subscribing you to this document"); + $_SESSION['KTErrorMessage'][] = _("There was a problem subscribing you to this folder"); } } controllerRedirect('browse', 'fFolderId=' . $this->oFolder->getId()); diff --git a/templates/ktcore/document/add.smarty b/templates/ktcore/document/add.smarty index 480676b..be0faea 100644 --- a/templates/ktcore/document/add.smarty +++ b/templates/ktcore/document/add.smarty @@ -29,10 +29,8 @@ function handleErrorsInResponse(req) { function swapElementFromRequest(elementId, url) { var deff = doSimpleXMLHttpRequest(url); - var cp = getElement(elementId); cp.innerHTML="loading..."; - deff.addCallback(partial(swapInItem, elementId)); deff.addErrback(handleErrorsInResponse); } @@ -82,4 +80,4 @@ addLoadEvent(startupMetadata); - \ No newline at end of file + diff --git a/view.php b/view.php index c9629a6..84d67a2 100755 --- a/view.php +++ b/view.php @@ -458,6 +458,7 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { function getUserForId($iUserId) { $u = User::get($iUserId); + if (PEAR::isError($u) || ($u == false)) { return _('User no longer exists'); } return $u->getName(); } }