<!-- #Include File="Include/Config.asp" -->
<!-- #include file="Include/Con_bbs_Fir.asp" -->
<!-- #Include File="../Include/Cls_PageCute.asp" -->
<%

'=======================================================
' 欢迎使用《阿赛大型门户网站系统V3.0》，简称“AsaiMHV3”
' 技术支持、商业版咨询、官方唯一指定联系QQ“4941172”
' 官方网站：http://77ya.com      程序负责人：阿赛
'=======================================================

tit_fir=Cls.ChannelName
ftit="论坛回收站"

call bbs_first()
call DoWebHead(1,1)
'if login_mode<>"admin" then
'if login_mode>"supers" then
if login_mode<>"admin" then
  if login_mode<>"supers" then
    call bbs_redirect("List.asp?fid="&Bbsid)
  end if
end if
call bbs_load_power()
call bbs_grade(0)
call bbs_top(0,"")

'----------------------------中间 开始----------------------------
Cls.LoadTemplate(4)
Response.write Cls.ReHtml(ShowWebHead(1),1)

Cls.OutPage
select case action
case "handle"
  call recycle_handle()
case "clear"
  call recycle_clear()
case else
  call recycle_list()
end select
'----------------------------中间 结束----------------------------
call bbs_end()
Response.write Cls.ReHtml(ShowWebEnd(1),1)

sub recycle_clear()
  dim selid,snum,now_bbs_data
  snum=-1
  sql="select id,bbs_data from AsaiMHBbsTopic where bbs_id=999999999 order by id"
  set rs=Cls.exec(sql,1)
  if not rs.eof then
    selid=rs.getrows()
    snum=ubound(selid,2)
  end if
  if snum<0 then
    Call Cls.Out_Msg("系统发现您提交的数据有错误存在：\n\n论坛回收站已经被清空或还没有记录！\n\n点击返回...","?fid="&Bbsid)
  end if
  for i=0 to snum
    now_bbs_data=selid(1,i)
    call Cls.exec("delete from "&now_bbs_data&" where reply_id="&selid(0,i),0)
    call Cls.exec("delete from AsaiMHBbsTopic where id="&selid(0,i),0)
  next
  erase selid
  Call Cls.Out_Msg("您已成功清空了论坛回收站！（共 "&snum+1&" 条记录）\n\n点击返回...","?fid="&Bbsid)
end sub

sub recycle_handle()
  dim selid,handle,snum,recid,fparent,numn,numt,numd,now_bbs_data,numnew,id_username
  numnew=dateadd("d",0,date)
  selid=Cls.code_form("sel_id")
  selid=replace(selid," ","")
  if selid="" then
    call recycle_list()
    exit sub
  end if
  snum=0
  handle=Cls.code_form("handle")
  selid=split(selid,",")
  for i=0 to ubound(selid)
    if Cls.is_int(selid(i)) then
      recid=0
      sql="select top 1 form_id,bbs_data from AsaiMHBbsTopic where bbs_id=999999999 and id in ("&selid(i)&") order by id"
      set rs=Cls.exec(sql,1)
      if not rs.eof then
        recid=rs(0)
        now_bbs_data=rs(1)
      end if
      rs.close
      if int(recid)>0 then
        sql="select top 1 bbs_parent from AsaiMHBbsClass where bbs_id="&recid
        set rs=Cls.exec(sql,1)
        if not rs.eof then fparent=Cls.Is_Null(rs(0))
        rs.close
        if handle="revert" and fparent<>"" then
          Sql="Select count(id) from "&now_bbs_data&" where tim like '"&numnew&"%' and reply_id="&recid 
          set rs=Cls.exec(sql,1)
          numn=rs(0)
          rs.close
          If not Cls.is_int(numn) Then numn=0
          Sql="Select count(id) from "&now_bbs_data&" where Is_Topic=True and reply_id="&recid
          set rs=Cls.exec(sql,1)
          numt=rs(0)
          rs.close
          If not Cls.is_int(numt) Then numt=0
          Sql="Select count(id) from "&now_bbs_data&" where reply_id="&recid
          set rs=Cls.exec(sql,1)
          numd=rs(0)
          rs.close
          If not Cls.is_int(numd) Then numd=0
          Sql="Select top "&numd&" UserName from "&now_bbs_data&" where reply_id="&recid 
          set rs=Cls.exec(sql,1)
          id_username=rs(0)
          rs.close
          call Cls.exec("update "&now_bbs_data&" set bbs_id="&recid&" where reply_id="&selid(i),0)
          call Cls.exec("update AsaiMHBbsTopic set bbs_id="&recid&",form_id=0 where id="&selid(i),0)
          Call Cls.exec("update AsaiMHBbsClass set bbs_new_num=bbs_new_num+"&numn&",bbs_topic_num=bbs_topic_num+"&numt&",bbs_data_num=bbs_data_num+"&numd&" where bbs_id in ("&fparent&")",0)
          Call Cls.exec("update AsaiMHUserData set bbs_del=bbs_del-"&numd&",bbs_counter=bbs_counter+"&numd&" where username='"&id_username&"'",0)
          Call Cls.exec("update AsaiMHChannel set ChannelCount=ChannelCount+"&numt&",ChannelHits=ChannelHits+"&numd&" Where ChannelIDs="&ChannelIDs&"",0)
          Call Cls.exec("update AsaiMHConfigs set Num_New=Num_New+"&numn&"",0)
          Call Cls.Cache_Del("web_menu")
          Call Cls.Cache_Del("Web_Info")
          Call Cls.Cache_Del("bbs_class")
        else
          call Cls.exec("delete from "&now_bbs_data&" where reply_id="&selid(i),0)
          call Cls.exec("delete from AsaiMHBbsTopic where id="&selid(i),0)
        end if
        snum=snum+1
      end if
    end if
  next
  erase selid
  Call Cls.Out_Msg("您已成功操作 "&snum&" 条记录！\n\n点击返回...","?fid="&Bbsid)
