php+ajax發(fā)起流程和審核流程(以請假為例)
上一篇隨筆中已經(jīng)提到如何新建流程,那么現(xiàn)在我們就來看一下如何發(fā)起一個流程和審核流程~~~
先說一下思路:
(1)登錄用session獲取到用戶的id
(2) 用戶發(fā)起一個流程
注意:需要寫申請事由
(3)處于節(jié)點的審核人去依次審核
注意:每審核通過一個,對應towhere字段要加1; 審核到最后時,對應的isok字段要變?yōu)?(此處1表示結束,0表示未結束)
共用到三張表:

第一步:先做一個簡單的登錄頁面,用session獲取用戶名:
denglu.php頁面
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <form method="post" action="denglu-cl.php"> 用戶名:<input type="text" name="uid" /><br /> 密碼:<input type="password" name="pwd" /><br /> <input type="submit" value="登錄" /> </form> </body> </html>
denglu-cl.php頁面
<?php
session_start();
require "../DB.class.php";
$db = new DB();
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
$sql = "select pwd from users where uid='{$uid}'";
$mm = $db->strquery($sql);
if($pwd==$mm && !empty($pwd))
{
$_SESSION["uid"]=$uid;
header("location:liucheng.php");
}
else
{
echo "密碼或登錄名輸入錯誤";
}
?>
效果圖:

第二步:做個簡單的注頁面:liucheng.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#body{
height: 200px;
width: 300px;
background-color: gainsboro;
margin: 200px auto;
text-align: center;
vertical-align: middle;
line-height: 30px;
}
</style>
</head>
<body>
<div id="body">
<h2>主頁面</h2>
<div>
<a href="faqi.php" rel="external nofollow" >發(fā)起流程</a><br />
<a href='shenhe.php'>審核流程</a>
</div>
</div>
</body>
</html>
效果圖:

第三步:發(fā)起流程頁面faqi.php
(1)先將所有流程用下拉列表顯示
(2)發(fā)起流程事由需要由登錄用戶填寫
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#body{
height: 250px;
width: 300px;
background-color: gainsboro;
margin: 200px auto;
text-align: left;
vertical-align: middle;
line-height: 30px;
padding-left: 30px;
}
</style>
</head>
<body>
<div id="body">
<form method="post" action="faqi-cl.php">
<h2>發(fā)起流程頁面</h2>
<select id="lc">
<?php
require "../DB.class.php";
$db = new DB();
$sql = "select * from liucheng";
$arr = $db->query($sql);
foreach($arr as $v)
{
echo "<option value='{$v[0]}'>{$v[1]}</option>";
}
?>
</select><br />
發(fā)起流程事由:
<textarea class="nr"> </textarea><br />
<input type="button" value="確定發(fā)起" />
</form>
</div>
</body>
</html>

第四步:寫發(fā)起流程的處理頁面fq-cl.php
<?php
session_start();
require "../DB.class.php";
$db = new DB();
$code = $_POST["lc"];
$nr =$_POST["nr"];
$uid = $_SESSION["uid"];
$time = date("Y-m-d H:i:s",time());
$sql = "insert into liuchengpath values ('','{$code}','{$uid}','{$nr}',0,'{$time}',0)";
$db->query($sql,0);
header("location:liucheng.php");
?>
點擊“確認發(fā)起”,數(shù)據(jù)庫中就會添加此條數(shù)據(jù)

