<!--#include file="act_inc/ACT.User.asp"-->
<%
ConnectionDatabase
Dim CommUser
Set CommUser = New ACT_User
Call CommUser.UserLoginChecked()
Dim ModeID,ClassID,ID,RS,CommentStr,UserIP,Total,TitleStr,TitleLinkStr,N,ACT_Domain
Dim totalPut, CurrentPage, MaxPerPage,SqlStr,Action
ModeID=ACTCMS.ChkNumeric(request("ModeID"))
IF ModeID=0 And request("Action")<>"Support" Then Response.End
ClassID=ACTCMS.rsql(request("ClassID"))
ID=ACTCMS.ChkNumeric(request("ID"))
ACT_Domain=ACTCMS.ActCMSDM
Action=request("Action")
Select Case Action
 Case "Get"
  Call GetComment()
 Case "Write"
  Response.Write("document.write('" & WriteComment(ModeID,request("ClassID"),request("ID")) & "');")
 Case "WriteSave"
  Call WriteSave()
 Case "Support"
  Call Support()
 Case Else
  Call CommentMain()
 End Select
Set CommUser=Nothing
Call CloseConn()
 Sub CommentMain
	Dim Cmsmake,FileContent
	Set Cmsmake =New ACT_Code
	MaxPerPage=5  
	FileContent = Cmsmake.LoadTemplate(Actcms.ACT_C(ModeID,16))
	   If Trim(FileContent) = "" Then FileContent = "模板不存在!"
				  FileContent = Cmsmake.LableFlag(Cmsmake.AllLabel(FileContent)) 
				  FileContent = Cmsmake.GeneralLabel(FileContent)       
	  Set Cmsmake = Nothing
	   SqlStr="Select Title,ClassID,ID,ChangesLink,FileName,GroupID_ACT,Score_ACT From "&ACTCMS.ACT_C(ModeID,2)&"  Where ID=" & ID & ""
Set RS=Server.CreateObject("ADODB.RECORDSET")
 RS.Open SqlStr,Conn,1,1
 If Not RS.Eof Then
   TitleStr=RS(0):TitleLinkStr="<a href='" & ACTCMS.GetInfoUrl(ModeID,RS("ClassID"),RS("ID"),RS("ChangesLink"),RS("FileName"),RS("GroupID_ACT"),RS("Score_ACT")) & "'>" & TitleStr & "</a>"
 Else
   Response.End
 End If
	If request("page") <> "" Then
			  CurrentPage = ACTCMS.ChkNumeric(request("page"))
	Else
			  CurrentPage = 1
	End If
	RS.Close
