ktdocumentactions.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 1,742 行 · 第 1/5 页
SVN-BASE
1,742 行
$sReason = $data['reason']; $sCurrentFilename = $docFileName; $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'; function getDisplayName() { return _kt('Cancel Checkout'); } function getInfo() { if (!$this->oDocument->getIsCheckedOut()) { return null; } if (is_null($this->bInAdminMode)) { $oFolder = Folder::get($this->oDocument->getFolderId()); if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) { $this->bAdminMode = true; return parent::getInfo(); } } else if ($this->bInAdminMode == true) { return parent::getInfo(); } if ($this->oDocument->getCheckedOutUserID() != $this->oUser->getId()) { return null; } return parent::getInfo(); } function check() { $res = parent::check(); if ($res !== true) { return $res; } if (!$this->oDocument->getIsCheckedOut()) { $_SESSION['KTErrorMessage'][] = _kt('This document is not checked out'); controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); } // hard override if we're in admin mode for this doc. if (is_null($this->bInAdminMode)) { $oFolder = Folder::get($this->oDocument->getFolderId()); if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) { $this->bAdminMode = true; return true; } } else if ($this->bInAdminMode == true) { return true; } 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('Cancel Checkout'), 'action' => 'checkin', 'fail_action' => 'main', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'submit_label' => _kt('Cancel Checkout'), 'context' => &$this, )); $oForm->setWidgets(array( array('ktcore.widgets.reason', array( 'label' => _kt('Reason'), 'description' => _kt('Please specify why you are cancelling this document\'s checked-out status. Please bear in mind that you can use a maximum of <strong>250</strong> characters.'), 'name' => 'reason', )), )); $oForm->setValidators(array( array('ktcore.validators.string', array( 'test' => 'reason', 'max_length' => 250, 'output' => 'reason', )), )); return $oForm; } function do_main() { $this->oPage->setBreadcrumbDetails(_kt('cancel checkout')); $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/cancel_checkout'); $oForm = $this->form_main(); $oTemplate->setData(array( 'context' => &$this, 'form' => $oForm, 'document' => $this->oDocument, )); return $oTemplate->render(); } function do_checkin() { $oForm = $this->form_main(); $res = $oForm->validate(); if (!empty($res['errors'])) { return $oForm->handleError(); } $data = $res['results']; $this->startTransaction(); // actually do the checkin. $this->oDocument->setIsCheckedOut(0); $this->oDocument->setCheckedOutUserID(-1); $res = $this->oDocument->update(); if (PEAR::isError($res) || ($res === false)) { $this->rollbackTransaction(); return $this->errorRedirectToMain(_kt('Failed to force the document\'s checkin.'),sprintf('fDocumentId=%d'),$this->oDocument->getId()); } // checkout cancelled transaction $oDocumentTransaction = & new DocumentTransaction($this->oDocument, $data['reason'], 'ktcore.transactions.force_checkin'); $res = $oDocumentTransaction->create(); if (PEAR::isError($res) || ($res === false)) { $this->rollbackTransaction(); return $this->errorRedirectToMain(_kt('Failed to force the document\'s checkin.'),sprintf('fDocumentId=%d'),$this->oDocument->getId()); } $this->commitTransaction(); redirect(KTBrowseUtil::getUrlForDocument($this->oDocument)); }}// }}}// {{{ KTDocumentDeleteActionclass KTDocumentDeleteAction extends KTDocumentAction { var $sName = 'ktcore.actions.document.delete'; var $_sShowPermission = 'ktcore.permissions.delete'; var $_bMutator = true; function getDisplayName() { return _kt('Delete'); } function getInfo() { if ($this->oDocument->getIsCheckedOut()) { return null; } return parent::getInfo(); } function check() { $res = parent::check(); if ($res !== true) { return $res; } if ($this->oDocument->getIsCheckedOut()) { $_SESSION['KTErrorMessage'][]= _kt('This document can\'t be deleted because it is checked out'); controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); } return true; } function form_confirm() { $oForm = new KTForm; $oForm->setOptions(array( 'label' => _kt('Are you sure?'), 'description' => _kt('There are shortcuts linking to this document; deleting the document will automatically delete them. Would you like to continue?'), 'action' => 'main', 'fail_action' => 'main', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'submit_label' => _kt('Delete Document'), 'context' => &$this, )); return $oForm; } function form_main() { $oForm = new KTForm; $oForm->setOptions(array( 'label' => _kt('Delete Document'), 'action' => 'delete', 'fail_action' => 'main', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'submit_label' => _kt('Delete Document'), 'context' => &$this, )); $oForm->setWidgets(array( array('ktcore.widgets.reason', array( 'label' => _kt('Reason'), 'description' => _kt('Please specify why you are deleting this document. Please bear in mind that you can use a maximum of <strong>250</strong> characters.'), 'name' => 'reason', )), )); $oForm->setValidators(array( array('ktcore.validators.string', array( 'test' => 'reason', 'max_length' => 250, 'output' => 'reason', )), )); return $oForm; } function do_main() { $this->oPage->setBreadcrumbDetails(_kt('Delete')); //check if we need confirmation for symblolic links linking to this document if(count($this->oDocument->getSymbolicLinks())>0 && KTutil::arrayGet($_REQUEST,'postReceived') != 1){ $this->redirectTo("confirm"); } $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/delete'); $oForm = $this->form_main(); $oTemplate->setData(array( 'context' => &$this, 'form' => $oForm, )); return $oTemplate->render(); } function do_confirm(){ $this->oPage->setBreadcrumbDetails(_kt('Confirm delete')); $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/delete_confirm'); $oForm = $this->form_confirm(); $oTemplate->setData(array( 'context' => &$this, 'form' => $oForm, )); return $oTemplate->render(); } function do_delete() { $oForm = $this->form_main(); $res = $oForm->validate(); $data = $res['results']; if (!empty($res['errors'])) { return $oForm->handleError(); } $sReason = $data['reason']; $fFolderId = $this->oDocument->getFolderId(); $res = KTDocumentUtil::delete($this->oDocument, $sReason); if (PEAR::isError($res)) { $this->errorRedirectToMain(sprintf(_kt('Unexpected failure deleting document: %s'), $res->getMessage())); } $_SESSION['KTInfoMessage'][] = sprintf(_kt('Document "%s" Deleted.'),$this->oDocument->getName()); controllerRedirect('browse', 'fFolderId=' . $fFolderId); exit(0); }}// }}}// {{{ KTDocumentMoveActionclass KTDocumentMoveAction extends KTDocumentAction { var $sName = 'ktcore.actions.document.move'; var $_sShowPermission = 'ktcore.permissions.write'; var $_bMutator = true; function getDisplayName() { return _kt('Move'); } function getInfo() { if ($this->oDocument->getIsCheckedOut()) { return null; } return parent::getInfo(); } function check() { $res = parent::check(); if ($res !== true) { return $res; } if ($this->oDocument->getIsCheckedOut()) { $_SESSION['KTErrorMessage'][]= _kt('This document can\'t be moved because it is checked out'); controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); } $this->persistParams(array('fFolderId')); $iFolderId = KTUtil::arrayGet($_REQUEST, 'fFolderId', $this->oDocument->getFolderId()); $this->oFolder = $this->oValidator->validateFolder($iFolderId); $this->oDocumentFolder = $this->oValidator->validateFolder($this->oDocument->getFolderId()); return true; } function do_main() { $oForm = $this->form_move(); return $oForm->renderPage(_kt('Move Document') . ': ' . $this->oDocument->getName()); } function form_move() { $oForm = new KTForm; $oForm->setOptions(array( 'label' => _kt('Move Document'), 'submit_label' => _kt('Move'), 'identifier' => 'ktcore.actions.movedoc', 'action' => 'move', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'fail_action' => 'main', 'context' => $this, )); /* * This is somewhat more complex than most forms, since the "filename" * and title shouldn't appear unless there's a clash. * * This is still not the most elegant solution. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?