<!--#include file="conn.asp"-->
<!--#include file="config.asp"-->
<%
if session("admin")="" then
  response.redirect "admin_login.asp"
end if

'00 分类管理
if not checkflag("00") then
  call mb("对不起，您没有Flash分类管理的权限！","",0)
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>分类管理</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="5" topmargin="0">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="0" bgcolor="#000000" vspace="0" hspace="0">
  <tr bgcolor="#EFEBEF"> 
    <td height="27"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr> 
          <td width="86%"><font color="#FF3000">.:: 您可以在这里进行[Flash分类管理]相关操作</font></td>
          <td width="14%" height="20" align="center"><a href="javascript:this.location.reload()"><img src="images/refresh.gif" alt="刷新" width="40" height="12" border="0"></a></td>
        </tr>
      </table></td>
  </tr>
  <tr > 
    <td height="1" bgcolor="#000000"></td>
  </tr>
</table>
<table width="600" border="0" cellpadding="0" cellspacing="1">
  <tr>
    <td width="156">&nbsp;</td>
    <td width="441">
<%
dim nsort,nsortn,class_an,action
'tit=vbcrlf & "<a href='?nsort=joke'>笑话分类</a>&nbsp;┋&nbsp;" & _
    'vbcrlf & "<a href='?nsort=sj'>手机分类</a>&nbsp;┋&nbsp;" & _
    'vbcrlf & "<a href='?nsort=down'>下载分类</a>&nbsp;┋&nbsp;" & _
    'vbcrlf & "<a href='?nsort=flash'>FLASH分类</a>&nbsp;┋&nbsp;" & _
    'vbcrlf & "<a href='?nsort=pro'>产品分类</a>&nbsp;┋&nbsp;" & _
    'vbcrlf & "<a href='?nsort=news'>动态分类</a>&nbsp;┋&nbsp;" & _
    'vbcrlf & "<a href='?nsort=gall'>图库分类</a>&nbsp;┋&nbsp;" & _
   ' vbcrlf & "<a href='?nsort=busin'>交易分类</a>&nbsp;┋&nbsp;" & _
    'vbcrlf & "<a href='?nsort=web'>网站分类</a>"
nsort=trim(request.querystring("nsort"))
action=trim(request.querystring("action"))
select case nsort
case "flash"
  nsortn="Flash分类"
case else
  nsort="flash"
  nsortn="Flash分类"
end select

select case action
case "up","down"
  class_an="分类排序"
  call class_order()
case "del"
  class_an="分类删除"
  call class_del()
case "list"
  class_an="分类查看"
  call class_list()
case "addc"
  class_an="添加一级分类"
  call class_addc()
case "adds"
  class_an="添加二级分类"
  call class_adds()
case "editc"
  class_an="修改一级分类"
  call class_editc()
case "edits"
  class_an="修改二级分类"
  call class_edits()
case else
  class_an="分类查看"
  call class_main()
end select
%>&nbsp;</td>
  </tr>
</table>
</body>
</html>
<%
sub class_list()
  dim i,j,bigclassid,sql2,rs2:i=1
  sql="select bigclassid from bigclass where nsort='"&nsort&"' order by b_order,bigclassid"
  set rs=conn.execute(sql)
  do while not rs.eof
    bigclassid=rs(0):j=1
    conn.execute("update bigclass set b_order="&i&" where bigclassid="&bigclassid)
    sql2="select smallclassid from smallclass where bigclassid="&bigclassid&" order by s_order,smallclassid"
    set rs2=conn.execute(sql2)
    do while not rs2.eof
      conn.execute("update smallclass set s_order="&j&" where smallclassid="&rs2(0))
      rs2.movenext
      j=j+1
    loop
    rs2.close
    rs.movenext
    i=i+1
  loop
  rs.close:set rs=nothing:set rs2=nothing
  call class_main()
end sub

