01-17权限管理
管理页面:
<!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="../ajaxfenye/jquery-1.11.2.min.js"></script>
</head>
<body>
<h1>人员对应角色管理</h1>
<div>
请选择人员:
<select id="user">
<?php
include("../ajax/DBDA.class.php");
$db = new DBDA();
$sql = "select * from users";
$attr = $db->Query($sql);
foreach($attr as $v)
{
echo "<option value='{$v[0]}'>{$v[2]}</option>";
}
?>
</select>
</div>
<br />
<div>
请选择角色:
<?php
$sjs = "select * from juese";
$ajs = $db->Query($sjs);
foreach($ajs as $v)
{
echo "<input class='ck' type='checkbox' value='{$v[0]}' />{$v[1]}";
}
?>
</div>
<br />
<input type="button" value="保存" id="save" />
</body>
<script type="text/javascript">
XuanZhong();
$("#user").change(function(){
XuanZhong();
})
$("#save").click(function(){
var uid = $("#user").val();
var ck = $(".ck");
var str = "";
for(var i=0;i<ck.length;i++)
{
if(ck.eq(i).prop("checked"))
{
str = str+ck.eq(i).val()+"|";
}
}
str = str.substr(0,str.length-1);
$.ajax({
url:"add.php",
data:{uid:uid,js:str},
type:"POST",
dataType:"TEXT",
success: function(data){
if(data.trim()=="OK")
{
alert("保存成功!");
}
}
});
})
function XuanZhong()
{
var uid = $("#user").val();
$.ajax({
url:"seljuese.php",
data:{uid:uid},
type:"POST",
dataType:"TEXT",
success: function(data){
var sz = data.split("|");
var ck = $(".ck");
ck.prop("checked",false);
for(var i=0;i<ck.length;i++)
{
var zhi = ck.eq(i).val();
if(sz.indexOf(zhi)>=0)
{
ck.eq(i).prop("checked",true);
}
}
}
});
}
</script>
</html>
添加页面
<?php
include("../ajax/DBDA.class.php");
$db = new DBDA();
$uid = $_POST["uid"];
$js = $_POST["js"];
$sdelete = "delete from userinjuese where userid='{$uid}'";
$db->Query($sdelete,0);
$attr = explode("|",$js);
foreach($attr as $v)
{
$sql = "insert into userinjuese values('','{$uid}','{$v}')";
$db->Query($sql,0);
}
echo "OK";
角色界面
<?php
include("../ajax/DBDA.class.php");
$db = new DBDA();
$uid = $_POST["uid"];
$sql = "select jueseid from userinjuese where userid='{$uid}'";
echo $db->StrQuery($sql);
登陆界面
<!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>
<form action="loginchuli.php" method="post">
<div>用户名:<input type="text" name="uid" /></div>
<div>密码:<input type="text" name="pwd" /></div>
<input type="submit" value="登录" />
</form>
</body>
</html>
登陆处理界面
<?php
session_start();
include("../ajax/DBDA.class.php");
$db = new DBDA();
$uid = $_POST["uid"];
$pwd = $_POST["pwd"];
$sql = "select count(*) from users where uid='{$uid}' and pwd='{$pwd}'";
if($db->StrQuery($sql)>0)
{
$_SESSION["uid"]= $uid;
header("location:main.php");
}
else
{
echo "登录失败!";
}
主界面
<!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>
<style type="text/css">
.menu{ float:left; width:100px; height:35px; text-align:center; line-height:35px; vertical-align:middle; background-color:#63C; color:white; border-right:1px solid white;}
</style>
</head>
<body>
<?php
session_start();
$uid = "";
if(empty($_SESSION["uid"]))
{
header("location:login.php");
}
else
{
$uid = $_SESSION["uid"];
}
include("../ajax/DBDA.class.php");
$db = new DBDA();
//根据用户名查询角色代号
$sjs = "select jueseid from userinjuese where userid='{$uid}'";
$ajs = $db->Query($sjs);
//根据角色代号查功能代号
$attr = array(); //存功能代号
foreach($ajs as $v)
{
$sgn = "select ruleid from juesewithrules where jueseid='{$v[0]}'";
$agn = $db->Query($sgn);
foreach($agn as $vg)
{
$attr[] = $vg[0];
}
}
$attr = array_unique($attr);
//遍历所有功能显示菜单
foreach($attr as $v)
{
$sql = "select name from rules where code='{$v}'";
$name = $db->StrQuery($sql);
echo "<div class='menu' bs='{$v}'>{$name}</div>";
}
?>
</body>
</html>