<%@ Control Language="VB" Inherits="WanerSoft.Provider.BaseControl" AutoEventWireup="false" EnableViewState="false"%>
<%@ Import Namespace="WanerSoft" %>
<%@ Import Namespace="WanerSoft.Common" %>
<%@ Import Namespace="WanerSoft.Provider" %>
<%@ Import Namespace="WanerSoft.Provider.Validate" %>
<%@ Import Namespace="WanerSoft.Model" %>
<%@ Import Namespace="WanerSoft.Data.Factory" %>
<%@ Register TagPrefix="Ws" TagName="Header" Src="../Common/Header.ascx" %>
<script runat="server">
Private ImgUrl As String = "Stop.gif"
Private Meg As String
Protected Overrides Sub CreateChildControls()
     If InfoSys.ReMarkOnOff Then
		 If InfoSys.ReMarkGuest = False And Session.Item("UserName") Is Nothing Then
             Meg = "对不起，游客不允许发表评论！请登陆后发表！"
			 Exit Sub
         Else
             If Cookies.GetCookies("WsBookComment") Is Nothing Then
                 Cookies.SetCookies("WsBookComment", Now().ToString, 360)
             Else
			     IF InfoSys.ReMarkCheckTime>0 Then
				       If DateDiff("s", CDate(Cookies.GetCookies("WsBookComment")), Now()) < InfoSys.ReMarkCheckTime Then
                           Meg = "累了吧？歇会，喝杯咖啡再发！"
                           Exit Sub
                       End If
				       IF InfoSys.ReMarkCheckTime>Ws.Instance.WebUserBookCommentSelectTime(Session.Item("ID")) Then
					       Meg = "累了吧？歇会，喝杯咖啡再发！"
                           Exit Sub
					   End IF
				 End IF
             End If
			 If InfoSys.ValidateCodeReMark Then
			    If Not Session.Item("Comment") Is Nothing Then
                 If Common.Request.Sift("CommentCode", "str", "").ToString.ToLower.Equals(Session.Item("Comment").ToString.ToLower) = False Then
                      Meg = "验证码出错，请返回重新填写!"
                      Exit Sub
                 End If
				Else
                      Meg = "验证码出错，请返回重新填写!"
                      Exit Sub
				End IF
             End If
             If Common.Strings.NoHtmlComment(Common.Request.Sift("CommentText", "str", "")).Trim.Equals("") Then
                 Meg = "错误：请填写书评内容！"
                 Exit Sub
             End If
             If Not Session.Item("UserName") Is Nothing Then
			    IF Cookies.GetSessions("GroupID").ToString="8" Then
                     Meg = "对不起，您已经被管理员禁止发言！"
                     Exit Sub
                End IF
                If CheckUser() = False Then
                    Meg = "对不起，您的积分目前太低，不允许发表书评！"
                    Exit Sub
                End If
                SaveComment()
				ImgUrl = "arrow_098.gif"
                Meg = "成功，发表书籍评论成功，积分增加！"
             ElseIf InfoSys.ReMarkGuest Then
                SaveComment()
				ImgUrl = "arrow_098.gif"
                Meg = "成功，发表书籍评论成功！"
             End If			 
         End If
     Else
        Meg = "系统设置，不允许发表书籍评论。"
     End If
End Sub
Function CheckUser() As Boolean
     If InfoSys.ReMarkCheckMoney > 0 Then
         If Ws.Instance.WebUserLoadMoney(Session.Item("ID")) < InfoSys.ReMarkCheckMoney Then
             Return False
         End If
     End If
     Return True
End Function
Sub SaveComment()
    Dim ImgUrl, Meg As String
    Dim BookID As Integer = Common.Request.Sift("WsEditID", "int", 0)
    Dim BookTitle As String = Common.Request.Sift("WsEditTitle", "str", "")
    If BookID = 0 Or BookTitle.Equals("") Then
       Meg = "错误：非法的操作，IP已经记录！"
       Exit Sub
    End If
    Dim TextType As String = Common.Strings.NoHtmlComment(Common.Request.Sift("CommentText", "str", "")).Trim
    If InfoSys.ReMarkCheckText.Equals("0") = False Then
        Dim Cc() As String = InfoSys.ReMarkCheckText.Split(",")
        For x As Integer = 0 To Cc.Length - 1
            TextType = TextType.Replace(Cc(x), "")
        Next
        Cc = Nothing
    End If
    Dim M As New Ws_BookComment
    M.bookid = BookID
    M.booktitle = BookTitle
    If Not Session.Item("UserName") Is Nothing Then
        M.userid = Session.Item("ID")
        M.username = Session.Item("UserNameB")
    Else
        M.userid = 0
        M.username = "游客"
    End If
        M.bookcommenttitle = ""
        M.bookcomment = Common.Strings.StrLeft(TextType,InfoSys.ReMarkTextNum)
        M.bookcommenttime = Now()
    If InfoSys.ReMarkAutoCheck Then
        M.bookcommentonoff = True
    Else
        M.bookcommentonoff = False
    End If
    Ws.Instance.WebBookCommentInsert(M,InfoUser)
    M = Nothing
    Cookies.SetCookies("WsBookComment", Now().ToString, 360)
	If InfoSys.ReMarkCache Then
	    WanerSoft.Provider.Caches.ClearCache("Ws.Web.Book.Comment."+BookID.ToString)
	End IF
End Sub
</script>
<Ws:Header id="Header" PageTitle="书籍发表评论" StyleSheet="Book/CommentSave" Runat="Server" />
<div>
    <h1><img src="/Skin/Default/Images/<%=ImgUrl%>" align="absmiddle" />&nbsp;<%=Meg%></h1>
	<h2><%Message.AutoCloseWin()%></h2>
</div>
	<%Message.ReFreshParent()%>