<!--#include file="Inc/conn.asp"-->
<!--#include file="inc/ubbcode.asp"-->
<!--#include file="Inc/function.asp"-->
<%
if CheckUserLogined()=False then 
	FoundErr=True
	ErrMsg=ErrMsg & "<br>&nbsp;&nbsp;&nbsp;&nbsp;你还没注册？或者没有登录？只有本站的注册用户才能发表评论！<br><br>"
	ErrMsg=ErrMsg & "&nbsp;&nbsp;&nbsp;&nbsp;如果你还没注册，请赶紧<a href='UserReg.asp'><font color=red>点此注册</font></a>吧！<br><br>"
	ErrMsg=ErrMsg & "&nbsp;&nbsp;&nbsp;&nbsp;如果你已经注册但还没登录，请赶紧<a href='UserLogin.asp'><font color=red>点此登录</font></a>吧！<br><br>"
end if

dim ArticleID,Action,ErrMsg,FoundErr
dim Commented,CommentedID,arrCommentedID,i
Action=trim(request("Action"))
ArticleID=trim(request("ArticleID"))
Commented=False
CommentedID=session("CommentedID")

if ArticleId="" then
	founderr=true
	errmsg=errmsg+"<li>请指定要评论的文章ID</li>"
else
	ArticleID=Clng(ArticleID)
end if
if CommentedID<>"" then
	if instr(CommentedID,"|")>0 then
		arrCommentedID=split(CommentedID,"|")
		for i=0 to ubound(arrCommentedID)
			if Clng(arrCommentedID(i))=ArticleID then
				Commented=True
				exit for
			end if
		next
	else
		if CommentedID=ArticleID then
			Commented=True
		end if
	end if
end if
if Commented=True then
	FoundErr=True
	ErrMsg=ErrMsg & "<li>你已经对该篇文章发表过评论了！请勿连续对同一篇文章发表评论。</li>"
end if

if FoundErr<>True then
	if Action="Save" then
		call SaveComment()
	else
		call main()
	end if
end if
if FoundErr=True then
	call WriteErrMsg()
end if
call CloseConn()

sub main()
%>
<html>
<head>
<title>发表评论</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="STYLE.CSS" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
function Check()
{
  if (document.form1.Title.value=="")
  {
    alert("请输入评论标题！");
	document.form1.Title.focus();
	return false;
  }
  if (document.form1.Content.value=="")
  {
    alert("请输入评论内容！");
	document.form1.Content.focus();
	return false;
  }
  return true;  
}
</script>
</head>

<body leftmargin="2" topmargin="0" marginwidth="0" marginheight="0">
<form name="form1" method="post" action="Comment.asp" onSubmit="return Check();">
  <table width="500" border="0" align="center" cellpadding="2" cellspacing="1" class="border">
    <tr align="center" class="title"> 
      <td height="22" colspan="2"><strong>发 表 评 论</strong></td>
    </tr>
    <tr class="tdbg"> 
      <td align="right">评论标题：</td>
      <td> <input name="Title" type="text" id="Title" size="60" maxlength="60"> 
        <font color="#FF0000">*</font></td>
    </tr>
    <tr class="tdbg"> 
      <td align="right">评论内容：</td>
      <td> <textarea name="Content" cols="50" rows="10" id="Content"></textarea></td>
    </tr>
    <tr align="center" bgcolor="#DAE8CA" class="tdbg"> 
      <td colspan="2"><input name="Action" type="hidden" id="Action" value="Save"> 
        <input name="ArticleID" type="hidden" id="ArticleID" value="<%=ArticleID%>"> 
        <input type="submit" name="Submit" value=" 发 表 "></td>
    </tr>
  </table>
</form>
</body>
</html>
<%
end sub

sub SaveComment()
	dim ClassID,tClass,Title,Content
	Title=trim(request.form("title"))
	Content=trim(request.Form("Content"))
	if Title="" then
		founderr=true
		errmsg=errmsg & "<br><li>请输入评论标题</li>"
	end if
	if Content="" then
		founderr=true
		errmsg=errmsg & "<br><li>请输入评论内容</li>"
	end if
	set tClass=conn.execute("select ClassID from Article where ArticleID=" & ArticleID)
	if tClass.bof and tClass.eof then
		FoundErr=True
		ErrMsg=ErrMsg & "<br><li>找不到要评论的文章，可能已经被删除！</li>"
	else
		ClassID=tClass(0)
	end if
	set tClass=nothing
	
	if founderr=true then
		exit sub
	end if
	Title=DvHtmlEncode(Title)
	Content=DvHtmlEncode(Content)
	
	sql="Insert Into Comment (ClassID,ArticleID,UserName,IP,Title,Content) values (" & ClassID & "," & ArticleID & ",'" & Request.Cookies("asp163")("UserName") & "','" & Request.ServerVariables("REMOTE_ADDR") & "','" & Title & "','" & Content & "')"
	conn.execute sql
	if CommentedID="" then
		session("CommentedID")=ArticleID
	else
		session("CommentedID")=CommentedID & "|" & ArticleID
	end if
	call WriteSuccessMsg("发表评论成功！")
end sub
%>