ktdocumentactions.php.tmp
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· TMP 代码 · 共 1,749 行 · 第 1/5 页
TMP
1,749 行
$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); }}// }}}// {{{ KTDocumentCheckOutActionclass 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); }}// }}}// {{{ KTDocumentCheckInActionclass KTDocumentCheckInAction extends KTDocumentAction { var $sName = 'ktcore.actions.document.checkin'; var $_sShowPermission = 'ktcore.permissions.write'; var $sIconClass = 'checkin'; function getDisplayName() { return _kt('Checkin'); } 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); $oForm->setWidgets(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', )), 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, )), )); $oForm->setValidators(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', )), array('ktcore.validators.boolean', array( 'test' => 'forcefilename', 'output' => 'forcefilename', )), )); 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(); if ($data['forcefilename'] && ($data['file']['name'] != $this->oDocument->getFilename())) { $extra_errors['file'] = sprintf(_kt('The file you uploaded was not called "%s". If you wish to change the filename, please set "Force Original Filename" below to false. '), htmlentities($this->oDocument->getFilename(),ENT_QUOTES,'UTF-8')); } if (!empty($res['errors']) || !empty($extra_errors)) { return $oForm->handleError(null, $extra_errors); } $sReason = $data['reason']; $sCurrentFilename = $this->oDocument->getFileName(); $sNewFilename = $data['file']['name']; $aOptions = array(); if ($data['major_update']) { $aOptions['major_update'] = true; } if ($sCurrentFilename != $sNewFilename) { $aOptions['newfilename'] = $sNewFilename; } $res = KTDocumentUtil::checkin($this->oDocument, $data['file']['tmp_name'], $sReason, $this->oUser, $aOptions); if (PEAR::isError($res)) { $this->errorRedirectToMain(_kt('An error occurred while trying to check in the document'), 'fDocumentId=' . $this->oDocument->getId() . '&reason=' . $sReason); } redirect(KTBrowseUtil::getUrlForDocument($this->oDocument)); exit(0); }}// }}}// {{{ KTDocumentCancelCheckOutActionclass KTDocumentCancelCheckOutAction extends KTDocumentAction { var $sName = 'ktcore.actions.document.cancelcheckout'; var $_sShowPermission = 'ktcore.permissions.write'; var $bAllowInAdminMode = true; var $bInAdminMode = null; var $sIconClass = 'cancel_checkout';
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?