<!--#include file="Admin_Common.asp"-->
<%
'**************************************************************
' Software name: PowerEasy SiteWeaver
' Web: http://www.powereasy.net
' Copyright (C) 2005－2009 佛山市动易网络科技有限公司 版权所有
'**************************************************************

Const NeedCheckComeUrl = True   '是否需要检查外部访问

Const PurviewLevel = 2      '0--不检查，1--超级管理员，2--普通管理员
Const PurviewLevel_Channel = 0   '0--不检查，1--频道管理员，2--栏目总编，3--栏目管理员
Const PurviewLevel_Others = "Equipment"   '其他权限

Response.Write "<html><head><title>专用设备管理</title>" & vbCrLf
Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & vbCrLf
Response.Write "<link href='Admin_Style.css' rel='stylesheet' type='text/css'>" & vbCrLf
Response.Write "</head>" & vbCrLf
Response.Write "<body leftmargin='2' topmargin='0' marginwidth='0' marginheight='0'>" & vbCrLf
Response.Write "<table width='100%' border='0' align='center' cellpadding='1' cellspacing='1' class='border'>" & vbCrLf
Call ShowPageTitle("专 用 室 场 管 理", 10191)
Response.Write "  <tr class='tdbg'>" & vbCrLf
Response.Write "    <td width='70' height='30'><strong>管理导航：</strong></td>" & vbCrLf
Response.Write "    <td width='617' >" & vbCrLf
Response.Write "  <a href='Admin_ClassroomSort.asp?Action=Add'>室场添加</a>&nbsp;|&nbsp;<a href='Admin_ClassroomSort.asp'>室场管理</a>&nbsp;|&nbsp;<a href='Admin_Equipment.asp?Action=Add'>设备添加</a>&nbsp;|&nbsp;<a href='Admin_Equipment.asp'>设备管理</a>&nbsp;|&nbsp;<a href='Admin_ManageRecord.asp'>使用记录管理</a>&nbsp;|&nbsp;<a href='Admin_SearchHistory.asp'>使用记录查询</a>" & vbCrLf
Response.Write "    </td>" & vbCrLf
Response.Write "  </tr>" & vbCrLf
Response.Write "</table>" & vbCrLf
Select Case Action
Case "Add"
    Call AddSort
Case "SaveAdd"
    Call SaveAdd
Case "Modify"
    Call Modify
Case "SaveModify"
    Call SaveModify
Case "Del"
    Call DelSort
Case "Show"
    Call Show
Case Else
    Call main
End Select
If FoundErr = True Then
    Call WriteErrMsg(ErrMsg, ComeUrl)
End If
Response.Write "</body></html>"
Call CloseConn

Sub main()
    Response.Write "<br><table width='100%'><tr><td align='left'>您现在的位置：专用设备管理 &nbsp;&gt;&gt;&nbsp;室场类别管理"
    Response.Write "</td></tr></table>"
    
    Response.Write "    <table width='100%' class='border' border='0' cellspacing='1' cellpadding='1' align='center'>" & vbCrLf
    Response.Write "      <tr class='title'>" & vbCrLf
    Response.Write "        <td width='18%'><div align='center'>类别名称/室场名称 </div></td>" & vbCrLf
    Response.Write "        <td width='17%'><div align='center'>属性</div></td>" & vbCrLf
    Response.Write "        <td width='40%'><div align='center'>说明</div></td>" & vbCrLf
    Response.Write "        <td width='25%'><div align='center'>常规管理操作</div></td>" & vbCrLf
    Response.Write "      </tr>" & vbCrLf
    Dim rsCount, RsNum
    Set rsCount = Conn.Execute("select count(*) from PE_Classroom")
    RsNum = rsCount(0)
    Set rsCount = Nothing
    If RsNum = 0 Then
    
        Response.Write "<tr class='tdbg'><td colspan='4' align='center'>您还没有添加任何室场类别和室场名称!</td><tr>" & vbCrLf
    Else
        Call selectTreeList(0, 0)
    End If
    Response.Write "    </table>" & vbCrLf
    Response.Write "    <br>" & vbCrLf
    Response.Write "    <b>注意：</b><br>" & vbCrLf
    Response.Write "    &nbsp;&nbsp;&nbsp;&nbsp;   室场类别,室场及设备之间有继承性，删除室场记得先删除室场下的设备，删除室场类别记得先删除室场及其里面的设备。" & vbCrLf
