PHP 流程管理

封装类

 1 <?php
 2 class DBDA
 3 {
 4     public $host="localhost";
 5     public $uid = "root";
 6     public $pwd = "123";
 7     public $dbname = "mydb";
 8     
 9     //成员方法
10     public function Query($sql,$type=1)
11     {
12         $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
13         $r = $db->query($sql);
14         
15         if($type==1)
16         {
17             return $r->fetch_all();
18         }
19         else
20         {
21             return $r;
22         }
23     }
24     
25     //返回字符串的方法
26     public function StrQuery($sql,$type=1)
27     {
28         $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
29         $r = $db->query($sql);
30         
31         if($type==1)
32         {
33             $attr = $r->fetch_all();
34             $str = "";
35             foreach($attr as $v)
36             {
37                 $str .= implode("^",$v)."|";
38             }
39             
40             return substr($str,0,strlen($str)-1);
41 
42         }
43         else
44         {
45             return $r;
46         }
47     }
48     
49     //返回JSON
50     function JSONQuery($sql,$type=1)
51     {
52         $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
53         $r = $db->query($sql);
54         
55         if($type==1)
56         {
57             return json_encode($r->fetch_all(MYSQLI_ASSOC));
58         }
59         else
60         {
61             return $r;
62         }
63     }
64 }
65 
66 DBDA.class.php
DBDA.class.php

首先 管理员部分

1.单选按钮组    添加流程   使用session 储存了数组    

  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="../ajaxfenye/jquery-1.11.2.min.js"></script>
  7 </head>
  8 
  9 <body>
 10 
 11 <h1>新建流程</h1>
 12 
 13 <div>
 14     请选择节点人员:
 15     
 16     <?php
 17     session_start();
 18     include("../ajax/DBDA.class.php");
 19     $db = new DBDA();
 20     
 21     $suser = "select * from users";
 22     $auser = $db->Query($suser);
 23     foreach($auser as $v)
 24     {
 25         echo "<input class='ck' type='radio' value='{$v[0]}' name='ck' />{$v[2]} ";
 26     }
 27     ?>
 28     
 29 </div>
 30 <br />
 31 <div>
 32 <input type="button" value="添加节点" id="addjiedian" />
 33 </div>
 34 <br />
 35 
 36 <?php
 37 if(empty($_SESSION["jiedian"]))
 38 {
 39     echo "<div>还没有添加节点</div>";
 40 }
 41 else
 42 {
 43     $attr = $_SESSION["jiedian"];
 44     foreach($attr as $k=>$v)
 45     {
 46         $sname = "select name from users where uid='{$v}'";
 47         $name = $db->StrQuery($sname);
 48         echo "<div>{$k}--{$name}--<input type='button' value='删除' sy='{$k}' class='sc' /></div>";
 49     }
 50 }
 51 ?>
 52 
 53 <br />
 54 <div>请输入流程名称:<input type="text" id="name" /></div>
 55 <br />
 56 <div><input type="button" value="保存" id="save" /></div>
 57 
 58 
 59 </body>
 60 <script type="text/javascript">
 61 //添加节点
 62 $("#addjiedian").click(function(){
 63         var ck = $(".ck");
 64         var uid = "";
 65         for(var i=0;i<ck.length;i++)
 66         {
 67             if(ck.eq(i).prop("checked"))
 68             {
 69                 uid = ck.eq(i).val();
 70             }
 71         }
 72         
 73         $.ajax({
 74                 url:"addjd.php",
 75                 data:{uid:uid},
 76                 type:"POST",
 77                 dataType:"TEXT",
 78                 success: function(data){
 79                         window.location.href="xinjian.php";
 80                     }
 81             });
 82         
 83     })
 84 //删除点击
 85 $(".sc").click(function(){
 86         var sy = $(this).attr("sy");
 87         $.ajax({
 88                 url:"shanchu.php",
 89                 data:{sy:sy},
 90                 type:"POST",
 91                 dataType:"TEXT",
 92                 success:function(data){
 93                         window.location.href="xinjian.php";
 94                     }
 95             });
 96     })
 97     
 98 //保存
 99 $("#save").click(function(){
100         var name = $("#name").val();
101         $.ajax({
102                 url:"baocun.php",
103                 data:{name:name},
104                 type:"POST",
105                 dataType:"TEXT",
106                 success: function(data){
107                         alert("添加成功!");
108                     }
109             });
110     })
111 </script>
112 </html>
main.php

  2.添加: 使用session  存放数组

 1 <?php
 2 session_start();
 3 $uid = $_POST["uid"];
 4 
 5 if(empty($_SESSION["jiedian"]))
 6 {
 7     $attr = array($uid);
 8     $_SESSION["jiedian"] = $attr;
 9 }