RS.Open "Select  * From Comment_Act Where Locked=1 And ModeID=" & ModeID & " And ClassID='" & ClassID & "' And acticleID=" & ID & " Order By ID",conn,1,1
  IF Not Rs.Eof Then
		 totalPut = RS.RecordCount
				If CurrentPage < 1 Then	CurrentPage = 1
				If (CurrentPage - 1) * MaxPerPage > totalPut Then
							If (totalPut Mod MaxPerPage) = 0 Then
									CurrentPage = totalPut \ MaxPerPage
							Else
									CurrentPage = totalPut \ MaxPerPage + 1
						   End If
				End If
		
				If CurrentPage = 1 Then
						Call showContent()
				Else
						If (CurrentPage - 1) * MaxPerPage < totalPut Then
									RS.Move (CurrentPage - 1) * MaxPerPage
									Call showContent()
						Else
									CurrentPage = 1
									Call showContent()
				        End If
				End If
  Else
	CommentStr=""
  End If
  FileContent=Replace(FileContent,"{$CommentTitle}",TitleStr)
  FileContent=Replace(FileContent,"{$TypeComment}",CommentStr)
  FileContent=Replace(FileContent,"{$WriteComment}","<script language=""javascript"" src=""?Action=Write&ModeID=" & ModeID& "&ClassID=" & ClassID & "&ID=" & ID & """></script>")

Response.Write(FileContent)
rs.close:set rs=nothing

End Sub

Sub ShowContent()
Dim I
 CommentStr="&nbsp;&nbsp;以下是对 <strong>[" & TitleLinkStr & "]</strong> 的评论,总共:<font color=red>" & rs.recordcount & " </font>条评论"
  Do While Not RS.Eof 
   CommentStr=CommentStr & "<table style='margin-top:3px' width='98%' border='0' align='center' cellpadding='0' cellspacing='1' class='comment_show_table'>"
   CommentStr=CommentStr & "<tr>"
    UserIP=RS("UserIP")
	UserIP=Replace(UserIP,split(UserIP,".")(3),"*")
   CommentStr=CommentStr & "<td height='25' style='BORDER-RIGHT: #efefef 1px dotted;BORDER-LEFT: #efefef 1px dotted;BORDER-BOTTOM: #efefef 1px dotted;'>"
   IF RS("Anonymous")=0 Then
   CommentStr=CommentStr & "会员："& RS("UserName")
   Else
   CommentStr=CommentStr & "游客："& RS("AnounName")
   End IF
   N=N+1
   CommentStr=CommentStr  & " 发表时间： " & RS("AddDate") &" IP地址：" & UserIP & "</td><td>第 <font color=red> " & N & "</font> 楼 </td>"
   CommentStr=CommentStr & "</tr>"
   CommentStr=CommentStr & "<tr>"
   CommentStr=CommentStr & "<td height='25' colspan='2'>" & RS("Content") & "</td>"
   CommentStr=CommentStr & "</tr>"
   CommentStr=CommentStr & "<tr>"
   CommentStr=CommentStr & "<td height='25' colspan='2' style='BORDER-TOP: #efefef 1px dotted;BORDER-LEFT: #efefef 1px dotted;BORDER-BOTTOM: #efefef 1px dotted;text-align:right'><A href='mailto:" & rs("Email") & "'>发邮件给评论人</a> <a href='" & ACT_Domain & "Comment.asp?Action=Support&ID=" & RS("ID") & "&Type=1'>支持(<font color=red>" & rs("y") & "</font>)</a> <a href='" & ACT_Domain & "Comment.asp?Action=Support&ID=" & RS("ID") & "&Type=0'>反对(" & rs("n") & ")</a> </td>"
   CommentStr=CommentStr & "</tr>"
   RS.MoveNext
		I = I + 1
	  If I >= MaxPerPage Then Exit Do
  loop
 CommentStr=CommentStr & "</table><table width='98%' border='0' ><tr>"
 CommentStr=CommentStr & " <td height='25'  align='right'>"
 CommentStr=CommentStr & ACTCMS.ShowPagePara(totalPut, MaxPerPage, "Comment.asp", True, "条", CurrentPage, "ModeID=" & ModeID & "&ClassID=" & ClassID & "&ID=" & ID)
 CommentStr=CommentStr & " </td>"
 CommentStr=CommentStr & "</tr>"
 CommentStr=CommentStr & "<tr><td height='2'></td></tr></table>"
End Sub

  '显示评论
 Sub GetComment()
	Dim Others
	 Set RS=Server.CreateObject("ADODB.RECORDSET")
	RS.Open "Select Count(ID) From Comment_Act Where Locked=1 And ModeID=" & ModeID & " And ClassID='" & ClassID & "' And acticleID=" & ID & "",conn,1,1
	Total=RS(0)
	RS.Close
	RS.Open "Select top 10 * From Comment_act Where Locked=1 And ModeID=" & ModeID & " And ClassID='" & ClassID & "' And acticleID=" & ID & " Order By ID asc ,AddDate Desc",conn,1,1
	IF Not Rs.Eof Then
	 CommentStr="&nbsp;总共:<font color=red>" & Total & "</font> 条评论 &nbsp;&nbsp;<a href='" & ACT_Domain & "Comment.asp?ModeID=" & ModeID & "&ClassID=" & ClassID & "&ID=" & ID &"' target='_blank'>查看全部评论</a><br>"
		CommentStr=CommentStr&("<div class=comment><div class=commentbox>"");")&vbcrlf
	  Do While Not RS.Eof 
		CommentStr=CommentStr &("document.write(""<dl>"");")&vbcrlf
	
		UserIP=RS("UserIP")
		UserIP=Replace(UserIP,split(UserIP,".")(3),"*")
	   IF RS("Anonymous")=0 Then
			Others= "<font color=red>会员</font>："& RS("UserName")
	   Else
			Others= "游客："& RS("AnounName")
	   End IF
	   N=N+1
	    Others=Others  & " 发表时间： " & RS("AddDate") &" IP地址：" & UserIP & " &nbsp;&nbsp;第 <font color=red> " & N & "</font> 楼  &nbsp;&nbsp;<a href='" & ACT_Domain & "Comment.asp?Action=Support&ID=" & RS("ID") & "&Type=1'>支持\(<font color=red>" & rs("Y") & "</font>\)</a> <a href='" & ACT_Domain & "Comment.asp?Action=Support&ID=" & RS("ID") & "&Type=0'>反对\(" & rs("N") & "\)</a>"
		CommentStr=CommentStr &("document.write(""<dt>"&Others&"</dt>"");")&vbcrlf
		CommentStr=CommentStr &("document.write(""<dd>" & RS("Content") & "</dd>"");")&vbcrlf
		CommentStr=CommentStr &("document.write(""</dl>"");")&vbcrlf&vbcrlf
	  rs.movenext
	  Loop
	  CommentStr=CommentStr &("document.write(""</div></div>"");")
	Else
	CommentStr=""");"
	End If
	Response.Write("document.write(""" & CommentStr & "")

 End Sub
 
 '发表评论
