<%@ LANGUAGE="VBSCRIPT" %>
<!--#include file="../conn/zkconn.asp"-->
<!-- #include file="bbsinc/const.asp" -->
<!--#include file="bbsinc/char.asp"-->
<title><%=ForumName%>--管理页面</title>
<link rel="stylesheet" type="text/css" href="../css/css.css">

<BODY topmargin="20">
<!--#include file="chkmanage.asp"-->
<%
	if founderr=true then
		call Error()
	else
	set rs=server.createobject("adodb.recordset")
	if request("action")="lock" then
		call lock()
	elseif request("action")="unlock" then
		call unlock()
	elseif request("action")="delete" then
		call delete()
	elseif request("action")="move" then
		call move()
	elseif request("action")="copy" then
		call copy()
	elseif request("action")="istop" then
		call istop()
	elseif request("action")="notop" then
		call notop()
	elseif request("action")="dele" then
		call dele()
	elseif request("action")="isbest" then
		call isbest()
	elseif request("action")="nobest" then
		call nobest()
	elseif request("action")="ztop" then
		call ztop()
	elseif request("action")="noztop" then
		call noztop()
	else
		founderr=true
		Errmsg=Errmsg+"<br>"+"<li>请选择相应操作。"
	end if
	if founderr=true then
		call error()
	end if
	set rs=nothing
	conn.close
	set conn=nothing
	sub lock()
	sql="update bbs_content set locktopic=1 where boardid="&boardid&" and rootid="&cstr(rootid)
	conn.Execute(sql)
	call success()
	end sub

	sub unlock()
	sql="update bbs_content set locktopic=0 where boardid="&boardid&" and rootid="&cstr(rootid)
	conn.Execute(sql)
	call success()
	end sub

	sub istop()
	sql="update bbs_content set istop=1 where boardid="&boardid&" and rootid="&cstr(rootid)
	conn.Execute(sql)
	call success()
	end sub
	sub notop()
	sql="update bbs_content set istop=0 where boardid="&boardid&" and rootid="&cstr(rootid)
	conn.Execute(sql)
	call success()
	end sub

	sub isbest()
	sql="update bbs_content set isbest=1 where boardid="&boardid&" and announceid="&cstr(id)
	conn.Execute(sql)
	call success()
	end sub
	sub nobest()
	sql="update bbs_content set isbest=0 where boardid="&boardid&" and announceid="&cstr(id)
	conn.Execute(sql)
	call success()
	end sub

	sub ztop()
	sql="update bbs_content set ztop=1 where boardid="&boardid&" and announceid="&cstr(id)
	conn.Execute(sql)
	call success()
	end sub
	sub noztop()
	sql="update bbs_content set ztop=0 where boardid="&boardid&" and announceid="&cstr(id)
	conn.Execute(sql)
	call success()
	end sub

	sub dele()
	dim NewAnnounceNum,lastpostime
	dim userpoint
	sql="select username from bbs_content where announceid="&cstr(rootid)
	set rs=conn.execute(sql)
	userpoint=rs(0)
	conn.execute("update [huiyuan] set article=article-1,jifen=jifen-10 where huiyuan='"&trim(userpoint)&"'")
	sql="delete from bbs_content where boardid="&boardid&" and ParentID<>0 and announceid="&cstr(id) 
	conn.Execute(sql)
	if Cint(id)<>Cint(rootid) then
	sql="select count(announceid) from bbs_content where boardid="&boardid
	set rs=conn.Execute(sql)
	NewAnnounceNum=rs(0)
	sql="select Max(announceid) from bbs_content where rootid="&rootid&" and boardid="&boardid
	set rs=conn.Execute(sql)
	LastPostime=rs(0)
	sql="update bbs_board set lastbbsnum="&NewAnnounceNum&" where boardid="&boardid
	conn.execute(sql)
	sql="update bbs_content set times="&LastPostime&" where rootid="&rootid&" and boardid="&boardid
	conn.execute(sql)
	sql="update bbs_content set child=child-1 where announceid="&rootid&" and boardid="&boardid
	conn.execute(sql)
	rs.close
	end if
	call success()
	end sub

	sub delete()
	dim NewAnnounceNum,NewTopicNum
	dim userpoint
	sql="select username from bbs_content where boardid="&boardid&" and rootid="&rootid
	set rs=conn.execute(sql)
	do while not rs.eof
	userpoint=rs(0)
	conn.execute("update [huiyuan] set article=article-1,jifen=jifen-10 where huiyuan='"&trim(userpoint)&"'")
	userpoint=""
	rs.movenext
	loop
	sql="delete from bbs_content where boardid="&boardid&" and rootid="&cstr(rootid)
	conn.Execute(sql)
	sql="select count(announceid) from bbs_content where boardid="&boardid
	set rs=conn.Execute(sql)
	NewAnnounceNum=rs(0)
	sql="select count(announceid) from bbs_content where ParentID=0 and boardid="&boardid
	set rs=conn.Execute(sql)
	NewTopicNum=rs(0)
	sql="update bbs_board set lastbbsnum="&NewAnnounceNum&",lasttopicnum="&NewTopicNum&" where boardid="&boardid
	conn.execute(sql)
	call success()
	end sub

	sub move()
	dim newboardid
	if request("checked")="yes" then
		if request("boardid")=request("newboardid") then
		founderr=true
		Errmsg=Errmsg+"<br>"+"<li>不能在相同版面内进行转移操作。"
		elseif not isInteger(request("newboardid")) then
			founderr=true
			Errmsg=Errmsg+"<br>"+"<li>非法的版面参数。"
			exit sub
		else
			newboardid=request("newboardid")
			sql="select boardid,announceid,Parentid from bbs_content where announceid="&id&" and boardid="&cstr(boardid)
			rs.open sql,conn,1,1
			if rs.eof and rs.bof then
				founderr=true
				Errmsg=Errmsg+"<br>"+"<li>您选择的贴子并不存在。"
			else
				if rs("Parentid")<>0 then
				founderr=true
				Errmsg=Errmsg+"<br>"+"<li>您必须选择一个主题，而不是贴子。"
				end if
			end if
			rs.close
		end if
		if founderr=false then
			if request("leavemessage")="yes" then
				'ON ERROR RESUME NEXT

			elseif request("leavemessage")="no" then
				dim newtopic
				sql="select topic from bbs_content where announceid="&rootid
				set rs=conn.execute(sql)
				newtopic=rs("topic") & "-->" & membername & "转移"
				sql="update bbs_content set topic='"&newtopic&"' where announceid="&rootid
				conn.execute(sql)
				sql="update bbs_content set boardid="&newboardid&" where rootid="&rootid
				conn.Execute(sql)
