<!--#include file="conn.asp"-->
<!--#include file="inc/bloginfo.asp"-->
<!--#include file="inc/userinfo.asp"-->
<!--#include file="inc/showcode.asp"-->
<!--#include file="inc/md5.asp"-->
<!--#include file="inc/calendar.asp"-->
<!--#include file="inc/function.asp"-->
<%
dim action,show_logid,commentid
dim showlogpass,logpassword
logpassword=trim(request("logpassword"))'md5
'show_username=replacebadchar(trim(request.QueryString("name")))
show_logid=clng(trim(request.QueryString("id")))
action=trim(request.QueryString("action"))
commentid=clng(request.QueryString("commentid"))
showlogpass=false
if logpassword<>"" then 
	logpassword=md5(logpassword)
	set rs=conn.execute("select id from blog where id="&show_logid&" and ispassword='"&logpassword&"'")
	if rs.eof then
		Response.Write"<script language=JavaScript>"
		Response.Write"alert(""对不起！日志密码错误！"");"
		Response.Write"window.history.go(-1);"
		Response.Write"</script>"
		response.End()
	else
		showlogpass=true
		response.Cookies(cookiesname)(show_logid&"_pass")="true"
	end if
end if
if request.Cookies(cookiesname)(show_logid&"_pass")="true" then
	showlogpass=true
end if
if action="addcomment" then
	if CheckUserLogined()=true then
		call addcomment()
	else
		if enguestcomment="true" then
			if trim(request("password"))<>"" then
				call commentlogin()
				if CheckUserLogined()=true then
					call addcomment()
				end if
			else
				call addcomment()
			end if
		else
			if CheckUserLogined()=false then
				call commentlogin()
				if CheckUserLogined()=true then
					call addcomment()
				end if
			else
				call addcomment()
			end if
		end if
	end if
end if