Function WriteComment(ModeID, ClassID, ID)
		Dim UserName,Checked,disabled
		 If Cint(CommUser.UserLoginChecked)=False Then UserName = "匿名":Checked=" Checked " Else UserName= CommUser.username:disabled=" disabled=true "
		 WriteComment = "<table width=""98%"" border=""0"" align=""center"" cellpadding=""0"" cellspacing=""0"" class=""comment_write_table"">"
		 WriteComment = WriteComment & "<form name=""form1"" action=""" & ACT_Domain &"Comment.asp?Action=WriteSave"" method=""post"">"
		 WriteComment = WriteComment & "<input type=""hidden"" value=""" & ModeID & """ name=""ModeID""><input type=""hidden"" value=""" & ClassID & """ name=""ClassID""><input type=""hidden"" value=""" & ID & """ name=""ID"">"
		 WriteComment = WriteComment & "  <td height=""30"" colspan=""2"" align=""center"" class=fonts>用户名："
		 WriteComment = WriteComment & "   <input name=""AnounName"" type=""text"" id=""AnounName"" "&disabled&" value=""" & UserName& """ class=UserNames />"
		 WriteComment = WriteComment & "&nbsp;邮件："
		 WriteComment = WriteComment & "    <input name=""Email"" value=""" & CommUser.Email & """ type=""text"" id=""Email""  class=UserNames  />"
		If Actcms.ACT_C(ModeID,13)=0 Then
		WriteComment = WriteComment & "&nbsp;验证码：<input name=""Code"" type=""text"" size=""4""  class=UserNames >" 
		WriteComment = WriteComment & "<img style=""cursor:hand;"" src="""&ACTCMS.ActSys&"ACT_INC/Code.asp?s=+Math.random();"" id=""IMG1"" onclick=this.src="""&ACTCMS.ActSys&"ACT_INC/Code.asp?s=+Math.random();"" alt=""看不清楚? 换一张！"">"
		End If
		WriteComment = WriteComment & "<input type=""checkbox"" value=""1"" "&Checked&" name=""Anonymous"" id=Anonymous><label for=""Anonymous"">匿名发表&nbsp;&nbsp;</label><a href=""" & ACT_Domain & "User/Reg.asp""><font color=red><u>注册</u><font></a></td>"
		WriteComment = WriteComment & "  </tr>"
		
		WriteComment = WriteComment & "  <tr>"
		WriteComment = WriteComment & "    <td width=""80"" align=""center""></td>"
		WriteComment = WriteComment & "    <td  align=""center"" width=""90%""></td>"
		WriteComment = WriteComment & "  </tr>"
		
		WriteComment = WriteComment & "  <tr>"
		WriteComment = WriteComment & "    <td height=""25"" align=""center""  colspan=""2"" >"
		WriteComment = WriteComment & "<textarea name=""Content"" rows=""6"" id=""Content"" style=""border:1px solid #CCC; width:624px; height:80px; padding:5px;""></textarea>"
		WriteComment = WriteComment & "  </td></tr>"
		WriteComment = WriteComment & "  <tr>"
		
		WriteComment = WriteComment & "    <td height=""25"" colspan=""2"" align=""center""><input type=""submit"" class=""ACT_btn"" name=""SubmitComment"" value=""提交发表""/>"
		
		WriteComment = WriteComment & "    <a href=""" & ACT_Domain &"Comment.asp?ModeID=" & ModeID & "&ClassID=" & ClassID & "&ID=" & ID & """ target=""_blank"">查看全部评论</a></td>"
		WriteComment = WriteComment & "  </tr>"
		WriteComment = WriteComment & "  </form>"
		WriteComment = WriteComment & "</table>"
		
		End Function  
		
		'保存发表
		Sub WriteSave()		  
		Dim UserName,Email,Content,Locked,Anonymous,point,Code,AnounName
		AnounName=request("AnounName")
		Email=request("Email")
		Content=request("Content")
		Code=request("Code")
		Anonymous=request("Anonymous")
		IF Anonymous="" Or Not IsNumeric(Anonymous) Then Anonymous=0
		IF Cint(CommUser.UserLoginChecked)=false Then Anonymous=1
			Select Case Actcms.ACT_C(ModeID,15)
				   Case 0
						If Cint(CommUser.UserLoginChecked)=True And  CommUser.G_WriteComment="1" Then 
						Else 
							Response.Write("<script>alert('本栏目禁止发表评论!');history.back();</script>")
							Response.End
						End If 
						Locked=0
						If Cint(CommUser.UserLoginChecked)=True And  CommUser.G_SH="1" Then Locked=1
				   Case 1
						If Cint(CommUser.UserLoginChecked)=True And  CommUser.G_WriteComment="1" Then 
							Locked=0
						Else 
							IF Cint(CommUser.UserLoginChecked)=False Then
								 Response.Write("<script>alert('本栏目只允许会员发表评论,请注册后再发表');history.back();</script>")
								 Response.End
							Else
								Locked=0
							End If 
						End If 
						If Cint(CommUser.UserLoginChecked)=True And  CommUser.G_SH="1" Then Locked=1
				   Case 2
						If Cint(CommUser.UserLoginChecked)=True And  CommUser.G_WriteComment="1" Then 
							Locked=1
						Else 
							IF Cint(CommUser.UserLoginChecked)=False Then
								 Response.Write("<script>alert('本栏目只允许会员发表评论,请注册后再发表');history.back();</script>")
								 Response.End
							Else
								Locked=1
							End If 
						End If 
					Case 3
						Locked=0
						If Cint(CommUser.UserLoginChecked)=True And  CommUser.G_SH="1" Then Locked=1
					Case 4
						Locked=1
					Case Else 
						Exit Sub 
			End Select 



		If Actcms.ACT_C(ModeID,13)=0 and Trim(Request.Form("Code"))<>Trim(Session("GetCode")) Then
		 Response.Write("<script>alert('验证码有误，请重新输入！!');history.back();</script>")
		 Response.End
		End IF
		IF ID="" Then 
		 Response.Write("<script>alert('参数传递有误!');history.back();</script>")
		 Response.End
		End if
		if Anonymous=1 And AnounName="" Then 
		 Response.Write("<script>alert('请填写你的昵称!');history.back();</script>")
		 Response.End
		End if
		if Content="" Then 
		 Response.Write("<script>alert('请填写评论内容!');history.back();</script>")
		 Response.End
		End If
		If  Anonymous=0 And  Cint(CommUser.Locked)=1 Then 
		 Response.Write("<script>alert('您的账号已被管理员锁定，请与管理员联系或选择游客发表!');history.back();</script>")
		 Response.End
		End If
		If Actcms.ACT_C(ModeID,14)<>0 Then 
			if Len(Content)>Actcms.ACT_C(ModeID,14) Then 
			 Response.Write("<script>alert('评论内容必须在" &Actcms.ACT_C(ModeID,14) & "个字符以内!');history.back();</script>")
			 Response.End
			End if

		End If 
		Set RS=Server.CreateObject("ADODB.RECORDSET")
		RS.Open "Select * From Comment_Act",Conn,1,3
		RS.AddNew
		 RS("ModeID")=ModeID
		 RS("ClassID")=ClassID
		 RS("acticleID")=ID
		 RS("AnounName")=AnounName
		 RS("UserName")=CommUser.UserName
		 RS("Anonymous")=Anonymous
		 RS("Email")=Email
		 RS("Content")=ACTCMS.HTMLEncode(Content)
		 RS("UserIP")=ACTCMS.GetIP
		 RS("Locked")=Locked
		 RS("AddDate")=Now
		RS.UpDate
		RS.Close:Set RS=Nothing
		If Locked=1 then
		 Response.Write "<script>alert('你的评论发表成功!');location.href='" & Request.ServerVariables("HTTP_REFERER") & "';</script>"
		Else
		 Response.Write "<script>alert('你的评论发表成功,需要管理员后台审核才能显示!');location.href='" & Request.ServerVariables("HTTP_REFERER") & "';</script>"
		End if
		End Sub
		
		Sub Support()
		Dim ID,OpType
		ID=ACTCMS.ChkNumeric(request("ID"))
		OpType=request("Type")
		IF Cbool(Request.Cookies(Cstr(ID))("SupportCommentID"))<>true Then
			Set RS=Server.CreateObject("Adodb.Recordset")
			RS.Open "Select * From Comment_Act Where ID=" & ID ,Conn,1,3
			 if not rs.eof then
				  if OpType=1 Then
				 RS("Y")=RS("Y")+1
				  else
				 RS("N")=RS("N")+1
				  end if
			 RS.UpDate
			 RS.Close:Set RS=Nothing
		   end if
			 Response.Cookies(Cstr(ID))("SupportCommentID")=true
		End If
		Response.Write "<script>location.href='" & Request.ServerVariables("HTTP_REFERER") & "';</script>"
		End Sub
		

		


%>
 
