<!-- #include file="include/config_forum.asp" -->
<% if not(isnumeric(forumid)) then call cookies_type("view_id") %>
<!-- #include file="include/config_upload.asp" -->
<!-- #include file="include/conn.asp" -->
<%
call forum_first()
call web_head(2,0,2,0,0)

dim title,content,allmsg,sucmsg,msgcontent,msg,doWealth,douserCP,douserEP,ismsg,dowealthmsg,douserEPMsg,douserCPMsg,checkbox,fir_top,uusername,u_usernam,ip,ccancel,cancel,bismsg
ccancel=trim(request.querystring("cancel"))
ip=Request.ServerVariables("REMOTE_ADDR")
uusername=trim(request.querystring("uusername"))
fir_top=trim(request.querystring("fir_top"))
checkbox=request.form("checkbox")
delid=trim(request.querystring("del_id"))
bismsg=request.form("bismsg")
msg=trim(request.form("msg"))
title=trim(request.form("title"))
content=trim(request.form("content"))
content="原因：" & title & content
if request("doWealth")="0" or request("doWealth")="" or isnumeric(request("doWealth"))=false then
	doWealth=0
	doWealthMsg=""
else
	doWealth=request("doWealth")
	doWealthMsg="积分" & request("doWealth") & " "
end if
if request("douserEP")="0" or request("douserEP")="" or isnumeric(request("douserEP"))=false then
	douserEP=0
	douserEPMsg=""
else
	douserEP=request("douserEP")
	douserEPMsg="金钱" & request("douserEP") & " "
end if
if  request("douserCP")="0" or request("douserCP")="" or isnumeric(request("douserCP"))=false then
	douserCP=0
	douserCPMsg=""
else
	douserCP=request("douserCP")
	douserCPMsg="魅力" & request("douserCP")
end if
if checkbox<>"1" then
if doWealthMsg="" and douserEPMsg="" and douserCPMsg="" then
	allmsg="分值操作：没有"
else
	allmsg="分值操作：" & doWealthMsg & douserEPMsg & douserCPMsg
end if
else
	allmsg="分值操作：没有"
end if

if action="istops" then
  if format_user_power(login_username,login_mode,"")<>"yes" then close_conn():call cookies_type("power")
else
  if format_user_power(login_username,login_mode,forumpower)<>"yes" then close_conn():call cookies_type("power")
end if

dim isaction,delid
isaction=trim(request.querystring("isaction"))
select case isaction
case "del"
  call is_del()
case "delete"
  call is_delete()
case "other"
  call is_action()
case else
  call main()
end select
call web_end(1)
call close_conn()

sub main()
%>
<FORM METHOD=POST ACTION="forum_isaction.asp?isaction=<%=action%>&forum_id=<%=forumid%>&del_id=<%=delid%>&fir_top=<%=fir_top%>&uusername=<%=uusername%>&view_id=<%=viewid%>&action=<%=isaction%>&cancel=<%=ccancel%>" name="frmAnnounce">
<%=forum_table1%>
  <tr <%=forum_table2%>> 
    <th height=25>论坛帖子管理中心</th>
  </tr>   
  <tr> 
    <td  <%=format_table(3,1)%> height=24><b>
      操作理由</b>：  
	  <select name="title" size=1>
<option value="">自定义</option>
<option value="[灌水]">灌水</option>
<option value="[维护]">维护</option>
<option value="[奖励]">奖励</option>
<option value="[好文章]">好文章</option>
<option value="[内容不符]">内容不符</option>
<option value="[重覆发贴]">重复覆帖</option>
	  </select>
	  <input type="text" name="content" size=60>  *</td>
  </tr>   
  <tr> 
    <td  <%=format_table(3,1)%> height=24><b>
      用户操作</b>：  积分：<input type=text value="0" name="doWealth" size=5>
&nbsp;魅力：<input type=text value="0" name="douserCP" size=5>
&nbsp;金钱：<input type=text value="0" name="douserEP" size=5>
&nbsp;<input type="checkbox" name="checkbox" value="1" >不对用户进行分值操作 <font color=red>(请输入数字)</font>
  </td>
  </tr> 
<input type=hidden value="<%=delid%>" name="del_id">
<input type=hidden value="<%=forumid%>" name="forumid">
  <tr> 
    <td height=24  <%=format_table(3,1)%>>
<B>短信通知</B>：<input type=text size=70 name="msg">&nbsp;<input type="checkbox" name="bismsg" value="1">使用</td>
  </tr>   
  <tr> 
    <td height=24  <%=format_table(3,1)%>>
<B>管理说明</B>：<BR>
  请慎重使用版主的管理职能，版主所有操作将被记录<BR>
  如果选择了短信通知，则会将删贴原因发送给用户，您也可以在短信中附上简短说明</td>
  </tr>   
  <tr> 
    <td height=24 <%=format_table(3,1)%> align=center>
      <input type="submit" name=submit value="确认操作"></td>
  </tr>   
</table>
</FORM>
<%
end sub

sub is_action()
  if not(isnumeric(viewid)) and (action<>"isgood" and action<>"islock" and action<>"istop" and action<>"istops") then
    call close_conn()
    call cookies_type("del_id")
  end if
  dim username,ufir_top
username=trim(request.querystring("uusername"))
ufir_top=trim(request.querystring("fir_top"))
  dim ismsg,ist,upss
  select case action
  case "isgood"
    ist="精华"
  case "ispel"
    ist="推荐"
  case "islock"
    ist="锁定"
  case "istop"
    ist="固顶"
  case "istops"
    ist="总固顶"
  end select
  if trim(request.querystring("cancel"))="yes" then
    if action="istops" then  action="istop"
    upss=0

sql="insert into log (l_announceid,l_boardid,l_touser,l_username,l_content,l_ip) values ("&viewid&","&forumid&",'"&Username&"','"&login_username&"','取消"&ist&"帖子《"&ufir_top&"》，"&content& "，"&allmsg&"','"&ip&"')"
conn.execute(sql)
if checkbox<>"1" then
	sql="update user_data set integral=integral+'"&doWealth&"',userCP=userCP+'"&douserCP&"',emoney=emoney+'"&douserEP&"' where username='"&username&"'"
  conn.execute(sql)
end if
sucmsg=ist&"贴子，"&allmsg&""
if bismsg="1" then
	msgcontent="您发表的帖子《[url=forum_view.asp?forum_id="&forumid&"&view_id="&viewid&"]"&ufir_top&"[/url]》因"&replace(Content,"原因：","")&"被取消"&sucmsg&""
	if msg<>"" then
	msgContent=msgContent & chr(10) & "以下为操作者给您的留言：" & msg
	end if
