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();
 }
Example #2
0
 function perform_action($oEntity)
 {
     // checkout document
     $sReason = $this->sReason;
     if (is_a($oEntity, 'Document')) {
         if ($oEntity->getImmutable()) {
             return PEAR::raiseError($oEntity->getName() . ': ' . _kt('Document cannot be checked out as it is immutable'));
         }
         if ($oEntity->getIsCheckedOut()) {
             $checkedOutUser = $oEntity->getCheckedOutUserID();
             $sUserId = $_SESSION['userID'];
             if ($checkedOutUser != $sUserId) {
                 $oCheckedOutUser = User::get($checkedOutUser);
                 return PEAR::raiseError($oEntity->getName() . ': ' . _kt('Document has already been checked out by ') . $oCheckedOutUser->getName());
             }
         } else {
             $res = KTDocumentUtil::checkout($oEntity, $sReason, $this->oUser);
             if (PEAR::isError($res)) {
                 return PEAR::raiseError($oEntity->getName() . ': ' . $res->getMessage());
             }
         }
         if ($this->bDownload) {
             if ($this->bNoisy) {
                 $oDocumentTransaction = new DocumentTransaction($oEntity, "Document part of bulk checkout", 'ktstandard.transactions.check_out', array());
                 $oDocumentTransaction->create();
             }
             $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
             $aTriggers = $oKTTriggerRegistry->getTriggers('checkoutDownload', 'postValidate');
             foreach ($aTriggers as $aTrigger) {
                 $sTrigger = $aTrigger[0];
                 $oTrigger = new $sTrigger();
                 $aInfo = array('document' => $oEntity);
                 $oTrigger->setInfo($aInfo);
                 $ret = $oTrigger->postValidate();
                 if (PEAR::isError($ret)) {
                     return $ret;
                 }
             }
             $this->oZip->addDocumentToZip($oEntity);
         }
     } else {
         if (is_a($oEntity, 'Folder')) {
             // get documents and subfolders
             $aDocuments = array();
             $oFolder = $oEntity;
             if ($oFolder->isSymbolicLink()) {
                 $oFolder = $oFolder->getLinkedFolder();
             }
             $sFolderId = $oFolder->getId();
             $sFolderDocs = $oFolder->getDocumentIDs($sFolderId);
             // get documents directly in the folder
             if (!empty($sFolderDocs)) {
                 $aDocuments = explode(',', $sFolderDocs);
             }
             // Get all the folders within the current folder
             $sWhereClause = "parent_folder_ids = '{$sFolderId}' OR\n            parent_folder_ids LIKE '{$sFolderId},%' OR\n            parent_folder_ids LIKE '%,{$sFolderId},%' OR\n            parent_folder_ids LIKE '%,{$sFolderId}'";
             $aFolderList = $this->oFolder->getList($sWhereClause);
             $aLinkingFolders = $this->getLinkingEntities($aFolderList);
             $aFolderList = array_merge($aFolderList, $aLinkingFolders);
             $aFolderObjects = array();
             $aFolderObjects[$sFolderId] = $oFolder;
             // Get the documents within the folder
             if (!empty($aFolderList)) {
                 foreach ($aFolderList as $k => $oFolderItem) {
                     if (Permission::userHasFolderReadPermission($oFolderItem)) {
                         // Get documents for each folder
                         if ($oFolderItem->isSymbolicLink()) {
                             $oFolderItem = $oFolderItem->getLinkedFolder();
                         }
                         $sFolderItemId = $oFolderItem->getID();
                         $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId);
                         if (!empty($sFolderItemDocs)) {
                             $aFolderDocs = explode(',', $sFolderItemDocs);
                             $aDocuments = array_merge($aDocuments, $aFolderDocs);
                         }
                         // Add the folder to the zip file
                         if ($this->bDownload) {
                             $this->oZip->addFolderToZip($oFolderItem);
                             $aFolderObjects[$oFolderItem->getId()] = $oFolderItem;
                         }
                     }
                 }
             }
             // Checkout each document within the folder structure
             if (!empty($aDocuments)) {
                 foreach ($aDocuments as $sDocId) {
                     $oDocument = Document::get($sDocId);
                     if (PEAR::isError($oDocument)) {
                         // add message, skip document and continue
                         $this->addErrorMessage($oDocument->getName() . ': ' . $oDocument->getMessage());
                         continue;
                     }
                     if ($oDocument->isSymbolicLink()) {
                         $oDocument->switchToLinkedCore();
                     }
                     if ($oDocument->getImmutable()) {
                         $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document cannot be checked out as it is immutable'));
                         continue;
                     }
                     // Check if the action is restricted by workflow on the document
                     if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.checkout')) {
                         $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Checkout is restricted by the workflow state.'));
                         continue;
                     }
                     // Check if document is already checked out, check the owner.
                     // If the current user is the owner, then include to the download, otherwise ignore.
                     if ($oDocument->getIsCheckedOut()) {
                         $checkedOutUser = $oDocument->getCheckedOutUserID();
                         $sUserId = $_SESSION['userID'];
                         if ($checkedOutUser != $sUserId) {
                             $oCheckedOutUser = User::get($checkedOutUser);
                             $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document has already been checked out by ') . $oCheckedOutUser->getName());
                             continue;
                         }
                     } else {
                         // Check out document
                         $res = KTDocumentUtil::checkout($oDocument, $sReason, $this->oUser);
                         if (PEAR::isError($res)) {
                             $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document could not be checked out. ') . $res->getMessage());
                             continue;
                         }
                     }
                     // Add document to the zip file
                     if ($this->bDownload) {
                         if ($this->bNoisy) {
                             $oDocumentTransaction = new DocumentTransaction($oDocument, 'Document part of bulk checkout', 'ktstandard.transactions.check_out', array());
                             $oDocumentTransaction->create();
                         }
                         $oKTTriggerRegistry = KTTriggerRegistry::getSingleton();
                         $aTriggers = $oKTTriggerRegistry->getTriggers('checkoutDownload', 'postValidate');
                         foreach ($aTriggers as $aTrigger) {
                             $sTrigger = $aTrigger[0];
                             $oTrigger = new $sTrigger();
                             $aInfo = array('document' => $oDocument);
                             $oTrigger->setInfo($aInfo);
                             $ret = $oTrigger->postValidate();
                             if (PEAR::isError($ret)) {
                                 return $ret;
                             }
                         }
                         $sDocFolderId = $oDocument->getFolderID();
                         $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId);
                         $this->oZip->addDocumentToZip($oDocument, $oFolder);
                     }
                 }
             }
         }
     }
     return true;
 }
