<!--#INCLUDE FILE="conn.asp" -->
<!--#include file="Class_Checkuser.asp" -->
<!--#INCLUDE FILE="Class_Top.asp" -->
<!--#include file="inc/char.asp" -->
<%
locat="论坛首页"
Dim TopicID,LinkID
boardid=request("boardid")
function ismaster()
 dim rsm,sqlm,master,ii
 set rsm=server.createobject("adodb.recordset")
 sqlm="select boardmaster from bbs where boardid="&boardid
 ii=0
 rsm.open sqlm,conn,1,1
    if rsm.bof and rsm.eof then
         ismaster=false
	 exit function
   else
          master=split(rsm(0),"$")                             
	  for ii=0 to ubound(master)           
	   if trim(membername)=trim(master(ii)) then
                   ismaster=true
                   exit function
		else                   
	    	   ismaster=false                                  
    		   
           end if
	 next
   end if  
  rsm.close
  set rsm=nothing  
 end function
if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=Class_Login.asp target=_blank><font color=red><B>登录</B></font></a>。"
	Call top(1,1)
	Call Error("Information",ErrMsg)
	
Else
	act="管理主题帖子"
	Select Case Request("Action")
	Case "Lock"
		Call top(4,1)
		Call mantopic()
	Case "Top"
		Call top(4,1)
		Call mantopic()
	Case "DeleteTopic"
		act="删除主题帖子"
		Call top(4,1)
		Call deletetopic()
	Case "DeleteReply"
		act="删除回复帖子"
		Call top(4,1)
		Call deletereply()
	Case "Edit"
		act="编辑帖子"
		Call top(4,1)
		Call editform()
	Case "Save"
		act="编辑帖子"
		Call top(4,1)
		Call savedit()
	Case "move"
	     act="移动帖子"
	    Call top(4,1)
		Call movetopic()
	End Select

End if

sub movetopic()
if not sysadmin and not ismaster() Then
		Errmsg=Errmsg+"<br>"+"<li>对不起，你没有操作权限！"
		Call Error("Exclamation",ErrMsg)
		exit sub
end if
if request("movenow")<>"" then
call movenow()
else
call movetemp()
end if
end sub
sub movenow()
	
dim boardid,sql,topicid,rs,replys
boardid=request("boardid")
topicid=request("topicid")
firstboardid=request("firstboardid")
set rs=server.createobject("adodb.recordset")
sql="select * from topic where postid="&clng(topicid)
rs.open sql,conn,1,1
if not(rs.bof and rs.eof) then
replys=rs("replys")
sql="update [bbs] set boardbbsnum=boardbbsnum-"&replys&"-1,topicnum=topicnum-1,postnum=postnum-"&replys&" where boardid="&rs("boardid")
conn.execute(sql)

sql="update bbs set boardbbsnum=boardbbsnum+"&replys&"+1,topicnum=topicnum+1,postnum=postnum+"&replys&" where boardid="&clng(boardid)
conn.execute(sql)

sql="update topic set boardid="&boardid&" where postid="&topicid
conn.execute(sql)

sql="update reply set boardid="&boardid&" where topicid="&topicid
conn.execute(sql)

end if
rs.close
set rs=nothing
response.write ("<script language=javascript>alert('移动贴子成功！');document.location.href='Bbs_ForumDisplay.asp?boardid="&firstboardid&"';</script>")

end sub
sub movetemp()
dim topicid,title,rs,sql,rs1,sql1,firstboardname,firstboardid,rs2,sql2
topicid=request("topicid")	
firstboardid=clng(request("boardid"))
if topicid="" then 
Errmsg=Errmsg+"<br>"+"<li>对不起，请指定的贴子主题！"
		Call Error("Exclamation",ErrMsg)
exit sub
else
set rs1=server.createobject("adodb.recordset")
sql1="select title from topic where postid="&clng(topicid)
rs1.open sql1,conn,1,1
if rs1.bof and rs1.eof Then
Errmsg=Errmsg+"<br>"+"<li>对不起，指定的贴子不存在！！"
		Call Error("Exclamation",ErrMsg)
exit sub
else
title=htmlencode(rs1(0))
rs1.close
set rs1=nothing
end if
end if
set rs2=server.createobject("adodb.recordset")
sql2="select boardname from bbs where boardid="&firstboardid
rs2.open sql2,conn,1,1
firstboardname=htmlencode(rs2(0))
rs2.close
set rs2=nothing

