Commit e55a8756028e264ad298a38ea54e6e2d61ec30c3

Authored by bshuttle
1 parent 8701fdea

- add "cancel checkout" document action

- improve the "checked out" notice
- improve the "checkout" page.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4703 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/actions/documentaction.inc.php
@@ -25,6 +25,8 @@ class KTDocumentAction extends KTStandardDispatcher { @@ -25,6 +25,8 @@ class KTDocumentAction extends KTStandardDispatcher {
25 $this->oDocument =& $oDocument; 25 $this->oDocument =& $oDocument;
26 $this->oUser =& $oUser; 26 $this->oUser =& $oUser;
27 $this->oPlugin =& $oPlugin; 27 $this->oPlugin =& $oPlugin;
  28 +
  29 +
28 parent::KTStandardDispatcher(); 30 parent::KTStandardDispatcher();
29 } 31 }
30 32
@@ -134,6 +136,13 @@ class KTDocumentAction extends KTStandardDispatcher { @@ -134,6 +136,13 @@ class KTDocumentAction extends KTStandardDispatcher {
134 ); 136 );
135 $this->aBreadcrumbs = array_merge($this->aBreadcrumbs, 137 $this->aBreadcrumbs = array_merge($this->aBreadcrumbs,
136 KTBrowseUtil::breadcrumbsForDocument($this->oDocument, $aOptions)); 138 KTBrowseUtil::breadcrumbsForDocument($this->oDocument, $aOptions));
  139 +
  140 +
  141 + $actions = KTDocumentActionUtil::getDocumentActionsForDocument($this->oDocument, $this->oUser);
  142 + $oPortlet = new KTActionPortlet(_("Document Actions"));
  143 + $oPortlet->setActions($actions, $this->sName);
  144 + $this->oPage->addPortlet($oPortlet);
  145 +
