Commit 1cf5cb757f9318ef6379c67d8d8818140d2d1dd3
1 parent
0db2cf79
Hook up Brad's document renaming code into a document action.
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4974 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
3 changed files
with
103 additions
and
0 deletions
plugins/ktcore/KTCorePlugin.php
| ... | ... | @@ -17,6 +17,7 @@ class KTCorePlugin extends KTPlugin { |
| 17 | 17 | $this->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete', 'KTDocumentActions.php'); |
| 18 | 18 | $this->registerAction('documentaction', 'KTDocumentMoveAction', 'ktcore.actions.document.move', 'KTDocumentActions.php'); |
| 19 | 19 | $this->registerAction('documentaction', 'KTDocumentCopyAction', 'ktcore.actions.document.copy', 'KTDocumentActions.php'); |
| 20 | + $this->registerAction('documentaction', 'KTDocumentRenameAction', 'ktcore.actions.document.rename', 'document/Rename.php'); | |
| 20 | 21 | $this->registerAction('documentaction', 'KTDocumentTransactionHistoryAction', 'ktcore.actions.document.transactionhistory', 'KTDocumentActions.php'); |
| 21 | 22 | $this->registerAction('documentaction', 'KTDocumentVersionHistoryAction', 'ktcore.actions.document.versionhistory', 'KTDocumentActions.php'); |
| 22 | 23 | $this->registerAction('documentaction', 'KTDocumentArchiveAction', 'ktcore.actions.document.archive', 'KTDocumentActions.php'); | ... | ... |
plugins/ktcore/document/Rename.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +require_once(KT_LIB_DIR . '/actions/documentaction.inc.php'); | |
| 4 | +require_once(KT_LIB_DIR . '/subscriptions/Subscription.inc'); | |
| 5 | +require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php'); | |
| 6 | +require_once(KT_LIB_DIR . '/browse/browseutil.inc.php'); | |
| 7 | +require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php'); | |
| 8 | +require_once(KT_LIB_DIR . '/documentmanagement/PhysicalDocumentManager.inc'); | |
| 9 | + | |
| 10 | +require_once(KT_LIB_DIR . "/browse/DocumentCollection.inc.php"); | |
| 11 | +require_once(KT_LIB_DIR . "/browse/BrowseColumns.inc.php"); | |
| 12 | +require_once(KT_LIB_DIR . "/browse/PartialQuery.inc.php"); | |
| 13 | + | |
| 14 | +// {{{ KTDocumentRenameAction | |
| 15 | +class KTDocumentRenameAction extends KTDocumentAction { | |
| 16 | + var $sName = 'ktcore.actions.document.rename'; | |
| 17 | + | |
| 18 | + var $_sShowPermission = "ktcore.permissions.write"; | |
| 19 | + | |
| 20 | + function getDisplayName() { | |
| 21 | + return _('Rename'); | |
| 22 | + } | |
| 23 | + | |
| 24 | + function getInfo() { | |
| 25 | + if ($this->oDocument->getIsCheckedOut()) { | |
| 26 | + return null; | |
| 27 | + } | |
| 28 | + return parent::getInfo(); | |
| 29 | + } | |
| 30 | + | |
| 31 | + function check() { | |
| 32 | + $res = parent::check(); | |
| 33 | + if ($res !== true) { | |
| 34 | + return $res; | |
| 35 | + } | |
| 36 | + if ($this->oDocument->getIsCheckedOut()) { | |
| 37 | + $_SESSION["KTErrorMessage"][]= _("This document can't be renamed because it is checked out"); | |
| 38 | + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); | |
| 39 | + exit(0); | |
| 40 | + } | |
| 41 | + return true; | |
| 42 | + } | |
| 43 | + | |
| 44 | + function do_main() { | |
| 45 | + $this->oPage->setBreadcrumbDetails("rename"); | |
| 46 | + $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/rename'); | |
| 47 | + $fields = array(); | |
| 48 | + $fields[] = new KTStringWidget(_('New file name'), _('The name to which the current file should be renamed.'), 'filename', "", $this->oPage, true); | |
| 49 | + | |
| 50 | + $oTemplate->setData(array( | |
| 51 | + 'context' => &$this, | |
| 52 | + 'fields' => $fields, | |
| 53 | + )); | |
| 54 | + return $oTemplate->render(); | |
| 55 | + } | |
| 56 | + | |
| 57 | + function do_rename() { | |
| 58 | + global $default; | |
| 59 | + $sFilename = KTUtil::arrayGet($_REQUEST, 'filename'); | |
| 60 | + $aOptions = array( | |
| 61 | + 'redirect_to' => array('', sprintf('fDocumentId=%d', $this->oDocument->getId())), | |
| 62 | + 'message' => "No filename given", | |
| 63 | + ); | |
| 64 | + $this->oValidator->validateString($sFilename, $aOptions); | |
| 65 | + | |
| 66 | + $res = KTDocumentUtil::rename($this->oDocument, $sFilename, $this->oUser); | |
| 67 | + if (PEAR::isError($res)) { | |
| 68 | + $_SESSION['KTErrorMessage'][] = $res->getMessage(); | |
| 69 | + controllerRedirect('viewDocument',sprintf('fDocumentId=%d', $this->oDocument->getId())); | |
| 70 | + } else { | |
| 71 | + $_SESSION['KTInfoMessage'][] = sprintf(_('Document "%s" renamed.'),$this->oDocument->getName()); | |
| 72 | + } | |
| 73 | + | |
| 74 | + controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId())); | |
| 75 | + exit(0); | |
| 76 | + } | |
| 77 | +} | |
| 78 | +// }}} | |
| 79 | + | |
| 80 | +?> | ... | ... |
templates/ktcore/action/rename.smarty
0 → 100644
| 1 | +<p class="descriptiveText">{i18n}This page allows you to rename the file | |
| 2 | +name (not the document title) for a document.{/i18n}</p> | |
| 3 | + | |
| 4 | +{assign var=iDocumentId value=$context->oDocument->getId()} | |
| 5 | +{capture assign=link}{"viewDocument"|generateControllerUrl:"fDocumentId=$iDocumentId"}{/capture} | |
| 6 | +<p class="descriptiveText">{i18n arg_link=$link}If you do not intend to | |
| 7 | +rename this document, you should <a href="#link#">cancel the | |
| 8 | +deletion</a>.{/i18n}</p> | |
| 9 | + | |
| 10 | +<form method="POST" action="{$smarty.server.PHP_SELF}"> | |
| 11 | +<fieldset><legend>{i18n}Rename{/i18n}</legend> | |
| 12 | +<input type="hidden" name="action" value="rename" /> | |
| 13 | +<input type="hidden" name="fDocumentId" value="{$iDocumentId}" /> | |
| 14 | +{foreach from=$fields item=oWidget } | |
| 15 | + {$oWidget->render()} | |
| 16 | +{/foreach} | |
| 17 | +<div class="form_actions"> | |
| 18 | +<input type="submit" name="submit" value="{i18n}Rename{/i18n}" /> | |
| 19 | +<input type="submit" name="kt_cancel[{$link}]" value="Cancel" /> | |
| 20 | +</div> | |
| 21 | +</fieldset> | |
| 22 | +</form> | ... | ... |