⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editqxb.asp

📁 一个关于网站权限管理的经典例子,适合初学者
💻 ASP
字号:
<% 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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -