<!-- #include file="include/con_forum.asp" -->
<%

if not isnumeric(forumid) then
  call format_redirect("forum.asp")
end if
dim sel_id,re_id,aname,ducou
ducou=int(format_mid_num(29))
sel_id=trim(request.querystring("sel_id"))
re_id=trim(request.querystring("re_id"))
if var_null(sel_id)="" then
  call format_redirect("forum_list.asp?forum_id="&forumid)
end if
select case action
case "revert"
  aname="还原"
case "restore"
  aname="修复"
case "rap"
  aname="奖惩"
case "move"
  aname="转移"
case "istop"
  aname="固顶"
case "istops"
  aname="总固顶"
case "isgood"
  aname="精华"
case "islock"
  aname="锁定"
case "del"
  aname="删除一条回贴"
  if not(isnumeric(re_id)) then
    call format_redirect("forum_list.asp?forum_id="&forumid)
  end if
case "delete"
  aname="删除"
case "del_re"
  aname="删除回贴"
case else
  aname=""
  action=""
  call format_redirect("forum_list.asp?forum_id="&forumid)
end select
%>
<!-- #include file="include/jk_upload.asp" -->
<!-- #include file="include/con_forum_fir.asp" -->
<%
dim dim_cause,action_num,num_err,num_ok,nums
dim_cause="维护|奖励|好文章|内容不符|重复|灌水|广告"
ftit=""&aname&""
call forum_first()
call web_head(0,1,h_var3,0,0)

if action="istops" then
  if forum_power_true("")=false then
    call web_error("power")
  end if
else
  if forum_power_true(forumpower)=false then
    call web_error("power")
  end if
end if

call forum_load()
'----------------------------中间 开始----------------------------
call forum_grade()
call forum_top(tit)

if forum_config(13)>0 then
  action_num=forum_config(13)
else
  action_num=dim_num(36)
end if

response.write vbcrlf&"<table cellspacing=1 cellpadding=4 class=table>"
response.write vbcrlf&"<tr><td colspan=2 class=td0>&nbsp;"&img_skin(web_img_m)&"&nbsp;"&tit&"</td></tr>"

if is_chk() then
  response.write "<tr><td colspan=2 class=bg_td align=center height=200>"
  call forum_isaction_chk()
  response.write "</td></tr>"
else
  call forum_isaction_main()
end if

response.write vbcrlf&"</table>"
response.write vbcrlf&ukong
'----------------------------中间 结束----------------------------
call forum_end()
call web_end(0,0)

function is_chk()
  is_chk=false
  if trim(request.form("chk"))="yes" then
    is_chk=joekoe_cms.post_chk()
  end if
end function

