查看: 385|回复: 0

[PHP学习] 利用ajax和PHP实现简单的流程管理

发表于 2018-2-7 08:00:03

本文实例为大家分享了ajax和PHP实现简单的流程管理,供大家参考,具体内容如下

首先要先有一个新建流程的页面xinjian.php

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>新建</title>
  6. <script src="../FENGZHUANG/jquery-3.1.1.min.js"></script>
  7. </head>
  8. <body>
  9. <h1>新建流程</h1>
  10. <div>
  11. 请选择节点人员:
  12. <select id="user">
  13. <?php
  14. session_start();//需要将一些数据暂时存在session里
  15. include("../FENGZHUANG/DBDA.class.php");
  16. $db = new DBDA();
  17. $sql = "select * from users";
  18. $arr = $db->Query($sql);
  19. foreach($arr as $v)
  20. {
  21. echo "<option value='{$v[0]}'>{$v[2]}</option>";
  22. }
  23. ?>
  24. </select>
  25. <input type="button" value="添加节点" id="add" />
  26. </div>
  27. <br />
  28. <div>
  29. <?php
  30. if(!empty($_SESSION["user"]))
  31. {
  32. $attr = $_SESSION["user"];
  33. foreach($attr as $k=>$v) //索引为$k,取值为$v
  34. {
  35. $sname = "select name from users where uid='{$v}'"; //取出名称
  36. $name = $db->StrQuery($sname);
  37. echo "<div>{$k}--{$name}--<input type='button' value='删除' key='{$k}' class='del' /></div>"; //向处理页面传的是key的值
  38. }
  39. }
  40. ?>
  41. </div>
  42. <br />
  43. <div>请输入流程名称:<input type="text" id="name" /></div>
  44. <br />
  45. <input type="button" value="保存" id="btn" />
  46. </body>
  47. <script type="text/javascript">
  48. //添加节点按钮加点击
  49. $("#add").click(function(){
  50. var uid = $("#user").val();
  51. $.ajax({
  52. url:"chuli.php",
  53. data:{uid:uid,type:0}, //传入一个type参数,以确保在同一页面处理时与其它的分开处理
  54. type:"POST",
  55. dataType:"TEXT",
  56. success: function(data){
  57. window.location.href="xinjian.php" rel="external nofollow" rel="external nofollow" ; //刷新页面
  58. }
  59. });
  60. })
  61. //给删除按钮加点击
  62. $(".del").click(function(){
  63. var key = $(this).attr("key"); //取删除的是哪条数据
  64. $.ajax({
  65. url:"chuli.php",
  66. data:{key:key,type:1},
  67. type:"POST",
  68. dataType:"TEXT",
  69. success:function(data){
  70. window.location.href="xinjian.php" rel="external nofollow" rel="external nofollow" ;
  71. }
  72. });
  73. })
  74. //给保存按钮加点击
  75. $("#btn").click(function(){
  76. var name = $("#name").val(); //取输入框中输入内容的值
  77. $.ajax({
  78. url:"chuli.php",
  79. data:{name:name,type:2},
  80. type:"POST",
  81. dataType:"TEXT",
  82. success:function(data){
  83. alert("保存成功!");
  84. }
  85. });
  86. })
  87. </script>
  88. </html>
复制代码

数据库图片:

处理页面chuli.php

  1. <?php
  2. session_start();
  3. include("../FENGZHUANG/DBDA.class.php");
  4. $db = new DBDA();
  5. $type = $_POST["type"];
  6. switch($type)
  7. {
  8. case 0://添加节点的加载数据,向session数组中添加数据
  9. $uid = $_POST["uid"];
  10. if(empty($_SESSION["user"]))
  11. {
  12. $arr = array($uid);
  13. $_SESSION["user"] = $arr;
  14. }
  15. else
  16. {
  17. $arr = $_SESSION["user"];
  18. array_push($arr,$uid);
  19. $_SESSION["user"] = $arr;
  20. }
  21. break;
  22. case 1://取节点的索引,然后删除,重新索引
  23. $key = $_POST["key"];
  24. $arr = $_SESSION["user"];
  25. unset($arr[$key]); //删除
  26. $arr = array_values($arr); //重新索引
  27. $_SESSION["user"] = $arr;
  28. break;
  29. case 2:
  30. $name = $_POST["name"];
  31. $code = time();
  32. //添加流程
  33. $sql = "insert into liucheng values('{$code}','{$name}')";
  34. $db->Query($sql,0);
  35. //添加流程节点
  36. $arr = $_SESSION["user"];
  37. foreach($arr as $k=>$v)
  38. {
  39. $sql = "insert into flowpath values('','{$code}','{$v}','{$k}')";
  40. $db->Query($sql,0);
  41. }
  42. break;
  43. case 3: //用户发起流程
  44. $code = $_POST["code"];
  45. $nr = $_POST["content"];
  46. $uid = $_SESSION["uid"];
  47. $time = date("Y-m-d H:i:s");
  48. $sql = "insert into userflow values('','{$code}','{$uid}','{$nr}',0,'{$time}',0)";
  49. $db->Query($sql,0);
  50. break;
  51. }
