diff --git a/plugins/ktcore/KTCorePlugin.php b/plugins/ktcore/KTCorePlugin.php index 423799a..a663505 100644 --- a/plugins/ktcore/KTCorePlugin.php +++ b/plugins/ktcore/KTCorePlugin.php @@ -67,6 +67,10 @@ class KTCorePlugin extends KTPlugin { $this->registerAction('documentaction', 'KTDocumentAssistAction', 'ktcore.actions.document.assist', 'KTAssist.php'); // $this->registerAction('folderaction', 'KTDocumentAssistAction', 'ktcore.actions.folder.assist', 'KTAssist.php'); + // Viewlets + $this->registerAction('documentviewlet', 'KTWorkflowViewlet', 'ktcore.viewlets.document.workflow', 'KTDocumentViewlets.php'); + + $this->registerNotificationHandler('KTAssistNotification', 'ktcore/assist', 'KTAssist.php'); $this->registerNotificationHandler("KTSubscriptionNotification", "ktcore/subscriptions", KT_LIB_DIR . '/dashboard/Notification.inc.php'); $this->registerNotificationHandler("KTWorkflowNotification", "ktcore/workflow", KT_LIB_DIR . '/dashboard/Notification.inc.php'); diff --git a/plugins/ktcore/KTDocumentActions.php b/plugins/ktcore/KTDocumentActions.php index 4bb8d7b..c0c3139 100644 --- a/plugins/ktcore/KTDocumentActions.php +++ b/plugins/ktcore/KTDocumentActions.php @@ -1303,6 +1303,10 @@ class KTDocumentWorkflowAction extends KTDocumentAction { var $sHelpPage = 'ktcore/user/workflow.html'; + function predispatch() { + $this->persistParams(array("fTransitionId")); + } + function getDisplayName() { return _kt('Workflow'); } @@ -1392,6 +1396,75 @@ class KTDocumentWorkflowAction extends KTDocumentAction { array('fDocumentId' => $oDocument->getId())); } } + + function form_quicktransition() { + + $oForm = new KTForm; + $oForm->setOptions(array( + 'identifier' => 'ktcore.workflow.quicktransition', + 'label' => _kt("Perform Quick Transition"), + 'submit_label' => _kt("Perform Transition"), + 'context' => $this, + 'action' => 'performquicktransition', + 'fail_action' => 'quicktransition', + 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), + )); + $oForm->setWidgets(array( + array('ktcore.widgets.reason', array( + 'label' => _kt("Reason"), + 'description' => _kt("Specify your reason for performing this action."), + 'important_description' => _kt("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_quicktransition() { + // make sure this gets through. + $this->persistParams(array('fTransitionId')); + + $transition_id = $_REQUEST['fTransitionId']; + $oTransition = KTWorkflowTransition::get($transition_id); + + $oForm = $this->form_quicktransition(); + return $oForm->renderPage(sprintf(_kt("Perform Transition: %s"), $oTransition->getName())); + } + + function do_performquicktransition() { + $oForm = $this->form_quicktransition(); + $res = $oForm->validate(); + + if (!empty($res['errors'])) { + return $oForm->handleError(); + } + + $this->startTransaction(); + + $data = $res['results']; + $oTransition = KTWorkflowTransition::get($_REQUEST['fTransitionId']); + + $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $this->oDocument, $this->oUser, $data['reason']); + + if(!Permission::userHasDocumentReadPermission($this->oDocument)) { + $this->commitTransaction(); + $_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document'); + controllerRedirect('browse', sprintf('fFolderId=%d', $this->oDocument->getFolderId())); + } else { + $this->commitTransaction(); + $_SESSION['KTInfoMessage'][] = _kt('Transition performed'); + controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId())); + } + } + } // }}} diff --git a/plugins/ktcore/KTDocumentViewlets.php b/plugins/ktcore/KTDocumentViewlets.php new file mode 100644 index 0000000..c6349c7 --- /dev/null +++ b/plugins/ktcore/KTDocumentViewlets.php @@ -0,0 +1,68 @@ +loadTemplate("ktcore/document/viewlets/workflow"); + if (is_null($oTemplate)) { return ""; } + + $oWorkflowState = KTWorkflowState::get($this->oDocument->getWorkflowStateId()); + if (PEAR::isError($oWorkflowState)) { + return ""; + } + + $aDisplayTransitions = array(); + $aTransitions = KTWorkflowUtil::getTransitionsForDocumentUser($this->oDocument, $this->oUser); + if (empty($aTransitions)) { + return ""; + } + + foreach ($aTransitions as $oTransition) { + $aDisplayTransitions[] = array( + 'url' => KTUtil::ktLink('action.php', 'ktcore.actions.document.workflow', array("fDocumentId" => $this->oDocument->getId(), "action" => "quicktransition", "fTransitionId" => $oTransition->getId())), + 'name' => $oTransition->getName(), + ); + } + + $oTemplate->setData(array( + 'context' => $this, + 'transitions' => $aDisplayTransitions, + 'state_name' => $oWorkflowState->getName(), + )); + return $oTemplate->render(); + } +} +// }}} + + + +?> diff --git a/templates/ktcore/document/view.smarty b/templates/ktcore/document/view.smarty index 04065d7..94fd38c 100644 --- a/templates/ktcore/document/view.smarty +++ b/templates/ktcore/document/view.smarty @@ -40,12 +40,12 @@ these tasks, use the Request Assistance action.{/i18n} {$oFieldset->render($document_data)} {/foreach} -{if !empty($viewlets)} +{if !empty($viewlet_data)}
{i18n arg_name=$state_name}The document is currently in state "#name#"{/i18n}
+