ktdocumentactions.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 1,703 行 · 第 1/5 页
PHP
1,703 行
$aOptions = array();
$iVersion = KTUtil::arrayGet($_REQUEST, 'version');
if ($iVersion) {
$oVersion = KTDocumentContentVersion::get($iVersion);
$aOptions['version'] = sprintf('%d.%d', $oVersion->getMajorVersionNumber(), $oVersion->getMinorVersionNumber());
$res = $oStorage->downloadVersion($this->oDocument, $iVersion);
} else {
$res = $oStorage->download($this->oDocument);
}
if ($res === false) {
$this->addErrorMessage(_kt('The file you requested is not available - please contact the system administrator if this is incorrect.'));
redirect(generateControllerLink('viewDocument',sprintf(_kt('fDocumentId=%d'),$this->oDocument->getId())));
exit(0);
}
$oDocumentTransaction = & new DocumentTransaction($this->oDocument, _kt('Document downloaded'), 'ktcore.transactions.download', $aOptions);
$oDocumentTransaction->create();
// fire subscription alerts for the downloaded document
$oKTConfig =& KTConfig::getSingleton();
$bNotifications = ($oKTConfig->get('export/enablenotifications', 'on') == 'on') ? true : false;
if($bNotifications){
$oSubscriptionEvent = new SubscriptionEvent();
$oFolder = Folder::get($this->oDocument->getFolderID());
$oSubscriptionEvent->DownloadDocument($this->oDocument, $oFolder);
}
exit(0);
}
}
// }}}
// {{{ KTDocumentCheckOutAction
class KTDocumentCheckOutAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.checkout';
var $_sShowPermission = 'ktcore.permissions.write';
var $_bMutator = true;
var $_bMutationAllowedByAdmin = false;
var $sIconClass = 'checkout';
function getDisplayName() {
return _kt('Checkout');
}
function getInfo() {
if ($this->oDocument->getIsCheckedOut()) {
return null;
}
return parent::getInfo();
}
function check() {
$res = parent::check();
if ($res !== true) {
return $res;
}
// since we actually check the doc out, then download it ...
if (($_REQUEST[$this->event_var] == 'checkout_final') && ($this->oDocument->getCheckedOutUserID() == $_SESSION['userID'])) {
return true;
}
// "normal".
if ($this->oDocument->getIsCheckedOut()) {
$_SESSION['KTErrorMessage'][] = _kt('This document is already checked out');
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
exit(0);
}
return true;
}
function form_checkout() {
$oForm = new KTForm;
$oForm->setOptions(array(
'label' => _kt('Checkout'),
'action' => 'checkout',
'fail_action' => 'main',
'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
'submit_label' => _kt('Checkout document'),
'context' => &$this,
));
$oForm->setWidgets(array(
array('ktcore.widgets.reason', array(
'label' => _kt('Reason'),
'description' => _kt('Please specify why you are checking out this document. It will assist other users in understanding why you have locked this file. Please bear in mind that you can use a maximum of <strong>250</strong> characters.'),
'name' => 'reason',
)),
array('ktcore.widgets.boolean', array(
'label' => _kt('Download File'),
'description' => _kt('Indicate whether you would like to download this file as part of the checkout.'),
'name' => 'download_file',
'value' => true,
)),
));
$oForm->setValidators(array(
array('ktcore.validators.string', array(
'test' => 'reason',
'max_length' => 250,
'output' => 'reason',
)),
array('ktcore.validators.boolean', array(
'test' => 'download_file',
'output' => 'download_file',
)),
));
return $oForm;
}
function do_main() {
$this->oPage->setBreadcrumbDetails(_kt('checkout'));
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout');
$oForm = $this->form_checkout();
$oTemplate->setData(array(
'context' => &$this,
'form' => $oForm,
));
return $oTemplate->render();
}
function do_checkout() {
$oForm = $this->form_checkout();
$res = $oForm->validate();
if (!empty($res['errors'])) {
return $oForm->handleError();
}
$data = $res['results'];
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkout_final');
$sReason = $data['reason'];
$this->startTransaction();
$res = KTDocumentUtil::checkout($this->oDocument, $sReason, $this->oUser);
if (PEAR::isError($res)) {
return $this->errorRedirectToMain(sprintf(_kt('Failed to check out the document: %s'), $res->getMessage()));
}
$this->commitTransaction();
if (!$data['download_file']) {
$this->addInfoMessage(_kt('Document checked out.'));
redirect(KTBrowseUtil::getUrlForDocument($this->oDocument));
exit(0);
}
$oTemplate->setData(array(
'context' => &$this,
'reason' => $sReason,
));
return $oTemplate->render();
}
function do_checkout_final() {
$sReason = KTUtil::arrayGet($_REQUEST, 'reason');
$this->oValidator->notEmpty($sReason);
$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;
}
}
$oStorage =& KTStorageManagerUtil::getSingleton();
$oStorage->download($this->oDocument, true);
exit(0);
}
}
// }}}
// {{{ KTDocumentCheckInAction
class KTDocumentCheckInAction extends KTDocumentAction {
var $sName = 'ktcore.actions.document.checkin';
var $_sShowPermission = 'ktcore.permissions.write';
var $sIconClass = 'checkin';
function getDisplayName() {
return _kt('Checkin');
}
function getButton() {
$btn = array();
$btn['display_text'] = _kt('Check Document In');
$btn['arrow_class'] = 'arrow_upload';
return $btn;
}
function getInfo() {
if (!$this->oDocument->getIsCheckedOut()) {
return null;
}
if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) {
return null;
}
return parent::getInfo();
}
function check() {
$res = parent::check();
if ($res !== true) {
return $res;
}
$postExpected = KTUtil::arrayGet($_REQUEST, 'postExpected');
$postReceived = KTUtil::arrayGet($_REQUEST, 'postReceived');
if (!empty($postExpected)) {
$aErrorOptions = array(
'redirect_to' => array('main', sprintf('fDocumentId=%d', $this->oDocument->getId())),
'message' => sprintf(_kt('Upload larger than maximum POST size: %s (post_max_size variable in .htaccess or php.ini)'), ini_get('post_max_size')),
);
$this->oValidator->notEmpty($postReceived, $aErrorOptions);
}
if (!$this->oDocument->getIsCheckedOut()) {
$_SESSION['KTErrorMessage'][] = _kt('This document is not checked out');
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
exit(0);
}
if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) {
$_SESSION['KTErrorMessage'][] = _kt('This document is checked out, but not by you');
controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId());
exit(0);
}
return true;
}
function form_main() {
$oForm = new KTForm;
$oForm->setOptions(array(
'label' => _kt('Checkin Document'),
'action' => 'checkin',
'actionparams' => 'postExpected=1&fDocumentId='.$this->oDocument->getId(),
'fail_action' => 'main',
'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),
'submit_label' => _kt('Checkin'),
'context' => &$this,
'file_upload' => true, // otherwise the post is not received.
));
$major_inc = sprintf('%d.%d', $this->oDocument->getMajorVersionNumber()+1, 0);
$minor_inc = sprintf('%d.%d', $this->oDocument->getMajorVersionNumber(), $this->oDocument->getMinorVersionNumber()+1);
// Set the widgets for the form
$aWidgets = array(
array('ktcore.widgets.file', array(
'label' => _kt('File'),
'description' => sprintf(_kt('Please specify the file you wish to upload. Unless you also indicate that you are changing its filename (see "Force Original Filename" below), this will need to be called <strong>%s</strong>'), htmlentities($this->oDocument->getFilename(),ENT_QUOTES,'UTF-8')),
'name' => 'file',
'basename' => 'file',
'required' => true,
)),
array('ktcore.widgets.boolean',array(
'label' => _kt('Major Update'),
'description' => sprintf(_kt('If this is checked, then the document\'s version number will be increased to %s. Otherwise, it will be considered a minor update, and the version number will be %s.'), $major_inc, $minor_inc),
'name' => 'major_update',
'value' => false,
)),
array('ktcore.widgets.reason', array(
'label' => _kt('Reason'),
'description' => _kt('Please describe the changes you made to the document. Bear in mind that you can use a maximum of <strong>250</strong> characters.'),
'name' => 'reason',
)),
);
// Set the validators for the widgets
$aValidators = array(
array('ktcore.validators.string', array(
'test' => 'reason',
'max_length' => 250,
'output' => 'reason',
)),
array('ktcore.validators.boolean', array(
'test' => 'major_update',
'output' => 'major_update',
)),
array('ktcore.validators.file', array(
'test' => 'file',
'output' => 'file',
)),
);
// Add the "Force Original Filename" option if applicable
global $default;
if(!$default->disableForceFilenameOption){
$aWidgets[] = array('ktcore.widgets.boolean',array(
'label' => _kt('Force Original Filename'),
'description' => sprintf(_kt('If this is checked, the uploaded document must have the same filename as the original: <strong>%s</strong>'), htmlentities($this->oDocument->getFilename(),ENT_QUOTES,'UTF-8')),
'name' => 'forcefilename',
'value' => true,
));
$aValidators[] = array('ktcore.validators.boolean', array(
'test' => 'forcefilename',
'output' => 'forcefilename',
));
}
// Add widgets and validators to the form
$oForm->setWidgets($aWidgets);
$oForm->setValidators($aValidators);
return $oForm;
}
function do_main() {
$this->oPage->setBreadcrumbDetails(_kt('Checkin'));
$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/checkin');
$oForm = $this->form_main();
$oTemplate->setData(array(
'context' => &$this,
'form' => $oForm,
));
return $oTemplate->render();
}
function do_checkin() {
$oForm = $this->form_main();
$res = $oForm->validate();
$data = $res['results'];
$extra_errors = array();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?