欢迎光临
我们一直在努力

权限管理的设计和实现(含演示和原代码)-ASP教程,数据库相关

建站超值云服务器,限时71元/月

权限管理的核心,就是对不同权限的用户,分配管理对应权限的资源。

本例以一个网站栏目后台管理模块(资源)的权限管理为例,实现了不同用户的权限管理。

数据库设计:

帐户信息表:

f_i_autoid 自动编码(主键)

f_i_orderid

f_accountid 帐户编码

f_accountname 帐户 (外键)

f_password 密码

f_accounttype

f_username

f_remark

f_datetime

栏目信息表:

f_i_autoid 自动编码(主键)

f_i_orderid

f_lanmuid 栏目编码

f_lanmuname 栏目 (外键)

f_ishidden

f_remark

f_datetime

权限表:

f_i_autoid 自动编码(主键)

f_accountname 帐户 (外键)

f_lanmuname 栏目 (外键)

f_remark

f_datetime

通过权限表的 f_accountname 帐户(外键)和 f_lanmuname 栏目(外键)把帐户信息表

和栏目信息表联系起来,通过给“帐户”分配“栏目”,或者给“栏目”分配“帐户”,使帐户和栏目建立关系(可以是“一对多”“多对一”或者“多对多”)。

然后以当前登陆的帐户为基准,在权限表中查找其可管理的栏目(资源)。

本例实现了一个用户对多栏目的管理(但是一个栏目只能被一个用户管理 – 这个通过程序代码的约束来实现)。

以下是部分代码:

<% option explicit %>

<!– #include file="./globals.inc" –>

<!– #include file="./connects.inc" –>

<html>

<head>

<title>编辑权限</title>

<link href="./style/style.css" rel="stylesheet" type="text/css">

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<meta http-equiv="page-enter" content="blendtrans(duration=1.0)">

<meta http-equiv="page-exit" content="blendtrans(duration=1.0)">

<script language="javascript">

function openwin(url, l, t, w ,h)

{open(url,,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=+ w +,height=+ h +,left=+ l +,top=+ t);}

function check_and_submit(frm)

{

selectall(frm.selecteditem);

frm.submit();

}

</script>

</head>

<body topmargin=20 leftmargin=0 background="../images/bg.gif">

<%

dim ssql, rs1, rs2, rs3, currentaccount

currentaccount = request("currentaccount")

%>

<form name="frm1" id="frm1" method="post" action="save.asp">

<input name="allowsubmit" type="hidden" value="ok">

<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">

<tr height=30>

<td colspan=3>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

帐号信息:

<input name="accountname" type="hidden" value="<%=currentaccount%>">

<%

ssql = "select * from tabaccountinfo where f_accountname=" & currentaccount & ""

set rs1 = server.createobject("adodb.recordset")

rs1.open ssql, sconn, 1, 1

if rs1.eof and rs1.bof then

response.write("没有取得该用户的信息。")

response.end

else

response.write " [帐号:] <font color=#ff0000>" & rs1("f_accountname") & "</font> [用户姓名:] " & rs1("f_username") & " [帐号类型:] " & rs1("f_accounttype")

end if

set rs1 = nothing

%>

</td>

</tr>

<tr height=10><td colspan=3></td></tr>

<tr>

<td width="220" align=center valign="top">

已分配该用户管理的栏目:<br><br>

<select name="selecteditem" id="selecteditem" size=12 multiple="true">

<%

选择所有栏目中除去已经分配的栏目:

ssql = "select f_lanmuname from tabqxb where f_accountname="& currentaccount &" order by f_lanmuname"

set rs3 = server.createobject("adodb.recordset")

rs3.open ssql, sconn, 1, 1

if rs3.eof and rs3.bof then

response.write("<option>无</option>") & chr(13)

else

while not rs3.eof

response.write "<option>" & rs3("f_lanmuname") & "</option>" & chr(13)

rs3.movenext

wend

end if

set rs3 = nothing

%>

</select>

</select>

</td>

<td width="60" align=center>

<br><br>

<button onclick="movesingleitem(waitselectitem, selecteditem)">&lt;</button><br><br>

<button onclick="moveallitems(waitselectitem, selecteditem)">&lt;&lt;</button><br><br><br><br>

<button onclick="movesingleitem(selecteditem, waitselectitem)">&gt;</button><br><br>

<button onclick="moveallitems(selecteditem, waitselectitem)">&gt;&gt;</button><br>

</td>

<td width="220" align=center valign="top">

待分配的栏目:<br><br>

<select name="waitselectitem" size=12 multiple=true>

<%

选择所有栏目中除去已经分配的栏目:

ssql = "select f_lanmuid, f_lanmuname from tablanmuinfo " & _

"where f_lanmuname not in (select distinct f_lanmuname from tabqxb) order by f_lanmuid"

set rs2 = server.createobject("adodb.recordset")

rs2.open ssql, sconn, 1, 1

if rs2.eof and rs2.bof then

response.write("<option>无</option><br>")

else

while not rs2.eof

response.write "<option>" & rs2("f_lanmuname") & "</option><br>"

rs2.movenext

wend

end if

set rs2 = nothing

%>

</select>

</td>

</tr>

<tr height=120>

<td colspan=3 align=center>

<button onclick="check_and_submit(frm1);"> 保 存 </button>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<button onclick="history.go(-1);"> 返 回 </button>

</td>

</tr>

</table>

</form>

<script language="javascript">

function movesingleitem(sel_source, sel_dest)

{

if (sel_source.selectedindex==-1) //源:没有点选任何项目

return;

if (sel_source.options[0].text=="无") //源:只有“无”项目

return;

if (sel_dest.options[0].text=="无") //目标:只有“无”项目,则先删除该提示性项目

sel_dest.options.remove(0);

var selectedtext = sel_source.options[sel_source.selectedindex].text;

sel_dest.options.add(new option(selectedtext));

sel_source.options.remove(sel_source.selectedindex);

if (sel_source.options.length==0) //源:如果删除完所有有用项目,则添加提示项目:“无”

sel_source.options.add(new option("无"));

}

function moveallitems(sel_source, sel_dest)

{

if (sel_source.options[0].text=="无") //源:只有“无”项目

return;

if (sel_dest.options[0].text=="无") //目标:只有“无”项目,则先删除该提示性项目

sel_dest.options.remove(0);

//首先拷贝所有项目到目标:

var sel_source_len = sel_source.length;

for (var j=0; j<sel_source_len; j++)

{

var selectedtext = sel_source.options[j].text;

sel_dest.options.add(new option(selectedtext));

}

//然后删除“源”所有项目:

while ((k=sel_source.length-1)>=0)

{

if (sel_source.options[0].text=="无") //源:只有“无”项目

break;

sel_source.options.remove(k);

if (sel_source.options.length==0) //源:如果删除完所有有用项目,则添加提示项目:“无”

sel_source.options.add(new option("无"));

}

}

function selectall(thesel) //选中select中全部项目

{ for (i = 0 ;i<thesel.length;i++)

thesel.options[i].selected = true;

}

</script>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 权限管理的设计和实现(含演示和原代码)-ASP教程,数据库相关
分享到: 更多 (0)

相关推荐

  • 暂无文章