conn.Execute("insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&Username&"','"&login_username&"','系统消息','"&msgContent&"',Now(),1,false)")
end if
    ismsg="已成功的对主题（ID："&viewid&"）取消 "&ist&" ！"
  else
    if action="istops" then
      action="istop"
      upss=2
    else
      upss=1
    end if

sql="insert into log (l_announceid,l_boardid,l_touser,l_username,l_content,l_ip) values ("&viewid&","&forumid&",'"&Username&"','"&login_username&"','"&ist&"帖子《"&ufir_top&"》，"&content& "，"&allmsg&"','"&ip&"')"
conn.execute(sql)
if checkbox<>"1" then
	sql="update user_data set integral=integral+'"&doWealth&"',userCP=userCP+'"&douserCP&"',emoney=emoney+'"&douserEP&"' where username='"&username&"'"
  conn.execute(sql)
end if
sucmsg=ist&"贴子，"&allmsg&""
if bismsg="1" then
	msgcontent="您发表的帖子《[url=forum_view.asp?forum_id="&forumid&"&view_id="&viewid&"]"&ufir_top&"[/url]》因"&replace(Content,"原因：","")&"被设为"&sucmsg&""
	if msg<>"" then
	msgContent=msgContent & chr(10) & "以下为操作者给您的留言：" & msg
	end if
conn.Execute("insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&Username&"','"&login_username&"','系统消息','"&msgContent&"',Now(),1,false)")
end if
    ismsg="已成功的将主题（ID："&viewid&"）设为 "&ist&" ！"
  end if
  sql="update bbs_topic set "&action&"="&upss&" where id="&viewid
  conn.execute(sql)

  response.write "<script language=javascript>" & _
		 vbcrlf & "alert("""&ismsg&"\n\n点击返回。"");" & _
		 vbcrlf & "location='forum_list.asp?forum_id="&forumid&"'" & _
		 vbcrlf & "</script>"
  'response.redirect "forum_list.asp?forum_id="&forumid
end sub

sub is_del()
  delid=trim(request.querystring("del_id"))
  if not(isnumeric(delid)) then
    call close_conn()
    call cookies_type("del_id")
  end if
  
  dim reid,username,topic,ip,rname,rtime
  sql="select topic,reply_id,username,ip from bbs_data where forum_id="&forumid&" and id="&delid
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then
    rs.close:set rs=nothing
    call close_conn()
    call cookies_type("del_id")
  end if
  reid=rs("reply_id")
  username=rs("username")
if rs("topic")<>"" then
  topic=rs("topic")
else
  topic="本帖子为回覆帖子"
end if
  ip=rs("ip")
  rs.close:set rs=nothing

  sql="delete from bbs_data where id="&delid
  conn.execute(sql)

 
 sql="select top 1 username,tim from bbs_data where reply_id="&reid&" order by id desc"
  set rs=conn.execute(sql)
  rname=rs("username")
  rtime=rs("tim")
  rs.close:set rs=nothing

  sql="update bbs_topic set re_counter=re_counter-1,re_username='"&rname&"',re_tim='"&rtime&"' where id="&reid
  conn.execute(sql)


  sql="update bbs_forum set forum_data_num=forum_data_num-1 where forum_id="&forumid
  conn.execute(sql)
  sql="update configs set num_data=num_data-1 where id=1"
  conn.execute(sql)
  sql="update user_data set bbs_counter=bbs_counter-1 where username='"&username&"'"
  conn.execute(sql)

sql="insert into log (l_announceid,l_boardid,l_touser,l_username,l_content,l_ip) values ("&reid&","&forumid&",'"&Username&"','"&login_username&"','删除回帖《"&topic&"》，"&content& "，"&allmsg&"','"&ip&"')"
conn.execute(sql)
if checkbox<>"1" then
	sql="update user_data set integral=integral+'"&doWealth&"',userCP=userCP+'"&douserCP&"',emoney=emoney+'"&douserEP&"' where username='"&username&"'"
  conn.execute(sql)
end if
sucmsg="删除回贴，"&allmsg&""
if bismsg="1" then
	msgcontent="您发表的帖子《[url=forum_view.asp?forum_id="&forumid&"&view_id="&reid&"]"&topic&"[/url]》因"&replace(Content,"原因：","")&"被"&sucmsg&""
	if msg<>"" then
	msgContent=msgContent & chr(10) & "以下为操作者给您的留言：" & msg
	end if
conn.Execute("insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&Username&"','"&login_username&"','系统消息','"&msgContent&"',Now(),1,false)")
end if

  response.write "<script language=javascript>" & _
		 vbcrlf & "alert(""成功删除了一条回贴！\n\n点击返回。"");" & _
		 vbcrlf & "location='forum_list.asp?forum_id="&forumid&"'" & _
		 vbcrlf & "</script>"
end sub

sub is_delete()
  delid=trim(request("del_id"))
  if len(delid)<1 then
    call close_conn()
    call cookies_type("del_id")
  end if
  
  dim del_dim,del_num,i,del_true,iok,ifail
  iok=0:ifail=0
  delid=replace(delid," ","")
  del_dim=split(delid,",")
  del_num=UBound(del_dim)
  for i=0 to del_num
    del_true=forum_delete(del_dim(i))
    call upload_del(index_url,del_dim(i))
    if del_true="yes" then
      iok=iok+1
    else
      ifail=ifail+1
    end if
  next
  erase del_dim
  response.write "<script language=javascript>" & _
		 vbcrlf & "alert(""成功删除了 "&iok&" 条贴子及其回贴！\n删除失败 "&ifail&" 条！\n\n点击返回。"");" & _
		 vbcrlf & "location='forum_list.asp?forum_id="&forumid&"'" & _
		 vbcrlf & "</script>"
end sub

function forum_delete(did)
  dim username,numd,sqladd,topic,ip
  did=trim(did)
  numd=1:sqladd=""
  forum_delete="yes"
  sql="select username from bbs_topic where forum_id="&forumid&" and id="&did
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then
    rs.close:set rs=nothing
    forum_delete="no":exit function
  end if
  username=rs("username")
  rs.close
  
  sql="update user_data set bbs_counter=bbs_counter-1 where username='"&username&"'"
  conn.execute(sql)
  
  sql="select count(id) from bbs_data where forum_id="&forumid&" and reply_id="&did
  set rs=conn.execute(sql)
  numd=rs(0)
  rs.close:set rs=nothing

  sql="select topic,reply_id,username,ip from bbs_data where reply_id="&did
  set rs=conn.execute(sql)
if rs("topic")<>"" then
  topic=rs("topic")
else
  topic="本帖子为回覆帖子"
end if
  ip=rs("ip")
  rs.close:set rs=nothing

sql="insert into log (l_announceid,l_boardid,l_touser,l_username,l_content,l_ip) values ("&did&","&forumid&",'"&Username&"','"&login_username&"','删除帖子《"&topic&"》，"&content& "，"&allmsg&"','"&ip&"')"
conn.execute(sql)
if checkbox<>"1" then
	sql="update user_data set integral=integral+'"&int(doWealth)&"',userCP=userCP+'"&int(douserCP)&"',emoney=emoney+'"&int(douserEP)&"' where username='"&username&"'"
  conn.execute(sql)
end if
sucmsg="删除贴子，"&allmsg&""
if bismsg="1" then
	msgcontent="您发表的帖子《[url=forum_view.asp?forum_id="&forumid&"&view_id="&did&"]"&topic&"[/url]》因"&replace(Content,"原因：","")&"被"&sucmsg&""
	if msg<>"" then
	msgContent=msgContent & chr(10) & "以下为操作者给您的留言：" & msg
	end if
conn.Execute("insert into user_mail(accept_u,send_u,topic,word,tim,types,isread) values('"&Username&"','"&login_username&"','系统消息','"&msgContent&"',Now(),1,false)")
end if

  sql="delete from bbs_data where reply_id="&did
  conn.execute(sql)
  sql="delete from bbs_topic where id="&did
  conn.execute(sql)
  sql="update bbs_forum set forum_topic_num=forum_topic_num-1,forum_data_num=forum_data_num-"&numd&" where forum_id="&forumid
  conn.execute(sql)
  sql="update configs set num_topic=num_topic-1,num_data=num_data-"&numd&" where id=1"
  conn.execute(sql)
end function
%>