ktdocumentactions.php.tmp

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

TMP
1,749
字号
            'submit_label' => _kt('Archive Document'),            'context' => &$this,        ));        $oForm->setWidgets(array(            array('ktcore.widgets.reason', array(                'label' => _kt('Reason'),                'description' => _kt('Please specify why you are archiving 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() {		//if there are symbolic links linking to this document we need confirmation    	if(count($this->oDocument->getSymbolicLinks())>0 && KTutil::arrayGet($_REQUEST,'postReceived') != 1){        	$this->redirectTo("confirm");        }        $this->oPage->setBreadcrumbDetails(_kt('Archive Document'));        $oTemplate =& $this->oValidator->validateTemplate('ktcore/action/archive');        $oForm = $this->form_main();        $oTemplate->setData(array(            'context' => &$this,            'form' => $oForm,        ));        return $oTemplate->render();    }    	function do_confirm(){    	$this->oPage->setBreadcrumbDetails(_kt('Confirm archive'));    	$oTemplate =& $this->oValidator->validateTemplate('ktcore/action/archive_confirm');        $oForm = $this->form_confirm();    	$oTemplate->setData(array(            'context' => &$this,            'form' => $oForm,        ));        return $oTemplate->render();    }    function do_archive() {        $oForm = $this->form_main();        $res = $oForm->validate();        $data = $res['results'];        if (!empty($res['errors'])) {            return $oForm->handleError();        }        $sReason = $data['reason'];        $res = KTDocumentUtil::archive($this->oDocument, $sReason);        if(PEAR::isError($res)){            $_SESSION['KTErrorMessage'][] = $res->getMessage();            controllerRedirect('viewDocument', 'fDocumentId=' .  $this->oDocument->getId());            exit(0);        }        $_SESSION['KTInfoMessage'][] = _kt('Document archived.');        controllerRedirect('browse', 'fFolderId=' .  $this->oDocument->getFolderID());        exit(0);    }}// }}}// {{{ KTDocumentWorkflowActionclass KTDocumentWorkflowAction extends KTDocumentAction {    var $sName = 'ktcore.actions.document.workflow';    var $_sShowPermission = 'ktcore.permissions.read';    var $sHelpPage = 'ktcore/user/workflow.html';    function predispatch() {        $this->persistParams(array('fTransitionId'));    }    function getDisplayName() {        return _kt('Workflow');    }    function getInfo() {        if ($this->oDocument->getIsCheckedOut()) {            return null;        }        return parent::getInfo();    }    function do_main() {        $this->oPage->setBreadcrumbDetails(_kt('workflow'));        $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/documentWorkflow');        $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);        $oWorkflow = KTWorkflowUtil::getWorkflowForDocument($oDocument);        $oWorkflowState = KTWorkflowUtil::getWorkflowStateForDocument($oDocument);        $oUser =& User::get($_SESSION['userID']);        // If the document is checked out - set transitions and workflows to empty and set checkedout to true        $bIsCheckedOut = $this->oDocument->getIsCheckedOut();        if ($bIsCheckedOut){            $aTransitions = array();            $aWorkflows = array();            $transition_fields = array();            $bHasPerm = FALSE;        }else{            $aTransitions = KTWorkflowUtil::getTransitionsForDocumentUser($oDocument, $oUser);            $aWorkflows = KTWorkflow::getList('start_state_id IS NOT NULL AND enabled = 1 ');            $bHasPerm = false;            if (KTPermissionUtil::userHasPermissionOnItem($oUser, 'ktcore.permissions.workflow', $oDocument)) {                $bHasPerm = true;            }            $fieldErrors = null;            $transition_fields = array();            if ($aTransitions) {                $aVocab = array();                foreach ($aTransitions as $oTransition) {                	if(is_null($oTransition) || PEAR::isError($oTransition)){                		continue;                	}                    $aVocab[$oTransition->getId()] = $oTransition->showDescription();                }                $fieldOptions = array('vocab' => $aVocab);                $transition_fields[] = new KTLookupWidget(_kt('Transition to perform'), _kt('The transition listed will cause the document to change from its current state to the listed destination state.'), 'fTransitionId', null, $this->oPage, true, null, $fieldErrors, $fieldOptions);                $transition_fields[] = new KTTextWidget(                    _kt('Reason for transition'), _kt('Describe why this document qualifies to be changed from its current state to the destination state of the transition chosen.'),                    'fComments', '',                    $this->oPage, true, null, null,                    array('cols' => 80, 'rows' => 4));            }        }        $aTemplateData = array(            'oDocument' => $oDocument,            'oWorkflow' => $oWorkflow,            'oState' => $oWorkflowState,            'aTransitions' => $aTransitions,            'aWorkflows' => $aWorkflows,            'transition_fields' => $transition_fields,            'bHasPerm' => $bHasPerm,            'bIsCheckedOut' => $bIsCheckedOut,        );        return $oTemplate->render($aTemplateData);    }    function do_startWorkflow() {        $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);        if (!empty($_REQUEST['fWorkflowId'])) {            $oWorkflow =& $this->oValidator->validateWorkflow($_REQUEST['fWorkflowId']);        } else {            $oWorkflow = null;        }        $res = KTWorkflowUtil::startWorkflowOnDocument($oWorkflow, $oDocument);        if (PEAR::isError($res)) {            $this->errorRedirectToMain($res->message, sprintf('fDocumentId=%s',$oDocument->getId()));        }        $this->successRedirectToMain(_kt('Workflow started'),                array('fDocumentId' => $oDocument->getId()));        exit(0);    }    function do_performTransition() {        $oDocument =& $this->oValidator->validateDocument($_REQUEST['fDocumentId']);        $oTransition =& $this->oValidator->validateWorkflowTransition($_REQUEST['fTransitionId']);        $aErrorOptions = array(            'redirect_to' => array('main', sprintf('fDocumentId=%d', $_REQUEST['fDocumentId'])),            'message' => _kt('You must provide a reason for the transition'),        );        $sComments =& $this->oValidator->validateString($_REQUEST['fComments'], $aErrorOptions);        $oUser =& User::get($_SESSION['userID']);        $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $oDocument, $oUser, $sComments);        if(!Permission::userHasDocumentReadPermission($oDocument)) {            $this->commitTransaction();            $_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document');            controllerRedirect('browse', sprintf('fFolderId=%d', $oDocument->getFolderId()));        } else {            $this->successRedirectToMain(_kt('Transition performed'),            array('fDocumentId' => $oDocument->getId()));        }    }    function form_quicktransition() {        $oForm = new KTForm;        if($this->oDocument->getIsCheckedOut()){            $this->addErrorMessage(_kt('The workflow cannot be changed while the document is checked out.'));        }else{            $oForm->setOptions(array(                'identifier' => 'ktcore.workflow.quicktransition',                'label' => _kt('Perform Quick Transition'),                'submit_label' => _kt('Perform Transition'),                'context' => $this,                'action' => 'performquicktransition',                'fail_action' => 'quicktransition',                'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),            ));            $oForm->setWidgets(array(                array('ktcore.widgets.reason', array(                    'label' => _kt('Reason'),                    'description' => _kt('Specify your reason for performing this action.'),                    'important_description' => _kt('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_quicktransition() {        // make sure this gets through.        $this->persistParams(array('fTransitionId'));        $transition_id = $_REQUEST['fTransitionId'];        $oTransition = KTWorkflowTransition::get($transition_id);        $oForm = $this->form_quicktransition();        return $oForm->renderPage(sprintf(_kt('Perform Transition: %s'), $oTransition->getName()));    }    function do_performquicktransition() {        $oForm = $this->form_quicktransition();        $res = $oForm->validate();        if (!empty($res['errors'])) {            return $oForm->handleError();        }        $this->startTransaction();        $data = $res['results'];        $oTransition = KTWorkflowTransition::get($_REQUEST['fTransitionId']);        $res = KTWorkflowUtil::performTransitionOnDocument($oTransition, $this->oDocument, $this->oUser, $data['reason']);        if(!Permission::userHasDocumentReadPermission($this->oDocument)) {            $this->commitTransaction();            $_SESSION['KTInfoMessage'][] = _kt('Transition performed') . '. ' . _kt('You no longer have permission to view this document');            controllerRedirect('browse', sprintf('fFolderId=%d', $this->oDocument->getFolderId()));        } else {            $this->commitTransaction();            $_SESSION['KTInfoMessage'][] = _kt('Transition performed');            controllerRedirect('viewDocument', sprintf('fDocumentId=%d', $this->oDocument->getId()));        }    }}// }}}class KTOwnershipChangeAction extends KTDocumentAction {    var $sName = 'ktcore.actions.document.ownershipchange';    var $_sShowPermission = 'ktcore.permissions.security';    function getDisplayName() {        return _kt('Change Document Ownership');    }    function form_owner() {        $oForm = new KTForm;        $oForm->setOptions(array(            'label' => _kt('Change Document Ownership'),            'description' => _kt('Changing document ownership allows you to keep the "owner" role relevant, even when the original user no longer is an appropriate choice.'),            'action' => 'reown',            'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument),            'fail_action' => 'main',            'identifier' => 'ktcore.actions.document.owner',            'context' => $this,        ));        $oForm->setWidgets(array(            array('ktcore.widgets.entityselection', array(                'label' => _kt('New Owner'),                'description' => _kt('The owner of a document is usually the person with ultimate responsibility for its contents.  It is initially set to the person who created the document, but can be changed to any other user.'),                'important_description' => _kt('Please note that changing the owner may affect access to this document.'),                'label_method' => 'getName',                'vocab' => User::getList('id > 0'),                'value' => $this->oDocument->getOwnerID(),                'name' => 'user_id'            )),        ));        $oForm->setValidators(array(            array('ktcore.validators.entity', array(                'test' => 'user_id',                'class' => 'User',                'output' => 'user',            )),        ));        return $oForm;    }    function do_main() {        $this->oPage->setBreadcrumbDetails(_kt('Changing Ownership'));        $oTemplate =& $this->oValidator->validateTemplate('ktcore/document/ownershipchangeaction');        $change_form = $this->form_owner();        $oTemplate->setData(array(            'context' => $this,            'form' => $change_form,        ));        return $oTemplate->render();    }    function do_reown() {        $oForm = $this->form_owner();        $res = $oForm->validate();        $data = $res['results'];        $errors = $res['errors'];        if (!empty($errors)) {            return $oForm->handleError();        }        $oUser = $data['user'];        $this->startTransaction();        $this->oDocument->setOwnerID($oUser->getId());        $res = $this->oDocument->update();        if (PEAR::isError($res)) {            $this->errorRedirectToMain(sprintf(_kt('Failed to update 

⌨️ 快捷键说明

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