ktdocumentactions.php.tmp

来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· TMP 代码 · 共 1,749 行 · 第 1/5 页

TMP
1,749
字号
    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.         */        $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'),

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?