'更新论坛贴子数据
	dim NewAnnounceNum,NewTopicNum
	sql="select count(announceid) from bbs_content where boardid="&boardid
	set rs=conn.Execute(sql)
	NewAnnounceNum=rs(0)
	sql="select count(announceid) from bbs_content where ParentID=0 and boardid="&boardid
	set rs=conn.Execute(sql)
	NewTopicNum=rs(0)
	sql="update bbs_board set lastbbsnum="&NewAnnounceNum&",lasttopicnum="&NewTopicNum&" where boardid="&boardid
	conn.execute(sql)
	dim MoveAnnounceNum,MoveTopicNum
	sql="select count(announceid) from bbs_content where boardid="&newboardid
	set rs=conn.Execute(sql)
	MoveAnnounceNum=rs(0)
	sql="select count(announceid) from bbs_content where ParentID=0 and boardid="&newboardid
	set rs=conn.Execute(sql)
	MoveTopicNum=rs(0)
	sql="update bbs_board set lastbbsnum="&MoveAnnounceNum&",lasttopicnum="&MoveTopicNum&" where boardid="&newboardid
	conn.execute(sql)
'更新论坛数据结束
				call success()
			else
				founderr=true
				Errmsg=Errmsg+"<br>"+"<li>请选择相应操作。"
			end if
		end if
	else
%>
            <table cellpadding=0 cellspacing=0 border=0 762 bgcolor=#efefef align=center>
                <tr>
                    <td>
                    <table cellpadding=6 cellspacing=1 border=0 width=100%>
                        <tr>
                        <td bgcolor=#ffffff valign=middle align=center colspan=2>
                        <form action="admin_postings.asp" method="post">
                        <input type=hidden name="action" value="move">
                        <input type=hidden name="checked" value="yes">
                        <input type=hidden name="boardid" value="<%=request("boardid")%>">
                        <input type=hidden name="rootid" value="<%=request("rootid")%>">
                        <input type=hidden name="id" value="<%=request("id")%>">
                        <b>移动主题</b></td></tr>

                                    <tr>
                                    <td bgcolor=#ffffff valign=middle>
                                    <b>移动选项</td>
                                    <td bgcolor=#ffffff valign=middle>
                                    <!--<input name="leavemessage" type="radio" value="yes"> 移动并保留一个已经锁定的主题在原论坛<br>--><input name="leavemessage" type="radio" value="no" checked> 移动并将此主题从原论坛中删除
                                    </td>
                                    </tr>

                            <tr>
                        <td bgcolor=#ffffff valign=top><b>移动到：</b></td>
                        <td bgcolor=#ffffff valign=top>
<%
   sql="select boardid,boardtype from bbs_board"
   rs.open sql,conn,1,1
%>
<select name="newboardid" size="1">
<option value="">选择一个论坛</option>
<%
	do while not rs.eof
        response.write "<option value='"+CStr(rs("BoardID"))+"'>"+rs("Boardtype")+"</option>"+chr(13)+chr(10)
	rs.movenext
	loop
	rs.close
%>        
          </select>
			</td>
                        </tr>
                    <tr>
                <td bgcolor=#ffffff valign=middle colspan=2 align=center><input type=submit name="submit" value="提 交"></td></tr></form></table></td></tr></table>
            </table>
            </td></tr>
            </table>