set rs=server.createobject("adodb.recordset")
sql="select * from bbs order by boardid desc "
rs.open sql,conn,1,1	
if rs.bof and rs.eof then
	 Errmsg=Errmsg+"<br>"+"<li>对不起，还没有任何版面！！"
		Call Error("Exclamation",ErrMsg)
exit sub
	end if
%>
<BR>
<form method="POST" action=Bbs_Admin_Post.asp name=boardform>
  <input type=hidden name=action value=move>
  <input type="hidden" name="movenow" value="movenow">
  <input type="hidden" name="topicid" value="<%=topicid%>">
    <input type="hidden" name="firstboardid" value="<%=firstboardid%>">
  <table width=90% cellspacing=1  cellpadding=3 align=center border="0" Class=TableBorder>
    <tr> 
      <th colspan=2>贴子移动</th>
    </tr>
    <tr  bgcolor=#ecf2fc> 
      <td width="23%" align="right"><font color="#000000">贴子主题：</font></td>
      <td width="77%"><%=title%>
      </td>
    </tr>
    <tr  bgcolor=#ecf2fc>
      <td align="right">原版面<font color="#000000">：</font></td>
      <td><%=firstboardname%></td>
    </tr>
    <tr  bgcolor=#ecf2fc> 
      <td width="23%" align="right"><font color="#000000">移动到：</font></td>
      <td width="77%"> 
        <select name="boardid" size="1">
          <%do while not rs.eof%>
          <option value=<%=rs("boardid")%>><%=rs("boardname")%></option>
          <%rs.movenext
  loop
  %>
        </select> 
      </td>
    </tr>
    <tr align="center"  bgcolor=#ecf2fc> 
      <td height="36" colspan="3" > 
        <input type="submit" name="submit" value="移 动"> 
      </td>
    </tr>
  </table>
</form>
<br>
<%
rs.close
set rs=nothing
end sub

