Private strHandle
Private intErrId
Private strReason
Private MyIO

Private Sub Class_Initialize()
    strHandle = Request.QueryString("Handle")
End Sub

Public Sub main()
    If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
        Call doPost
    Else
        Call doGet
    End If
End Sub

Private Sub doGet()
    Select Case LCase(strHandle)
    Case "list"
        Call doGetList
    Case "add"
        Call doGetAdd
    Case "modify"
        Call doGetModify
    Case Else
        Call doGetMain
    End Select
End Sub

Private Sub doPost()
    Select Case LCase(strHandle)
    Case "add"
        Set MyIO = Server.CreateObject("WMCore.IIO")
        Call doPostAdd
        Set MyIO = Nothing
    Case "modify"
        Set MyIO = Server.CreateObject("WMCore.IIO")
        Call doPostModify
        Set MyIO = Nothing
    Case "move"
        Call doPostMove
    Case "remove"
        Call doPostRemove
    Case "sort"
        Call doPostSort
    Case Else
    End Select
End Sub

Private Sub doGetMain()
    Echo "<html>"
    Echo "<head>"
    Echo "<meta http-equiv=""cache-control"" content=""no-cache"" />"
    Echo "<meta http-equiv=""cache-control"" content=""max-age=0"" />"
    Echo "<meta http-equiv=""content-type"" content=""text/html; charset=gb2312"" />"
    Echo "<title>" & MyKernel.Env("ProVName") & " - ̳</title>"
    Echo "<link rel=""stylesheet"" href=""images/xw.css"" />"
    Echo "<script language=""javascript"" src=""jspp/jspp.js""></script>"
    Echo "<script language=""javascript"">"
    Echo "<!--"
    Echo "jspp.Caption = """ & MyKernel.Env("ProName") & """;"
    Echo "jspp.SiteName = """ & MyKernel.Config("SiteName") & """;"
    Echo "-->"
    Echo "</script>"
    Echo "<script language=""javascript"" src=""images/wm_forum.js""></script>"
    Echo "</head>"
    Echo "<body style=""padding:5;margin:0;overflow:auto;border:0"">"
    Echo "<table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"" style=""border:1px solid #000000"">"
    Echo "    <tr>"
    Echo "        <td align=""right"" bgcolor=""#A2ADC4"" style=""border-bottom:1px solid #000000;padding-right:1px;padding-top:1px"" height=""24""><img src=""images/xw_cls0.gif"" border=""0"" align=""absMiddle"" onMouseOver=""this.src='images/xw_cls1.gif'"" onMouseOut=""this.src='images/xw_cls0.gif'"" onMouseDown=""this.src='images/xw_cls2.gif'"" onMouseUp=""this.src='images/xw_cls1.gif'"" /></td>"
    Echo "    </tr>"
    Echo "    <tr>"
    Echo "        <td>"
    Echo "            <table width=""100%"" border=""0"" cellpadding=""0"" cellspacing=""0"">"
    Echo "                <tr>"
    Echo "                    <td height=""24"" style=""background-image:url(images/xw_back4.gif)"">&nbsp;</td>"
    Echo "                </tr>"
    Echo "                <tr>"
    Echo "                    <td>"
    Echo "                        <table width=""98%"" border=""0"" cellpadding=""0"" cellspacing=""0"" align=""center"">"
    Echo "                            <tr id=""child_0"" style=""display:none"">"
    Echo "                                <td>"
    Call setListForm
    Echo "                                </td>"
    Echo "                            </tr>"
    Echo "                        </table>"
    Echo "                    </td>"
    Echo "                </tr>"
    Echo "            </table>"
    Echo "        </td>"
    Echo "    </tr>"
    Echo "</table>"
    Echo "<iframe id=""console"" name=""console"" frameborder=""0"" scrolling=""no"" width=""0"" height=""0"" style=""display:none""></iframe>"
    Echo "</body>"
    Echo "</html>"
End Sub

Private Sub setListForm()
    Echo "<form id=""frmMain_0"" onsubmit=""return(false)"">"
    Echo "<table width=""100%"" border=""1"" cellpadding=""2"" cellspacing=""0"" align=""center"" style=""border-collapse:collapse"" bordercolor=""#000000"">"
    Echo "    <tr>"
    Echo "        <td width=""42%"" class=""winT0""><b>̳</b></td>"
    Echo "        <td width=""42%"" class=""winT0""><b>̳˵</b></td>"
    Echo "        <td width=""6%"" class=""winT0""><b>ҳ</b></td>"
    Echo "        <td width=""10%"" class=""winT0""><b></b></td>"
    Echo "    </tr>"
    Echo "    <tr>"
    Echo "        <td colspan=""5"">"
    Echo "            <div id=""_tree_"">"
    Echo "                <div id=""tree_item_0"" expand=""no"" mark="""" last=""1"" style=""font-size:12px""></div>"
    Echo "            </div>"
    Echo "        </td>"
    Echo "    </tr>"
    Echo "    <tr class=""winT1"">"
    Echo "        <td colspan=""5"">"
    Echo "            <label style=""padding:4px 2px 0px 2px""><b></b></label>"
    Echo "            <input type=""button"" value=""½"" class=""btn"" onclick=""tree.add()"" />"
    Echo "            <input type=""button"" value=""ƶ"" class=""btn"" onclick=""tree.moveAll()"" />"
    Echo "            <input type=""button"" value=""ɾ"" class=""btn"" onclick=""tree.removeAll()"" />"
    Echo "            <input type=""button"" value="""" class=""btn"" onclick=""tree.sort()"" />"
    Echo "        </td>"
    Echo "    </tr>"
    Echo "</table>"
    Echo "</form>"
End Sub

Private Sub doGetList()
    Response.Charset = "utf-8"
    Response.ContentType = "text/html"
    Dim strSQL
    Dim rs
    Dim objForum
    Dim strTemp
    strSQL = "SELECT * FROM " & T_FORUM
    Set rs = MyKernel.Execute(strSQL)
    Set objForum = MyKernel.Table(T_FORUM)
    Echo "$forum = new Array();"
    Do While rs.EOF = False
        objForum.Source = rs
        strTemp = "$forum.push({SeqId:$(SeqId),Title:""$(Title)"",Content:""$(Content)"",Page:$(Page),Follow:$(Follow),Intime:$(Intime)});"
        strTemp = Replace(strTemp, "$(SeqId)", objForum.Item("SeqId"))
        strTemp = Replace(strTemp, "$(Title)", ScriptEncode(objForum.Item("Title")))
        strTemp = Replace(strTemp, "$(Content)", ScriptEncode(objForum.Item("Content")))
        strTemp = Replace(strTemp, "$(Page)", objForum.Item("Page"))
        strTemp = Replace(strTemp, "$(Follow)", objForum.Item("Follow"))
        strTemp = Replace(strTemp, "$(Intime)", objForum.Item("Intime"))
        Echo strTemp
        rs.MoveNext
    Loop
    Set objForum = Nothing
    rs.Close
    Set rs = Nothing
End Sub

Private Function ScriptEncode(ByVal strIn)
    Dim ret
    ret = atos(strIn)
    ret = Replace(ret, "\", "\\")
    ret = Replace(ret, """", "\""")
    ret = Replace(ret, "'", "\'")
    ret = Replace(ret, vbCrLf, "\r\n")
    ScriptEncode = ret
End Function

Private Sub doGetAdd()
    Response.ContentType = "text/html"
    Response.Charset = "utf-8"
    Echo "<form id=""frmTemplet"" onsubmit=""return(false)"">"
    Echo "<table width=""400"" border=""1"" cellpadding=""2"" cellspacing=""0"" style=""border-collapse:collapse"" bordercolor=""#000000"">"
    Echo "    <tr>"
    Echo "        <td colspan=""2"" class=""winT0""><b>½̳</b></td>"
    Echo "    </tr>"
    Echo "    <tr class=""winT4"">"
    Echo "        <td width=""80"">̳</td>"
    Echo "        <td width=""320"">"
    Echo "            <select name=""Follow"" class=""sel"">"
    Echo "                <option value=""0"">½Ϊ</option>"
    Echo "            </select>"
    Echo "        </td>"
    Echo "    </tr>"
    Echo "    <tr class=""winT4"">"
    Echo "        <td width=""80"">̳</td>"
    Echo "        <td width=""320""><input type=""text"" name=""Title"" class=""txt"" /></td>"
    Echo "    </tr>"
    Echo "    <tr class=""winT4"">"
    Echo "        <td>̳˵</td>"
    Echo "        <td><textarea name=""Content"" class=""area"" style=""width:300px;height:100px""></textarea></td>"
    Echo "    </tr>"
    Echo "    <tr class=""winT4"">"
    Echo "        <td>ӷҳ</td>"
    Echo "        <td><input type=""text"" name=""Page"" class=""txt"" value=""10"" /></td>"
    Echo "    </tr>"
    Echo "    <tr class=""winT4"">"
    Echo "        <td colspan=""2"" align=""center"">"
    Echo "            <input name=""Accept"" type=""button"" value=""ȷ  "" class=""btn"" />"
    Echo "            <input name=""Cancel"" type=""button"" value=""ȡ  "" class=""btn"" />"
    Echo "        </td>"
    Echo "    </tr>"
    Echo "</table>"
    Echo "</form>"
End Sub

Private Sub doGetModify()
    Response.ContentType = "text/html"
    Response.Charset = "utf-8"
    Dim objForum
    Set objForum = MyKernel.Table(T_FORUM)
    If objForum.Exec("*", "SeqId=" & atol(Request.QueryString("SeqId"))) = False Then
        ExportHintX "ҲҪ༭̳"
    Else
        Echo "<form id=""frmTemplet"" onsubmit=""return(false)"">"
        Echo "<table width=""400"" border=""1"" cellpadding=""2"" cellspacing=""0"" style=""border-collapse:collapse"" bordercolor=""#000000"">"
        Echo "    <tr>"
        Echo "        <td colspan=""2"" class=""winT0""><b>༭̳</b></td>"
        Echo "    </tr>"
        Echo "    <tr class=""winT4"">"
        Echo "        <td width=""80"">̳</td>"
        Echo "        <td width=""320""><input type=""text"" name=""Title"" class=""txt"" value=""" & Server.HTMLEncode(objForum.Item("Title")) & """ /></td>"
        Echo "    </tr>"
        Echo "    <tr class=""winT4"">"
        Echo "        <td>̳˵</td>"
        Echo "        <td><textarea name=""Content"" class=""area"" style=""width:300px;height:100px"">" & Server.HTMLEncode(objForum.Item("Content")) & "</textarea></td>"
        Echo "    </tr>"
        Echo "    <tr class=""winT4"">"
        Echo "        <td>ӷҳ</td>"
        Echo "        <td><input type=""text"" name=""Page"" class=""txt"" value=""" & objForum.Item("Page") & """ /></td>"
        Echo "    </tr>"
        Echo "    <tr class=""winT4"">"
        Echo "        <td colspan=""2"" align=""center"">"
        Echo "            <input name=""Accept"" type=""button"" value=""ȷ  "" class=""btn"" />"
        Echo "            <input name=""Cancel"" type=""button"" value=""ȡ  "" class=""btn"" />"
        Echo "        </td>"
        Echo "    </tr>"
        Echo "</table>"
        Echo "</form>"
    End If
    Set objForum = Nothing
End Sub

Private Sub doPostAdd()
    Response.ContentType = "text/html"
    Response.Charset = "utf-8"
    Dim objForum
    Set objForum = MyKernel.Table(T_FORUM)
    If MyPower.Item("AddForum") = 0 Then
        Push "ûӰ/̳Ȩ"
    Else
        objForum.Item("Title") = Trim(MyIO.Form("Title", 65001))
        objForum.Item("Content") = Trim(MyIO.Form("Content", 65001))
        objForum.Item("Page") = MyIO.Form("Page")
        objForum.Item("Follow") = MyIO.Form("Follow")
        If objForum.Item("Title") = "" Then
            Push "̳"
        Else
            Push "OK"
            If objForum.Item("Page") <= 0 Then objForum.Item("Page") = 10
            Dim strSQL
            strSQL = "INSERT INTO $(Table) (Title,Content,Page,Follow,Intime) VALUES ('$(Title)','$(Content)',$(Page),$(Follow),$(Timeval))"
            strSQL = Replace(strSQL, "$(Table)", T_FORUM)
            strSQL = Replace(strSQL, "$(Title)", SafeString(objForum.Item("Title")))
            strSQL = Replace(strSQL, "$(Content)", SafeString(objForum.Item("Content")))
            strSQL = Replace(strSQL, "$(Page)", objForum.Item("Page"))
            strSQL = Replace(strSQL, "$(Follow)", objForum.Item("Follow"))
            strSQL = Replace(strSQL, "$(Timeval)", getTime(Now()))
            SafeExecute strSQL
        End If
    End If
    Set objForum = Nothing
End Sub

Private Sub doPostModify()
    Response.ContentType = "text/html"
    Response.Charset = "utf-8"
    Dim objForum
    Set objForum = MyKernel.Table(T_FORUM)
    If MyPower.Item("ModifyForum") = 0 Then
        Push "ûб༭/̳Ȩ"
    ElseIf objForum.Exec("*", "SeqId=" & atol(Request.QueryString("SeqId"))) = False Then
        Push "ҲҪ༭̳"
    Else
        objForum.Item("Title") = Trim(MyIO.Form("Title", 65001))
        objForum.Item("Content") = Trim(MyIO.Form("Content", 65001))
        objForum.Item("Page") = MyIO.Form("Page")
        If objForum.Item("Title") = "" Then
            Push "̳"
        Else
            Push "OK"
            If objForum.Item("Page") <= 0 Then objForum.Item("Page") = 20
            Dim strSQL
            strSQL = "UPDATE $(Table) SET Title='$(Title)',Content='$(Content)',Page=$(Page) WHERE SeqId=$(SeqId)"
            strSQL = Replace(strSQL, "$(Table)", T_FORUM)
            strSQL = Replace(strSQL, "$(Title)", SafeString(objForum.Item("Title")))
            strSQL = Replace(strSQL, "$(Content)", SafeString(objForum.Item("Content")))
            strSQL = Replace(strSQL, "$(Page)", objForum.Item("Page"))
            strSQL = Replace(strSQL, "$(SeqId)", objForum.Item("SeqId"))
            SafeExecute strSQL
        End If
    End If
    Set objForum = Nothing
End Sub

Private Sub doPostMove()
    Response.Charset = "utf-8"
    Response.ContentType = "text/xml"
    If MyPower.Item("ModifyForum") = 0 Then
        Push "ûб༭/̳Ȩ"
    Else
        Dim varSource, lngTarget
        Dim varPtr
        Dim strSQL
        varSource = Split(Request.Form("Source"), ",")
        lngTarget = atol(Request.Form("Target"))
        For Each varPtr in varSource
            strSQL = "UPDATE $(Table) SET Follow=$(Follow) WHERE SeqId=$(SeqId)"
            strSQL = Replace(strSQL, "$(Table)", T_FORUM)
            strSQL = Replace(strSQL, "$(Follow)", lngTarget)
            strSQL = Replace(strSQL, "$(SeqId)", atol(varPtr))
            SafeExecute strSQL
        Next
        Push "OK"
    End If
End Sub

Private Sub doPostRemove()
    Response.Charset = "utf-8"
    Response.ContentType = "text/xml"
    If MyPower.Item("DeleteForum") = 0 Then
        Push "ûɾ/̳Ȩ"
    Else
        Dim arrSeq
        Dim lngSeq
        arrSeq = Split(Request.Form("SeqId"), ",")
        For Each lngSeq In arrSeq
            SafeExecute "DELETE FROM " & T_ARTICLE & " WHERE ForumId=" & atol(lngSeq)
            SafeExecute "DELETE FROM " & T_FORUM & " WHERE SeqId=" & atol(lngSeq)
        Next
        Push "OK"
    End If
End Sub

Private Sub doPostSort()
    Response.Charset = "utf-8"
    Response.ContentType = "text/xml"
    If MyPower.Item("ModifyForum") = 0 Then
        Push "ûб༭/̳Ȩ"
    Else
        Dim lngId
        Dim arrList
        Dim i
        lngId = atol(Request.Form("SeqId"))
        arrList = Split(Request.Form("List"), ",")
        For i = 0 To UBound(arrList)
            SafeExecute "UPDATE " & T_FORUM & " SET Serial=" & i & " WHERE SeqId=" & atol(arrList(i)) & " AND Follow=" & lngId
        Next
        Push "OK"
    End If
End Sub
