<!-- #include file="include/admin_onlogin.asp" -->
<%
admins=true
nsort="event"
index_url="forum"
data_name="bbs_topic"
tit_fir="主题"
tit="回收站管理"
dim ducou,f_id,numd,forumid,id_username
ducou=int(format_mid_num(24))
call format_search("topic","username,re_username",2,1)
call admin_header(0,0)
%>
<tr><td align=left colspan=2 height=30>
<table border=0><tr>
<td><a href='?'>删除<%response.write tit_fir%></a></td>
<td width=5> </td>
<td><a href='?action=revert'>还原<%response.write tit_fir%></a></td>
</tr></table>
</td></tr>
</table>
<%
call admin_table(1,0)

select case action
case "delete"
  call recycle_delete()
case "do_revert"
  call recycle_do_revert()
case "revert"
  call recycle_revert()
case else
  call recycle_main()
end select

call admin_ender(1)

sub recycle_delete()
  dim sel_id,ddim,dnum,ni
  sel_id=trim(request.form("sel_id"))
  sel_id=replace(sel_id," ","")
  if sel_id="" then
    call recycle_main()
    exit sub
  end if
  ddim=split(sel_id,",")
  dnum=ubound(ddim)
  ni=0
  for i=0 to dnum
    if isnumeric(ddim(i)) then
      call joekoe_cms.exec("delete from "&data_name&" where id="&ddim(i)&" and fixid=1",0)
      call joekoe_cms.exec("delete from bbs_data where reply_id="&ddim(i),0)
      call joekoe_cms.exec("delete from bbs_vote where reply_id="&ddim(i),0)   '删除投票
      ni=ni+1
    end if
  next
  call admin_msg("已成功删除 "&ni&" 条"&tit_fir&"！","?",1)
end sub

sub recycle_do_revert()
  dim sel_id,ddim,dnum,ni
  sel_id=trim(request.form("sel_id"))
  sel_id=replace(sel_id," ","")
  if sel_id="" then
    call recycle_main()
    exit sub
  end if
  ddim=split(sel_id,",")
  dnum=ubound(ddim)
  ni=0
  for i=0 to dnum
      sql="select count(id) from bbs_data where reply_id="&ddim(i)
      set rs=joekoe_cms.exec(sql,1)
      numd=rs(0)
      rs.close
    if isnumeric(ddim(i)) then
    call joekoe_cms.exec("update "&data_name&" set fixid=0 where id="&ddim(i),0)
      sql="select forum_id,username from bbs_data where id="&ddim(i)
      set rs=joekoe_cms.exec(sql,1)
      forumid=rs(0)
      id_username=rs(1)
      rs.close
    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

      ni=ni+1
    end if
  next
  call admin_msg("已成功还原 "&ni&" 条"&tit_fir&"！","?action=revert",1)
end sub

sub recycle_revert()
  dim topic,tim
%>
<form name=sel_form action='?action=do_revert' method=post>
<tr align=center>
<td class=td width='6%'>序号</td>
<td class=td width='12%'>所属版面</td>
<td class=td width='12%'>发贴者</td>
<td class=td width='41%'>贴子主题</td>
<td class=td width='15%'>发贴时间</td>
<td class=td width='8%'>浏览</td>
<td class=td width='6%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
</tr>
<%
  sql="select count(id) from "&data_name&sql_add&" where fixid=1"
  set rs=joekoe_cms.exec(sql,1)
  rssum=rs(0)
  rs.close
  call format_pagecute()
  sql="select top "&nummer*viewpage&" * from "&data_name&sql_add&" where fixid=1 order by id desc"
  call joekoe_cms.exec(sql,-1)
  rs.open sql,conn,1,1
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  if int(viewpage*nummer)>int(rssum) then nums=nummer-(viewpage*nummer-rssum)
  for i=1 to nums
    topic=rs("topic")
    tim=rs("tim")
    f_id=rs("forum_id")
