首页 > 代码库 > 用户的权限列表编辑
用户的权限列表编辑
/*
* 用户的权限列表编辑
*
* */
function setaccess()
{
$id=$_GET[‘id‘];
$D=M("Access");
$rdata=http://www.mamicode.com/$D->where("role_id=".$id)->getField("node_id",true);
$M=M("Node");
$data=http://www.mamicode.com/$M->where("pid=0")->select();
foreach($data as &$v)
{
$v[‘second‘]=$M->where("pid=".$v[‘id‘])->select();
foreach($v[‘second‘] as &$t)
{
$t[‘third‘]=$M->where("pid=".$t[‘id‘])->select();
}
}
$this->assign("rdata",$rdata);
$this->assign("role_id",$id);
$this->assign("nodelist",$data);
$this->display();
}
function addaccess()
{
$M=M("access");
$M->where("role_id=".$_POST[‘role_id‘])->delete();
$data=http://www.mamicode.com/array();
foreach($_POST[‘access‘]as $v)
{
$tmp=explode("_",$v);
$data[]=array(
‘role_id‘=>$_POST[‘role_id‘],
‘node_id‘=>$tmp[0],
‘level‘=>$tmp[1]
);
}
//dump($_POST);
$succ=$M->addall($data);
if($succ!==false)
{
$this->success("添加成功!","rolelist");
}
else
{
$this->success("添加失败!");
}
}
}
HTML:
<!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>
<link href="http://www.mamicode.com/__ROOT__/Public/css/style.css" rel="stylesheet" type="text/css" />
<script src="http://www.mamicode.com/__ROOT__/Public/js/jquery.js"></script>
</head>
<script language="javascript">
$(function (){
$("input").click(function(){
var level=$(this).attr("level");
if(level==1)
{
var str="_";
var inputs=$("input[value*="+str+"]");
$(this).attr("checked")?inputs.attr("checked",true):inputs.removeAttr("checked");
}
else if(level==2)
{
var id=$(this).attr("id");
var inputs=$("input[pid="+id+"]");
$(this).attr("checked")?inputs.attr("checked",true):inputs.removeAttr("checked");
var pid=$(this).attr("pid");
var put=$("input[id="+pid+"]");
$(this).attr("checked")?put.attr("checked",true):put.removeAttr("checked");
}
else if(level==3)
{
var pid=$(this).attr("pid");
var inputs=$("input[id="+pid+"]");
$(this).attr("checked")?inputs.attr("checked",true):"";
var pids=$("input[id="+pid+"]").attr("pid");
var put=$("input[id="+pids+"]");
$(this).attr("checked")?put.attr("checked",true):"";
}
});
});
</script>
<body>
<div class="place">
<span>位置:</span>
<ul class="placeul">
<li><a href="http://www.mamicode.com/#">首页</a></li>
<li><a href="http://www.mamicode.com/#">表单</a></li>
</ul>
</div>
<div class="formbody">
<div class="formtitle"><span>基本信息</span></div>
<form method="post" action="{:U(‘Access/addaccess‘)}">
<foreach name="nodelist" item="first">
<div style="clear:both; line-height:40px;">
<input type="checkbox" id="{$first.id}" name="access[]" <in name="first.id" value="http://www.mamicode.com/$rdata">checked=checked</in> pid="{$first.pid}"level="{$first.level}"id=""value="http://www.mamicode.com/{$first.id}_{$first.level}"/>
{$first.title}
</div>
<div>
<foreach name="first.second" item="sec">
<div style="margin-left:50px;clear:both; line-height:40px;">
<input type="checkbox" name="access[]" <in name="sec.id" value="http://www.mamicode.com/$rdata">checked=checked</in> id="{$sec.id}"pid="{$sec.pid}"level="{$sec.level}"value="http://www.mamicode.com/{$sec.id}_{$sec.level}"/>
{$sec.title}
</div>
<div style="margin-left:100px;">
<ul>
<foreach name="sec.third" item="third">
<li style="float:left; line-height:40px; padding-left:20px;">
<input type="checkbox" name="access[]"<in name="third.id" value="http://www.mamicode.com/$rdata">checked=checked</in> id="{$third.id}"pid="{$third.pid}"level="{$third.level}"value="http://www.mamicode.com/{$third.id}_{$third.level}"/>
{$third.title}
</li>
</foreach>
</ul>
</div>
</foreach>
</div>
</foreach>
<div style="clear:both">
<label> </label>
<input name="role_id" type="hidden" value="http://www.mamicode.com/{$role_id}"/>
<input name="submit" type="submit" class="btn" value="http://www.mamicode.com/确认保存"/>
</div>
</form>
</div>
</body>
</html>
用户的权限列表编辑