首先要先有一个新建流程的页面xinjian.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> <script src="https://www.jb51.net/FENGZHUANG/jquery-3.1.1.min.js"></script> </head> <body> <h1>新建流程</h1> <div> 请选择节点人员: <select> <?php session_start();//需要将一些数据暂时存在session里 include("../FENGZHUANG/DBDA.class.php"); $db = new DBDA(); $sql = "select * from users"; $arr = $db->Query($sql); foreach($arr as $v) { echo "<option value='{$v[0]}'>{$v[2]}</option>"; } ?> </select> <input type="button" value="添加节点" /> </div> <br /> <div> <?php if(!empty($_SESSION["user"])) { $attr = $_SESSION["user"]; foreach($attr as $k=>$v) //索引为$k,取值为$v { $sname = "select name from users where uid='{$v}'"; //取出名称 $name = $db->StrQuery($sname); echo "<div>{$k}--{$name}--<input type='button' value='删除' key='{$k}' /></div>"; //向处理页面传的是key的值 } } ?> </div> <br /> <div>请输入流程名称:<input type="text" /></div> <br /> <input type="button" value="保存" /> </body> <script type="text/javascript"> //添加节点按钮加点击 $("#add").click(function(){ var uid = $("#user").val(); $.ajax({ url:"chuli.php", data:{uid:uid,type:0}, //传入一个type参数,以确保在同一页面处理时与其它的分开处理 type:"POST", dataType:"TEXT", success: function(data){ window.location.href="xinjian.php" ; //刷新页面 } }); }) //给删除按钮加点击 $(".del").click(function(){ var key = $(this).attr("key"); //取删除的是哪条数据 $.ajax({ url:"chuli.php", data:{key:key,type:1}, type:"POST", dataType:"TEXT", success:function(data){ window.location.href="xinjian.php" ; } }); }) //给保存按钮加点击 $("#btn").click(function(){ var name = $("#name").val(); //取输入框中输入内容的值 $.ajax({ url:"chuli.php", data:{name:name,type:2}, type:"POST", dataType:"TEXT", success:function(data){ alert("保存成功!"); } }); }) </script> </html>
数据库图片:
处理页面chuli.php
<?php session_start(); include("../FENGZHUANG/DBDA.class.php"); $db = new DBDA(); $type = $_POST["type"]; switch($type) { case 0://添加节点的加载数据,向session数组中添加数据 $uid = $_POST["uid"]; if(empty($_SESSION["user"])) { $arr = array($uid); $_SESSION["user"] = $arr; } else { $arr = $_SESSION["user"]; array_push($arr,$uid); $_SESSION["user"] = $arr; } break; case 1://取节点的索引,然后删除,重新索引 $key = $_POST["key"]; $arr = $_SESSION["user"]; unset($arr[$key]); //删除 $arr = array_values($arr); //重新索引 $_SESSION["user"] = $arr; break; case 2: $name = $_POST["name"]; $code = time(); //添加流程 $sql = "insert into liucheng values('{$code}','{$name}')"; $db->Query($sql,0); //添加流程节点 $arr = $_SESSION["user"]; foreach($arr as $k=>$v) { $sql = "insert into flowpath values('','{$code}','{$v}','{$k}')"; $db->Query($sql,0); } break; case 3: //用户发起流程 $code = $_POST["code"]; $nr = $_POST["content"]; $uid = $_SESSION["uid"]; $time = date("Y-m-d H:i:s"); $sql = "insert into userflow values('','{$code}','{$uid}','{$nr}',0,'{$time}',0)"; $db->Query($sql,0); break; }
发起流程页面faqi.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><br /> <script src="https://www.jb51.net/FENGZHUANG/jquery-3.1.1.min.js"></script> </head> <body> <h1>发起流程</h1> <div> 请选择发起的流程: <select> <?php session_start(); include("../FENGZHUANG/DBDA.class.php"); $db = new DBDA(); $sql = "select * from liucheng"; $arr = $db->Query($sql); foreach($arr as $v) { echo "<option value='{$v[0]}'>{$v[1]}</option>"; } ?> </select> </div> <br /> <div> 请输入内容: <textarea></textarea> </div> <br /> <input type="button" value="发起" /> </body> <script type="text/javascript"> $("#btn").click(function(){ var code = $("#liucheng").val(); var content = $("#nr").val(); $.ajax({ url:"chuli.php", data:{code:code,content:content,type:3}, type:"POST", dataType:"TEXT", success: function(data){ alert("发起成功!"); } }); }) </script> </html>
审核页面shenhe.php