<!--#include file="../Inc/Cls_Main.Asp"-->
<!--#include file="../Inc/Cms/Cms.Asp"-->
<!--#include file="../Inc/Cls_Pager.Asp"-->
<%
'=======================================================
Dim Action, Page
'=======================================================
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, ShowPage, CountNum
    TempFilePath = CmsTemplates & CmsTempSkin & TplBookInexFile
    Easp.Use "fso"
    If Easp.Fso.IsFile(TempFilePath) Then
        Cms.Tpl.Path = CmsTemplates & CmsTempSkin
        Cms.Tpl.File = TplBookInexFile
        Cms.Fun.Init()
        '==========================================================================
        Dim strHtml, oRs
        Dim Blocks, block
        Dim html, i, ii
        Dim tagname
        tagname = "booklist"
        Dim matchs
        Set Blocks = cms.tpl.getBlocks(tagname)
        For Each block In Blocks
            ShowNum = CmsFun.ChkNumEric(Cms.Tpl.Attr(block.SubMatches(0), "num"))
            ShowNum = Easp.IIf(ShowNum = 0, 10, ShowNum)
            '=====================================================================
            PageSet TablePrefix & "Book", ShowNum, "*", "id", " id Desc"
            Page.AddCondition " IsChk = 1 "
            Dim PageInfo, Pager
            PageInfo = Page.PageInfo()'//获取记录集信息
            Pager = Page.Pager()'//获取分页信息
            CountNum = Page.RecordCount()
            '=====================================================================
            Set oRs = Page.Recordset()
            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
                i = 1
                ii = 1
                Do While Not oRs.EOF
                    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)
                    i = i + 1
                    ii = ii + 1
                    oRs.MoveNext
                Loop
            End If
            Easp.C oRs
            Cms.Tpl.d("booklistnum") = CountNum
            If CountNum > 0 Then
                If CountNum > ShowNum Then
                    Cms.Tpl.d("ShowPage") = Pager & PageInfo
                Else
                    Cms.Tpl.d("ShowPage") = ""
                End If
            Else
                Cms.Tpl.d("ShowPage") = ""
            End If
            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 UserName, QQ, Email, Tel, Title, Content, Code
    UserName = Easp.Post("UserName:s")
    Title = Easp.Post("Title:s")
    Tel = Easp.Post("Tel:s")
    Email = Easp.Post("Email:s")
    QQ = Easp.Post("QQ:s")
    Content = Easp.Post("Content:s")
    Code = Easp.Post("Code:n:0")
    '================================================
    If Easp.IsN(UserName) Then
        Easp.Alert "姓名必须填写!"
    End If
    If Easp.IsN(Tel) Then
        Easp.Alert "联系电话必须填写!"
    End If
    If Easp.IsN(Email) Then
        Easp.Alert "电子邮箱必须填写!"
    End If
    If Easp.IsN(Content) Then
        Easp.Alert "留言内容必须填写!"
    End If
    '================================================
    Dim List, ResultVal
    Easp.Use "list"
    Set List = Easp.List.New
    List("UserName") = UserName
    List("QQ") = QQ
    List("Email") = Email
    List("Tel") = Tel
    List("Title") = Title
    List("Content") = Content
    List("IP") = Easp.GetIp()
    List("AdminTime") = Now()
    List("IsChk") = 0
    List("AddTime") = Now()
    ResultVal = Easp.db.AR(TablePrefix & "Book", 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)
    Cms.Tpl.blockTagd sHtml, TagName & ".content", CmsFun.HtmlRCdoe(Rs("content"))
    Cms.Tpl.blockTagd sHtml, TagName & ".addtime", CmsFun.DateToString(Rs("addtime"))
    Cms.Tpl.blockTagd sHtml, TagName & ".img", "http://www.gravatar.com/avatar/"& Easp.MD5(Rs("email")) &"?s=50&d=mm&r=g"
    Cms.Tpl.blockTagd sHtml, TagName & ".ishf", Easp.IIf(Easp.IsN(Rs("admincontent")), 0, 1)
    Cms.Tpl.blockTagd sHtml, TagName & ".admincontent", Rs("admincontent") & ""
    ReturnBookRs = sHtml
End Function

'初始化分页类

Sub PageSet(TableName, iPageSize, iFields, PKey, OrderBy)
    Set Page = New Cls_Pager
    Page.ConnectionString = Easp.db.Conn()
    Page.PageParam = "p"'//指定表示页数的URL变量 默认值:"page"
    Page.TableName = TableName'//指定目标表 可用临时表"(Select * From [Table])"
    Page.Fields = iFields'//选择列 用逗号分隔 默认值:"*"
    Page.PKey = PKey'//指定该表的主键
    Page.OrderBy = OrderBy'//指定排序条件
    'page.AddCondition "ArticleDel = 0"'//添加条件 可多次使用.如果用Or条件需要(条件1 Or 条件2 Or ...)
    Page.PageSize = iPageSize'//指定每页记录集数量
    Page.Page = CmsFun.ChkNumEric(Request(Page.PageParam))'//指定当前页数
    '// 对该记录集的分页样式及模板进行设置(不设置则使用默认样式)
    Page.FirstPage = "首　页"'//定义 首页/上一页/下一页/末页 链接样式(支持HTML)
    Page.PreviewPage = "上一页"
    Page.NextPage = "下一页"
    Page.LastPage = "末　页"
    Page.CurrentPage = "{$CurrentPage}"'//定义 当前页/列表页 链接样式 {$CurrentPage}{$ListPage}将被替换成 当前页/列表页 的数字
    Page.ListPage = "{$ListPage}"
    Page.PagerTop = 0'//定义分页列表前后要显示几个链接 如12...456...78 默认为0
    Page.PagerSize = 7'//定义分页列表最大数量 默认为7
    Page.PageInfo = "<span class=""disabled"">" & page.PageSize &"条记录/页</span><span class=""disabled"">共{$Kin_RecordCount}记录</span><span class=""disabled"">页次:<span style=""color:red;"">{$Kin_Page}</span>/{$Kin_PageCount}</span>"'//定义记录集综合信息
    Page.RewritePath = ""'//自定义ISAPI_REWRITE路径 * 号 将被替换为当前页数
End Sub
%>