本文实例为大家分享了ajax和php实现简单的流程管理,供大家参考,具体内容如下
首先要先有一个新建流程的页面xinjian.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<!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> 请选择节点人员: <select id= "user" > <?php session_start(); //需要将一些数据暂时存在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= "添加节点" 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>" ; //向处理页面传的是key的值 } } ?> </div> <br /> <div>请输入流程名称:<input type= "text" id= "name" /></div> <br /> <input type= "button" value= "保存" id= "btn" /> </body> <script type= "text/javascript" > //添加节点按钮加点击 $( "#add" ).click( function (){ var uid = $( "#user" ).val(); $.ajax({ url: "chuli.php" , data:{uid:uid,type:0}, //传入一个type参数,以确保在同一页面处理时与其它的分开处理 type: "post" , datatype: "text" , success: function (data){ window.location.href= "xinjian.php" rel= "external nofollow" rel= "external nofollow" ; //刷新页面 } }); }) //给删除按钮加点击 $( ".del" ).click( function (){ var key = $(this).attr( "key" ); //取删除的是哪条数据 $.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" ; } }); }) //给保存按钮加点击 $( "#btn" ).click( function (){ var name = $( "#name" ).val(); //取输入框中输入内容的值 $.ajax({ url: "chuli.php" , data:{name:name,type:2}, type: "post" , datatype: "text" , success: function (data){ alert( "保存成功!" ); } }); }) </script> </html> |
数据库图片:
处理页面chuli.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
<?php session_start(); include ( "../fengzhuang/dbda.class.php" ); $db = new dbda(); $type = $_post [ "type" ]; switch ( $type ) { case 0: //添加节点的加载数据,向session数组中添加数据 $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: //取节点的索引,然后删除,重新索引 $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); //添加流程节点 $arr = $_session [ "user" ]; foreach ( $arr as $k => $v ) { $sql = "insert into flowpath values('','{$code}','{$v}','{$k}')" ; $db ->query( $sql ,0); } break ; case 3: //用户发起流程 $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 ; } |
发起流程页面faqi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<!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><br /> <script src= "../fengzhuang/jquery-3.1.1.min.js" ></script> </head> <body> <h1>发起流程</h1> <div> 请选择发起的流程: <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> 请输入内容: <textarea id= "nr" ></textarea> </div> <br /> <input type= "button" value= "发起" 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( "发起成功!" ); } }); }) </script> </html> |
审核页面shenhe.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<!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>发起者</td> <td>发起内容</td> <td>是否结束</td> <td>发起时间</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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
<?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); //判断流程是否结束 $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 ); //该流程节点人数 if ( $tw >= $count ) { $sql = "update userflow set isok=1 where ids='{$code}'" ; //如果结束了流程,将isok项改为结束。 $db ->query( $sql ,0); } header( "location:shenhe.php" ); |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。