sub class_del()
  dim bigclassid,smallclassid
  bigclassid=trim(request.querystring("bigclassid")):smallclassid=trim(request.querystring("smallclassid"))
  if not(isnumeric(bigclassid)) and not(isnumeric(smallclassid)) then call class_main():exit sub
  if isnumeric(bigclassid) then smallclassid=""
  if smallclassid="" then
    sql="delete from bigclass where bigclassid="&bigclassid
    conn.execute(sql)
    sql="delete from smallclass where bigclassid="&bigclassid
    conn.execute(sql)
  else
    sql="delete from smallclass where smallclassid="&smallclassid
    conn.execute(sql)
  end if
  call class_main()
end sub

sub class_order()
  dim bigclassid,smallclassid,nid,t1,t11,t2,t22,sqladd:sqladd=""
  bigclassid=trim(request.querystring("bigclassid")):smallclassid=trim(request.querystring("smallclassid"))
  if not(isnumeric(bigclassid)) and not(isnumeric(smallclassid)) then call class_main():exit sub
  if isnumeric(bigclassid) then smallclassid=""
  if action="up" then sqladd=" desc"
  if smallclassid="" then
    t1=int(bigclassid)
    sql="select bigclassid,b_order from bigclass where nsort='"&nsort&"' order by b_order"&sqladd&",bigclassid"&sqladd
    set rs=conn.execute(sql)
    do while not rs.eof
      nid=int(rs(0))
      if int(bigclassid)=nid then
        t22=rs(1)
        rs.movenext
        if rs.eof then exit do
        t2=rs(0):t11=rs(1)
        conn.execute("update bigclass set b_order="&t11&" where bigclassid="&t1)
        conn.execute("update bigclass set b_order="&t22&" where bigclassid="&t2)
        exit do
      end if
      rs.movenext
    loop
    
rs.close:set rs=nothing
  else
    t1=int(smallclassid)
    sql="select smallclass.bigclassid from bigclass inner join smallclass on bigclass.bigclassid=smallclass.bigclassid where smallclass.smallclassid="&smallclassid
    set rs=conn.execute(sql)
    if rs.eof and rs.bof then
      rs.close:set rs=nothing
      call class_main():exit sub
    end if
    bigclassid=int(rs(0))
    
rs.close
    sql="select smallclassid,s_order from smallclass where bigclassid="&bigclassid&" order by s_order"&sqladd&",smallclassid"&sqladd
    set rs=conn.execute(sql)
    do while not rs.eof
      nid=int(rs(0))
      if int(smallclassid)=nid then
        t22=rs(1)
        rs.movenext
        if rs.eof then exit do
        t2=rs(0):t11=rs(1)
        conn.execute("update smallclass set s_order="&t11&" where smallclassid="&t1)
        conn.execute("update smallclass set s_order="&t22&" where smallclassid="&t2)
        exit do
      end if
      rs.movenext
    loop
    
rs.close:set rs=nothing
  end if
  call class_main()
end sub

sub class_editc()
  dim bigclassname,bigclassid,folder
  bigclassid=trim(request.querystring("bigclassid"))
  if not(isnumeric(bigclassid)) then call class_main():exit sub
  sql="select bigclassname,folder from bigclass where nsort='"&nsort&"' and bigclassid="&bigclassid
  set rs=server.createobject("adodb.recordset")
  rs.open sql,conn,1,3
  if rs.eof and rs.bof then
    rs.close:set rs=nothing
    call class_main():exit sub
  end if
  response.write class_tit()&"<table border=1 width=350 cellspacing=0 cellpadding=2 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>"
  if trim(request.querystring("edit"))="ok" then
    response.write vbcrlf&"<tr><td height=100 align=center>"
    bigclassname=checkstr(trim(request.form("bigclassname")))
	folder=checkstr(trim(request.form("folder")))
    if bigclassname="" or len(bigclassname)>16 then
      call mb("一级分类名称不能为空（长度不大于16）！","",0)
	end if
	
	if folder="" or len(folder)>50 then
	  call mb("文件夹名称不能为空（长度不大于50）！","",0)
	end if
      rs("bigclassname")=bigclassname
	  rs("folder")=folder
      rs.update
	  
	  '更新Flash列表的folder字段
	  conn.execute("update flash set folder='"&folder&"' where bigclassid="&bigclassid&" and folder<>''")
      call mb("修改一级分类成功！","admin_class.asp?nsort="&nsort,1)
    response.write vbcrlf&"</td></tr>"
  else