137 return true; 146 return true;
138 } 147 }
139 148
plugins/ktcore/KTCorePlugin.php
@@ -11,6 +11,7 @@ class KTCorePlugin extends KTPlugin { @@ -11,6 +11,7 @@ class KTCorePlugin extends KTPlugin {
11 $this->registerAction('documentaction', 'KTDocumentDetailsAction', 'ktcore.actions.document.displaydetails', 'KTDocumentActions.php'); 11 $this->registerAction('documentaction', 'KTDocumentDetailsAction', 'ktcore.actions.document.displaydetails', 'KTDocumentActions.php');
12 $this->registerAction('documentaction', 'KTDocumentViewAction', 'ktcore.actions.document.view', 'KTDocumentActions.php'); 12 $this->registerAction('documentaction', 'KTDocumentViewAction', 'ktcore.actions.document.view', 'KTDocumentActions.php');
13 $this->registerAction('documentaction', 'KTDocumentCheckOutAction', 'ktcore.actions.document.checkout', 'KTDocumentActions.php'); 13 $this->registerAction('documentaction', 'KTDocumentCheckOutAction', 'ktcore.actions.document.checkout', 'KTDocumentActions.php');
  14 + $this->registerAction('documentaction', 'KTDocumentCancelCheckOutAction', 'ktcore.actions.document.cancelcheckout', 'KTDocumentActions.php');
14 $this->registerAction('documentaction', 'KTDocumentCheckInAction', 'ktcore.actions.document.checkin', 'KTDocumentActions.php'); 15 $this->registerAction('documentaction', 'KTDocumentCheckInAction', 'ktcore.actions.document.checkin', 'KTDocumentActions.php');
15 $this->registerAction('documentaction', 'KTDocumentEditAction', 'ktcore.actions.document.edit', 'KTDocumentActions.php'); 16 $this->registerAction('documentaction', 'KTDocumentEditAction', 'ktcore.actions.document.edit', 'KTDocumentActions.php');
16 $this->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete', 'KTDocumentActions.php'); 17 $this->registerAction('documentaction', 'KTDocumentDeleteAction', 'ktcore.actions.document.delete', 'KTDocumentActions.php');
plugins/ktcore/KTDocumentActions.php
@@ -100,16 +100,6 @@ class KTDocumentCheckOutAction extends KTDocumentAction { @@ -100,16 +100,6 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
100 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final'); 100 $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final');
101 $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions); 101 $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions);
102 102
103 - $oTemplate->setData(array(  
104 - 'context' => &$this,  
105 - 'reason' => $sReason,  
106 - ));  
107 - return $oTemplate->render();  
108 - }  
109 -  
110 - function do_checkout_final() {  
111 - $sReason = KTUtil::arrayGet($_REQUEST, 'reason');  
112 - $this->oValidator->notEmpty($sReason);  
113 103
114 // flip the checkout status 104 // flip the checkout status
115 $this->oDocument->setIsCheckedOut(true); 105 $this->oDocument->setIsCheckedOut(true);
@@ -139,6 +129,18 @@ class KTDocumentCheckOutAction extends KTDocumentAction { @@ -139,6 +129,18 @@ class KTDocumentCheckOutAction extends KTDocumentAction {
139 129
140 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $sReason, 'ktcore.transactions.check_out'); 130 $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $sReason, 'ktcore.transactions.check_out');
141 $oDocumentTransaction->create(); 131 $oDocumentTransaction->create();
  132 +
  133 + $oTemplate->setData(array(
  134 + 'context' => &$this,
  135 + 'reason' => $sReason,
  136 + ));
  137 + return $oTemplate->render();
  138 + }
  139 +
  140 + function do_checkout_final() {
  141 + $sReason = KTUtil::arrayGet($_REQUEST, 'reason');
  142 + $this->oValidator->notEmpty($sReason);
  143 +
142 144
143 $oStorage =& KTStorageManagerUtil::getSingleton(); 145 $oStorage =& KTStorageManagerUtil::getSingleton();
144 $oStorage->download($this->oDocument); 146 $oStorage->download($this->oDocument);
@@ -224,6 +226,88 @@ class KTDocumentCheckInAction extends KTDocumentAction { @@ -224,6 +226,88 @@ class KTDocumentCheckInAction extends KTDocumentAction {
224 } 226 }
225 // }}} 227 // }}}
226 228
  229 +
  230 +// {{{ KTDocumentCheckInAction
  231 +class KTDocumentCancelCheckOutAction extends KTDocumentAction {
  232 + var $sDisplayName = 'Cancel Checkout';
  233 + var $sName = 'ktcore.actions.document.cancelcheckout';
  234 +
  235 + var $_sShowPermission = "ktcore.permissions.write";
  236 +
  237 + function getInfo() {
  238 + if (!$this->oDocument->getIsCheckedOut()) {
  239 + return null;
  240 + }
  241 +
  242 + if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) {
  243 + return null;
  244 + }
  245 + return parent::getInfo();
  246 + }
  247 +
  248 + function check() {
  249 + $res = parent::check();
  250 + if ($res !== true) {
  251 + return $res;
  252 + }
  253 + if (!$this->oDocument->getIsCheckedOut()) {
  254 + $_SESSION['KTErrorMessage'][] = _("This document is not checked out");
  255 + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
  256 + exit(0);
  257 + }
  258 + if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) {
  259 + $_SESSION['KTErrorMessage'][] = _("This document is checked out, but not by you");
  260 + controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
  261 + exit(0);
  262 + }
  263 + return true;
  264 + }
  265 +
  266 + function do_main() {
  267 + $this->oPage->setBreadcrumbDetails("cancel checkin");
  268 + $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/cancel_checkout');
  269 +
  270 + $sReason = KTUtil::arrayGet($_REQUEST, 'reason', "");
  271 + $checkin_fields = array();
  272 + $checkin_fields[] = new KTStringWidget(_('Reason'), _('Give a reason for cancelling this checkout.'), 'reason', $sReason, $this->oPage, true);
  273 +
  274 + $oTemplate->setData(array(
  275 + 'context' => &$this,
  276 + 'checkin_fields' => $checkin_fields,
  277 + 'document' => $this->oDocument,
  278 + ));
  279 + return $oTemplate->render();
  280 + }
  281 +
  282 + function do_checkin() {
  283 + $sReason = KTUtil::arrayGet($_REQUEST, 'reason');
  284 + $sReason = $this->oValidator->notEmpty($sReason);
  285 +
  286 + global $default;
  287 +
  288 + $this->startTransaction();
  289 + // actually do the checkin.
  290 + $this->oDocument->setIsCheckedOut(0);
  291 + $this->oDocument->setCheckedOutUserID(-1);
  292 + if (!$this->oDocument->update()) {
  293 + $this->rollbackTransaction();
  294 + return $this->errorRedirectToMain(_("Failed to force the document's checkin."),sprintf('fDocumentId=%d'),$this->oDocument->getId());
  295 + }
  296 +
  297 + // checkout cancelled transaction
  298 + $oDocumentTransaction = & new DocumentTransaction($this->oDocument, "Document checked out cancelled", 'ktcore.transactions.force_checkin');
  299 + $res = $oDocumentTransaction->create();
  300 + if (PEAR::isError($res) || ($res == false)) {
  301 + $this->rollbackTransaction();
  302 + return $this->errorRedirectToMain(_("Failed to force the document's checkin."),sprintf('fDocumentId=%d'),$this->oDocument->getId());
  303 + }
  304 + $this->commitTransaction(); // FIXME do we want to do this if we can't created the document-transaction?
  305 + redirect("$default->rootUrl/control.php?action=viewDocument&fDocumentID=" . $this->oDocument->getID());
  306 + }
  307 +}
  308 +// }}}
  309 +
  310 +
