PHP——小尾巴之流程处理

说明:首先新建一个流程,把处理流程的节点人员添加进去,最后点确定提交至数据库

        处理流程:不同用户登录进去处理自己的节点部分对其审核通过

新建两个流程:

第一个为借款流程:处理顺序为:李四发起=>张三=>再见孙悟空

第二个为请假流程:处理顺序为:李四发起=>张三

效果为

lisi先进行处理

 

zhangsan处理完之后

zaijian处理完之后

数据库:

test.php

<?php
    session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="../jquery-1.11.2.min.js"></script>
</head>

<body>
<h1>新建流程</h1>
<div>输入流程名:
    <input type="text" id="liucheng"/>
</div><br />

<div>请选择节点人员:</div><br />
<div>
    <?php
        include("../mydbda.php");
        $db = new mydbda();
        $sqlj = "select * from Users";
        $strj = $db->Select($sqlj,"CX","mydb");
        $hangj = explode("|",$strj);
        for($i=0;$i<count($hangj);$i++)
        {
            list($uid,$pwd,$name) = explode("^",$hangj[$i]);
            echo "<input type='radio' value='{$uid}' class='ry' name='ry'/>{$name}&nbsp;";
        }
    ?>
</div><br />
<input type="button" value="添加节点" id="sure" />
<br /><br />
<div id="biao">
    <?php
        if(isset($_SESSION["liucheng"]))
        {
            $attr = $_SESSION["liucheng"];
            
            for($i=0;$i<count($attr);$i++)
            {
                $sqlu = "select Name from Users where Uid = '".$attr[$i]."'";
                $stru = $db->Select($sqlu,"CX","mydb");
                echo "<div class='jd' bs='".$attr[$i]."'>{$i}.{$stru}--<input type='button' class='delete' bs='".$i."' value='删除'/></div>";
            }
        }
        else
        {
            echo "当前流程节点为空!";
        }
    ?>
</div><br />
<input type="button" value="确定" id="add" />
<br />

</body><br />
<script type="text/javascript">
$(document).ready(function(e) {
    
    //添加节点
    $("#sure").click(function(){
            var user = $(".ry");
            for(var i=0; i<user.length;i++)
            {
                if(user.eq(i)[0].checked == true)
                {
                    var uid = user.eq(i).val();
                    
                    $.ajax({
                        
                            url:"chulilc.php",
                            data:{uid:uid},
                            type:"POST",
                            dataType:"TEXT",
                            success: function(data){
                                    window.location = "test.php";//让页面刷新一下是为了调上面的php代码
                                }
                        
                        });
                }
            }
        
        })
        
    //删除节点
    $(".delete").click(function(){
        
        var ids = $(this).attr("bs");
        
        $.ajax({
                        
                url:"chulisc.php",
                data:{ids:ids},
                type:"POST",
                dataType:"TEXT",
                success: function(data){
                        window.location = "test.php";
                    }
            
            });
        
        })
        
    //添加流程
    $("#add").click(function(){
            
            var name = $("#liucheng").val();
            
            $.ajax({
                
                url:"add.php",
                data:{name:name},
                type:"POST",
                dataType:"TEXT",
                success: function(data){
                        if(data=="OK")
                        {
                            alert("添加成功!");
                        }
                        else
                        {
                            alert("添加失败!");
                        }
                    
                    }
                
                });
        
        })
    
});
</script>
</html>

chulilc.php

<?php
    session_start();
    
    $uid = $_POST["uid"];
    
    //isset判断有没有被附上值
    if(isset($_SESSION["liucheng"]))
    {
        //当第二次运行之后
        $shuzu = $_SESSION["liucheng"];
        array_push($shuzu,$uid);
        $_SESSION["liucheng"] = $shuzu;
    }
    else
    {
        //没有值的时候(第一次运行的时候)  
        //新建数组
        $shuzu = array();
        
        //往数组末尾添加数据
        array_push($shuzu,$uid);
        
        //定义session liucheng
        $_SESSION["liucheng"] = $shuzu;
    }

    
?>

chulisc.php

<?php
    session_start();
    
    $ids = $_POST["ids"];

    $shuzu = $_SESSION["liucheng"];
    unset($shuzu[$ids]); //删除元素
    $shuzu = array_values($shuzu); //重新索引
    $_SESSION["liucheng"] = $shuzu;

?>

add.php

<?php
    session_start();
    
    include("../mydbda.php");
    
    $db = new mydbda();
    
    $name = $_POST["name"];
    
    $code = date("YmdHisms",time());
    
    $sqll = "insert into LiuCheng values('{$code}','{$name}')";
    $db->Select($sqll,"QT","mydb");
    
    $attr = $_SESSION["liucheng"];
    
    for($i=0;$i<count($attr);$i++)
    {
        $sqlj = "insert into FlowPath values('','{$code}','{$attr[$i]}','{$i}')";
        $db->Select($sqlj,"QT","mydb");
    }
    echo "OK";

denglu.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>登录</h1>
<form action="dlchuli.php" method="post">
<div>用户名:<input type="text" name="uid"/></div>
<div>密码:<input type="text" name="pwd"/></div>
<input type="submit" value="登录" />
</form>
</body>
</html>

dlchuli.php

<?php
    session_start();
    include("../mydbda.php");
    $db = new mydbda();
    
    $uid = $_POST["uid"];
    $pwd = $_POST["pwd"];
    
    $sql = "select count(*) from Users where Uid = '{$uid}' and Pwd = '{$pwd}'";
    $str = $db->Select($sql,"CX","mydb");
    
    if($str == "1")
    {
        $_SESSION["uid"] = $uid;
        header("Location:faqi.php");
    }
    else
    {
        header("Location:denglu.php");
    }
    

