<!--#include file="Inc.asp"-->
<!--#include file="pet_conn.asp"-->

<!--#include file="lock.asp"-->

<%
Dim Action,Caption,Content,Face,Page,TmpUbbString
If Not BBS94KK.Founduser then BBS94KK.GoToerr(10)
BBS94KK.CheckMake
IF (Session(CacheName&"SayTime")+Int(BBS94KK.Info(11))/86400)>Now() Then BBS94KK.Alert"本论坛为了防止灌水，限制了同一人发帖的时间间隔为"& BBS94KK.Info(11)&" 秒！","back"
IF (Session("SafeCode")<>request.form("safecode") or Session("SafeCode")="") And BBS94KK.Info(15)="1" then BBS94KK.GoToErr(35)
BBS94KK.CheckBoard()
Face=BBS94KK.CheckNum(Request.form("face"))
Caption=Trim(BBS94KK.Fun.filtrateHtmlCode(BBS94KK.Fun.Checkbad(Request.form("Caption"))))
Content=BBS94KK.Fun.Checkbad(BBS94KK.Fun.GetForm("content"))

If Caption="" Or Content="" then BBS94KK.GoToErr(27)

If BBS94KK.Fun.CheckIsEmpty(Content) Then BBS94KK.GoToErr(50)
If BBS94KK.Info(60)="1" Then Content=BBS94KK.Fun.Replacehtml(Content)

IF Len(Caption)>200 Then BBS94KK.GoToErr(28)
IF Len(Content)>int(Session(CacheName & "MyGradeInfo")(9)) Then BBS94KK.GoToErr(29)
TmpUbbString=BBS94KK.Fun.UbbString(content)
BBS94KK.Head""

Action=lcase(request.querystring("action"))
If Len(Action)>10 Then BBS94KK.GotoErr(1)
IF Action="reply" Then
 	Reply()
ElseIf Action="edit" Then
	Edit()
Else
	Say()
End if

If BBS94KK.Info(15)=0 then Session("SafeCode")=Empty
Content="<div style=""margin:18px;line-height:150%"">"&Content&"</div>"
BBS94KK.ShowTable Caption,Content
Session(CacheName & "SayTime")=Now()
BBS94KK.Footer()
Set BBS94KK=Nothing

Function CheckUploadType(Str)
	dim re,s
	s=Str
	Set re=new RegExp
	re.IgnoreCase=true
	re.Global=True
	re.Pattern="(^.*)\[upload=(.+?),(.+?)\](.+?)\[\/upload\](.*)"
	s=Re.replace(s,"$2")
	Set re=nothing
	CheckUploadType=s
End function