%>
<form action='?nsort=<% response.write nsort %>&action=editc&bigclassid=<% response.write bigclassid %>&edit=ok' method=post>
<tr height=25 >
<td align=center>一级分类名称：</td>
<td><input type=text name=bigclassname value='<% response.write rs(0) %>' size=30 maxlength=16 class='input'></td>
</tr>
<tr height=25 >
<td align=center>文 件 夹名称：</td>
<td><input type=text name=folder value='<% response.write rs(1) %>' size=30 maxlength=50 class='input'></td>
</tr>
<tr><td colspan=2 height=30 align=center><input type=submit value='修改一级分类' class='button'></td></tr>
</form>
<%
end if
  rs.close:set rs=nothing
  response.write "</table>"
end sub

sub class_edits()
  dim smallclassname,s_order,smallclassid,bigclassid,cbigclassid,nbigclassid,sqladd
  sqladd=""
  smallclassid=trim(request.querystring("smallclassid"))
  if not(isnumeric(smallclassid)) then smallclassid=0
  sql="select bigclassid,smallclassname from smallclass where smallclassid="&smallclassid
  set rs=conn.execute(sql)
  if rs.eof and rs.bof then
    rs.close:set rs=nothing
    call class_main():exit sub
  end if
  bigclassid=rs(0)
  response.write class_tit()&"<table border=1 width=350 cellspacing=0 cellpadding=2 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>"
  if trim(request.querystring("edit"))="ok" then
    response.write vbcrlf&"<tr><td height=100 align=center>"
    cbigclassid=trim(request.form("bigclassid"))
    smallclassname=replace(trim(request.form("smallclassname")),"'","")
    if len(smallclassname)<1 or len(smallclassname)>16 then
      call mb("二级分类名称不能为空（长度不大于16）！","",0)
    else
      if int(cbigclassid)<>int(bigclassid) then
        rs.close
        sql="select top 1 s_order from smallclass where bigclassid="&cbigclassid&" order by s_order desc"
        set rs=conn.execute(sql)
        if rs.eof and rs.bof then
          s_order=1
        else
          s_order=int(rs(0))+1
        end if
        sqladd=",s_order="&s_order
      end if
      sql="update smallclass set bigclassid="&cbigclassid&",smallclassname='"&smallclassname&"'"&sqladd&" where smallclassid="&smallclassid
      conn.execute(sql)
       call mb("修改二级分类成功！","admin_class.asp?nsort="&nsort,1)
    end if
    response.write vbcrlf&"</td></tr>"
  else
   '修改二级分类
%>
<form action='?nsort=<% response.write nsort %>&action=edits&smallclassid=<% response.write smallclassid %>&edit=ok' method=post>
<tr height=25 >
<td align=center>一级分类类型：</td>
<td><select name=bigclassid size=1 class='input'>
<%
  smallclassname=rs(1):rs.close
  sql="select bigclassid,bigclassname from bigclass where nsort='"&nsort&"' order by b_order,bigclassid"
  set rs=conn.execute(sql)
  do while not rs.eof
    nbigclassid=int(rs(0))
    response.write vbcrlf&"<option value='"&nbigclassid&"'"
    if bigclassid=nbigclassid then response.write " selected"
    response.write ">"&rs(1)&"</option>"
    rs.movenext
  loop
%>
</select></td>
</tr>
<tr height=25>
<td align=center>二级分类名称：</td>
<td><input type=text name=smallclassname value='<% response.write smallclassname %>' size=30 maxlength=16 class='input'></td>
</tr>
<tr><td colspan=2 height=30 align=center><input type=submit value='修改二级分类' class='button'></td></tr>
</form>
<%
  end if
  rs.close:set rs=nothing
  response.write "</table>"
end sub