第五步:流程審核頁面shenhe.php
用到知識點:子查詢:無關子查詢(子查詢和父查詢可以獨立執(zhí)行); 相關子查詢(子查詢里的條件使用到了父查詢的某個東西 )
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style>
#body{
height: 450px;
width: 800px;
background-color: gainsboro;
margin: 200px auto;
text-align: left;
vertical-align: middle;
line-height: 30px;
padding-left: 30px;
}
</style>
</head>
<body>
<div id="body">
<h2>流程審核頁面</h2>
<?php
session_start();
$uid = $_SESSION["uid"];
require "../DB.class.php";
$db = new DB();
//先取該用戶參與的所有流程
//并且取流程步驟到達該用戶或已經(jīng)被改用戶審核通過的記錄
$sql="select * from liuchengpath a where code in(select code from liuchengjiedian where uids='{$uid}') and towhere >=(select orders from liuchengjiedian b where b.code = a.code and b.uids = '{$uid}')";
$arr = $db->query($sql);
//var_dump($arr);
echo "<table border='1' width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td>流程代號</td>
<td>發(fā)起者</td>
<td>發(fā)起內(nèi)容</td>
<td>發(fā)起時間</td>
<td>是否結束</td>
<td>操作</td>
</tr>";
foreach($arr as $v){
//操作最后一列
//設置默認項
$zt = "<a href='tongguo-cl.php?code={$v[0]}'>審核未通過</a>";
$sql = "select orders from liuchengjiedian 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>";
?>
</div>
</body>
</html>
第六步:寫tongguo-cl.php頁面(重要)
<?php
$ids = $_GET["code"];
require "../DB.class.php";
$db = new DB();
//點擊審核后,towhere列加1,目的是使流程向下走
$sql = "update liuchengpath set towhere = towhere+1 where ids ='{$ids}' ";
$db->query($sql,0);
//當流程走到最后一個審核的人時,流程要結束
//獲取該流程最大的orders
$sql =" select max(orders) from liuchengjiedian where code = (select code from liuchengpath where ids ='{$ids}')";
$maxorders = $db->strquery($sql);
//獲取該用戶處于哪個位置,也就是towhere等于多少
$sql ="select towhere from liuchengpath where ids ='{$ids}'";
$towhere = $db->strquery($sql);
//判斷是否已到達最后一個審核的人
if($towhere>$maxorders)
{
$sql = "update liuchengpath set isok=1 where ids='{$ids}'";
// var_dump($sql);
$db->query($sql,0);
}
header("location:shenhe.php");
?>
當寫好這一步時,點擊“審核未通過”則會變成“審核已通過”;

我們從頭來驗證一下效果:
首先:發(fā)起一個新的請假流程:

其次:zhangsan是第一個要審核人


點擊“審核未通過后“,

最后:zhaoliu是最后一個審核人


點擊“審核未通過”后,是否結束變?yōu)?nbsp; 1 ;操作變?yōu)榫G色的 “審核已通過”~~~

以上所述是小編給大家介紹的php+ajax發(fā)起流程和審核流程(以請假為例),希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復大家的!
相關文章
laravel admin實現(xiàn)分類樹/模型樹的示例代碼
這篇文章主要介紹了laravel admin實現(xiàn)分類樹/模型樹,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06
php+memcache實現(xiàn)的網(wǎng)站在線人數(shù)統(tǒng)計代碼
這篇文章主要介紹了php+memcache實現(xiàn)的網(wǎng)站在線人數(shù)統(tǒng)計代碼,代碼例子簡潔實用,需要的朋友可以參考下2014-07-07
layui框架實現(xiàn)文件上傳及TP3.2.3(thinkPHP)對上傳文件進行后臺處理操作示例
這篇文章主要介紹了layui框架實現(xiàn)文件上傳及TP3.2.3對上傳文件進行后臺處理操作,結合實例形式分析了layui框架結合thinkPHP進行文件上傳與處理操作相關實現(xiàn)技巧,需要的朋友可以參考下2018-05-05
PHP數(shù)據(jù)庫萬能引擎類adodb配置使用以及實例集錦
ADODB 是一種兼容的各類數(shù)據(jù)庫應用程序接口(API),各種數(shù)據(jù)庫都可以。MySQL,PostgreSQL,Interbase,F(xiàn)irebird,Informix,Oracle,MS SQL 7,F(xiàn)oxpro,Access,ADO,Sybase,F(xiàn)rontBase,DB22014-06-06

