newworkflow.inc.php

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

PHP
410
字号
<?php
/**
 * $Id: newworkflow.inc.php 8491 2008-05-21 14:28:28Z megan_w $
 *
 * KnowledgeTree Community Edition
 * Document Management Made Simple
 * Copyright (C) 2008 KnowledgeTree Inc.
 * Portions copyright The Jam Warehouse Software (Pty) Limited
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 3 as published by the
 * Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * You can contact KnowledgeTree Inc., PO Box 7775 #87847, San Francisco,
 * California 94120-7775, or email info@knowledgetree.com.
 *
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU General Public License version 3.
 *
 * In accordance with Section 7(b) of the GNU General Public License version 3,
 * these Appropriate Legal Notices must retain the display of the "Powered by
 * KnowledgeTree" logo and retain the original copyright notice. If the display of the
 * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices
 * must display the words "Powered by KnowledgeTree" and retain the original
 * copyright notice.
 * Contributor( s): ______________________________________
 */

// core
require_once(KT_LIB_DIR . "/dispatcher.inc.php");

// workflow
require_once(KT_LIB_DIR . '/workflow/workflow.inc.php');
require_once(KT_LIB_DIR . '/workflow/workflowstate.inc.php');
require_once(KT_LIB_DIR . '/workflow/workflowtransition.inc.php');
require_once(KT_LIB_DIR . '/workflow/workflowstatepermissionsassignment.inc.php');
require_once(KT_LIB_DIR . '/workflow/workflowutil.inc.php');
require_once(KT_LIB_DIR . '/workflow/workflowadminutil.inc.php');

// other
require_once(KT_LIB_DIR . '/permissions/permission.inc.php');
require_once(KT_LIB_DIR . '/actions/documentaction.inc.php');
require_once(KT_LIB_DIR . '/widgets/portlet.inc.php');
require_once(KT_LIB_DIR . '/users/User.inc');
require_once(KT_LIB_DIR . '/groups/Group.inc');
require_once(KT_LIB_DIR . '/roles/Role.inc');
require_once(KT_LIB_DIR . '/widgets/portlet.inc.php');
require_once(KT_LIB_DIR . '/widgets/forms.inc.php');

class KTNewWorkflowWizard extends KTAdminDispatcher {
    function predispatch() {
        $this->persistParams(array('fWizardKey'));
    }

    function &form_step1() {
        $oForm = new KTForm;

        $oForm->setOptions(array(
            'action' => 'process_step1',
            'cancel_url' => KTUtil::addQueryStringSelf(''), // NBM:  is there a cleaner way to reference the parent?
            'fail_action' => 'main',
            'label' => _kt('Workflow Details'),
            'submit_label' => _kt('Next'),
            'description' => _kt('This first step requires that you provide basic details about the workflow: its name, etc.'),
            'context' => $this,
        ));
        $oForm->setWidgets(array(
            array('ktcore.widgets.string',array(
                'label' => _kt('Workflow Name'),
                'description' => _kt('Each workflow must have a unique name.'),
                'required' => true,
                'name' => 'workflow_name',
            )),
            array('ktcore.widgets.text',array(
                'label' => _kt('States'),
                'description' => _kt('As documents progress through their lifecycle, they pass through a number of <strong>states</strong>.  These states describe a step in the process the document must follow.  Examples of states include "reviewed","submitted" or "pending".  Please enter a list of states, one per line.  State names must be unique.'),
                'important_description' => _kt('Note that the first state you list is the one in which documents will start the workflow - this can be changed later on. '),
                'required' => true,
                'name' => 'states',
                'rows' => 15,
            )),
            array('ktcore.widgets.text',array(
                'label' => _kt('Transitions'),
                'description' => _kt('In order to move between states, users will cause "transitions" to occur.  These transitions represent processes followed, e.g. "review document", "distribute invoice" or "publish".  Please enter a list of transitions, one per line.  Transition names must be unique.  You\'ll assign transitions to states in the next step.'),
                'required' => false,
                'name' => 'transitions',
            )),
            array('ktcore.widgets.hidden',array(
                'required' => false,
                'name' => 'fWizardKey',
                'value' =>  KTUtil::randomString()
            )),
        ));

        $oForm->setValidators(array(
            array('ktcore.validators.string', array(
                'test' => 'workflow_name',
                'output' => 'workflow_name',
            )),
            array('ktcore.validators.string', array(
                'test' => 'fWizardKey',
                'output' => 'fWizardKey',
            )),
            array('ktcore.validators.string', array(
                'test' => 'states',
                'output' => 'states',
                'max_length' => 9999,
            )),
            array('ktcore.validators.string', array(
                'test' => 'transitions',
                'output' => 'transitions',
                'max_length' => 9999,
            )),
        ));

        return $oForm;
    }

    function do_main() {
        $oTemplate =& $this->oValidator->validateTemplate('ktcore/workflow/admin/new_wizard_step1');

        $oForm =& $this->form_step1();

        $oTemplate->setData(array(
            'context' => $this,
            'form' => $oForm,
        ));
        return $oTemplate->render();
    }

    function do_process_step1() {

    	 $fWizardKey = KTUtil::arrayGet($_REQUEST, 'fWizardKey');
    	if (!empty($fWizardKey))
    	{
    		 $this->errorRedirectToMain(_kt("Could not create workflow.") );
    		 exit;
    	}

        $oForm =& $this->form_step1();
        $res = $oForm->validate();
        $data = $res['results'];
        // perform additional validation.
        $extra_errors = array();

        $data['workflow_name'] = str_replace(array('   ', '  '), array(' ', ' '), $data['workflow_name']);
        $oWorkflow = KTWorkflow::getByName($data['workflow_name']);
        if (!PEAR::isError($oWorkflow)) {
            $extra_errors['workflow_name'][] = _kt("A workflow with that name already exists.  Please choose a different name for this workflow.");
        }

        $initial_states = (array) explode("\n", $data['states']);   // must be there, we validated it.
        $failed = array();
        $states = array();
        $is_first = true;
        $initial_state = '';
        foreach ($initial_states as $sInitialStateName) {
            $state_name = trim($sInitialStateName);
            if (empty($state_name)) {
                continue;
            }

            if ($states[$state_name]) {
                $failed[] = $state_name;
                continue;
            }
            if ($is_first) {
                $is_first = false;
                $initial_state = $state_name;
            }
            $states[$state_name] = $state_name;
        }
        if (empty($states)) {
            $extra_errors['states'][] = _kt('You must provide at least one state name.');
        }
        if (!empty($failed)) {
            $extra_errors['states'] = sprintf(_kt("You cannot have duplicate state names: %s"), implode(', ', $failed));
        }
        $data['states'] = $states;
        $data['initial_state'] = $initial_state;

        $initial_transitions = (array) explode("\n", $data['transitions']);   // must be there, we validated it.
        $failed = array();
        $transitions = array();
        foreach ($initial_transitions as $sInitialTransitionName) {
            $transition_name = trim($sInitialTransitionName);
            if (empty($transition_name)) {
                continue;
            }

            if ($transitions[$transition_name]) {
                $failed[] = $transition_name;
                continue;
            }

            $transitions[$transition_name] = $transition_name;

⌨️ 快捷键说明

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