<!-- #include file="include/admin_onlogin.asp" -->
<%
dim classid,forumid,ddim
classid=trim(request.querystring("class_id"))
forumid=trim(request.querystring("forum_id"))
if not(isnumeric(classid)) then classid=0
if not(isnumeric(forumid)) then forumid=0

index_url="forum"
call admin_master(0,0)
tit_fir="论坛"
tit="论坛管理"

call admin_header(0,0)
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?'>管理首页</a></td>
  <td width=10></td>
  <td><a href='?action=add'>添加新论坛</a></td>
  <td width=10></td>
  <td><a href='?action=mod'>合并论坛数据</a></td>
  <td width=10></td>
  <td><a href='?action=order'>重新计数排序</a></td>
  <td width=10></td>
  <td><a href='?action=event'>清理论坛日记</a></td>
  <!--
  <td width=10></td>
  <td><a href='?action=delete'>批量删除数据</a></td>
  -->
<% call joekoe_is_js("",tit_fir) %>
  </tr>
  </table>
</td></tr>
</table>
<%
if action="mod" or action="add" or action="edit" then
  call admin_table(1,1)
else
  call admin_table(1,0)
end if

select case action
case "js"
  call forum_js()
case "del"
  call forum_del()
case "mod"
  call forum_mod()
case "event"
  call forum_event()
case "restore"
  call forum_restore()
case "order"
  call forum_order()
case "orders"
  call forum_orders()
case "add"
  call forum_add()
case "edit"
  call forum_edit()
case else
  call forum_main()
end select

call admin_ender(1)

