function display_viewlet() { $oKTTemplating =& KTTemplating::getSingleton(); $oTemplate =& $oKTTemplating->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 ""; } // Check if the document has been checked out $bIsCheckedOut = $this->oDocument->getIsCheckedOut(); $iId = $this->oDocument->getId(); if ($bIsCheckedOut) { // If document is checked out, don't link into the workflow. $aDisplayTransitions = array(); } else { foreach ($aTransitions as $oTransition) { if (is_null($oTransition) || PEAR::isError($oTransition)) { continue; } $aDisplayTransitions[] = array('url' => KTUtil::ktLink('action.php', 'ktcore.actions.document.workflow', array("fDocumentId" => $iId, "action" => "quicktransition", "fTransitionId" => $oTransition->getId())), 'name' => $oTransition->getName()); } } //Retreive the comment for the previous transition $aCommentQuery = array("SELECT comment FROM document_transactions\n where transaction_namespace='ktcore.transactions.workflow_state_transition'\n AND document_id = ?\n ORDER BY id DESC LIMIT 1;"); $aCommentQuery[] = array($iId); $aTransitionComments = DBUtil::getResultArray($aCommentQuery); $oLatestTransitionComment = null; if (!empty($aTransitionComments)) { $aRow = $aTransitionComments[0]; $oLatestTransitionComment = $aRow['comment']; $iCommentPosition = strpos($oLatestTransitionComment, ':'); //comment found after first colon in string if ($iCommentPosition > 0) { $oLatestTransitionComment = substr($oLatestTransitionComment, $iCommentPosition + 2, strlen($oLatestTransitionComment) - $iCommentPosition); } else { $oLatestTransitionComment = null; } } $oTemplate->setData(array('context' => $this, 'bIsCheckedOut' => $bIsCheckedOut, 'transitions' => $aDisplayTransitions, 'state_name' => $oWorkflowState->getName(), 'comment' => $oLatestTransitionComment)); return $oTemplate->render(); }
function do_main() { $this->oPage->setBreadcrumbDetails(_kt('workflow')); $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/documentWorkflow'); $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']); $oWorkflow = KTWorkflowUtil::getWorkflowForDocument($oDocument); $oWorkflowState = KTWorkflowUtil::getWorkflowStateForDocument($oDocument); $oUser =& User::get($_SESSION['userID']); // If the document is checked out - set transitions and workflows to empty and set checkedout to true $bIsCheckedOut = $this->oDocument->getIsCheckedOut(); if ($bIsCheckedOut) { $aTransitions = array(); $aWorkflows = array(); $transition_fields = array(); $bHasPerm = FALSE; } else { $aTransitions = KTWorkflowUtil::getTransitionsForDocumentUser($oDocument, $oUser); $aWorkflows = KTWorkflow::getList('start_state_id IS NOT NULL AND enabled = 1 '); $bHasPerm = false; if (KTPermissionUtil::userHasPermissionOnItem($oUser, 'ktcore.permissions.workflow', $oDocument)) { $bHasPerm = true; } $fieldErrors = null; $transition_fields = array(); if ($aTransitions) { $aVocab = array(); foreach ($aTransitions as $oTransition) { if (is_null($oTransition) || PEAR::isError($oTransition)) { continue; } $aVocab[$oTransition->getId()] = $oTransition->showDescription(); } $fieldOptions = array('vocab' => $aVocab); $transition_fields[] = new KTLookupWidget(_kt('Transition to perform'), _kt('The transition listed will cause the document to change from its current state to the listed destination state.'), 'fTransitionId', null, $this->oPage, true, null, $fieldErrors, $fieldOptions); $transition_fields[] = new KTTextWidget(_kt('Reason for transition'), _kt('Describe why this document qualifies to be changed from its current state to the destination state of the transition chosen.'), 'fComments', '', $this->oPage, true, null, null, array('cols' => 80, 'rows' => 4)); } } // Add an electronic signature global $default; if ($default->enableESignatures) { $sUrl = KTPluginUtil::getPluginPath('electronic.signatures.plugin', true); $heading = _kt('You are attempting to modify the document workflow'); $submit['type'] = 'button'; $submit['onclick'] = "javascript: showSignatureForm('{$sUrl}', '{$heading}', 'ktcore.transactions.modify_workflow', 'document', 'start_workflow_form', 'submit', {$this->oDocument->iId});"; $heading2 = _kt('You are attempting to transition the document workflow'); $submit2['onclick'] = "javascript: showSignatureForm('{$sUrl}', '{$heading2}', 'ktcore.transactions.transition_workflow', 'document', 'transition_wf_form', 'submit', {$this->oDocument->iId});"; } else { $submit['type'] = 'submit'; $submit['onclick'] = ''; $submit2['onclick'] = ''; } $aTemplateData = array('oDocument' => $oDocument, 'oWorkflow' => $oWorkflow, 'oState' => $oWorkflowState, 'aTransitions' => $aTransitions, 'aWorkflows' => $aWorkflows, 'transition_fields' => $transition_fields, 'bHasPerm' => $bHasPerm, 'bIsCheckedOut' => $bIsCheckedOut, 'submit' => $submit, 'submit2' => $submit2); return $oTemplate->render($aTemplateData); }
/** * This returns the workflow transitions available for the user on the document * * @author KnowledgeTree Team * @access public * @return array|PEAR_Error Array of the workflow transitions | a PEAR_Error on failure */ function get_workflow_transitions() { $user = $this->can_user_access_object_requiring_permission($this->document, KTAPI_PERMISSION_WORKFLOW); if (PEAR::isError($user)) { return $user; } $workflowid = $this->document->getWorkflowId(); if (empty($workflowid)) { return array(); } $result = array(); $transitions = KTWorkflowUtil::getTransitionsForDocumentUser($this->document, $user); if (is_null($transitions) || PEAR::isError($transitions)) { return new KTAPI_Error(KTAPI_ERROR_WORKFLOW_INVALID, $transitions); } foreach ($transitions as $transition) { $result[] = $transition->getName(); } return $result; }