End Sub

Sub AddSort()
    Dim rootIDRs
    Dim tempName
    Dim i, rsID
    rsID = PE_CLng(Request("id"))
    Response.Write "    <script language='JavaScript'>" & vbCrLf
    Response.Write "    function form1_onsubmit() " & vbCrLf
    Response.Write "    {" & vbCrLf
    Response.Write "        if (form1.ClassroomName.value=='')" & vbCrLf
    Response.Write "        {   alert(""请填写栏目名称!"");" & vbCrLf
    Response.Write "            document.form1.ClassroomName.focus();" & vbCrLf
    Response.Write "            return false;" & vbCrLf
    Response.Write "        }" & vbCrLf
    Response.Write "    }" & vbCrLf
    Response.Write "    //-->" & vbCrLf
    Response.Write "    </script>" & vbCrLf
    Response.Write "    <p>　</p>" & vbCrLf
    Response.Write "    <form method='post' action='Admin_ClassroomSort.asp?Action=SaveAdd' name='form1' onsubmit='return form1_onsubmit()' >" & vbCrLf
    Response.Write "      <table width='100%'  class='border' border='0' cellspacing='1' cellpadding='1' align='center'>" & vbCrLf
    Response.Write "        <tr> " & vbCrLf
    Response.Write "          <td colspan='2' height='22' class='title'> " & vbCrLf
    Response.Write "            <div align='center' ><b>添 加 室 场 类 别</b></div>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "    " & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td width='35%' nowrap height='25'> " & vbCrLf
    Response.Write "            <div align='left'><b>所属类别：</b></div>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "          <td width='65%' height='25'> " & vbCrLf
    Response.Write "            <select name='fatherID'>" & vbCrLf
    Response.Write "              <option value='0'>无（作为室场类别）</option>" & vbCrLf
    i = 0
    Set rootIDRs = Conn.Execute("select * from PE_Classroom where fatherID=0 order by id")
    Do While Not (rootIDRs.EOF Or Err)
        tempName = rootIDRs("ClassroomName")
        Response.Write "<option value='" & rootIDRs("id") & "'"
        If rootIDRs("id") = rsID Then Response.Write " selected"
        Response.Write ">" & tempName & "</option>"
        If i > 100 Then Exit Do
        i = i + 1
        rootIDRs.MoveNext
    Loop
    Response.Write "            </select>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td width='35%' nowrap> " & vbCrLf
    Response.Write "            <div align='left'><b>室场/类别名称：</b></div></td>" & vbCrLf
    Response.Write "          <td width='65%'> " & vbCrLf
    Response.Write "            <p align='left'> " & vbCrLf
    Response.Write "            <input type='text' name='ClassroomName' size='30'><font color='red'> *</font></td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td width='35%' nowrap> " & vbCrLf
    Response.Write "            <div align='left'><b>室场/类别说明：</b></div></td>" & vbCrLf
    Response.Write "          <td width='65%'> " & vbCrLf
    Response.Write "          <textarea rows='5' name='ClassroomIntroduce' cols='40'></textarea></td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td colspan='2'> " & vbCrLf
    Response.Write "            <div align='center'> " & vbCrLf
    Response.Write "              <input type='submit' name='Submit' value=' 添 加 '>" & vbCrLf
    Response.Write "            </div>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td colspan='2'>注：此处可以指定室场类别或室场名称。如：语音室(类别)<font color='#0000FF'> &gt;&gt;</font> " & vbCrLf
    Response.Write "            语音一室,语音二室,语音三室.....(名称)</td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>" & vbCrLf
    Response.Write "    </form>" & vbCrLf
