php+ajax發起流程和審核流程(以請假為例)


上一篇隨筆中已經提到如何新建流程,那么現在我們就來看一下如何發起一個流程和審核流程~~~

先說一下思路

(1)登錄用session獲取到用戶的id

 (2) 用戶發起一個流程

         注意:需要寫申請事由

(3)處於節點的審核人去依次審核

          注意:每審核通過一個,對應towhere字段要加1; 審核到最后時,對應的isok字段要變為1(此處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">發起流程</a><br />
			<a href='shenhe.php'>審核流程</a>
		</div>
		</div>
	</body>
</html>

  

 效果圖:

第三步:發起流程頁面faqi.php

(1)先將所有流程用下拉列表顯示

(2)發起流程事由需要由登錄用戶填寫

<!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>發起流程頁面</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 />
			發起流程事由:
			<textarea class="nr"> </textarea><br />
			<input type="button" value="確定發起" />	
			</form>
		</div>
	</body>
</html>

第四步:寫發起流程的處理頁面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");
?>

  點擊“確認發起”,數據庫中就會添加此條數據

 

第五步:流程審核頁面shenhe.php

用到知識點:子查詢:無關子查詢(子查詢和父查詢可以獨立執行); 相關子查詢(子查詢里的條件使用到了父查詢的某個東西   )

<!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();
				//先取該用戶參與的所有流程
				//並且取流程步驟到達該用戶或已經被改用戶審核通過的記錄
				$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>發起者</td>
								<td>發起內容</td>
								<td>發起時間</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");
?>

  當寫好這一步時,點擊“審核未通過”則會變成“審核已通過”;

 

 

我們從頭來驗證一下效果:

首先:發起一個新的請假流程:

       

 

 

 

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

點擊“審核未通過后“,

 

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

 

 

點擊“審核未通過”后,是否結束變為  1 ;操作變為綠色的  “審核已通過”~~~

 

 這樣簡單的發起流程和流程審核就已經實現了~~~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM