<%@ Language=VBScript %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--#include file="inc/conndb.asa"-->
<!--#include file="inc/function.asp"-->
<%
server_v1=Cstr(Request.ServerVariables("HTTP_REFERER"))
server_v2=Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(server_v1,8,len(server_v2))<>server_v2 then
response.write "<br><br><center><table border=1 cellpadding=20 bordercolor=black bgcolor=#EEEEEE width=450>"
response.write "<tr><td style='font:9pt Verdana'>"
response.write bbsname&" - 提示您，我们不接受来自站点外部提交的数据."
response.write "</td></tr></table></center>"
response.end
end if
comurl=server_v1
cz=Request.QueryString("cz")
id=cint(Request.QueryString("id"))
tn=Request.QueryString("tn")

'----------------读取数据-------------------
ycid=request.form("ycid")
boardid=Trim(request.form("boardid"))
title=Trim(request.form("title"))
content=rtrim(request.form("content"))
username=Dreamsun_name
ip=Trim(reip())
recount=request.form("recount")
titlecolor=request.form("titlecolor")
titleBold =Request.Form("titleBold")
picurl =Request.Form("picurl")
fee = Request.Form("isFee") ' 看帖所需积分 Add For V 1.5
isRe = Request.Form("isRe") ' 是否允许回复该帖  Add For V 1.5
'----------------数据编码-------------------
content=server.htmlencode(content)
title=server.htmlencode(title)

If cz<>"" Then 
	Select Case cz
		Case "del"
			If isadmin<>9 Then
				Call checkbz()
				Call checkbanzhu()
			End If 
			Call del()
		Case "redel"
			If isadmin<>9 Then
				Call checkbz()
				Call checkbanzhu()
			End If 
			Call redel()
		Case "istop"
			If isadmin<>9 Then
				Call checkbz()
				Call checkbanzhu()
			End If 
			Call istop()
		Case "isgood"
			If isadmin<>9 Then
				Call checkbz()
				Call checkbanzhu()
			End If 
			Call isgood()
		Case "addsave"
			Call addsave()
		Case "editsave"
			Call checkadmin()
			Call editsave()
		Case "ueditsave"
			call checkuser()
			Call ueditsave()
		Case "ischeck" '审核 Add For V1.5
			If isadmin<>9 Then
				Call checkbz()
				Call checkbanzhu()
			End If 
			Call checkstatus()

	End Select
End If 

Sub checkbz()'根据id判断boardid，用来判断是否版主，根checkbanzhu配合使用
	If cz="rebbs" Then
		sql_bz="Select b.boardid,b.id,r.re,r.id from "&bbstable&" as b "&rebbstable&" as r where r.re=b.id where r.id="&id&""
	Else 
		sql_bz="Select boardid from "&boardtable&" where id="&id&""
	End If 
		rss=conn.execute(sql_bz)
		boardid=rss(0)
End Sub 
'----------------------定义主题帖子删除----------------------------------
Sub del()
	conn.execute("update "&bbsTable&" set IsCheck=-1 where id ="&id&"")'虚拟删除主题,回复暂时不管了，回收站处理
		Set rs_u= Server.CreateObject("ADODB.Recordset")
			sql_u="Select "&bbstable&".username as zuozhe,"&usertable&".username From "&bbstable&","&usertable&" where "&usertable&".username="&bbstable&".username and "&bbstable&".id="&id
			rs_u.Open sql_u,conn,3,3
			if not rs_u.eof Then 
				username=rs_u("zuozhe")
				'判断删除帖子的是不是作者本人，若是，就扣相应添加的分，否则就是那个删除的分数
					If username=Dreamsun_name Then
						del_money_t=add_money
					Else
						del_money_t=del_money
					End If 
				conn.execute("update ["&usertable&"] set [umoney]=umoney-"&del_money_t&" where [username]='"&username&"'")
				qian=",扣除 "&username&" 积分"&del_money_t&"分"
			' 删除成功后,给[ACCOUNT]表中插入积分记录
				OptTable("insert into [account] (accID,accValue,accFromUser,accToUser,accTime,accReason,accRemark) values("&CStr(GetMaxID("account","accid"))&","&CStr(del_money_t)&",'"&username&"','"&"系统"&"','"&CStr(Now())&"','被删 ','')")
				shuoming="原贴&回复删除"
				comurl="index.asp"
			End If 
			rs_u.close
		set rs_u=Nothing
	response.write backmsg("恭喜您！帖子"&shuoming&"成功"&qian,comurl)
End Sub 

'----------------------定义回复帖子删除----------------------------------
Sub redel()
		Set rs= Server.CreateObject("ADODB.Recordset")
			rs.Open "Select re,addtime From "&rebbstable&" where id="&id, conn,1,1  
			res=rs("re")
			addtime=rs("addtime")
			rs.close
		set rs=Nothing
						Set rs= Server.CreateObject("ADODB.Recordset")
							rs.Open "Select recount,retime,addtime,username From "&bbstable&" where id="&res, conn,3,3  
							zhangd=rs("recount")
							retime=rs("retime")
							addtime2=rs("addtime")
							username2=rs("username")
							rs("recount")=zhangd-1
							rs.update
							rs.close
						set rs=Nothing
If addtime=retime Then '如果删除的是最后的一个回复，就要更新主题帖子里面的回复信息。
		Set rs= Server.CreateObject("ADODB.Recordset")
			sql2="Select top 2 addtime,username From "&rebbstable&" where ischeck>-1 and re="&res&" order by addtime desc"
			rs.Open sql2,conn,1,1  
			if not rs.eof then Rs.MoveNext
			if not rs.eof then 
				addtime1=rs("addtime")
				username1=rs("username")
				sql_3="update ["&bbstable&"] set [retime]='"&addtime1&"',[rename]='"&username1&"' where id="&res&""
				conn.execute(sql_3)
			Else
				sql_3="update ["&bbstable&"] set [retime]='"&addtime2&"',[rename]='"&username2&"' where id="&res&""
				conn.execute(sql_3)
			End If 
			rs.close
		set rs=Nothing
End If 
						Set rs_u= Server.CreateObject("ADODB.Recordset")
							sql_u="Select "&rebbstable&".username as zuozhe,"&usertable&".username From "&rebbstable&","&usertable&" where "&usertable&".username="&rebbstable&".username and "&rebbstable&".id="&id
							rs_u.Open sql_u,conn,3,3
							if not rs_u.eof Then 
								username=rs_u("zuozhe")
									'判断删除帖子的是不是作者本人，若是，就扣相应添加的分，否则就是那个删除的分数
									If username=Dreamsun_name Then
										del_money_t=re_money
									Else
										del_money_t=del_money
									End If 
								conn.execute("update ["&usertable&"] set [umoney]=umoney-"&del_money_t&" where [username]='"&username&"'")
								' Add For V1.5 CHANG, ZIDONE '''''''''''''Begin
								' 删除成功后,给[ACCOUNT]表中插入积分记录
								OptTable("insert into [account] (accID,accValue,accFromUser,accToUser,accTime,accReason,accRemark) values("&CStr(GetMaxID("account","accid"))&","&CStr(del_money_t)&",'"&username&"','"&"系统"&"','"&CStr(Now())&"','被删 ','')")
								''''''''''''''''''''''''''''''''''''''''''End
								qian=",扣除 "&username&" 积分"&del_money_t&"分"
							End If 
							rs_u.close
						set rs_u=Nothing
	conn.execute("update "&rebbsTable&" set IsCheck=-1 where id ="&id&"")'虚拟删除回复
response.write backmsg("恭喜您！本贴删除成功"&qian,comurl)
End Sub 
'----------------------置顶操作----------------------------------
Sub istop()
		Set rs= Server.CreateObject("ADODB.Recordset")
			rs.Open "Select istop From "&bbstable&" where id="&id, conn,1,3  
			istops=rs("istop")
				If istops=0 Then
					rs("istop")=1
					shuoming="设置置顶"
				Else
					rs("istop")=0
					shuoming="取消置顶"
				End If
			 
			rs.update
			rs.close
	response.write backmsg("恭喜您！帖子"&shuoming&"成功",comurl)