sub forum_isaction_chk()
  dim cause,c_topic,r_id,move_fid,pm,pn,ismail,m_topic,ddim,dnum,chk_msg,chk_num,chk_topic,chk_f,found_err
  num_err=0
  num_ok=0
  chk_num=0
  chk_topic=""
  found_err=""
  cause=trim(request.form("cause"))
  if instr("|"&dim_cause&"|","|"&cause&"|")<1 then cause=""
  if cause<>"" then cause="["&cause&"]"
  c_topic=joekoe_cms.code_form(request.form("c_topic"))
  pm=trim(request.form("pm"))
  if pm<>"m" then pm="p"
  pn=trim(request.form("pn"))
  if not(isnumeric(pn)) then pn=0
  pn=cint(pn)
  if pn>action_num or pn<0 then pn=0
  ismail=trim(request.form("ismail"))
  m_topic=joekoe_cms.code_form(request.form("m_topic"))
  if var_null(m_topic)="" then m_topic="没有"
  m_topic=joekoe_cms.code_form(m_topic)
  move_fid=trim(request.form("move_fid"))
  if not(isnumeric(move_fid)) then move_fid=0
  if cause="" and c_topic="" then
    found_err=found_err&"+请先输入操作（"&aname&"）的原因！<br>"
  end if
  if action="move" then
    if int(move_fid)<1 or int(move_fid)=int(forumid) then
      found_err=found_err&"+请先选择将主题要转移至的论坛！<br>"
    else
      sql="select top 1 forum_w,forum_hidden from bbs_forum where forum_id="&move_fid
      set rs=conn.execute(sql)
      if rs.eof then
        found_err=found_err&"+<font class=red>要转移至的论坛不存在！！！</font><br>"
      else
        if rs("forum_w")=false then
          found_err=found_err&"+要转移至的论坛已设置不可发贴！<br>"
        end if
        if rs("forum_hidden")=true then
          found_err=found_err&"+要转移至的论坛已设置隐藏！<br>"
        end if
      end if
      rs.close
    end if
  end if
  if found_err<>"" then
    response.write found_error(found_err,200)
    exit sub
  end if
  
  sel_id=replace(sel_id," ","")
  ddim=split(sel_id,",")
  dnum=ubound(ddim)
  nums=dnum
  for i=0 to dnum
    if isnumeric(ddim(i)) then
      chk_num=chk_num+1
      call is_type(ddim(i),move_fid,cause,c_topic,pm,pn,ismail,m_topic,chk_topic,chk_f)
    end if
  next
  erase ddim
  if int(num_ok)>0 and (action="del" or action="delete" or action="move" or action="revert" or action="restore") then
    call forum_new_info_update(forumid)
  end if
  
  chk_msg=aname
  if int(chk_num)>1 then
    chk_msg=chk_msg&chk_num&"帖主题"
  else
    chk_msg=chk_msg&"《"&chk_topic&"》"
  end if
  chk_msg=chk_msg&"，原因："&cause&c_topic&"，分值操作："&chk_f
  response.write vbcrlf&"<table border=0>" & _
        	 vbcrlf&"<tr><td align=center>恭喜，操作（"&aname&"）成功！</td></tr>" & _
        	 vbcrlf&"<tr><td><font class=red2>"&chk_msg&"</font></td></tr>" & _
        	 vbcrlf&"<tr><td>统计信息：共 <font class=red>"&chk_num&"</font> 项，成功 <font class=red>"&num_ok&"</font> 项，失败 <font class=red>"&num_err&"</font> 项</td></tr>" & _
        	 vbcrlf&"<tr><td height=30>您现在可以选择以下操作：</td></tr>" & _
        	 vbcrlf&"<tr><td>　　1、<a href='forum_list.asp?forum_id=" & forumid & "'>返回 <b>" & forumname & "</b></a></td></tr>" & _
        	 vbcrlf&"<tr><td>　　2、<a href='forum.asp'>返回论坛首页</a></td></tr>" & _
        	 vbcrlf&"<tr><td height=30>系统将在 "&dim_num(21)&" 秒钟后自动返回 <b>" & forumname & "</b> ……</td></tr>" & _
		 vbcrlf&"</table><meta http-equiv='refresh' content='"&dim_num(21)&"; url=forum_list.asp?forum_id=" & forumid & "'>"
end sub

