利用ajax和PHP實(shí)現(xiàn)簡單的流程管理
更新時(shí)間:2017年03月23日 17:11:59 作者:v斌v
這篇文章主要為大家詳細(xì)介紹了ajax和PHP實(shí)現(xiàn)簡單的流程管理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了ajax和PHP實(shí)現(xiàn)簡單的流程管理,供大家參考,具體內(nèi)容如下
首先要先有一個(gè)新建流程的頁面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="../FENGZHUANG/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>新建流程</h1>
<div>
請選擇節(jié)點(diǎn)人員:
<select id="user">
<?php
session_start();//需要將一些數(shù)據(jù)暫時(shí)存在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="添加節(jié)點(diǎn)" id="add" />
</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}' class='del' /></div>"; //向處理頁面?zhèn)鞯氖莐ey的值
}
}
?>
</div>
<br />
<div>請輸入流程名稱:<input type="text" id="name" /></div>
<br />
<input type="button" value="保存" id="btn" />
</body>
<script type="text/javascript">
//添加節(jié)點(diǎn)按鈕加點(diǎn)擊
$("#add").click(function(){
var uid = $("#user").val();
$.ajax({
url:"chuli.php",
data:{uid:uid,type:0}, //傳入一個(gè)type參數(shù),以確保在同一頁面處理時(shí)與其它的分開處理
type:"POST",
dataType:"TEXT",
success: function(data){
window.location.href="xinjian.php" rel="external nofollow" rel="external nofollow" ; //刷新頁面
}
});
})
//給刪除按鈕加點(diǎn)擊
$(".del").click(function(){
var key = $(this).attr("key"); //取刪除的是哪條數(shù)據(jù)
$.ajax({
url:"chuli.php",
data:{key:key,type:1},
type:"POST",
dataType:"TEXT",
success:function(data){
window.location.href="xinjian.php" rel="external nofollow" rel="external nofollow" ;
}
});
})
//給保存按鈕加點(diǎn)擊
$("#btn").click(function(){
var name = $("#name").val(); //取輸入框中輸入內(nèi)容的值
$.ajax({
url:"chuli.php",
data:{name:name,type:2},
type:"POST",
dataType:"TEXT",
success:function(data){
alert("保存成功!");
}
});
})
</script>
</html>

數(shù)據(jù)庫圖片:




處理頁面chuli.php
<?php
session_start();
include("../FENGZHUANG/DBDA.class.php");
$db = new DBDA();
$type = $_POST["type"];
switch($type)
{
case 0://添加節(jié)點(diǎn)的加載數(shù)據(jù),向session數(shù)組中添加數(shù)據(jù)
$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://取節(jié)點(diǎn)的索引,然后刪除,重新索引
$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);
//添加流程節(jié)點(diǎn)
$arr = $_SESSION["user"];
foreach($arr as $k=>$v)
{
$sql = "insert into flowpath values('','{$code}','{$v}','{$k}')";
$db->Query($sql,0);
}
break;
case 3: //用戶發(fā)起流程
$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;
}
發(fā)起流程頁面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>發(fā)起流程</title><br />
<script src="../FENGZHUANG/jquery-3.1.1.min.js"></script>
</head>
<body>
<h1>發(fā)起流程</h1>
<div>
請選擇發(fā)起的流程:
<select id="liucheng">
<?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>
請輸入內(nèi)容:
<textarea id="nr"></textarea>
</div>
<br />
<input type="button" value="發(fā)起" id="btn" />
</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("發(fā)起成功!");
}
});
})
</script>
</html>

審核頁面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>
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>流程代號</td>
<td>發(fā)起者</td>
<td>發(fā)起內(nèi)容</td>
<td>是否結(jié)束</td>
<td>發(fā)起時(shí)間</td>
<td>操作</td>
</tr>
<?php
session_start();
include("../FENGZHUANG/DBDA.class.php");
$db = new DBDA();
$uid = $_SESSION["uid"];
echo $uid;
//查找登錄者參與的所有流程
$sql = "select * from userflow where code in(select code from flowpath where uids='{$uid}')";
$arr = $db->Query($sql);
//顯示
foreach($arr as $v)
{
//判斷該流程走到登錄者
$lcdh = $v[1]; //流程代號
$towhere = $v[6];//流程走到哪
$sql = "select orders from flowpath where code='{$lcdh}' and uids='{$uid}'";
$order = $db->StrQuery($sql);//該人員在流程中的次序
if($towhere>=$order)
{
$caozuo = "";
if($towhere==$order)
{
$caozuo="<a href='tongguo.php?code={$v[0]}'>通過</a>";
}
else
{
$caozuo="<span style='background-color:green;color:white'>已通過</span>";
}
echo "<tr>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
<td>{$caozuo}</td>
</tr>";
}
}
?>
</table>
</body>
</html>






tongguo.php
<?php
session_start();
include("../FENGZHUANG/DBDA.class.php");
$db = new DBDA();
//流程往下走
$code = $_GET["code"];
$sql = "update userflow set towhere=towhere+1 where ids='{$code}'"; //使流程向下走
$db->Query($sql,0);
//判斷流程是否結(jié)束
$sql = "select * from userflow where ids='{$code}'";
$arr = $db->Query($sql);
$lcdh = $arr[0][1]; //流程代號
$tw = $arr[0][6]; //流程走到哪
$sql = "select count(*) from flowpath where code='{$lcdh}'";
$count = $db->StrQuery($sql); //該流程節(jié)點(diǎn)人數(shù)
if($tw>=$count)
{
$sql = "update userflow set isok=1 where ids='{$code}'"; //如果結(jié)束了流程,將isok項(xiàng)改為結(jié)束。
$db->Query($sql,0);
}
header("location:shenhe.php");
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
PHP實(shí)現(xiàn)驗(yàn)證碼校驗(yàn)功能
這篇文章主要為大家詳細(xì)介紹了PHP實(shí)現(xiàn)驗(yàn)證碼校驗(yàn)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11
Laravel5.7框架安裝與使用學(xué)習(xí)筆記圖文詳解
這篇文章主要介紹了Laravel5.7框架安裝與使用學(xué)習(xí)筆記,結(jié)合圖文形式詳細(xì)講解了Laravel5.7框架的安裝、配置、組件、路由等基礎(chǔ)與操作技巧,需要的朋友可以參考下2019-04-04
Laravel 之url參數(shù),獲取路由參數(shù)的例子
今天小編就為大家分享一篇Laravel 之url參數(shù),獲取路由參數(shù)的例子,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-10-10