<%
	end if
	end sub

	sub copy()
	dim newboardid
	if request("checked")="yes" then
		if request("boardid")=request("newboardid") then
		founderr=true
		Errmsg=Errmsg+"<br>"+"<li>不能在相同版面内进行转移操作。"
		elseif not isInteger(request("newboardid")) then
			founderr=true
			Errmsg=Errmsg+"<br>"+"<li>非法的版面参数。"
			exit sub
		else
			newboardid=request("newboardid")
			sql="select boardid,announceid,Parentid from bbs_content where announceid="&id&" and boardid="&cstr(boardid)
			rs.open sql,conn,1,1
			if rs.eof and rs.bof then
				founderr=true
				Errmsg=Errmsg+"<br>"+"<li>您选择的贴子并不存在。"
			end if
			rs.close
		end if
		if founderr=false then
			'ON ERROR RESUME NEXT
			dim newtopic,username,body,dateandtime,length,ip,Expression
			dim announceid
			sql="select * from bbs_content where announceid="&id
			set rs=conn.execute(sql)
			newtopic=rs("topic") & "-->" & membername & "添加"
			username=rs("username")
			body=rs("body")
			DateAndTime=rs("DateAndTime")
			length=rs("length")
			ip=rs("ip")
			Expression=rs("Expression")
			rs.close
			sql="select * from bbs_content"
			rs.open sql,conn,1,3
	     		rs.AddNew
			rs("BoardID")=newboardID
	     		rs("ParentID")=0
         		rs("Child")=0
	     		rs("UserName")=UserName
	     		rs("Topic")=newTopic
	     		rs("Body")=Body
	     		rs("DateAndTime")=DateAndTime
	     		rs("hits")=0
	     		rs("length")=length
	     		rs("rootID")=0
	     		rs("layer")=1
	     		rs("orders")=0
         		rs("ip")=ip
         		rs("Expression")=Expression
         		rs("locktopic")=0
         		rs("signflag")=0
         		rs("emailflag")=0
	     		rs.Update
			rs.MoveLast
         		announceid=rs("AnnounceID")
         		rs("RootID")= announceid
	     		rs("Times")= announceid
	     		rs.Update
 	    		rs.close

'更新论坛贴子数据
	sql="update bbs_board set lastbbsnum=lastbbsnum+1,lasttopicnum=lasttopicnum+1,lastpostuser='"&username&"',lastposttime='"&DateAndTime&"' where boardid="&newboardid
	conn.execute(sql)
'更新论坛数据结束
			call success()
		end if
	else
%>
            <table cellpadding=0 cellspacing=0 border=0 width=95% bgcolor=#ffffff align=center>
                <tr>
                    <td>
                    <table cellpadding=6 cellspacing=1 border=0 width=100%>
                        <tr>
                        <td bgcolor=#ffffff valign=middle align=center colspan=2>
                        <form action="admin_postings.asp" method="post">
                        <input type=hidden name="action" value="copy">
                        <input type=hidden name="checked" value="yes">
                        <input type=hidden name="boardid" value="<%=request("boardid")%>">
                        <input type=hidden name="rootid" value="<%=request("rootid")%>">
                        <input type=hidden name="id" value="<%=request("id")%>">
                        <b>复制贴子</b></td></tr>

                                    <tr>
                                    <td bgcolor=#ffffff valign=middle>
                                    <b>操作说明</td>
                                    <td bgcolor=#ffffff valign=middle>
贴子将复制到别的论坛，成为新的贴子，并保留在原来论坛
                                    </td>
                                    </tr>
                            <tr>
                        <td bgcolor=#ffffff valign=top><b>移动到：</b></td>
                        <td bgcolor=#ffffff valign=top>
<%
   sql="select boardid,boardtype from bbs_board"
   rs.open sql,conn,1,1
%>
<select name="newboardid" size="1">
<option value="">选择一个论坛</option>
<%
	do while not rs.eof
        response.write "<option value='"+CStr(rs("BoardID"))+"'>"+rs("Boardtype")+"</option>"+chr(13)+chr(10)
	rs.movenext
	loop
	rs.close
%>        
          </select>
			</td>
                        </tr>
                    <tr>
                <td bgcolor=#ffffff valign=middle colspan=2 align=center><input type=submit name="submit" value="提 交"></td></tr></form></table></td></tr></table>
            </table>
            </td></tr>
            </table>
<%
	end if
	end sub

sub success()
%>
    <table cellpadding=0 cellspacing=0 border=0 width=95% bgcolor=#efefef align=center>
        <tr>
            <td>
                <table cellpadding=3 cellspacing=1 border=0 width=100%>
    <tr align="center"> 
      <td width="100%" bgcolor=#ffffff>成功：贴子操作</td>
    </tr>
    <tr> 
      <td width="100%" bgcolor=#ffffff><li><b>贴子操作成功</b><br>
      </td>
    </tr>
    <tr align="center"> 
      <td width="100%" bgcolor=#ffffff>
<a href="list.asp?boardid=<%=request("boardid")%>"> << 返回论坛</a>
      </td>
    </tr>  
</table></td></tr></table>
<%
end sub
end if
%>
</body>