function folderOrDocument($sPath, $bAction = false)
 {
     $sFileName = basename($sPath);
     $sFolderPath = dirname($sPath);
     $aFolderInfo = KTBrowseUtil::_folderOrDocument($sFolderPath);
     if ($aFolderInfo === false) {
         return $aFolderInfo;
     }
     list($iFolderID, $iDocumentID) = $aFolderInfo;
     if ($iDocumentID && $bAction) {
         $aActions = array_keys(KTDocumentActionUtil::getAllDocumentActions());
         if (in_array($sFileName, $aActions)) {
             return array($iFolderID, $iDocumentID, $sFileName);
         }
         return false;
     }
     $sQuery = 'SELECT id FROM folders WHERE parent_id = ? AND name = ?';
     $aParams = array($iFolderID, $sFileName);
     $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id');
     if (PEAR::isError($id)) {
         // XXX: log error
         return false;
     }
     if ($id) {
         return array($id, null, null);
     }
     $sQuery = sprintf('SELECT d.id FROM %s AS d' . ' LEFT JOIN %s AS dm ON (d.metadata_version_id = dm.id) LEFT JOIN %s AS dc ON (dm.content_version_id = dc.id)' . ' WHERE d.folder_id = ? AND dc.filename = ?', KTUtil::getTableName(documents), KTUtil::getTableName('document_metadata_version'), KTUtil::getTableName('document_content_version'));
     $aParams = array($iFolderID, $sFileName);
     $iDocumentID = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id');
     if (PEAR::isError($iDocumentID)) {
         // XXX: log error
         return false;
     }
     if ($iDocumentID) {
         return array($iFolderID, $iDocumentID, null);
     }
     if ($bAction) {
         // $aActions = array_keys(KTFolderAction::getFolderActions());
         $aActions = array('ktcore.delete');
         if (in_array($sFileName, $aActions)) {
             return array($iFolderID, null, $sFileName);
         }
     }
     return false;
 }
 /**
  * Display a list of versions for comparing
  *
  * @return unknown
  */
 function do_main()
 {
     $show_version = KTUtil::arrayGet($_REQUEST, 'show');
     $showall = isset($show_version) && $show_version == 'all' ? true : false;
     $this->oPage->setSecondaryTitle($this->oDocument->getName());
     $this->oPage->setBreadcrumbDetails(_kt('Version History'));
     $aMetadataVersions = KTDocumentMetadataVersion::getByDocument($this->oDocument);
     $aVersions = array();
     foreach ($aMetadataVersions as $oVersion) {
         $version = Document::get($this->oDocument->getId(), $oVersion->getId());
         if ($showall) {
             $aVersions[] = $version;
         } else {
             if ($version->getMetadataStatusID() != VERSION_DELETED) {
                 $aVersions[] = $version;
             }
         }
     }
     // render pass.
     $this->oPage->title = _kt('Document History');
     $oTemplate = $this->oValidator->validateTemplate('ktcore/document/metadata_history');
     $aActions = KTDocumentActionUtil::getDocumentActionsByNames(array('ktcore.actions.document.view'));
     $oAction = $aActions[0];
     $oAction->setDocument($this->oDocument);
     // create delete action if user is sys admin or folder admin
     $bShowDelete = false;
     require_once KT_LIB_DIR . '/security/Permission.inc';
     $oUser =& User::get($_SESSION['userID']);
     $iFolderId = $this->oDocument->getFolderId();
     if (Permission::userIsSystemAdministrator($oUser) || Permission::isUnitAdministratorForFolder($oUser, $iFolderId)) {
         // Check if admin mode is enabled
         $bShowDelete = KTUtil::arrayGet($_SESSION, 'adminmode', false);
     }
     // Check if the document comparison plugin is installed
     $isActive = KTPluginUtil::pluginIsActive('document.comparison.plugin');
     $bShowCompare = false;
     $bShowVersionCompare = false;
     $sUrl = false;
     if ($isActive) {
         $oRegistry =& KTPluginRegistry::getSingleton();
         $oPlugin =& $oRegistry->getPlugin('document.comparison.plugin');
         if ($oPlugin->loadHelpers()) {
             $sUrl = $oPlugin->getPagePath('DocumentComparison');
             $file = $oPlugin->_aPages['document.comparison.plugin/DocumentComparison'][2];
             include_once $file;
             // Check mime type of document for content comparison
             list($bShowCompare, $bShowVersionCompare) = DocumentComparison::checkMimeType($this->oDocument);
         }
     }
     $aTemplateData = array('context' => $this, 'document_id' => $this->oDocument->getId(), 'document' => $this->oDocument, 'versions' => $aVersions, 'downloadaction' => $oAction, 'showdelete' => $bShowDelete, 'showall' => $showall, 'bShowCompare' => $bShowCompare, 'bShowVersionCompare' => $bShowVersionCompare, 'sUrl' => $sUrl);
     return $oTemplate->render($aTemplateData);
 }
Exemple #3
0
 function do_main()
 {
     // fix legacy, broken items.
     if (KTUtil::arrayGet($_REQUEST, 'fDocumentID', true) !== true) {
         $_REQUEST['fDocumentId'] = sanitizeForSQL(KTUtil::arrayGet($_REQUEST, 'fDocumentID'));
         unset($_REQUEST['fDocumentID']);
     }
     $document_data = array();
     $document_id = sanitizeForSQL(KTUtil::arrayGet($_REQUEST, 'fDocumentId'));
     if ($document_id === null) {
         $this->oPage->addError(sprintf(_kt("No document was requested.  Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl()));
         return $this->do_error();
     }
     // try get the document.
     $oDocument =& Document::get($document_id);
     if (PEAR::isError($oDocument)) {
         $this->oPage->addError(sprintf(_kt("The document you attempted to retrieve is invalid.   Please <a href=\"%s\">browse</a> for one."), KTBrowseUtil::getBrowseBaseUrl()));
         $this->oPage->booleanLink = true;
         return $this->do_error();
     }
     $document_id = $oDocument->getId();
     $document_data['document_id'] = $oDocument->getId();
     if (!KTBrowseUtil::inAdminMode($this->oUser, $oDocument->getFolderId())) {
         if ($oDocument->getStatusID() == ARCHIVED) {
             $this->oPage->addError(_kt('This document has been archived.  Please contact the system administrator to have it restored if it is still needed.'));
             return $this->do_request($oDocument);
         } else {
             if ($oDocument->getStatusID() == DELETED) {
                 $this->oPage->addError(_kt('This document has been deleted.  Please contact the system administrator to have it restored if it is still needed.'));
                 return $this->do_error();
             } else {
                 if (!Permission::userHasDocumentReadPermission($oDocument)) {
                     $this->oPage->addError(_kt('You are not allowed to view this document'));
                     return $this->permissionDenied();
                 }
             }
         }
     }
     if ($oDocument->getStatusID() == ARCHIVED) {
         $this->oPage->addError(_kt('This document has been archived.'));
     } else {
         if ($oDocument->getStatusID() == DELETED) {
             $this->oPage->addError(_kt('This document has been deleted.'));
         }
     }
     $this->oPage->setSecondaryTitle($oDocument->getName());
     $aOptions = array('documentaction' => 'viewDocument', 'folderaction' => 'browse');
     $this->oDocument =& $oDocument;
     //Figure out if we came here by navigating trough a shortcut.
     //If we came here from a shortcut, the breadcrumbspath should be relative
     //to the shortcut folder.
     $iSymLinkFolderId = KTUtil::arrayGet($_REQUEST, 'fShortcutFolder', null);
     if (is_numeric($iSymLinkFolderId)) {
         $oBreadcrumbsFolder = Folder::get($iSymLinkFolderId);
         $aOptions['final'] = false;
         $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForFolder($oBreadcrumbsFolder, $aOptions));
         $this->aBreadcrumbs[] = array('name' => $this->oDocument->getName());
     } else {
         $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForDocument($oDocument, $aOptions, $iSymLinkFolderId));
     }
     $this->oPage->setBreadcrumbDetails(_kt('document details'));
     $this->addPortlets('Document Details');
     $document_data['document'] = $oDocument;
     $document_data['document_type'] =& DocumentType::get($oDocument->getDocumentTypeID());
     $is_valid_doctype = true;
     if (PEAR::isError($document_data['document_type'])) {
         $this->oPage->addError(_kt('The document you requested has an invalid <strong>document type</strong>.  Unfortunately, this means that we cannot effectively display it.'));
         $is_valid_doctype = false;
     }
     // we want to grab all the md for this doc, since its faster that way.
     $mdlist =& DocumentFieldLink::getByDocument($oDocument);
     $field_values = array();
     foreach ($mdlist as $oFieldLink) {
         $field_values[$oFieldLink->getDocumentFieldID()] = $oFieldLink->getValue();
     }
     //var_dump($field_values);
     $document_data['field_values'] = $field_values;
     // Fieldset generation.
     //
     //   we need to create a set of FieldsetDisplay objects
     //   that adapt the Fieldsets associated with this lot
     //   to the view (i.e. ZX3).   Unfortunately, we don't have
     //   any of the plumbing to do it, so we handle this here.
     $fieldsets = array();
     // we always have a generic.
     array_push($fieldsets, new GenericFieldsetDisplay());
     $fieldsetDisplayReg =& KTFieldsetDisplayRegistry::getSingleton();
     $aDocFieldsets = KTMetadataUtil::fieldsetsForDocument($oDocument);
     foreach ($aDocFieldsets as $oFieldset) {
         $displayClass = $fieldsetDisplayReg->getHandler($oFieldset->getNamespace());
         array_push($fieldsets, new $displayClass($oFieldset));
     }
     $checkout_user = '******';
     if ($oDocument->getIsCheckedOut() == 1) {
         $oCOU = User::get($oDocument->getCheckedOutUserId());
         if (!(PEAR::isError($oCOU) || $oCOU == false)) {
             $checkout_user = $oCOU->getName();
         }
     }
     // is the checkout action active?
     $bCanCheckin = false;
     foreach ($this->actions as $oDocAction) {
         $sActName = $oDocAction->sName;
         if ($sActName == 'ktcore.actions.document.cancelcheckout') {
             if ($oDocAction->getInfo()) {
                 $bCanCheckin = true;
             }
         }
     }
     // viewlets.
     $aViewlets = array();
     $aViewletActions = KTDocumentActionUtil::getDocumentActionsForDocument($this->oDocument, $this->oUser, 'documentviewlet');
     foreach ($aViewletActions as $oAction) {
         $aInfo = $oAction->getInfo();
         if ($aInfo !== null) {
             $aViewlets[] = $oAction->display_viewlet();
             // use the action, since we display_viewlet() later.
         }
     }
     $viewlet_data = implode(' ', $aViewlets);
     $viewlet_data = trim($viewlet_data);
     $content_class = 'view';
     if (!empty($viewlet_data)) {
         $content_class = 'view withviewlets';
     }
     $this->oPage->setContentClass($content_class);
     $oTemplating =& KTTemplating::getSingleton();
     $oTemplate = $oTemplating->loadTemplate('ktcore/document/view');
     $aTemplateData = array('context' => $this, 'sCheckoutUser' => $checkout_user, 'isCheckoutUser' => $this->oUser->getId() == $oDocument->getCheckedOutUserId(), 'canCheckin' => $bCanCheckin, 'document_id' => $document_id, 'document' => $oDocument, 'documentName' => $oDocument->getName(), 'document_data' => $document_data, 'fieldsets' => $fieldsets, 'viewlet_data' => $viewlet_data);
     //return '<pre>' . print_r($aTemplateData, true) . '</pre>';
     return $oTemplate->render($aTemplateData);
 }
 function getDocumentActionsByNames($aNames, $slot = 'documentaction', $oDocument = null, $oUser = null)
 {
     $aObjects = array();
     foreach (KTDocumentActionUtil::getDocumentActionInfo($slot) as $aAction) {
         list($sClassName, $sPath, $sName, $sPlugin) = $aAction;
         $oRegistry =& KTPluginRegistry::getSingleton();
         $oPlugin =& $oRegistry->getPlugin($sPlugin);
         if (!in_array($sName, $aNames)) {
             continue;
         }
         if (!empty($sPath)) {
             require_once $sPath;
         }
         $aObjects[] = new $sClassName($oDocument, $oUser, $oPlugin);
     }
     return $aObjects;
 }
 function do_saveactions()
 {
     $disabled_actions = (array) $_REQUEST['fActions'];
     $states = KTWorkflowState::getByWorkflow($this->oWorkflow);
     $actions = KTUtil::keyArray(KTDocumentActionUtil::getAllDocumentActions(), 'getName');
     $this->startTransaction();
     foreach ($states as $oState) {
         $disable = array();
         $state_disabled = (array) $disabled_actions[$oState->getId()];
         if (!empty($state_disabled)) {
             foreach ($actions as $name => $oAction) {
                 if ($state_disabled[$name]) {
                     $disable[] = $name;
                 }
             }
         }
         $res = KTWorkflowUtil::setDisabledActionsForState($oState, $disable);
     }
     $this->successRedirectTo('actionsoverview', _kt('Disabled actions updated.'));
 }