end sub

sub recycle_list()
  dim obj_page
  set obj_page=new Cls_PageCute
  obj_page.pageurl="?fid="&Bbsid
  obj_page.nummer=Format_Mid_Num(12)
  obj_page.page_t=1
  obj_page.page_p=5
  obj_page.page_unit="条"
  obj_page.page_tit="记录"
  obj_page.v_id="id"
  Call obj_page.p_init("*","AsaiMHBbsTopic","bbs_id=999999999 and form_id="&Bbsid,"re_tim desc")
  sql=obj_page.sql_count
  set rs=Cls.exec(sql,1)
  obj_page.rssum=rs(0)
  rs.close
  call obj_page.p_main("*","AsaiMHBbsTopic","bbs_id=999999999 and form_id="&Bbsid,"re_tim desc")
  Response.Write Cls.js_put(""&Cls.Web_Dir&"Style/Select.js",0)
  Response.write Cls.ReadSkin(8)
  Response.write Cls.ReHtml(bbs_grade(0),1)
  Response.write Cls.ReHtml(bbs_top(2,""),1)
%>
<table cellspacing=1 cellpadding=4 class=bbs_table>
<tr align=center height=20>
<td class=bbs_td width='5%'>状态</td>
<td class=bbs_td width='60%'>回收站主题（每页<%response.write obj_page.nummer%>贴）</td>
<td class=bbs_td width='15%'>作者</td>
<td class=bbs_td width='15%'>回复</td>
<td class=bbs_td width='5%'>浏览</td>
</tr>
<form name=recycle_frm action='?fid=<%=Bbsid%>&action=handle' method=post>
<%
  if obj_page.page_num=0 then
%>
<tr align=center height=50 class=bbs_tr><td colspan=5 ><font class=Gys>暂时没有可操作的记录！</font></td></tr>
<%
  else
    for i=1 to obj_page.page_num
      call bbs_topic_type(rs("id"),rs("form_id"),rs("topic"),rs("tim"),rs("username"),rs("re_username"),rs("re_tim"),rs("counter"),rs("re_counter"),rs("istop"),rs("islock"),rs("isgood"),rs("isvote"),rs("vote_num"))
      rs.movenext
    next
  end if
  rs.close
%>
<tr class=bbs_trp><td colspan=5>
  <table border=0 cellspacing=0 cellpadding=0 width='100%'>
  <tr>
  <td>
    <div><%response.write obj_page.page_var%>分页：<%response.write obj_page.page_cute%> <%response.write obj_page.page_shortcut%></div>
  </td>
  <td align=right>
    <table border=0 cellspacing=0 cellpadding=2>
    <tr>
    <td><input class=btn type=button onclick="javascript:recycle_clear();" value='清空所有'></td>
    <td width=3></td>
    <td><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);" class=bbs_trp>&nbsp;选择所有</td>
    <td><select name=handle><option value='delete'>删除</option><option value='revert'>还原</option></select></td>
    <td><input class=btn type=submit name=submit value=' 操 作' onclick="javascript:return sel_click(this.form);"></td>
    </tr>
    </table>
  </td>
  </tr>
  </table>
</td></tr>
</form>
</table>
<%response.write ukong
 dim tmp1
  tmp1=vbcrlf&"<script language=javascript>"&_
            vbcrlf&"<!--"&_
            vbcrlf&"function recycle_clear()"&_
            vbcrlf&"{"&_
            vbcrlf&" if (click_return('清空所有的回收站主题',0))"&_
            vbcrlf&"{ location.href=""?fid="&Bbsid&"&action=clear""; }"&_
            vbcrlf&"}"&_
            vbcrlf&"-->"&_
            vbcrlf&"</script>"
response.write tmp1
  set obj_page=nothing
end sub

sub bbs_topic_type(t_id,t_bbs_id,t_topic,t_tim,t_username,t_re_username,t_re_tim,t_counter,t_re_counter,t_istop,t_islock,t_isgood,t_isvote,t_vote_num)
%>
<tr class=bbs_tr align=center>
<td><img src='<%response.write Cls.web_skindir%>Bbs/<%response.write bbs_topic_folder(t_re_counter,10,t_istop,t_isvote)%>.gif' border=0></td>
<td align=left><input type=checkbox name=sel_id value='<%response.write t_id%>' ><a href='View.asp?id=<%response.write t_id%>&recycle=yes' target=_blank title='<%response.write Cls.code_html(t_topic,1,0)&vbcrlf%>发表时间：<%response.write t_tim&vbcrlf%>最后回复：<%response.write t_re_username&vbcrlf%>回复时间：<%response.write t_re_tim%>'><%response.write Cls.code_html(t_topic,1,28)%></a><%response.write pagecute_topic(10,t_re_counter,"View.asp?id="&t_id)%></td>
<td><%response.write format_user_view(t_username,1,1)%></td>
<td><%response.write t_re_counter%></td>
<td><%
  if t_isvote=true then
    response.write "<font class=red>"&t_vote_num&"</font>"
  else
    response.write t_counter
  end if
%></td>
</tr>
<%
end sub
%>