End Sub

Sub SaveAdd()
    Dim InsertCursor, cmdTemp
    Set InsertCursor = Server.CreateObject("ADODB.Recordset")
    cmdTemp = "SELECT * FROM PE_Classroom WHERE (id is null)"
    InsertCursor.Open cmdTemp, Conn, 1, 3
    InsertCursor.addnew
    InsertCursor("ClassroomName") = PE_HTMLEncode(Request("ClassroomName"))
    InsertCursor("ClassroomIntroduce") = PE_HTMLEncode(Request("ClassroomIntroduce"))
    InsertCursor("fatherID") = Request("fatherID")
    InsertCursor.Update
    InsertCursor.Close
    Conn.Close
    Set InsertCursor = Nothing
    Set Conn = Nothing
    Call WriteSuccessMsg("添加成功！", ComeUrl)

End Sub

Sub DelSort()
    Dim sql, rs2 , intID ,rs
    intID = PE_Clng(Request("id"))
    sql = "select * from PE_Classroom where fatherID=" & intID
    Set rs = Server.CreateObject("adodb.recordset")
    rs.Open sql, Conn, 1, 1
    If rs.EOF Then
        sql = "select * from PE_Equipment where ClassroomID=" & intID
        Set rs2 = Server.CreateObject("adodb.recordset")
        rs2.Open sql, Conn, 1, 1
        If rs2.EOF Then
            sql = "delete from PE_Classroom where id=" & intID
            'response.write sql
            Conn.Execute (sql)
            Call WriteSuccessMsg("删除成功！", ComeUrl)

        Else
            FoundErr = True
            ErrMsg = ErrMsg & "<li>该目录下有设备资料,请先删除设备资料！</li>"
            Exit Sub
        End If
    Else
        FoundErr = True
        ErrMsg = ErrMsg & "<li>该目录下有设备资料,请先删除设备资料！</li>"
        Exit Sub
    End If
End Sub

Sub SaveModify()
    Dim cmdTemp, InsertCursor
    Set InsertCursor = Server.CreateObject("ADODB.Recordset")
    cmdTemp = "SELECT * FROM PE_Classroom WHERE id=" & PE_Clng(Request("id"))
    InsertCursor.Open cmdTemp, Conn, 1, 3
    InsertCursor("ClassroomName") = PE_HTMLEncode(Request("ClassroomName"))
    InsertCursor("ClassroomIntroduce") = PE_HTMLEncode(Request("ClassroomIntroduce"))
    InsertCursor.Update
    InsertCursor.Close
    Set InsertCursor = Nothing
    Call WriteSuccessMsg("修改成功！", "Admin_ClassroomSort.asp")

End Sub