sub is_type(ftid,t_move_fid,t_cause,t_c_topic,t_pm,t_pn,t_ismail,t_m_topic,t_chk_topic,t_chk_f)
  if not int_true(ftid) then exit sub
  dim n_istop
  n_istop=0
  sql="select id,topic,username,istop from bbs_topic where forum_id="&forumid&" and id="&ftid
  if action="del" then
    sql="select reply_id,topic,username from bbs_data where forum_id="&forumid&" and reply_id="&ftid&" and id="&re_id
  end if
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof and rs.bof then
    rs.close
    num_err=num_err+1
    exit sub
  end if
  dim it_topic,it_id,it_chk_msg,id_username,sql_0,sql_u,sql_t,sql_e,re_counter,re_username,re_tim,it_integral,numd
  it_id=rs(0)
  it_topic=rs(1)
  id_username=rs(2)
  if action<>"del" then n_istop=rs(3)
  rs.close
  if action="del" then it_topic="本贴为回贴"
  t_chk_topic=it_topic
  it_chk_msg=aname&"帖子《"&it_topic&"》，原因："&t_cause&t_c_topic&"，分值操作："
  t_chk_f="没有"
  sql_u=""
  it_integral=0
  if int(t_pn)>0 then
    it_integral=int(t_pn)
    sql_u="update user_data set integral=integral"
    if t_pm="m" then
      sql_u=sql_u&"-"
      it_integral=-it_integral
      t_chk_f="减"
    else
      sql_u=sql_u&"+"
      t_chk_f="加"
    end if
    sql_u=sql_u&t_pn&" where username='"&id_username&"'"
    t_chk_f=t_chk_f&t_pn&"分"
  end if
  it_chk_msg=it_chk_msg&t_chk_f
  
  select case action
  case "revert","restore"
    sql_0="select count(id) from bbs_data where forum_id="&forumid&" and reply_id="&ftid
    set rs=joekoe_cms.exec(sql_0,1)
    re_counter=rs(0)
    rs.close
    sql_0="select top 1 username,tim from bbs_data where forum_id="&forumid&" and reply_id="&ftid&" order by id desc"
    set rs=joekoe_cms.exec(sql_0,1)
    if not rs.eof then
      re_username=joekoe_cms.code_form(rs("username"))
      re_tim=rs("tim")
    end if
    rs.close
    sql="update bbs_topic set re_counter="&re_counter-1&",re_username='"&re_username&"'"	',re_tim='"&re_tim&"'"
    if action="revert" then sql=sql&",istop=0,isgood=0,islock=0"
    sql=sql&" where id="&ftid
    call joekoe_cms.exec(sql,0)
    if action="revert" then
      if int(n_istop)=1 then
        application.lock
        application(joekoe_cms.web_cookies&"_forum_istop_state_"&forumid)=""
        application.unlock
      end if
      if int(n_istop)=2 then
        application.lock
        application(joekoe_cms.web_cookies&"_forum_istops_state")=""
        application.unlock
      end if
    end if
  case "rap"
    '奖惩项暂时没有操作
  case "move"
    sql="select count(id) from bbs_data where reply_id="&ftid
    set rs=joekoe_cms.exec(sql,1)
    numd=rs(0)
    rs.close
    if not int_true(numd) then numd=0
    call joekoe_cms.exec("update bbs_topic set forum_id="&t_move_fid&" where id="&ftid,0)
    call joekoe_cms.exec("update bbs_data set forum_id="&t_move_fid&" where reply_id="&ftid,0)
    call joekoe_cms.exec("update bbs_forum set forum_topic_num=forum_topic_num-1,forum_data_num=forum_data_num-"&numd&" where forum_id="&forumid,0)
    call joekoe_cms.exec("update bbs_forum set forum_topic_num=forum_topic_num+1,forum_data_num=forum_data_num+"&numd&" where forum_id="&t_move_fid,0)
    call forum_new_info_update(t_move_fid)
    if int(n_istop)=1 then
      application.lock
      application(joekoe_cms.web_cookies&"_forum_istop_state_"&forumid)=""
      application(joekoe_cms.web_cookies&"_forum_istop_state_"&t_move_fid)=""
      application.unlock
    end if
  case "istop","istops","isgood","islock"
    sql="update bbs_topic set "&action&"=1 where id="&ftid
    if action="istops" then
      sql="update bbs_topic set istop=2 where id="&ftid
    end if
    call joekoe_cms.exec(sql,0)
    if action="istop" then
      if int(n_istop)<>1 then
        application.lock
        application(joekoe_cms.web_cookies&"_forum_istop_state_"&forumid)=""
        if int(n_istop)=2 then
          application(joekoe_cms.web_cookies&"_forum_istops_state")=""
        end if
        application.unlock
      end if
    end if
    if action="istops" then
      if int(n_istop)<>2 then
        application.lock
        application(joekoe_cms.web_cookies&"_forum_istops_state")=""
        if int(n_istop)=1 then
          application(joekoe_cms.web_cookies&"_forum_istop_state_"&forumid)=""
        end if
        application.unlock
      end if
    end if
  case "del"
    call joekoe_cms.exec("delete from bbs_data where id="&re_id,0)
    call joekoe_cms.exec("update bbs_topic set re_counter=re_counter-1 where id="&ftid,0)
    call joekoe_cms.exec("update bbs_forum set forum_data_num=forum_data_num-1 where forum_id="&forumid,0)
    call joekoe_cms.exec("update configs set num_data=num_data-1 where id=1",0)
    if ducou=1 then      
      call joekoe_cms.exec("update user_data set bbs_counter=bbs_counter-1 where username='"&id_username&"'",0)
    end if    
    application.lock
    application(joekoe_cms.web_cookies&"_configs_num_data")=application(joekoe_cms.web_cookies&"_configs_num_data")-1
    application.unlock
  case "delete"
    call upload_del(index_url,ftid)
    sql="select count(id) from bbs_data where forum_id="&forumid&" and reply_id="&ftid
    set rs=joekoe_cms.exec(sql,1)
    numd=rs(0)
    rs.close
    if not int_true(numd) then numd=0
    call joekoe_cms.exec("update bbs_data set forum_id=999999999 where reply_id="&ftid,0)
    call joekoe_cms.exec("update bbs_topic set forum_id=999999999,form_id="&forumid&",istop=0 where id="&ftid,0)
    call joekoe_cms.exec("update bbs_forum set forum_topic_num=forum_topic_num-1,forum_data_num=forum_data_num-"&numd&" where forum_id="&forumid,0)
    call joekoe_cms.exec("update configs set num_topic=num_topic-1,num_data=num_data-"&numd&" where id=1",0)
    if ducou=1 then      
      call joekoe_cms.exec("update user_data set bbs_counter=bbs_counter-1 where username='"&id_username&"'",0)
    end if
    application.lock
    application(joekoe_cms.web_cookies&"_configs_num_topic")=application(joekoe_cms.web_cookies&"_configs_num_topic")-1
    application(joekoe_cms.web_cookies&"_configs_num_data")=application(joekoe_cms.web_cookies&"_configs_num_data")-numd
    if int(n_istop)=1 then
      application(joekoe_cms.web_cookies&"_forum_istop_state_"&forumid)=""
    end if
    if int(n_istop)=2 then
      application(joekoe_cms.web_cookies&"_forum_istops_state")=""
    end if
    application.unlock
  end select
  
  if sql_u<>"" then conn.execute(sql_u)
  it_chk_msg=joekoe_cms.code_form(it_chk_msg)
  sql_e="insert into bbs_event(forum_id,topic_id,username,o_user,integral,remark,tim) " & _
	"values("&forumid&","&ftid&",'"&login_username&"','"&id_username&"',"&it_integral&",'"&it_chk_msg&"','"&joekoe_cms.now_time&"')"
  call joekoe_cms.exec(sql_e,0)
  if t_ismail="yes" then
    sql_e="insert into user_mail(send_u,accept_u,topic,word,tim,types,isread) " & _
	  "values('"&login_username&"','"&id_username&"','系统短信（论坛主题处理）','"&it_chk_msg&"；附加信息："&t_m_topic&"','"&joekoe_cms.now_time&"',1,0)"
    conn.execute(sql_e)
  end if
  num_ok=num_ok+1