sub class_addc()
 
 if trim(request.querystring("add"))="ok" then
  dim bigclassname,b_order,folder
  bigclassname=checkstr(trim(request.form("bigclassname")))
	folder=checkstr(trim(request.form("floder")))
    if bigclassname="" or len(bigclassname)>16 then
      call mb("一级分类名称不能为空（长度不大于16）！","",0)
	end if
	
	if folder="" or len(folder)>50 then
	  call mb("文件夹名称不能为空(长度不大于50)！","",0)
	end if
	
    
      sql="select top 1 b_order from bigclass where nsort='"&nsort&"' order by b_order desc"
      set rs=conn.execute(sql)
      if rs.eof and rs.bof then
        b_order=1
      else
        b_order=int(rs(0))+1
      end if
      rs.close:set rs=nothing
      sql="insert into bigclass(nsort,bigclassname,b_order,folder) values('"&nsort&"','"&bigclassname&"',"&b_order&",'"&folder&"')"
      conn.execute(sql)
     call mb("添加一级分类成功！","admin_class.asp?nsort="&nsort,1)
else
 response.write class_tit()
%>
<table border=1 width=350 cellspacing=0 cellpadding=2 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>
 <form action='?nsort=<% response.write nsort %>&action=addc&add=ok' method=post>
<tr height=25 align=center>
<td>一级分类名称：</td>
<td><input type=text name=bigclassname size=30 maxlength=16 class='input'></td>
</tr>
<tr height=25 align=center>
<td>文 件 夹：</td>
<td><input type=text name=floder size=30 maxlength=16 class='input'></td>
</tr>
<tr><td colspan=2 height=30 align=center><input type=submit value='添加一级分类' class='button'></td></tr>
</form>
</table>
<%
 end if
end sub

sub class_adds()
  dim smallclassname,s_order,cname,bigclassid,nbigclassid
  bigclassid=trim(request.querystring("bigclassid"))
  if not(isnumeric(bigclassid)) then bigclassid=0
  bigclassid=int(bigclassid)
  response.write class_tit()&"<table border=1 width=350 cellspacing=0 cellpadding=2 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>"
  if trim(request.querystring("add"))="ok" then
    response.write vbcrlf&"<tr><td height=100 align=center>"
    smallclassname=replace(trim(request.form("smallclassname")),"'","")
    if len(smallclassname)<1 or len(smallclassname)>50 then
      call mb("二级分类名称不能为空（长度不大于50）！","",0)
    else
      bigclassid=trim(request.form("bigclassid"))
      if not(isnumeric(bigclassid)) then bigclassid=0
      sql="select bigclassname from bigclass where nsort='"&nsort&"' and bigclassid="&bigclassid
      set rs=conn.execute(sql)
      if rs.eof and rs.bof then
        rs.close:set rs=nothing
        call class_main():exit sub
      end if
      cname=rs(0)
      rs.close
      
      sql="select top 1 s_order from smallclass where bigclassid="&bigclassid&" order by s_order desc"
      set rs=conn.execute(sql)
      if rs.eof and rs.bof then
        s_order=1
      else
        s_order=int(rs(0))+1
      end if
      rs.close:set rs=nothing
      
      sql="insert into smallclass(bigclassid,smallclassname,s_order) values("&bigclassid&",'"&smallclassname&"',"&s_order&")"
      conn.execute(sql)
       call mb("添加二级分类成功！","admin_class.asp?nsort="&nsort,1)
    end if
    response.write vbcrlf&"</td></tr>"
  else
%>
<form action='?nsort=<% response.write nsort %>&action=adds&bigclassid=<% response.write bigclassid %>&add=ok' method=post>
<tr height=25>
<td align=center>一级分类类型：</td>
<td><select name=bigclassid size=1 class='input'><%
  sql="select bigclassid,bigclassname from bigclass where nsort='"&nsort&"' order by b_order"
  set rs=conn.execute(sql)
  do while not rs.eof
    nbigclassid=int(rs(0))
    response.write vbcrlf&"<option value='"&nbigclassid&"'"
    if bigclassid=nbigclassid then response.write " selected"
    response.write ">"&rs(1)&"</option>"
    rs.movenext
  loop
  rs.close:set rs=nothing
