ktdocumentactions.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 1,703 行 · 第 1/5 页
PHP
1,703 行
<?php
/**
* $Id: KTDocumentActions.php 9404 2008-09-28 20:25:05Z kevin_fourie $
*
* KnowledgeTree Community Edition
* Document Management Made Simple
* Copyright (C) 2008 KnowledgeTree Inc.
* Portions copyright The Jam Warehouse Software (Pty) Limited
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 3 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
* California 94120-7775, or email info@knowledgetree.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* KnowledgeTree" logo and retain the original copyright notice. If the display of the
* logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
* must display the words "Powered by KnowledgeTree" and retain the original
* copyright notice.
* Contributor( s): ______________________________________
*
*/
require_once(KT_LIB_DIR . '/actions/documentaction.inc.php');
require_once(KT_LIB_DIR . '/subscriptions/Subscription.inc');
require_once(KT_LIB_DIR . '/widgets/fieldWidgets.php');
require_once(KT_LIB_DIR . '/browse/browseutil.inc.php');
require_once(KT_LIB_DIR . '/documentmanagement/documentutil.inc.php');
require_once(KT_LIB_DIR . '/documentmanagement/PhysicalDocumentManager.inc');
require_once(KT_LIB_DIR . '/browse/DocumentCollection.inc.php');
require_once(KT_LIB_DIR . '/browse/BrowseColumns.inc.php');
require_once(KT_LIB_DIR . '/browse/PartialQuery.inc.php');
require_once(KT_LIB_DIR . '/widgets/forms.inc.php');
// {{{ KTDocumentDetailsAction
class KTDocumentDetailsAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.displaydetails';
function do_main() {
redirect(generateControllerLink('viewDocument',sprintf(_kt('fDocumentId=%d'),$this->oDocument->getId())));
exit(0);
}
function getDisplayName() {
return _kt('Display Details');
}
}
// }}}
// {{{ KTDocumentHistoryAction
class KTDocumentTransactionHistoryAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.transactionhistory';
function getDisplayName() {
return _kt('Transaction History');
}
function do_main() {
$this->oPage->setSecondaryTitle($this->oDocument->getName());
$this->oPage->setBreadcrumbDetails(_kt('history'));
$aTransactions = array();
// FIXME create a sane "view user information" page somewhere.
// FIXME do we really need to use a raw db-access here? probably...
$sQuery = 'SELECT DTT.name AS transaction_name, U.name AS user_name, DT.version AS version, DT.comment AS comment, DT.datetime AS datetime ' .
'FROM ' . KTUtil::getTableName('document_transactions') . ' AS DT INNER JOIN ' . KTUtil::getTableName('users') . ' AS U ON DT.user_id = U.id ' .
'INNER JOIN ' . KTUtil::getTableName('transaction_types') . ' AS DTT ON DTT.namespace = DT.transaction_namespace ' .
'WHERE DT.document_id = ? ORDER BY DT.datetime DESC';
$aParams = array($this->oDocument->getId());
$res = DBUtil::getResultArray(array($sQuery, $aParams));
if (PEAR::isError($res)) {
var_dump($res); // FIXME be graceful on failure.
exit(0);
}
$aTransactions = $res;
// render pass.
$this->oPage->setTitle(_kt('Document History'));
$oTemplate = $this->oValidator->validateTemplate('ktcore/document/transaction_history');
$aTemplateData = array(
'context' => $this,
'document_id' => $this->oDocument->getId(),
'document' => $this->oDocument,
'transactions' => $aTransactions,
);
return $oTemplate->render($aTemplateData);
}
}
// }}}
// {{{ KTDocumentHistoryAction
class KTDocumentVersionHistoryAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.versionhistory';
function getDisplayName() {
return _kt('Version History');
}
/**
* 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->load()){
$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);
}
/**
* Display list of metadata versions to compare with the selected version
*
* @return unknown
*/
function do_startComparison() {
$comparison_version = KTUtil::arrayGet($_REQUEST, 'fComparisonVersion');
$oDocument =& Document::get($this->oDocument->getId(), $comparison_version);
if (PEAR::isError($oDocument)) {
return $this->redirectToMain(_kt('The document you selected was invalid'));
}
if (!Permission::userHasDocumentReadPermission($oDocument)) {
return $this->errorRedirectToMain(_kt('You are not allowed to view this document'));
}
$this->oDocument =& $oDocument;
$this->oPage->setSecondaryTitle($oDocument->getName());
$this->oPage->setBreadcrumbDetails(_kt('Select Document Version to compare against'));
$aMetadataVersions = KTDocumentMetadataVersion::getByDocument($oDocument);
$aVersions = array();
foreach ($aMetadataVersions as $oVersion) {
$aVersions[] = Document::get($oDocument->getId(), $oVersion->getId());
}
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate('ktcore/document/comparison_version_select');
$aTemplateData = array(
'context' => $this,
'document_id' => $this->oDocument->getId(),
'document' => $oDocument,
'versions' => $aVersions,
'downloadaction' => $oAction,
);
return $oTemplate->render($aTemplateData);
}
/**
* Display the metadata comparison
*
*/
function do_viewComparison() {
// this is just a redirector
$QS = array(
'action' => 'viewComparison',
'fDocumentId' => $this->oDocument->getId(),
'fBaseVersion' => $_REQUEST['fBaseVersion'],
'fComparisonVersion' => $_REQUEST['fComparisonVersion'],
);
$frag = array();
foreach ($QS as $k => $v) {
$frag[] = sprintf('%s=%s', urlencode($k), urlencode($v));
}
redirect(KTUtil::ktLink('view.php',null,implode('&', $frag)));
}
function getUserForId($iUserId) {
$u = User::get($iUserId);
if (PEAR::isError($u) || ($u == false)) { return _kt('User no longer exists'); }
return $u->getName();
}
/**
* Confirm the deletion of a version
*
* @return unknown
*/
function do_confirmdeleteVersion() {
$this->oPage->setSecondaryTitle($this->oDocument->getName());
$this->oPage->setBreadcrumbDetails(_kt('Delete document version'));
// Display the version name and number
$iVersionId = $_REQUEST['version'];
$oVersion = Document::get($this->oDocument->getId(), $iVersionId);
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate('ktcore/document/delete_version');
$aTemplateData = array(
'context' => $this,
'fDocumentId' => $this->oDocument->getId(),
'oVersion' => $oVersion,
);
return $oTemplate->render($aTemplateData);
}
/**
* Delete a version
*
*/
function do_deleteVersion() {
$iVersionId = $_REQUEST['versionid'];
$sReason = $_REQUEST['reason'];
$oVersion = Document::get($this->oDocument->getId(), $iVersionId);
$res = KTDocumentUtil::deleteVersion($this->oDocument, $iVersionId, $sReason);
if(PEAR::isError($res)){
$this->addErrorMessage($res->getMessage());
redirect(KTDocumentAction::getURL());
exit(0);
}
// Record the transaction
$aOptions['version'] = sprintf('%d.%d', $oVersion->getMajorVersionNumber(), $oVersion->getMinorVersionNumber());
$oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document version deleted'), 'ktcore.transactions.delete_version', $aOptions);
$oDocumentTransaction->create();
redirect(KTDocumentAction::getURL());
}
}
// }}}
// {{{ KTDocumentViewAction
class KTDocumentViewAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.view';
var $sIconClass = 'download';
function getDisplayName() {
return _kt('Download');
}
function getButton() {
$btn = array();
$btn['display_text'] = _kt('Download Document');
$btn['arrow_class'] = 'arrow_download';
return $btn;
}
function customiseInfo($aInfo) {
$aInfo['alert'] = _kt('This will download a copy of the document and is not the same as Checking Out a document. Changes to this downloaded file will not be managed in the DMS.');
return $aInfo;
}
function do_main() {
$oStorage =& KTStorageManagerUtil::getSingleton();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?