<!--#include file="conn.asp"-->
<%
if not theUser.master then
	connclose()
	response.redirect ("index.asp")
end if


dim id,act
dim exec, rs

set id=request.form("id")
act=encodestr(request.form("act"))

main()
connclose()
response.redirect "admin_ok.asp"


sub main()
	select case act
		case "del"		'删留言
			for i=1 to id.count
				delete(id(i))
			next
		case "best"	'设为精华
			for i=1 to id.count
				best(id(i))
			next
		case "top"		'固顶
			for i=1 to id.count
				top(id(i))
			next
		case "lock"	'锁定
			for i=1 to id.count
				lock(id(i))
			next
	end select
end sub

sub delete(xxid)
	dim rs1
	exec="select rt,jh,name,isPrivate from ly where id="& Cstr(xxid)
	set rs=conn.execute(exec)
	'本留言发表用户发留言数减
	exec="update [user] set GBpostNum=GBpostNum-1 where username='"& rs("name") &"'"
	conn.execute(exec)
	'是根留言计数减
	if rs(0)=0 then
		'悄悄话计数减
		if rs("isPrivate") then
			exec="update [user] set GBprivateNum=GBprivateNum-1 where username='"& rs("name") &"' "
			conn.execute(exec)
			exec="update GBconst set privateNum=privateNum-1"
			conn.execute(exec)
		end if
		
		exec="update GBconst set topicNum=topicNum-1"
		conn.execute(exec)
		'跟帖用户发表数减
		exec="select name from ly where bl=1 and rt="& Cstr(xxid)
		set rs1=conn.execute(exec)
		do until rs1.eof
			exec="update [user] set GBpostNum=GBpostNum-1 where username='"& rs1("name") &"'"
			conn.execute(exec)
			rs1.movenext
		loop
		rs1.close
		'是精华的跟帖数减
		exec="select count(*) from ly where jh=1 and rt="& Cstr(xxid)
		set rs1=conn.execute(exec)
		if rs1(0)>0 then
			exec="update GBconst set bestNum=bestNum-"& rs1(0)
			conn.execute(exec)
		end if
		rs1.close
		set rs1=nothing
		'删除跟帖
		exec="delete from ly where rt="& Cstr(xxid)
		conn.execute(exec)
	else
		'最后回复ID改变
		exec="select top 1 id from ly where rt="& rs(0) &" and id<>"& Cstr(xxid) &" order by id desc"
		set rs1=conn.execute(exec)
		if not (rs1.eof and rs1.bof) then
			exec="update ly set reid="& rs1(0) &" where id="& rs(0)
		else
			exec="update ly set reid=id where id="& rs(0)
		end if
		conn.execute(exec)
		rs1.close
		set rs1=nothing
		
		exec="update ly set hf=hf-1 where id="& rs(0)
		conn.execute(exec)
	end if
	'是精华计数减
	if rs(1)=1 then
		exec="update GBconst set bestNum=bestNum-1"
		conn.execute(exec)
	end if
	rsclose()
	exec="delete from ly where id=" + CStr(xxid)
	conn.execute(exec)
end sub

sub best(xxid)
 	exec="select jh,isPrivate from ly where id="& Cstr(xxid)
	set rs=conn.execute(exec)
	if rs(1) then
		session("error")="悄悄话不可以设为精华！"
		rsclose()
		connclose()
		response.redirect "error.asp"
	end if
	
	if rs(0)=1 then
		exec="update ly set jh=0 where id=" + CStr(xxid)
		conn.execute(exec)
		exec="update GBconst set bestNum=bestNum-1"
		conn.execute(exec)
	else
		exec="update ly set jh=1 where id=" + CStr(xxid)
		conn.execute(exec)
		exec="update GBconst set bestNum=bestNum+1"
		conn.execute(exec)
	end if
end sub

sub top(xxid)
 	exec="select istop from ly where id="& Cstr(xxid)
	set rs=conn.execute(exec)
	if rs(0)=1 then
		exec="update ly set istop=0 where id=" + CStr(xxid)
		conn.execute(exec)
	else
		exec="update ly set istop=1 where id=" + CStr(xxid)
		conn.execute(exec)
	end if
end sub

sub lock(xxid)
 	exec="select islock from ly where id="& Cstr(xxid)
	set rs=conn.execute(exec)
	if rs(0) then
		exec="update ly set islock=0 where id=" + CStr(xxid)
		conn.execute(exec)
	else
		exec="update ly set islock=1 where id=" + CStr(xxid)
		conn.execute(exec)
	end if
end sub
%>