%>
</select></td>
</tr>
<tr height=25>
<td align=center>二级分类名称：</td>
<td><input type=text name=smallclassname size=30 maxlength=50 class='input'></td>
</tr>
<tr><td colspan=2 height=30 align=center><input type=submit value='添加二级分类' class='button'></td></tr>
</form>
<%
  end if
  response.write "</table>"
end sub

sub class_main()
  response.expires=0
  response.write class_tit()
  dim sql2,rs2,bigclassid,smallclassid
  response.write vbcrlf&"<table border=1 cellspacing=0 cellpadding=2 width=400 bordercolorlight=#C0C0C0 bordercolordark=#FFFFFF>"
  sql="select bigclassid,bigclassname from bigclass where nsort='"&nsort&"' order by b_order,bigclassid"
  set rs=conn.execute(sql)
  do while not rs.eof
    bigclassid=rs(0)
    response.write vbcrlf&"<tr bgcolor=#ffffff align=center><td align=left>&nbsp;<font color=#CE3000><b>"&rs(1)&"</b></font>&nbsp;&nbsp;（<a href='?nsort="&nsort&"&action=adds&bigclassid="&bigclassid&"'>添加二级分类</a>）</td><td><a href='?nsort="&nsort&"&action=editc&bigclassid="&bigclassid&"'>修改</a>&nbsp;&nbsp;<a href=""javascript:Do_del_class('"&bigclassid&"');"">删除</a></td><td>排序：<a href='?nsort="&nsort&"&action=up&bigclassid="&bigclassid&"'>向上</a>&nbsp;&nbsp;<a href='?nsort="&nsort&"&action=down&bigclassid="&bigclassid&"'>向下</a></td></tr>"
    sql2="select smallclassid,smallclassname from smallclass where bigclassid="&bigclassid&" order by s_order,smallclassid"
    set rs2=conn.execute(sql2)
    do while not rs2.eof
       smallclassid=rs2(0)
       response.write vbcrlf&"<tr align=center><td align=left>　　<font color=#0065CE>"&rs2(1)&"</font></td><td><a href='?nsort="&nsort&"&action=edits&smallclassid="&smallclassid&"'>修改</a>&nbsp;&nbsp;<a href=""javascript:Do_del_sort('"&smallclassid&"');"">删除</a></td><td>排序：<a href='?nsort="&nsort&"&action=up&smallclassid="&smallclassid&"'>向上</a>&nbsp;&nbsp;<a href='?nsort="&nsort&"&action=down&smallclassid="&smallclassid&"'>向下</a></td></tr>"
       rs2.movenext
    loop
    rs2.close:set rs2=nothing
    rs.movenext
  loop
  rs.close:set rs=nothing
  response.write vbcrlf&"<tr><td height=30 align=center colspan=3><a href='?nsort="&nsort&"&action=addc'>添加一级分类</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href='?nsort="&nsort&"&action=list'>重新排序</a></td></tr></table>"
%>
<script language=JavaScript>
<!--
function Do_del_class(data1)
{
if (confirm("此操作将删除id为 "+data1+" 的一级分类！\n\n真的要删除吗？\n\n删除后将无法恢复！"))
  window.location="?nsort=<% response.write nsort %>&action=del&bigclassid="+data1
}

function Do_del_sort(data1)
{
if (confirm("此操作将删除id为 "+data1+" 的二级分类！\n\n真的要删除吗？\n\n删除后将无法恢复！"))
  window.location="?nsort=<% response.write nsort %>&action=del&smallclassid="+data1
}
//-->
</script><%
end sub

function class_tit()
  class_tit=vbcrlf&"<table border=0><tr><td height=30><font class=red>"&nsortn&"</font>&nbsp;&nbsp;-&nbsp;&nbsp;<font class=blue>"&class_an&"</font></td></tr></table>"&vbcrlf
end function
%>
