标签:
权限管理界面
<!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 type="text/javascript" src="./jquery-1.11.2.min.js"></script> </head> <body> <h1>权限管理界面</h1> <?php include("DBDA.php"); $db=new DBDA(); //取出人员 $usesql="select * from users"; $user=$db->Query($usesql); //取出职务 $rsql="select * from juese"; $jse=$db->Query($rsql); ?> <div> <select id="users"> <?php foreach($user as $v) { echo "<option value=‘{$v[0]}‘>{$v[2]}</option>"; } ?> </select> </div> <div> <?php //复选框 foreach($jse as $v) { echo "<input type=‘checkbox‘ value=‘{$v[0]}‘ class=‘ajuese‘>{$v[1]} "; } ?> </div> <div> <input type="button" value="保存" id=‘btn‘> </div> </body> <script type="text/javascript"> $(document).ready(function (e) { JSxianshi(); $("#btn").click(function() { var users = $("#users").val(); //alert(users); var ck = $(".ajuese"); var js = ""; for (var i = 0; i < ck.length; i++) { if (ck[i].checked) { js = js + ck.eq(i).val() + "|"; } } js = js.substr(0, js.length - 1); //alert(js); $.ajax({ url: "0704pmguanlichuli.php", data: {users: users, js: js}, type: "POST", dataType: "TEXT", success: function (data) { if (data.trim() == "ok") { alert("写入成功"); } else { alert("失败"); } } }) }) $("#users").change(function() { JSxianshi(); }) }) function JSxianshi() { var users = $("#users").val(); $.ajax({ url: "0704pmxianshi.php", data: {users: users}, type: "POST", dataType: "TEXT", success: function (data) { //清空原有选中信息 $(".ajuese").prop("checked", false); //找到该人员对应的角色代号数组 var attr = data.split("|"); //找到所有的checkbox var ck = $(".ajuese"); //遍历每个复选框,设置选中 for (var i = 0; i < ck.length; i++) { var dh = ck.eq(i).val(); //$.inArray(dh,attr) 判断元素是否在数组中,如果在返回所在位置的索引,如果不在返回-1 if ($.inArray(dh, attr) >= 0) { ck.eq(i).prop("checked", true); } } } }); } </script> </html>
0704pmguanlichuli.php 管理处理
<?php include("DBDA.php"); $db=new DBDA(); $users=$_POST["users"]; $juese=$_POST["js"]; //将传入的角色字符串拆分为数组 $attr= explode("|",$juese); //删除原数据 $sqldel="delete from userinjuese where userid=‘{$users}‘"; $db->query($sqldel,0); //循环添加数据 foreach($attr as $v) { $sql="insert into userinjuese values(‘‘,‘{$users}‘,‘{$v}‘)"; $db->query($sql,0); } echo "ok";
0704pmxianshi.php
<?php include("DBDA.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="0704pmloginchuli.php" method="post"> <div>用户名<input type="text" name="uid"></div> <div>密码<input type="password" name="pwd"></div> <div><input type="submit" value="登录" ></div> </form> </body> </html>
0704pmloginchuli.php
<?php session_start(); include("DBDA1.php"); $db=new DBDA(); $uid=$_POST["uid"]; $pwd=$_POST["pwd"]; $sql="select pwd from users where uid=‘{$uid}‘"; $mima=$db->StrQuery($sql); if($mima==$pwd and $uid!="" and $pwd!="") { $_SESSION["uid"]=$uid; header("location:0704pmmain.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> </head> <?php session_start(); include("DBDA.php"); $db=new DBDA(); if(empty($_SESSION["uid"])) { header("location:0704pmlogin.php"); exit; } $uid=$_SESSION["uid"]; //根据用户名查找对应角色表,找出相应的角色代号 $sql="select jueseid from userinjuese where userid=‘{$uid}‘"; $attr= $db->query($sql); //根据角色查找功能 $gn=array(); foreach($attr as $v) { $sgn="select ruleid from juesewithrule where jueseid=‘{$v[0]}‘"; $agn=$db->query($sgn); $gn=array_merge($gn,$agn); } //var_dump($gn); //转换为一位数组 foreach($gn as $v) { $onegn[]= $v[0]; } //对功能的一维数组去重 $onegn=array_unique($onegn); ?> <body> <h1>主页面<h1> <div id="menu"> <?php foreach($onegn as $v) { $sname="select name from rules where code=‘{$v}‘"; $name=$db->StrQuery($sname); echo "<div class=‘list‘>{$name}</div>"; } ?> </div> </body> </html>
标签:
原文地址:http://www.cnblogs.com/pangchunlei/p/5646272.html