end sub

sub forum_new_info_update(nfid)
  dim rsnf,nf_id,nf_topic,nf_username,nf_tim
  nf_id=""
  nf_topic=""
  nf_username=""
  nf_tim=""
  set rsnf=joekoe_cms.exec("select top 1 id,topic,re_username,re_tim from bbs_topic where forum_id="&nfid&" order by re_tim desc",1)
  if not rsnf.eof then
    nf_id=rsnf("id")
    nf_topic=rsnf("topic")
    nf_username=rsnf("re_username")
    nf_tim=rsnf("re_tim")
    nf_topic=replace(nf_topic,"'","")
    nf_topic=replace(nf_topic,"|","")
  end if
  rsnf.close
  set rsnf=nothing
  'forum_new_num=(select count(id) from bbs_data where forum_id="&nfid&" and tim>'"&joekoe_cms.time_type(joekoe_cms.now_time,4)&" 00:00:00')
  'forum_topic_num=(select count(id) from bbs_topic where forum_id="&nfid&")
  'forum_data_num=(select count(id) from bbs_data where forum_id="&nfid&")
  call joekoe_cms.exec("update bbs_forum set forum_new_info='"&nf_username&"|"&nf_tim&"|"&nf_id&"|"&nf_topic&"' where forum_id="&nfid,0)
