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"
        Set MyIO = Server.CreateObject("WMCore.IIO")
        Call doGetList
        Set MyIO = Nothing
    Case "detail"
        Call doGetDetail
    Case Else
        Call doGetMain
    End Select
End Sub

Private Sub doPost()
    Select Case LCase(strHandle)
    Case "move"
        Call doPostMove
    Case "remove"
        Call doPostRemove
    Case Else
        Echo "δ֪"
    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 "-->"
    Echo "</script>"
    Echo "<script language=""javascript"" src=""images/wm_article.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 colspan=""2"" class=""winT0"">"
    Echo "            <b></b>"
    Echo "            <a href=""javascript:void(0)"" class=""a1"" onclick=""jspp.Article.doPage(jspp.Article.page)"">ˢб</a>"
    Echo "        </td>"
    Echo "    </tr>"
    Echo "    <tr class=""winT1"">"
    Echo "        <td colspan=""2"" id=""_list_""></td>"
    Echo "    </tr>"
    Echo "</table>"
    Echo "</form>"
End Sub

Private Sub doGetList()
    Response.Charset = "utf-8"
    Response.ContentType = "text/xml"
    Dim objPage
    Dim rs
    Dim i
    Dim strKey
    Dim strWhere
    strKey = Trim(MyIO.QueryString("Keyword", 65001))
    Set objPage = Server.CreateObject("WMKernel.IPage")
    objPage.PageName = "Page"
    objPage.PageSize = 20
    objPage.DataType = WM_DataType
    objPage.Increment = "SeqId"
    objPage.Column = "*"
    objPage.Table = T_ARTICLE
    strWhere = "Follow=0"
    If strKey <> "" Then
        strWhere = strWhere & Replace(" AND (Title LIKE '%$(Keyword)%' Or UserName LIKE '%$(Keyword)%' Or Content LIKE '%$(Keyword)%')", "$(Keyword)", SafeString(strKey))
    End If
    objPage.Where = strWhere
    objPage.Sort = "SeqId DESC"
    objPage.SortType = True
    Set rs = objPage.Exec()
    Echo "<table width=""100%"" border=""1"" cellpadding=""2"" cellspacing=""0"" align=""center"" style=""border-collapse:collapse;word-break:break-all;word-wrap:break-word;"" bordercolor=""#000000"">"
    Echo "    <tr>"
    Echo "        <td width=""8%"" class=""winT0""><b>ѡ</b></td>"
    Echo "        <td width=""10%"" class=""winT0""><b>̳<b/></td>"
    Echo "        <td width=""30%"" class=""winT0""><b><b/></td>"
    Echo "        <td width=""10%"" class=""winT0""><b><b/></td>"
    Echo "        <td width=""10%"" class=""winT0""><b>ظ<b/></td>"
    Echo "        <td width=""12%"" class=""winT0""><b>ʱ<b/></td>"
    Echo "        <td width=""12%"" class=""winT0""><b>ظ<b/></td>"
    Echo "        <td width=""8%"" class=""winT0""><b></b></td>"
    Echo "    </tr>"
    If objPage.TotalRow > 0 Then
        i = 0
        Dim objArt
        Set objArt = MyKernel.Table(T_ARTICLE)
        Do While rs.EOF = False And i < objPage.PageSize
            objArt.Source = rs
            Echo "<tr class=""winT1"">"
            Echo "<td align=""center""><input type=""checkbox"" id=""SeqId"" name=""SeqId"" value=""" & objArt.Item("SeqId") & """ /></td>"
            Echo "<td>" & Server.HTMLEncode(objArt.Item("ForumName")) & "</td>"
            Echo "<td>" & Server.HTMLEncode(objArt.Item("Title")) & "</td>"
            Echo "<td>" & Server.HTMLEncode(objArt.Item("UserName")) & "</td>"
            Echo "<td>" & objArt.Item("Reply") & "</td>"
            Echo "<td align=""right"">" & FormatTime(getDate(objArt.Item("Intime")), "YY-MM-DD HH24:MI") & "</td>"
            Echo "<td align=""right"">" & FormatTime(getDate(objArt.Item("Outime")), "YY-MM-DD HH24:MI") & "</td>"
            Echo "<td align=""center"">"
            Echo "<select class=""sel"" onchange=""jspp.Article.control(this, " & objArt.Item("SeqId") & ")"">"
            Echo "<option value=""0""></option>"
            'Echo "<option value=""1""></option>"
            Echo "<option value=""2"">ƶ</option>"
            Echo "<option value=""3"">ɾ</option>"
            Echo "</select>"
            Echo "</td>"
            Echo "</tr>"
            rs.MoveNext
            i = i + 1
        Loop
        Set objArt = Nothing
        Call ShowControl
        Call ShowPage(objPage)
    Else
        Echo "    <tr class=""winT4"">"
        Echo "        <td colspan=""8"">κ</td>"
        Echo "    </tr>"
        Call ShowControl
    End If
    Echo "</table>"
    If TypeName(rs) <> "Nothing" Then rs.Close
    Set rs = Nothing
    Set objPage = Nothing
End Sub

Private Sub ShowControl()
    Echo "    <tr class=""winT4"">"
    Echo "        <td align=""center""><input type=""checkbox"" onclick=""chkAll(this)"" /></td>"
    Echo "        <td colspan=""7"">"
    Echo "            <input type=""button"" class=""btn"" value=""ƶ"" onclick=""jspp.Article.moveAll(this.form)"" />"
    Echo "            <input type=""button"" class=""btn"" value=""ɾ"" onclick=""jspp.Article.removeAll(this.form)"" />"
    Echo "            <input type=""button"" class=""btn"" value="""" onclick=""jspp.Article.query(this.form)"" />"
    Echo "            <input name=""Keyword"" type=""text"" class=""txt"" value=""" & Server.HTMLEncode(MyIO.QueryString("Keyword", 65001)) & """ />"
    Echo "        </td>"
    Echo "    </tr>"
End Sub

Private Sub ShowPage(ByVal objPage)
    Echo "    <tr class=""winT4"">"
    Echo "        <td colspan=""8"" align=""right"">"
    Echo "            " & objPage.TotalRow & "Ϣ"
    Echo "            " & objPage.PageSize & "/ҳ"
    Echo "            " & objPage.PageNum & "/" & objPage.TotalPage & "ҳ"
    If objPage.PageNum > 1 Then
        Echo "            <a href=""javascript:void(0)"" onclick=""jspp.Article.doPage(1)"" class=""a1"" />  ҳ</a>"
        Echo "            <a href=""javascript:void(0)"" onclick=""jspp.Article.doPage(" & (objPage.PageNum - 1) & ")"" class=""a1"" />һҳ</a>"
    Else
        Echo "            <a class=""a1"">  ҳ</a>"
        Echo "            <a class=""a1"">һҳ</a>"
    End If
    If objPage.PageNum < objPage.TotalPage Then
        Echo "            <a href=""javascript:void(0)"" onclick=""jspp.Article.doPage(" & (objPage.PageNum + 1) & ")"" class=""a1"" />һҳ</a>"
        Echo "            <a href=""javascript:void(0)"" onclick=""jspp.Article.doPage(" & objPage.TotalPage & ")"" class=""a1"" />β  ҳ</a>"
    Else
        Echo "            <a class=""a1"">һҳ</a>"
        Echo "            <a class=""a1"">β  ҳ</a>"
    End If
    Echo "        </td>"
    Echo "    </tr>"
End Sub

Private Sub doGetDetail()
    Response.Charset = "utf-8"
    Response.ContentType = "text/xml"
    Dim objArt
    Set objArt = MyKernel.Table(T_ARTICLE)
    If objArt.Exec("*", "SeqId=" & atol(Request.QueryString("SeqId"))) = False Then
        Echo "<table width=""200"" border=""1"" cellpadding=""2"" cellspacing=""0"" bordercolor=""#000000"" style=""border-collapse:collapse"">"
        Echo "<tr class=""winT4"">"
        Echo "<td>ҲҪ鿴</td>"
        Echo "</tr>"
        Echo "</table>"
    Else
        Echo "<table width=""300"" border=""1"" cellpadding=""2"" cellspacing=""0"" bordercolor=""#000000"" style=""border-collapse:collapse"">"
        Echo "<tr class=""winT1"">"
        Echo "<td width=""100"">Ʒ</td>"
        Echo "<td width=""200"">" & Server.HTMLEncode(objArt.Item("Title")) & "</td>"
        Echo "</tr>"
        Echo "<tr class=""winT1"">"
        Echo "<td>û</td>"
        Echo "<td>" & objArt.Item("Name") & "</td>"
        Echo "</tr>"
        Echo "<tr class=""winT1"">"
        Echo "<td>绰</td>"
        Echo "<td>" & objArt.Item("Phone") & "</td>"
        Echo "</tr>"
        Echo "<tr class=""winT1"">"
        Echo "<td>ֻ</td>"
        Echo "<td>" & objArt.Item("Mobile") & "</td>"
        Echo "</tr>"
        Echo "<tr class=""winT1"">"
        Echo "<td>ͨŵַ</td>"
        Echo "<td>" & objArt.Item("Address") & "</td>"
        Echo "</tr>"
        Echo "<tr class=""winT1"">"
        Echo "<td></td>"
        Echo "<td>" & objArt.Item("ZipCode") & "</td>"
        Echo "</tr>"
        Echo "<tr class=""winT1"">"
        Echo "<td>ʱ</td>"
        Echo "<td>" & FormatTime(getDate(objArt.Item("Intime")), "YYYY-MM-DD HH24:MI:SS") & "</td>"
        Echo "</tr>"
        Echo "<tr class=""winT1"">"
        Echo "<td>ظ</td>"
        Echo "<td>" & FormatTime(getDate(objArt.Item("Outime")), "YYYY-MM-DD HH24:MI:SS") & "</td>"
        Echo "</tr>"
        Echo "</table>"
    End If
    Set objArt = Nothing
End Sub

Private Sub doPostMove()
    Response.Charset = "utf-8"
    Response.ContentType = "text/xml"
    Dim arrSeq
    Dim lngSeq
    Dim objForum
    Set objForum = MyKernel.Table(T_FORUM)
    If objForum.Exec("*", "SeqId=" & atol(Request.Form("Follow"))) = False Then
        Push "ҲҪƶĿ̳"
    Else
        arrSeq = Split(Request.Form("SeqId"), ",")
        For Each lngSeq In arrSeq
            SafeExecute "UPDATE " & T_ARTICLE & " SET ForumId=" & objForum.Item("SeqId") & ",ForumName='" & SafeString(objForum.Item("Title")) & "' WHERE SeqId=" & atol(lngSeq)
        Next
        Push "OK"
    End If
    Set objForum = Nothing
End Sub

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