<!--#include file="../inc/Conn.asp"-->
<!--#include file="../Inc/Cls.Common.asp"-->
<!--#include file="../Inc/Cls.Templates.asp"-->
<!--#include file="Channel_Config.asp"-->
<%
Dim Action
Dim Anonymity,ID,WM_Key,Code
Dim ReviewRe,ReUser
ID = WRMPS.CheckStr(Request("ID"),1)

Action = WRMPS.CheckStr(Request("Action"),0)
Select Case Action
  Case "ReBallot"
    Select Case Ucase(Request("W"))
      Case "GOOD"
        If IsEmpty(WRMPS.GetCookies("ReBallot_"&ID)) = False Then Response.write "不能重复投票哦 ^_^":Response.end
		WRMPS.SCookies "ReBallot_"&ID,"True",365
		If IsNumeric(ID) Then Conn.Execute("Update WM_Review Set WM_Agree=WM_Agree+1 Where WM_ID="&ID)
        Response.end
      Case "BAD"
        If IsEmpty(WRMPS.GetCookies("ReBallot_"&ID)) = False Then Response.write "不能重复投票哦 ^_^":Response.end
		WRMPS.SCookies "ReBallot_"&ID,"True",365
		If IsNumeric(ID) Then Conn.Execute("Update WM_Review Set WM_Oppose=WM_Oppose+1 Where WM_ID="&ID)
        Response.end
    End Select

  Case "ReviewSave"
	If Revert < 1 Or Int(Mem(0)(14)) > 1 Then Response.write "您没有权限使用此功能":Response.End
	ChannelID = WRMPS.CheckStr(Request("ChannelID"),1)
	If IsNumeric(ChannelID) = False Or IsNumeric(ID) = False Then Response.write "操作错误":Response.End
	Content = WRMPS.CheckStr(Request("Content"),2)
	If Content = "" Then Response.write "内容不能为空":Response.End
	If Len(Content) > Int(Mem(1)(1)) Then Response.write "内容不能超过 "&Int(Mem(1)(1))&" 字符":Response.End
	ReviewRe = WRMPS.CheckStr(Request("ContentRe"),2)
	If ReviewRe = "" Then ReviewRe = Null
	If WRMPS.CheckCode("Re",1) Then
	  Code = WRMPS.CheckStr(Request("Code"),0)
	  If Code = "" Then Response.write "请输入验证码":Response.End
	  If Code <> Session("Code") Then Response.write "验证码输入不正确":Response.End
	End If
    Anonymity = WRMPS.CheckStr(Request("Anonymity"),0)
	If Anonymity <> "" Then
	  Anonymity = Null
	Else
      If WRUser.ChkLogin Then Anonymity = MemName Else Anonymity = Null
	End If
    WM_Key = Int(Mem(0)(14))
	Session("Code") = ""
	'垃圾信息检测
	Set WRClass = New Cls_Sift
	SiftState = WRClass.ClassSift(False,"",Content,"","","")
	If SiftState = 1 Then Response.write "提交失败，被系统判定为非法或垃圾信息":Response.End
	If SiftState = 2 Then WM_Key = 0
	Set WRClass = Nothing
	Call DBConnBegin()
	'检测是否为自己的内容
	Set rs = Conn.Execute("Select WM_ID From WM_Article Where WM_ID="&ID&" and WM_Post = '"&Anonymity&"' and WM_PostType = 1")
	If Not rs.eof Then
      Response.write "您不能评论自己的文章":Response.End
	End If
	rs.Close
    Conn.Execute("Insert into WM_Review(WM_ChannelID,WM_ParentID,WM_Content,WM_Time,WM_IP,WM_User,WM_Agree,WM_Oppose,WM_Key,WM_ContentRe)values("&ChannelID&","&ID&",'"&Content&"',"&ConnTime&",'"&MemIP&"','"&Anonymity&"',0,0,"&WM_Key&",'"&ReviewRe&"')")
    If WM_Key < 1 Then
	  If SiftState = 2 Then
	    Response.write "由于您提交的内容带有敏感字符，请等待管理员的审核":Response.End
	  Else
	    Response.write "评论提交成功,请等待管理员的审核":Response.End
	  End If
	Else
	  Conn.Execute("Update WM_Article Set WM_Re=WM_Re+1 where WM_ID="&ID)
	End If
    Call ClassEnd()
    Call DBConnEnd()

  Case Else
    Dim ReviewTitle,Midst,MidstC,MidstContent,B_Place,L_Place,B_ParentPath,i,reUrl,User
    Dim n
    If ID = "" Then Call WRMPS.ErrView("","","<li>操作错误",0)
    Call DBConnBegin()
	Call WRMPS.FsoBegin()
	Content = WRTemp.SiteTemplates(1,0,25,ChannelID)
    Call WRMPS.FsoEnd()

	Set Rs = Conn.Execute("Select WM_Title,WM_ClassID,WM_AddTime,WM_ClassDir From WM_Article Where WM_ID="&ID&" and WM_Passed =1 and WM_IsDeleted = 0")
    If Rs.Eof Then
	   Call WRMPS.ErrView("","","<li>内容不存在",0)
	Else
	   ReUrl = WRMPS.GetShowUrl(1,1,0,ID,Rs(2),ChannelDir&Rs(3),ChannelID)
	   Content = WRMPS.GetReplace(Content,"{$Url}",reUrl)
       Set Rst = Conn.Execute("Select WM_ID,WM_Name,WM_ParentPath,WM_ParentDir,WM_Dir From WM_ArticleSort Where WM_ID="&Rs(1)&"")
         If Not Rst.Eof Then
		     B_Place = ",<a href="&WRMPS.GetClassUrl(1,1,ChannelDir&Rst(3)&Rst(4),Rst(0))&">"&Rst(1)&"</a>,评论中心"
	         ClassName = Rst(1)
	         ClassID = Rst(0)
	          If Rst(2) <> "0" Then
	            B_ParentPath = Right(Rst(2),Len(Rst(2))-2)
	            B_ParentPath = Split(B_ParentPath,",")
	            L_Place = ""
		        For i=0 to UBound(B_ParentPath)
	             Set Rso = Conn.Execute("Select WM_ID,WM_Name,WM_ParentDir,WM_Dir From WM_ArticleSort Where WM_ID="&Int(B_ParentPath(i))&"")
		           L_Place = L_Place & ",<a href="&WRMPS.GetClassUrl(1,1,ChannelDir&Rso(2)&Rso(3),Rso(0))&">"&Rso(1)&"</a>"
				 Rso.Close
	           Next
	         End If
         Else
	       Rst.Close
	       Call WRMPS.ErrView("","","<li>栏目不存在",0)
         End If
	     Rst.Close
	  SitePath = WRMPS.GetSitePath(-1,",<a href="&WR_Setting(3)&ChannelDir&"/>"&ChannelName&"</a>"&L_Place&B_Place)
      ReviewTitle = Rs(0)
	End If
	Rs.Close

	Page = WRMPS.CheckStr(Request("Page"),1)
	If Page = "" Then Page = 1
    If Instr(Content,"{$CycBegin}") > 0 Then
	  Dim ShowNum,ReID
	  ReID = WRMPS.CheckStr(Request("ReID"),1)
	  If ReID = "" Then ReID = 0
      ShowNum = WRMPS.HCode(2,Content,"{\$CycBegin}【","】")
	  MidstContent = WRMPS.HCode(2,Content,"{\$CycBegin}【"&ShowNum&"】","{\$CycEnd}")
	  If Request("iframe") <> "" Then ShowNum = 10
	  Set rs = Conn.Execute("Select Count(0) as WM_ID From WM_Review Where WM_ParentID="&ID&" and WM_ChannelID="&ChannelID&" and WM_Key=1")
	    n = Rs(0)
	  Rs.close
	  If Page > 1 Then n = n-((Page-1)*ShowNum)
	  Set ClsPageList = New Cls_PageView
      ClsPageList.strTableName = "WM_Review"
      ClsPageList.strPageUrl = ""
      ClsPageList.strFieldsList = "WM_ID,WM_Content,WM_Time,WM_IP,WM_User,WM_Agree,WM_Oppose,WM_ContentRe"
      ClsPageList.strCondiction = "WM_ParentID="&ID&" and WM_ChannelID="&ChannelID&" and WM_Key=1"
      ClsPageList.strOrderList = "WM_ID Desc"
      ClsPageList.strPrimaryKey = "WM_ID"
      ClsPageList.intPageSize = ShowNum
      ClsPageList.intPageNow = Page
      ClsPageList.strCookiesName = "RecordCount"
      ClsPageList.strPageVar = "Page"
      ClsPageList.intRefresh = 1
      ClsPageList.objConn = Conn
      ClsPageList.InitClass
      arrPage = ClsPageList.arrPage
      strPageList = ClsPageList.strPageList
      Set ClsPageList = nothing
      If IsArray(arrPage) Then
        For i = 0 to UBound(arrPage, 2)
	       User = arrPage(4,i)
		   If User = "" Then User = "网友("&Split(arrPage(3,i),".")(0)&"."&Split(arrPage(3,i),".")(1)&".*.*)" Else User = WRUser.DispUser(0,User)
		   Midst = WRMPS.GetReplace(MidstContent,"{$ReviewUser}",User)
		   Midst = WRMPS.GetReplace(Midst,"{$ReviewNumber}",n-i)
		   Midst = WRMPS.GetReplace(Midst,"{$ReviewTime}",arrPage(2,i))
		   Midst = WRMPS.GetReplace(Midst,"{$ReviewContent}",WRMPS.ReCode(arrPage(7,i)&arrPage(1,i)))
		   Midst = WRMPS.GetReplace(Midst,"{$ReviewAgree}",arrPage(5,i))
		   Midst = WRMPS.GetReplace(Midst,"{$ReviewOppose}",arrPage(6,i))
		   Midst = WRMPS.GetReplace(Midst,"{$ReviewConID}",arrPage(0,i))
		   MidstC = MidstC & Midst
           If Int(ReID) = Int(arrPage(0,i)) Then
		     ReUser = arrPage(4,i)
             If ReUser = "" Then ReUser = "网友("&Split(arrPage(3,i),".")(0)&"."&Split(arrPage(3,i),".")(1)&".*.*)"
             ReviewRe = "[quote:]"&WRMPS.CheckStr(arrPage(7,i),3)&"[dt]引用 ["&n-i&"] 楼 "&ReUser&" 发表于 "&arrPage(2,i)&" 的评论内容[/dt][dd]"&WRMPS.CheckStr(arrPage(1,i),3)&"[/dd][:quote]"
           End If
		Next
	  End If
	  If Request("iframe") <> "" Then
		If MidstC <> "" Then
	      Content = "<link type='text/css' rel='stylesheet' href='{$InstallDir}Skins/{$SkinDir}/Style.css'>" & vbCrLf & "<Script language='JavaScript' Src='{$InstallDir}Inc/Site.Js'></Script>" & vbCrLf & MidstC
		Else
	      Content = MidstC
		End If
	  Else
	    Content = WRMPS.HCode(1,Content,"{\$CycBegin}","{\$CycEnd}") & MidstC & WRMPS.HCode(3,Content,"{\$CycBegin}","{\$CycEnd}")
	  End If
    End If
    Content = WRMPS.GetReplace(Content,"{$NextPage}",strPageList)
	If Instr(Content,"{$IDCode}") > 0 Then
	  If WRMPS.CheckCode("Re",1) Then
	      Content = WRMPS.GetReplace(Content,"{$IDCode}","")
	  Else
		  Content = WRMPS.GetReplace(Content,"{$IDCode}"," style=""display:none""")
	  End If
    End If
    Content = WRMPS.GetReplace(Content,"{$ReviewRe}",ReviewRe)
    Content = WRMPS.GetReplace(Content,"{$ReviewID}",ID)
    Content = WRMPS.GetReplace(Content,"{$ReviewTitle}",reviewTitle)
    Content = WRTemp.SiteClass(Content)
    Content = WRTemp.SiteChannel(Content)
    Content = WRTemp.SiteLabel(Content)
    Set Rs = Nothing
    Call ClassEnd()
    Call DBConnEnd()
    Response.write Content
    If Request("iframe") <> "" Then
      Response.write "<script>" & vbCrLf
  	  Response.write "function rereh(){" & vbCrLf
  	  If Content <> "" Then
  	    Response.write "parent.document.getElementById('NewRe').height=document.body.scrollHeight;"
  	  Else
  	    Response.write "parent.document.getElementById('NewRe').height=0;"
  	  End If
  	  Response.write "}" & vbCrLf
  	  Response.write "setTimeout(""rereh()"", 100)" & vbCrLf
  	  Response.write "</script>" & vbCrLf
	End If
End Select
%>