Example #3
0
 function do_savenotifications()
 {
     $oForm = $this->form_editnotifications($this->oState);
     $res = $oForm->validate();
     if (!empty($res['errors'])) {
         return $oForm->handleError();
     }
     $data = $res['results'];
     // now, an annoying problem is that we do *not* have the final set.
     // so we need to get the original, add the new ones, remove the old ones.
     //
     // because its not *really* isolated properly, we need to post-process
     // the data.
     // we need the old one
     $aAllowed = KTWorkflowUtil::getInformedForState($this->oState);
     $user_pattern = '|users\\[(.*)\\]|';
     $group_pattern = '|groups\\[(.*)\\]|';
     $role_pattern = '|roles\\[(.*)\\]|';
     $user = KTUtil::arrayGet($aAllowed, 'user', array());
     $group = KTUtil::arrayGet($aAllowed, 'group', array());
     $role = KTUtil::arrayGet($aAllowed, 'role', array());
     // do a quick overpass
     $newAllowed = array();
     if (!empty($user)) {
         $newAllowed['user'] = array_combine($user, $user);
     } else {
         $newAllowed['user'] = array();
     }
     if (!empty($group)) {
         $newAllowed['group'] = array_combine($group, $group);
     } else {
         $newAllowed['group'] = array();
     }
     if (!empty($role)) {
         $newAllowed['role'] = array_combine($role, $role);
     } else {
         $newAllowed['role'] = array();
     }
     $added = explode(',', $data['users']['added']);
     $removed = explode(',', $data['users']['removed']);
     foreach ($added as $akey) {
         $matches = array();
         if (preg_match($user_pattern, $akey, $matches)) {
             $newAllowed['user'][$matches[1]] = $matches[1];
         } else {
             if (preg_match($group_pattern, $akey, $matches)) {
                 $newAllowed['group'][$matches[1]] = $matches[1];
             } else {
                 if (preg_match($role_pattern, $akey, $matches)) {
                     $newAllowed['role'][$matches[1]] = $matches[1];
                 }
             }
         }
     }
     foreach ($removed as $akey) {
         $matches = array();
         if (preg_match($user_pattern, $akey, $matches)) {
             unset($newAllowed['user'][$matches[1]]);
         } else {
             if (preg_match($group_pattern, $akey, $matches)) {
                 unset($newAllowed['group'][$matches[1]]);
             } else {
                 if (preg_match($role_pattern, $akey, $matches)) {
                     unset($newAllowed['role'][$matches[1]]);
                 }
             }
         }
     }
     // FIXME check that these are all users.
     $res = KTWorkflowUtil::setInformedForState($this->oState, $newAllowed);
     if (PEAR::isError($res)) {
         return $oForm->handleError($res->getMessage());
     }
     $this->successRedirectTo("managenotifications", _kt("Notifications updated."));
 }
    function do_main()
    {
        $config = KTConfig::getSingleton();
        $useQueue = $config->get('export/useDownloadQueue', true);
        // Create the export code
        $exportCode = KTUtil::randomString();
        $this->oZip = new ZipFolder('', $exportCode);
        if (!$this->oZip->checkConvertEncoding()) {
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        $bNoisy = $config->get("tweaks/noisyBulkOperations");
        $bNotifications = $config->get('export/enablenotifications', 'on') == 'on' ? true : false;
        $sCurrentFolderId = $this->oFolder->getId();
        $url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $sCurrentFolderId, $exportCode));
        $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder);
        if ($useQueue) {
            DownloadQueue::addItem($exportCode, $sCurrentFolderId, $sCurrentFolderId, 'folder');
            $task_url = KTUtil::kt_url() . '/bin/ajaxtasks/downloadTask.php';
            $oTemplating =& KTTemplating::getSingleton();
            $oTemplate = $oTemplating->loadTemplate('ktcore/action/bulk_download');
            $aParams = array('folder_url' => $folderurl, 'url' => $task_url, 'code' => $exportCode, 'download_url' => $url);
            return $oTemplate->render($aParams);
        }
        // Get all folders and sub-folders
        $sWhereClause = "parent_folder_ids = '{$sCurrentFolderId}' OR\n        parent_folder_ids LIKE '{$sCurrentFolderId},%' OR\n        parent_folder_ids LIKE '%,{$sCurrentFolderId},%' OR\n        parent_folder_ids LIKE '%,{$sCurrentFolderId}'";
        $aFolderList = $this->oFolder->getList($sWhereClause);
        // Get any folder shortcuts within the folders
        $aLinkedFolders = KTBulkAction::getLinkingEntities($aFolderList);
        $aFolderList = array_merge($aFolderList, $aLinkedFolders);
        // Add the folders to the zip file
        $aFolderObjects = array($sCurrentFolderId => $this->oFolder);
        if (!empty($aFolderList)) {
            foreach ($aFolderList as $oFolderItem) {
                $itemId = $oFolderItem->getId();
                $linkedFolder = $oFolderItem->getLinkedFolderId();
                // If the folder has been added or is a shortcut then skip
                // The shortcut folders don't need to be added as their targets will be added.
                if (array_key_exists($itemId, $aFolderObjects) || !empty($linkedFolder)) {
                    continue;
                }
                $this->oZip->addFolderToZip($oFolderItem);
                $aFolderObjects[$oFolderItem->getId()] = $oFolderItem;
            }
        }
        // Get the list of folder ids
        $aFolderIds = array_keys($aFolderObjects);
        // Get all documents in the folder list
        $aQuery = $this->buildQuery($aFolderIds);
        $aDocumentIds = DBUtil::getResultArrayKey($aQuery, 'id');
        if (PEAR::isError($aDocumentIds)) {
            $this->addErrorMessage(_kt('There was a problem exporting the documents: ') . $aDocumentIds->getMessage());
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        // Redirect if there are no documents and no folders to export
        if (empty($aDocumentIds) && empty($aFolderList)) {
            $this->addErrorMessage(_kt("No documents found to export"));
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        $this->oPage->template = "kt3/minimal_page";
        $this->handleOutput("");
        // Add the documents to the zip file
        if (!empty($aDocumentIds)) {
            foreach ($aDocumentIds as $iId) {
                $oDocument = Document::get($iId);
                $sFolderId = $oDocument->getFolderID();
                if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')) {
                    $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document cannot be exported as it is restricted by the workflow.'));
                    continue;
                }
                $oFolder = isset($aFolderObjects[$sFolderId]) ? $aFolderObjects[$sFolderId] : Folder::get($sFolderId);
                if ($bNoisy) {
                    $oDocumentTransaction =& new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
                    $oDocumentTransaction->create();
                }
                // fire subscription alerts for the downloaded document
                if ($bNotifications) {
                    //$oSubscriptionEvent = new SubscriptionEvent();
                    //$oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
                }
                $this->oZip->addDocumentToZip($oDocument, $oFolder);
            }
        }
        $sExportCode = $this->oZip->createZipFile(TRUE);
        $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => "Bulk export", 'transactionNS' => 'ktstandard.transactions.bulk_export', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP()));
        $sReturn = '<p>' . _kt('Creating zip file. Compressing and archiving in progress ...') . '</p>';
        $sReturn .= "<p style='margin-bottom: 10px;'><br /><b>" . _kt('Warning! Please wait for archiving to complete before closing the page.') . '</b><br />' . _kt('Note: Closing the page before the download link displays will cancel your Bulk Download.') . '</p>';
        $sReturn .= '<p>' . _kt('Once your download is complete, click <a href="' . $folderurl . '">here</a> to return to the original folder') . "</p>\n";
        print $sReturn;
        printf("</div></div></body></html>\n");
        printf('<script language="JavaScript">
                function kt_bulkexport_redirect() {
                    document.location.href = "%s";
                }
                callLater(2, kt_bulkexport_redirect);

                </script>', $url);
        exit(0);
    }
 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);
 }