end sub

sub forum_isaction_main()
  dim ddim,dnum
%>
<form name=isaction_frm action='' method=post onsubmit="javascript:frm_submitonce(this);">
<input type=hidden name=chk value='yes'>
<tr class=bg_td>
<td width='20%'>&nbsp;操作原因：</td>
<td width='80%'>&nbsp;<select name=cause>
<option value='' selected class=bg_td>自定义</option>
<%
  ddim=split(dim_cause,"|")
  dnum=ubound(ddim)
  for i=0 to dnum
    response.write vbcrlf&"<option value='"&ddim(i)&"'>"&ddim(i)&"</option>"
  next
  erase ddim
%>
</select>&nbsp;<input type=input name=c_topic size=47 maxlength=20></td>
</tr>
<%if action="move" then%>
<tr class=bg_td>
<td>&nbsp;主题转移：</td>
<td>&nbsp;<%response.write forum_isaction_list(forumid)%></td>
</tr>
<%end if%>
<tr class=bg_tds>
<td>&nbsp;加减积分：</td>
<td>&nbsp;<select name=pm>
<option value='p' selected>加</option>
<option value='m'>减</option>
</select>&nbsp;<select name=pn>
<option class=bg_3 selected>0</option>
<%
for i=1 to action_num
   response.write "<option>"&i&"</option>"
next
%>
</select>&nbsp;分</td>
</tr>
<tr class=bg_td>
<td>&nbsp;站内短信：</td>
<td>&nbsp;<input type=checkbox name=ismail value='yes' class=bg_td>&nbsp;&nbsp;附加内容：<input type=input name=m_topic size=60 maxlength=50></td>
</tr>
<tr class=bg_tds height=30>
<td>&nbsp;</td>
<td>&nbsp;<input type=submit value=' 提 交 操 作 '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset value='重新填写'></td>
</tr>
</form>
<%
end sub

function forum_isaction_list(il_forumid)
  dim temp1,ncid,forumn,nfid,classid
  ncid=0
  temp1="<select name=move_fid>"
  sql="select forum_id,class_id,forum_name,forum_n,forum_w,forum_star,forum_hidden,forum_pro from bbs_forum where forum_hidden=0 order by class_id,forum_order,forum_star"
  set rs=joekoe_cms.exec(sql,1)
  do while not rs.eof
    classid=rs("class_id")
    if int(ncid)<>int(classid) then
      temp1=temp1&vbcrlf&"<option class=bg_tds>╋"&rs("forum_name")&"</option>"
      ncid=classid
    else
      forumn=rs("forum_n")
      nfid=rs("forum_id")
      temp1=temp1&vbcrlf&"<option value='"&nfid&"'"
      if int(nfid)=int(il_forumid) then
        temp1=temp1&" selected"
      end if
      temp1=temp1&">"
      for i=1 to rs("forum_star")-1
        temp1=temp1&"│"
      next
      temp1=temp1&"├"&rs("forum_name")
      if rs("forum_w")=false then temp1=temp1&" <不可发贴>"
      if rs("forum_hidden")=true then temp1=temp1&" <隐>"
      if rs("forum_pro")=1 then temp1=temp1&" <只读>"
      temp1=temp1&"</option>"
    end if
    rs.movenext
  loop
  rs.close
  temp1=temp1&"</select>"
  forum_isaction_list=temp1
end function

%>