Sub Say()
	with BBS94KK
	Dim ISvote,VoteType,VoteAutoValue,Votes,VoteNum,Outtime
	Dim UploadType,TopicLastReply,BoardLastReply,MaxID,TopicOpt
	Dim Temp,I,Font_S,Font_C
	IsVote=0
	Temp=CheckUploadType(Content)
	If Temp <> "" Then
		If instr(lcase("|"&.Info(34)&"|"&.Info(35)&"|"),lcase("|"&Temp&"|"))>0 then
			UploadType=Temp
		Else
			UploadType=""
		End if
	End IF
	'==--->>检查投票
	VoteType=.CheckNum(request.Form("votetype"))
	If VoteType<>2 Then VoteType=1
	VoteAutoValue=.CheckNum(request.Form("autovalue"))
	For i=1 to VoteAutoValue
	Temp=Left(.Fun.Checkbad(Trim(.Fun.GetStr("Votes"&I))),250)
	IF Temp<>"" Then
		Votes=Votes&"|"&Temp
		VoteNum=VoteNum&"|0"
	End If
	Next
	Outtime=cDate(.NowBbsTime)+int(request.form("OutTime"))
	If Votes<>"" Then IsVote=1
	'标题样式
	Font_S=.FUN.GetStr("font_s")
	Font_C=.FUN.GetStr("font_c")
	If Font_S<>"" or Font_C<>"" Then Temp=Font_S&"|"&Font_C Else Temp=""
	'插入主题表
	TopicLastReply="——|"&.Fun.StrLeft(.Fun.FixReply(Content),40)
	.Execute("Insert into [KK_Topic](Caption,Name,Face,IsVote,AddTime,LastTime,Lastreply,UploadType,BoardID,SqlTableID,Font)Values('"&Caption&"','"&.Myname&"',"&Face&","&IsVote&",'"&.NowBbsTime&"','"&.NowBbsTime&"','"&TopicLastReply&"','"&UploadType&"',"&.BoardID&","&.TB&",'"&Temp&"')")
	'得到新发表主题的ID	
	MaxID=.Execute("select Max(TopicID) from [KK_Topic]")(0)
	'操作选项
	Call Topict(MaxID)
	'插入投票
	IF IsVote=1 Then .Execute("insert into[KK_TopicVote](TopicID,Vote,VoteNum,VoteType,OutTime)values("&MaxID&",'"&votes&"','"&VoteNum&"',"&votetype&",'"&Outtime&"')")
	'插入帖子
	.Execute("Insert into [KK_bbs"&.TB&"](TopicID,Caption,name,Content,AddTime,LastTime,Face,BoardID,UbbString,IP)VALUES("&MaxID&",'"&Caption&"','"&.MyName&"','"&Content&"','"&.NowBbsTime&"','"&.NowBbsTime&"',"&Face&","&.BoardID&",'"&TmpUbbString&"','"&.MyIP&"')")
	'更新版块
	If .BoardString(6)=1 or .BoardString(5)=1 Then'特殊版面
		BoardLastReply=""
	Else
		BoardLastReply=.MyName&"|"&.Fun.StrLeft(Caption,20)&"|"&.NowBbsTime&"|"&Face&"|"&MaxID&"|"&.BoardID&"|"&.TB
	End If
		.Execute("Update [KK_Board] set TopicNum=TopicNum+1,TodayNum=TodayNum+1,EssayNum=EssayNum+1,LastReply='"&BoardLastReply&"' where BoardID="&.BoardID&" And Depth>0")
		Temp=.BoardID
		'更新上级版块
		If .BoardDepth>1 Then
			.Execute("Update [KK_Board] set TopicNum=TopicNum+1,TodayNum=TodayNum+1,EssayNum=EssayNum+1,LastReply='"&BoardLastReply&"' where BoardID In ("&.BoardParentStr&") And Depth>0")
			Temp=Temp&","&.BoardParentStr
		End If
		'更新各版块缓存
		.UpdateEcachBoardCache Temp,"1|1|1|"&BoardLastReply
	'更新系统
	.Execute("Update [KK_config] set Topicnum=Topicnum+1,allEssayNum=AllEssayNum+1,TodayNum=TodayNum+1")	
	'更新用户
	If Len(Content)>Int(.info(112)) Then
		Temp="Coin=Coin+"&.Info(102)&",Mark=Mark+"&.Info(103)&",GameCoin=GameCoin+"&.Info(104)&","
		If .Info(76)="1" Then Content=ShowGained(.Info(102),.Info(103),.Info(104))
	Else
		Temp=""
		Content=""
	End If
		.execute("Update [KK_user] set "&Temp&"EssayNum=EssayNum+1 WHERE ID="&.MyID&"")


'更新宠物经验
Connpet.execute("Update [mypetdata] set mypetexp=mypetexp+"&DEF_PET_newtopicexp&"  WHERE UserName='"&BBS94KK.MyName&"'")



	'更新等级
	.UpdateGrade .MyID,Session(CacheName & "MyInfo")(4)+1,int(Session(CacheName & "MyGradeInfo")(1))
	UpdateInfoCache(1)
	Caption="发帖成功！"
	Content="<meta http-equiv=""refresh"" content=""5;url=show.asp?id="&MaxId&"&BoardID="&.BoardID&"&TB="&.TB&""" /><li><b>发表成功----如果你不点击下面的连接，将在 5 秒后自动跳转到 回到你所发的帖的页面！</b></li><li><a href=""show.asp?id="&MaxId&"&BoardID="&.BoardID&"&TB="&.TB&""">回到你所发的帖的页面！</a></li><li><a href=""List.asp?BoardID="&.BoardID&""">"&.Boardname&"</a><li><a href=""index.asp"">"&.Info(0)&" 首页</a></li>"&Content
	End with
End Sub