复制代码

发起流程页面faqi.php

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>发起流程</title><br />
  6. <script src="../FENGZHUANG/jquery-3.1.1.min.js"></script>
  7. </head>
  8. <body>
  9. <h1>发起流程</h1>
  10. <div>
  11. 请选择发起的流程:
  12. <select id="liucheng">
  13. <?php
  14. session_start();
  15. include("../FENGZHUANG/DBDA.class.php");
  16. $db = new DBDA();
  17. $sql = "select * from liucheng";
  18. $arr = $db->Query($sql);
  19. foreach($arr as $v)
  20. {
  21. echo "<option value='{$v[0]}'>{$v[1]}</option>";
  22. }
  23. ?>
  24. </select>
  25. </div>
  26. <br />
  27. <div>
  28. 请输入内容:
  29. <textarea id="nr"></textarea>
  30. </div>
  31. <br />
  32. <input type="button" value="发起" id="btn" />
  33. </body>
  34. <script type="text/javascript">
  35. $("#btn").click(function(){
  36. var code = $("#liucheng").val();
  37. var content = $("#nr").val();
  38. $.ajax({
  39. url:"chuli.php",
  40. data:{code:code,content:content,type:3},
  41. type:"POST",
  42. dataType:"TEXT",
  43. success: function(data){
  44. alert("发起成功!");
  45. }
  46. });
  47. })
  48. </script>
  49. </html>
复制代码

审核页面shenhe.php

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>审核</title>
  6. </head>
  7. <body>
  8. <h1>审核页面</h1>
  9. <table width="100%" border="1" cellpadding="0" cellspacing="0">
  10. <tr>
  11. <td>流程代号</td>
  12. <td>发起者</td>
  13. <td>发起内容</td>
  14. <td>是否结束</td>
  15. <td>发起时间</td>
  16. <td>操作</td>
  17. </tr>
  18. <?php
  19. session_start();
  20. include("../FENGZHUANG/DBDA.class.php");
  21. $db = new DBDA();
  22. $uid = $_SESSION["uid"];
  23. echo $uid;
  24. //查找登录者参与的所有流程
  25. $sql = "select * from userflow where code in(select code from flowpath where uids='{$uid}')";
  26. $arr = $db->Query($sql);
  27. //显示
  28. foreach($arr as $v)
  29. {
  30. //判断该流程走到登录者
  31. $lcdh = $v[1]; //流程代号
  32. $towhere = $v[6];//流程走到哪
  33. $sql = "select orders from flowpath where code='{$lcdh}' and uids='{$uid}'";
  34. $order = $db->StrQuery($sql);//该人员在流程中的次序
  35. if($towhere>=$order)
  36. {
  37. $caozuo = "";
  38. if($towhere==$order)
  39. {
  40. $caozuo="<a href='tongguo.php?code={$v[0]}'>通过</a>";
  41. }
  42. else
  43. {
  44. $caozuo="<span style='background-color:green;color:white'>已通过</span>";
  45. }
  46. echo "<tr>
  47. <td>{$v[1]}</td>
  48. <td>{$v[2]}</td>
  49. <td>{$v[3]}</td>
  50. <td>{$v[4]}</td>
  51. <td>{$v[5]}</td>
  52. <td>{$caozuo}</td>
  53. </tr>";
  54. }
  55. }
  56. ?>
  57. </table>
  58. </body>
  59. </html>
复制代码

tongguo.php

  1. <?php
  2. session_start();
  3. include("../FENGZHUANG/DBDA.class.php");
  4. $db = new DBDA();
  5. //流程往下走
  6. $code = $_GET["code"];
  7. $sql = "update userflow set towhere=towhere+1 where ids='{$code}'"; //使流程向下走
  8. $db->Query($sql,0);
  9. //判断流程是否结束
  10. $sql = "select * from userflow where ids='{$code}'";
  11. $arr = $db->Query($sql);
  12. $lcdh = $arr[0][1]; //流程代号
  13. $tw = $arr[0][6]; //流程走到哪
  14. $sql = "select count(*) from flowpath where code='{$lcdh}'";
  15. $count = $db->StrQuery($sql); //该流程节点人数
  16. if($tw>=$count)
  17. {
  18. $sql = "update userflow set isok=1 where ids='{$code}'"; //如果结束了流程,将isok项改为结束。
  19. $db->Query($sql,0);
  20. }
  21. header("location:shenhe.php");
复制代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持程序员之家。

您可能感兴趣的文章:

  • php+ajax发起流程和审核流程(以请假为例)


回复

使用道具 举报