<!-- #include file="include/admin_onlogin.asp" -->
<%
dim ndim,nnum,cname,sname,ntit1,ntit2
index_url="nsort"
call admin_master(0,0)
call admin_cid_sid()
call admin_header(0,0)
nsort=""
ntit=tit
call joekoe_chk_dim()
%>
<tr><td align=center colspan=2 height=30>
  <table border=0>
  <tr>
  <td><a href='?nsort=<%response.write nsort%>'><%response.write ntit1&tit%></a></td>
  <td width=10></td>
  <td><a href='?nsort=<%response.write nsort%>&action=addc'>添加一级<%response.write ntit%></a></td>
  <td width=10></td>
  <td><a href='?nsort=<%response.write nsort%>&action=list' alt='在您发现<%response.write tit_fir%>排序等发生不正常时请点击，可进行有效的修覆'>重新排序</a></td>
<%call joekoe_is_js("&nsort="&nsort,ntit)%>
  </tr>
  </table>
</td></tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
<%
call admin_table(1,1)
call admin_td(ntit)

if int(nnum)<0 then
  response.write vbcrlf&"<tr><td align=center height=100 colspan=2><font class=red>暂时没有栏目"&tit_fir&"可管理！</font><br><br>请先在 <a href='admin_menu.asp'>管理菜单</a> 里设置正确。</td></tr>"
else
  response.write vbcrlf&"<tr align=center valign=top><td>" & _
		 vbcrlf&"<table class=table2>" & _
		 vbcrlf&"<tr><td width=15></td><td></td></tr>"
  for i=0 to nnum
    if nsort=ndim(0,i) then
      response.write vbcrlf&"<tr><td align=center>"&img_admin("s_left_sort","")&"</td><td><a href='?nsort="&ndim(0,i)&"' class=red2>"&ndim(1,i)&tit_fir&"</a></td></tr>"
    else
      response.write vbcrlf&"<tr><td align=center>"&img_admin("s_nsort","")&"</td><td><a href='?nsort="&ndim(0,i)&"'>"&ndim(1,i)&tit_fir&"</a></td></tr>"
    end if
  next
  response.write vbcrlf&"</table>" & _
		 vbcrlf&"</td><td>"
  
select case action
case "up","down"
  ntit2=tit_fir&"查看"
  call joekoe_chk_order()
case "del"
  ntit2=tit_fir&"查看"
  call joekoe_chk_del()
case "list"
  ntit2=tit_fir&"查看"
  call joekoe_chk_list()
case "addc"
  ntit2="添加一级"&tit_fir
  call joekoe_chk_addc()
case "adds"
  ntit2="添加二级"&tit_fir
  call joekoe_chk_adds()
case "editc"
  ntit2="修改一级"&tit_fir
  call joekoe_chk_editc()
case "edits"
  ntit2="修改二级"&tit_fir
  call joekoe_chk_edits()
case "js"
  ntit2=tit_fir&"查看"
  call joekoe_chk_js()
case else
  ntit2=tit_fir&"查看"
  call joekoe_chk_main()
end select

  response.write vbcrlf&"</td></tr>"
end if

call joekoe_chk_erase()
call admin_ender(1)