Sub Reply()
	With BBS94KK
	Dim Rs,ID,TopicUserName,TopicLastReply,BoardLastReply,Temp,TopicCoin
	ID=.Checknum(request.querystring("ID"))
	If Id=0 or .BoardID=0 Then .GoToErr(1)
	'读主题信息
	Set Rs=.Execute("Select Name,IsLock,SqlTableID,BoardID,Caption From [KK_Topic] where TopicID="&ID&" And (BoardID="&.BoardID&" Or TopType=4 or TopType=5) And SqlTableID="&.TB&" And IsDel=0 ")
	IF Rs.Eof Then .GoToErr(21)  
	IF Rs(1)=1 Then .GoToErr(22)
	TopicUserName=Rs(0)
	.TB=Rs(2)
	.BoardID=Rs(3)
	Caption="回复:"&Rs(4)
	Rs.Close
	Set Rs=Nothing
	'插入帖子
	.execute("insert into [KK_bbs"&.TB&"](ReplyTopicID,name,Caption,Content,AddTime,LastTime,Face,Boardid,UbbString,ip)VALUES("&ID&",'"&.MyName&"','"&Caption&"','"&Content&"','"&.NowBbsTime&"','"&.NowBbsTime&"',"&face&","&.BoardID&",'"&TmpUbbString&"','"&.MyIp&"')")
	'更新主题帖子
	.execute("Update [KK_bbs"&.TB&"] Set LastTime='"&.NowBbsTime&"' where TopicId="&ID&"")
	'更新主题
	TopicLastReply=.MyName&"|"&.Fun.StrLeft(.Fun.FixReply(Content),40)
		.execute("Update [KK_Topic] set ReplyNum=ReplyNum+1,LastTime='"&.NowBbsTime&"',LastReply='"&TopicLastReply&"' where TopicId="&ID&"")
	'更新楼主
	If Lcase(.MyName)<>Lcase(TopicUserName) Then
		.execute("Update [KK_user] set Coin=Coin+"&.Info(111)&" WHERE Name='"&TopicUserName&"'")
	End If
	'更新版块
	If .BoardString(6)=6 or .BoardString(6)=5 Then	'特殊版面
		BoardLastReply=""
	Else
		If .Info(81)="1" Then
			Temp=.Fun.StrLeft(.Fun.FixReply(Content),20)
		Else
			Temp=.Fun.StrLeft(Caption,20)	
		End If	
		BoardLastReply=.MyName&"|"&Temp&"|"&.NowBbsTime&"|"&Face&"|"&ID&"|"&.BoardID&"|"&.TB
	End If
		.execute("Update [KK_Board] set lastReply='"&BoardLastReply&"',TodayNum=TodayNum+1,EssayNum=EssayNum+1 where BoardID="&.BoardID&" and Depth<>0")
		Temp=.BoardID
		If .BoardDepth>1 Then
			.Execute("Update [KK_Board] set TopicNum=TopicNum+1,TodayNum=TodayNum+1,EssayNum=EssayNum+1,LastReply='"&BoardLastReply&"' where BoardID In ("&.BoardParentStr&") And Depth>0")
			Temp=Temp&","&.BoardParentStr
		End If
	.UpdateEcachBoardCache Temp,"1|0|1|"&BoardLastReply

	'更新系统
	.execute("Update [KK_Config] set TodayNum=TodayNum+1,AllEssayNum=AllEssayNum+1")
	'更新用户
	If Len(Content)>Int(.info(112)) Then
		Temp="Coin=Coin+"&.Info(105)&",Mark=Mark+"&.Info(106)&",GameCoin=GameCoin+"&.Info(107)&","
		If .Info(76)="1" Then Content=ShowGained(.Info(105),.Info(106),.Info(106))
	Else
		Temp=""
		Content=""
	End If
	.execute("Update [KK_user] set "&Temp&"EssayNum=EssayNum+1 WHERE ID="&.MyID)