End Sub 
'----------------------精华操作----------------------------------
Sub isgood()
		Set rs= Server.CreateObject("ADODB.Recordset")
			rs.Open "Select isgood From "&bbstable&" where id="&id, conn,1,3  
			istops=rs("isgood")
				If istops=0 Then
					rs("isgood")=1
					Set rs_u= Server.CreateObject("ADODB.Recordset")
						sql_u="Select "&bbstable&".username as zuozhe,"&usertable&".username From "&bbstable&","&usertable&" where "&usertable&".username="&bbstable&".username and "&bbstable&".id="&id
						rs_u.Open sql_u,conn,3,3
						if not rs_u.eof Then 
							username=rs_u("zuozhe")
							conn.execute("update ["&usertable&"] set [umoney]=umoney+"&good_money&" where [username]='"&username&"'")
							qian=","&username&" 获得积分"&good_money&"分"
						End If 
						rs_u.close
					set rs_u=Nothing
					shuoming="设置精华"
					accFromUser = "系统" 'Add For V1.5 CHANG, ZIDONE '积分管理使用
					accToUser = OptTable("select [username] from "&bbstable&" where id="&id) 'Add For V1.5 
					accReason = "设精" 'Add For V1.5 
				Else
					rs("isgood")=0
					Set rs_u= Server.CreateObject("ADODB.Recordset")
						sql_u="Select "&bbstable&".username as zuozhe,"&usertable&".username From "&bbstable&","&usertable&" where "&usertable&".username="&bbstable&".username and "&bbstable&".id="&id
						rs_u.Open sql_u,conn,3,3
						if not rs_u.eof Then 
							username=rs_u("zuozhe")
							conn.execute("update ["&usertable&"] set [umoney]=umoney-"&good_money&" where [username]='"&username&"'")
							qian=","&username&" 减去积分"&good_money&"分"
						End If 
						rs_u.close
					set rs_u=Nothing
					shuoming="取消精华"
					accFromUser = OptTable("select [username] from "&bbstable&" where id="&id) 'Add For V1.5
					accToUser = "系统" 'Add For V1.5 CHANG, ZIDONE '积分管理使用
					accReason = "消精" 'Add For V1.5 CHANG, ZIDONE '积分管理使用
				End If 
			rs.update
			rs.close
		set rs=nothing
		set rs=nothing
	' Add For V1.5 CHANG, ZIDONE '''''''''''''Begin
	' 精华/取消精华成功后,给[ACCOUNT]表中插入积分记录
	OptTable("insert into [account] (accID,accValue,accFromUser,accToUser,accTime,accReason,accRemark) values("&CStr(GetMaxID("account","accid"))&","&CStr(good_money)&",'"&accFromUser&"','"&accToUser&"','"&CStr(Now())&"','"&accReason&"','')")
	''''''''''''''''''''''''''''''''''''''''''End
	response.write backmsg("恭喜您！帖子"&shuoming&"成功"&qian,comurl)
End Sub 
'----------------------添加帖子----------------------------------
Sub addsave()

If ISdate(Session("posttime")) Then
    If DateDiff("s",Session("posttime"),Now) < posttime Then
        Response.Write("<script>alert(""对不起，您灌水速度太快...请稍后再灌"");window.history.back();</script>")
        Response.End
    End If