call usershow()
response.Write "<script language=""javascript"">"
response.Write "quote='"&Replace(Replace(Replace(Replace(quote(commentid),"\","\\"),"'","\'"),VbCrLf,"\n"),chr(13),"")&"';"
response.Write "</script>"
call sub_showlogmore(user_showcomment_num,"more.asp?name="&show_username&"&id="&show_logid)
show=replace(show,"$show_log$",show_logmore)
response.Write show
call bottom()

function quote(commentid)
if commentid>0 then
dim rs
set rs=conn.execute("select comment_user,addtime,comment from comment where id="&commentid)
	if not rs.eof then
		quote="<div style='margin:5px 20px;border:1px solid #CCCCCC;padding:5px; background:#F3F3F3'><strong>以下引用"&trim(rs(0))&"在"&trim(rs(1))&"的评论:</strong><br><br>"
		quote=quote&rs(2)&"</div><br>"
	end if
end if
set rs=nothing
end function

dim password,CookieDate,rsreg,sql
sub commentlogin()
dim sql
username=replace(trim(request("username")),"'","")
password=replace(trim(Request("password")),"'","")
if UserName="" then
	Response.Write"<script language=JavaScript>"
	Response.Write"alert(""对不起！用户名不能为空！"");"
	Response.Write"window.history.go(-1);"
	Response.Write"</script>"
	response.End()
end if
if Password="" then
	Response.Write"<script language=JavaScript>"
	Response.Write"alert(""对不起！密码不能为空！"");"
	Response.Write"window.history.go(-1);"
	Response.Write"</script>"
	response.End()
end if
if CookieDate="" then
	CookieDate=0
else
	CookieDate=Clng(CookieDate)
end if
set rs=conn.execute("select lockip from lockip where lockip='"&Request.ServerVariables("REMOTE_ADDR")&"'")
if not (rs.bof or rs.eof) then
	Response.Write"<script language=JavaScript>"
	Response.Write"alert(""对不起！你的IP已被锁定，不能登陆！"");"
	Response.Write"window.history.go(-1);"
	Response.Write"</script>"
	response.End()
else
	if ot_user then
		call ot_chklogin()
	else
		call ob_chklogin()
	end if	
end if
end sub

sub addcomment()
	if ChkPost()=false then
		response.write("不允许从外部提交！")
		response.End()
	end if
	dim rs,sql,subjectid,classid,mainuser
	set rs=conn.execute("select lockip from lockip where lockip='"&Request.ServerVariables("REMOTE_ADDR")&"'")
	if not (rs.bof or rs.eof) then
		Response.Write"<script language=JavaScript>"
		Response.Write"alert(""对不起！你的IP已被锁定，不能发表留言！"");"
		Response.Write"window.history.go(-1);"
		Response.Write"</script>"
		response.End()
	end if
	'增加日志回复数
	set rs=server.createobject("adodb.recordset")
	sql="select * from blog where id="&show_logid
	rs.open sql,conn,1,3
	subjectid=rs("subjectid")
	mainuser=rs("username")
	classid=rs("classid")
	rs("commentnum")=rs("commentnum")+1
	rs.update
	rs.close
	conn.execute("update [user] set commentcount=commentcount+1 where username='"&show_username&"'")
	conn.execute("update [bloginfo] set commentcount=commentcount+1 ")
	sql="select * from comment where mainuser='"&show_username&"'"
	rs.open sql,conn,1,3
	rs.addnew
	rs("mainid")=clng(request.QueryString("id"))
	if CheckUserLogined()=true then
		rs("comment_user")=username
	else
	     rs("comment_user")=request.Form("username")&"(游客)"
	end if
	rs("comment")=debadstr(request.Form("edit"))
	rs("commenttopic")=debadstr(request.Form("commenttopic"))
	rs("homepage")=request.Form("homepage")
	rs("addtime")=blognow()
	rs("mainsubject")=subjectid
	rs("mainuser")=mainuser
	rs("mainclass")=classid
	rs("addip")=Request.ServerVariables("REMOTE_ADDR")
	rs.update
	rs.close
	Response.Redirect("more.asp?name="&show_username&"&id="&show_logid)	
end sub

sub sub_showlogmore(num,strurl)
	dim show_logcyc,show_topic,show_loginfo,show_logtext,show_more,commenttopic
	dim show_emot,show_author,show_addtime,show_topictxt
	dim rs,rssubject
	dim vipsee
	dim qurl,qcommentid
	dim homepage
	dim isshowcomment
	isshowcomment=true
	qcommentid=clng(request.QueryString("commentid"))
	'response.Write(strurl)
	dim count,pagesize,pagecount,page,temp
	'=======以下为分页设置=====================
	'num=2
	pagesize=num '每页显示多少篇回复
	set rs=conn.execute("select count(id) from comment where mainid="&show_logid)
	count=rs(0)
	set rs=nothing
	if (count mod pagesize)=0 then
    	pagecount= count \ pagesize
	else
    	pagecount= (count \ pagesize)+1
	end if
	if request.querystring("page")<>"" then
    	page=request.querystring("page")
	    if page<=0 then page=1
	else
    	page=1
	end if
	'===============以下为显示代码===============
	if issqldate then
		dim cmd
		set cmd = Server.CreateObject("ADODB.Command")
		Set cmd.ActiveConnection=conn
		cmd.CommandType=4
		cmd.CommandText="ob_user_showlogmore"
		cmd("@id")=show_logid
		set rs=cmd.Execute
		set cmd=nothing
	else
		set rs=conn.execute("select face,topic,subjectid,id,username,addtime,logtext,ishide,commentnum,showword,ispassword,iis,trackback,isbest,blog_password,author from blog where passcheck<>'false' and id="&show_logid)
	end if
	if not rs.eof then
		response.write "<meta name='DEscriptions' contect='"&user_blogname&"--"&rs(1)&"'>"& vbcrlf
		response.Write "<title>"&user_blogname&"--"&rs(1)&"</title>"& vbcrlf
		response.Write "</head>" & vbcrlf
		response.Write "<body>" & vbcrlf& "<a name='top'></a>"
		if rs(0)="0" then
			show_emot=""
		else
			show_emot="<img src=images/face/"&rs(0)&".gif >"
		end if
		if isnull(rs(15)) then
			if nickname<>"" then show_author=nickname else show_author=rs(4)
		else 
			if rs(15)=rs(4) then
				if nickname<>"" then show_author=nickname else show_author=rs(4)
			else
				dim rstmp
				set rstmp=conn.execute("select nickname from [user] where username='"&rs(15)&"'")
				if rstmp.eof then
					show_author=rs(15)
				else
					if rstmp(0)<>"" then show_author=rstmp(0) else show_author=rs(15)
				end if
				set rstmp=nothing
			end if
		end if
		show_topic=show_emot
		show_addtime=rs(5)
		if rs(2)>0 then
			set rssubject=conn.execute("select subjectname from subject where id="&rs(2))
			if not (rssubject.eof and rssubject.bof) then
				show_topic=show_topic&"<a href=blog.asp?name="&rs(4)&"&subjectid="&rs(2)&">["&rssubject(0)&"]"
			end if
			set rssubject=nothing
		end if
		commenttopic="回复:"&htmlencode(rs(1))
		show_topictxt="<a href=more.asp?name="&rs(4)&"&id="&rs(3)&">"&htmlencode(rs(1))&"</a>"
		if rs(13)="true" then
			show_topictxt=show_topictxt&"　<img src=images/jhinfo.gif >"
		end if

		show_topic=show_topic&show_topictxt		
		show_loginfo=show_author&" 发表于 "&show_addtime
		show_more="<a href=more.asp?name="&rs(4)&"&id="&rs(3)&">阅读全文("&rs(11)&")</a>"
		show_more=show_more&" | "&"<a href=more.asp?name="&rs(4)&"&id="&rs(3)&"#comment>回复("&rs(8)&")</a>"
		qurl="more.asp?name="&rs(4)&"&id="&rs(3)
		show_more=show_more&" | "&"<a href=showtb.asp?id="&rs(3)&" target=_blank>引用("&rs(12)&")</a>"
		if Request.Cookies(cookiesname)("userlevel")=8 and vip_prosee="true" then
			vipsee=true
			else
			vipsee=false
		end if
		if rs(7)="true" and Request.Cookies(cookiesname)("UserName")<>rs(4) and Request.Cookies(cookiesname)("userlevel")<>9 and vipsee=false then
			show_logtext="<div align=center>此处隐藏一篇日志。</div>"
			isshowcomment=false
		elseif rs(10)<>"" and Request.Cookies(cookiesname)("UserName")<>rs(4) and Request.Cookies(cookiesname)("userlevel")<>9 and vipsee=false and showlogpass<>true then
'			call sub_showpasswordlog()
'			show_logtext="<div align=center>此日志需要密码访问。</div>"
			show_logtext="<form name=logpassword method=post action=''>"& vbcrlf
			show_logtext=show_logtext&"请输入日志密码：<input name=logpassword type=password id=logpassword size=15 maxlength=20>　　"
			show_logtext=show_logtext&"<input type=submit name=Submit value=提交>"
			show_logtext=show_logtext&"</form>"
			isshowcomment=false
		else
		show_logtext=filtimg(filtscript(rs(6)))
		end if
		conn.execute("update blog set iis=iis+1 where id="&show_logid)
		show_logcyc=replace(show_logtmp,"$show_topic$",show_topic)
		show_logcyc=replace(show_logcyc,"$show_loginfo$",show_loginfo)
		show_logcyc=replace(show_logcyc,"$show_logtext$",show_logtext)
		show_logcyc=replace(show_logcyc,"$show_more$",show_more)
		show_logcyc=replace(show_logcyc,"$show_emot$",show_emot)
		show_logcyc=replace(show_logcyc,"$show_author$",show_author)
		show_logcyc=replace(show_logcyc,"$show_addtime$",show_addtime)
		show_logcyc=replace(show_logcyc,"$show_topictxt$",show_topictxt)
		show_logmore=show_logmore&show_logcyc
		if isshowcomment then
		if show_comment_asc="true" then
			show_comment_asc=" order by id asc"
		else
			show_comment_asc=" order by id desc"
		end if
		if issqldate then
			set cmd = Server.CreateObject("ADODB.Command")
			Set cmd.ActiveConnection=conn
			cmd.CommandType=4
			cmd.CommandText="ob_user_showcommentmore"
			cmd("@mainid")=show_logid
			cmd("@addstr")=show_comment_asc
			set rs=cmd.Execute
			set cmd=nothing
		else	
			set rs=conn.execute("select comment_user,commenttopic,comment,addtime,id,homepage from comment where mainid="&show_logid&show_comment_asc)
		end if
		if not rs.eof then
			dim isshowpage
			isshowpage=true
		end if
		if page <>1 then rs.move pagesize*(page-1)
         for temp=1 to pagesize
		 	if rs.eof then exit for
				if isnull(rs(5)) then
					homepage="个人主页"
				else
					if trim(replace(rs(5),"http://",""))="" then
						homepage="个人主页"
					else
						homepage="<a href='"&HTMLEncode(rs(5))&"' target='_blank'>个人主页</a>"
					end if
				end if
			  	show_topic=htmlencode(rs(1))&"<a name='"&rs(4)&"'></a>"
				show_author=htmlencode(rs(0))
				show_addtime=rs(3)
				show_topictxt=show_topic
				show_loginfo=show_author&"发表评论于"&show_addtime
				show_logtext=rs(2)
				show_more=homepage&" | <a href="&qurl&"&commentid="&rs(4)&"#comment>引用</a> | <a href='#top'>返回</a>"
				show_logcyc=replace(show_logtmp,"$show_topic$",show_topic)
				show_logcyc=replace(show_logcyc,"$show_loginfo$",show_loginfo)
				show_logcyc=replace(show_logcyc,"$show_logtext$",show_logtext)
				show_logcyc=replace(show_logcyc,"$show_more$",show_more)
				show_logcyc=replace(show_logcyc,"$show_emot$","")
				show_logcyc=replace(show_logcyc,"$show_author$",show_author)
				show_logcyc=replace(show_logcyc,"$show_addtime$",show_addtime)
				show_logcyc=replace(show_logcyc,"$show_topictxt$",show_topictxt)
				show_logmore=show_logmore&show_logcyc
				rs.movenext
			next	
	'===================分页尾部=======================
	dim pagelist
	dim pot,i
	strurl=joinchar(strurl)
	if page-1 mod 10=0 then
       pot=(page-1) \ 10
	else
       pot=(page-1) \ 10
	end if
 
	if page=1 then 
        pagelist=" <font face=webdings color='red'>9</font> "
	else
        pagelist=" <a href='"&strurl&"page=1' title=首页><font face=webdings>9</font></a> "
	end if
 
	if pot*10>0 then pagelist=pagelist &  " <a href='"&strurl&"page="&Cstr(pot*10)&"' title=上十页><font face=webdings>7</font></a> "
 
	pagelist=pagelist & "<b>" 
 
	for i=pot*10+1 to Pot*10+10
          if i=cint(Page) then
                    pagelist=pagelist & " <font color='red'>"+Cstr(i)+"</font> "
          else
     pagelist=pagelist & " <a href='"&strurl&"page="&Cstr(i)&"'>"+Cstr(i)+"</a> "
          end if
          if i=pagecount then exit for 
	next
 
	pagelist=pagelist & "</b>"

	if i<pagecount then pagelist=pagelist & " <a href='"&strurl&"page="&Cstr(i)&"' title=下十页><font face=webdings>8</font></a> "
	if Page=pagecount then
           pagelist=pagelist & "<font face=webdings color='red'>:</font>"
	else
           pagelist=pagelist & " <a href='"&strurl&"page="&Cstr(pagecount)&"' title=尾页><font face=webdings>:</font></a> "
	end if

	dim showpage
'	showpage="页次："&page&"/"&pagecount&"　"
'	showpage=showpage&"每页："&pagesize
'	showpage=showpage&"　日志数：<b>"&count&"</b>"
	if isshowpage=false then 
		showpage=""
	else
		showpage=showpage&"<div align=right>"&pagelist&"</div>"
	end if
	dim strguest
	if  enguestcomment="true" then
		strguest="(游客无须输入密码)"
	else
		strguest=""	
	end if
	show_logmore=show_logmore&showpage
	show_logmore=show_logmore&"<br><a name='comment'></a><table width='90%' border='0' align='center' cellspacing='0' cellpadding='0'> <tr> <td><strong>发表评论：</strong></tr></td></table>"& vbcrlf
	show_logmore=show_logmore&"<table width='90%' border='0' align='center' cellspacing='0' cellpadding='0'> <tr> <td><table align='left' width='100%' border='0' cellspacing='0' cellpadding='0'>" & vbcrlf
	show_logmore=show_logmore&  "<form action='more.asp?name="&show_username&"&id="&show_logid&"&action=addcomment' method='post' name='commentform' onSubmit='return Verifycomment()'>" & vbcrlf
    show_logmore=show_logmore& "<tr><td height='25'  align='left'>昵称：<input name='UserName' type='text' id='UserName' size='15' maxlength='20' value='"&Request.Cookies(cookiesname)("UserName")&"'></td></tr>" & vbcrlf
    show_logmore=show_logmore& "<tr><td height='25' align='left'>密码：<input name='Password' type='password' id='Password' size='15' maxlength='20' value='"&Request.Cookies(cookiesname)("Password")&"'> "&strguest&"</td></tr>" & vbcrlf
	show_logmore=show_logmore&"<tr ><td height='25' align='left'  >主页：<input name='homepage' type='text' id='homepage' size='42' maxlength='50' value='http://'><td></tr>"
	show_logmore=show_logmore&"<tr ><td height='25' align='left'  >标题：<input name='commenttopic' type='text' id='commenttopic' size='42' maxlength='50' value='"&commenttopic&"'><td></tr>"
    show_logmore=show_logmore& "<tr height='200'><td ><INPUT type='hidden' name='edit' id='edit' value=''>"& vbcrlf
	show_logmore=show_logmore& aApplicationValue(31) & vbcrlf
	show_logmore=show_logmore& "</td></tr>" & vbcrlf
	show_logmore=show_logmore& "<tr><td height='30' ><input name='login' type='submit' id='Login' value=' 提交 '> " & vbcrlf
    show_logmore=show_logmore& "</td>" & vbcrlf      
    show_logmore=show_logmore& "</tr></form></table></td></tr></table>" & vbcrlf
	end if
	else
		show_logmore="日志不存在！"
	end if
end sub

function debadstr(str)
	dim rs,badstr,i
	debadstr=str
	set rs=conn.execute("select blogFiltrate from filtrate")
	badstr=split(rs(0),"|")
	for i=0 to ubound(badstr)
	debadstr=replace(debadstr,badstr(i),"***")
	next
end function

%>

<SCRIPT language="javascript">

function del_space(s)
{
	for(i=0;i<s.length;++i)
	{
	 if(s.charAt(i)!=" ")
		break;
	}

	for(j=s.length-1;j>=0;--j)
	{
	 if(s.charAt(j)!=" ")
		break;
	}

	return s.substring(i,++j);
}

function Verifycomment()
{
	//submits(); 
	v = del_space(document.commentform.commenttopic.value);
     if (v.length == 0)
     {
        alert("您忘了填写题目!");
	return false;
     }
	 
	 v = del_space(document.commentform.UserName.value);
     if (v.length == 0)
     {
        alert("您忘了留下名字!");
	return false;
     }
	submits(); 
	if (document.commentform.edit.value == "")
     {
        alert("内容不能为空!");
	return false;
     }
	
	return true;
}

</SCRIPT>
