<!--#include file="../../Inc/Cls_Main.Asp"-->
<!--#include file="../../Inc/Cms/Cms.Asp"-->
<%
'=======================================================
Dim Action
'=======================================================
Action = LCase(Trim(Easp.Get("action:s")))
'=======================================================
Select Case Action
    Case "getcomment"
        Call GetComment()
    Case "savecomment"
        Call SaveComment()
    Case Else
        Easp.RR "/"
End Select
Set Cms = Nothing
Set Easp = Nothing

Sub GetComment()
    Dim ChannelId, DataId
    ChannelId = Easp.Get("ChannelId:n:0")
    DataId = Easp.Get("id:n:0")
    If (ChannelId = 0 Or DataId = 0) Then
        Easp.WE "缺少参数"
    End If
    Dim HtmlTempFile, TempFilePath
    HtmlTempFile = PcCommentListTemplate
    TempFilePath = CmsTemplates & CmsTempSkin & HtmlTempFile
    Easp.Use "fso"
    If Easp.Fso.IsFile(TempFilePath) Then
        Cms.Tpl.Path = CmsTemplates & CmsTempSkin
        Cms.Tpl.File = HtmlTempFile
        '==========================================================================
        Dim strHtml, oRs, TempWhere, Blocks, block, html, i, n, TagName, Matchs
        tagname = "commentlist"
        Set Blocks = cms.tpl.getBlocks(tagname)
        For Each block In Blocks
            Dim ShowNum, ShowPage, CountNum, ShowId
            Dim PageMode, PageHtmlList, PageTipName, objDic
            Set objDic = Server.CreateObject("Scripting.Dictionary")
            ShowNum = CmsFun.ChkNumEric(Cms.Tpl.Attr(block.SubMatches(0), "num"))
            ShowNum = Easp.IIf(ShowNum = 0, 10, ShowNum)
            ShowId = Trim(Easp.Get("ShowId:s"))
            PageMode = Trim(Cms.Tpl.Attr(block.SubMatches(0), "pagemode"))
            PageTipName = Trim(Cms.Tpl.Attr(block.SubMatches(0), "pagetip"))
            If Easp.IsN(PageMode) Then
                PageHtmlList = "<span class=""disableds"">总数：{recordcount}</span><span class=""disableds"">总页数：{pagecount}</span>{first}{prev}{list}{next}{last}{jump}"
            Else
                PageHtmlList = Replace(Replace(Replace(PageMode & "", "|", """"), "[", "{"), "]", "}")
            End If
            If Not Easp.IsN(PageTipName) Then
                PageTipName = Split(PageTipName, "|")
                objDic("First") = PageTipName(0)
                objDic("Last") = PageTipName(1)
                objDic("Prev") = PageTipName(2)
                objDic("Next") = PageTipName(3)
            Else
                objDic("First") = "首　页"
                objDic("Last") = "尾　页"
                objDic("Prev") = "上一页"
                objDic("Next") = "下一页"
            End If
            '=====================================================================
            TempWhere = " IsChk = 1 "
            Easp.db.PageSize = ShowNum
            Easp.db.PageParam = "p"
            Easp.db.SetPager "ajax", PageHtmlList, Array("first:" & objDic("First"), "last:" & objDic("Last"), "prev:" & objDic("Prev"), "next:" & objDic("Next"), "link:javascript:GetCommentPage(*,"& ChannelId &","& DataId &",'"& ShowId &"')", "jumpaction:GetCommentPage(*,"& ChannelId &","& DataId &",'"& ShowId &"')")
            If ChannelId > 0 Then
                TempWhere = TempWhere & " And ChannelId In("& ChannelId &") "
            End If
            If DataId > 0 Then
                TempWhere = TempWhere & " And DataId In("& DataId &") "
            End If
            Set oRs = Easp.db.GPR("0", Array(TablePrefix & "Comment", TempWhere, " Id Desc ", " Id "))
            '=====================================================================
            html = block.SubMatches(1)
            strHtml = ""
            Set Matchs = Easp.RegMatch(html, "\{((?:empty|null|eof|nodata)\:"&tagname&")\s*?(?:[\s\S.]*?)\/?\}(?:([\s\S.]*?)\{/\1\})")
            If Easp.IsN(oRs) Then
                If Matchs.Count > 0 Then
                    strHtml = Matchs(0).SubMatches(1)
                End If
            Else
                If Matchs.Count > 0 Then
                    html = Easp.RegReplace(html, Matchs(0).Value, "")
                End If
            End If
            If Not oRs.EOF Then
                ShowPage = Easp.db.GetPager("ajax")
                CountNum = Easp.db.PageRecordCount
                i = 1
                n = 0
                Do While Not oRs.EOF And (n < oRs.PageSize)
                    strHtml = strHtml & html
                    strHtml = ReturnCommentRs(strHtml, tagname, oRs)
                    strHtml = Cms.Tpl.Assign(strHtml, tagname, oRs)
                    Cms.Tpl.blockTagd strHtml, tagname & ".i", i
                    Cms.Tpl.blockTagd strHtml, tagname & ".ii", CmsFun.ZeroFill(i, 2)
                    Cms.Tpl.blockTagd strHtml, tagname & ".n", n
                    Cms.Tpl.blockTagd strHtml, tagname & ".nn", CmsFun.ZeroFill(n, 2)
                    n = n + 1
                    i = i + 1
                    oRs.MoveNext
                Loop
            End If
            Easp.C oRs
            If CountNum > 0 Then
                If CountNum > ShowNum Then
                    Cms.Tpl.d("ShowPage") = ShowPage
                    Cms.Tpl.d("CountNum") = CountNum
                Else
                    Cms.Tpl.d("ShowPage") = ""
                    Cms.Tpl.d("CountNum") = 0
                End If
            Else
                Cms.Tpl.d("ShowPage") = ""
                Cms.Tpl.d("CountNum") = 0
            End If
            Cms.Tpl.blockTag(block) = strHtml
        Next
        Set Blocks = Nothing
        '==========================================================================
        Cms.Fun.Init()
        Cms.Tpl.Show()
        Set Cms = Nothing
    Else
        Easp.WE "模版文件："& TempFilePath &",未找到!"
    End If
End Sub

Sub SaveComment()
    Dim ChannelId, DataId, ArrayChannel, TabName
    Dim UserName, Info, MsgNum
    Dim Code, ToUrl, IsMsg
    ToUrl = CmsFun.LoadToUrl()
    ChannelId = Easp.Post("ChannelId:n:0")
    DataId = Easp.Post("DataId:n:0")
    UserName = Trim(Easp.Post("UserName:s"))
    Info = Trim(Easp.Post("Info:s"))
    Code = Easp.Post("Code:n:0")
    If (ChannelId = 0 Or DataId = 0) Then
        Easp.Alert "缺少参数"
    End If
    ArrayChannel = GetCaCheChannelInfo("Channel", ChannelId, ChannelField)
    If Easp.IsN(ArrayChannel) Then
        Easp.Alert "不存在的频道"
    Else
        TabName = ArrayChannel(2)
    End If
    '================================================
    IsMsg = Easp.db.RT(TabName, " Id = "& DataId &" ", "DataIsMsg")
    If CmsFun.ChkNumEric(IsMsg) = 0 Then
        Easp.Alert "信息已关闭评论"
    End If
    '================================================
    If Code = 0 Then
        Easp.Alert "验证码必须填写!"
    End If
    If Trim(Code) <> Trim(Session("ZjjCmsCommentCode")) Then
        Easp.Alert "验证码输入错误!"
        Session("ZjjCmsCommentCode") = ""
    End If
    Session("ZjjCmsCommentCode") = ""
    '================================================
    Dim List, ResultVal
    Easp.Use "list"
    Set List = Easp.List.New
    List("ChannelId") = ChannelId
    List("DataId") = DataId
    List("UserName") = Easp.IIf(Easp.IsN(UserName), "匿名用户", UserName)
    List("Info") = Info
    List("Ip") = Easp.GetIp()
    List("IsReply") = 0
    List("ReplyTime") = Now()
    List("AddTime") = Now()
    ' 开始保存
    ResultVal = Easp.db.AR(TablePrefix & "Comment:Id", List.Hash)
    Easp.C List
    If ResultVal <> 0 Then
        MsgNum = CmsFun.ChkNumEric(Easp.db.RT(TablePrefix & "Comment", " DataId = "& DataId &" ", "Count(0)"))
        If MsgNum > 0 Then
            Easp.db.UR TabName, " Id = "& DataId &" ", Array("MsgNum:" & MsgNum)
        End If
        Easp.AlertUrl "评论成功", ToUrl
    Else
        Easp.Alert "评论出错"
    End If
End Sub

Function ReturnCommentRs(ByVal sHtml, ByVal TagName, ByVal Rs)
    If LCase(TypeName(Rs)) = "recordset" Then
        Cms.Tpl.blockTagd sHtml, TagName & ".info", CmsFun.HtmlRCdoe(Rs("info"))
        ReturnCommentRs = sHtml
    End If
End Function
%>