<!--#INCLUDE FILE="setup.asp" -->
<!--#include file="checkuser.asp" -->
<!--#INCLUDE FILE="theme.asp" -->
<!--#include file="include/char.asp" -->
<%
locat="校友留言"
Dim TopicID,LinkID

if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=login.asp>登录</a>。"
	Call top(1,1)
	Call Error("Information",ErrMsg)
Else
	act="管理主题帖子"
	Select Case Request("Action")
	Case "Lock"
		Call top(2,1)
		Call mantopic()
	Case "Top"
		Call top(2,1)
		Call mantopic()
	Case "DeleteTopic"
		act="删除主题帖子"
		Call top(2,1)
		Call deletetopic()
	Case "DeleteReply"
		act="删除回复帖子"
		Call top(2,1)
		Call deletereply()
	Case "Edit"
		act="编辑帖子"
		Call top(2,1)
		Call editform()
	Case "Save"
		act="编辑帖子"
		Call top(2,1)
		Call savedit()
	End Select

End if



Sub savedit()

	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 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
				char_changed = "[align=right][此留言已被作者于"&EditTime&"编辑过][/align]"
			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="ViewThread.asp?TopicID="&TopicID&"&Page="&Cint(request("Page"))&"#PID"&PostID
			rtitle="编辑帖子成功"
			rmsg="本页面将在3秒后自动返回您所编辑的帖子页面，<b>您可以选择以下操作：</b><br><ul>"&_
					"<li><a href=ForumDisplay.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()

	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="ManagePost.asp" 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=""?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=68 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 18%>
	<input type="radio" value="<%=i%>" name="mood" <%if i=rs(2) Then Response.Write "checked"%>><img src="mood/face<%=i%>.gif" WIDTH="15" HEIGHT="15">
<%if i=9 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('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="include/ubbtools.asp" --><%End if%><tr><td>&nbsp;<textarea onkeydown=ctlent() name="content" rows="10" cols="68" title="Ctrl+Enter直接提交修改的帖子"  wrap="soft" ><%=rs(1)%></textarea></td><td>&nbsp;<font color=red>*</font></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()
	
	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 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)

			rURL="ViewThread.asp?TopicID="&TopicID&"&Page="&Cint(request("Page"))
			rtitle="删除回复帖子成功"
			rmsg="本页面将在3秒后自动返回您所管理的主题帖子，<b>您可以选择以下操作：</b><br><ul>"&_
					"<li><a href=ForumDisplay.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 chktopic=False Then Exit Sub
	if not sysadmin 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)

		rURL="ForumDisplay.asp"
		rtitle="删除主题帖子"
		rmsg="<br><ul><li><a href=ForumDisplay.asp>返回校友论坛</a></li></ul>"
		Redirect 3,rurl,rtitle,rmsg

	End if

End Sub


Sub mantopic()

	if chktopic=False Then Exit Sub
	if not sysadmin Then
		Errmsg=Errmsg+"<br>"+"<li>对不起，你没有操作权限！"
		Call Error("Exclamation",ErrMsg)
	Else
		if Request("Action")="Top" Then
			sql="update topic Set istop=not istop where postid="&TopicID
		ElseIf Request("Action")="Lock" Then
			sql="update topic Set locked=not locked where postid="&TopicID
		End if
		conn.execute(sql)

		rURL="ViewThread.asp?TopicID="&TopicID
		rtitle="管理帖子成功"
		rmsg="本页面将在3秒后自动返回您所管理的主题帖子，<b>您可以选择以下操作：</b><br><ul>"&_
				"<li><a href=ForumDisplay.asp>返回校友论坛</a></li>"&_
				"<li><a href=""ViewThread.asp?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()%>