<!--#INCLUDE FILE="conn.asp" -->
<!--#include file="Class_checkuser.asp" -->
<!--#INCLUDE FILE="Class_Top.asp" -->
<!--#include file="inc/char.asp" -->
<%
locat="学校论坛"
Dim TopicID,LinkID
if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=Class_Login.asp><font color=red>登录或注册校友录</font></a>。"
	Call top(1,1)
	Call Error("Information",ErrMsg)
	
Else
	Dim ClsID,Degree,ClassName
	ClsID=Request("ClassID")
	joinstatus=chkjoinclass(ClsID)
	if joinstatus<>"" Then
		Call top(1,1)
		Call Error("Exclamation",joinstatus)
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
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 ClassTopicreply where Classid="&Clsid&" and 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 ChkRights(4)=False 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
			Elseif ChkRights(4)=True then
			char_changed = "[align=right][此帖子已被学校管理员"&getrealname(membername)&"于"&EditTime&"编辑过][/align]"
			else
				char_changed = "[align=right][此帖子已被作者于"&EditTime&"编辑过][/align]"
			End if

			Body=body+vbCrLf+vbCrLf+char_changed

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

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

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

			rURL="Class_bbs_ShowTopic.asp?Classid="&Clsid&"&TopicID="&TopicID&"&Page="&Cint(request("Page"))&"#PID"&PostID
			rtitle="编辑帖子成功"
			rmsg="本页面将在3秒后自动返回您所编辑的帖子页面，<b>您可以选择以下操作：</b><br><ul>"&_
					"<li><a href=Class_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()

	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,userid from ClassTopicreply where Classid="&Clsid&" and 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>
<div align="center">
<table Class=TableBorder cellpadding=0 cellspacing=0 border=0 width=100% cellspacing="0">
<form action="Class_bbs_Admin.asp?Classid=<%=Clsid%>" 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%>">
<tr>
      <td>
<table cellpadding=5 cellspacing=1 border=0 width=100%>
    <tr>
      <th width="100%" colspan=2>编辑帖子&nbsp;
	  <%response.write "<A HREF=""?Classid="&Clsid&"&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(GetRealname(rs(3)))%></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></form>
  </table>
</div>

<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 ClassTopicreply where classid="&Clsid&" and 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 ChkRights(4)=False 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 classtopicreply where classid="&clsid&" and postid="&PostID
			conn.execute(sql)

			sql="update Classtopic set replys=replys-1 where Classid="&clsid&" and postid="&TopicID
			conn.execute(sql)

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

	Set ReplyRs=conn.execute("Select userid from Classtopic where Classid="&Clsid&" and postid="&TopicID)
	if not sysadmin and ReplyRs(0)<>membername and ChkRights(4)=False Then
			Errmsg=Errmsg+"<br>"+"<li>对不起，您无权对这个帖子进行管理操作！"
			Call Error("Exclamation",ErrMsg)
			Exit Sub
	Else

		sql="delete from Classtopic where Classid="&Clsid&" and postid="&TopicID
		conn.execute(sql)
        
		sql="delete from Classtopicreply where Classid="&Clsid&" and topicid="&TopicID
		conn.execute(sql)
		
		rURL="Class_bbs_index.asp?Classid="&Clsid&""
		rtitle="删除主题帖子"
		rmsg="<br><ul><li><a href=Class_bbs_index.asp?Classid="&Clsid&">返回学校论坛首页</a></li></ul>"
		Redirect 3,rurl,rtitle,rmsg

	End if
	set ReplyRs=nothing

End Sub


Sub mantopic()

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

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