'更新宠物回复经验
Connpet.execute("update [mypetdata] set mypetexp=mypetexp+"&DEF_PET_replytopicexp&"  WHERE username='"&BBS94KK.Myname&"'")


	.UpdateGrade .MyID,Session(CacheName & "MyInfo")(4)+1,int(Session(CacheName & "MyGradeInfo")(1))
	UpdateInfoCache(0)
	'清分页缓存
	Response.Cookies(CacheName&"P")("Show_"&ID)=""
	Caption="回复成功 ！"
	Content="<meta http-equiv=refresh content=""5;url=show.asp?id="&ID&"&BoardID="&.BoardID&"&TB="&.TB&"&page=999"" /><li><b>发表成功----如果你不点击下面的连接，将在 5 秒后自动跳转到 您所回复的帖子内容页面！</b></li><li><a href='show.asp?id="&ID&"&BoardID="&.BoardID&"&TB="&.TB&"'>回到您所回复主题！</a></li><li><a href='show.asp?id="&ID&"&BoardID="&.BoardID&"&TB="&.TB&"&page=999'>回到您所回复的帖子内容页面！</a></li><li><a href='list.asp?BoardID="&.BoardID&"'>"&.Boardname&"</a><li><a href='index.asp'>"&.Info(0)&" 首页</a>"&Content
	End with
End Sub

Sub Edit()
	Dim Temp,Rs,ID,BbsID,TopicID,EditChalk,ReplyTopicID,Font_S,Font_C
	With BBS94KK
	Page=.CheckNum(request.querystring("page"))
	EditChalk=Request.form("editchalk")
	ID=.CheckNum(request.querystring("ID"))
	BbsID=.CheckNum(request.querystring("BbsID"))
	If BbsID=0 Or ID=0 Then .GoToErr(1)
	If EditChalk<>"No" Then
		Content=Content&vbcrlf&vbcrlf&"<div style=""color:#A48E7B;text-align:right"">「该帖子被 "&.MyName&" 在 "&.NowBbsTime&" 编辑过」</div>"
	End If
	Set Rs=.Execute("select TopicID,ReplyTopicID,Caption,Name from [KK_bbs"&.TB&"] where BbsID="&BbsID&" and IsDel=0")
	If Not Rs.eof  Then
		If Session(CacheName & "MyGradeInfo")(24)="0" And Lcase(.MyName)<>Lcase(rs("name")) Then .GoToErr(33)
		TopicID=Rs(0)
		ReplyTopicID=Rs(1)
		Temp=Rs(2)
	Else
		.GoToErr(58)
	End if
	Rs.Close
	If ReplyTopicID=0 then
		'标题样式
		Font_S=.FUN.GetStr("font_s")
		Font_C=.FUN.GetStr("font_c")
		If Font_S="" And Font_C="" Then
			Font_S=""
		Else
			If Font_S="no" Then Font_S=""
			If Font_C="no" Then Font_C=""
			If Font_S<>"" or Font_C<>"" Then
				Font_S=",Font='"&Font_S&"|"&Font_C&"'"
			Else
				Font_S=",Font=''"
			End If
		End If
		.execute("Update [KK_Topic] set Caption='"&Caption&"',Face="&Face&",LastTime='"&.NowBbsTime&"'"&Font_S&" where TopicID="&TopicID&"")
	Else
		Caption=Temp
	End If
	'更新
	.execute("Update [KK_bbs"&.TB&"] set Caption='"&Caption&"',Content='"&Content&"',Face="&Face&",LastTime='"&.NowBbsTime&"',UbbString='"&TmpUbbString&"',IP='"&.MyIp&"' where BbsID="&BbsID&"")
	'更新主题的最后回复
	dim tBBSID,tName,tLastTime,tFace
	Temp=""
	Set Rs=.execute("select top 1 BbsID,Name,Caption,Content,LastTime,Face from [KK_bbs"&.TB&"] where BoardID="&.BoardID&" And (TopicID="&ID&" or ReplyTopicID="&ID&") And IsDel=0 order by BbsID desc")
	If Not Rs.Eof Then
		If BbsID=Rs(0) Then	Temp=Rs(1)&"|"&.Fun.StrLeft(.Fun.FixReply(Rs(2)),40)
		tBBSID=Rs(0)
		tName=Rs(1)
		Caption=Rs(2)
		Content=Rs(3)
		tLastTime=Rs(4)
		tFace=Rs(5)
	Else
		Temp="——|"&.Fun.StrLeft(.Fun.FixReply(Content),40)
	End If
		Rs.Close
	Set Rs=Nothing
	If Temp<>"" then .execute("Update [KK_Topic] set LastReply='"&Temp&"' where TopicId="&ID&"")
	'更新版块
	Dim Boardupdate,BoardLastReply
	Boardupdate=.GetEachBoardCache(.BoardID)
	If Boardupdate(7)=ID&"" Then
		If .BoardString(6)=6 or .BoardString(6)=5 Then	'特殊版面
		Else
			If .Info(81)="1" Then
				Temp=.Fun.StrLeft(.Fun.FixReply(Content),20)
			Else
				Temp=.Fun.StrLeft(Caption,20)	
			End If	
			BoardLastReply=tName&"|"&Temp&"|"&tLastTime&"|"&tFace&"|"&ID&"|"&.BoardID&"|"&.TB
			.execute("Update [KK_Board] set lastReply='"&BoardLastReply&"' where BoardID="&.BoardID&" and Depth<>0")
			Temp=.BoardID
			If .BoardDepth>1 Then
				.Execute("Update [KK_Board] set LastReply='"&BoardLastReply&"' where BoardID In ("&.BoardParentStr&") And Depth>0")
				Temp=Temp&","&.BoardParentStr
			End If
			.UpdateEcachBoardCache Temp,"0|0|0|"&BoardLastReply
		End If
	End If
	Content="<li>修改成功！ <a href='Show.asp?ID="&ID&"&BoardID="&.BoardID&"&TB="&.TB&"&page="&page&"'>回到帖子页面</a></li><li><a href='List.asp?BoardID="&.BoardID&"'>"&.BoardName&"</a></li><li> <a href='index.asp'>"&.Info(0)&"论坛首页</a></li>"
	End with
