<!--#include file="../../fy_inc/fy.User.asp"-->
<%Dim CommUser,hfid
ConnectionDatabase
 	Dim ModeID,ClassID,ID,Action,rs,CommentStr,names
 	ClassID=ChkNumeric(request("ClassID"))
	 ModeID=fycms.ACT_L(ClassID,10) 
 	ID=ChkNumeric(request("ID"))
 	hfid=ChkNumeric(request("hfid"))
	Action=request("Action")
	Set CommUser = New ACT_User
	Action=request("Action")
	Select Case Action
	  Case "WriteSave","hfWriteSave"
	  Call WriteSave()
	 Case "Support"
	  Call Support()
	 Case "Write"
	  Call Write
	 Case Else
		echo "error":response.end
	 End Select


  
	Function Write()
    	If fycms.ACT_C(ModeID,15)="0"  Then 
		echo ("document.write(""该评论已关闭"");")&vbcrlf&vbcrlf
		response.end
	End If 

	Set rs=fycms.actexe("select rev from  "&fycms.ACT_C(ModeID,2)&"  where id="&ID)
	If rs.eof Then echo ("document.write(""已经关闭评论"");")&vbcrlf&vbcrlf:response.end
	If rs("rev")="0" Then  echo ("document.write(""已经关闭评论"");")&vbcrlf&vbcrlf:response.End
	CommentStr=CommentStr &("document.write(""<form action='"&fycms.actsys&"plus/Comment/fy.Comment.asp?Action=WriteSave' method='post' name='Comment'>"");")&vbcrlf&vbcrlf
    CommentStr = CommentStr &("document.write(""<input type='hidden' value='" & ModeID & "' name='ModeID'><input type='hidden' value='" & ClassID & "' name='ClassID'><input type='hidden' value='" & ID & "' name='ID'>"");")&vbcrlf&vbcrlf
  	
	
	
  	CommentStr=CommentStr &("document.write(""<textarea cols='60' name='Content' rows='5'></textarea>"");")&vbcrlf&vbcrlf
 	CommentStr=CommentStr &("document.write(""<div class='pcomuser'>"");")&vbcrlf&vbcrlf


 
	
	IF Cbool(CommUser.UserLoginChecked)=false then
		CommentStr=CommentStr &("document.write(""<span>用户名：<input name='username' type='text' class='tinput' value='匿名'></span>"");")&vbcrlf&vbcrlf
		CommentStr=CommentStr &("document.write(""<span>E-mail：<input name='Email' type='text' class='tinput'></span>"");")&vbcrlf&vbcrlf
 	Else
		CommentStr=CommentStr &("document.write(""<span>会员："&CommUser.username&"</span>"");")&vbcrlf&vbcrlf
  	End If	
	
	If fycms.ACT_C(ModeID,13)=0 Then
		CommentStr=CommentStr &("document.write(""<span>验证码：<input type='text' class='tinput'  size='4' name='Code' />"");")&vbcrlf&vbcrlf
		CommentStr = CommentStr &("document.write(""<img style='cursor:hand;' src='"&fycms.ActSys&"fy_inc/Code.asp?s=+Math.random();' id='IMG1' onclick=this.src='"&fycms.ActSys&"fy_inc/Code.asp?s=+Math.random();' alt='看不清楚? 换一张！'></span>"");")&vbcrlf&vbcrlf
	End If
	'	CommentStr=CommentStr &("document.write(""<span><label for='AnounNames'><input name='AnounName' id='AnounNames' type='checkbox'  class='cinput'>匿名</label></span>"");")&vbcrlf&vbcrlf
		CommentStr=CommentStr &("document.write(""<input name='submit' type='submit' value='提交评论' class='form_submit'>"");")&vbcrlf&vbcrlf
	CommentStr=CommentStr &("document.write(""</div></form>"");")&vbcrlf&vbcrlf
	 echo CommentStr
	End Function 

	Sub WriteSave()
 		Dim UserName,Email,Content,Locked,point,Code,AnounName
  		If fycms.ACT_C(ModeID,15)="0"  Then 
			echo ("document.write(""已经关闭评论1"");")&vbcrlf&vbcrlf
			response.end
		End If 
		Set rs=fycms.actexe("select rev from  "&fycms.ACT_C(ModeID,2)&"  where id="&ID)
		If rs.eof Then echo ("document.write(""已经关闭评论2"");")&vbcrlf&vbcrlf:response.End
		If rs("rev")="0" Then  echo ("document.write(""已经关闭评论3"");")&vbcrlf&vbcrlf:response.End
		UserName=Server.HTMLEncode(fycms.s("UserName"))
 		AnounName=ChkNumeric(request("AnounName"))
		Email=Server.HTMLEncode(fycms.s("Email"))
		Content=request("Content")
		Code=request("Code")
 		IF AnounName="" Or Not IsNumeric(AnounName) Then AnounName=1
		IF Cint(CommUser.UserLoginChecked)=false Then AnounName=1
			Select Case fycms.ACT_C(ModeID,15)
				   Case 0
						If Cint(CommUser.UserLoginChecked)=True And  CommUser.G_WriteComment="1" Then 
						Else 
							echo("<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
								 echo("<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
								 echo("<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 fycms.ACT_C(ModeID,13)=0 and Trim(Request.Form("Code"))<>Trim(Session("GetCode")) Then
		 echo("<script>alert('验证码有误，请重新输入！!');history.back();</script>")
		 Response.End
		End IF
		IF ID="0" Then 
		 echo("<script>alert('参数传递有误!');history.back();</script>")
		 Response.End
		End if
	 
		if Content="" Then 
		 echo("<script>alert('请填写评论内容!');history.back();</script>")
		 Response.End
		End If
		If  AnounName=0 And  Cint(CommUser.Locked)=1 Then 
		 echo("<script>alert('您的账号已被管理员锁定，请与管理员联系或选择游客发表!');history.back();</script>")
		 Response.End
		End If
		If fycms.ACT_C(ModeID,14)<>0 Then 
			if Len(Content)>fycms.ACT_C(ModeID,14) Then 
			 echo("<script>alert('评论内容必须在" &fycms.ACT_C(ModeID,14) & "个字符以内!');history.back();</script>")
			 Response.End
			End if

		End If 
 		Set RS=Server.CreateObject("ADODB.RECORDSET")
		RS.Open "Select * From Comment_fy",Conn,1,3
		RS.AddNew

		If AnounName=1 Then 
 			 If UserName="" Then RS("userid")="0"
 			 RS("Email")=Email
		Else
			 RS("UserID")=CommUser.UserID
  		End If 
		 RS("ModeID")=ModeID
		 RS("ClassID")=ClassID
		 RS("acticleID")=ID
		 Dim strc
		 If action="hfWriteSave" Then '要回复的
 		    strc=strc&"<div class=""quote"">"&vbcrlf
			Dim names,userip
			names=fycms.UserM(getc(hfid,"userid"))
			If names=false Then names="匿名"
			'die request.form
 			userip=left(getc(hfid,"userip"),(len(getc(hfid,"userip"))-2))+".*"
			If getc(hfid,"Commentrev")=1 then
			 strc=strc&"                 <strong>引用："&userip&" ["&names&"] 的原贴：</strong>"&vbcrlf&getc(hfid,"quotecontent")&""&vbcrlf
			Else
			 strc=strc&"                 <strong>"&userip&" ("&names&") ：</strong>"&vbcrlf
			End If 
            strc=strc&"                <div class='p'>"&vbcrlf
             strc=strc&getc(hfid,"content")&"    </div>"&vbcrlf&"</div>"&vbcrlf
			' strc=rep(strc,"[quote]",Content)
			   'die strc
			 RS("quotecontent")=strc



			' getc(hfid)
			 	
		 RS("Commentrev")=RS("Commentrev")+1
		 Else
		 	 RS("quotecontent")=Content
 











		 End If 
		 RS("Content")=fycms.HTMLEncode(Content)
		 RS("UserIP")=GetIP
		 RS("Locked")=Locked
		 RS("AddDate")=Now
		RS.UpDate
		RS.Close:Set RS=Nothing

		fycms.actexe("update "&fycms.ACT_C(ModeID,2)&" set commentscount=commentscount+1 where id="&id)
		If Locked=1 then
		 echo "<script>alert('你的评论发表成功!');location.href='" & Request.ServerVariables("HTTP_REFERER") & "';</script>"
		Else
		 echo "<script>alert('你的评论发表成功,需要管理员后台审核才能显示!');location.href='" & Request.ServerVariables("HTTP_REFERER") & "';</script>"
		End if

	End Sub 


	Function getc(id,Commentrev)
		Dim rs2
		Set rs2=fycms.actexe("Select * From Comment_fy where id="&id)
		If Not rs2.eof Then
		 
				getc=rs2(Commentrev)
			 
		End If 
 	End  Function 

	Sub Support()
 	Dim ID,OpType,RS,rs1
	ID=ChkNumeric(request("id"))
	OpType=ChkNumeric(request("Type"))
	IF Cbool(Request.Cookies(Cstr(ID))("SupportCommentID"))<>true Then
		Set RS=Server.CreateObject("Adodb.Recordset")
		RS.Open "Select * From Comment_fy 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
 		 Set rs1=fycms.actexe("Select top 1 id,y,n From Comment_fy Where ID="&id)
		 If Not rs1.eof Then 
			if OpType=1 Then
 				echo "ok|"&rs1("Y")
			 Else 
				 echo "ok|"&rs1("N")
			End If 
		End If 
  	Else
 		 echo "err|0"
	End If
 	End Sub











%>