PHP人员管理
<a href='tongguo.php?ids={$vu_flow[0]}'>通过</a> 使用 get 方法接受数据
难点: 联合查询 查询的嵌套
1.一个提交内容分别提交到不同的界面
2.一条信息 需要同时 查询 不同的表格
一.人员管理
①.自己做的 界面处理部分 页面处理部分 转化储存在数组中 数组索引的 处理 和 数组转化为字符串
JSON 往 PHP 界面传值得时候 必须使用 字符串
AJAX 和 <?php ?> 使用的选择 如果不需要 频繁刷新的 界面内容 最好使用后者 DOM 添加checked
注意去重处理:
<!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="jquery-1.11.2.min.js"></script> </head> <body> <form action="chuli.php" method="post"> <select name="xuanze" id="xuanze"></select> <div>请选择职位</div> <div id="zhiwei"></div> <input id="tijiao" type="button" value="tijiao"> </form> </body> <script> $(document).ready(function(e) { duoxuan(); fuxuan(); tianjia(); $("#xuanze").change(function(){ tianjia(); }) $("#tijiao").click(function(){ tijiao(); }) }); function duoxuan() { $.ajax({ async:false, url:"xuanze.php", dataType:"JSON", success: function(date){ var str=""; for(var v in date) {//value里面存的是人的id str += "<option name = '"+date[v][1]+"' value= '"+date[v][1]+"'>"+date[v][3]+"</option>"; } $("#xuanze").html(str); }//success括号 })//下拉AJAX } function fuxuan() { $.ajax({ async:false, url:"fuxuan.php", dataType:"JSON", success: function(u) { str = ""; for(var k in u) { str+=" <input type='checkbox' class='aa' value='"+u[k][1]+"'>"+u[k][2]+"</input>"//储存的是职位代号 } $("#zhiwei").html(str); } }) } function tianjia() { var value = $("#xuanze").val(); $.ajax({ async:false, data:{value:value}, type:"POST", url:"tianjia.php", dataType:"JSON", success: function(u) { $(".aa").prop("checked",false); for( var k in u) //value 里面存的是职位代号 { $("[value='"+u[k][0]+"']").prop("checked",true); } } }) } function tijiao() { var value = $("#xuanze").val(); var tt = $(".aa"); var attr = new Array(); var i=0//注意变量位置 for(var k=0; k<tt.length; k++) { if(tt[k].checked) { attr[i] = tt[k].value; i++; } } var astr= attr.join("--"); $.ajax({ async:false, data:{value:value,astr:astr},//人的id 和 职位代号 传过去 type:"POST", url:"tijiao.php", dataType:"TEXT", success: function(u) { if(u.trim()=="OK") alert("修改成功"); else alert("失败!"); } }) } </script> </html>
1.管理界面处理 数组转化为字符串 JQ 添加选中 checked方法
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 <body> 9 <h1>人员对应角色管理</h1> 10 <div> 11 请选择人员: 12 <select id="user"> 13 <?php 14 include("../ajax/DBDA.class.php"); 15 $db = new DBDA(); 16 $sql = "select * from users"; 17 $attr = $db->Query($sql); 18 foreach($attr as $v) 19 { 20 echo "<option value='{$v[0]}'>{$v[2]}</option>"; 21 } 22 ?> 23 </select> 24 </div> 25 <br /> 26 <div> 27 请选择角色: 28 <?php 29 $sjs = "select * from juese"; 30 $ajs = $db->Query($sjs); 31 foreach($ajs as $v) 32 { 33 echo "<input class='ck' type='checkbox' value='{$v[0]}' />{$v[1]}"; 34 } 35 ?> 36 37 </div> 38 <br /> 39 40 <input type="button" value="保存" id="save" /> 41 42 </body> 43 <script type="text/javascript"> 44 45 XuanZhong(); 46 47 $("#user").change(function(){ 48 XuanZhong(); 49 }) 50 51 $("#save").click(function(){ 52 var uid = $("#user").val(); 53 var ck = $(".ck"); 54 var str = ""; 55 for(var i=0;i<ck.length;i++) 56 { 57 if(ck.eq(i).prop("checked")) 58 { 59 str = str+ck.eq(i).val()+"|"; 60 } 61 } 62 str = str.substr(0,str.length-1); 63 64 $.ajax({ 65 url:"add.php", 66 data:{uid:uid,js:str}, 67 type:"POST", 68 dataType:"TEXT", 69 success: function(data){ 70 if(data.trim()=="OK") 71 { 72 alert("保存成功!"); 73 } 74 } 75 }); 76 77 }) 78 79 function XuanZhong() 80 { 81 var uid = $("#user").val(); 82 $.ajax({ 83 url:"seljuese.php", 84 data:{uid:uid}, 85 type:"POST", 86 dataType:"TEXT", 87 success: function(data){ 88 var sz = data.split("|"); 89 90 var ck = $(".ck"); 91 92 ck.prop("checked",false); 93 94 for(var i=0;i<ck.length;i++) 95 { 96 var zhi = ck.eq(i).val(); 97 if(sz.indexOf(zhi)>=0) 98 { 99 ck.eq(i).prop("checked",true); 100 } 101 } 102 } 103 }); 104 } 105 </script> 106 </html>
2.seljuese
1 <?php 2 include("../ajax/DBDA.class.php"); 3 $db = new DBDA(); 4 $uid = $_POST["uid"]; 5 $sql = "select jueseid from userinjuese where userid='{$uid}'"; 6 echo $db->StrQuery($sql);
3.add.php
1 <?php 2 include("../ajax/DBDA.class.php"); 3 $db = new DBDA(); 4 $uid = $_POST["uid"]; 5 $js = $_POST["js"]; 6 7 $sdelete = "delete from userinjuese where userid='{$uid}'"; 8 $db->Query($sdelete,0); 9 10 $attr = explode("|",$js); 11 12 foreach($attr as $v) 13 { 14 $sql = "insert into userinjuese values('','{$uid}','{$v}')"; 15 $db->Query($sql,0); 16 } 17 18 echo "OK";
4.登录界面
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 <form action="loginchuli.php" method="post"> 10 <div>用户名:<input type="text" name="uid" /></div> 11 <div>密码:<input type="text" name="pwd" /></div> 12 <input type="submit" value="登录" /> 13 </form> 14 </body> 15 </html>
5.loginchuli.php
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 10 if($db->StrQuery($sql)>0) 11 { 12 $_SESSION["uid"]= $uid; 13 header("location:main.php"); 14 } 15 else 16 { 17 echo "登录失败!"; 18 }
二.注意多个AJAX连接到一个界面的处理
界面处理 多个AJAX传值到一个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="jquery-1.11.2.min.js"></script> 7 </head> 8 9 <body> 10 <div> 11 请选择流程节点: 12 13 <?php 14 session_start(); 15 include("./LIU.class.php"); 16 $db = new Liu(); 17 18 $suser ="select * from users"; 19 $auser = $db->Query($suser); 20 21 foreach($auser as $v) 22 { 23 echo "<input class='rd' type='radio' name='user' value='{$v[0]}' /> {$v[1]} "; 24 } 25 26 ?> 27 28 </div> 29 <br /> 30 <div><input type="button" value="添加节点" id="jiedian" /></div> 31 <br /> 32 33 <div> 34 <?php 35 $attr = array(); 36 if(!empty($_SESSION["user"])) 37 { 38 $attr = $_SESSION["user"]; 39 } 40 $attr = array_unique($attr); 41 42 foreach($attr as $k=>$v) 43 { 44 $sname = "select name from users where uname='{$v}'"; 45 $name = $db->StrQuery($sname); 46 47 echo "<div>{$k}--{$name}--<input type='button' value='删除' bs='{$k}' class='shanchu' /></div>"; 48 } 49 50 ?> 51 </div> 52 <br /> 53 <div> 54 请输入流程名称: 55 <input type="text" id="name" /> 56 </div> 57 <br /> 58 <input type="button" value="保存" id="xinjian" /> 59 60 61 <script type="text/javascript"> 62 $("#jiedian").click(function(){ 63 64 //取选中的用户名 65 var rd = $(".rd"); 66 for(var i=0;i<rd.length;i++) 67 { 68 if(rd.eq(i).prop("checked")) 69 { 70 uid = rd.eq(i).val(); 71 } 72 } 73 74 $.ajax({ 75 url:"add.php", 76 data:{uid:uid,type:0}, 77 type:"POST", 78 dataType:"TEXT", 79 success: function(data){ 80 window.location.href="main.php"; 81 } 82 }); 83 84 }) 85 86 $(".shanchu").click(function(){ 87 var sy = $(this).attr("bs"); 88 $.ajax({ 89 url:"add.php", 90 data:{sy:sy,type:1}, 91 type:"POST", 92 dataType:"TEXT", 93 success: function(data){ 94 window.location.href="main.php"; 95 } 96 }); 97 }) 98 $("#xinjian").click(function(){ 99 var name = $("#name").val(); 100 $.ajax({ 101 url:"add.php", 102 data:{name:name,type:2}, 103 type:"POST", 104 dataType:"TEXT", 105 success: function(data){ 106 window.location.href="main.php"; 107 } 108 }); 109 }) 110 </script> 111 </body> 112 </html>
php端处理
1 <?php 2 session_start(); 3 include("./LIU.class.php"); 4 $db = new Liu(); 5 6 $type = $_POST["type"]; 7 8 switch($type) 9 { 10 case 0: 11 $uid = $_POST["uid"]; 12 if(empty($_SESSION["user"])) 13 { 14 $_SESSION["user"] = array($uid); 15 } 16 else 17 { 18 $attr = $_SESSION["user"]; 19 $attr[] = $uid; 20 $attr = array_values($attr); 21 $_SESSION["user"] = $attr; 22 } 23 break; 24 case 1: 25 $sy = $_POST["sy"]; 26 $attr = $_SESSION["user"]; 27 unset($attr[$sy]); 28 $attr = array_values($attr); 29 $_SESSION["user"] = $attr; 30 break; 31 case 2: 32 $name = $_POST["name"]; 33 $code = time(); 34 $slc = "insert into liucheng values('{$code}','{$name}')"; //liucheng 名字 代号 35 $db->Query($slc,0); 36 37 $attr = array(); 38 if(!empty($_SESSION["user"])) 39 { 40 $attr = $_SESSION["user"]; 41 } 42 43 foreach($attr as $k=>$v) 44 { 45 $sfp = "insert into flowpath values('','{$code}','{$v}','{$k}')"; //flowpath 流程具体经过哪些人 46 $db->Query($sfp,0); 47 } 48 49 break; 50 case 3: 51 $code = $_POST["code"]; 52 $nr = $_POST["nr"]; 53 $uid = $_SESSION["uid"]; 54 $rq = time(); 55 $sql = "insert into userflow values('','{$code}','{$uid}','{$nr}',0,'{$rq}',0)"; //userflow 流程具体内容,名字,发起人 56 $db->Query($sql,0); //,内容,是否通过,事件,进行到哪一步 57 break; 58 }