标签:
权限管理:rbac
用户表
用户对应角色表
角色表
角色对应功能表
功能表
用户角色对照页面、
<?php //判断是否登录 session_start(); if (empty($_SESSION["uid"])) { header("location:denglu.php"); exit(); } else { @$uid=$_SESSION["uid"]; } ?> <!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> <table width="100%" align="center"> <tr> <div align="left"> 用户 <select id="yh"> <?php include ("./DBDA.class.php"); $db=new DBDA(); $sql="select * from yonghu"; $attr=$db->Query($sql); foreach($attr as $v) { echo "<option value=‘{$v[0]}‘>{$v[2]}</option>"; } ?> </select> </div> </tr> <tr> <div>职务 <?php $sql1="select * from jiaose"; $attr=$db->Query($sql1); foreach($attr as $u) { echo "<div><input type=‘checkbox‘ value=‘{$u[0]}‘ class=‘rd‘/>{$u[1]}</div>"; } ?> </div> </tr> <tr> <input type="button" id="btn" value="提交" /> </tr> <div> </table> <script type="text/javascript" > $(document).ready(function(e) { JiaoSe(); $("#btn").click(function(e) { //取人员选中值 var uid=$("#yh").val(); //取复选框选中值 var ck=$(".rd"); var js=""; for(var i=0;i<ck.length;i++) { if(ck[i].checked)// jq 写法ck.eq(i).prop("checked"); { js=js+ck.eq(i).val()+"|"; } } js=js.substr(0,js.length-1); //用ajax操作数据库 $.ajax({ url:"yonghuzhiwuduizhaochuli.php", data:{js:js,uid:uid}, dataType:"TEXT", type:"POST", success: function(data){ if(data.trim()=="ok") { alert("操作成功"); } else { alert("操作失败"); } } }); }); $("#yh").change(function(e) { JiaoSe(); }); }); function JiaoSe() { var uid= $("#yh").val(); $.ajax({ url:"yonghuzhiwuduizhaochuli1.php", data:{uid:uid}, dataType:"TEXT", type:"POST", success: function(data){ //清空原有选中信息 $(".rd").prop("checked",false); var workid=data.split("|") var ck= $(".rd"); for (var i=0; i<ck.length;i++) { //判断元素在不在数组中 var dh=ck.eq(i).val(); //$.inArray(dh,attr)判断元素是否在数组中, // 如果在返回所在位置的索引,如果不再返回-1 if ($.inArray(dh,workid)>=0) { ck.eq(i).prop("checked",true); } } } }); } </script> </div> </div> </body>
用户处理页面
<?php $uid=$_POST["uid"]; include ("./DBDA.class.php"); $db=new DBDA(); $sql1="select workid from yonghujiaoseduiying where uid=‘{$uid}‘"; $str=$db->StrQuery($sql1); echo $str;
职务处理页面
<?php include ("./DBDA.class.php"); $db=new DBDA(); $uid=$_POST["uid"]; $js=$_POST["js"]; //拆分js $attr=explode("|",$js); //删除原数据 $sql0="delete from yonghujiaoseduiying where uid=‘{$uid}‘"; $db->Query($sql0,0); //循环添加 foreach ($attr as $v) { $sql1="insert into yonghujiaoseduiying values(‘‘,‘{$uid}‘,‘{$v}‘)"; $result=$db->Query($sql1,0); } echo "ok";
角色功能页面
<?php //判断是否登录 session_start(); if (empty($_SESSION["uid"])) { header("location:denglu.php"); exit(); } else { @$uid=$_SESSION["uid"]; } ?> <!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> <?php include ("./DBDA.class.php"); $db=new DBDA(); /*$uid=$_SEESSION["uid"];*/ $uid="admin"; //从用户角色对照表查询角色id $sql1="select workid from yonghujiaoseduiying where uid=‘{$uid}‘"; $attr1=$db->Query($sql1); //从角色功能对照表查询 //存放功能的数组 $hebing=array();//二维数组 foreach ($attr1 as $v) { $attr2="select functionid from jiaosegongnengduiying where workid=‘{$v[0]}‘"; $attr2=$db->Query($attr2); //数组合并 $hebing=array_merge($hebing,$attr2); } //数组去重 $rq=array();//一位数组 //二维数组转一位数组 foreach($hebing as $v) { $rq[]=$v[0]; //赋值 } $re=array_unique($rq); foreach($re as $v) { //根据功能id查询功能 $sql2="select function from gongneng where functionid=‘{$v}‘"; $attr3=$db->Query($sql2); //显示 foreach($attr3 as $v) { echo "<div class=‘remove‘ style=‘ float: left; padding: 0 5px 0 12px; line-height: 35px; color: #8a6d3b; font-family: 微软雅黑; font-weight: bold; font-size: 14px;‘ >{$v[0]}</div>"; } } ?> </div> </div> </body>
标签:
原文地址:http://www.cnblogs.com/zoubizhici/p/5668190.html