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);
 }
示例#2
0
 function renderData($aDataRow)
 {
     // only _ever_ show this for documents.
     if ($aDataRow["type"] === "folder") {
         return ' ';
     }
     $oWorkflow = KTWorkflowUtil::getWorkflowForDocument($aDataRow['document']);
     $oState = KTWorkflowUtil::getWorkflowStateForDocument($aDataRow['document']);
     if ($oState == null || $oWorkflow == null) {
         return '—';
     } else {
         return sprintf('%s <span class="descriptive">%s</span>', htmlentities($oState->getName(), ENT_NOQUOTES, 'UTF-8'), htmlentities($oWorkflow->getName(), ENT_NOQUOTES, 'UTF-8'));
     }
 }
 function renderData($aDataRow)
 {
     $localname = $this->name;
     // only _ever_ show this folder documents.
     if ($aDataRow['type'] === 'folder') {
         return '&nbsp;';
     }
     $oWorkflow = KTWorkflowUtil::getWorkflowForDocument($aDataRow['document']);
     $oState = KTWorkflowUtil::getWorkflowStateForDocument($aDataRow['document']);
     if ($oState == null || $oWorkflow == null) {
         return '&mdash;';
     } else {
         return $oState->getName() . ' <span class="descriptiveText">(' . $oWorkflow->getName() . ')</span>';
     }
 }