sub joekoe_chk_js()
  dim rs2,sql2,ncid,temp1,file_name,c_num
  file_name="style/data_sort_"&nsort&".asp"
  i=0
  ncid=0
  c_num=5
  sql="select count(c_id) from jk_class where nsort='"&nsort&"'"
  set rs=joekoe_cms.exec(sql,1)
  if not rs.eof then
    c_num=int(rs(0))-1
  end if
  rs.close
  temp1=temp1&"<"&"%" & _
      vbcrlf&"redim sort_dim("&c_num&")"
  sql="select c_id,c_name from jk_class where nsort='"&nsort&"' order by c_order,c_id"
  set rs=joekoe_cms.exec(sql,1)
  do while not rs.eof
    cid=rs(0)
    cname=rs("c_name")
    temp1=temp1&vbcrlf&"sort_dim("&i&")="""&code_fso(cname,1,1)&":"&cid
    sql2="select s_id,s_name from jk_sort where c_id="&cid&" order by s_order,s_id"
    set rs2=joekoe_cms.exec(sql2,1)
    do while not rs2.eof
      sid=rs2(0)
      sname=rs2(1)
      temp1=temp1&"|"&code_fso(sname,1,1)&":"&sid
      rs2.movenext
    loop
    rs2.close
    temp1=temp1&""""
    rs.movenext
    i=i+1
  loop
  rs.close
  if isobject(rs2) then set rs2=nothing
  temp1=temp1&vbcrlf&"%"&">"
  call create_file(file_name,temp1)
  call admin_event("更新"&ntit&"分类数据："&file_name,0,0)
  call admin_msg("已成功更新了"&ntit&"分类数据："&file_name,"?nsort="&nsort,1)
end sub

sub joekoe_chk_del()
  if int(cid)<1 and int(sid)<1 then
    call joekoe_chk_main()
    exit sub
  end if
  if int(cid)>0 then sid=0
  if int(sid)<1 then
    sql="delete from jk_sort where c_id="&cid
    call joekoe_cms.exec(sql,0)
    sql="delete from jk_class where c_id="&cid
    call joekoe_cms.exec(sql,0)
    call admin_event("删除一个一级"&ntit&"及其下面的二级"&tit_fir,0,0)
    call admin_msg("已成功删除一个一级"&ntit&"及其下面的二级"&tit_fir&"！","?nsort="&nsort,1)
  else
    sql="delete from jk_sort where s_id="&sid
    call joekoe_cms.exec(sql,0)
    call admin_event("删除一个二级"&ntit,0,0)
    call admin_msg("已成功删除一个二级"&ntit&"！","?nsort="&nsort,1)
  end if
end sub

sub joekoe_chk_list()
  dim j,sql2,rs2
  i=1
  sql="select c_id from jk_class where nsort='"&nsort&"' order by c_order,c_id"
  set rs=joekoe_cms.exec(sql,1)
  do while not rs.eof
    cid=rs(0)
    j=1
    call joekoe_cms.exec("update jk_class set c_order="&i&" where c_id="&cid,0)
    sql2="select s_id from jk_sort where c_id="&cid&" order by s_order,s_id"
    set rs2=joekoe_cms.exec(sql2,1)
    do while not rs2.eof
      call joekoe_cms.exec("update jk_sort set s_order="&j&" where s_id="&rs2(0),0)
      rs2.movenext
      j=j+1
    loop
    rs2.close
    rs.movenext
    i=i+1
  loop
  rs.close
  if isobject(rs2) then set rs2=nothing
  call joekoe_chk_main()
end sub

sub joekoe_chk_order()
  dim nid,t1,t11,t2,t22
  if int(cid)<1 and int(sid)<1 then
    call joekoe_chk_main()
    exit sub
  end if
  if int(cid)>0 then sid=0
  if action="up" then sql_add=" desc"
  if int(sid)=0 then
    t1=int(cid)
    sql="select c_id,c_order from jk_class where nsort='"&nsort&"' order by c_order"&sql_add&",c_id"&sql_add
    set rs=joekoe_cms.exec(sql,1)
    do while not rs.eof
      nid=int(rs(0))
      if int(cid)=nid then
        t22=rs(1)
        rs.movenext
        if rs.eof then exit do
        t2=rs(0)
        t11=rs(1)
        call joekoe_cms.exec("update jk_class set c_order="&t11&" where c_id="&t1,0)
        call joekoe_cms.exec("update jk_class set c_order="&t22&" where c_id="&t2,0)
        exit do
      end if
      rs.movenext
    loop
    
rs.close
  else
    t1=int(sid)
    sql="select jk_sort.c_id from jk_class inner join jk_sort on jk_class.c_id=jk_sort.c_id where jk_sort.s_id="&sid
    set rs=joekoe_cms.exec(sql,1)
    if rs.eof then
      rs.close
      call joekoe_chk_main()
      exit sub
    end if
    cid=int(rs(0))
    
rs.close
    sql="select s_id,s_order from jk_sort where c_id="&cid&" order by s_order"&sql_add&",s_id"&sql_add
    set rs=joekoe_cms.exec(sql,1)
    do while not rs.eof
      nid=int(rs(0))
      if int(sid)=nid then
        t22=rs(1)
        rs.movenext
        if rs.eof then exit do
        t2=rs(0)
        t11=rs(1)
        call joekoe_cms.exec("update jk_sort set s_order="&t11&" where s_id="&t1,0)
        call joekoe_cms.exec("update jk_sort set s_order="&t22&" where s_id="&t2,0)
        exit do
      end if
      rs.movenext
    loop
    
rs.close
  end if
  call joekoe_chk_main()
end sub

sub joekoe_chk_edits()
  dim s_order,ncid
  sql="select top 1 c.c_name,s.s_name from jk_class c inner join jk_sort s on c.c_id=s.c_id where c.nsort='"&nsort&"' and s.s_id="&sid
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call admin_msg("二级"&tit_fir&"ID（"&sid&"）不存在！","?nsort="&nsort,1)
    exit sub
  end if
  cname=rs(0)
  sname=rs(1)
  rs.close
%>
<table cellspacing=1 cellpadding=3 class=table0>
<tr>
<td class=td width='20%'></td>
<td class=td width='80%'><%response.write ntit&"（"&ntit2&"）"%></td>
</tr>
<%
  if chk() then
    sname=code_admin("s_name",1,16)
    if sname="" then
      call admin_error("二级"&tit_fir&"名称不能为空！")
      response.write "</table>"
      exit sub
    end if
    sql="update jk_sort set s_name='"&sname&"' where s_id="&sid
    call joekoe_cms.exec(sql,0)
    call admin_msg("成功修改二级"&tit_fir&"（"&sname&"）！","?nsort="&nsort,1)
    response.write "</table>"
    exit sub
  end if
  call form_first()
%>
<form action='?nsort=<%response.write nsort%>&action=edits&s_id=<%response.write sid%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td>一级<%response.write tit_fir%>名称：</td>
<td><font class=blue><b><%response.write cname%></b></font></td>
</tr>
<tr>
<td>二级<%response.write tit_fir%>名称：</td>
<td><input type=text name=s_name value='<%response.write sname%>' size=30 maxlength=16><%response.write redx%></td>
</tr>
<%
  call submit_edit()
  response.write "</table>"
end sub

sub joekoe_chk_adds()
  dim s_order,ncid
  sql="select top 1 c_name from jk_class where nsort='"&nsort&"' and c_id="&cid
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call admin_msg("一级"&tit_fir&"ID（"&cid&"）不存在！","?nsort="&nsort,1)
    exit sub
  end if
  cname=rs(0)
  rs.close
%>
<table cellspacing=1 cellpadding=3 class=table0>
<tr>
<td class=td width='20%'></td>
<td class=td width='80%'><%response.write ntit&"（"&ntit2&"）"%></td>
</tr>
<%
  if chk() then
    sname=code_admin("s_name",1,16)
    if sname="" then
      call admin_error("二级"&tit_fir&"名称不能为空！")
      response.write "</table>"
      exit sub
    end if
    s_order=1
    sql="select top 1 s_order from jk_sort where c_id="&cid&" order by s_order desc"
    set rs=joekoe_cms.exec(sql,1)
    if not rs.eof then s_order=int(rs(0))+1
    rs.close
    sql="insert into jk_sort(c_id,s_name,s_order) values('"&cid&"','"&sname&"',"&s_order&")"
    call joekoe_cms.exec(sql,0)
    call admin_msg("成功添加二级"&tit_fir&"（"&sname&"）！","?nsort="&nsort,1)
    response.write "</table>"
    exit sub
  end if
  call form_first()
%>
<form action='?nsort=<%response.write nsort%>&action=adds&c_id=<%response.write cid%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td>一级<%response.write tit_fir%>名称：</td>
<td><font class=blue><b><%response.write cname%></b></font></td>
</tr>
<tr>
<td>二级<%response.write tit_fir%>名称：</td>
<td><input type=text name=s_name size=30 maxlength=16><%response.write redx%></td>
</tr>
<%
  call submit_add()
  response.write "</table>"
end sub

sub joekoe_chk_editc()
  sql="select top 1 c_name from jk_class where nsort='"&nsort&"' and c_id="&cid
  set rs=joekoe_cms.exec(sql,1)
  if rs.eof then
    rs.close
    call admin_msg("一级"&tit_fir&"ID（"&cid&"）不存在！","?nsort="&nsort,1)
    exit sub
  end if
  cname=rs(0)
  rs.close
%>
<table cellspacing=1 cellpadding=3 class=table0>
<tr>
<td class=td width='20%'></td>
<td class=td width='80%'><%response.write ntit&"（"&ntit2&"）"%></td>
</tr>
<%
  if chk() then
    cname=code_admin("c_name",1,16)
    if cname="" then
      call admin_error("一级"&tit_fir&"名称不能为空！")
      response.write "</table>"
      exit sub
    end if
    sql="update jk_class set c_name='"&cname&"' where c_id="&cid
    call joekoe_cms.exec(sql,0)
    call admin_msg("成功编辑一级"&tit_fir&"（"&cname&"）！","?nsort="&nsort,1)
    response.write "</table>"
    exit sub
  end if
  call form_first()
%>
<form action='?nsort=<%response.write nsort%>&action=editc&c_id=<%response.write cid%>' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td>一级<%response.write tit_fir%>名称：</td>
<td><input type=text name=c_name value='<%response.write cname%>' size=30 maxlength=16><%response.write redx%></td>
</tr>
<%
  call submit_edit()
  response.write "</table>"
end sub

sub joekoe_chk_addc()
  dim c_order
%>
<table cellspacing=1 cellpadding=3 class=table0>
<tr>
<td class=td width='20%'></td>
<td class=td width='80%'><%response.write ntit&"（"&ntit2&"）"%></td>
</tr>
<%
  if joekoe_cms.chk() then
    cname=code_admin("c_name",1,16)
    if cname="" then
      call admin_error("一级"&tit_fir&"名称不能为空！")
      response.write "</table>"
      exit sub
    end if
    c_order=1
    sql="select top 1 c_order from jk_class where nsort='"&nsort&"' order by c_order desc"
    set rs=joekoe_cms.exec(sql,1)
    if not rs.eof then c_order=int(rs(0))+1
    rs.close
    sql="insert into jk_class(nsort,c_name,c_order) values('"&nsort&"','"&cname&"',"&c_order&")"
    call joekoe_cms.exec(sql,0)
    call admin_msg("成功添加一级"&tit_fir&"（"&cname&"）！","?nsort="&nsort,1)
    response.write "</table>"
    exit sub
  end if
  call form_first()
%>
<form name=add_frm action='?jk_mod=<%response.write jk_mod%>&nsort=<%response.write nsort%>&action=addc' method=post>
<input type=hidden name=chk value='yes'>
<tr>
<td>一级<%response.write tit_fir%>名称：</td>
<td><input type=text name=c_name size=30 maxlength=16><%response.write redx%></td>
</tr>
<%
  call submit_add()
  response.write "</table>"
end sub

sub joekoe_chk_main()
  dim rs2,sql2
%>
<table cellspacing=1 cellpadding=3 class=table0>
<tr align=center>
<td class=td width='70%'><%response.write ntit%>名称及添加操作</td>
<td class=td width='30%'>相关操作</td>
</tr>
<%
  'sql="select c.c_id,s.s_id,c.c_name,s.s_name from jk_class c inner join jk_sort s on c.c_id=s.c_id where c.nsort='"&nsort&"' order by c.c_order,c.c_id,s.s_order,s.s_id"
  sql="select c_id,c_name from jk_class where nsort='"&nsort&"' order by c_order,c_id"
  set rs=joekoe_cms.exec(sql,1)
  do while not rs.eof
    cid=rs(0)
    cname=rs("c_name")
%>
<tr>
<td>&nbsp;<%response.write img_admin("s_left","")%>&nbsp;<font class=red2><b><%response.write cname%></b></font>&nbsp;（<a href='?nsort=<%response.write nsort%>&action=adds&c_id=<%response.write cid%>'>添加二级分类</a>）</td>
<td>
&nbsp;<a href='?nsort=<%response.write nsort%>&c_id=<%response.write cid%>&action=editc'>编辑</a>
&nbsp;<a href='?nsort=<%response.write nsort%>&c_id=<%response.write cid%>&action=up'><%response.write img_admin("up_1","向上移动此主"&tit_fir)%></a>
&nbsp;<a href='?nsort=<%response.write nsort%>&c_id=<%response.write cid%>&action=down'><%response.write img_admin("down_1","向下移动此主"&tit_fir)%></a>
&nbsp;<a href='?nsort=<%response.write nsort%>&c_id=<%response.write cid%>&action=del' onclick="return del_nsort(<%response.write cid%>,'<%response.write cname%>','yes');">删除</a>
</td>
</tr>
<%
    sql2="select s_id,s_name from jk_sort where c_id="&cid&" order by s_order,s_id"
    set rs2=joekoe_cms.exec(sql2,1)
    do while not rs2.eof
      sid=rs2(0)
      sname=rs2(1)
%>
<tr>
<td>&nbsp;　<font class=blue><b><%response.write sname%></b></font></td>
<td>
&nbsp;<a href='?nsort=<%response.write nsort%>&s_id=<%response.write sid%>&action=edits'>修改</a>
&nbsp;<a href='?nsort=<%response.write nsort%>&s_id=<%response.write sid%>&action=up'><%response.write img_admin("up_2","向上移动此二级"&tit_fir)%></a>
&nbsp;<a href='?nsort=<%response.write nsort%>&s_id=<%response.write sid%>&action=down'><%response.write img_admin("down_2","向下移动此二级"&tit_fir)%></a>
&nbsp;<a href='?nsort=<%response.write nsort%>&s_id=<%response.write sid%>&action=del' onclick="return del_nsort(<%response.write sid%>,'<%response.write sname%>','no');">删除</a>
</td>
</tr>
<%
      rs2.movenext
    loop
    rs2.close
    rs.movenext
  loop
  rs.close
  if isobject(rs2) then set rs2=nothing
%>
</table>
<script language=javascript>
<!--
function del_nsort(t1,t2,t3)
{
  if (t3=="yes")
  {
    var cf=window.confirm("您确定要删除主<%response.write tit_fir%>（"+t2+"）吗？\n其下的二级<%response.write tit_fir%>也将一并删除！\n\n删除后将不可恢复！是否确定该操作？");
    if (cf)
    { return true; }
    else
    { return false; }
  }
  else
  {
    var cf1=window.confirm("您确定要删除二级<%response.write tit_fir%>（"+t2+"）吗？\n\n删除后将不可恢复！是否确定该操作？");
    if (cf1)
    { return true; }
    else
    { return false; }
  }
  return false;
}
-->
</script>
<%
end sub

sub joekoe_chk_dim()
  dim tmpsort
  tmpsort=trim(request.querystring("nsort"))
  nnum=-1
  sql="select m_nsort,m_tit_fir from admin_menu where m_is_master=1 and m_is_nsort=1 order by m_id"
  call joekoe_cms.exec("",-1)
  rs.open sql,conn,1,1
  if not rs.eof then
    nnum=rs.recordcount-1
    redim ndim(1,nnum)
    for i=1 to nnum+1
      ndim(0,i-1)=rs(0)
      ndim(1,i-1)=rs(1)
      if tmpsort=ndim(0,i-1) then
        nsort=tmpsort
        ntit=ndim(1,i-1)
      end if
      rs.movenext
    next
    if nsort="" then
      nsort=ndim(0,0)
      ntit=ndim(1,0)
    end if
    ntit1=ntit
    ntit=ntit&tit_fir
  end if
  rs.close
end sub

sub joekoe_chk_erase()
  if isarray(ndim) then erase ndim
end sub
%>