Sub Modify()
    Dim sql, fatherIDRs, FatherID, sqlname, ClassroomName, intID
    intID = PE_CLng(Request("id"))
    sql = "select * from PE_Classroom where id=" & intID
    Set fatherIDRs = Server.CreateObject("adodb.recordset")
    fatherIDRs.Open sql, Conn, 1, 1
    If Not fatherIDRs.EOF Then
        FatherID = PE_CLng(fatherIDRs("fatherID"))
    Else
        FatherID = 0
    End If
    If FatherID <> 0 Then
        sqlname = "select * from PE_Classroom where id=" & FatherID
        Set rs = Server.CreateObject("adodb.recordset")
        rs.Open sqlname, Conn, 1, 1
        ClassroomName = rs("ClassroomName")
    End If
    Response.Write "    <script language=""JavaScript"">    " & vbCrLf
    Response.Write "   " & vbCrLf
    Response.Write "    function checkMe(theForm)" & vbCrLf
    Response.Write "    {" & vbCrLf
    Response.Write "        if(theForm.ClassroomName.value==""""){" & vbCrLf
    Response.Write "            alert(""错！名称不能为空！"");" & vbCrLf
    Response.Write "            return false;" & vbCrLf
    Response.Write "        }" & vbCrLf
    Response.Write "        return true;" & vbCrLf
    Response.Write "    }" & vbCrLf
    Response.Write "    </script> " & vbCrLf
    Response.Write "    <form method='post' Name='sortMod' action='Admin_ClassroomSort.asp?Action=SaveModify'><br>    " & vbCrLf
    Response.Write "      <table width='100%' class='border' border='0' cellspacing='1' cellpadding='1' align='center'>" & vbCrLf
    Response.Write "        <tr class='title'>" & vbCrLf
    Response.Write "          <td width='100%' colspan='2'><div align='center'><b>修 改 室 场</b></div></td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'>" & vbCrLf
    Response.Write "          <td nowrap><strong>所属类别：</strong></td><td>" & vbCrLf
    If FatherID = 0 Then Response.Write "无（作为室场类别）" Else Response.Write ClassroomName
    Response.Write "        </td></tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td width='35%' nowrap> " & vbCrLf
    Response.Write "            <div align='left'><b>名称：</b></div></td>" & vbCrLf
    Response.Write "          <td width='65%'> " & vbCrLf
    Response.Write "            <p align='left'>" & vbCrLf
    Response.Write "              <input type='text' name='ClassroomName' value='" & fatherIDRs("ClassroomName") & "'>" & vbCrLf
    Response.Write "              <input type='hidden' name='id' value='" & intID & "'><font color='red'> *</font></td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td width='35%' nowrap> " & vbCrLf
    Response.Write "            <div align='left'><b>说明：</b></div></td>" & vbCrLf
    Response.Write "          <td width='65%'> " & vbCrLf
    Response.Write "          <textarea rows='3' name='ClassroomIntroduce' cols='40'>" & PE_ConvertBR(fatherIDRs("ClassroomIntroduce")) & "</textarea></td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td colspan='2'> " & vbCrLf
    Response.Write "            <div align='center'> " & vbCrLf
    Response.Write "              <input type='submit' name='Submit' value='修改' onClick='return checkMe(sortMod)'>" & vbCrLf
    Response.Write "              " & vbCrLf
    Response.Write "            </div>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>" & vbCrLf
    Response.Write "    </form>" & vbCrLf
    Response.Write "    <br>" & vbCrLf
    Response.Write "    <b>注意：</b><br>" & vbCrLf
    Response.Write "    &nbsp;&nbsp;&nbsp;&nbsp;   室场类别,室场及设备之间有继承性，删除室场记得先删除室场下的设备，删除室场类别记得先删除室场及其里面的设备。" & vbCrLf
End Sub

Sub Show()
    Dim sql, fatherIDRs, FatherID, sqlname, ClassroomName, intID
    intID = PE_CLng(Request("id"))
    sql = "select * from PE_Classroom where id=" & intID
    Set fatherIDRs = Server.CreateObject("adodb.recordset")
    fatherIDRs.Open sql, Conn, 1, 1
    If Not fatherIDRs.EOF Then
        FatherID = fatherIDRs("fatherID")
    Else
        FatherID = 0
    End If
    If FatherID <> 0 Then
        sqlname = "select * from PE_Classroom where id=" & FatherID
        Set rs = Server.CreateObject("adodb.recordset")
        rs.Open sqlname, Conn, 1, 1
        ClassroomName = rs("ClassroomName")
    End If

    Response.Write "      <br><table width='100%' class='border' border='0' cellspacing='1' cellpadding='1' align='center'>" & vbCrLf
    Response.Write "        <tr class='title'>" & vbCrLf
    Response.Write "          <td width='100%' colspan='2'><div align='center'><b>查 看 室 场 信 息</b></div></td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'>" & vbCrLf
    Response.Write "          <td nowrap><strong>所属类别：</strong></td><td>" & vbCrLf
    If FatherID = 0 Then Response.Write "无（作为室场类别）" Else Response.Write ClassroomName
    Response.Write "        </td></tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td width='35%' nowrap> " & vbCrLf
    Response.Write "            <div align='left'><b>名称：</b></div></td>" & vbCrLf
    Response.Write "          <td width='65%'align='left'>" & fatherIDRs("ClassroomName") & "</td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td width='35%' nowrap> " & vbCrLf
    Response.Write "            <div align='left'><b>说明：</b></div></td>" & vbCrLf
    Response.Write "          <td width='65%'>" & fatherIDRs("ClassroomIntroduce") & "</td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "        <tr class='tdbg'> " & vbCrLf
    Response.Write "          <td colspan='2'> " & vbCrLf
    Response.Write "            <div align='center'> " & vbCrLf
    Response.Write "                  <input type='submit' name='Submit' value='修改信息' onClick=""window.location.href='Admin_ClassroomSort.asp?Action=Modify&id=" & intID & "';"">" & vbCrLf
    Response.Write "                  <input type='button' name='Submit2' value='返回上页' onClick=""window.location.href='Admin_ClassroomSort.asp';"">" & vbCrLf
    Response.Write "              " & vbCrLf
    Response.Write "            </div>" & vbCrLf
    Response.Write "          </td>" & vbCrLf
    Response.Write "        </tr>" & vbCrLf
    Response.Write "      </table>" & vbCrLf
End Sub

Function selectTreeList(i, deep)
    Dim sql
    Dim rs
    Dim tempi, rsName, rsIntroduce
    Dim rsID, FatherID
    Set rs = Server.CreateObject("adodb.recordset")
    sql = "select * from PE_Classroom where fatherID=" & i
    rs.Open sql, Conn, 1, 1

    If rs.RecordCount = 0 Then
        'Response.Write "<tr class='tdbg'><td colspan='4' align='center'>您还没有添加任何室场类别和室场名称!</td><tr>" & vbCrLf
    Else
        Do While Not rs.EOF
            rsID = rs("id")
            rsName = rs("ClassroomName")
            rsIntroduce = rs("ClassroomIntroduce")
            FatherID = rs("fatherID")
            'response.write "<option value="&rsID
            Response.Write "<tr class='tdbg' height='18' onmouseout='this.style.backgroundColor=""""' onmouseover='this.style.backgroundColor=""#BFDFFF""'><td><a href=Admin_ClassroomSort.asp?Action=Show&id=" & rsID
            Response.Write ">"
            For tempi = 1 To deep
                    Response.Write "<img src='../Images/tree_line2.gif' width='15' height='15' border=0>&nbsp;&nbsp;"
            Next
            Response.Write rsName & "</a></td><td align='center'>"
            If FatherID = 0 Then
                Response.Write "室场类别</td><td align='center'>"
                If rsIntroduce <> "" Then
                    Response.Write rsIntroduce
                Else
                    Response.Write "无"
                End If
                Response.Write "</td><td align='center'><a href=Admin_ClassroomSort.asp?Action=Add&id=" & rsID
                Response.Write ">添加室场</a>&nbsp;|"
            Else
                Response.Write "室场名</td><td align='center'>"
                If rsIntroduce <> "" Then
                    Response.Write rsIntroduce
                Else
                    Response.Write "无"
                End If
                Response.Write "</td><td align='center'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|"
            End If
            Response.Write "&nbsp;<a href=Admin_ClassroomSort.asp?Action=Show&id=" & rsID & ">查看</a>&nbsp;|"
            Response.Write "&nbsp;<a href=Admin_ClassroomSort.asp?Action=Modify&id=" & rsID & ">修改</a>&nbsp;|"
            Response.Write "&nbsp;<a href=Admin_ClassroomSort.asp?Action=Del&id=" & rsID & "&fatherID=" & FatherID & " onClick=""return confirm('确定要删除此项吗？');"">删除</a></td></tr>"
            Call selectTreeList(rsID, deep + 1)
            rs.MoveNext
        Loop
    End If
End Function
%>
