<!--#INCLUDE FILE="setup.asp" -->
<!--#INCLUDE FILE="checkuser.asp" -->
<!--#INCLUDE FILE="theme.asp" -->
<!--#INCLUDE FILE="include/char.asp" -->
<!--#INCLUDE FILE="include/email.asp" -->
<%
locat="班级心声"

if membername="" Then
  	ErrMsg=ErrMsg+"<br>"+"<li>您还没有<a href=login.asp>登录</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
		Select Case Request("action")
		Case "Save"
			Dim content,title
			act="发表留言"
			Call top(2,1)
			Call saveboard()
		Case "Sign"
			act="发表留言"
			Call top(2,1)
			Call signboard()
		Case "Edit"
			act="编辑留言"
			Call top(2,1)
			Call editform()
		Case "Modify"
			act="编辑留言"
			Call top(2,1)
			Call modify()
		Case "Delete"
			act="删除留言"
			Call top(2,1)
			Call delete()
		End Select
	End if
End if



	
Sub signboard()
Dim advmode

bisquotepost=False

if Request("quotepostno")<>"" Then
postno=Clng(Request("quotepostno"))
sql="Select name,content,signtime,classid from classboard where id="&postno
Set rs=Conn.Execute(sql)
if not rs.eof and rs("classid")=Clng(ClsID) Then
content=reubbcode(rs("content"))
	 	content = replace(content, "&gt;", ">")
  		content = replace(content, "&lt;", "<")
   		content = Replace(content, "</P><P>", CHR(10) & CHR(10))
   		content = Replace(content, "<BR>", CHR(10))
quotecontent="[quote][b]以下是引用[i]"&getrealname(rs("name"))&"在"&rs("signtime")&"[/i]的发言：[/b]"
quotecontent=quotecontent+chr(13)+content+chr(13)+"[/quote]"
bisquotepost=True
End if
End if

if Request("mode")="advanced" Then
	advmode=True
ElseIf Request("mode")="typical" Then
	advmode=False
Else
	advmode=BoolVar(3)
End if
%>
<BR><BR>
        <form style="MARGIN: 0px" name="frmgbk" action="ManageBoard.asp?ClassID=<%=ClsID%>&Action=Save" method="post"
        onsubmit="return submitonce(this)">
		  <input type="hidden" name="ClsID"
          value="<%=ClsID%>">
		  <table border="0" cellspacing="1" width="100%" cellpadding="4"
          Class=TableBorder align="center">
            <tr>
              <th height="20" align="center" colspan=2>
			  <b>发表留言</b>&nbsp;&nbsp;
			  
			  <%if advmode=False Then
				  response.write "<A HREF=ManageBoard.asp?ClassID="&ClsID&"&Action=Sign&Mode=advanced"
				  if bisquotepost=True Then Response.Write "&quotepostno="&postno
				  response.write " title=""当前为简洁模式，按此切换到高级发贴模式"">[高级模式]</A>"
			  Else
				  response.write "<A HREF=ManageBoard.asp?ClassID="&ClsID&"&Action=Sign&Mode=typical"
				  if bisquotepost=True Then Response.Write "&quotepostno="&postno
				  response.write " title=""当前为高级模式，按此切换到简洁发贴模式"">[简洁模式]</A>"
			  End if%></th>

            <tr  Class=LightTableBody>
              <td height="13" width="30%">&nbsp;留 言 人：</td><td> 
              &nbsp;<%=htmlencode(getrealname(membername))%>&nbsp;[<a href="Login.asp?Action=logout">退出登录</a>]</td>
            </tr>
            <tr Class=LightTableBody>
              <td height="13" nowrap>&nbsp;留言主题：&nbsp;<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>&nbsp;<input size="50" name="title" maxlength=20>&nbsp;<FONT COLOR="red">*</FONT>不得超过10个汉字 </td>
            </tr>
 <tr Class=LightTableBody>
              <td height="13">&nbsp;留言心情：<br><li>将放在留言的前面