示例#4
0
 /**
  * Get's a folder listing, recursing to the maximum depth.
  * Derived from the get_listing function.
  *
  * <code>
  * $root = $this->ktapi->get_root_folder();
  * $listing = $root->get_full_listing();
  * foreach($listing as $val) {
  * 	if($val['item_type'] == 'F') {
  *   // It's a folder
  *   echo $val['title'];
  *  }
  * }
  * </code>
  *
  * @author KnowledgeTree Team
  * @access public
  * @param string $what
  * @return array
  */
 function get_full_listing($what = 'DFS')
 {
     $what = strtoupper($what);
     $read_permission =& KTPermission::getByName(KTAPI_PERMISSION_READ);
     $folder_permission =& KTPermission::getByName(KTAPI_PERMISSION_VIEW_FOLDER);
     $config = KTConfig::getSingleton();
     $wsversion = $config->get('webservice/version', LATEST_WEBSERVICE_VERSION);
     $user = $this->ktapi->get_user();
     $contents = array();
     if (strpos($what, 'F') !== false) {
         $folder_children = Folder::getList(array('parent_id = ?', $this->folderid));
         foreach ($folder_children as $folder) {
             if (KTPermissionUtil::userHasPermissionOnItem($user, $folder_permission, $folder) || KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $folder)) {
                 $sub_folder =& $this->ktapi->get_folder_by_id($folder->getId());
                 if (!PEAR::isError($sub_folder)) {
                     $items = $sub_folder->get_full_listing($what);
                 } else {
                     $items = array();
                 }
                 $creator = $this->_resolve_user($folder->getCreatorID());
                 if ($wsversion >= 2) {
                     $array = array('id' => (int) $folder->getId(), 'item_type' => 'F', 'custom_document_no' => 'n/a', 'oem_document_no' => 'n/a', 'title' => $folder->getName(), 'document_type' => 'n/a', 'filename' => $folder->getName(), 'filesize' => 'n/a', 'created_by' => is_null($creator) ? 'n/a' : $creator->getName(), 'created_date' => 'n/a', 'checked_out_by' => 'n/a', 'checked_out_date' => 'n/a', 'modified_by' => 'n/a', 'modified_date' => 'n/a', 'owned_by' => 'n/a', 'version' => 'n/a', 'is_immutable' => 'n/a', 'permissions' => KTAPI_Folder::get_permission_string($folder), 'workflow' => 'n/a', 'workflow_state' => 'n/a', 'mime_type' => 'folder', 'mime_icon_path' => 'folder', 'mime_display' => 'Folder', 'storage_path' => 'n/a');
                     if ($wsversion >= 3) {
                         $array['linked_folder_id'] = $folder->getLinkedFolderId();
                         if ($folder->isSymbolicLink()) {
                             $array['item_type'] = "S";
                         }
                     }
                     $array['items'] = $items;
                     if ($wsversion < 3 || strpos($what, 'F') !== false && !$folder->isSymbolicLink() || $folder->isSymbolicLink() && strpos($what, 'S') !== false) {
                         $contents[] = $array;
                     }
                 } else {
                     $contents[] = array('id' => (int) $folder->getId(), 'item_type' => 'F', 'title' => $folder->getName(), 'creator' => is_null($creator) ? 'n/a' : $creator->getName(), 'checkedoutby' => 'n/a', 'modifiedby' => 'n/a', 'filename' => $folder->getName(), 'size' => 'n/a', 'major_version' => 'n/a', 'minor_version' => 'n/a', 'storage_path' => 'n/a', 'mime_type' => 'folder', 'mime_icon_path' => 'folder', 'mime_display' => 'Folder', 'items' => $items, 'workflow' => 'n/a', 'workflow_state' => 'n/a');
                 }
             }
         }
     }
     if (strpos($what, 'D') !== false) {
         $document_children = Document::getList(array('folder_id = ? AND status_id = 1', $this->folderid));
         // I hate that KT doesn't cache things nicely...
         $mime_cache = array();
         foreach ($document_children as $document) {
             if (KTPermissionUtil::userHasPermissionOnItem($user, $read_permission, $document)) {
                 $created_by = $this->_resolve_user($document->getCreatorID());
                 $created_date = $document->getCreatedDateTime();
                 if (empty($created_date)) {
                     $created_date = 'n/a';
                 }
                 $checked_out_by = $this->_resolve_user($document->getCheckedOutUserID());
                 $checked_out_date = $document->getCheckedOutDate();
                 if (empty($checked_out_date)) {
                     $checked_out_date = 'n/a';
                 }
                 $modified_by = $this->_resolve_user($document->getCreatorID());
                 $modified_date = $document->getLastModifiedDate();
                 if (empty($modified_date)) {
                     $modified_date = 'n/a';
                 }
                 $owned_by = $this->_resolve_user($document->getOwnerID());
                 $mimetypeid = $document->getMimeTypeID();
                 if (!array_key_exists($mimetypeid, $mime_cache)) {
                     $type = KTMime::getMimeTypeName($mimetypeid);
                     $icon = KTMime::getIconPath($mimetypeid);
                     $display = KTMime::getFriendlyNameForString($type);
                     $mime_cache[$mimetypeid] = array('type' => $type, 'icon' => $icon, 'display' => $display);
                 }
                 $mimeinfo = $mime_cache[$mimetypeid];
                 $workflow = 'n/a';
                 $state = 'n/a';
                 $wf = KTWorkflowUtil::getWorkflowForDocument($document);
                 if (!is_null($wf) && !PEAR::isError($wf)) {
                     $workflow = $wf->getHumanName();
                     $ws = KTWorkflowUtil::getWorkflowStateForDocument($document);
                     if (!is_null($ws) && !PEAR::isError($ws)) {
                         $state = $ws->getHumanName();
                     }
                 }
                 if ($wsversion >= 2) {
                     $docTypeId = $document->getDocumentTypeID();
                     $documentType = DocumentType::get($docTypeId);
                     $oemDocumentNo = $document->getOemNo();
                     if (empty($oemDocumentNo)) {
                         $oemDocumentNo = 'n/a';
                     }
                     $array = array('id' => (int) $document->getId(), 'item_type' => 'D', 'custom_document_no' => 'n/a', 'oem_document_no' => $oemDocumentNo, 'title' => $document->getName(), 'document_type' => $documentType->getName(), 'filename' => $document->getFileName(), 'filesize' => $document->getFileSize(), 'created_by' => is_null($created_by) ? 'n/a' : $created_by->getName(), 'created_date' => $created_date, 'checked_out_by' => is_null($checked_out_by) ? 'n/a' : $checked_out_by->getName(), 'checked_out_date' => $checked_out_date, 'modified_by' => is_null($modified_by) ? 'n/a' : $modified_by->getName(), 'modified_date' => $modified_date, 'owned_by' => is_null($owned_by) ? 'n/a' : $owned_by->getName(), 'version' => $document->getMajorVersionNumber() . '.' . $document->getMinorVersionNumber(), 'content_id' => $document->getContentVersionId(), 'is_immutable' => $document->getImmutable() ? 'true' : 'false', 'permissions' => KTAPI_Document::get_permission_string($document), 'workflow' => $workflow, 'workflow_state' => $state, 'mime_type' => $mime_cache[$mimetypeid]['type'], 'mime_icon_path' => $mime_cache[$mimetypeid]['icon'], 'mime_display' => $mime_cache[$mimetypeid]['display'], 'storage_path' => $document->getStoragePath());
                     if ($wsversion >= 3) {
                         $document->switchToRealCore();
                         $array['linked_document_id'] = $document->getLinkedDocumentId();
                         $document->switchToLinkedCore();
                         if ($document->isSymbolicLink()) {
                             $array['item_type'] = "S";
                         }
                     }
                     $array['items'] = array();
                     if ($wsversion < 3 || strpos($what, 'D') !== false && !$document->isSymbolicLink() || $document->isSymbolicLink() && strpos($what, 'S') !== false) {
                         $contents[] = $array;
                     }
                 } else {
                     $contents[] = array('id' => (int) $document->getId(), 'item_type' => 'D', 'title' => $document->getName(), 'creator' => is_null($created_by) ? 'n/a' : $created_by->getName(), 'checkedoutby' => is_null($checked_out_by) ? 'n/a' : $checked_out_by->getName(), 'modifiedby' => is_null($modified_by) ? 'n/a' : $modified_by->getName(), 'filename' => $document->getFileName(), 'size' => $document->getFileSize(), 'major_version' => $document->getMajorVersionNumber(), 'minor_version' => $document->getMinorVersionNumber(), 'storage_path' => $document->getStoragePath(), 'mime_type' => $mime_cache[$mimetypeid]['type'], 'mime_icon_path' => $mime_cache[$mimetypeid]['icon'], 'mime_display' => $mime_cache[$mimetypeid]['display'], 'items' => array(), 'workflow' => $workflow, 'workflow_state' => $state);
                 }
             }
         }
     }
     return $contents;
 }