faqi.php

<?php
    session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="../jquery-1.11.2.min.js"></script>
</head>

<body>
<h1>发起流程</h1>
<div>请选择流程:
<select id="lc">
<?php

    include("../mydbda.php");
    $db = new mydbda();
    
    $sql = "select * from LiuCheng";
    $str = $db->Select($sql,"CX","mydb");
    $hang = explode("|",$str);
    for($i=0;$i<count($hang);$i++)
    {
        list($code,$name) = explode("^",$hang[$i]);
        
        echo "<option value='{$code}'>{$name}</option>";
    }
    
?>
</select>
</div>
<br />
<div>
    <div>请输入流程内容:</div><br />
    <div>
        <textarea id="nr" style="width:400px; height:250px"></textarea>
    </div>
</div>
<br />
<input type="button"  value="确定" id="btn"/>
<a href="chuliliucheng.php">处理</a>
</body>
<script type="text/javascript">
$(document).ready(function(e) {
    $("#btn").click(function(){
        
        var code = $("#lc").val();
        var nr = $("#nr").val();
        
        $.ajax({
            
                url:"faqichuli.php",
                data:{code:code,nr:nr},
                type:"POST",
                dataType:"TEXT",
                success: function(data){
                    
                        if(data == "OK")
                        {
                            alert("发起成功!");
                        }
                        else
                        {
                            alert("发起失败!");
                        }
                    
                    }
            
            });
        
        })
});
</script>
</html>

faqichuli.php

<?php
    session_start();
    
    include("../mydbda.php");
    $db = new mydbda();
    
    $code = $_POST["code"];
    $nr = $_POST["nr"];
    
    $uid = $_SESSION["uid"];
    $riqi = date("Y-m-d H:i:s",time());
    
    $sql = "insert into UserFlow values('','{$code}','{$uid}','{$nr}',false,'{$riqi}',0)";
    $str = $db->Select($sql,"QT","mydb");
    echo $str;

 chuliliucheng.php

<?php
    session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<h1>处理流程</h1>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <td>流程名称</td>
        <td>发起者</td>
        <td>内容</td>
        <td>是否结束</td>
        <td>发起日期</td>
        <td>操作</td>
    </tr>
    
    <?php
        $uid = $_SESSION["uid"];
        
        include("../mydbda.php");
        $db = new mydbda();
        
        $sql = "select * from UserFlow";
        
        $str = $db->Select($sql,"CX","mydb");
        
        $hang = explode("|",$str);
        for($i=0;$i<count($hang);$i++)
        {
            list($ids,$code,$uids,$nr,$isok,$riqi,$towhere) = explode("^",$hang[$i]);
            
            $sqlj = "select * from FlowPath where Code = '{$code}'";
            $strj = $db->Select($sqlj,"CX","mydb");
            $hangj = explode("|",$strj);
            $bs = false;
            $bscl = false;
            for($j=0;$j<count($hangj);$j++)
            {
                list($idsj,$codej,$uidj,$orderj) = explode("^",$hangj[$j]);
                
                //判断登陆用户名是否等于节点,即要不要处理这个节点;并判断节点是否走到他
                if(($uidj == $uid) and ($orderj <= $towhere))
                {
                    
                    $bs= true;
                }
                if(($uidj == $uid) and ($orderj == $towhere))
                {
                    
                    $bscl= true;
                }
            }
            
            //处理流程名
            $sqllc = "select Name from LiuCheng where Code = '{$code}'";
            $lcname = $db->Select($sqllc,"CX","mydb");
            //处理发起者名
            $sqlfq = "select Name from Users where Uid = '{$uids}'";
            $fqname = $db->Select($sqlfq,"CX","mydb");
            //处理是否结束
            $jieshu = $isok?"<span style='background-color:green'>已结束</span>":"<span style='background-color:red'>进行中</span>";
            //处理操作
            $caozuo = $bscl?"<a href='tongguo.php?code=".$ids."'>通过</a>":"<span style='background-color:gray'>已通过</span>";
            if($bs)
            {
                echo "<tr><td>{$lcname}</td><td>{$fqname}</td><td>{$nr}</td><td>{$jieshu}</td><td>{$riqi}</td><td>{$caozuo}</td></tr>";
            }
        }
    ?>
    
</table>
</body>
</html>

tongguo.php

<?php
include("../mydbda.php");
$db = new mydbda();

$code = $_GET["code"];
//通过,流程指向下一个人
$sql = "update UserFlow set ToWhere = ToWhere+1 where Ids = '{$code}' ";

$db->Select($sql,"QT","mydb");
//查询流程走到哪了
$sqlt = "select Code,ToWhere from UserFlow where Ids = '{$code}'";
$strtw = $db->Select($sqlt,"CX","mydb");
list($lccode,$tw) = explode("^",$strtw);
//查询该流程下节点数量
$sqlf = "select count(*) from FlowPath where Code = '{$lccode}'";
$zs = $db->Select($sqlf,"CX","mydb");
//判断是否走完流程
if($tw >= $zs)
{
    $sqlx = "update UserFlow set IsOk = true where Ids = '{$code}' ";

    $db->Select($sqlx,"QT","mydb");
}


header("Location:chuliliucheng.php");

 

posted on 2016-03-18 22:59  Chen_s  阅读(339)  评论(0编辑  收藏  举报

导航