上一篇博文是新建流程,此篇是流程管理的后續內容:發起流程和審核流程
一. 發起流程和審核流程需要用到的三張表



二.寫代碼
1. 用ajax做了一個登錄頁面,用session獲取用戶名:
<!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" />
<script src="../jquery-3.2.0.min.js"></script>
<title>無標題文檔</title>
</head>
<body>
<h1>登錄頁面</h1>
<form action="dlchuli.php" method="post">
<div>用戶名:<input type="text" id="uid" /></div>
<div>密碼:<input type="password" id="pwd" /></div>
<input type="button" value="登錄" id="btn" />
</form>
</body>
<script type="text/javascript"> //!!!用ajax之前一定先引用jqery
$("#btn").click(function(){ //對登錄按鈕添加單擊事件
var uid=$("#uid").val(); //獲取用戶的值
var pwd=$("#pwd").val(); //獲取密碼的值
$.ajax({
url:"dlchuli.php", //編寫登錄的處理頁面
data:{uid:uid,pwd:pwd}, //將用戶和密碼傳到處理頁面
type:"POST",
dataType:"TEXT",
success: function(data)
{
if(data.trim()=="OK")
{
window.location.href="main.php"; //處理頁面執行成功后,跳轉到主頁面
}
else
{
alert("用戶名或密碼輸入錯誤"); //否則就提示錯誤
}
}
})
})
</script>
</html>
2.登錄界面的處理頁面 dlchuli.php
<?php
session_start();
require "../DBDA.class.php";
$db = new DBDA(); //造新對象
//傳過來的值
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
//查詢語句
$sql = " select pwd from users where uid='{$uid}' and pwd='{$pwd}'";
//執行語句
$attr = $db->query($sql,1);
if(!empty($pwd) && !empty($attr) && $attr[0][0]==$pwd)
{
$_SESSION["uid"] =$uid; //session接收用戶值
echo "OK";
}
else
{
echo "NO";
}

3.主頁面 main.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> <div><a href="faqi.php">發起流程</a> <a href="shenhe.php">審核流程</a></div> </body> </html>

4.發起流程頁面 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>
</head>
<body>
<h1>發起流程</h1>
<form action="fqchuli.php" method="post">
<div>請選擇發起的流程:
<select name="lc">
<?php
require "../DBDA.class.php";
$db = new DBDA();
$sql = "select * from liucheng";
$arr = $db->query($sql,1);
foreach($arr as $v)
{
echo "<option value='{$v[0]}'>{$v[1]}</option>";
}
?>
</select>
</div>
<br />
<div>
請輸入發起的內容:<textarea name="nr"></textarea>
</div>
<br />
<input type="submit" value="發起" />
</form>
</body>
</html>
5.發起流程處理頁面 fqchuli.php
<?php
session_start();
require "../DBDA.class.php";
$db = new DBDA();
$code =$_POST["lc"];
$nr =$_POST["nr"];
$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);
header("location:main.php");

點擊“發起”,數據庫中就會添加此條數據
6.流程審核頁面 shenhe.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>
<?php
session_start();
$uid = $_SESSION["uid"];
require "../DBDA.class.php";
$db = new DBDA();
$sql = "select * from userflow a where code in(select code from flowpath where uids='{$uid}')
and towhere >=(select orders from flowpath b where b.code=a.code and b.uids='{$uid}' )" ;
$arr = $db->query($sql,1);
echo "<table width='100%' border='1' cellpadding='0' cellspacing='0'>
<tr>
<td>流程代號</td>
<td>發起者</td>
<td>發起內容</td>
<td>是否結束</td>
<td>發起時間</td>
<td>操作</td>
</tr>
";
foreach($arr as $v)
{
$zt = "<a href='tongguo.php?code={$v[0]}'>通過</a>";
$sql = "select orders from flowpath where code='{$v[1]}' and uids='{$uid}'";
$wz = $db->strquery($sql);
if($v[6]>$wz)
{
$zt = "<span style='color:green'>已通過</span>";
}
echo "<tr>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
<td>{$zt}</td>
</tr>";
}
echo "</table>";
?>
</body>
</html>
7.寫審核處理頁面 tongguo.php(*)
<?php
$ids = $_GET["code"];
require "../DBDA.class.php";
$db = new DBDA();
//讓流程往下走,每審核通過一個,對應towhere字段要加1
$sql = "update userflow set towhere = towhere+1 where ids='{$ids}'";
$db->query($sql);
//判斷流程是否結束
$sql = "select max(orders) from flowpath where code=( select code from userflow where ids='{$ids}')";
$maxsx = $db->strquery($sql);
$sql = "select towhere from userflow where ids='{$ids}'";
$towhere = $db->strquery($sql);
if($towhere>$maxsx)
{
//如果結束了,修改狀態 ;審核到最后時,對應的isok字段要變為1(此處1表示結束,0表示未結束)
$sql = "update userflow set isok = 1 where ids='{$ids}'";
$db->query($sql);
}
header("location:shenhe.php");
當寫好這一步時,點擊“通過”則會變成“已通過”;
zhangsan是第一個審核人,從zhangsan開始依次審核


niuniu是最后一個審核人,結束顯示1


END
