ASP中給用戶或群組分配權限的例子
HTML頁面內容:
==============================================================
<%
dim comm_auth(4)
comm_auth(1)="查詢(瀏覽)"
comm_auth(2)="新增"
comm_auth(3)="修改"
comm_auth(4)="刪除"
%>
<%
user_group_id=request("user_group_id")
rdr=request("rdr")
searchstr="user_group_id="+user_group_id+"&rdr="+rdr
set conn=opendb("EMSC")
sql="select a.*,b.user_group_name from sis_authority a"&_
" left join user_group b on a.user_group_id=b.user_group_id"&_
" where a.user_group_id='"+user_group_id+"'"
set rs=conn.execute(sql)
%>
<form name="frm" action="sis_authority_save.asp" method="post">
<input type="hidden" name="rdr" value="<%=rdr%>">
<TABLE width="100%" border=1 cellPadding=3 cellSpacing=0 bordercolor="#C0C0C0" class="default" style="border-collapse: collapse">
<tr>
<td width="100" bgcolor="#E6E6E6" align="center"> 群組</td>
<td colspan="2">
<%if rdr<>"" then%>
<%if not rs.eof then%><font color="maroon"><%=rs("user_group_name")%></span><%end if%>
<%else%>
<select name="user_group_id" onchange="location.href='sis_authority.asp?rdr=<%=rdr%>&user_group_id='+this.value;"><option value="">---請選擇---</option><%=group_combobox(user_group_id,false)%></select>
<%end if%>
</td>
</tr>
<tr>
<td width="100" rowspan="4" bgcolor="#E6E6E6" align="center"> 基本資料</td>
<td width="200" align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_1" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),1,1)="1" then response.write " checked"%><%end if%>> 廠別資料
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=1 to 4%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_2" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),2,1)="1" then response.write " checked"%><%end if%>> 車間組別資料
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=5 to 8%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-4)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_3" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),3,1)="1" then response.write " checked"%><%end if%>> 時段資料
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=9 to 12%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-8)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_4" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),4,1)="1" then response.write " checked"%><%end if%>> 生產配額資料
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=13 to 16%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-12)%>
<%next%>
</td>
</tr>
<tr>
<td width="100" rowspan="2" bgcolor="#E6E6E6" align="center"> 統計報表</td>
<td width="200" align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_5" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),5,1)="1" then response.write " checked"%><%end if%>> 產量明細表(小時)
</td>
<td align="left" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_6" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),6,1)="1" then response.write " checked"%><%end if%>> 產量明細表(日)
</td>
<td align="left" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td width="100" bgcolor="#E6E6E6" align="center"> 資料維護</td>
<td width="200" align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_7" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),7,1)="1" then response.write " checked"%><%end if%>> SIS資料維護
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=17 to 20%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-16)%>
<%next%>
</td>
</tr>
<tr>
<td width="100" rowspan="3" bgcolor="#E6E6E6" align="center"> 系統設定</td>
<td width="200" align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_8" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),8,1)="1" then response.write " checked"%><%end if%>> 使用者群組
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=21 to 24%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-20)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_9" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),9,1)="1" then response.write " checked"%><%end if%>> 使用者
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=25 to 28%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-24)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_10" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),10,1)="1" then response.write " checked"%><%end if%>> 權限管理
</td>
<td align="left" bgcolor="#FFFFFF"> </td>
</tr>
<%if mid(session("pwr1"),10,1)="1" then%>
<tr>
<td colspan="3" align="center">
<input type="reset" name="reset" value="清除欄位">
<input name="submit" type="submit" value="送出存檔">
</td>
</tr>
<%end if%>
</table>
</form>
<%
rs.close
conn.close
%>
============================================================
數據處理內容:
=====================================
<%
user_group_id=request("user_group_id")
rdr=request("rdr")
pwr1=""
for i=1 to 10
if request("p1_"+cstr(i))="1" then
pwr1=pwr1+"1"
else
pwr1=pwr1+"0"
end if
next
pwr2=""
for i=1 to 28
if request("p2_"+cstr(i))="1" then
pwr2=pwr2+"1"
else
pwr2=pwr2+"0"
end if
next
set conn=opendb("EMSC")
set rs=conn.execute("select user_group_id from sis_authority where user_group_id='"+user_group_id+"'")
if rs.eof then
sql="insert into sis_authority (user_group_id,pwr1,pwr2) "&_
"values ('"+user_group_id+"','"+pwr1+"','"+pwr2+"')"
else
sql="update sis_authority set pwr1='"+pwr1+"',pwr2='"+pwr2+"' where user_group_id='"+user_group_id+"'"
end if
rs.close
conn.execute(sql)
conn.close
if rdr<>"" then
response.redirect rdr
else
response.redirect "sis_authority.asp"
end if
%>
==============================================================
<%
dim comm_auth(4)
comm_auth(1)="查詢(瀏覽)"
comm_auth(2)="新增"
comm_auth(3)="修改"
comm_auth(4)="刪除"
%>
<%
user_group_id=request("user_group_id")
rdr=request("rdr")
searchstr="user_group_id="+user_group_id+"&rdr="+rdr
set conn=opendb("EMSC")
sql="select a.*,b.user_group_name from sis_authority a"&_
" left join user_group b on a.user_group_id=b.user_group_id"&_
" where a.user_group_id='"+user_group_id+"'"
set rs=conn.execute(sql)
%>
<form name="frm" action="sis_authority_save.asp" method="post">
<input type="hidden" name="rdr" value="<%=rdr%>">
<TABLE width="100%" border=1 cellPadding=3 cellSpacing=0 bordercolor="#C0C0C0" class="default" style="border-collapse: collapse">
<tr>
<td width="100" bgcolor="#E6E6E6" align="center"> 群組</td>
<td colspan="2">
<%if rdr<>"" then%>
<%if not rs.eof then%><font color="maroon"><%=rs("user_group_name")%></span><%end if%>
<%else%>
<select name="user_group_id" onchange="location.href='sis_authority.asp?rdr=<%=rdr%>&user_group_id='+this.value;"><option value="">---請選擇---</option><%=group_combobox(user_group_id,false)%></select>
<%end if%>
</td>
</tr>
<tr>
<td width="100" rowspan="4" bgcolor="#E6E6E6" align="center"> 基本資料</td>
<td width="200" align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_1" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),1,1)="1" then response.write " checked"%><%end if%>> 廠別資料
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=1 to 4%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_2" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),2,1)="1" then response.write " checked"%><%end if%>> 車間組別資料
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=5 to 8%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-4)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_3" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),3,1)="1" then response.write " checked"%><%end if%>> 時段資料
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=9 to 12%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-8)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_4" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),4,1)="1" then response.write " checked"%><%end if%>> 生產配額資料
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=13 to 16%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-12)%>
<%next%>
</td>
</tr>
<tr>
<td width="100" rowspan="2" bgcolor="#E6E6E6" align="center"> 統計報表</td>
<td width="200" align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_5" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),5,1)="1" then response.write " checked"%><%end if%>> 產量明細表(小時)
</td>
<td align="left" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_6" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),6,1)="1" then response.write " checked"%><%end if%>> 產量明細表(日)
</td>
<td align="left" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td width="100" bgcolor="#E6E6E6" align="center"> 資料維護</td>
<td width="200" align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_7" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),7,1)="1" then response.write " checked"%><%end if%>> SIS資料維護
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=17 to 20%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-16)%>
<%next%>
</td>
</tr>
<tr>
<td width="100" rowspan="3" bgcolor="#E6E6E6" align="center"> 系統設定</td>
<td width="200" align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_8" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),8,1)="1" then response.write " checked"%><%end if%>> 使用者群組
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=21 to 24%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-20)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_9" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),9,1)="1" then response.write " checked"%><%end if%>> 使用者
</td>
<td align="left" bgcolor="#FFFFFF">
<%for i=25 to 28%>
<input type="checkbox" name="p2_<%=i%>" value="1"<%if not rs.eof then%><%if mid(rs("pwr2"),i,1)="1" then response.write " checked"%><%end if%>> <%=comm_auth(i-24)%>
<%next%>
</td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">
<input type="checkbox" name="p1_10" value="1"<%if not rs.eof then%><%if mid(rs("pwr1"),10,1)="1" then response.write " checked"%><%end if%>> 權限管理
</td>
<td align="left" bgcolor="#FFFFFF"> </td>
</tr>
<%if mid(session("pwr1"),10,1)="1" then%>
<tr>
<td colspan="3" align="center">
<input type="reset" name="reset" value="清除欄位">
<input name="submit" type="submit" value="送出存檔">
</td>
</tr>
<%end if%>
</table>
</form>
<%
rs.close
conn.close
%>
============================================================
數據處理內容:
=====================================
<%
user_group_id=request("user_group_id")
rdr=request("rdr")
pwr1=""
for i=1 to 10
if request("p1_"+cstr(i))="1" then
pwr1=pwr1+"1"
else
pwr1=pwr1+"0"
end if
next
pwr2=""
for i=1 to 28
if request("p2_"+cstr(i))="1" then
pwr2=pwr2+"1"
else
pwr2=pwr2+"0"
end if
next
set conn=opendb("EMSC")
set rs=conn.execute("select user_group_id from sis_authority where user_group_id='"+user_group_id+"'")
if rs.eof then
sql="insert into sis_authority (user_group_id,pwr1,pwr2) "&_
"values ('"+user_group_id+"','"+pwr1+"','"+pwr2+"')"
else
sql="update sis_authority set pwr1='"+pwr1+"',pwr2='"+pwr2+"' where user_group_id='"+user_group_id+"'"
end if
rs.close
conn.execute(sql)
conn.close
if rdr<>"" then
response.redirect rdr
else
response.redirect "sis_authority.asp"
end if
%>
申明
非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!
博文欢迎转载,但请给出原文连接。