<?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);
}
 /**
  * Add a folder to the archive
  *
  * @param unknown_type $zip
  * @param unknown_type $folderId
  * @return unknown
  */
 public function addFolder(&$zip, $folderId)
 {
     $oFolder = Folder::get($folderId);
     if (PEAR::isError($oFolder)) {
         $this->errors[] = _kt('Folder cannot be exported, an error occurred: ') . $oFolder->getMessage();
         return $oFolder;
     }
     $sFolderDocs = $oFolder->getDocumentIDs($folderId);
     if (PEAR::isError($sFolderDocs)) {
         $default->log->error('Download Queue: get document ids for folder caused an error: ' . $sFolderDocs->getMessage());
         $sFolderDocs = '';
     }
     // Add folder to zip
     $zip->addFolderToZip($oFolder);
     $aDocuments = array();
     if (!empty($sFolderDocs)) {
         $aDocuments = explode(',', $sFolderDocs);
     }
     // Get all the folders within the current folder
     $sWhereClause = "parent_folder_ids like '%,{$folderId}'\n            OR parent_folder_ids like '%,{$folderId},%'\n            OR parent_folder_ids like '{$folderId},%'\n            OR parent_id = {$folderId}";
     $aFolderList = $oFolder->getList($sWhereClause);
     $aLinkingFolders = $this->getLinkingEntities($aFolderList);
     $aFolderList = array_merge($aFolderList, $aLinkingFolders);
     $aFolderObjects = array();
     $aFolderObjects[$folderId] = $oFolder;
     // Export the folder structure to ensure the export of empty directories
     if (!empty($aFolderList)) {
         foreach ($aFolderList as $k => $oFolderItem) {
             if ($oFolderItem->isSymbolicLink()) {
                 $oFolderItem = $oFolderItem->getLinkedFolder();
             }
             if (Permission::userHasFolderReadPermission($oFolderItem)) {
                 // Get documents for each folder
                 $sFolderItemId = $oFolderItem->getID();
                 $sFolderItemDocs = $oFolderItem->getDocumentIDs($sFolderItemId);
                 if (!empty($sFolderItemDocs)) {
                     $aFolderDocs = explode(',', $sFolderItemDocs);
                     $aDocuments = array_merge($aDocuments, $aFolderDocs);
                 }
                 $zip->addFolderToZip($oFolderItem);
                 $aFolderObjects[$oFolderItem->getId()] = $oFolderItem;
             }
         }
     }
     // Add all documents to the export
     if (!empty($aDocuments)) {
         foreach ($aDocuments as $sDocumentId) {
             $oDocument = Document::get($sDocumentId);
             if ($oDocument->isSymbolicLink()) {
                 $oDocument->switchToLinkedCore();
             }
             if (Permission::userHasDocumentReadPermission($oDocument)) {
                 if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')) {
                     $this->errors[] = $oDocument->getName() . ': ' . _kt('Document cannot be exported as it is restricted by the workflow.');
                     continue;
                 }
                 $sDocFolderId = $oDocument->getFolderID();
                 $oFolder = isset($aFolderObjects[$sDocFolderId]) ? $aFolderObjects[$sDocFolderId] : Folder::get($sDocFolderId);
                 if ($this->bNoisy) {
                     $oDocumentTransaction = new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
                     $oDocumentTransaction->create();
                 }
                 // fire subscription alerts for the downloaded document
                 if ($this->bNotifications) {
                     $oSubscriptionEvent = new SubscriptionEvent();
                     $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
                 }
                 $zip->addDocumentToZip($oDocument, $oFolder);
             }
         }
     }
 }
 /**
  * Update's the permission lookup on one folder or document,
  * non-recursively.
  */
 function updatePermissionLookup(&$oFolderOrDocument, $aOptions = null)
 {
     $is_a_folder = is_a($oFolderOrDocument, 'Folder');
     $is_a_document = is_a($oFolderOrDocument, 'Document') || is_a($oFolderOrDocument, 'KTDocumentCore');
     //ensure that the document shortcut is being updated.
     if ($is_a_document && $oFolderOrDocument->isSymbolicLink()) {
         $oFolderOrDocument->switchToRealCore();
     }
     $oChannel = null;
     $aMapPermAllowed = null;
     $oPermLookup = null;
     if (!is_null($aOptions)) {
         $oChannel = $aOptions['channel'];
         $aMapPermAllowed = $aOptions['map_allowed'];
         $oPermLookup = $aOptions['perm_lookup'];
     }
     if (!$is_a_folder && !$is_a_document) {
         return;
         // we occasionally get handed a PEAR::raiseError.  Just ignore it.
     }
     if (is_null($oChannel)) {
         $oChannel =& KTPermissionChannel::getSingleton();
     }
     if ($is_a_folder) {
         $msg = sprintf("Updating folder %s", join('/', $oFolderOrDocument->getPathArray()));
     } else {
         if (is_a($oFolderOrDocument, 'Document')) {
             //modify the message to reflect that a shortcut is begin updated
             if ($oFolderOrDocument->isSymbolicLink()) {
                 $msg = sprintf("Updating shortcut to %s", $oFolderOrDocument->getName());
             } else {
                 $msg = sprintf("Updating document %s", $oFolderOrDocument->getName());
             }
         } else {
             $msg = sprintf("Updating document %d", $oFolderOrDocument->getId());
         }
     }
     $oChannel->sendMessage(new KTPermissionGenericMessage($msg));
     //var_dump($msg);
     $iPermissionObjectId = $oFolderOrDocument->getPermissionObjectID();
     if (empty($iPermissionObjectId)) {
         return;
     }
     $oPO = KTPermissionObject::get($iPermissionObjectId);
     if (is_null($aMapPermAllowed)) {
         $aPAs = KTPermissionAssignment::getByObjectMulti($oPO);
         $aMapPermAllowed = array();
         foreach ($aPAs as $oPA) {
             $oPD = KTPermissionDescriptor::get($oPA->getPermissionDescriptorID());
             $aGroupIDs = $oPD->getGroups();
             $aUserIDs = array();
             $aRoleIDs = $oPD->getRoles();
             $aAllowed = array('group' => $aGroupIDs, 'user' => $aUserIDs, 'role' => $aRoleIDs);
             $aMapPermAllowed[$oPA->getPermissionID()] = $aAllowed;
         }
     }
     if (!$is_a_folder) {
         $aDynamicConditions = KTPermissionDynamicCondition::getByPermissionObject($oPO);
         if (!PEAR::isError($aDynamicConditions)) {
             foreach ($aDynamicConditions as $oDynamicCondition) {
                 $iConditionId = $oDynamicCondition->getConditionId();
                 if (KTSearchUtil::testConditionOnDocument($iConditionId, $oFolderOrDocument)) {
                     $iGroupId = $oDynamicCondition->getGroupId();
                     $aPermissionIds = $oDynamicCondition->getAssignment();
                     foreach ($aPermissionIds as $iPermissionId) {
                         $aCurrentAllowed = KTUtil::arrayGet($aMapPermAllowed, $iPermissionId, array());
                         $aCurrentAllowed['group'][] = $iGroupId;
                         $aMapPermAllowed[$iPermissionId] = $aCurrentAllowed;
                     }
                 }
             }
         }
     }
     if (!$is_a_folder) {
         $oState = KTWorkflowUtil::getWorkflowStateForDocument($oFolderOrDocument);
         if (!(PEAR::isError($oState) || is_null($oState) || $oState == false)) {
             $aWorkflowStatePermissionAssignments = KTWorkflowStatePermissionAssignment::getByState($oState);
             foreach ($aWorkflowStatePermissionAssignments as $oAssignment) {
                 $iPermissionId = $oAssignment->getPermissionId();
                 $iPermissionDescriptorId = $oAssignment->getDescriptorId();
                 $oPD = KTPermissionDescriptor::get($iPermissionDescriptorId);
                 $aGroupIDs = $oPD->getGroups();
                 $aUserIDs = array();
                 $aRoleIDs = $oPD->getRoles();
                 $aAllowed = array('group' => $aGroupIDs, 'user' => $aUserIDs, 'role' => $aRoleIDs);
                 $aMapPermAllowed[$iPermissionId] = $aAllowed;
             }
         }
     }
     // if we have roles:  nearest folder.
     $iRoleSourceFolder = null;
     if ($is_a_document) {
         $iRoleSourceFolder = $oFolderOrDocument->getFolderID();
     } else {
         $iRoleSourceFolder = $oFolderOrDocument->getId();
     }
     // very minor perf win:  map role_id (in context) to PD.
     $_roleCache = array();
     foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) {
         $aAfterRoles = array();
         if (array_key_exists('role', $aAllowed)) {
             foreach ($aAllowed['role'] as $k => $iRoleId) {
                 // store the PD <-> RoleId map
                 // special-case "all" or "authenticated".
                 if ($iRoleId == -3 || $iRoleId == -4) {
                     $aAfterRoles[] = $iRoleId;
                     continue;
                 }
                 if (!array_key_exists($iRoleId, $_roleCache)) {
                     $oRoleAllocation = null;
                     if ($is_a_document) {
                         $oRoleAllocation =& DocumentRoleAllocation::getAllocationsForDocumentAndRole($oFolderOrDocument->getId(), $iRoleId);
                         if (PEAR::isError($oRoleAllocation)) {
                             $oRoleAllocation = null;
                         }
                     }
                     // if that's null - not set _on_ the document, then
                     if (is_null($oRoleAllocation)) {
                         $oRoleAllocation =& RoleAllocation::getAllocationsForFolderAndRole($iRoleSourceFolder, $iRoleId);
                     }
                     $_roleCache[$iRoleId] = $oRoleAllocation;
                 }
                 // roles are _not_ always assigned (can be null at root)
                 if (!is_null($_roleCache[$iRoleId])) {
                     $aMapPermAllowed[$iPermissionId]['user'] = kt_array_merge($aMapPermAllowed[$iPermissionId]['user'], $_roleCache[$iRoleId]->getUserIds());
                     $aMapPermAllowed[$iPermissionId]['group'] = kt_array_merge($aMapPermAllowed[$iPermissionId]['group'], $_roleCache[$iRoleId]->getGroupIds());
                     // naturally, roles cannot be assigned roles, or madness follows.
                 }
                 unset($aAllowed['role'][$k]);
             }
         }
         unset($aMapPermAllowed[$iPermissionId]['role']);
         if (!empty($aAfterRoles)) {
             $aMapPermAllowed[$iPermissionId]['role'] = $aAfterRoles;
         }
     }
     /*
     print '<pre>';
     print '=======' . $oFolderOrDocument->getName();
     print '<br />';
     var_dump($aMapPermAllowed);
     print '</pre>';
     */
     //if (is_null($oPermLookup)) {
     $aMapPermDesc = array();
     foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) {
         $oLookupPD = KTPermissionUtil::getOrCreateDescriptor($aAllowed);
         $aMapPermDesc[$iPermissionId] = $oLookupPD->getID();
     }
     $oPermLookup = KTPermissionLookupAssignment::findOrCreateLookupByPermissionDescriptorMap($aMapPermDesc);
     //}
     $oFolderOrDocument->setPermissionLookupID($oPermLookup->getID());
     $oFolderOrDocument->update();
 }
 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);
 }
