<!--#include file="../Inc/Cls_Main.Asp"-->
<!--#include file="../Inc/Cms/Cms.Asp"-->
<%
'=======================================================
Dim Action
'=======================================================
Action = Easp.Get("action:s")
'=======================================================
Select Case Action
    Case "PageLoad"
        Call PageLoad()
    Case "savedata"
        Call SaveData()
    Case Else
        Call PageLoad()
End Select
Set Cms = Nothing
Set Easp = Nothing

Sub PageLoad()
    Dim TempFilePath, ShowNum, ClassId, ShowPage, CountNum
    CountNum = 0
    ShowPage = ""
    TempFilePath = CmsTemplates & CmsTempSkin & PcBookIndexTemplate
    Easp.Use "fso"
    If Easp.Fso.IsFile(TempFilePath) Then
        Cms.Tpl.Path = CmsTemplates & CmsTempSkin
        Cms.Tpl.File = PcBookIndexTemplate
        Cms.Fun.Init()
        '==========================================================================
        Dim strHtml, oSQLText, oRs, Blocks, block, html, i, ii, n, tagname, matchs
        tagname = "booklist"
        Set Blocks = cms.tpl.getBlocks(tagname)
        For Each block In Blocks
            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)
            ClassId = Easp.Get("ClassId:n:0")
            '=====================================================================
            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
            '=====================================================================
            Easp.db.PageSize = ShowNum
            Easp.db.PageParam = "p"
            Easp.db.SetPager "default", PageHtmlList, Array("first:" & objDic("First"), "last:" & objDic("Last"), "prev:" & objDic("Prev"), "next:" & objDic("Next"), "list:*")
            oSQLText = "Select a.*,b.CnName From ["& TablePrefix & "Book] As a Left Join ["& TablePrefix & "BookType] As b On a.ClassId=b.id "
            oSQLText = oSQLText & " Where a.IsChk = 1 "
            If ClassId > 0 Then
                oSQLText = oSQLText & " And a.ClassId = "& ClassId &" "
            End If
            oSQLText = oSQLText & " Order By a.Id Desc "
            Set oRs = Easp.db.GPR(1, oSQLText)
            '=====================================================================
            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("default")
                CountNum = Easp.db.PageRecordCount
                i = 1
                ii = 1
                n = 0
                Do While Not oRs.EOF And (n < oRs.PageSize)
                    strHtml = strHtml & html
                    strHtml = ReturnBookRs(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(ii, 2)
                    n = n + 1
                    i = i + 1
                    ii = ii + 1
                    oRs.MoveNext
                Loop
            End If
            Easp.C oRs
            Cms.Tpl.d("booklistnum") = CountNum
            Cms.Tpl.d("ShowPage") = ShowPage
            Cms.Tpl.d("ChannelId") = 1
            Cms.Tpl.blockTag(block) = strHtml
        Next
        Set Blocks = Nothing
        Cms.Tpl.Show()
        '==========================================================================
    Else
        Easp.WE "留言模版文件："& TempFilePath &",未找到!"
    End If
End Sub

Sub SaveData()
    If Not Easp.CheckDataFrom() Then
        Easp.RR CmsFun.LoadToUrl()
    End If
    Dim ClassId, Title, UserName, Tel, Info
    Dim Code
    ClassId = Easp.Post("ClassId:n:0")
    Title = Trim(Easp.Post("Title:s"))
    UserName = Trim(Easp.Post("UserName:s"))
    Tel = Trim(Easp.Post("Tel:s"))
    Info = Trim(Easp.Post("Info:s"))
    Code = Easp.Post("Code:n:0")
    '================================================
    If Code = 0 Then
        Easp.Alert "验证码必须填写!"
    End If
    If Trim(Code) <> Trim(Session("ZjjCmsBookCode")) Then
        Easp.Alert "验证码输入错误!"
        Session("ZjjCmsBookCode") = ""
    End If
    Session("ZjjCmsBookCode") = ""
    '================================================
    Dim List, ResultVal
    Easp.Use "list"
    Set List = Easp.List.New
    List("ClassId") = ClassId
    List("Title") = Title
    List("UserName") = UserName
    List("Tel") = Tel
    List("Info") = Info
    List("IP") = Easp.getIp()
    List("IsChk") = 0
    List("AddTime") = Now()
    ResultVal = Easp.db.AR(TablePrefix & "Book:Id", List.Hash)
    Easp.C List
    If ResultVal <> 0 Then
        Easp.AlertUrl "留言成功,请耐心等待管理员的审核!", CmsFun.LoadToUrl()
    End If
    '================================================
End Sub

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