End If
ip1=split(ip,".")
ip2= ip1(0)&"."&ip1(1)&"."&ip1(2)&".*"
if username="" then username=ip2
	'------------判断验证码---------------
	if Dreamsun_name="" then
		zd_code=trim(request.form("zd_code"))
		If (ycid="" and cstr(Session("GetCode_yc"))<>cstr(zd_code)) Or _
		(ycid<>"" And cstr(Session("GetCode_re"))<>cstr(zd_code)) then
			Response.Write(backmsg("请输入正确的验证码！",""))
		end if
	end If
	
	'Edit At 2007-11-11 CHANG,ZIDONE
	Dim addInfo,addErr
	addErr = 0
	addInfo = ""
	If ycid="" And BoardId = "" Then 
		addErr = addErr + 1
		addInfo = addInfo & "- 请选择贴吧名\n"
	End If
	If Len(title)>100 Then 
		addErr = addErr + 1
		addInfo = addInfo & "- 标题不能超过100个字符\n"
	End If
	If Len(title)<4 Then 
		addErr = addErr + 1
		addInfo = addInfo & "- 标题不能少于四个字节\n"
	End If
	If Len(content)>20000 Then 
		addErr = addErr + 1
		addInfo = addInfo & "- 内容不能超过20000个字符\n"
	End If
	If Len(content)<10 Then 
		addErr = addErr + 1
		addInfo = addInfo & "- 内容不能少于10个字节\n"
	End If
	If addErr>0 Then
		addInfo = "常网信息网提醒: 请注意以下"&CStr(addErr)&"个提示:\n\n" & addInfo
		Response.Write backmsg(addInfo,"")
	End If	
	'------------判断脏话---------------
	'Add For V1.5 检查是否广告帖
	If IsAdTopic(content) = True Or IsAdTopic(title) = True Then
		Response.Write backMsg("发现疑似广告内容,请检查后再发","")
	End If
	'Add For V1.5 格式化看帖所需要花费的积分
	if Dreamsun_name <>"" then
		If Not IsNumeric(fee) Then
			fee = 0
		Else
			fee = CInt(fee)
			MaxAccount = CInt(OptTable("select [umoney] from "&usertable&" where [username]='"&Dreamsun_name&"'"))
			If fee<0 Then fee = 0
			If fee>MaxAccount Then fee = MaxAccount
		End If
	end if 
	
	'去掉验证码Session
	Session("GetCode_yc") = ""
	Session("GetCode_re") = ""
	
	if ycid="" then 
		'------把新信息写进数据库-------------
		if Dreamsun_name="" And guestadd=0 Then	Response.Write backmsg("登录信息丢失，请重新登录！","")
		Set rs= Server.CreateObject("ADODB.Recordset")
		sql="select * from "&bbstable&""
		rs.open sql,conn,3,2
		rs.addnew
		rs("title")=title
		rs("content")=content
		rs("username")=username
		rs("BoardID")=BoardID
		rs("ip")=ip
		rs("rename")=username
		rs("IsCheck")=isCheck
		rs("retime")=now()
		If ispicurl=1 Then rs("picurl")=picurl
		If titlecolor<>"" Then rs("titlecolor")=titlecolor
		If titlecolor="" Then
			rs("titleBold") = 0
		Else
			rs("titleBold") = titleBold
		End If 
		rs("IsRe") = isRe 'Add For V1.5
		rs("IsFee") = fee 'Add For V1.5		
		rs.update
		rs.close
		Session("posttime") = Now()
		If Dreamsun_name<>"" Then 
			OptTable("update ["&usertable&"] set [umoney]=[umoney]+"&add_money&" where [username]='"&Dreamsun_name&"'")
		'Add For V1.5 提醒用户发该帖要扣掉的积分
		If fee>0 then
			OptTable("update ["&usertable&"] set [umoney]=[umoney]-"&fee&" where [username]='"&Dreamsun_name&"'")
			OptTable("insert into [account] (accID,accValue,accFromUser,accToUser,accTime,accReason,accRemark) values("&CStr(GetMaxID("account","accid"))&","&CStr(fee)&",'"&Dreamsun_name&"','"&"系统"&"','"&CStr(Now())&"','积分帖','')")
			feeAlert = ",扣掉读帖积分"&CStr(fee)&"分"
		End if
		'判断是否默认不审核
		if IsCheck=0 Then checkAlert = "，您的帖子可能需要经过审核后才能公布"
		qian=",您获得发帖积分"&add_money&"分"&feeAlert&checkAlert
		End If 
		' Add For V1.5 CHANG, ZIDONE '''''''''''''Begin
		' 发表成功后,给[ACCOUNT]表中插入积分记录
		OptTable("insert into [account] (accID,accValue,accFromUser,accToUser,accTime,accReason,accRemark) values("&CStr(GetMaxID("account","accid"))&","&CStr(add_money)&",'"&"系统"&"','"&username&"','"&CStr(Now())&"','发帖','')")
		''''''''''''''''''''''''''''''''''''''''''End
		response.write backmsg("恭喜您！帖子发表成功"&qian,comurl)
'------把回复信息写进数据库-------------
	Else
		if Dreamsun_name="" And guestrev=0 Then
			Response.Write(backmsg("登录信息丢失，请重新登录！"))
			Response.End()
		End If
'------1,读取出主题帖子的相关信息-------------
		Set rs1= Server.CreateObject("ADODB.Recordset")
		rs1.Open "Select * From "&bbstable&" where id="&ycid, conn,3,3  
		recount=rs1("recount")
		isRe=rs1("IsRe") '是否允许回复 Add For V1.5
		If CInt(IsRe)=0 And isadmin<>9 Then response.write backmsg("该主题已被关闭回复","")
		rs1("recount")=recount+1 
		rs1("rename")=username
		rs1("retime")=now()
		lou=rs1("lou")'纪录当前主题的最高楼层
			if lou="" Then lou=0
		nowlou=lou+1 
		rs1("lou")=nowlou
		rs1.update
		rs1.close