%>
<tr align=center>
<td><%response.write (viewpage-1)*nummer+i%></td>
<td>
<%
  dim sql1,rs1
  sql1="select forum_name from bbs_forum where forum_id="&f_id&""
  set rs1=joekoe_cms.exec(sql1,1)
  response.write rs1(0)
  rs1.close
%>
</td>
<td><%response.write rs("username")%></td>
<td align=left alt='详细内容：<%response.write joekoe_cms.code_html(topic,1,0)%>' ><%response.write joekoe_cms.code_html(topic,1,30)%></td>
<td><font alt='发贴时间：<%response.write joekoe_cms.time_type(tim,2)%>'><%response.write joekoe_cms.time_type(tim,3)%></font></td>
<td><%response.write rs("counter")%></td>
<td><input type=checkbox name=sel_id value='<%response.write rs("id")%>'></td>
</tr>
<%
    rs.movenext
  next
  rs.close
%>
<tr class=tr1>
<td colspan=4>
现有<font class=red><%response.write rssum%></font>条<%response.write tit_fir%>，
每页<font class=red><%response.write nummer%></font>条，
页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font>
分页：<%response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%>
</td>
<td colspan=3 align=center>
执行
<select name=sel_type size=1>
<option value='revert'>还原</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);">
</td>
</tr>
</form>
<%
end sub

sub recycle_main()
dim topic,tim
%>
<form name=sel_form action='?action=delete' method=post>
<tr align=center>
<td class=td width='6%'>序号</td>
<td class=td width='12%'>所属版面</td>
<td class=td width='12%'>发贴者</td>
<td class=td width='41%'>贴子主题</td>
<td class=td width='15%'>发贴时间</td>
<td class=td width='8%'>浏览</td>
<td class=td width='6%'><input type=checkbox name=sel_all value='yes' onclick="javascript:select_all(this.form);"></td>
</tr>
<%
  sql="select count(id) from "&data_name&sql_add&" where fixid=1"
  set rs=joekoe_cms.exec(sql,1)
  rssum=rs(0)
  rs.close
  call format_pagecute()
  sql="select top "&nummer*viewpage&" * from "&data_name&sql_add&" where fixid=1 order by id desc"
  call joekoe_cms.exec(sql,-1)
  rs.open sql,conn,1,1
  if int(viewpage)>1 then rs.move (viewpage-1)*nummer
  if int(viewpage*nummer)>int(rssum) then nums=nummer-(viewpage*nummer-rssum)
  for i=1 to nums
    topic=rs("topic")
    tim=rs("tim")
    f_id=rs("forum_id")
%>
<tr align=center>
<td><%response.write (viewpage-1)*nummer+i%></td>
<td>
<%
  dim sql1,rs1
  sql1="select forum_name from bbs_forum where forum_id="&f_id&""
  set rs1=joekoe_cms.exec(sql1,1)
  response.write rs1(0)
  rs1.close
%>
</td>
<td><%response.write rs("username")%></td>
<td align=left alt='详细内容：<%response.write joekoe_cms.code_html(topic,1,0)%>'><%response.write joekoe_cms.code_html(topic,1,30)%></td>
<td><font alt='发贴时间：<%response.write joekoe_cms.time_type(tim,2)%>'><%response.write joekoe_cms.time_type(tim,3)%></font></td>
<td><%response.write rs("counter")%></td>
<td><input type=checkbox name=sel_id value='<%response.write rs("id")%>'></td>
</tr>
<%
    rs.movenext
  next
  rs.close
%>
<tr class=tr1>
<td colspan=4>
现有<font class=red><%response.write rssum%></font>条<%response.write tit_fir%>，
每页<font class=red><%response.write nummer%></font>条，
页次：<font class=red><%response.write viewpage%></font>/<font class=red><%response.write thepages%></font>
分页：<%response.write jk_pagecute(nummer,thepages,viewpage,pageurl,5,"#ff0000")%>
</td>
<td colspan=3 align=center>
执行
<select name=sel_type size=1>
<option value='delete'>删除</option>
</select>
<input type=submit value='操作' onclick="return sel_click(this.form);">
</td>
</tr>
</form>
<%
end sub
%>