diff --git a/plugins/ktcore/KTDocumentActions.php b/plugins/ktcore/KTDocumentActions.php index 3c2c9df..c4e93e9 100644 --- a/plugins/ktcore/KTDocumentActions.php +++ b/plugins/ktcore/KTDocumentActions.php @@ -1210,32 +1210,62 @@ class KTDocumentArchiveAction extends KTDocumentAction { return parent::getInfo(); } + function form_main() { + $oForm = new KTForm; + $oForm->setOptions(array( + 'label' => _kt("Archive Document"), + 'action' => 'archive', + 'fail_action' => 'main', + 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), + 'submit_label' => _kt("Archive Document"), + 'context' => &$this, + )); + $oForm->setWidgets(array( + array('ktcore.widgets.reason', array( + 'label' => _kt("Reason"), + 'description' => _kt("Please specify why you are archiving this document. Please bear in mind that you can use a maximum of 250 characters."), + 'name' => 'reason', + )), + )); + $oForm->setValidators(array( + array('ktcore.validators.string', array( + 'test' => 'reason', + 'max_length' => 250, + 'output' => 'reason', + )), + )); + + return $oForm; + } + function do_main() { - $this->oPage->setBreadcrumbDetails(_kt("archiving")); + $this->oPage->setBreadcrumbDetails(_kt("Archive Document")); $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/archive'); - $fields = array(); - $fields[] = new KTStringWidget(_kt('Reason'), _kt('The reason for the archiving of this document. This will be displayed when the archived document is to be displayed.'), 'reason', "", $this->oPage, true); + + $oForm = $this->form_main(); $oTemplate->setData(array( 'context' => &$this, - 'fields' => $fields, + 'form' => $oForm, )); return $oTemplate->render(); } function do_archive() { - $aErrorOptions = array( - 'redirect_to' => array('','fDocumentId=' . $this->oDocument->getId()), - 'message' => _kt("You must provide a reason"), - ); + $oForm = $this->form_main(); + $res = $oForm->validate(); + $data = $res['results']; + if (!empty($res['errors'])) { + return $oForm->handleError(); + } - $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions); - + $sReason = $data['reason']; $this->startTransaction(); $this->oDocument->setStatusID(ARCHIVED); - if (!$this->oDocument->update()) { + $res = $this->oDocument->update(); + if (PEAR::isError($res) || ($res === false)) { $_SESSION['KTErrorMessage'][] = _kt("There was a database error while trying to archive this file"); controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); diff --git a/templates/ktcore/action/archive.smarty b/templates/ktcore/action/archive.smarty index cd4c760..670a986 100644 --- a/templates/ktcore/action/archive.smarty +++ b/templates/ktcore/action/archive.smarty @@ -1,29 +1,9 @@ +
{i18n}Archiving a document changes the document's state to invisible to non-administrative users. Only an Administrator may unarchive a document. Please note that this is a non-permanent change and does not delete the document from the repository.{/i18n}
-{assign var=iDocumentId value=$context->oDocument->getId()} -{capture assign=link} -{"viewDocument"|generateControllerUrl:"fDocumentId=$iDocumentId"} -{/capture} - -{i18n arg_link=$link}If you do not intend to -archive this document, you should cancel the -archive.{/i18n}
- - +{$form->render()} diff --git a/templates/ktcore/action/assistance.smarty b/templates/ktcore/action/assistance.smarty index d43ed68..a67ac33 100644 --- a/templates/ktcore/action/assistance.smarty +++ b/templates/ktcore/action/assistance.smarty @@ -1,3 +1,5 @@ +{i18n}If you are unable to perform an action on this document that you think you should be able to, or wish to request a change in location, metadata values, or workflow status, you