sub forum_js()
  dim file_name,temp1,fi,fnum,total_num
  file_name="style/data_forum.asp"
  fi=0
  fnum=0
  sql="select count(forum_id) from bbs_forum where forum_hidden=0"
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then
    total_num=int(rs(0))
    if total_num>0 then total_num=total_num-1
  end if
  rs.close
  sql="select class_id,forum_id,forum_star,forum_name from bbs_forum where forum_hidden=0 order by class_id,forum_order"
  call joekoe_cms.exec(sql,-1)
  rs.open sql,conn,1,1
  if not rs.eof then
    fnum=rs.recordcount
  end if
  temp1=temp1&"<"&"%" & _
        vbcrlf&"dim forum_list_sorts("&total_num&")"
  for fi=0 to fnum-1
    temp1=temp1&vbcrlf&"forum_list_sorts("&fi&")="""&rs("forum_id")&"|"&rs("class_id")&"|"&rs("forum_star")&"|"&rs("forum_name")&""""
    rs.movenext
  next
  rs.close
  temp1=temp1&vbcrlf&"%"&">"
  call create_file(file_name,temp1)
  call admin_msg("成功更新了论坛分类数据！","?",1)
end sub

sub forum_del()
  dim num_topic,num_data,fparent
  sql="select top 1 forum_parent from bbs_forum where forum_id="&forumid
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call admin_msg("要删除的论坛ID（"&forumid&"）不存！","?",1)
    exit sub
  end if
  fparent=rs("forum_parent")
  rs.close
  sql="select count(forum_id) from bbs_forum where forum_f="&forumid
  set rs=joekoe_cms.exec(sql,1)
  if rs(0)>0 then
    rs.close
    call admin_msg("要删除的论坛ID（"&forumid&"）含有下级论坛！请先删除下级论坛。","?",1)
    exit sub
  end if
  rs.close
  sql="select count(id) from bbs_topic where forum_id="&forumid
  set rs=joekoe_cms.exec(sql,1)
  num_topic=rs(0)
  rs.close
  sql="select count(id) from bbs_data where forum_id="&forumid
  set rs=joekoe_cms.exec(sql,1)
  num_data=rs(0)
  rs.close
  sql="delete from bbs_topic where forum_id="&forumid
  call joekoe_cms.exec(sql,0)
  sql="delete from bbs_data where forum_id="&forumid
  call joekoe_cms.exec(sql,0)
  sql="delete from bbs_forum where forum_id="&forumid
  call joekoe_cms.exec(sql,0)
  if var_null(fparent)<>"" then
    sql="update bbs_forum set forum_n=forum_n-1,forum_topic_num=forum_topic_num-"&num_topic&",forum_data_num=forum_data_num-"&num_data&" where forum_id in("&fparent&")"
    call joekoe_cms.exec(sql,0)
  end if
  sql="update configs set num_topic=num_topic-"&num_topic&",num_data=num_data-"&num_data
  call joekoe_cms.exec(sql,0)
  if isarray(application(joekoe_cms.web_cookies&"_configs")) then
    application.lock
    application(joekoe_cms.web_cookies&"_configs")(1,0)=application(joekoe_cms.web_cookies&"_configs")(1,0)-num_topic
    application(joekoe_cms.web_cookies&"_configs")(2,0)=application(joekoe_cms.web_cookies&"_configs")(2,0)-num_data
    application.unlock
  end if
  call admin_msg("成功删除论坛ID（"&forumid&"）！","?",1)
end sub

sub forum_event()
  dim data_type,clear_msg
  call admin_td("清理论坛日记")
  if joekoe_cms.chk() then
    data_type=trim(request.form("data_type"))
    select case data_type
    case "all"
      sql="delete from bbs_event"
      clear_msg="所有"
    case "week"
      sql="delete from bbs_event where datediff("&s_d&"d"&s_d&",tim,"&s_tim&")>7"
      clear_msg="一周前"
    case else	'"month"
      sql="delete from bbs_event where datediff("&s_d&"d"&s_d&",tim,"&s_tim&")>30"
      clear_msg="一个月前"
    end select
    call joekoe_cms.exec(sql,0)
    call admin_msg("已成功清理了"&clear_msg&"的论坛日记！",pageurl&"action="&action,1)
    exit sub
  end if
  call form_first()
%>
<form name=event_frm action='<%response.write pageurl%>action=<%response.write action%>' method=post>
<input type=hidden name=chk value='yes'>
<td width='20%' class=htd>注意：<br>清除后将不能再恢复</td>
<td width='80%'>
  <table border=0>
  <tr><td><input type=radio name=data_type value='month' checked>&nbsp;清除一个月前的论坛日记</td></tr>
  <tr><td><input type=radio name=data_type value='week'>&nbsp;清除一周前的论坛日记</td></tr>
  <tr><td><input type=radio name=data_type value='all'>&nbsp;清除所有的论坛日记</td></tr>
  </table>
</td>
</tr>
<tr>
<td></td>
<td><input type=submit value='执行清除操作' onclick="javascript:return click_return('执行清除操作',0);"></td>
</form>
<%
end sub

sub forum_restore()
  dim forumparent,forumw,forumn,forumtopicnum,forumdatanum,forumnewinfo,forumnewnum,frs,fsql,nforumid,ntopic
  sql="select top 1 forum_parent,forum_w from bbs_forum where forum_id="&forumid
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call admin_msg("要进行数据修复的论坛ID（"&forumid&"）不存！","?",1)
    exit sub
  end if
  forumparent=rs("forum_parent")
  forumw=rs("forum_w")
  rs.close
  forumn=0
  forumtopicnum=0
  forumdatanum=0
  forumnewinfo=""
  forumnewnum=0
  if not forumw then
    sql="select forum_id,forum_topic_num,forum_data_num,forum_new_num from bbs_forum where forum_hidden=0 and left(forum_parent,"&(len(forumparent)+1)&")='"&forumparent&",'"
    set rs=joekoe_cms.exec(sql,1)
    do while not rs.eof
      nforumid=rs(0)
      forumn=forumn+1
      forumtopicnum=forumtopicnum+rs(1)
      forumdatanum=forumdatanum+rs(2)
      forumnewnum=forumnewnum+rs(3)
      rs.movenext
    loop
    rs.close
  end if
  if int(forumn)=0 then
    sql="select count(id) from bbs_topic where forum_id="&forumid
    set rs=joekoe_cms.exec(sql,1)
    forumtopicnum=forumtopicnum+rs(0)
    rs.close
    sql="select count(id) from bbs_data where forum_id="&forumid
    set rs=joekoe_cms.exec(sql,1)
    forumdatanum=forumdatanum+rs(0)
    rs.close
    sql="select count(id) from bbs_data where forum_id="&forumid&" and tim>#"&joekoe_cms.time_type(joekoe_cms.now_time,4)&" 00:00:00#"
    set rs=joekoe_cms.exec(sql,1)
    forumnewnum=forumnewnum+rs(0)
    rs.close
  end if
  response.write 3
  sql="select top 1 id,topic,username,tim from bbs_topic where forum_id="&forumid&" order by re_tim desc"
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then
    ntopic=rs("topic")
    ntopic=replace(ntopic,"'","")
    ntopic=replace(ntopic,"|","")
    forumnewinfo=rs("username")&"|"&rs("tim")&"|"&rs("id")&"|"&ntopic
  end if
  rs.close
  sql="update bbs_forum set forum_topic_num="&forumtopicnum&",forum_data_num="&forumdatanum&",forum_new_info='"&forumnewinfo&"',forum_new_num="&forumnewnum&" where forum_id="&forumid
  response.write sql
  call joekoe_cms.exec(sql,0)
  call admin_msg("成功对论坛（ID："&forumid&"）进行了数据修复！","?",1)
end sub

sub forum_order()

  if trim(request.querystring("chk"))<>"yes" then
    call admin_td("重新计数排序")
%>
<tr>
<td>注意：</td>
<td height=60 class=htd>现在正在执行重新计算所有论坛计数、所属下级论坛、论坛排序等操作；<br>根据您的服务器情况可能会执行一到两秒钟左右的时间，请在些期间不要关闭本页！</td>
</tr>
<tr><td height=40 colspan=2 align=center><input type=button value='执行重新计数排序操作' onclick="javascript:location.href='?action=order&chk=yes';"></td></tr>
<%
    exit sub
  end if
  dim star_min
  sql="select top 1 forum_star from bbs_forum order by forum_star"
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call admin_msg("暂时还没有论坛分类！","?",1)
    exit sub
  end if
  star_min=rs(0)
  rs.close
  if not isnumeric(star_min) then star_min=0
  if int(star_min)>0 then
    call admin_msg("论坛分类出现严重错误！请与开发人员联系。","?",1)
    exit sub
  end if
  classid=1
  sql="select forum_id,class_id from bbs_forum where forum_star="&star_min&" order by class_id,forum_id"
  set rs=joekoe_cms.exec(sql,1)
  do while not rs.eof
    forumid=rs("forum_id")
    call joekoe_cms.exec("update bbs_forum set class_id="&classid&",forum_f=0,forum_n=0,forum_order=0,forum_star=0,forum_parent='"&forumid&"' where forum_id="&forumid,0)
    call forum_order_board(classid,forumid,1,forumid,1,1)
    rs.movenext
    classid=classid+1
  loop
  rs.close
  call admin_msg("成功对所有论坛进行了重新计数排序！","?",1)
end sub

sub forum_order_board(cid,fid,fstar,fparent,forder,fh)
  dim rsb,sqlb,nfid,ffp,fhh,nf_id,nf_topic,nf_username,nf_tim
  ffp=fparent&","
  if fparent="" then
    ffp=""
  end if
  sqlb="select forum_id,forum_star,forum_hidden,forum_topic_num,forum_data_num from bbs_forum where forum_f="&fid&" order by forum_order,forum_id"
  set rsb=joekoe_cms.exec(sqlb,1)
  do while not rsb.eof
    fhh=fh
    nfid=rsb("forum_id")
    nf_id=""
    nf_topic=""
    nf_username=""
    nf_tim=""
    call joekoe_cms.exec("update bbs_forum set class_id="&cid&",forum_f="&fid&",forum_n=0,forum_order="&forder&",forum_star="&fstar&",forum_parent='"&ffp&nfid&"' where forum_id="&nfid,0)
    forder=forder+1
    if rsb("forum_hidden")=true then fhh=0
    if int(fhh)=1 then
      call joekoe_cms.exec("update bbs_forum set forum_n=forum_n+1 where class_id="&cid&" and forum_id in("&fparent&")",0)
    end if
    call forum_order_board(cid,nfid,fstar+1,ffp&nfid,forder,fhh)
    rsb.movenext
  loop
  rsb.close
  set rsb=nothing
end sub

sub forum_orders()
  dim star_min,actions,forumf,forumorder,forumstar,forumparent,num1,num2,num3
  actions=trim(request.querystring("actions"))
  if forumid<1 or (actions<>"up" and actions<>"down") then
    call admin_msg("论坛排序参数出错！","?",1)
    exit sub
  end if
  sql="select top 1 class_id,forum_f,forum_order,forum_star,forum_parent from bbs_forum where forum_id="&forumid
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call admin_msg("论坛ID（"&forumid&"）不存在！","?",1)
    exit sub
  end if
  classid=rs("class_id")
  forumf=rs("forum_f")
  forumorder=rs("forum_order")
  forumstar=rs("forum_star")
  forumparent=rs("forum_parent")
  rs.close
  sql="select top 1 forum_star from bbs_forum order by forum_star"
  set rs=joekoe_cms.exec(sql,1)
  star_min=rs(0)
  rs.close
  if int(forumstar)=int(star_min) then
    num1=classid
    sql="select top 1 class_id from bbs_forum where class_id>"&classid&" order by class_id"
    if actions="up" then
      sql="select top 1 class_id from bbs_forum where class_id<"&classid&" order by class_id desc"
    end if
    set rs=joekoe_cms.exec(sql,1)
    if rs.eof then
      rs.close
      call forum_main()
      exit sub
    end if
    num2=rs(0)
    rs.close
    sql="select top 1 class_id from bbs_forum order by class_id desc"
    set rs=joekoe_cms.exec(sql,1)
    num3=rs(0)+10000
    rs.close
    sql="update bbs_forum set class_id="&num3&" where class_id="&classid
    call joekoe_cms.exec(sql,0)
    sql="update bbs_forum set class_id="&classid&" where class_id="&num2
    call joekoe_cms.exec(sql,0)
    sql="update bbs_forum set class_id="&num2&" where class_id="&num3
    call joekoe_cms.exec(sql,0)
    call forum_main()
    exit sub
  end if
  dim forumid2,forumorder2,forumparent2,forder1,forder2
  sql="select top 1 forum_id,forum_order,forum_parent from bbs_forum where class_id="&classid&" and forum_f="&forumf&" and forum_star="&forumstar&" and forum_id<>"&forumid&" and forum_order>"&forumorder&" order by forum_order"
  if actions="up" then
    sql="select top 1 forum_id,forum_order,forum_parent from bbs_forum where class_id="&classid&" and forum_f="&forumf&" and forum_star="&forumstar&" and forum_id<>"&forumid&" and forum_order<"&forumorder&" order by forum_order desc"
  end if
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call forum_main()
    exit sub
  end if
  forumid2=rs("forum_id")
  forumorder2=rs("forum_order")
  forumparent2=rs("forum_parent")
  rs.close
  sql="select top 1 forum_order from bbs_forum where class_id="&classid&" and ( left(forum_parent,"&len(forumparent2)+1&")='"&forumparent2&",' or forum_id="&forumid2&" ) order by forum_order desc"
  set rs=joekoe_cms.exec(sql,1)
  forder2=rs(0)
  rs.close
  sql="select top 1 forum_order from bbs_forum where class_id="&classid&" and ( left(forum_parent,"&len(forumparent)+1&")='"&forumparent&",' or forum_id="&forumid&" ) order by forum_order desc"
  set rs=joekoe_cms.exec(sql,1)
  forder1=rs(0)
  rs.close
  num1=forder1-forumorder+1
  num2=forder2-forumorder2+1
  sql="update bbs_forum set forum_order=forum_order"
  if actions="up" then
    sql=sql&"-"
  else
    sql=sql&"+"
  end if
  sql=sql&num2&" where left(forum_parent,"&len(forumparent)+1&")='"&forumparent&",' or forum_id="&forumid
  call joekoe_cms.exec(sql,0)
  sql="update bbs_forum set forum_order=forum_order"
  if actions="up" then
    sql=sql&"+"
  else
    sql=sql&"-"
  end if
  sql=sql&num1&" where left(forum_parent,"&len(forumparent2)+1&")='"&forumparent2&",' or forum_id="&forumid2
  call joekoe_cms.exec(sql,0)
  call forum_main()
end sub

sub forum_edit()
  dim funder,ftrue,fir_true,forumname,forumtype,forumpro,forumstar,forumparent,forumorder,fparent,forumhidden,fhidden,rs2,forumf,forumid2,classid2,fhn,forumconfig
  fhidden=false
  funder=false
  ftrue=false
  fir_true=false
  sql="select count(forum_id) from bbs_forum where forum_f="&forumid
  set rs=joekoe_cms.exec(sql,1)
  if int(rs(0))>0 then funder=true
  rs.close
  sql="select top 1 * from bbs_forum where forum_id="&forumid
  call joekoe_cms.exec(sql,-1)
  rs.open sql,conn,1,3
  if rs.eof then
    rs.close
    call admin_msg("论坛ID（"&forumid&"）不存在！","?",1)
    exit sub
  end if
  forumname=rs("forum_name")
  if cstr(rs("forum_star"))="0" and cstr(rs("forum_star"))="0" then fir_true=true
  call admin_td("编辑论坛（"&forumname&"）信息")
  if chk() then
    classid=rs("class_id")
    forumf=rs("forum_f")
    forumparent=rs("forum_parent")
    forumhidden=rs("forum_hidden")
    forumid2=trim(request.form("forum_id"))
    if not(isnumeric(forumid2)) then forumid2=forumid
    forumname=code_admin("forum_name",1,20)
    forumtype=trim(request.form("forum_type"))
    if not(isnumeric(forumtype)) then forumtype=0
    forumpro=trim(request.form("forum_pro"))
    if not(isnumeric(forumpro)) then forum_pro=0
	forumconfig=trim(request.form("forum_config")) 
    if int(forumpro)<>1 and int(forumpro)<>2 then forumpro=0
    if forumname="" then
      rs.close
      call admin_error("论坛名称不能为空！")
      exit sub
    end if
    if int(forumid2)<>int(forumid) and int(forumid2)<>int(forumf) and funder=false then
      ftrue=true
      sql="select top 1 class_id,forum_star,forum_parent,forum_hidden from bbs_forum where forum_id="&forumid2
      set rs2=joekoe_cms.exec(sql,1)
      if rs2.eof then
        rs2.close
        set rs2=nothing
        rs.close
        call admin_msg("要更改所属的父级论坛ID（"&forumid2&"）不存在！","?",1)
        exit sub
      end if
      classid2=rs2("class_id")
      forumstar=rs2("forum_star")
      fparent=rs2("forum_parent")
      fhidden=rs2("forum_hidden")
      rs2.close
      forumorder=0
      sql="select max(forum_order) from bbs_forum where class_id="&classid2
      set rs2=joekoe_cms.exec(sql,1)
      if not rs2.eof then forumorder=rs2(0)
      rs2.close
      rs("forum_order")=forumorder+1
      rs("forum_star")=forumstar+1
      'sql="select top 1 forum_order,forum_star from bbs_forum where class_id="&classid2&" and ( left(forum_parent,"&len(fparent)+1&")='"&fparent&",') order by forum_order desc"
      'set rs2=joekoe_cms.exec(sql,1)
      'if not rs2.eof then
      '  forumorder=rs2("forum_order")
      '  rs("forum_order")=forumorder
      '  rs("forum_star")=rs2("forum_star")
      'end if
      'rs2.close
      set rs2=nothing
      call joekoe_cms.exec("update bbs_forum set forum_order=forum_order+1 where class_id="&classid2&" and forum_order>"&forumorder,0)
      rs("class_id")=classid2
      rs("forum_f")=forumid2
      rs("forum_n")=0
      rs("forum_parent")=fparent&","&forumid
    else
      if not fir_true then
        sql="select top 1 forum_hidden from bbs_forum where forum_id="&forumf
        set rs2=joekoe_cms.exec(sql,1)
        if rs2.eof then
          rs2.close
          call admin_msg("所属的父级论坛ID（"&forumf&"）不存在！","?",1)
          exit sub
        end if
        fhidden=rs2("forum_hidden")
        rs2.close
      end if
    end if
    if fhidden=false and trim(request.form("forum_hidden"))<>"no" then fhidden=true
    if trim(request.form("forum_w"))="yes" then
      rs("forum_w")=true
    else
      rs("forum_w")=false
    end if
    rs("forum_name")=forumname
    rs("forum_pic")=code_admin("forum_pic",1,50)
    rs("forum_hidden")=fhidden
    rs("forum_pro")=forumpro
    rs("forum_type")=forumtype
    rs("forum_remark")=code_admin("forum_remark",1,250)
    rs("forum_power")=code_admin("forum_power",1,50)
	if forumconfig<>"" then rs("forum_config")=forumconfig 
    rs.update
    rs.close
    if ftrue=true then
      call joekoe_cms.exec("update bbs_forum set forum_n=forum_n-1 where class_id="&classid&" and forum_id in ("&forumparent&")",0)
    end if
    if ftrue=false and forumhidden<>fhidden then
      if forumhidden=true then
        call joekoe_cms.exec("update bbs_forum set forum_n=forum_n+1 where class_id="&classid&" and forum_id in ("&forumparent&") and forum_id<>"&forumid,0)
      else
        fhn=1
        sql="select count(forum_id) from bbs_forum where class_id="&classid&" and ( left(forum_parent,"&len(forumparent)+1&")='"&forumparent&",')"
        set rs=joekoe_cms.exec(sql,1)
        fhn=fhn+rs(0)
        rs.close
        call joekoe_cms.exec("update bbs_forum set forum_n=forum_n-"&fhn&" where class_id="&classid&" and forum_id in ("&forumparent&")",0)
        call joekoe_cms.exec("update bbs_forum set forum_hidden=1 where class_id="&classid&" and ( left(forum_parent,"&len(forumparent)+1&")='"&forumparent&",')",0)
      end if
    end if
    if fhidden=false and len(fparent)>0 then
      call joekoe_cms.exec("update bbs_forum set forum_n=forum_n+1 where class_id="&classid2&" and forum_id in ("&fparent&")",0)
    end if
    call admin_msg("成功编辑了论坛（"&forumname&"）信息！","?",1)
    exit sub
  end if
  call form_first()
  forumtype=rs("forum_type")
  forumpro=rs("forum_pro")
  forumhidden=rs("forum_hidden")
  forumconfig=rs("forum_config") 
%>
<form action='?action=edit&forum_id=<%response.write forumid%>' method=post>
<input type=hidden name='chk' value='yes'>
<tr><td>论坛名称：</td><td><input type=text name=forum_name value='<%response.write forumname%>' size=30 maxlength=20></td></tr>
<tr><td>所属分类：</td><td><%
  if funder=true then
    response.write "<font class=red2>本论坛有下级论坛，不可更改所属分类</font><input type=hidden name=forum_id value='"&forumid&"'>"
  else
    if forumhidden then
      response.write "<font class=red>本论坛隐藏论坛，不可更改所属分类</font><input type=hidden name=forum_id value='"&forumid&"'>"
    else
      call forum_add_edit_list(forumid)
    end if
  end if
%></td></tr>
<%if rs("forum_f")=0 then%> 
  <tr><td>分类样式：</td><td><input type=radio name=forum_config value='1'<%if int(forumconfig)=1 then response.write " checked"%>>正常 <input type=radio name=forum_config value='2'<%if int(forumconfig)=2 then response.write " checked"%>>简洁(2列) <input type=radio name=forum_config value='3'<%if int(forumconfig)=3 then response.write " checked"%>>简洁(3列)</td></tr> 
 <%end if%>
<tr><td>论坛类型：</td><td><select name=forum_type size=1><%
  ddim=split(web_dim(21),"|")
  for i=0 to ubound(ddim)
    response.write vbcrlf&"<option value='"&i+1&"'"
    if int(forumtype)=(i+1) then response.write " selected"
    response.write ">"&right(ddim(i),len(ddim(i))-instr(ddim(i),":"))&"</option>"
  next
  erase ddim
%></select></td></tr>
<tr><td>开放隐藏：</td><td><input type=checkbox name=forum_hidden value='no'<%if forumhidden=false then response.write " checked"%>>&nbsp;（选上为开放，否则为隐藏）</td></tr>
<tr><td>论坛属性：</td><td><input type=radio name=forum_pro value='0'<%if int(forumpro)<>1 then response.write " checked"%>>正常&nbsp;<input type=radio name=forum_pro value='1'<%if int(forumpro)=1 then response.write " checked"%>>只读</td></tr>
<tr><td>发贴模式：</td><td><input type=checkbox name=forum_w value='yes'<%if rs("forum_w")=true then response.write " checked"%>>&nbsp;（选上为可以发表新的主题）</td></tr>
<tr><td>论坛图片：</td><td><input type=text name=forum_pic value='<%response.write rs("forum_pic")%>' size=30 maxlength=20> 例：<a title='代表 images/forum/sample.gif 这个图片<br>也可以直接填写图片的URL地址'>$sample.gif</a> （绝对地址也可以）</td></tr>
<tr><td>论坛版主：</td><td><input type=text name=forum_power value='<%response.write rs("forum_power")%>' size=50 maxlength=50><br>多个请用“|”分开，如：“joekoe|super1|andy”</td></tr>
<tr><td>论坛说明：<br><br><=250字</td><td><textarea name=forum_remark rows=5 cols=50><%response.write joekoe_cms.code_word(rs("forum_remark"))%></textarea></td></tr>
<%
  call submit_edit()
  rs.close
end sub

sub forum_add_edit_list(fid)
  dim temp1,nfid,ncid,forumn,rsf,sqlf
  ncid=0
  temp1="<select name=forum_id size=1><option value='0'>将本论坛作为主论坛分类</option>"
  sqlf="select forum_id,class_id,forum_name,forum_n,forum_w,forum_star,forum_hidden,forum_pro from bbs_forum order by class_id,forum_order,forum_star"
  set rsf=joekoe_cms.exec(sqlf,1)
  do while not rsf.eof
    classid=rsf("class_id")
    nfid=rsf("forum_id")
    if int(ncid)<>int(classid) then
      temp1=temp1&vbcrlf&"<option class=bg_2 value='"&nfid&"'"
      if int(nfid)=int(fid) then temp1=temp1&" selected"
      temp1=temp1&">╋"&rsf("forum_name")&"</option>"
      ncid=classid
    else
      forumn=rsf("forum_n")
      temp1=temp1&vbcrlf&"<option value='"&nfid&"'"
      if int(nfid)=int(fid) then temp1=temp1&" selected"
      temp1=temp1&">"
      for i=1 to rsf("forum_star")-1
        temp1=temp1&"│"
      next
      temp1=temp1&"├"&rsf("forum_name")
      if rsf("forum_w")=false then temp1=temp1&" <不可发贴>"
      if rsf("forum_hidden")=true then temp1=temp1&" <隐>"
      if rsf("forum_pro")=1 then temp1=temp1&" <只读>"
      temp1=temp1&"</option>"
    end if
    rsf.movenext
  loop
  rsf.close
  set rsf=nothing
  temp1=temp1&"</select>"
  response.write temp1
end sub

sub forum_add()
  call admin_td("添加新论坛")
  dim forumname,forumf,forumstar,forumparent,forumorder,forumtype,forumpro,fhidden,fo_id
  classid=1
  sql="select top 1 class_id from bbs_forum order by class_id"
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then classid=rs(0)-1
  rs.close
  forumparent=""
  forumorder=-1
  forumf=0
  fhidden=false
  if chk() then
    classid=0
    forumid=trim(request.form("forum_id"))
    if not int_true(forumid) then forumid=0
    if int(forumid)<1 then
      sql="select top 1 class_id from bbs_forum order by class_id desc"
      set rs=joekoe_cms.exec(sql,1)
      if not rs.eof then classid=rs(0)
      rs.close
      classid=classid+1
    else
      sql="select top 1 class_id,forum_order,forum_star,forum_parent,forum_hidden from bbs_forum where forum_id="&forumid
      set rs=joekoe_cms.exec(sql,1)
      if rs.eof then
        rs.close
        call admin_msg("所属分类论坛ID（"&forumid&"）不存在！","?",1)
        exit sub
      end if
      classid=rs("class_id")
      forumorder=rs("forum_order")
      forumstar=rs("forum_star")
      forumparent=rs("forum_parent")
      fhidden=rs("forum_hidden")
      rs.close
      forumf=forumid
      fo_id=forumid
      sql="select top 1 forum_id,forum_order from bbs_forum where left(forum_parent,"&(len(forumparent)+1)&")='"&forumparent&",' order by forum_order desc"
      set rs=joekoe_cms.exec(sql,1)
      if not rs.eof then
        fo_id=rs(0)
        forumorder=rs(1)
      end if
      rs.close
    end if
    forumname=code_admin("forum_name",1,20)
    forumtype=trim(request.form("forum_type"))
    if not(isnumeric(forumtype)) then forumtype=0
    forumpro=trim(request.form("forum_pro"))
    if not(isnumeric(forumpro)) then forumpro=0
    if int(forumpro)<>1 and int(forumpro)<>2 then forumpro=0
    if fhidden=false then
      if trim(request.form("forum_hidden"))<>"no" then fhidden=true
    end if
    if forumname="" then
      call admin_error("论坛名称不能为空！")
      exit sub
    end if
    if int(forumid)>0 then
      sql="select top 1 forum_order from bbs_forum where class_id="&classid&" and forum_f="&fo_id&" order by forum_order desc"
      set rs=joekoe_cms.exec(sql,1)
      if not rs.eof then forumorder=rs(0)
      rs.close
      if int(forumid)>0 then call joekoe_cms.exec("update bbs_forum set forum_order=forum_order+1 where class_id="&classid&" and forum_order>"&forumorder,0)
    end if
    sql="select * from bbs_forum"
    call joekoe_cms.exec("",-1)
    rs.open sql,conn,1,3
    rs.addnew
    rs("class_id")=classid
    rs("forum_order")=forumorder+1
    rs("forum_f")=forumf
    rs("forum_n")=0
    if trim(request.form("forum_w"))="yes" then
      rs("forum_w")=true
    else
      rs("forum_w")=false
    end if
    if int(forumf)=0 then
      rs("forum_star")=0
    else
      rs("forum_star")=forumstar+1
    end if
    rs("forum_name")=forumname
    rs("forum_remark")=code_admin("forum_remark",1,250)
    rs("forum_power")=code_admin("forum_power",1,50)
    rs("forum_pic")=code_admin("forum_pic",1,50)
    rs("forum_hidden")=fhidden
    rs("forum_pro")=forumpro
    rs("forum_type")=forumtype
    rs("forum_new_num")=0
    rs("forum_topic_num")=0
    rs("forum_data_num")=0
    rs("forum_new_info")="|||"
    rs("forum_config")=1
    rs.update
    rs.close
    dim firid
    firid=first_id("bbs_forum","forum_id")
    if var_null(forumparent)<>"" then
      call joekoe_cms.exec("update bbs_forum set forum_parent='"&forumparent&","&firid&"' where forum_id="&firid,0)
    else
      call joekoe_cms.exec("update bbs_forum set forum_parent='"&firid&"' where forum_id="&firid,0)
    end if
    if fhidden=false and var_null(forumparent)<>"" then
      call joekoe_cms.exec("update bbs_forum set forum_n=forum_n+1 where class_id="&classid&" and forum_id in ("&forumparent&")",0)
    end if
    call admin_msg("成功添加一个新的论坛（"&forumname&"）！","?",1)
    exit sub
  end if
  call form_first()
%>
<form action='?action=add&forum_id=<%response.write forumid%>' method=post>
<input type=hidden name='chk' value='yes'>
<tr><td>论坛名称：</td><td><input type=text name=forum_name size=30 maxlength=20></td></tr>
<tr><td>所属分类：</td><td><%call forum_add_edit_list(forumid)%></td></tr>
<tr><td>论坛类型：</td><td><select name=forum_type size=1><%
  ddim=split(web_dim(21),"|")
  for i=0 to ubound(ddim)
    response.write vbcrlf&"<option value='"&i+1&"'>"&right(ddim(i),len(ddim(i))-instr(ddim(i),":"))&"</option>"
  next
  erase ddim
%></select></td></tr>
<tr><td>开放隐藏：</td><td><input type=checkbox name=forum_hidden value='no' checked>&nbsp;（选上为开放，否则为隐藏）</td></tr>
<tr><td>论坛属性：</td><td><input type=radio name=forum_pro value='0' checked>正常&nbsp;<input type=radio name=forum_pro value='1'>只读</td></tr>
<tr><td>发贴模式：</td><td><input type=checkbox name=forum_w value='yes' checked>&nbsp;（选上为可以发表新的主题）</td></tr>
<tr><td>论坛图片：</td><td><input type=text name=forum_pic value='' size=30 maxlength=20> 例：<a title='代表 images/forum/sample.gif 这个图片<br>也可以直接填写图片的URL地址'>$sample.gif</a> （绝对地址也可以）</td></tr>
<tr><td>论坛版主：</td><td><input type=text name=forum_power size=50 maxlength=50><br>多个请用“|”分开，如：“joekoe|super1|andy”</td></tr>
<tr><td>论坛说明：<br><br><=250字</td><td><textarea name=forum_remark rows=5 cols=50></textarea></td></tr>
<%
  call submit_add()
end sub

sub forum_main()
  dim classname,nforumid,forumname,forumn,forumstar,oclassid,foo,fi,cc,fclass,up_down
  oclassid=0
%>
<tr align=center>
<td width='65%' class=td>论坛分类/名称,是否可发贴,是否隐藏,今日新贴,主题数,贴子数</td>
<td width='15%' class=td>添加分论坛</td>
<td width='20%' class=td>相关操作</td>
</tr>
<%
  sql="select forum_id,class_id,forum_name,forum_w,forum_n,forum_star,forum_hidden,forum_pro,forum_topic_num,forum_data_num,forum_new_num,forum_config from bbs_forum order by class_id,forum_order,forum_star" 
set rs=joekoe_cms.exec(sql,1)
  do while not rs.eof
    nforumid=rs("forum_id")
    classid=rs("class_id")
    forumname=rs("forum_name")
    forumn=rs("forum_n")
    forumstar=rs("forum_star")
    fclass="blue"
    up_down=2
    cc="tr"
    foo=""
    if classid<>oclassid then
      fclass="red2"
      up_down=1
      cc="tr3"
      oclassid=classid
    end if
    for fi=1 to forumstar
      foo=foo&"　"
    next
%>

  <table border=0 cellspacing=0 cellpadding=0 width='100%'>
  <tr class=<%response.write cc%>>
  
  <td> 
  <table border=0 cellspacing=0 cellpadding=0 width='100%'> 
  <tr class=<%response.write cc%>> 
  <td><font class=<%response.write fclass%>><b><%response.write foo&forumname%></b></font><%if int(forumn)>0 then response.write " <font class=red>"&forumn&"</font>"%> 
  <% 
      if int(forumn)>0 then 
   response.write "  分类样式：" 
   if int(rs("forum_config"))=2 then 
        response.write "<font class=red>简洁(2列)</font>" 
   elseif int(rs("forum_config"))=3 then 
        response.write "<font class=red>简洁(3列)</font>" 
   else 
        response.write "<font class=gray>正常</font>" 
   end if 
      end if 
  %> 
  </td>
  
  
  <td><font class=<%response.write fclass%>><b><%response.write foo&forumname%></b></font><%if int(forumn)>0 then response.write " <font class=red>"&forumn&"</font>"%></td>
  <td align=right><%
    if rs("forum_w")=false then response.write "<font class=gray>不可发贴</font>&nbsp;"
    if rs("forum_hidden")=true then response.write "<font class=gray>隐藏</font>&nbsp;"
    if rs("forum_pro")=1 then response.write "<font class=gray>只读</font>&nbsp;"
    response.write "<font class=tims><font class=red>"&rs("forum_new_num")&"</font>,"&rs("forum_topic_num")&","&rs("forum_data_num")&"</font>"
%></td>
  </tr>
  </table>
</td>
<td><a href='?action=add&forum_id=<%response.write nforumid%>'>添加分论坛</a></td>
<td>
<a href='?action=edit&forum_id=<%response.write nforumid%>'>编辑</a>&nbsp;
<a href='?action=restore&forum_id=<%response.write nforumid%>' onclick="javascript:return click_return('对 <%response.write joekoe_cms.code_js(forumname,1)%> 进行主题等数据修复',0);">修复</a>&nbsp;
<a href='?action=del&forum_id=<%response.write nforumid%>' onclick="javascript:return click_return('删除论坛（<%response.write joekoe_cms.code_js(forumname,1)%>）及其下属论坛',0);">删除</a>&nbsp;&nbsp;
<a href='?forum_id=<%response.write nforumid%>&action=orders&actions=up'><%response.write img_admin("up_"&up_down,"向上移动此论坛")%></a>&nbsp;
<a href='?forum_id=<%response.write nforumid%>&action=orders&actions=down'><%response.write img_admin("down_"&up_down,"向下移动此论坛")%></a>
</td>
</tr>
<%
    rs.movenext
  loop
  rs.close
end sub

sub forum_mod()
  dim temp1,forum_topic_num,forum_data_num,forum_new_info,ftrue,fname1,fname2
  call admin_td("合并论坛数据")
  if chk() then
    dim sel1,sel2
    sel1=trim(request.form("sel_1"))
    sel2=trim(request.form("sel_2"))
    if not(isnumeric(sel1)) or not(isnumeric(sel2)) then
      response.write "<tr><td align=center height=50 colspan=2><font class=red2>您没有选择要合并的论坛！</font></td></tr>"
    else
      sel1=int(sel1)
      sel2=int(sel2)
      ftrue=true
      sql="select forum_topic_num,forum_data_num,forum_name from bbs_forum where forum_id="&sel2
      set rs=joekoe_cms.exec(sql,1)
      if rs.eof then
        ftrue=false
        response.write "<tr><td align=center height=50 colspan=2><font class=red2>转移论坛ID（"&sel1&"）不存在！</font></td></tr>"
      else
        forum_topic_num=rs(0)
        forum_data_num=rs(1)
        fname1=rs(2)
      end if
      rs.close
      if ftrue=true then
        sql="select forum_topic_num,forum_data_num,forum_name from bbs_forum where forum_id="&sel1
        set rs=joekoe_cms.exec(sql,1)
        if rs.eof then
          ftrue=false
          response.write "<tr><td align=center height=50 colspan=2><font class=red2>主论坛ID（"&sel1&"）不存在！</font></td></tr>"
        else
          forum_topic_num=forum_topic_num+rs(0)
          forum_data_num=forum_data_num+rs(1)
          fname2=rs(2)
        end if
        rs.close
      end if
      if ftrue=true then
        sql="update bbs_forum set forum_topic_num=0,forum_data_num=0,forum_new_info='' where forum_id="&sel1
        call joekoe_cms.exec(sql,0)
        sql="update bbs_forum set forum_topic_num="&forum_topic_num&",forum_data_num="&forum_data_num&" where forum_id="&sel2
        call joekoe_cms.exec(sql,0)
        sql="update bbs_topic set forum_id="&sel2&" where forum_id="&sel1
        call joekoe_cms.exec(sql,0)
        sql="update bbs_data set forum_id="&sel2&" where forum_id="&sel1
        call joekoe_cms.exec(sql,0)
        call admin_msg("成功将论坛（"&fname1&"）数据合并到论坛（"&fname2&"）中！","?action=mod",0)
        exit sub
      end if
    end if
  end if
  call form_first()
  temp1=forum_mod_list()
%>
<form action='?action=mod' method=post>
<input type=hidden name='chk' value='yes'>
<tr>
<td>从论坛：</td>
<td height=50><select name=sel_1><%response.write temp1%></select></td>
</tr>
<tr>
<td>合并到论坛：</td>
<td height=50><select name=sel_2><%response.write temp1%></select></td>
</tr>
<tr>
<td></td>
<td height=50><input type=submit value='开始合并'></td>
</tr>
</form>
<%
end sub

function forum_mod_list()
  dim temp1,ncid,forumn
  ncid=0
  sql="select forum_id,class_id,forum_name,forum_n,forum_w,forum_star,forum_hidden,forum_pro from bbs_forum 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_2>╋"&rs("forum_name")&"</option>"
      ncid=classid
    else
      forumn=rs("forum_n")
      temp1=temp1&vbcrlf&"<option value='"&rs("forum_id")&"'>"
      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
  forum_mod_list=temp1
end function

%>