10 else
11 {
12     $attr = $_SESSION["jiedian"];
13     $attr[] = $uid;
14     $_SESSION["jiedian"] = $attr;
15 }
add.php

3.删除数组中的制定  位置 的 数     重新索引  array_values()   删除   unset();使用  数组中 存放 的数组

1 <?php
2 session_start();
3 $attr = $_SESSION["jiedian"];
4 $sy = $_POST["sy"];
5 
6 unset($attr[$sy]); //删除数据
7 $attr = array_values($attr); //重新索引
8 $_SESSION["jiedian"] = $attr;
shanchu.php

 审批人员部分---

 4.  登录  

1 <form action="loginchuli.php" method="post">
2 <div>用户名:<input type="text" name="uid" /></div>
3 <div>密码:<input type="text" name="pwd" /></div>
4 <input type="submit" value="登录" />
5 </form>
login.php

 5.    登录处理    略   登录成功后  session 储存  用户名

 1 <?php
 2 session_start();
 3 include("../ajax/DBDA.class.php");
 4 $db = new DBDA();
 5 $uid = $_POST["uid"];
 6 $pwd = $_POST["pwd"];
 7 
 8 $sql = "select count(*) from users where uid='{$uid}' and pwd='{$pwd}'";
 9 $n = $db->StrQuery($sql);
10 
11 if($n>0)
12 {
13     $_SESSION["uid"] = $uid;
14     header("location:main.php");
15 }
16 else
17 {
18     echo "登录失败!";
19 }
loginchuli.php

6.审批界面

 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 
 8 <body>
 9 
10 <h1>流程处理页面</h1>
11 
12 <!--审批过的也要显示-->
13 
14 <table width="100%" border="1" cellpadding="0" cellspacing="0">
15     <tr>
16         <td>流程代号</td>
17         <td>发起者</td>
18         <td>发起内容</td>
19         <td>是否结束</td>
20         <td>发起时间</td>
21         <td>操作</td>
22     </tr>
23 
24 <?php
25 session_start();
26 include("../ajax/DBDA.class.php");
27 $db = new DBDA();
28 $uid = "";
29 if(empty($_SESSION["uid"]))
30 {
31     header("location:login.php");
32 }
33 else
34 {
35     $uid = $_SESSION["uid"];
36 }
37 
38 
39 //查询登录者参与的所有流程
40 $su_flow = "select * from userflow where code in(select code from flowpath where uids='{$uid}')";
41 $au_flow = $db->Query($su_flow);
42 
43 foreach($au_flow as $vu_flow)
44 {
45     $towhere = $vu_flow[6]; //流程走到哪里了
46     
47     //找到登录者在该流程中的位置
48     $s_weizhi = "select orders from flowpath where code='{$vu_flow[1]}' and uids='{$uid}'";
49     $wezhi = $db->StrQuery($s_weizhi); //该人员在流程中的位置
50     
51     if($towhere>=$wezhi)
52     {
53         $caozuo = "";
54         if($towhere==$wezhi)
55         {
56             //流程正好走到登录者位置
57             $caozuo="<a href='tongguo.php?ids={$vu_flow[0]}'>通过</a>";
58         }
59         else
60         {
61             //流程走过登录者
62             $caozuo = "<span style='background-color:green; color:white'>已通过</span>";
63         }
64         echo "
65         <tr>
66             <td>{$vu_flow[1]}</td>
67             <td>{$vu_flow[2]}</td>
68             <td>{$vu_flow[3]}</td>
69             <td>{$vu_flow[4]}</td>
70             <td>{$vu_flow[5]}</td>
71             <td>{$caozuo}</td>
72         </tr>";
73     }
74     else
75     {
76         //流程未走到登录者
77     }    
78 }
79 ?>
80 </table>
81 </body>
82 </html>
main.php

6(1)通过界面处理     使用 多张表 联合查询 和  多张表 嵌套查询  (循环里面)

 1 <?php
 2 include("../ajax/DBDA.class.php");
 3 $db = new DBDA();
 4 $ids = $_GET["ids"];
 5 $sql = "update userflow set towhere=towhere+1 where ids='{$ids}'";
 6 $db->Query($sql,0);
 7 
 8 $swhere = "select * from userflow where ids='{$ids}'";
 9 $attr = $db->Query($swhere);
10 
11 $towhere = $attr[0][6]; //走到哪了
12 $code = $attr[0][1]; //流程代号
13 $ssl = "select count(*) from flowpath where code='{$code}'";
14 $pcount = $db->StrQuery($ssl); //该流程节点人员数量
15 
16 if($towhere>=$pcount)
17 {
18 $sql = "update userflow set isok=true where ids='{$ids}'";
19 $db->Query($sql,0);
20 }
21 header("location:main.php");
tongguo.php

  

posted @ 2017-01-18 14:19  get("新技能")  阅读(208)  评论(1编辑  收藏  举报