权限管理页面body>
<h1>权限管理</h1> <div>请选择用户: <select id="user"> <?php include("DBDA.php"); $db= new DBDA(); $sql ="select * from users"; $attr = $db->Query($sql); for($i=0;$i<count($attr);$i++) { echo "<option value=‘{$attr[$i][0]}‘>{$attr[$i][2]}</option>" } ?> </select> </div> <div>请选择角色:</div> <div> <?php $sqlj="select * from JueSe"; $attrj = $db->Query($sqlj); for($i=0;$i<count($attrj);$i++) { echo "<input class=‘js‘ type=‘checkbox‘ value=‘{$attrj[$i][1]}‘ />{$attrj[$i][1]} "; } ?> </div> <div><input id="sure" type="button" value="确定" /></div> </body> <script type="text/javascript"> $(document).ready(function(e){ ShowJs(); $("#user").change(function(){ShowJs();}) $("#sure").click(function(){ var uid = $("#user").val(); var js=""; var cks = $(".js"); for(var i=0;i<cks.length;i++){if(cks.eq(i)[0].checked){js=js+cks.eq(i).val()+"|";}}js = js.substr(0,js.length-1); $.ajax({url:"add.php",data:{uid:uid,juese:js},type:"POST",datatype:"TEXT",success:function(data){ alert(data); } }); }) function ShowJs(){
var uid = $("#user").val(); $.ajax({url:"JueSeChuLi.php",data:{uid:uid},type:"POST",dataType:"TEXT",success:function(data){ var ck = $(".js");for(var j=0;j<ck.length;j++){ck.eq(j).removeAttr("checked");} if(data.trim() !="") //trim()去除空格{var hang = data.split("|");for(var i =0;i<hang.length;i++){var lie = hang[i].split("^"); var ck = $(".js"); for(var j=0;j<ck.lenght;j++){if(ck.eq(j).val()==lie[2]){ck.eq(j).prop("checked",true);}} }} }});
} });</script>
JueSeChuLi.php
<?php $uid = $_POST["uid"]; include("DBDA.php"); $db = new DBDA(); $sql = "select * from UserInJueSe where UserId = ‘{$uid}‘"; echo $db->StrQuery($sql);
add.php
$uid = $_POST["uid"]; $juese=$_POST["juese"]; include("DBDA.php"); $db = new DBDA(); $sqld = "delete from UserInJueSe where UserId=‘{$uid}‘"; $db->Query($sqld,0); $js = explode("|",$juese); $isok = true; for($i=0;$i<count($js);$i++) { $sql = "insert into UserInJueSe values(‘‘,‘{$uid}‘,‘{$js[$i]}‘)"; $isok = $isok && $db->Query($sql,0); } if($isok) { echo "ok"; } else { echo "no"; }
loginchuli.php
<?php session_start() $uid = $_POST["uid"]; $pwd= $_POST["pwd"]; include("DBDA.php"); $db = new DBDA(); $sql = "select count(*) from Users where Uid=‘{$uid}‘ and Pwd=‘{$pwd}‘"; if($db->StrQuery($sql)=="1") { $_SESSION["uid"]=$uid; header("location:main.php") } else { header("location:login.php"); }
main.php
<body> <?php session_start(); if(!empty($_SESSION["uid"])) { $uid = $_SESSION["uid"]; } else { header("location:login.php"); } include("DBDA.php"); $db -> new DBDA(); //根据用户名查角色 $sql ="select * from UserInJueSe where UserId=‘{$uid}‘"; $attrj =$db->Query($sqlj); //存放功能代号的数组 $attr = array(); for($i=0;$i<count($attrj);$i++) { //根据角色查功能 $js = $attrj[$i][2]; $sqlr = "select RuleId from JueSeWithRules where JueSeId=‘{$js}‘"; $strr = $db->StrQuery($sqlr); $attrr = explode("|",$strr); //将数组合并 $attr = array_merge($attr,$attrr); } //去重 $attr = array_unique($attr); //根据功能代号查功能名称并显示在div里面 for($j=0;$j<count($attr);$j++) { $sqlg = "select Name from Rules where Code=‘{$attr[$j]}‘"; $name = $db->StrQuery($sqlg); echo "<div class =‘menu‘>{$name}</div>" } ?> </body>
时间: 2024-10-28 18:44:11