</td><td><table border=0 width=100%><tr><td>
<%for i=1 to 18
	response.write "<input type=radio value="""&i&""" name=mood>"&_
		"<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;留言内容&nbsp;[<a href=javascript:checklength()>检测长度</a>]：<BR><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 name="content" rows="10" cols="65" title="可以使用Ctrl+Enter直接提交留言" onkeydown="ctlent()"><%if bisquotepost=True Then Response.Write quotecontent%></textarea></tr></table></td>
            </tr>
            <tr Class=DarkTableBody>
              <td height="30" align="center" colspan=2><input
              style="WIDTH: 80px; HEIGHT: 22px" type="submit" value="提交留言" name="sbmt" class=button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
              &nbsp; <input style="WIDTH: 80px; HEIGHT: 22px" type="reset" value="清除重写"
              name="reset" class=button> </td>
            </tr>
          </table>
        </form>
<script language="javascript">
function checklength(theform) {
var ly=frmgbk.content.value;
var strlen=strlength(ly);
alert("您的留言长度为 "+strlen+" 字符.");
}
</script>
<BR>

<%End Sub



rem ================================================================


Sub editform()
bbsid=Request("id")
Set rs=Conn.Execute("Select * from classboard where id="&bbsid)

if rs.eof and rs.bof Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，该留言信息不存在！"
	Call Error("Exclamation",ErrMsg)
Else
%>
    <table border="0" cellspacing="1" width="100%">
      <tr>
        <td align="center"><br>
        </p>
        <form style="MARGIN: 0px" name="frmgbk" action="ManageBoard.asp?ClassID=<%=ClsID%>" method="post"
        onsubmit="return submitonce(this)">
		  <input type="hidden" name="bbsid" value="<%=bbsid%>">
		  <input type="hidden" name="Page" value="<%=Request("page")%>">
		  <input type="hidden" name="Action" value="Modify">
		  <table border="0" cellspacing="1" width="100%" cellpadding="4"
          Class=TableBorder>
            <tr>
              <th height="20" align="center" colspan=2>
			  <b>修改班级留言</b></th>

            <tr  Class=LightTableBody>
              <td height="13" width=30%>&nbsp;留 言 人：</td><td> 
              &nbsp;&nbsp;<%=htmlencode(getrealname(rs("name")))%></td>
            </tr>
            <tr Class=LightTableBody>
              <td height="13">&nbsp;留言主题：</td><td>&nbsp;&nbsp;<input size="38" name="title" value=<%=htmlencode(rs("title"))%>></td>
            </tr>
 <tr Class=LightTableBody>
              <td height="13">&nbsp;留言心情：</td><td><br><table border=0 width=100%><tr><td>
<%for i=1 to 18
	response.write "<input type=radio value="""&i&""" name=mood"
	if i=rs("mood") then Response.Write " checked"
	response.write "><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 width=120>&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('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>&nbsp;&nbsp;<textarea name="content" rows="10" cols="50" ><%=rs("content")%></textarea></td>
            </tr>
            <tr Class=DarkTableBody>
              <td height="30" align="center" colspan=2><input
              style="WIDTH: 80px" type="submit" value="修&nbsp;&nbsp;改" name="submit" class=button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
              &nbsp; <input style="WIDTH: 80px" type="button" value="返&nbsp;&nbsp;回" onclick="javascript:history.go(-1)"
              name="reset" class=button> </td>
            </tr>
          </table>
        </form>
        </td>
      </tr>
    </table>
<%

End if
	Set rs=Nothing

End Sub



Sub modify()

bbsid=Request.form("bbsid")

if bbsid="" Then
	ErrMsg=ErrMsg+"<br>"+"<li>操作失败，缺少参数！"
	Call Error("Exclamation",ErrMsg)
	Exit Sub
End if

sql="Select name,classid from classboard where id="&bbsid
Set rs=Conn.Execute(sql)

if not sysadmin Then
	if Clng(ClsID)<>rs(1) Then
		ErrMsg=ErrMsg+"<br>"+"<li>非法操作，您无权修改其他班级同学的留言！"
		founderr=True
	ElseIf ChkRights(4)=False and rs(0)<>membername Then
		ErrMsg=ErrMsg+"<br>"+"<li>操作失败，您无权修改班内其他同学的留言！"
		founderr=True
	End if
End if

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

	if Request.form("title")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请确认输入了留言主题。"
		founderr=True
	Else
		title=checkstr(trim(Request.form("title")))
	End if

	content=checkstr(rtrim(Request.form("content")))
	if content="" Then
		Errmsg=Errmsg+"<br>"+"<li>留言内容不能为空。"
		founderr=True
	ElseIf strLength(content)>(IntVar(1)*1024) Then
   		ErrMsg=ErrMsg+"<Br>"+"<li>留言内容不得大于"&IntVar(1)& "KBytes"
   		FoundErr=True
	End if

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

EditTime=date()&"&nbsp;"&formatdatetime(now(),vbShortTime)

if  bisclsadm=True or sysadmin Then 
	char_changed = "[align=right][此留言已被"&getrealname(membername)&"于"&edittime&"编辑过][/align]"
Else
	char_changed = "[align=right][此留言已被作者于"&edittime&"编辑过][/align]"
End if

 Body=Content+vbCrLf+vbCrLf+char_changed+vbCr


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

sql="update classboard Set title='"&title&"',mood='"&mood&"',content='"&body&"' where id="&Clng(bbsid)
Conn.Execute(sql)

sql="update student Set point=point+"&PointSet(17)&" where userid='"&membername&"'"
Conn.Execute(sql)


rURL="ClassBoard.asp?ClassID="&ClsID&"&Page="&Request("page")
rtitle="修改留言成功"
rmsg="本页面将在2秒后自动返回班级留言页面<br><ul>"&_
		"<li><a href="&rURL&">返回留言簿</a></li>"&_
		"</ul>"
Redirect 2,rurl,rtitle,rmsg

Set rs=Nothing

End Sub


rem ---------------------------------------------------------------------
Sub saveboard()

if not isnull(session("lastpost"))  Then
	if not sysadmin and DateDiff("s",session("lastpost"),Now())<10 Then
  		ErrMsg=ErrMsg+"<Br>"+"<li>留言簿限制发言间隔时间为10秒，请稍后再发。"
		Call Error("Exclamation",ErrMsg)
		session("lastpost")=Now()
		Exit Sub
	End if
End if

if chkpost=False Then
	ErrMsg=ErrMsg+"<Br>"+"<li>您提交的数据不合法，请不要从同学录外部提交信息。"
	founderr=True
	Exit Sub
Else
	if Request.form("title")="" Then
		Errmsg=Errmsg+"<br>"+"<li>请确认输入了留言主题。"
		founderr=True
	Else
		title=request("keyword")&trim(Request.form("title"))
	End if

	content=rtrim(Request.form("content"))
	if content="" Then
		Errmsg=Errmsg+"<br>"+"<li>留言内容不能为空。"
		founderr=True
	ElseIf strLength(content)>(IntVar(1)*1024) Then
   		ErrMsg=ErrMsg+"<Br>"+"<li>留言内容不得大于"&IntVar(1)&"KBytes"
   		FoundErr=True
	End if
End if


if founderr=True Then
	Call Error("Exclamation",ErrMsg)
	session("lastpost")=Now()
Else
	Call savedata()
	session("lastpost")=Now()
	rURL="ClassBoard.asp?ClassID="&ClsID
	rtitle="发表留言成功"
	rmsg="本页面将在2秒后自动返回班级留言页面<br><ul>"&_
		"<li><a href="&rURL&">返回留言簿</a></li>"&_
		"</ul>"
	Redirect 2,rurl,rtitle,rmsg
End if

End Sub


Sub savedata()

Dim sql,rs
dim LastSign

if Cint(IntVar(5))<>0 then
	sql="select max(signtime) from classboard where classid="&ClsID
	set rs=conn.execute(sql)
	if not (rs.eof and rs.bof) then	LastSign=rs(0)
end if

Set rs = Server.CreateObject("ADODB.Recordset")
rs.open "classboard",Conn,1,3

rs.addnew
rs("ip")=Request.ServerVariables("REMOTE_ADDR") 
rs("name")=membername
rs("title")=title
rs("mood")=cint(Request.form("mood"))
rs("content")=content
rs("classid")=Clng(Request.form("ClsID"))
rs.update
rs.close

sql = "update student Set point=point+"&PointSet(15)&" where userid='"&name&"'"
Conn.Execute(sql)

if Cint(IntVar(5))<>0 then

	sql="Select distinct S.email from student S inner join joinclass J on S.userid=J.userid where J.classid="&_
	ClsID&" and J.userid<>'"&membername&"' and J.isauditing=False and S.NewAnnounceFlag=True"
	if not isNull(LastSign) then sql=sql&" and J.lastvisit > #"&LastSign&"#"
	Set rs=Conn.Execute(sql)

	if not (rs.eof and rs.bof) Then
		mailto=rs(0)
		rs.movenext
		do until rs.eof
			mailto=mailto&","&rs(0)
			rs.movenext
		loop

		mailfrom=StrVar(2)
		mailtopic=StrVar(1)&"-班级留言通知"
		mailbody=vbcrlf&"您好！您的班级:"&ClassName&"有新留言,请注意查看！"&vbcrlf&vbcrlf
		mailbody=mailbody&space(20)&"-------"&StrVar(1)&vbcrlf
		mailbody=mailbody&space(20)&SchoolmateURL&vbclf
		select case Cint(IntVar(5))
		case 1
			Call jmail_smtp()		
		case 2
			Call Cdonts()		
		case 3
			Call aspemail()
		case 4
			Call jmail_msg()		
		End select

	End if

end if 

Set rs=Nothing
End Sub


Sub delete()


	Dim rs,sql

	bbsid=Request("id")

	if bbsid="" Then
		ErrMsg=ErrMsg+"<br>"+"<li>没有操作请求，您正试图进行非法操作！"
		Call Error("Exclamation",ErrMsg)
		Exit Sub
	End if

	bbsid=clng(bbsid)

	sql="Select name,classid from classboard where id="&bbsid
	Set rs=Conn.Execute(sql)

	if rs.eof and rs.bof Then
		ErrMsg=ErrMsg+"<br>"+"<li>非法操作，该留言信息不存在！"
		founderr=True
	Else
		if not sysadmin Then
			if Clng(ClsID)<>rs(1) Then
				ErrMsg=ErrMsg+"<br>"+"<li>非法操作，您无权删除其他班级同学的留言！"
				founderr=True
			ElseIf ChkRights(4)=False and rs(0)<>membername Then
				ErrMsg=ErrMsg+"<br>"+"<li>操作失败，您无权删除班内其他同学的留言！"
				founderr=True
			End if
		End if
	End if

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

	sql="update student set point=point+"&PointSet(18)&" where userid='"&rs(0)&"'"
	Conn.Execute(sql)


	sql="delete from classboard where id="&bbsid
	Conn.Execute(sql)

	Set rs=Nothing

	rURL="ClassBoard.asp?ClassID="&ClsID&"&Page="&Request("page")
	rtitle="删除留言成功"
	rmsg="本页面将在2秒后自动返回班级留言页面<br><ul>"&_
		"<li><a href="&rURL&">返回留言簿</a></li>"&_
		"</ul>"
	Redirect 2,rurl,rtitle,rmsg


End Sub


function reUBBCode(strContent)
    strContent = htmlencode(strContent)
    dim re
    Set re=new RegExp
    re.IgnoreCase =true
    re.Global=True

    re.Pattern="(\[QUOTE\])(.*)(\[\/QUOTE\])"
    strContent=re.Replace(strContent,"")

    set re=Nothing
    reUBBCode=strContent
end function

%>

<%Call footer()%>