'------把回复信息写进数据库-------------
		Set rs= Server.CreateObject("ADODB.Recordset")
		sql="select * from "&rebbstable&""
		rs.open sql,conn,3,2
		rs.addnew
		rs("re")=ycid
		rs("title")=title
		rs("content")=content
		rs("lou")=nowlou'当前楼层
		rs("username")=username
		rs("IsCheck")=isCheck
		rs("ip")=ip
		rs.update
		rs.close
		Session("posttime") = Now()
		'判断是否默认不审核
		if IsCheck=0 Then checkAlert = "，您的帖子可能需要经过审核后才能公布"
		If Dreamsun_name<>"" Then 
			conn.execute("update ["&usertable&"] set [umoney]=[umoney]+"&re_money&" where [username]='"&Dreamsun_name&"'")
			qian=",您获得积分"&re_money&"分"
			' Add For V1.5 CHANG, ZIDONE '''''''''''''Begin
			' 回复成功后,给[ACCOUNT]表中插入积分记录
			OptTable("insert into [account] (accID,accValue,accFromUser,accToUser,accTime,accReason,accRemark) values("&CStr(GetMaxID("account","accid"))&","&CStr(re_money)&",'"&"系统"&"','"&Dreamsun_name&"','"&CStr(Now())&"','回帖','')")
		End If 
		response.write backmsg("恭喜您！帖子回复成功"&qian&checkAlert,comurl)
	End If
End Sub 
'----------------------定义编辑帖子----------------------------------
Sub editsave()
	If tn="bbs" Then
		Set rs= Server.CreateObject("ADODB.Recordset")
			rs.Open "Select * From "&bbstable&" where id="&ycid, conn,3,3  
			rs("re")=request.form("re")
			rs("title")=title
			rs("content")=content
			rs("boardid")=boardid
			rs("lou")=request.form("lou")
			rs("istop")=request.form("istop")
			rs("username")=request.form("username")
			rs("recount")=recount
			rs("hits")=request.form("hits")
			rs("titlecolor")=titlecolor
			rs("titleBold") = titleBold
			If ispicurl=1 Then rs("picurl")=picurl
			rs("IsRe") = isRe '是否允许回复 Add For V1.5
			'rs("IsFee")= rs("IsFee") '看帖需要花费的积分
			rs.update
			rs.close
		set rs=Nothing
	ElseIf tn="rebbs" Then
		Set rs= Server.CreateObject("ADODB.Recordset")
			rs.Open "Select * From "&rebbstable&" where id="&ycid, conn,3,3  
			rs("re")=request.form("re")
			rs("title")=title
			rs("content")=content
			rs("lou")=request.form("lou")
			rs("username")=request.form("username")
			rs.update
			rs.close
		set rs=Nothing
	End If
	comurl=request.form("comurl")
	response.write backmsg("恭喜您！帖子编辑成功",comurl)
End Sub
'----------------------定义 用户自己编辑自己的帖子----------------------------------
Sub ueditsave()
wei="[ALIGN=right][color=#939598]该帖子被"&Dreamsun_name&"在"&Now()&"编辑过[/color][/ALIGN]"
If tn="bbs" Then
		Set rs= Server.CreateObject("ADODB.Recordset")
			rs.Open "Select * From "&bbstable&" where id="&ycid, conn,3,3
			boardid=rs("boardid")
			If rs("username")<>Dreamsun_name Then
			Call checkbanzhu
			End If 
			rs("title")=title
			rs("content")=content&wei
			If ispicurl=1 Then rs("picurl")=picurl
			rs.update
			rs.close
		set rs=Nothing
	ElseIf tn="rebbs" Then
		Set rs= Server.CreateObject("ADODB.Recordset")
			rs.Open "Select * From "&rebbstable&" where id="&ycid, conn,3,3
			re=rs("re")
sql_bzhu="Select boardid from "&bbstable&" where id="&re&""
rss=conn.execute(sql_bzhu)
boardid=rss(0)
			If rs("username")<>Dreamsun_name Then
			Call checkbanzhu
			End If 
			rs("title")=title
			rs("content")=content&wei
			rs.update
			rs.close
	End If
	set rs=Nothing
	comurl=request.form("comurl")
	response.write backmsg("恭喜您！帖子编辑成功",comurl)
End Sub 
'----------------------审核帖子操作----------------------------------
'Add For V1.5 CHANG,ZIDONE
Sub checkstatus()
		Set rs= Server.CreateObject("ADODB.Recordset")
			rs.Open "Select IsCheck From "&bbstable&" where [id]="&id, conn,1,3  
			ischecks=rs("IsCheck")
				If ischecks=0 Then
					rs("IsCheck")=1
					shuoming="审核"
				Else
					rs("IsCheck")=0
					shuoming="屏蔽"
				End If
			rs.update
			rs.close
	response.write backmsg("恭喜您！帖子"&shuoming&"成功",comurl)
End Sub 
'其实是调用那个什么玩意儿conn.close
 Call foot()
%>
