<!--#include file="../conn/zkconn.asp"-->
<!-- #include file="bbsinc/char.asp" -->
<!--#include file="bbsinc/const.asp"-->
<!--#include file="bbsinc/grade.asp"-->
<% 
	dim announceid
	dim UserName,cname
	dim userPassword
	dim useremail
	dim Topic
	dim body
	dim FoundError
	dim ErrMsg
	dim dateTimeStr
	dim newUser
	dim UserID
	dim ip
	dim Expression
	dim boardID,rootid
	dim signflag
	dim mailflag
	dim char_changed
	if  request.cookies("lgcookie")("userclass") = user_level8 or request.cookies("lgcookie")("userclass") = user_level9 then 
	char_changed = "[此贴子已经被"&request.cookies("lgcookie")("username")&"编辑过]"
	else
	char_changed = "[此贴子已经被作者编辑过]"
	end if
	'cname=session.contents("username")
   	cname = Request("username")
   	UserName=trim(request("username"))
   	UserPassWord=trim(request("passwd"))
   	IP=Request.ServerVariables("REMOTE_ADDR") 
   	Expression=Request.Form("Expression")&".gif"
   	BoardID=Request("boardID")
   	AnnounceID=Cstr(Request("ID"))
   	RootID=request("RootID")
   	Topic=trim(request("subject"))
   	Body=request("body")+chr(13)+chr(10)+char_changed+chr(13)
	signflag=trim(request("signflag"))
	mailflag=trim(request("emailflag"))
	FoundError=false

	if request.cookies("lgcookie")("username")="" then
   		ErrMsg=ErrMsg+"<Br>"+"<li>您还没有登陆呀~"
   		foundError=True
'判断假如修改者不是版主则判断其权限
	elseif request.cookies("lgcookie")("username")<>cname then
		if request.cookies("lgcookie")("userclass") <> user_level8 and request.cookies("lgcookie")("userclass") <> user_level9 then
   		ErrMsg=ErrMsg+"<Br>"+"<li>您没有权限编辑该贴子。"
   		foundError=True
		end if
	end if
	if not isInteger(request("skin")) then
		skin=0
	elseif request("skin")=0 then
		skin=0
	elseif request("skin")=1 then
		skin=1
	else
		skin=0
	end if
	if signflag="yes" then
		signflag=1
	else
		signflag=0
	end if
	if mailflag="yes" then
		mailflag=1
	else
		mailflag=0
	end if
	if UserName="" or strLength(UserName)>20 then
   		ErrMsg=ErrMsg+"<Br>"+"<li>请输入姓名(长度不能大于20)"
   		foundError=True
	elseif Trim(UserPassWord)="" or strLength(UserPassWord)>20 then
   		ErrMsg=ErrMsg+"<Br>"+"<li>请输入密码(长度不能大于20)"
   		foundError=True
	end if
	if Topic="" then
   		FoundError=True
   		if Len(ErrMsg)=0 then
      			ErrMsg=ErrMsg+"<Br>"+"<li>主题不应为空"
   		else
      			ErrMsg=ErrMsg+"<Br>"+"<li>主题不应为空"
   		end if
	elseif strLength(topic)>100 then
   		FoundError=True
   		if strLength(ErrMsg)=0 then
      			ErrMsg=ErrMsg+"<Br>"+"<li>主题长度不能超过100"
   		else
      			ErrMsg=ErrMsg+"<Br>"+"<li>主题长度不能超过100"
   		end if
	end if
	if strLength(body)>AnnounceMaxBytes then
   		ErrMsg=ErrMsg+"<Br>"+"<li>发言内容不得大于" & CSTR(AnnounceMaxBytes) & "bytes"
   		foundError=true
	end if

	if FoundError=true then
   		call Error()
	else
   		dim FoundUser

      	if foundError=false then
         	DateTimeStr=CSTR(NOW()+TIMEADJUST/24)
         	dim cmdTemp
	     	dim InsertCursor
	     	Set InsertCursor = Server.CreateObject("ADODB.Recordset")
         	cmdTemp="SELECT *, UserName FROM bbs_content where username='"&trim(cname)&"' and AnnounceID="&AnnounceID
   	     	InsertCursor.Open cmdTemp, conn, 1, 3
		if InsertCursor.eof then
			response.write"<script language=Javascript>"
			response.write"alert('错误：您不是本帖子的作者，无权修改！！');"
			response.write"location.href = 'javascript:history.back()'"
			response.write"</script>"
			set InsertCursor=nothing
    			response.end()
		elseif InsertCursor("locktopic")=1 then
			Errmsg=ErrMsg+"<Br>"+"<li>本主题已经锁定，不能编辑。"
			founderror=true
			call error()
		else
	     		InsertCursor("Topic") =Topic
	     		InsertCursor("Body") =Body
	     		InsertCursor("DateAndTime") =DateTimeStr
	     		InsertCursor("length")=strlength(body)
         		InsertCursor("ip")=ip
         		InsertCursor("Expression")=Expression
         		InsertCursor("signflag")=signflag
         		InsertCursor("emailflag")=mailflag
	     		InsertCursor.Update
    			session("subject")=topic
  	     		if err.number<>0 then
	       			err.clear
		   		ErrMsg=ErrMsg+"<Br>"+"<li>数据库操作失败，请以后再试"&err.Description 
  	       			call Error()
	     		else
 	    		InsertCursor.close
			set InsertCursor=nothing
	    		'response.redirect("list.asp?boardid="&boardid&"")
			response.redirect("dispbbs.asp?boardid="&boardid&"&rootid="&rootid&"&id="&rootid)
    			end if
  		end if
	end if
	end if
	conn.close
	set conn=nothing
%>
</body>
</html>