From e55a8756028e264ad298a38ea54e6e2d61ec30c3 Mon Sep 17 00:00:00 2001
From: bshuttle
Date: Fri, 27 Jan 2006 14:33:26 +0000
Subject: [PATCH] - add "cancel checkout" document action - improve the "checked out" notice - improve the "checkout" page.
---
lib/actions/documentaction.inc.php | 9 +++++++++
plugins/ktcore/KTCorePlugin.php | 1 +
plugins/ktcore/KTDocumentActions.php | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
plugins/ktcore/admin/documentCheckout.php | 10 +++++-----
templates/kt3/view_document.smarty | 7 +++++++
templates/ktcore/action/cancel_checkout.smarty | 17 +++++++++++++++++
templates/ktcore/action/checkout.smarty | 6 ------
templates/ktcore/metadata/listFieldsets.smarty | 28 +++++++++++++++++-----------
view.php | 1 +
9 files changed, 163 insertions(+), 32 deletions(-)
create mode 100644 templates/ktcore/action/cancel_checkout.smarty
diff --git a/lib/actions/documentaction.inc.php b/lib/actions/documentaction.inc.php
index 596e072..0fc22c4 100644
--- a/lib/actions/documentaction.inc.php
+++ b/lib/actions/documentaction.inc.php
@@ -25,6 +25,8 @@ class KTDocumentAction extends KTStandardDispatcher {
$this->oDocument =& $oDocument;
$this->oUser =& $oUser;
$this->oPlugin =& $oPlugin;
+
+
parent::KTStandardDispatcher();
}
@@ -134,6 +136,13 @@ class KTDocumentAction extends KTStandardDispatcher {
);
$this->aBreadcrumbs = array_merge($this->aBreadcrumbs,
KTBrowseUtil::breadcrumbsForDocument($this->oDocument, $aOptions));
+
+
+ $actions = KTDocumentActionUtil::getDocumentActionsForDocument($this->oDocument, $this->oUser);
+ $oPortlet = new KTActionPortlet(_("Document Actions"));
+ $oPortlet->setActions($actions, $this->sName);
+ $this->oPage->addPortlet($oPortlet);
+
return true;
}
diff --git a/plugins/ktcore/KTCorePlugin.php b/plugins/ktcore/KTCorePlugin.php
index f2f181e..c53bf46 100644
--- a/plugins/ktcore/KTCorePlugin.php
+++ b/plugins/ktcore/KTCorePlugin.php
@@ -11,6 +11,7 @@ class KTCorePlugin extends KTPlugin {
$this->registerAction('documentaction', 'KTDocumentDetailsAction', 'ktcore.actions.document.displaydetails', 'KTDocumentActions.php');
$this->registerAction('documentaction', 'KTDocumentViewAction', 'ktcore.actions.document.view', 'KTDocumentActions.php');
$this->registerAction('documentaction', 'KTDocumentCheckOutAction', 'ktcore.actions.document.checkout', 'KTDocumentActions.php');
+ $this->registerAction('documentaction', 'KTDocumentCancelCheckOutAction', 'ktcore.actions.document.cancelcheckout', 'KTDocumentActions.php');
$this->registerAction('documentaction', 'KTDocumentCheckInAction', 'ktcore.actions.document.checkin', 'KTDocumentActions.php');
$this->registerAction('documentaction', 'KTDocumentEditAction', 'ktcore.actions.document.edit', 'KTDocumentActions.php');
$this->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete', 'KTDocumentActions.php');
diff --git a/plugins/ktcore/KTDocumentActions.php b/plugins/ktcore/KTDocumentActions.php
index a308f35..8d836ea 100644
--- a/plugins/ktcore/KTDocumentActions.php
+++ b/plugins/ktcore/KTDocumentActions.php
@@ -100,16 +100,6 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final');
$sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions);
- $oTemplate->setData(array(
- 'context' => &$this,
- 'reason' => $sReason,
- ));
- return $oTemplate->render();
- }
-
- function do_checkout_final() {
- $sReason = KTUtil::arrayGet($_REQUEST, 'reason');
- $this->oValidator->notEmpty($sReason);
// flip the checkout status
$this->oDocument->setIsCheckedOut(true);
@@ -139,6 +129,18 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
$oDocumentTransaction = & new DocumentTransaction($this->oDocument, $sReason, 'ktcore.transactions.check_out');
$oDocumentTransaction->create();
+
+ $oTemplate->setData(array(
+ 'context' => &$this,
+ 'reason' => $sReason,
+ ));
+ return $oTemplate->render();
+ }
+
+ function do_checkout_final() {
+ $sReason = KTUtil::arrayGet($_REQUEST, 'reason');
+ $this->oValidator->notEmpty($sReason);
+
$oStorage =& KTStorageManagerUtil::getSingleton();
$oStorage->download($this->oDocument);
@@ -224,6 +226,88 @@ class KTDocumentCheckInAction extends KTDocumentAction {
}
// }}}
+
+// {{{ KTDocumentCheckInAction
+class KTDocumentCancelCheckOutAction extends KTDocumentAction {
+ var $sDisplayName = 'Cancel Checkout';
+ var $sName = 'ktcore.actions.document.cancelcheckout';
+
+ var $_sShowPermission = "ktcore.permissions.write";
+
+ function getInfo() {
+ if (!$this->oDocument->getIsCheckedOut()) {
+ return null;
+ }
+
+ if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) {
+ return null;
+ }
+ return parent::getInfo();
+ }
+
+ function check() {
+ $res = parent::check();
+ if ($res !== true) {
+ return $res;
+ }
+ if (!$this->oDocument->getIsCheckedOut()) {
+ $_SESSION['KTErrorMessage'][] = _("This document is not checked out");
+ controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
+ exit(0);
+ }
+ if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) {
+ $_SESSION['KTErrorMessage'][] = _("This document is checked out, but not by you");
+ controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
+ exit(0);
+ }
+ return true;
+ }
+
+ function do_main() {
+ $this->oPage->setBreadcrumbDetails("cancel checkin");
+ $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/cancel_checkout');
+
+ $sReason = KTUtil::arrayGet($_REQUEST, 'reason', "");
+ $checkin_fields = array();
+ $checkin_fields[] = new KTStringWidget(_('Reason'), _('Give a reason for cancelling this checkout.'), 'reason', $sReason, $this->oPage, true);
+
+ $oTemplate->setData(array(
+ 'context' => &$this,
+ 'checkin_fields' => $checkin_fields,
+ 'document' => $this->oDocument,
+ ));
+ return $oTemplate->render();
+ }
+
+ function do_checkin() {
+ $sReason = KTUtil::arrayGet($_REQUEST, 'reason');
+ $sReason = $this->oValidator->notEmpty($sReason);
+
+ global $default;
+
+ $this->startTransaction();
+ // actually do the checkin.
+ $this->oDocument->setIsCheckedOut(0);
+ $this->oDocument->setCheckedOutUserID(-1);
+ if (!$this->oDocument->update()) {
+ $this->rollbackTransaction();
+ return $this->errorRedirectToMain(_("Failed to force the document's checkin."),sprintf('fDocumentId=%d'),$this->oDocument->getId());
+ }
+
+ // checkout cancelled transaction
+ $oDocumentTransaction = & new DocumentTransaction($this->oDocument, "Document checked out cancelled", 'ktcore.transactions.force_checkin');
+ $res = $oDocumentTransaction->create();
+ if (PEAR::isError($res) || ($res == false)) {
+ $this->rollbackTransaction();
+ return $this->errorRedirectToMain(_("Failed to force the document's checkin."),sprintf('fDocumentId=%d'),$this->oDocument->getId());
+ }
+ $this->commitTransaction(); // FIXME do we want to do this if we can't created the document-transaction?
+ redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $this->oDocument->getID());
+ }
+}
+// }}}
+
+
// {{{ KTDocumentEditAction
class KTDocumentEditAction extends KTDocumentAction {
var $sDisplayName = 'Edit metadata';
@@ -540,6 +624,15 @@ class KTDocumentArchiveAction extends KTDocumentAction {
}
function do_archive() {
+
+ $aErrorOptions = array(
+ 'redirect_to' => array('','fDocumentId=' . $this->oDocument->getId()),
+ 'message' => "You must provide a reason"
+ );
+
+ $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions);
+
+
$this->startTransaction();
$this->oDocument->setStatusID(ARCHIVED);
if (!$this->oDocument->update()) {
@@ -547,6 +640,9 @@ class KTDocumentArchiveAction extends KTDocumentAction {
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
exit(0);
}
+ $oDocumentTransaction = & new DocumentTransaction($this->oDocument, sprintf(_("Document archived: %s"), $sReason), 'ktcore.transactions.update');
+ $oDocumentTransaction->create();
+
$this->commitTransaction();
$oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
diff --git a/plugins/ktcore/admin/documentCheckout.php b/plugins/ktcore/admin/documentCheckout.php
index 3375c34..1b9eecf 100644
--- a/plugins/ktcore/admin/documentCheckout.php
+++ b/plugins/ktcore/admin/documentCheckout.php
@@ -110,11 +110,11 @@ class KTCheckoutAdminDispatcher extends KTAdminDispatcher {
// checkout cancelled transaction
$oDocumentTransaction = & new DocumentTransaction($oDocument, "Document checked out cancelled", 'ktcore.transactions.force_checkin');
- if ($oDocumentTransaction->create()) {
- $default->log->debug("editDocCheckoutBL.php created forced checkin document transaction for document ID=" . $oDocument->getID());
- } else {
- $default->log->error("editDocCheckoutBL.php couldn't create create document transaction for document ID=" . $oDocument->getID());
- }
+ $res = $oDocumentTransaction->create();
+ if (PEAR::isError($res) || ($res == false)) {
+ $this->rollbackTransaction();
+ return $this->errorRedirectToMain(_("Failed to force the document's checkin."));
+ }
$this->commitTransaction(); // FIXME do we want to do this if we can't created the document-transaction?
return $this->successRedirectToMain(sprintf(_('Successfully forced "%s" to be checked in.'), $oDocument->getName()));
}
diff --git a/templates/kt3/view_document.smarty b/templates/kt3/view_document.smarty
index 749e1d3..e70d44d 100644
--- a/templates/kt3/view_document.smarty
+++ b/templates/kt3/view_document.smarty
@@ -6,11 +6,18 @@
#version#{/i18n}
{if ($document->getIsCheckedOut() == 1)}
{capture assign=checkout_user}{$sCheckoutUser}{/capture}
+{if ($isCheckoutUser)}
+
+
{i18n}This document is currently checked out by you. If
+this is incorrect, or you no longer need to make changes to it, please cancel the checkout.{/i18n}
+
+{else}
{i18n arg_checkoutuser=$checkout_user}This document is currently checked out by #checkoutuser#. You cannot make
changes until that user checks it in. If you have urgent modifications to make, please
contact your KnowledgeTree Administrator.{/i18n}
+{/if}
{/if}
{foreach item=oFieldset from=$fieldsets}
{$oFieldset->render($document_data)}
diff --git a/templates/ktcore/action/cancel_checkout.smarty b/templates/ktcore/action/cancel_checkout.smarty
new file mode 100644
index 0000000..dffeead
--- /dev/null
+++ b/templates/ktcore/action/cancel_checkout.smarty
@@ -0,0 +1,17 @@
+{i18n}Cancel Checkout{/i18n}
+
+If you do not want to have this document be checked-out,
+please give a reason and cancel the checkout.
+
+
diff --git a/templates/ktcore/action/checkout.smarty b/templates/ktcore/action/checkout.smarty
index 7655118..3adee3e 100644
--- a/templates/ktcore/action/checkout.smarty
+++ b/templates/ktcore/action/checkout.smarty
@@ -4,12 +4,6 @@ anyone else changing the document and placing it into the document
management system.{/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 edit the document, and you
-do not wish to prevent others from changing the document, you should
-cancel this checkout.{/i18n}