<!--#INCLUDE FILE="conn.asp" -->
<!--#include file="Class_Checkuser.asp" -->
<!--#INCLUDE FILE="Class_Top.asp" -->
<!--#include file="inc/char.asp" -->
<%
locat="风铃论坛"
act="发表新主题"
Call top(4,1)

if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=Class_Login.asp target=_blank><font color=red><B>登录</B></font></a>。"
	Call Error("Information",ErrMsg)
	
Else
boardid=clng(request("boardid"))
	if Request("Action")="Save" Then
		Dim Topic,body
		Call savepost()
	Else
		Call ShowPostForm()
	End if
End if


Sub ShowPostForm()

Dim advmode

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

%>
<BR><BR>
<form action="Bbs_NewTopic.asp?boardid=<%=boardid%>" method="POST" onSubmit="submitonce(this)" name="frmgbk">
<input type=hidden name=Action value="Save">
<table Class=TableBorder cellpadding=0 cellspacing=0 border=0 width=100% cellspacing="0" align=center>
    <tr>
      <td width="100%">
<table cellpadding=5 cellspacing=1 border=0 width=100%>
    <tr>
      <th width="100%" colspan=2>发表新主题&nbsp;<%if advmode=False Then%><A HREF="?Mode=Advanced" title="当前为简洁模式，按此切换到高级发贴模式">[高级模式]</A><%Else%><A HREF="?Mode=Typical" title="当前为高级模式，按此切换到简洁发贴模式">[简洁模式]</A><%End if%></th>
    </tr>
        <tr Class=LightTableBody>
          <td width="22%">作者：
	  </td>
		            <td width="78%">&nbsp;<%=htmlencode(membername)%>&nbsp;[<A HREF="Class_Login.asp?Action=logout">退出登录</A>]
	 </td>
        </tr>
        <tr Class=LightTableBody>
          <td width="22%">帖子标题：
              <SELECT name="keyword">
              <OPTION selected value="">话题类型</OPTION>
				<OPTION value=[原创]>[原创]</OPTION>
				<OPTION value=[转帖]>[转帖]</OPTION>
				<OPTION value=[闲聊]>[闲聊]</OPTION>
				<OPTION value=[搞笑]>[搞笑]</OPTION>
				<OPTION value=[精品]>[精品]</OPTION>   
				<OPTION value=[灌水]>[灌水]</OPTION>
				<OPTION value=[讨论]>[讨论]</OPTION>
				<OPTION value=[感慨]>[感慨]</OPTION>
				<OPTION value=[求助]>[求助]</OPTION>
				<OPTION value=[介绍]>[介绍]</OPTION>
				<OPTION value=[推荐]>[推荐]</OPTION>
				<OPTION value=[公告]>[公告]</OPTION>
				<OPTION value=[注意]>[注意]</OPTION>
				<OPTION value=[贴图]>[贴图]</OPTION>
				<OPTION value=[视频]>[视频]</OPTION>
				<OPTION value=[动画]>[动画]</OPTION>
				<OPTION value=[音频]>[音频]</OPTION>
				<OPTION value=[建议]>[建议]</OPTION>
				<OPTION value=[下载]>[下载]</OPTION>
				<OPTION value=[分享]>[分享]</OPTION>													
							</SELECT>
	  </td>
		            <td width="78%">&nbsp;
            <input name="title" size=70 maxlength=80 class=FormClass>
            &nbsp;&nbsp;<font color=red><strong>*</strong></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=1 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;[<a href=javascript:checklength()>检测长度</a>]：<BR>&nbsp;<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" ></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>
</form>
<script language="javascript">
function checklength(theform) {
var ly=frmgbk.content.value;
var strlen=strlength(ly);
alert("您的帖子长度为 "+strlen+" 字符.");

}</script>
<%
End Sub



Sub savepost()

	dim ip,mood,username
	dim rs,sql
	dim TopicID

	if chkdata=False Then
		session("lastpost")=Now()
	else
		IP=Request.ServerVariables("REMOTE_ADDR") 
		mood=cint(Request.Form("mood"))
		UserName=Checkstr(membername)


		Sql="insert into topic (userid,title,ip,mood,boardid) values "&_
			"('"&UserName&"','"&topic&"','"&ip&"',"&mood&","&boardid&")"
		conn.execute(sql)

		Set rs=conn.execute("select max(postid) from topic")
		TopicID=rs(0)

		Sql="insert into reply (topicid,userid,title,body,ip,mood,boardid) values "&_
			"("&TopicID&",'"&UserName&"','"&topic&"','"&body&"','"&ip&"',"&mood&","&boardid&")"
		conn.execute(sql)

		Set rs=conn.execute("select postid from reply where topicid="&TopicID)
		ReplyID=rs(0)
		Set rs=Nothing
		conn.execute("update topic set linkid="&ReplyID&" where postid="&TopicID)

		conn.execute("update config Set topicnum=topicnum+1,bbsnum=bbsnum+1,todayNum="&alltodays())
		conn.execute("update student Set point=point+"&PointSet(15)&",Topicnum=Topicnum+1 where userid='"&UserName&"'")
        
		'后来再加入的。用于更新表bbs里的贴子统计
dim lastpost
lastpost=left(topic,12)&"...$"&username&"$"&now()    '用于更新版面最后的贴子
conn.execute("update bbs set lastpost='"&lastpost&"',boardbbsnum=boardbbsnum+1,todaynum=todaynum+1,topicnum=topicnum+1 where boardid="&boardid)

		session("lastpost")=Now()

		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="&rURL&">发表的新主题帖子</a></li>"&_
				"</ul>"
		Redirect 3,rurl,rtitle,rmsg

	End if

End Sub


Function alltodays()
    	tmprs=conn.execute("Select count(postid) from reply Where datediff(day,posttime,getdate())=0")
    	alltodays=tmprs(0)
	Set tmprs=Nothing
	if isnull(alltodays) Then alltodays=0
End Function


Function chkData()

	if not sysadmin and not isnull(session("lastpost"))  Then
		if DateDiff("s",session("lastpost"),Now())<10 Then
			ErrMsg=ErrMsg+"<Br>"+"<li>本论坛限制发贴间隔时间为10秒，请稍后再发。"
			Call Error("Exclamation",ErrMsg)
			chkdata=False
			Exit Function
		End if
	End if

	if chkpost=False Then
		ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从外部提交发言。"
		Call Error("Critical",ErrMsg)
		chkdata=False
		Exit Function
	End if

	Topic=Request("keyword")&Checkstr(trim(Request("title")))
	if trim(Request("title"))="" Then
		FoundErr=True
		ErrMsg=ErrMsg+"<Br>"+"<li>主题不应为空。"
	ElseIf 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=True Then
		chkdata=False
		Call Error("Information",ErrMsg)
	Else
		chkdata=True
	End if

End Function
%>

<%Call footer()%>
