<!-- #include file=../inc/BBSsetup.asp -->
<!-- #include file=../inc/Board_Popfun.asp -->
<!-- #include file=../inc/Limit_fun.asp -->
<%
DEF_BBS_HomeUrl = "../"
initDatabase
GBL_CHK_TempStr = ""
siteHead("   购买帖子")
Dim AnnounceID,NeedValue,SellUserID
%>
<script language=javascript>
	window.moveTo(window.screen.width/2-225,window.screen.height/2-18);
</script>
<%
UpdateOnlineUserAtInfo GBL_board_ID,"购买帖子"

If GBL_CHK_Flag=1 Then
	If CheckIsBuySure = 1 Then
		DisplayBuyAnnounce
	End If
Else
	If Request("submitflag")="" Then
		Response.Write "<br><b>请先登录</b>"
	Else
		Response.Write "<br><p align=left><font color=ff0000 class=RedFont><b>" & GBL_CHK_TempStr & "</b></font>"
	End If
	Response.Write "</p>"
End If

closeDataBase
SiteBottom_Spend

Function CheckIsBuySure

	AnnounceID = Left(Request("AnnounceID"),14)
	If isNumeric(AnnounceID) = 0 or inStr(AnnounceID,",") > 0 or AnnounceID = "" Then
		Response.Write "错误,请提供要购买的帖子的ID!<br>" & VbCrLf
		Exit Function
	End if

	AnnounceID = cCur(AnnounceID)
	Dim Rs,SQL
	SQL = "Select top 1 BoardID,TopicType,NeedValue,UserID from LeadBBS_Announce where id=" & AnnounceID
	Set Rs = Con.Execute(SQL)
	GBL_DBNum = GBL_DBNum + 1
	If Rs.Eof Then
		Response.Write "错误,要购买的帖子ID不存在!<br>" & VbCrLf
		Rs.Close
		Set Rs = Nothing
		CheckIsBuySure = 0
		Exit Function
	End if

	Dim GBL_Board_ID,TopicType
	GBL_Board_ID = cCur(Rs("BoardID"))
	TopicType = Rs("TopicType")
	NeedValue = cCur(Rs("NeedValue"))
	SellUserID = cCur(Rs("UserID"))
	Rs.Close
	Set Rs = Nothing
	If TopicType <> 54 or NeedValue < 1 Then
		Response.Write "此帖子属于免费帖子，不必购买!<br>" & VbCrLf
		CheckIsBuySure = 0
		Exit Function
	End If

	If GBL_CHK_Points < NeedValue Then
		Response.Write "你的" & DEF_PointsName & "才" & GBL_CHK_Points & "，而购买此帖需要" & DEF_PointsName & "" & NeedValue & "!<br>" & VbCrLf
		CheckIsBuySure = 0
		Exit Function
	End If

	If GBL_UserID = SellUserID Then
		Response.Write "自己的帖子就不要买来买去了!<br>" & VbCrLf
		CheckIsBuySure = 0
		Exit Function
	End If

	Set Rs = Con.ExeCute("Select top 1 ID from LeadBBS_VoteUser where AnnounceID=" & AnnounceID & " and UserName='" & Replace(GBL_CHK_User,"'","''") & "'")
	If Not Rs.Eof Then
		Response.Write "你已经购买了此帖子，不需要重复购买!<br>" & VbCrLf
		CheckIsBuySure = 0
		Rs.Close
		Exit Function
	End If
	Rs.Close
	Set Rs = Nothing
	CheckisBoardMaster
	CheckAccessLimit
	If GBL_CHK_TempStr <> "" Then
		Response.Write GBL_CHK_TempStr
		CheckIsBuySure = 0
	Else
		CheckIsBuySure = 1
	End If
		
End Function

Function DisplayBuyAnnounce

	If Request.Form("DeleteSureFlag")="dk9@dl9s92lw_SWxl" Then
		Con.Execute("insert into LeadBBS_VoteUser(UserName,VoteItem,AnnounceID) values('" & Replace(GBL_CHK_User,"'","''") & "','" & NeedValue & "'," & AnnounceID & ")")
		GBL_DBNum = GBL_DBNum + 1
		Con.Execute ("Update LeadBBS_Announce Set PollNum=PollNum+1 where ID=" & AnnounceID)
		GBL_DBNum = GBL_DBNum + 1
		Con.Execute ("Update LeadBBS_Topic Set PollNum=PollNum+1 where ID=" & AnnounceID)
		GBL_DBNum = GBL_DBNum + 1
		Con.Execute ("Update LeadBBS_User Set Points=Points+" & NeedValue & " where ID=" & SellUserID)
		GBL_DBNum = GBL_DBNum + 1
		Con.Execute ("Update LeadBBS_User Set Points=Points-" & NeedValue & " where ID=" & GBL_UserID)
		GBL_DBNum = GBL_DBNum + 1
		UpdateSessionValue 4,0-NeedValue,1
		Response.Write "成功购买论坛帖子，请刷新页面来查看帖子内容．"
	Else
		%>
		<form name=DellClientForm action=BuyAnnounce.asp method=post>
			<input type=hidden name=DeleteSureFlag value="dk9@dl9s92lw_SWxl">
			<input type=hidden name=BoardID value="<%=GBL_Board_ID%>">
			<input type=hidden name=AnnounceID value="<%=AnnounceID%>"><%=GBL_CHK_TempStr%>
			<b>购买此帖需要花费<%=DEF_PointsName%><font color=ff0000 class=RedFont><%=NeedValue%></font>，确认要购买编号为<font color=ff0000 class=RedFont><%=AnnounceID%></font>的帖子吗？</b>
			<p><input type=submit value=确定 class=fmbtn>
			<input type=button value=不购买 onclick="javascript:window.close();" class=fmbtn>
		</form>
		<%
	End If

End Function%>