<?php require_once '../../config/dmsDefaults.php'; require_once KT_LIB_DIR . '/documentmanagement/Document.inc'; require_once KT_LIB_DIR . '/workflow/workflow.inc.php'; require_once KT_LIB_DIR . '/workflow/workflowutil.inc.php'; $oDocument =& Document::get(4); $oWorkflow =& KTWorkflow::get(1); $res = KTWorkflowUtil::startWorkflowOnDocument($oWorkflow, $oDocument); if (PEAR::isError($res)) { var_dump($res); }
/** * Gets the workflow that applies to the given document, returning * null if there is no workflow assigned. */ function getWorkflowForDocument($oDocument, $aOptions = null) { $ids = KTUtil::arrayGet($aOptions, 'ids', false); if (is_a($oDocument, 'KTDocumentCore')) { $oDocument = $oDocument->getId(); } $oDocument = KTUtil::getObject('Document', $oDocument); $iWorkflowId = $oDocument->getWorkflowId(); if (PEAR::isError($iWorkflowId)) { return $iWorkflowId; } if (is_null($iWorkflowId)) { return $iWorkflowId; } if ($ids) { return $iWorkflowId; } return KTWorkflow::get($iWorkflowId); }
/** * This returns detailed information on the document. * * @author KnowledgeTree Team * @access public * @return array The document information */ function get_detail() { global $default; // make sure we ge tthe latest $this->clearCache(); $config = KTConfig::getSingleton(); $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION); $detail = array(); $document = $this->document; // get the document id $detail['document_id'] = (int) $document->getId(); $oem_document_no = null; if ($wsversion >= 2) { $oem_document_no = $document->getOemNo(); } if (empty($oem_document_no)) { $oem_document_no = 'n/a'; } $detail['custom_document_no'] = 'n/a'; $detail['oem_document_no'] = $oem_document_no; // get the title $detail['title'] = $document->getName(); // get the document type $documenttypeid = $document->getDocumentTypeID(); $documenttype = '* unknown *'; if (is_numeric($documenttypeid)) { $dt = DocumentType::get($documenttypeid); if (!is_null($dt) && !PEAR::isError($dt)) { $documenttype = $dt->getName(); } } $detail['document_type'] = $documenttype; // get the filename $detail['filename'] = $document->getFilename(); // get the filesize $detail['filesize'] = (int) $document->getFileSize(); // get the folder id $detail['folder_id'] = (int) $document->getFolderID(); // get the creator $userid = $document->getCreatorID(); $username = '******'; if (is_numeric($userid)) { $username = '******'; $user = User::get($userid); if (!is_null($user) && !PEAR::isError($user)) { $username = $user->getName(); } } $detail['created_by'] = $username; // get the creation date $detail['created_date'] = $document->getCreatedDateTime(); // get the checked out user $userid = $document->getCheckedOutUserID(); $username = '******'; if (is_numeric($userid)) { $username = '******'; $user = User::get($userid); if (!is_null($user) && !PEAR::isError($user)) { $username = $user->getName(); } } $detail['checked_out_by'] = $username; // get the checked out date list($major, $minor, $fix) = explode('.', $default->systemVersion); if ($major == 3 && $minor >= 5) { $detail['checked_out_date'] = $document->getCheckedOutDate(); } else { $detail['checked_out_date'] = $detail['modified_date']; } if (is_null($detail['checked_out_date'])) { $detail['checked_out_date'] = 'n/a'; } // get the modified user $userid = $document->getModifiedUserId(); $username = '******'; if (is_numeric($userid)) { $username = '******'; $user = User::get($userid); if (!is_null($user) && !PEAR::isError($user)) { $username = $user->getName(); } } $detail['modified_by'] = $detail['updated_by'] = $username; // get the modified date $detail['updated_date'] = $detail['modified_date'] = $document->getLastModifiedDate(); // get the owner $userid = $document->getOwnerID(); $username = '******'; if (is_numeric($userid)) { $username = '******'; $user = User::get($userid); if (!is_null($user) && !PEAR::isError($user)) { $username = $user->getName(); } } $detail['owned_by'] = $username; // get the version $detail['version'] = $document->getVersion(); if ($wsversion >= 2) { $detail['version'] = (double) $detail['version']; } //might be unset at the bottom in case of old webservice version //make sure we're using the real document for this one $this->document->switchToRealCore(); $detail['linked_document_id'] = $document->getLinkedDocumentId(); $this->document->switchToLinkedCore(); // check immutability $detail['is_immutable'] = (bool) $document->getImmutable(); // check permissions $detail['permissions'] = KTAPI_Document::get_permission_string($document); // get workflow name $workflowid = $document->getWorkflowId(); $workflowname = 'n/a'; if (is_numeric($workflowid)) { $workflow = KTWorkflow::get($workflowid); if (!is_null($workflow) && !PEAR::isError($workflow)) { $workflowname = $workflow->getName(); } } $detail['workflow'] = $workflowname; // get the workflow state $stateid = $document->getWorkflowStateId(); $workflowstate = 'n/a'; if (is_numeric($stateid)) { $state = KTWorkflowState::get($stateid); if (!is_null($state) && !PEAR::isError($state)) { $workflowstate = $state->getName(); } } $detail['workflow_state'] = $workflowstate; // get the full path $detail['full_path'] = '/' . $this->document->getFullPath(); // get mime info $mimetypeid = $document->getMimeTypeID(); $detail['mime_type'] = KTMime::getMimeTypeName($mimetypeid); $detail['mime_icon_path'] = KTMime::getIconPath($mimetypeid); $detail['mime_display'] = KTMime::getFriendlyNameForString($detail['mime_type']); // get the storage path $detail['storage_path'] = $document->getStoragePath(); if ($wsversion >= 2) { unset($detail['updated_by']); unset($detail['updated_date']); } if ($wsversion < 3) { unset($detail['linked_document_id']); } return $detail; }
function do_confirmCopy() { $oSelWorkflow = KTWorkflow::get(KTUtil::arrayGet($_REQUEST, 'workflowId', array())); $sWorkflowName = KTUtil::arrayGet($_REQUEST, 'workflowName', array()); // Check that the workflow does not exist already $sWorkflowName = str_replace(array(' ', ' '), array(' ', ' '), $sWorkflowName); $oWorkflow = KTWorkflow::getByName($sWorkflowName); if (!PEAR::isError($oWorkflow)) { return $this->errorRedirectToMain(_kt("A workflow with that name already exists. Please choose a different name for this workflow.")); } // create the initial workflow $oNewWorkflow = KTWorkflow::createFromArray(array('name' => $sWorkflowName, 'humanname' => $sWorkflowName, 'enabled' => true)); // get selected workflow states from database $oSelWorkflowStates = KTWorkflowState::getByWorkflow($oSelWorkflow); // array to store map of old and new states $aStatesMap = array(); // create new states and build old-to-new map foreach ($oSelWorkflowStates as $oOldState) { $oNewState = KTWorkflowState::createFromArray(array('workflowid' => $oNewWorkflow->getId(), 'name' => $oOldState->getName(), 'humanname' => $oOldState->getName())); $aStatesMap[oldId][] = $oOldState->getId(); $aStatesMap[newId][] = $oNewState->getId(); if (PEAR::isError($oNewState)) { $oForm->errorRedirectToMain(sprintf(_kt("Unexpected failure cloning state: %s"), $oNewState->getMessage())); } // Get all state permission assignments for old workflow transitions // and copy for copied workflow state permission assignments $aPermissionAssignments = KTWorkflowStatePermissionAssignment::getByState($oOldState); if (count($aPermissionAssignments) > 0) { foreach ($aPermissionAssignments as $oPermAssign) { for ($i = 0; $i < count($aStatesMap[oldId]); $i++) { if ($aStatesMap[oldId][$i] == $oPermAssign->getStateId()) { $iStateId = $aStatesMap[newId][$i]; $res = KTWorkflowStatePermissionAssignment::createFromArray(array('iStateId' => $iStateId, 'iPermissionId' => $oPermAssign->getPermissionId(), 'iDescriptorId' => $oPermAssign->getDescriptorId())); if (PEAR::isError($res)) { return $this->errorRedirectToMain(sprintf(_kt("Unable to copy state permission assignment: %s"), $res->getMessage())); } } } } } // Copy all disabled actions for states $aDisabled = KTWorkflowUtil::getDisabledActionsForState($oOldState); $res = KTWorkflowUtil::setDisabledActionsForState($oNewState, $aDisabled); // Copy all enabled actions for states $aDisabled = KTWorkflowUtil::getEnabledActionsForState($oOldState); $res = KTWorkflowUtil::setEnabledActionsForState($oNewState, $aDisabled); if (PEAR::isError($res)) { return $this->errorRedirectToMain(sprintf(_kt("Unable to copy disabled state actions: %s"), $res->getMessage())); } $this->copyStateNotifications($oOldState, $oNewState); } // update workflow and set initial state for ($i = 0; $i < count($aStatesMap[oldId]); $i++) { if ($oSelWorkflow->getStartStateId() == $aStatesMap[oldId][$i]) { $oNewWorkflow->setStartStateId($aStatesMap[newId][$i]); $res = $oNewWorkflow->update(); if (PEAR::isError($res)) { $this->errorRedirectToMain(sprintf(_kt("Failed to update workflow: %s"), $res->getMessage())); } } } // set controlled workflow actions $aWFActions = KTWorkflowUtil::getControlledActionsForWorkflow($oSelWorkflow); $res = KTWorkflowUtil::setControlledActionsForWorkflow($oNewWorkflow, $aWFActions); if (PEAR::isError($res)) { $this->errorRedirectToMain(sprintf(_kt("Failed to copy workflow controlled actions: %s"), $res->getMessage())); } // get selected workflow transitions from database $oSelWorkflowTransitions = KTWorkflowTransition::getByWorkflow($oSelWorkflow); // array to store map of old and new transitions $aTransitionsMap = array(); // copy transitions for workflow foreach ($oSelWorkflowTransitions as $oOldTransition) { for ($i = 0; $i < count($aStatesMap[oldId]); $i++) { if ($oOldTransition->getTargetStateId() == $aStatesMap[oldId][$i]) { $iDestState = $aStatesMap[newId][$i]; } } $oNewTransition = KTWorkflowTransition::createFromArray(array('workflowid' => $oNewWorkflow->getId(), 'Name' => $oOldTransition->getName(), 'HumanName' => $oOldTransition->getName(), 'TargetStateId' => $iDestState, 'GuardPermissionId' => null, 'GuardGroupId' => null, 'GuardRoleId' => null, 'GuardConditionId' => null)); $aTransitionsMap[oldId][] = $oOldTransition->getId(); $aTransitionsMap[newId][] = $oNewTransition->getId(); if (PEAR::isError($oNewTransition)) { $this->errorRedirectToMain(sprintf(_kt("Failed to copy transition: %s"), $oTransition->getMessage())); } // map source transitions onto states $aOldTransitionSources = KTWorkflowAdminUtil::getSourceStates($oOldTransition); $aSourceStates = array(); for ($j = 0; $j < count($aOldTransitionSources); $j++) { for ($i = 0; $i < count($aStatesMap[oldId]); $i++) { if ($aStatesMap[oldId][$i] == $aOldTransitionSources[$j]->getId()) { $aSourceStates[] = $aStatesMap[newId][$i]; continue; } } } $res = KTWorkflowAdminUtil::saveTransitionSources($oNewTransition, $aSourceStates); if (PEAR::isError($res)) { $this->errorRedirectToMain(sprintf(_kt("Failed to set transition origins: %s"), $res->getMessage())); } // Get all triggers for old workflow transitions and // copy for copied workflow transitions $aTriggers = KTWorkflowTriggerInstance::getByTransition($oOldTransition); if (count($aTriggers) > 0) { foreach ($aTriggers as $oTrigger) { for ($i = 0; $i < count($aTransitionsMap[oldId]); $i++) { if ($aTransitionsMap[oldId][$i] == $oTrigger->getTransitionId()) { $iTransitionId = $aTransitionsMap[newId][$i]; $res = KTWorkflowTriggerInstance::createFromArray(array('transitionid' => $iTransitionId, 'namespace' => $oTrigger->getNamespace(), 'config' => $oTrigger->getConfigArrayText())); if (PEAR::isError($res)) { return $this->errorRedirectToMain(sprintf(_kt("Unable to add trigger: %s"), $res->getMessage())); } } } } } } return $this->successRedirectToMain(sprintf(_kt("%s successfully copied as %s"), $oSelWorkflow->getName(), $oNewWorkflow->getName())); }
/** * Create a table of the document metadata. * Hard coded for the moment * * @return unknown */ function getMetadata() { /* Get document info */ // Filename $sFilenameLb = _kt('Document Filename: '); $sFilename = $this->_oDocument->getFileName(); // Mime type $sMimeTypeLb = _kt('File is a: '); $iMimeId = $this->_oDocument->getMimeTypeID(); $sMimeType = KTMime::getMimeTypeName($iMimeId); $sMimeType = KTMime::getFriendlyNameForString($sMimeType); // Version $sVersionLb = _kt('Document Version: '); $iVersion = $this->_oDocument->getVersion(); // Created by $sCreatedByLb = _kt('Created by: '); $iCreatorId = $this->_oDocument->getCreatorID(); $sCreated = $this->_oDocument->getCreatedDateTime(); $oCreator = User::get($iCreatorId); $sCreatedBy = $oCreator->getName() . ' (' . $sCreated . ')'; // Owned by $sOwnedByLb = _kt('Owned by: '); $iOwnedId = $this->_oDocument->getOwnerID(); $oOwner = User::get($iOwnedId); $sOwnedBy = $oOwner->getName(); // Last update by $iModifiedId = $this->_oDocument->getModifiedUserId(); $sLastUpdatedByLb = ''; $sLastUpdatedBy = ''; if (!empty($iModifiedId)) { $sLastUpdatedByLb = _kt('Last updated by: '); $sModified = $this->_oDocument->getLastModifiedDate(); $oModifier = User::get($iModifiedId); $sLastUpdatedBy = $oModifier->getName() . ' (' . $sModified . ')'; } // Document type $sDocTypeLb = _kt('Document Type: '); $iDocTypeId = $this->_oDocument->getDocumentTypeID(); $oDocType = DocumentType::get($iDocTypeId); $sDocType = $oDocType->getName(); // Workflow $iWFId = $this->_oDocument->getWorkflowId(); $sWF = ''; $sWFLb = ''; if (!empty($iWFId)) { $sWFLb = _kt('Workflow: '); $iWFStateId = $this->_oDocument->getWorkflowStateId(); $oWF = KTWorkflow::get($iWFId); $sWF = $oWF->getHumanName(); $oWFState = KTWorkflowState::get($iWFStateId); $sWF .= ' (' . $oWFState->getHumanName() . ')'; } // Checked out by $sCheckedLb = ''; $sCheckedOutBy = ''; if ($this->_oDocument->getIsCheckedOut()) { $sCheckedLb = _kt('Checked out by: '); $iCheckedID = $this->_oDocument->getCheckedOutUserID(); $oCheckedUser = User::get($iCheckedID); $sCheckedOutBy = $oCheckedUser->getName(); } // Id $sIdLb = _kt('Document ID: '); $sId = $this->_IDocId; /* Create table */ $sInfo = "<div style='float:left; width:405px;'>\n <table cellspacing='3px' cellpadding='3px' width='405px'>\n <tr><td>{$sFilenameLb}</td><td><b>{$sFilename}</b></td></tr>\n <tr><td>{$sMimeTypeLb}</td><td><b>{$sMimeType}</b></td></tr>\n <tr><td>{$sVersionLb}</td><td><b>{$iVersion}</b></td></tr>\n <tr><td>{$sCreatedByLb}</td><td><b>{$sCreatedBy}</b></td></tr>\n <tr><td>{$sOwnedByLb}</td><td><b>{$sOwnedBy}</b></td></tr>"; if (!empty($sLastUpdatedBy)) { $sInfo .= "<tr><td>{$sLastUpdatedByLb}</td><td><b>{$sLastUpdatedBy}</b></td></tr>"; } $sInfo .= "<tr><td>{$sDocTypeLb}</td><td><b>{$sDocType}</b></td></tr>"; if (!empty($sWF)) { $sInfo .= "<tr><td>{$sWFLb}</td><td><b>{$sWF}</b></td></tr>"; } if (!empty($sCheckedOutBy)) { $sInfo .= "<tr><td>{$sCheckedLb}</td><td><b>{$sCheckedOutBy}</b></td></tr>"; } $sInfo .= "<tr><td>{$sIdLb}</td><td><b>{$sId}</b></td></tr>"; $sInfo .= " </table></div>"; return $sInfo; }
function getWorkflowForDoc($oDocument) { $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('folder_workflow_map'); $sQuery .= ' WHERE `folder_id` = ?'; $aParams = array($oDocument->getFolderID()); $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'workflow_id'); if (PEAR::isError($res) || is_null($res)) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); // don't remove if moved out. } return KTWorkflow::get($res); }
function &getByDocument($oDocument) { $oDocument = KTUtil::getObject('Document', $oDocument); $iWorkflowId = $oDocument->getWorkflowId(); if (PEAR::isError($iWorkflowId)) { return $iWorkflowId; } if (is_null($iWorkflowId)) { return $iWorkflowId; } return KTWorkflow::get($iWorkflowId); }
function getWorkflowForType($iDocTypeId, $oDocument) { if (is_null($iDocTypeId)) { return null; } // Link to the workflows table to ensure disabled workflows aren't associated $sQuery = 'SELECT `workflow_id` FROM ' . KTUtil::getTableName('type_workflow_map') . ' m'; $sQuery .= ' LEFT JOIN workflows w ON w.id = m.workflow_id WHERE document_type_id = ? AND w.enabled = 1'; $aParams = array($iDocTypeId); $res = DBUtil::getOneResultKey(array($sQuery, $aParams), 'workflow_id'); if (PEAR::isError($res) || is_null($res)) { return KTWorkflowUtil::getWorkflowForDocument($oDocument); // don't remove if type changed out. } return KTWorkflow::get($res); }