当前位置:Gxlcms > PHP教程 > php+ajax发起、审核请假流程教程

php+ajax发起、审核请假流程教程

时间:2021-07-01 10:21:17 帮助过:5人阅读

这篇文章主要介绍了php+ajax发起流程和审核流程(以请假为例) ,需要的朋友可以参考下

上一篇随笔中已经提到如何新建流程,那么现在我们就来看一下如何发起一个流程和审核流程~~~

先说一下思路:

(1)登录用session获取到用户的id

(2) 用户发起一个流程

注意:需要写申请事由

(3)处于节点的审核人去依次审核

注意:每审核通过一个,对应towhere字段要加1; 审核到最后时,对应的isok字段要变为1(此处1表示结束,0表示未结束)

共用到三张表:

第一步:先做一个简单的登录页面,用session获取用户名:

denglu.php页面


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <form method="post" action="denglu-cl.php">
  9. 用户名:<input type="text" name="uid" /><br />
  10. 密码:<input type="password" name="pwd" /><br />
  11. <input type="submit" value="登录" />
  12. </form>
  13. </body>
  14. </html>

  denglu-cl.php页面


  1. <?php
  2. session_start();
  3. require "../DB.class.php";
  4. $db = new DB();
  5. $uid = $_POST["uid"];
  6. $pwd = $_POST["pwd"];
  7. $sql = "select pwd from users where uid='{$uid}'";
  8. $mm = $db->strquery($sql);
  9. if($pwd==$mm && !empty($pwd))
  10. {
  11. $_SESSION["uid"]=$uid;
  12. header("location:liucheng.php");
  13. }
  14. else
  15. {
  16. echo "密码或登录名输入错误";
  17. }
  18. ?>

  效果图:

第二步:做个简单的注页面:liucheng.php


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. #body{
  8. height: 200px;
  9. width: 300px;
  10. background-color: gainsboro;
  11. margin: 200px auto;
  12. text-align: center;
  13. vertical-align: middle;
  14. line-height: 30px;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <p id="body">
  20. <h2>主页面</h2>
  21. <p>
  22. <a href="faqi.php" rel="external nofollow" >发起流程</a><br />
  23. <a href='shenhe.php'>审核流程</a>
  24. </p>
  25. </p>
  26. </body>
  27. </html>

效果图:

第三步:发起流程页面faqi.php

(1)先将所有流程用下拉列表显示

(2)发起流程事由需要由登录用户填写


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. #body{
  8. height: 250px;
  9. width: 300px;
  10. background-color: gainsboro;
  11. margin: 200px auto;
  12. text-align: left;
  13. vertical-align: middle;
  14. line-height: 30px;
  15. padding-left: 30px;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <p id="body">
  21. <form method="post" action="faqi-cl.php">
  22. <h2>发起流程页面</h2>
  23. <select id="lc">
  24. <?php
  25. require "../DB.class.php";
  26. $db = new DB();
  27. $sql = "select * from liucheng";
  28. $arr = $db->query($sql);
  29. foreach($arr as $v)
  30. {
  31. echo "<option value='{$v[0]}'>{$v[1]}</option>";
  32. }
  33. ?>
  34. </select><br />
  35. 发起流程事由:
  36. <textarea class="nr"> </textarea><br />
  37. <input type="button" value="确定发起" />
  38. </form>
  39. </p>
  40. </body>
  41. </html>

第四步:写发起流程的处理页面fq-cl.php


  1. <?php
  2. session_start();
  3. require "../DB.class.php";
  4. $db = new DB();
  5. $code = $_POST["lc"];
  6. $nr =$_POST["nr"];
  7. $uid = $_SESSION["uid"];
  8. $time = date("Y-m-d H:i:s",time());
  9. $sql = "insert into liuchengpath values ('','{$code}','{$uid}','{$nr}',0,'{$time}',0)";
  10. $db->query($sql,0);
  11. header("location:liucheng.php");
  12. ?>

  点击“确认发起”,数据库中就会添加此条数据

第五步:流程审核页面shenhe.php

用到知识点:子查询:无关子查询(子查询和父查询可以独立执行); 相关子查询(子查询里的条件使用到了父查询的某个东西 )


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. <style>
  7. #body{
  8. height: 450px;
  9. width: 800px;
  10. background-color: gainsboro;
  11. margin: 200px auto;
  12. text-align: left;
  13. vertical-align: middle;
  14. line-height: 30px;
  15. padding-left: 30px;
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <p id="body">
  21. <h2>流程审核页面</h2>
  22. <?php
  23. session_start();
  24. $uid = $_SESSION["uid"];
  25. require "../DB.class.php";
  26. $db = new DB();
  27. //先取该用户参与的所有流程
  28. //并且取流程步骤到达该用户或已经被改用户审核通过的记录
  29. $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}')";
  30. $arr = $db->query($sql);
  31. //var_dump($arr);
  32. echo "<table border='1' width='100%' cellpadding='0' cellspacing='0'>
  33. <tr>
  34. <td>流程代号</td>
  35. <td>发起者</td>
  36. <td>发起内容</td>
  37. <td>发起时间</td>
  38. <td>是否结束</td>
  39. <td>操作</td>
  40. </tr>";
  41. foreach($arr as $v){
  42. //操作最后一列
  43. //设置默认项
  44. $zt = "<a href='tongguo-cl.php?code={$v[0]}'>审核未通过</a>";
  45. $sql = "select orders from liuchengjiedian where code ='{$v[1]}' and uids ='{$uid}'";
  46. $wz = $db->strquery($sql);
  47. if($v[6]>$wz)
  48. {
  49. $zt = "<span style='color:green'>审核已通过</span>";
  50. }
  51. echo "<tr>
  52. <td>{$v[1]}</td>
  53. <td>{$v[2]}</td>
  54. <td>{$v[3]}</td>
  55. <td>{$v[4]}</td>
  56. <td>{$v[5]}</td>
  57. <td>{$zt}</td>
  58. </tr>";
  59. }
  60. echo "</table>";
  61. ?>
  62. </p>
  63. </body>
  64. </html>

  第六步:写tongguo-cl.php页面(重要)


  1. <?php
  2. $ids = $_GET["code"];
  3. require "../DB.class.php";
  4. $db = new DB();
  5. //点击审核后,towhere列加1,目的是使流程向下走
  6. $sql = "update liuchengpath set towhere = towhere+1 where ids ='{$ids}' ";
  7. $db->query($sql,0);
  8. //当流程走到最后一个审核的人时,流程要结束
  9. //获取该流程最大的orders
  10. $sql =" select max(orders) from liuchengjiedian where code = (select code from liuchengpath where ids ='{$ids}')";
  11. $maxorders = $db->strquery($sql);
  12. //获取该用户处于哪个位置,也就是towhere等于多少
  13. $sql ="select towhere from liuchengpath where ids ='{$ids}'";
  14. $towhere = $db->strquery($sql);
  15. //判断是否已到达最后一个审核的人
  16. if($towhere>$maxorders)
  17. {
  18. $sql = "update liuchengpath set isok=1 where ids='{$ids}'";
  19. // var_dump($sql);
  20. $db->query($sql,0);
  21. }
  22. header("location:shenhe.php");
  23. ?>

  当写好这一步时,点击“审核未通过”则会变成“审核已通过”;

我们从头来验证一下效果:

首先:发起一个新的请假流程:

其次:zhangsan是第一个要审核人

点击“审核未通过后“,

最后:zhaoliu是最后一个审核人

点击“审核未通过”后,是否结束变为 1 ;操作变为绿色的 “审核已通过”~~~

以上就是php+ajax发起、审核请假流程教程的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行