/** * 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); }
function do_disableAdminMode() { $iDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId'); if ($iDocumentId) { $oDocument = Document::get($iDocumentId); if (PEAR::isError($oDocument) || $oDocument === false) { return null; } $iFolderId = $oDocument->getFolderId(); } if (!Permission::userIsSystemAdministrator() && !Permission::isUnitAdministratorForFolder($this->oUser, $iFolderId)) { $this->errorRedirectToMain(_kt('You are not an administrator')); } // log this entry $oLogEntry =& KTUserHistory::createFromArray(array('userid' => $this->oUser->getId(), 'datetime' => date('Y-m-d H:i:s', time()), 'actionnamespace' => 'ktcore.user_history.disable_admin_mode', 'comments' => 'Admin Mode disabled', 'sessionid' => $_SESSION['sessionID'])); $aOpts = array('redirect_to' => 'main', 'message' => _kt('Unable to log admin mode exit. Not de-activating admin mode.')); $this->oValidator->notError($oLogEntry, $aOpts); $_SESSION['adminmode'] = false; if ($_REQUEST['fDocumentId']) { $_SESSION['KTInfoMessage'][] = _kt('Administrator mode disabled'); redirect(KTBrowseUtil::getUrlForDocument($iDocumentId)); exit(0); } if ($_REQUEST['fFolderId']) { $this->successRedirectToMain(_kt('Administrator mode disabled'), sprintf('fFolderId=%d', $_REQUEST['fFolderId'])); } $this->successRedirectToMain(_kt('Administrator mode disabled')); }
/** * Determines whether the user is in administrator mode, including * whether the user is in the unit for which it is unit * administrator. */ function inAdminMode($oUser, $oFolder) { if (KTUtil::arrayGet($_SESSION, 'adminmode', false) !== true) { return false; } if (Permission::userIsSystemAdministrator($oUser)) { return true; } return Permission::isUnitAdministratorForFolder($oUser, $oFolder); }
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 render() { $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', 1); $iDocumentId = KTUtil::arrayGet($_REQUEST, 'fDocumentId'); if (!$iFolderId && !$iDocumentId) { return null; } if ($iDocumentId) { $oDocument = Document::get($iDocumentId); if (PEAR::isError($oDocument) || $oDocument === false) { return null; } $iFolderId = $oDocument->getFolderId(); } require_once KT_LIB_DIR . '/security/Permission.inc'; $oUser =& User::get($_SESSION['userID']); if (!Permission::userIsSystemAdministrator($oUser) && !Permission::isUnitAdministratorForFolder($oUser, $iFolderId)) { return null; } require_once KT_LIB_DIR . '/browse/browseutil.inc.php'; $oTemplating =& KTTemplating::getSingleton(); $oTemplate = $oTemplating->loadTemplate("kt3/portlets/admin_mode_portlet"); $toggleMode = 'action=disableAdminMode'; if (KTUtil::arrayGet($_SESSION, 'adminmode', false) == false) { $toggleMode = 'action=enableAdminMode'; } $QS = sprintf('fDocumentId=%s&fFolderId=%s&%s', $iDocumentId, $iFolderId, $toggleMode); $toggleUrl = KTUtil::addQueryString(KTBrowseUtil::getBrowseBaseUrl(), $QS); $aTemplateData = array("context" => $this, 'toggleurl' => $toggleUrl, 'enabled' => KTUtil::arrayGet($_SESSION, 'adminmode', false)); return $oTemplate->render($aTemplateData); }