示例#5
0
 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);
 }
示例#6
0
 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);
 }
 function renderComparison($aDocumentData, $aComparisonData)
 {
     // we do a fair bit of fetching, etc. in here.
     $document = $aDocumentData['document'];
     $comparison_document = $aComparisonData['document'];
     // creation
     $creator =& User::get($document->getCreatorId());
     if (PEAR::isError($creator)) {
         $creator = '<span class="ktError">' . _kt("Unable to find the document's creator") . '</span>';
     } else {
         $creator = $creator->getName();
     }
     $creation_date = $this->_dateHelper($document->getCreatedDateTime());
     // last mod
     $last_modified_date = $this->_dateHelper($document->getVersionCreated());
     $comparison_last_modified_date = $this->_dateHelper($comparison_document->getVersionCreated());
     // document type // FIXME move this to view.php
     $document_type = $aDocumentData['document_type']->getName();
     $comparison_document_type = $aComparisonData['document_type']->getName();
     $modified_user =& User::get($document->getVersionCreatorId());
     if (PEAR::isError($modified_user)) {
         $modified_user = "******" . _kt("Unable to find the document's modifier") . '</span>';
     } else {
         $modified_user = $modified_user->getName();
     }
     $owner_user =& User::get($document->getOwnerId());
     if (PEAR::isError($owner_user)) {
         $owner_user = "******" . _kt("Unable to find the document's owner") . '</span>';
     } else {
         $owner_user = $owner_user->getName();
     }
     $comparison_modified_user =& User::get($comparison_document->getVersionCreatorId());
     if (PEAR::isError($comparison_modified_user)) {
         $comparison_modified_user = "******" . _kt("Unable to find the document's modifier") . '</span>';
     } else {
         $comparison_modified_user = $comparison_modified_user->getName();
     }
     $oWorkflow = KTWorkflowUtil::getWorkflowForDocument($document);
     $oState = KTWorkflowUtil::getWorkflowStateForDocument($document);
     $oComparisonWorkflow = KTWorkflowUtil::getWorkflowForDocument($comparison_document);
     $oComparisonState = KTWorkflowUtil::getWorkflowStateForDocument($comparison_document);
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate('kt3/fieldsets/generic_versioned');
     $aTemplateData = array('context' => $this, 'document_data' => $aDocumentData, 'document' => $aDocumentData['document'], 'title' => $document->getName(), 'comparison_title' => $comparison_document->getName(), 'filename' => $document->getFileName(), 'comparison_filename' => $comparison_document->getFileName(), 'creator' => $creator, 'creation_date' => $creation_date, 'owner' => $owner_user, 'last_modified_by' => $modified_user, 'last_modified_date' => $last_modified_date, 'comparison_last_modified_by' => $comparison_modified_user, 'comparison_last_modified_date' => $comparison_last_modified_date, 'document_type' => $document_type, 'comparison_document_type' => $comparison_document_type, 'workflow_state' => $oState, 'comparison_workflow_state' => $oComparisonState, 'workflow' => $oWorkflow, 'comparison_workflow' => $oComparisonWorkflow, 'comparison_document' => $aComparisonData['document']);
     return $oTemplate->render($aTemplateData);
 }
 function copyTrigger($oDocument)
 {
     return KTWorkflowUtil::getWorkflowForDocument($oDocument);
 }