Example #10
0
 function check_entity($oEntity)
 {
     $oPermission =& KTPermission::getByName($this->_sPermission);
     if (PEAR::isError($oPermission)) {
         return true;
     }
     // basic document checks
     // TODO: check if this is appropriate
     //       should probably store the 'equivalent' action (ie. document.delete)
     //       and check that, rather than add a new list of actions to the workflow
     //       section
     if (is_a($oEntity, 'Document')) {
         if (!KTWorkflowUtil::actionEnabledForDocument($oEntity, $this->sName)) {
             return PEAR::raiseError(_kt('Action is disabled by workflow'));
         }
         $status = $oEntity->getStatusID();
         if ($status == DELETED || $status == ARCHIVED) {
             return PEAR::raiseError(_kt('Document is archived or deleted'));
         }
     }
     // admin check
     if ($this->bAllowInAdminMode) {
         if (KTBrowseUtil::inAdminMode($this->oUser, null)) {
             return true;
         }
     }
     if (!KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $oEntity)) {
         return PEAR::raiseError(_kt('You do not have the required permissions'));
     }
     return true;
 }
 function canBeMoved($oDocument)
 {
     if ($oDocument->getIsCheckedOut()) {
         return false;
     }
     if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.move')) {
         return false;
     }
     if ($oDocument->getImmutable()) {
         return false;
     }
     return true;
 }
    function do_main()
    {
        $folderName = $this->oFolder->getName();
        $this->oZip = new ZipFolder($folderName);
        if (!$this->oZip->checkConvertEncoding()) {
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        $oKTConfig =& KTConfig::getSingleton();
        $bNoisy = $oKTConfig->get("tweaks/noisyBulkOperations");
        $bNotifications = $oKTConfig->get('export/enablenotifications', 'on') == 'on' ? true : false;
        // Get all folders and sub-folders
        $sCurrentFolderId = $this->oFolder->getId();
        $sWhereClause = "parent_folder_ids = '{$sCurrentFolderId}' OR\n        parent_folder_ids LIKE '{$sCurrentFolderId},%' OR\n        parent_folder_ids LIKE '%,{$sCurrentFolderId},%' OR\n        parent_folder_ids LIKE '%,{$sCurrentFolderId}'";
        $aFolderList = $this->oFolder->getList($sWhereClause);
        // Get any folder shortcuts within the folders
        $aLinkedFolders = KTBulkAction::getLinkingEntities($aFolderList);
        $aFolderList = array_merge($aFolderList, $aLinkedFolders);
        // Add the folders to the zip file
        $aFolderObjects = array($sCurrentFolderId => $this->oFolder);
        if (!empty($aFolderList)) {
            foreach ($aFolderList as $oFolderItem) {
                $itemId = $oFolderItem->getId();
                $linkedFolder = $oFolderItem->getLinkedFolderId();
                // If the folder has been added or is a shortcut then skip
                // The shortcut folders don't need to be added as their targets will be added.
                if (array_key_exists($itemId, $aFolderObjects) || !empty($linkedFolder)) {
                    continue;
                }
                $this->oZip->addFolderToZip($oFolderItem);
                $aFolderObjects[$oFolderItem->getId()] = $oFolderItem;
            }
        }
        // Get the list of folder ids
        $aFolderIds = array_keys($aFolderObjects);
        // Get all documents in the folder list
        $aQuery = $this->buildQuery($aFolderIds);
        $aDocumentIds = DBUtil::getResultArrayKey($aQuery, 'id');
        if (PEAR::isError($aDocumentIds)) {
            $this->addErrorMessage(_kt('There was a problem exporting the documents: ') . $aDocumentIds->getMessage());
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        // Redirect if there are no documents and no folders to export
        if (empty($aDocumentIds) && empty($aFolderList)) {
            $this->addErrorMessage(_kt("No documents found to export"));
            redirect(KTBrowseUtil::getUrlForFolder($this->oFolder));
            exit(0);
        }
        $this->oPage->template = "kt3/minimal_page";
        $this->handleOutput("");
        // Add the documents to the zip file
        if (!empty($aDocumentIds)) {
            foreach ($aDocumentIds as $iId) {
                $oDocument = Document::get($iId);
                $sFolderId = $oDocument->getFolderID();
                if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.view')) {
                    $this->addErrorMessage($oDocument->getName() . ': ' . _kt('Document cannot be exported as it is restricted by the workflow.'));
                    continue;
                }
                $oFolder = isset($aFolderObjects[$sFolderId]) ? $aFolderObjects[$sFolderId] : Folder::get($sFolderId);
                if ($bNoisy) {
                    $oDocumentTransaction =& new DocumentTransaction($oDocument, "Document part of bulk export", 'ktstandard.transactions.bulk_export', array());
                    $oDocumentTransaction->create();
                }
                // fire subscription alerts for the downloaded document
                if ($bNotifications) {
                    $oSubscriptionEvent = new SubscriptionEvent();
                    $oSubscriptionEvent->DownloadDocument($oDocument, $oFolder);
                }
                $this->oZip->addDocumentToZip($oDocument, $oFolder);
            }
        }
        $sExportCode = $this->oZip->createZipFile(TRUE);
        $oTransaction = KTFolderTransaction::createFromArray(array('folderid' => $this->oFolder->getId(), 'comment' => "Bulk export", 'transactionNS' => 'ktstandard.transactions.bulk_export', 'userid' => $_SESSION['userID'], 'ip' => Session::getClientIP()));
        $url = KTUtil::addQueryStringSelf(sprintf('action=downloadZipFile&fFolderId=%d&exportcode=%s', $this->oFolder->getId(), $sExportCode));
        printf('<p>' . _kt('Your download will begin shortly. If you are not automatically redirected to your download, please click <a href="%s">here</a> ') . "</p>\n", $url);
        $folderurl = KTBrowseUtil::getUrlForFolder($this->oFolder);
        printf('<p>' . _kt('Once your download is complete, click <a href="%s">here</a> to return to the original folder') . "</p>\n", $folderurl);
        printf("</div></div></body></html>\n");
        printf('<script language="JavaScript">
                function kt_bulkexport_redirect() {
                    document.location.href = "%s";
                }
                callLater(1, kt_bulkexport_redirect);

                </script>', $url);
        exit(0);
    }
 function canBeArchived($oDocument, &$sError)
 {
     if ($oDocument->getIsCheckedOut()) {
         $sError = PEAR::raiseError(_kt('Document cannot be archived as it is checked out.'));
         return false;
     }
     if (!KTWorkflowUtil::actionEnabledForDocument($oDocument, 'ktcore.actions.document.archive')) {
         $sError = PEAR::raiseError(_kt('Document cannot be archived as it is restricted by the workflow.'));
         return false;
     }
     return true;
 }
Example #14
0
 function do_resolved_users()
 {
     $this->oPage->setBreadcrumbDetails(_kt("Permissions"));
     $oTemplate = $this->oValidator->validateTemplate("ktcore/document/resolved_permissions_user");
     $oPL = KTPermissionLookup::get($this->oDocument->getPermissionLookupID());
     $aPermissions = KTPermission::getList();
     $aMapPermissionGroup = array();
     $aMapPermissionRole = array();
     $aMapPermissionUser = array();
     $aUsers = User::getList();
     foreach ($aPermissions as $oPermission) {
         $oPLA = KTPermissionLookupAssignment::getByPermissionAndLookup($oPermission, $oPL);
         if (PEAR::isError($oPLA)) {
             continue;
         }
         $oDescriptor = KTPermissionDescriptor::get($oPLA->getPermissionDescriptorID());
         $iPermissionID = $oPermission->getID();
         $aMapPermissionGroup[$iPermissionID] = array();
         foreach ($aUsers as $oUser) {
             if (KTPermissionUtil::userHasPermissionOnItem($oUser, $oPermission, $this->oDocument)) {
                 $aMapPermissionUser[$iPermissionID][$oUser->getId()] = true;
                 $aActiveUsers[$oUser->getId()] = true;
             }
         }
     }
     // now we constitute the actual sets.
     $users = array();
     $groups = array();
     $roles = array();
     // should _always_ be empty, barring a bug in permissions::updatePermissionLookup
     // this should be quite limited - direct role -> user assignment is typically rare.
     foreach ($aActiveUsers as $id => $marker) {
         $oUser = User::get($id);
         $users[$oUser->getName()] = $oUser;
     }
     asort($users);
     // ascending, per convention.
     $bEdit = false;
     $sInherited = '';
     $aDynamicControls = array();
     $aWorkflowControls = array();
     // handle conditions
     $iPermissionObjectId = $this->oDocument->getPermissionObjectID();
     if (!empty($iPermissionObjectId)) {
         $oPO = KTPermissionObject::get($iPermissionObjectId);
         $aDynamicConditions = KTPermissionDynamicCondition::getByPermissionObject($oPO);
         if (!PEAR::isError($aDynamicConditions)) {
             foreach ($aDynamicConditions as $oDynamicCondition) {
                 $iConditionId = $oDynamicCondition->getConditionId();
                 if (KTSearchUtil::testConditionOnDocument($iConditionId, $this->oDocument)) {
                     $aPermissionIds = $oDynamicCondition->getAssignment();
                     foreach ($aPermissionIds as $iPermissionId) {
                         $aDynamicControls[$iPermissionId] = true;
                     }
                 }
             }
         }
     }
     // indicate that workflow controls a given permission
     $oState = KTWorkflowUtil::getWorkflowStateForDocument($this->oDocument);
     if (!(PEAR::isError($oState) || is_null($oState) || $oState == false)) {
         $aWorkflowStatePermissionAssignments = KTWorkflowStatePermissionAssignment::getByState($oState);
         foreach ($aWorkflowStatePermissionAssignments as $oAssignment) {
             $aWorkflowControls[$oAssignment->getPermissionId()] = true;
             unset($aDynamicControls[$oAssignment->getPermissionId()]);
         }
     }
     $aTemplateData = array("context" => $this, "permissions" => $aPermissions, "groups" => $groups, "users" => $users, "roles" => $roles, "oDocument" => $this->oDocument, "aMapPermissionGroup" => $aMapPermissionGroup, "aMapPermissionRole" => $aMapPermissionRole, "aMapPermissionUser" => $aMapPermissionUser, "edit" => $bEdit, "inherited" => $sInherited, 'workflow_controls' => $aWorkflowControls, 'conditions_control' => $aDynamicControls);
     return $oTemplate->render($aTemplateData);
 }
Example #15
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 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>';
     }
 }
 function getActionTriggersForTransition($oTransition)
 {
     $aTriggers = KTWorkflowUtil::getTriggersForTransition($oTransition);
     if (PEAR::isError($aTriggers)) {
         return $aTriggers;
     }
     $aGuards = array();
     foreach ($aTriggers as $oTrigger) {
         $aInfo = $oTrigger->getInfo();
         if ($aInfo['action']) {
             $aGuards[] = $oTrigger;
         }
     }
     return $aGuards;
 }
