管理页面
1 <script src="../../jquery-1.11.2.min.js"></script> 2 </head> 3 4 <body> 5 <?php 6 include("../DBDA.class.php"); 7 $db = new DBDA(); 8 ?> 9 <br /> 10 11 <div> 12 请选择用户: 13 <select id="sel"> 14 <?php 15 $sql = "select * from users"; 16 $attr = $db->Query($sql); 17 foreach($attr as $v) 18 { 19 echo "<option value='{$v[0]}'>{$v[2]}</option>"; 20 } 21 //取到第一个人的用户名 22 $fuid = $attr[0][0]; 23 24 ?> 25 </select> 26 </div> 27 <br /> 28 <div> 29 请选择角色:<br /><br /> 30 <?php 31 $sjuese="select * from juese"; 32 $ajuese = $db->Query($sjuese); 33 foreach($ajuese as $v) 34 { 35 $sxz = "select count(*) from userinjuese where userid='{$fuid}' and jueseid='{$v[0]}'"; 36 37 $n = $db->StrQuery($sxz); 38 39 if($n>0) 40 { 41 echo "<input type='checkbox' class='juese' checked='checked' value='{$v[0]}' /> {$v[1]} "; 42 } 43 else 44 { 45 echo "<input type='checkbox' class='juese' value='{$v[0]}' /> {$v[1]} "; 46 } 47 } 48 ?> 49 </div> 50 51 <br /> 52 <input type="button" value="保存" id="btn" /> 53 54 </body> 55 <script type="text/javascript"> 56 57 $("#sel").change(function(){ 58 var uid = $("#sel").val(); 59 $.ajax({ 60 url:"chuli.php", 61 data:{uid:uid}, 62 type:"POST", 63 dataType:"TEXT", 64 success: function(data){ 65 var js = data.split("|"); 66 67 //清除选中状态 68 var ck = $(".juese"); 69 ck.prop("checked",false); 70 71 //让等于返回角色代号的选中 72 for(var i=0;i<ck.length;i++) 73 { 74 if(js.indexOf(ck.eq(i).val())>-1) 75 { 76 ck.eq(i).prop("checked",true); 77 } 78 79 } 80 81 } 82 }); 83 }) 84 85 $("#btn").click(function(){ 86 var uid = $("#sel").val(); 87 //角色代号 88 var ck = $(".juese"); 89 var str =""; 90 for(var i=0;i<ck.length;i++) 91 { 92 if(ck.eq(i).prop("checked")) 93 { 94 str=str+ck.eq(i).val()+"|"; 95 } 96 } 97 str = str.substr(0,str.length-1); 98 99 $.ajax({ 100 url:"add.php", 101 data:{uid:uid,juese:str}, 102 type:"POST", 103 dataType:"TEXT", 104 success: function(){ 105 alert("保存成功!"); 106 } 107 }); 108 109 }) 110 </script>
管理处理
1 <?php 2 include("../DBDA.class.php"); 3 $db = new DBDA(); 4 5 $uid = $_POST["uid"]; 6 7 $sql = "select jueseid from userinjuese where userid='{$uid}'"; 8 9 echo $db->StrQuery($sql);
管理权限添加
1 <?php 2 include("../DBDA.class.php"); 3 $db = new DBDA(); 4 5 $uid = $_POST["uid"]; 6 $juese = $_POST["juese"]; 7 8 $attr = explode("|",$juese); 9 10 //删除所有该用户的角色信息 11 $sdel = "delete from userinjuese where userid='{$uid}'"; 12 $db->Query($sdel,0); 13 14 //将取到了角色信息添加进去 15 foreach($attr as $v) 16 { 17 $sql = "insert into userinjuese values('','{$uid}','{$v}')"; 18 $db->Query($sql,0); 19 }
登陆页面
1 <form action="loginchuli.php" method="post"> 2 <div>用户名:<input type="text" name="uid" /></div> 3 <div>密码:<input type="password" name="pwd" /></div> 4 <input type="submit" value="登录" /><br /> 5 </form>
登陆处理
1 session_start(); 2 include("../DBDA.class.php"); 3 $db = new DBDA(); 4 $uid = $_POST["uid"]; 5 $pwd = $_POST["pwd"]; 6 7 $sql = "select pwd from users where uid='{$uid}'"; 8 $mm = $db->StrQuery($sql); 9 10 if($mm==$pwd && $pwd!="") 11 { 12 $_SESSION["uid"] = $uid; 13 header("location:main.php"); 14 } 15 else 16 { 17 echo "登录失败!"; 18 }
主页
1 <style type="text/css"> 2 *{ margin:0px auto; padding:0px} 3 .list{ width:100px; height:35px; background-color:#66C; color:white; text-align:center; line-height:35px; vertical-align:middle; float:left} 4 </style> 5 </head> 6 <?php 7 session_start(); 8 include("../DBDA.class.php"); 9 $db = new DBDA(); 10 11 if(empty($_SESSION["uid"])) 12 { 13 header("location:login.php"); 14 exit; 15 } 16 17 $uid = $_SESSION["uid"]; 18 19 ?> 20 <body> 21 22 <div style="width:100%; height:35px;"> 23 <?php 24 25 //根据用户名查角色代号 26 $sjuese="select jueseid from userinjuese where userid='{$uid}'"; 27 $ajuese = $db->Query($sjuese); 28 29 //根据角色代号查功能 30 $attr = array(); 31 foreach($ajuese as $v) 32 { 33 $sgn = "select ruleid from juesewithrules where jueseid='{$v[0]}'"; 34 $agn = $db->Query($sgn); 35 $attr = array_merge($attr,$agn); 36 } 37 //对功能代号数组进行去重 38 39 $attr = array_unique($attr,SORT_REGULAR); 40 41 42 43 foreach($attr as $v) 44 { 45 $sname = "select name from rules where code='{$v[0]}'"; 46 $name = $db->StrQuery($sname); 47 echo "<div class='list'>{$name}</div>"; 48 } 49 50 51 ?> 52 </div>