ktdocumentactions.php.svn-base
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· SVN-BASE 代码 · 共 1,742 行 · 第 1/5 页
SVN-BASE
1,742 行
$oForm->setWidgets(array( array('ktcore.widgets.foldercollection', array( 'label' => _kt('Target Folder'), 'description' => _kt('Use the folder collection and path below select the folder into which you wish to move the document.'), 'required' => true, 'name' => 'browse', 'folder_id' => $this->oDocument->getFolderID(), )), array('ktcore.widgets.reason', array( 'label' => _kt('Reason'), 'description' => _kt('Please specify why you are moving this document. 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', )), array('ktcore.validators.entity', array( 'class' => 'Folder', 'test' => 'browse', 'output' => 'browse', )), )); // here's the ugly bit. $err = $oForm->getErrors(); if (!empty($err['name']) || !empty($err['filename'])) { $oForm->addWidget( array('ktcore.widgets.string', array( 'label' => _kt('Document Title'), 'value' => sanitizeForHTML($this->oDocument->getName()), 'important_description' => _kt('Please indicate a new title to use to resolve any title conflicts.'), 'name' => 'name', 'required' => true, )) ); $oForm->addValidator( array('ktcore.validators.string', array( 'output' => 'name', 'test' => 'name' )) ); $oForm->addWidget( array('ktcore.widgets.string', array( 'label' => _kt('Filename'), 'value' => sanitizeForHTML($this->oDocument->getFilename()), 'important_description' => _kt('Please indicate a new filename to use to resolve any conflicts.'), 'name' => 'filename', 'required' => true, )) ); $oForm->addValidator( array('ktcore.validators.string', array( 'output' => 'filename', 'test' => 'filename' )) ); } return $oForm; } function do_move() { $oForm = $this->form_move(); $res = $oForm->validate(); $errors = $res['errors']; $data = $res['results']; $sReason = $data['reason']; $extra_errors = array(); if (!is_null($data['browse'])) { if ($data['browse']->getId() == $this->oDocument->getFolderID()) { $extra_errors['browse'] = _kt('You cannot move the document within the same folder.'); } else { $bNameClash = KTDocumentUtil::nameExists($data['browse'], $this->oDocument->getName()); if ($bNameClash && isset($data['name'])) { $name = $data['name']; $bNameClash = KTDocumentUtil::nameExists($data['browse'], $name); } else { $name = $this->oDocument->getName(); } if ($bNameClash) { $extra_errors['name'] = _kt('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); } $bFileClash = KTDocumentUtil::fileExists($data['browse'], $this->oDocument->getFilename()); if ($bFileClash && isset($data['filename'])) { $filename = $data['filename']; $bFileClash = KTDocumentUtil::fileExists($data['browse'], $filename); } else { $filename = $this->oDocument->getFilename(); } if ($bFileClash) { $extra_errors['filename'] = _kt('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); } if (!Permission::userHasFolderWritePermission($data['browse'])) { $extra_errors['browse'] = _kt('You do not have permission to create new documents in that folder.'); } } } if (!empty($errors) || !empty($extra_errors)) { return $oForm->handleError(null, $extra_errors); } $this->startTransaction(); // now try update it. $res = KTDocumentUtil::move($this->oDocument, $data['browse'], $this->oUser, $sReason); if (PEAR::isError($oNewDoc)) { $this->errorRedirectTo('main', _kt('Failed to move document: ') . $oNewDoc->getMessage()); exit(0); } $this->oDocument->setName($name); // if needed. $this->oDocument->setFilename($filename); // if needed. $res = $this->oDocument->update(); if (PEAR::isError($res)) { return $this->errorRedirectTo('main', _kt('Failed to move document: ') . $res->getMessage()); } $this->commitTransaction(); controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); }}// }}}class KTDocumentCopyColumn extends TitleColumn { function KTDocumentCopyColumn($sLabel, $sName, $oDocument) { $this->oDocument = $oDocument; parent::TitleColumn($sLabel, $sName); } function buildFolderLink($aDataRow) { return KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $aDataRow['folder']->getId())); }}// {{{ KTDocumentMoveActionclass KTDocumentCopyAction extends KTDocumentAction { var $sName = 'ktcore.actions.document.copy'; var $_sShowPermission = 'ktcore.permissions.read'; function getDisplayName() { return _kt('Copy'); } 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 copied because it is checked out'); controllerRedirect('viewDocument', 'fDocumentId=' . $this->oDocument->getId()); exit(0); } $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 form_copyselection() { $oForm = new KTForm; $oForm->setOptions(array( 'label' => _kt('Copy Document'), 'submit_label' => _kt('Copy'), 'identifier' => 'ktcore.actions.copydoc', 'action' => 'copy', '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. */ $oForm->setWidgets(array( array('ktcore.widgets.foldercollection', array( 'label' => _kt('Target Folder'), 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to copy the documents into.'), 'required' => true, 'name' => 'browse', 'folder_id' => $this->oDocument->getFolderID(), )), array('ktcore.widgets.reason', array( 'label' => _kt('Reason'), 'description' => _kt('Please specify why you are copying this document. 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', )), array('ktcore.validators.entity', array( 'class' => 'Folder', 'test' => 'browse', 'output' => 'browse', )), )); // here's the ugly bit. $err = $oForm->getErrors(); if (!empty($err['name']) || !empty($err['filename'])) { $oForm->addWidget( array('ktcore.widgets.string', array( 'label' => _kt('Document Title'), 'value' => sanitizeForHTML($this->oDocument->getName()), 'important_description' => _kt('Please indicate a new title to use to resolve any title conflicts.'), 'name' => 'name', 'required' => true, )) ); $oForm->addValidator( array('ktcore.validators.string', array( 'output' => 'name', 'test' => 'name' )) ); $oForm->addWidget( array('ktcore.widgets.string', array( 'label' => _kt('Filename'), 'value' => sanitizeForHTML($this->oDocument->getFilename()), 'important_description' => _kt('Please indicate a new filename to use to resolve any conflicts.'), 'name' => 'filename', 'required' => true, )) ); $oForm->addValidator( array('ktcore.validators.string', array( 'output' => 'filename', 'test' => 'filename' )) ); } return $oForm; } function do_main() { $this->oPage->setBreadcrumbDetails(_kt('Copy')); $oForm = $this->form_copyselection(); return $oForm->renderPage(_kt('Copy Document') . ': ' . $this->oDocument->getName()); } function do_copy() { $oForm = $this->form_copyselection(); $res = $oForm->validate(); $errors = $res['errors']; $data = $res['results']; $sReason = $data['reason']; $extra_errors = array(); if (!is_null($data['browse'])) { $bNameClash = KTDocumentUtil::nameExists($data['browse'], $this->oDocument->getName()); if ($bNameClash && isset($data['name'])) { $name = $data['name']; $bNameClash = KTDocumentUtil::nameExists($data['browse'], $name); } else { $name = $this->oDocument->getName(); } if ($bNameClash) { $extra_errors['name'] = _kt('A document with this title already exists in your chosen folder. Please choose a different folder, or specify a new title for the copied document.'); } $bFileClash = KTDocumentUtil::fileExists($data['browse'], $this->oDocument->getFilename()); if ($bFileClash && isset($data['filename'])) { $filename = $data['filename']; $bFileClash = KTDocumentUtil::fileExists($data['browse'], $filename); } else { $filename = $this->oDocument->getFilename(); } if ($bFileClash) { $extra_errors['filename'] = _kt('A document with this filename already exists in your chosen folder. Please choose a different folder, or specify a new filename for the copied document.'); } if (!Permission::userHasFolderWritePermission($data['browse'])) { $extra_errors['browse'] = _kt('You do not have permission to create new documents in that folder.'); } } if (!empty($errors) || !empty($extra_errors)) { return $oForm->handleError(null, $extra_errors); } // FIXME agree on document-duplication rules re: naming, etc. $this->startTransaction(); // now try update it. $oNewDoc = KTDocumentUtil::copy($this->oDocument, $data['browse'], $sReason); if (PEAR::isError($oNewDoc)) { $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $oNewDoc->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId())); exit(0); } $oNewDoc->setName($name); $oNewDoc->setFilename($filename); $res = $oNewDoc->update(); if (PEAR::isError($res)) { return $this->errorRedirectTo('main', _kt('Failed to copy document: ') . $res->getMessage(), sprintf('fDocumentId=%d&fFolderId=%d', $this->oDocument->getId(), $this->oFolder->getId())); } $this->commitTransaction(); $_SESSION['KTInfoMessage'][] = _kt('Document copied.'); controllerRedirect('viewDocument', 'fDocumentId=' . $oNewDoc->getId()); exit(0); }}// }}}// {{{ KTDocumentArchiveActionclass KTDocumentArchiveAction extends KTDocumentAction { var $sName = 'ktcore.actions.document.archive';
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?