Sub savedit()
 boardid=request("boardid")
	dim rs
	dim PostID
	
	if chktopic=False Then Exit Sub

	if Request("PostID")="" Then
		founderr=True
		Errmsg=Errmsg+"<br>"+"<li>请指定要编辑的贴子。"
	ElseIf not isInteger(Request("PostID")) Then
		founderr=True
		Errmsg=Errmsg+"<br>"+"<li>非法的贴子参数。"
	Else
		PostID=Clng(Request("PostID"))
	End if

	if founderr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

   	Set rs=conn.execute("select userid from reply where postID="&PostID&" and topicid="&TopicID)
	if rs.bof and rs.eof Then
		ErrMsg=ErrMsg+"<br>"+"<li>指定的贴子不存在！</li>"
		Call Error("Exclamation",ErrMsg)
	Else
		if not sysadmin and rs(0)<>membername and not ismaster() Then
			Errmsg=Errmsg+"<br>"+"<li>对不起，您无权对这个帖子进行编辑操作！"
			Call Error("Exclamation",ErrMsg)
		Else
			if chkpost=False Then
				ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从外部提交数据。"
				Call Error("Critical",ErrMsg)
				Exit Sub
			End if

			Topic=Checkstr(trim(Request("title")))

			if LinkID=PostID Then
				if Topic="" Then
					FoundErr=True
					ErrMsg=ErrMsg+"<Br>"+"<li>主题不应为空。"
				End if
			End if

			if strLength(topic)>100 Then
				FoundErr=True
			   	ErrMsg=ErrMsg+"<Br>"+"<li>主题长度不能超过100个字符!"
			End if

			Body=Checkstr(rtrim(Request.form("content")))

			if body="" Then
				ErrMsg=ErrMsg+"<Br>"+"<li>没有填写帖子内容。"
			   	FoundErr=True
			ElseIf strLength(body)>(IntVar(1)*1024) Then
			   	ErrMsg=ErrMsg+"<Br>"+"<li>帖子内容不得大于" & IntVar(1) & "KBytes"
			   	FoundErr=True
			End if

			if founderr Then
				Call Error("Information",ErrMsg)
				Exit Sub
			End if

			mood=cint(Request.form("mood"))

			EditTime=formatdatetime(now(),vbShortDate)&"&nbsp;"&formatdatetime(now(),vbShortTime)
			if  sysadmin Then 
				if BoolVar(9) then
					char_changed = "[align=right][此贴子已被管理员于"&EditTime&"编辑过][/align]"
				else
				char_changed = "[align=right][此贴子已被"&membername&"于"&EditTime&"编辑过][/align]"
			end if
			Else
			if ismaster() then
					char_changed = "[align=right][此贴子已被版主于"&EditTime&"编辑过][/align]"
					
				else
				char_changed = "[align=right][此贴子已被作者于"&EditTime&"编辑过][/align]"
			End if
			end if
			Body=body+vbCrLf+vbCrLf+char_changed

			if LinkID=PostID then
				sql="update topic set title='"&topic&"' where postid="&TopicID
				conn.execute(sql)
				if mood=0 then mood=1
			end if

			sql="update reply set title='"&topic&"',mood="&mood&",body='"&body&"' where postid="&PostID
			conn.execute(sql)

			conn.execute("update student Set point=point+"&PointSet(17)&" where userid='"&membername&"'")

			rURL="Bbs_ViewThread.asp?boardid="&boardid&"&TopicID="&TopicID&"&Page="&Cint(request("Page"))&"#PID"&PostID
			rtitle="编辑帖子成功"
			rmsg="本页面将在3秒后自动返回您所编辑的帖子页面，<b>您可以选择以下操作：</b><br><ul>"&_
					"<li><a href=Bbs_index.asp>返回校园论坛</a></li>"&_
					"<li><a href="""&rURL&""">您所编辑的帖子</a></li>"&_
					"</ul>"
			Redirect 3,rurl,rtitle,rmsg
		End if

	End if
	Set rs=Nothing

End Sub


Sub editform()
if request("boardid")="" then
  response.write "<script language=javascript>alert('请确认您是否从有效路径进入本站');history.go(-1);</script>"
  response.end
else
boardid=request("boardid")
end if
	dim rs
	dim PostID
	if chktopic=False Then Exit Sub

	if Request("PostID")="" Then
		founderr=True
		Errmsg=Errmsg+"<br>"+"<li>请指定要编辑的贴子。"
	ElseIf not isInteger(Request("PostID")) Then
		founderr=True
		Errmsg=Errmsg+"<br>"+"<li>非法的贴子参数。"
	Else
		PostID=Clng(Request("PostID"))
	End if

	if founderr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

   	Set rs=conn.execute("select title,body,mood from reply where postID="&PostID&" and topicid="&TopicID)
	if rs.bof and rs.eof Then
		ErrMsg=ErrMsg+"<br>"+"<li>指定的贴子不存在！</li>"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

if Request("Mode")="Advanced" Then
	advmode=True
ElseIf Request("Mode")="Typical" Then
	advmode=False
Else
	advmode=BoolVar(3)
End if

Page=Cint(request("Page"))
%>

<BR><BR>
<form action="Bbs_Admin_Post.asp?boardid=<%=boardid%>" method="POST" onSubmit="submitonce(this)" name="frmgbk">
<input type=hidden name=Action value="Save">
<input type=hidden name=TopicID value="<%=TopicID%>">
<input type=hidden name=PostID value="<%=PostID%>">
<input type=hidden name=Page value="<%=Page%>">
<div align="center"><center>
<table Class=TableBorder cellpadding=0 cellspacing=0 border=0 width=100% cellspacing="0">
    <tr>
      <td width="100%">
<table cellpadding=5 cellspacing=1 border=0 width=100%>
    <tr>
      <th width="100%" colspan=2>编辑帖子&nbsp;
	  <%response.write "<A HREF=""?boardid="&boardid&"&Action=Edit&TopicID="&TopicID&"&PostID="&PostID&"&Page="&Page
	  if advmode=False Then
	  response.write "&Mode=Advanced"&""" title=""当前为简洁模式，按此切换到高级发贴模式"">[高级模式]</A>"
	  Else
	  response.write "&Mode=Typical"&""" title=""当前为高级模式，按此切换到简洁发贴模式"">[简洁模式]</A>"
	  End if
	  %></th>
    </tr>
        <tr Class=LightTableBody>
          <td width="22%">作者：
	  </td>
		            <td width="78%">&nbsp;<%=htmlencode(membername)%></font>
	 </td>
        </tr>
        <tr Class=LightTableBody>
          <td width="22%">帖子标题：
              	  </td>
		            <td width="78%">&nbsp;
                <input name="title" size=70 maxlength=100 class=FormClass value="<%=rs(0)%>">
                &nbsp;&nbsp;<font color=red><%if LinkID=PostID Then%><strong>*</strong><%End if%></font>不超过50个汉字</font>
	 </td>
        </tr>

        <tr Class=LightTableBody>
          <td width="22%" valign="middle">发贴心情：</font></td>
          <td width="78%">
<table border=0 width=100%><tr><td>
			  <%for i=1 to 36%>
	<input type="radio" value="<%=i%>" name="mood" <%if i=rs(2) Then Response.Write "checked"%>><img src="images/mood/<%=i%>.gif" WIDTH="20" HEIGHT="20">
<%if i=12 or i=24 Then Response.Write "<br>" 
next%>
    </td>
                  </tr></table>
 </td>
        </tr>

            <tr Class=LightTableBody>
              <td>&nbsp;帖子内容：<BR>&nbsp;<a href=javascript:checklength()>[检测帖子长度]</a><BR><br><li>HTML标签：<font color=brown>OFF</font><BR><li>UBB标签：<%if BoolVar(4)=True Then Response.Write "<font color=#003399>ON" Else Response.Write "<font color=brown>OFF"%></font><BR><li>最大长度：<font color=brown><%=IntVar(1)%>KB</font><BR><BR>
			  <a href="javascript:openScript('Class_Help.asp?about=ubb',670,500)"  style="cursor:help"><IMG SRC="images/help.gif" WIDTH="42" HEIGHT="17" BORDER=0 ALT="查看UBB代码使用说明"></a>
              </td>
              <td><table border=0>
                  <%if advmode=True Then%>
                  <!--#INCLUDE FILE="inc/ubbtools.asp" -->
                  <%End if%>
                  <tr>
                    <td>&nbsp; <textarea onkeydown=ctlent() name="content" rows="10" cols="100" title="Ctrl+Enter直接提交修改的帖子"  wrap="soft" ><%=rs(1)%></textarea></td>
                    <td>&nbsp;<font color=red>*</font></td>
                  </tr>
                  <tr>
                    <td><div align="center"><script language="JavaScript">
				function insertsmilie(smilieface){

	document.frmgbk.content.value+=smilieface;
}
				</script><%dim ii
for i=1 to 36
	response.write "<img src="""&"images/mood/"&i&".gif"&""" border=0 onclick=""insertsmilie('[em"&i&"]')"" style=""CURSOR: hand"">&nbsp;"
if i=18 or i=36 Then Response.Write "<br>"
next%>
                      </div></td>
                    <td>&nbsp;</td>
                  </tr>
                </table></td></tr>

<tr Class=DarkTableBody>
                <td valign=middle colspan=2 align=center>
                <input type=Submit value="修 改" name=Sbmt class=button> &nbsp; &nbsp;
<input type="reset" name="reset" value="清 除" class=button>
                </td></tr>
      </table>
      </td>
    </tr>
  </table>
  </center></div>
</form>
<script language="javascript">
function checklength(theform) {
var ly=frmgbk.content.value;
var strlen=strlength(ly);
alert("您的帖子长度为 "+strlen+" 字符.");

}</script>

<%
	Set rs=Nothing

End Sub

Sub saveedit()


End Sub


Sub deleteReply()
	if request("boardid")="" then
  response.write "<script language=javascript>alert('请确认您是否从有效路径进入本站');history.go(-1);</script>"
  response.end
else
boardid=request("boardid")
end if
	Dim ReplyRs
	if chktopic=False Then Exit Sub

	if Request("PostID")="" Then
		founderr=True
		Errmsg=Errmsg+"<br>"+"<li>请指定要删除的回复贴子。"
	ElseIf not isInteger(Request("PostID")) Then
		founderr=True
		Errmsg=Errmsg+"<br>"+"<li>非法的贴子参数。"
	Else
		PostID=Clng(Request("PostID"))
		if LinkID=PostID then 
			founderr=True
			Errmsg=Errmsg+"<br>"+"<li>操作失败，不能对主题贴子执行该操作！"
		end if
	End if

	if founderr Then
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

   	Set ReplyRs=conn.execute("Select userid from reply where postid="&PostID&" and topicid="&TopicID)
	if ReplyRs.bof and ReplyRs.eof Then
		ErrMsg=ErrMsg+"<br>"+"<li>指定的贴子不存在！</li>"
		Call Error("Exclamation",ErrMsg)
	Else
		if not sysadmin and ReplyRs(0)<>membername and not ismaster() Then
			Errmsg=Errmsg+"<br>"+"<li>对不起，您无权对这个帖子进行管理操作！"
			Call Error("Exclamation",ErrMsg)
		Else
			conn.execute("update student set point=point+"&PointSet(18)&" where userid='"&ReplyRs(0)&"'")

			sql="delete from reply where postid="&PostID
			conn.execute(sql)

			sql="update topic set replys=replys-1 where postid="&TopicID
			conn.execute(sql)
			
			sql="update bbs set postnum=postnum-1 where boardid="&boardid
			conn.execute(sql)

			rURL="Bbs_ViewThread.asp?boardid="&boardid&"&TopicID="&TopicID&"&Page="&Cint(request("Page"))
			rtitle="删除回复帖子成功"
			rmsg="本页面将在3秒后自动返回您所管理的主题帖子，<b>您可以选择以下操作：</b><br><ul>"&_
					"<li><a href=Bbs_index.asp>返回校园论坛</a></li>"&_
					"<li><a href="""&rURL&""">返回主题帖子</a></li>"&_
					"</ul>"
			Redirect 3,rurl,rtitle,rmsg

		End if

	End if
	Set ReplyRs=Nothing
End Sub



Sub deletetopic()
if request("boardid")="" then
  response.write "<script language=javascript>alert('请确认您是否从有效路径进入本站');history.go(-1);</script>"
  response.end
else
boardid=request("boardid")
end if
	if chktopic=False Then Exit Sub
	if not sysadmin and not ismaster() Then
		Errmsg=Errmsg+"<br>"+"<li>对不起，你没有操作权限！"
		Call Error("Exclamation",ErrMsg)
	Else

		sql="delete from topic where postid="&TopicID
		conn.execute(sql)

		sql="delete from reply where topicid="&TopicID
		conn.execute(sql)
sql="update bbs set topicnum=topicnum-1 where boardid="&boardid
			conn.execute(sql)

		rURL="Bbs_ForumDisplay.asp?boardid="&boardid&""
		rtitle="删除主题帖子"
		rmsg="<br><ul><li><a href=Bbs_index.asp>返回校园论坛</a></li></ul>"
		Redirect 3,rurl,rtitle,rmsg

	End if

End Sub


Sub mantopic()
if request("boardid")="" then
  response.write "<script language=javascript>alert('请确认您是否从有效路径进入本站');history.go(-1);</script>"
  response.end
else
boardid=request("boardid")
end if
	if chktopic=False Then Exit Sub
	if not sysadmin and not ismaster() Then
		Errmsg=Errmsg+"<br>"+"<li>对不起，你没有操作权限！"
		Call Error("Exclamation",ErrMsg)
	Else
		if Request("Action")="Top" Then
			sql="update topic Set istop=abs(istop-1) where postid="&TopicID
		ElseIf Request("Action")="Lock" Then
			sql="update topic Set locked=abs(locked-1) where postid="&TopicID
		End if
		conn.execute(sql)

		rURL="Bbs_ViewThread.asp?boardid="&boardid&"&TopicID="&TopicID
		rtitle="管理帖子成功"
		rmsg="本页面将在3秒后自动返回您所管理的主题帖子，<b>您可以选择以下操作：</b><br><ul>"&_
				"<li><a href=Bbs_index.asp>返回校园论坛</a></li>"&_
				"<li><a href=""Bbs_ViewThread.asp?boardid="&boardid&"&TopicID="&TopicID&""">主题帖子</a></li>"&_
				"</ul>"
		Redirect 3,rurl,rtitle,rmsg

	End if

End Sub


Function chktopic()

	Dim TopicRs
	if Request("TopicID")="" Then
		founderr=True
		Errmsg=Errmsg+"<br>"+"<li>请指定要管理的贴子主题。"
	ElseIf not isInteger(Request("TopicID")) Then
		founderr=True
		Errmsg=Errmsg+"<br>"+"<li>非法的贴子参数。"
	Else
		TopicID=Clng(Request("TopicID"))
	End if

	if founderr Then
		Call Error("Exclamation",ErrMsg)
		chktopic=False
		Exit Function
	End if

   	Set TopicRs=conn.execute("Select linkid from topic where postid="&TopicID)
	if TopicRs.bof and TopicRs.eof Then
		foundErr = True
		ErrMsg=ErrMsg+"<br>"+"<li>指定的贴子不存在</li>"
	else
		LinkID=TopicRs(0)
	End if
	Set TopicRs=Nothing

	chktopic=not founderr
	
	if founderr Then
		Call Error("Exclamation",ErrMsg)
	End if

End Function
%>

<%Call footer()%>