End Sub

'更新缓存(参数：0回复/1主题)
Sub UpdateInfoCache(IsSay)
	Dim Temp,Max
	Temp=BBS94KK.Infoupdate(2)+1
	Max=BBS94KK.InfoUpdate(4)
	If Int(Temp)>Int(Max) Then
		BBS94KK.Execute("Update [KK_Config] set MaxEssayNum="&Temp&"")
		Max=Temp
	End If
	Temp=Replace(Join(BBS94KK.InfoUpdate,","),BBS94KK.InfoUpdate(0)&","&BBS94KK.InfoUpdate(1)&","&BBS94KK.InfoUpdate(2)&","&BBS94KK.InfoUpdate(3)&","&BBS94KK.InfoUpdate(4)  ,	BBS94KK.InfoUpdate(0)+1&","&BBS94KK.InfoUpdate(1)+Int(IsSay)&","&BBS94KK.InfoUpdate(2)+1&","&BBS94KK.InfoUpdate(3)&","&Max)
	BBS94KK.Cache.Add "InfoUpdate",Temp,dateadd("n",2000,BBS94KK.NowBBSTime)
	Session(CacheName & "MyInfo") = Empty


BBS94KK.Cache.clean("IndexNewTopic1")
BBS94KK.Cache.clean("IndexNewTopic2")



End Sub
'显示发帖奖励
Function ShowGained(C,M,G)
	If C<>"0" Then ShowGained=BBS94KK.Info(120)&":<span style='color:#F00'>"&C&"</span> "
	If M<>"0" Then ShowGained=ShowGained&BBS94KK.Info(121)&":<span style='color:#F00'>"&M&"</span> "
	If G<>"0" Then ShowGained=ShowGained&BBS94KK.Info(122)&":<span style='color:#F00'>"&G&"</span> "
	ShowGained="<li>您此次发帖获得："&ShowGained&"</li>"
End Function
'主题选项
Sub Topict(M_ID)
	Dim S
	S=""
	If request.Form("top")="1" Then S="toptype=3,"
	If Request.Form("classtop")="1" Then S="toptype=4,"
	If Request.Form("alltop")="1" Then S="toptype=5,"
	If Request.Form("good")="1" Then S=S&"isgood=1,"
	If Request.Form("lock")="1" Then S=S&"islock=1,"
	If S<>"" Then
	S=Left(S,len(S)-1)
	BBS94KK.Execute("update [KK_Topic] Set "&S&" where TopicID="&M_ID)
	End If
End Sub
%>