Example #18
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;
 }
 /**
  * This returns the current workflow state
  *
  * @author KnowledgeTree Team
  * @access public
  * @return string Returns the name of the state | a PEAR_Error on failure
  */
 function get_workflow_state()
 {
     $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 new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS);
     }
     $result = array();
     $state = KTWorkflowUtil::getWorkflowStateForDocument($this->document);
     if (is_null($state) || PEAR::isError($state)) {
         return new PEAR_Error(KTAPI_ERROR_WORKFLOW_INVALID);
     }
     $statename = $state->getName();
     return $statename;
 }
Example #20
0
 function renderData($aDataRow)
 {
     // only _ever_ show this for 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 sprintf('%s <span class="descriptive">%s</span>', htmlentities($oState->getName(), ENT_NOQUOTES, 'UTF-8'), htmlentities($oWorkflow->getName(), ENT_NOQUOTES, 'UTF-8'));
     }
 }
 function _show()
 {
     if (is_null($this->_sShowPermission)) {
         return true;
     }
     $oFolder = Folder::get($this->oDocument->getFolderId());
     if ($this->_bMutator && $this->oDocument->getImmutable()) {
         if ($this->_bMutationAllowedByAdmin === true) {
             if (!KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) {
                 return false;
             }
         } else {
             return false;
         }
     }
     if ($this->_bAdminAlwaysAvailable) {
         if (Permission::userIsSystemAdministrator($this->oUser->getId())) {
             return true;
         }
         if (Permission::isUnitAdministratorForFolder($this->oUser, $this->oDocument->getFolderId())) {
             return true;
         }
     }
     $oPermission =& KTPermission::getByName($this->_sShowPermission);
     if (PEAR::isError($oPermission)) {
         return true;
     }
     if (!KTWorkflowUtil::actionEnabledForDocument($this->oDocument, $this->sName)) {
         return false;
     }
     // be nasty in archive/delete status.
     $status = $this->oDocument->getStatusID();
     if ($status == DELETED || $status == ARCHIVED) {
         return false;
     }
     if ($this->bAllowInAdminMode) {
         // check if this user is in admin mode
         if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) {
             return true;
         }
     }
     return KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPermission, $this->oDocument);
 }
 function &getBySourceState($oState)
 {
     return KTWorkflowUtil::getTransitionsFrom($oState);
 }
 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()));
     }
 }
 function copyTrigger($oDocument)
 {
     return KTWorkflowUtil::getWorkflowForDocument($oDocument);
 }