227 // {{{ KTDocumentEditAction 311 // {{{ KTDocumentEditAction
228 class KTDocumentEditAction extends KTDocumentAction { 312 class KTDocumentEditAction extends KTDocumentAction {
229 var $sDisplayName = 'Edit metadata'; 313 var $sDisplayName = 'Edit metadata';
@@ -540,6 +624,15 @@ class KTDocumentArchiveAction extends KTDocumentAction { @@ -540,6 +624,15 @@ class KTDocumentArchiveAction extends KTDocumentAction {
540 } 624 }
541 625
542 function do_archive() { 626 function do_archive() {
  627 +
  628 + $aErrorOptions = array(
  629 + 'redirect_to' => array('','fDocumentId=' . $this->oDocument->getId()),
  630 + 'message' => "You must provide a reason"
  631 + );
  632 +
  633 + $sReason = $this->oValidator->validateString(KTUtil::arrayGet($_REQUEST, 'reason'), $aErrorOptions);
  634 +
  635 +
543 $this->startTransaction(); 636 $this->startTransaction();
544 $this->oDocument->setStatusID(ARCHIVED); 637 $this->oDocument->setStatusID(ARCHIVED);
545 if (!$this->oDocument->update()) { 638 if (!$this->oDocument->update()) {
@@ -547,6 +640,9 @@ class KTDocumentArchiveAction extends KTDocumentAction { @@ -547,6 +640,9 @@ class KTDocumentArchiveAction extends KTDocumentAction {
547 controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); 640 controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
548 exit(0); 641 exit(0);
549 } 642 }
  643 + $oDocumentTransaction = & new DocumentTransaction($this->oDocument, sprintf(_("Document archived: %s"), $sReason), 'ktcore.transactions.update');
  644 + $oDocumentTransaction->create();
  645 +
550 $this->commitTransaction(); 646 $this->commitTransaction();
551 647
552 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); 648 $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
plugins/ktcore/admin/documentCheckout.php
@@ -110,11 +110,11 @@ class KTCheckoutAdminDispatcher extends KTAdminDispatcher { @@ -110,11 +110,11 @@ class KTCheckoutAdminDispatcher extends KTAdminDispatcher {
110 110
111 // checkout cancelled transaction 111 // checkout cancelled transaction
112 $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document checked out cancelled", 'ktcore.transactions.force_checkin'); 112 $oDocumentTransaction = & new DocumentTransaction($oDocument, "Document checked out cancelled", 'ktcore.transactions.force_checkin');
113 - if ($oDocumentTransaction->create()) {  
114 - $default->log->debug("editDocCheckoutBL.php created forced checkin document transaction for document ID=" . $oDocument->getID());  
115 - } else {  
116 - $default->log->error("editDocCheckoutBL.php couldn't create create document transaction for document ID=" . $oDocument->getID());  
117 - } 113 + $res = $oDocumentTransaction->create();
  114 + if (PEAR::isError($res) || ($res == false)) {
  115 + $this->rollbackTransaction();
  116 + return $this->errorRedirectToMain(_("Failed to force the document's checkin."));
  117 + }
118 $this->commitTransaction(); // FIXME do we want to do this if we can't created the document-transaction? 118 $this->commitTransaction(); // FIXME do we want to do this if we can't created the document-transaction?
119 return $this->successRedirectToMain(sprintf(_('Successfully forced "%s" to be checked in.'), $oDocument->getName())); 119 return $this->successRedirectToMain(sprintf(_('Successfully forced "%s" to be checked in.'), $oDocument->getName()));
120 } 120 }
templates/kt3/view_document.smarty
@@ -6,11 +6,18 @@ @@ -6,11 +6,18 @@
6 #version#</strong>{/i18n}</p> 6 #version#</strong>{/i18n}</p>
7 {if ($document->getIsCheckedOut() == 1)} 7 {if ($document->getIsCheckedOut() == 1)}
8 {capture assign=checkout_user}<strong>{$sCheckoutUser}</strong>{/capture} 8 {capture assign=checkout_user}<strong>{$sCheckoutUser}</strong>{/capture}
  9 +{if ($isCheckoutUser)}
  10 +<div class="ktInfo">
  11 +<p>{i18n}This document is currently checked out by <strong>you</strong>. If
  12 +this is incorrect, or you no longer need to make changes to it, please cancel the checkout.{/i18n}</p>
  13 +</div>
  14 +{else}
9 <div class="ktInfo"> 15 <div class="ktInfo">
10 <p>{i18n arg_checkoutuser=$checkout_user}This document is currently checked out by #checkoutuser#. You cannot make 16 <p>{i18n arg_checkoutuser=$checkout_user}This document is currently checked out by #checkoutuser#. You cannot make
11 changes until that user checks it in. If you have urgent modifications to make, please 17 changes until that user checks it in. If you have urgent modifications to make, please
12 contact your KnowledgeTree Administrator.{/i18n}</p> 18 contact your KnowledgeTree Administrator.{/i18n}</p>
13 </div> 19 </div>
  20 +{/if}
14 {/if} 21 {/if}
15 {foreach item=oFieldset from=$fieldsets} 22 {foreach item=oFieldset from=$fieldsets}
16 {$oFieldset->render($document_data)} 23 {$oFieldset->render($document_data)}
templates/ktcore/action/cancel_checkout.smarty 0 โ†’ 100644
  1 +<h2>{i18n}Cancel Checkout{/i18n}</h2>
  2 +
  3 +<p class="descriptiveText">If you do not want to have this document be checked-out,
  4 +please give a reason and cancel the checkout.</p>
  5 +
  6 +<form method="POST" action="{$smarty.server.PHP_SELF}" enctype="multipart/form-data">
  7 +<fieldset><legend>{i18n}Checkin{/i18n}</legend>
  8 +<input type="hidden" name="action" value="checkin" />
  9 +<input type="hidden" name="fDocumentId" value="{$document->getId()}" />
  10 +{foreach from=$checkin_fields item=oWidget }
  11 + {$oWidget->render()}
  12 +{/foreach}
  13 +<div class="form_actions">
  14 +<input type="submit" name="submit" value="{i18n}Cancel Checkout{/i18n}" />
  15 +</div>
  16 +</fieldset>
  17 +</form>
templates/ktcore/action/checkout.smarty
@@ -4,12 +4,6 @@ anyone else changing the document and placing it into the document @@ -4,12 +4,6 @@ anyone else changing the document and placing it into the document
4 management system.{/i18n}</p> 4 management system.{/i18n}</p>
5 5
6 {assign var=iDocumentId value=$context->oDocument->getId()} 6 {assign var=iDocumentId value=$context->oDocument->getId()}
7 -{capture assign=link}  
8 -{"viewDocument"|generateControllerUrl:"fDocumentId=$iDocumentId"}  
9 -{/capture}  
10 -<p class="descriptiveText">{i18n arg_link=$link}If you do not intend to edit the document, and you  
11 -do not wish to prevent others from changing the document, you should  
12 -<a href="#link#">cancel this checkout</a>.{/i18n}</p>  
13 7
14 <form method="POST" action="{$smarty.server.PHP_SELF}"> 8 <form method="POST" action="{$smarty.server.PHP_SELF}">
15 <fieldset><legend>{i18n}Checkout{/i18n}</legend> 9 <fieldset><legend>{i18n}Checkout{/i18n}</legend>
templates/ktcore/metadata/listFieldsets.smarty
@@ -8,19 +8,18 @@ @@ -8,19 +8,18 @@
8 <table class="listing" cellpadding="1.5em" cellspacing="0"> 8 <table class="listing" cellpadding="1.5em" cellspacing="0">
9 <thead> 9 <thead>
10 <tr> 10 <tr>
11 - <th colspan="2">{i18n}Name{/i18n}</th>  
12 - <th>{i18n}Generic{/i18n}</th> 11 + <th>{i18n}Name{/i18n}</th>
  12 + <th>{i18n}Is Generic{/i18n}</th>
13 <th>{i18n}Fields{/i18n}</th> 13 <th>{i18n}Fields{/i18n}</th>
  14 + <th>{i18n}Edit{/i18n}</th>
  15 + <th>{i18n}Delete{/i18n}</th>
14 </tr> 16 </tr>
15 </thead> 17 </thead>
16 <tbody> 18 <tbody>
17 {foreach from=$fieldsets item=oFieldset} 19 {foreach from=$fieldsets item=oFieldset}
18 <tr> 20 <tr>
19 - <td>  
20 - <a href="?action=delete&fFieldsetId={$oFieldset->getId()}" class="ktAction ktDelete">{i18n}Delete{/i18n}</a>  
21 - </td>  
22 <td> 21 <td>
23 - <a href="?action=edit&fFieldsetId={$oFieldset->getId()}"> { $oFieldset->getName() } 22 + { $oFieldset->getName() }
24 </a> 23 </a>
25 </td> 24 </td>
26 <td> 25 <td>
@@ -33,15 +32,22 @@ @@ -33,15 +32,22 @@
33 <td> 32 <td>
34 {assign var="aFields" value=$oFieldset->getFields()} 33 {assign var="aFields" value=$oFieldset->getFields()}
35 {if $aFields} 34 {if $aFields}
36 -<ul>  
37 -{foreach from=$aFields item=oField}  
38 - <li>{$oField->getName()}</li> 35 +
  36 +{foreach from=$aFields item=oField name=fields}
  37 +{$oField->getName()}{if (!$smarty.foreach.fields.last)}, {/if}
39 {/foreach} 38 {/foreach}
40 -</ul> 39 +
41 {else} 40 {else}
42 -&nbsp; 41 +&mdash;
43 {/if} 42 {/if}
44 </td> 43 </td>
  44 + <td>
  45 + <a href="?action=edit&fFieldsetId={$oFieldset->getId()}" class="ktAction ktEdit">{i18n}Edit{/i18n}</a>
  46 + </td>
  47 + <td>
  48 + <a href="?action=delete&fFieldsetId={$oFieldset->getId()}" class="ktAction ktDelete">{i18n}Delete{/i18n}</a>
  49 + </td>
  50 +
45 </tr> 51 </tr>
46 </tbody> 52 </tbody>
47 {/foreach} 53 {/foreach}
view.php
@@ -139,6 +139,7 @@ class ViewDocumentDispatcher extends KTStandardDispatcher { @@ -139,6 +139,7 @@ class ViewDocumentDispatcher extends KTStandardDispatcher {
139 $aTemplateData = array( 139 $aTemplateData = array(
140 "context" => $this, 140 "context" => $this,
141 "sCheckoutUser" => $checkout_user, 141 "sCheckoutUser" => $checkout_user,
  142 + "isCheckoutUser" => ($this->oUser->getId() == $oDocument->getCheckedOutUserId()),
142 "document_id" => $document_id, 143 "document_id" => $document_id,
143 "document" => $oDocument, 144 "document" => $oDocument,
144 "document_data" => $document_data, 145 "document_data" => $document_data,