<!--#include file=down_conn.asp-->
<!-- #include file="inc/const.asp" -->

<head>
<title>--管理页面</title>

<meta NAME=GENERATOR Content="Microsoft FrontPage 4.0" CHARSET=GB2312>
<base target="footer">
</head>

<BODY leftMargin=0 topmargin="2">
<%

Dvbbs.LoadTemplates("")
Dvbbs.Head()
dim i
	dim admin_flag,isEdit,boname,msgtitle,msginfo,SubRs
	admin_flag="22"
	if not Dvbbs.master or instr(session("flag"),admin_flag)=0 then
		response.write "<BR><li>本页面为管理员专用，请<a href=admin_login.asp target=_top>登陆</a>后进入。<br><li>您没有管理本页面的权限。"
		response.end
	end if
   %>
<SCRIPT LANGUAGE=javascript>
<!--
function Juge(myform)
{

	if (myform.Nclass.value == "")
	{
		alert("小类名称不能为空！");
		myform.Nclass.focus();
		return (false);
	}
	if (myform.ClassID.value == "")
	{
		alert("所属大类没有选择！");
		myform.ClassID.focus();
		return (false);
	}

}


function SelectAll() {
	for (var i=0;i<document.selform.selNclassid.length;i++) {
		var e=document.selform.selNclassid[i];
		e.checked=!e.checked;
	}
}
//-->
</script>
<% 
if dvbbs.master then
  select case request("action")
  case "add" 
       call SaveAdd()
  case "modify"  
       call SaveModify()
  case "del"
       call delSubCate()
  case "edit" 
       isEdit=True
       call myform(isEdit)
  case else
       isEdit=False
       call myform(isEdit) 
  end select 
else
  msgtitle="小类管理"
  msginfo="<li>操作错误，你不是系统管理员，没有权限进行此项操作！</li>" 
  call Sysmsg(msgtitle,msginfo) 
 end if

  sub SaveAdd  
      msgtitle="添加小类"
	  if Trim(Request.Form("Nclass"))="" or Trim(Request.Form("ClassID"))="" then
	   msginfo="添加小类时出现错误，小类名称没有填写或者所属大类没有选择！" 
	  else
	     set rs=server.createobject("adodb.recordset")   '检查版面是否重名
         rs.open "select * from [DNclass] where Nclass='"&trim(request("Nclass"))&"'",conndown,1,1	
           if not(rs.bof and rs.eof) then
	         msginfo="添加小类时出现错误，已经有相同名称的小类已存在！"
           else
		     sql="insert into [DNclass](Nclass,ClassID) values('" & trim(request("Nclass")) & "'," & cstr(request("ClassID")) & ")"
            conndown.execute sql  
            msginfo="添加成功，<a href=""admin_down_classmana2.asp"" class=""ArticleList"">点此继续添加分类</a>！" 
		    end if
	     rs.close
	     set rs=nothing
	   end if	
        call Sysmsg(msgtitle,msginfo) 
  end sub 
  
  
  sub SaveModify()
     msgtitle="修改小类"
	  if Trim(Request.Form("Nclass"))="" or Trim(Request.Form("ClassID"))="" then
	   msginfo="修改小类时出现错误，小类名称没有填写或者所属大类没有选择！" 
	  else
	     set rs=server.createobject("adodb.recordset")   '检查版面是否重名
         rs.open "select * from [DNclass] where Nclass='"&trim(request("Nclass"))&"'",conndown,1,1	
           if not(rs.bof and rs.eof) then
	         msginfo="修改小类时出现错误，已经有相同名称的小类已存在！"
           else
		    sql="update [DNclass] set Nclass='" &trim(request("Nclass")) & "',ClassID="&request("ClassID")&" where Nclassid=" & request("Nclassid")
	         conndown.execute sql
			 sql="update [download] set ClassID=" & request("ClassID") & " where Nclassid=" &request("Nclassid")
	         conndown.execute sql
            msginfo="修改成功，<a href=""admin_down_classmana2.asp"" class=""ArticleList"">点此返回小类管理页面</a>！" 
		   end if
	     rs.close
	     set rs=nothing
	  end if 		 
	call Sysmsg(msgtitle,msginfo) 
  end sub 
  
  sub delSubCate()
  if Request.Form("selNclassid")<>"" then
        msgtitle="删除小类"
        conndown.execute("delete from [DNclass] where Nclassid in ("&Request.Form("selNclassid")&")")
		'删除该分类下的全部软件		
		conndown.execute("delete from [download] where Nclassid in ("&Request.Form("selNclassid")&")") 
		msginfo="删除操作成功，该分类相关信息已全部删除，<a href=""admin_down_classmana2.asp"">点此返回小类管理页面</a>！" 
      else
	  msginfo="删除操作不成功，没有选择分类，<a href=""admin_down_classmana2.asp"">点此返回小类管理页面</a>！"
	  end if 
	   call Sysmsg(msgtitle,msginfo) 
  end sub
  %> <% sub myform(isEdit) %> 
  <table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableBorder2">
   <tr> 
    <th height="23" colspan="2">管理说明</th>
    </tr>
    <tr>
    <td colspan="2" align="center" class="tablebody1"> 
  <a href="admin_down_classmana.asp"><font color="#FF0000">管理/添加大分类</font></a>&nbsp;&nbsp;&nbsp; 
      <a href="admin_down_classmana2.asp"><font color="#FF0000">管理/添加小分类</font></a> </td></tr></table><br>
<table width="95%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableBorder2">
  <tr>          
    <th>
      <%
	    set Rs=server.createobject("adodb.recordset")
		set SubRs=server.createobject("adodb.recordset")
	   if isedit then
	   boname="编辑"
		   rs.open "select * from [DNclass] where Nclassid=" & request("Nclassid"),conndown,1,1
	       response.write "编辑小类"
	   else
	   boname="添加"
	       response.write "添加小类"
	   end if %></th>
        </tr>
        <form name="myform" method="post" action="admin_down_classmana2.asp" onSubmit="return Juge(this)" >
          <tr>             
      <td align="center" class="forumRow" > 
        <input type="Hidden" name="action" value='<% If isedit then%>modify<% Else %>add<% End If %>'> 
              <%If isedit then%> <input type="Hidden" name="Nclassid" value='<%=request("Nclassid")%>'> 
              <%End If%>
              <%=boname%>小类名称： 
              <input type="text" name="Nclass" maxlength=40 size="12" value="<% if isedit then
			 response.write rs("Nclass") 
			 end if %>">
              所属大类： 
              <select name="ClassID">
                <option value="">请选择...</option>
                <% 
            SubRs.open "select * from [Dclass] order by ClassID",conndown,1,1 
			 if not(SubRs.bof and SubRs.eof) then
			 do while not SubRs.eof 
				 if isedit then %>
                <option value="<%=SubRs("ClassID")%>" <% if trim(rs("ClassID"))=trim(SubRs("ClassID")) then
					                                             response.write "selected" 
														      end if %>><%=SubRs("Class")%></option>
                <% else %>
                <option value="<%=SubRs("ClassID")%>"><%=SubRs("Class")%></option>
                <% 
				  end if
			   SubRs.movenext
			   loop
			   end if
			   SubRs.close
			 %>
              </select> <input name="submit" type=submit value="<%=boname%>"> </td>
          </tr>
        </form>
        <form name="selform" method="post" action="admin_down_classmana2.asp" >
          <% if isedit then rs.close
		 rs.open "select * from [Dclass] order by ClassID asc",conndown,1,1
	          if not(rs.bof and rs.eof) then
			  do while not rs.eof %>
          <tr>             
      <td class="tablebody1">&nbsp; <strong><%=rs("Class")%></strong> </td>
          </tr>
          <tr> 
            
      <td class="tablebody1" > 
        <% SubRs.open "select * from [DNclass] where ClassID="&Rs("ClassID")&" order by Nclassid asc",conndown,1,1
        if err.number <> 0 then
	           response.write "数据库出错"
           else
	           if SubRs.bof and SubRs.eof then
		        response.write "没有添加小类"
	           else
			   i=1
			 do while not SubRs.eof 			 
			 %> <input type="checkbox" name="selNclassid" value="<%=SubRs("Nclassid")%>"><a href="admin_down_classmana2.asp?Nclassid=<%=SubRs("Nclassid")%>&action=edit" class="ArticleList"><%=SubRS("Nclass")%></a> <% if (i mod 7)=0 then response.write "<br>"
			i=i+1
			SubRs.movenext
	               loop
	           end if
  end if
  SubRs.close
  %> </td>
          </tr>
          <% rs.movenext
	        loop
		   end if
		 rs.close
		 set subrs=nothing
		 set rs=nothing
	%>
          <tr> 
            
      <td class="tablebody1">管理操作：选择/反选 
        <input type="checkbox" name="checkbox" value="checkbox" onClick="javascript:SelectAll()"> 
              <input onClick="{if(confirm('此操作同时将删除该分类下的全部软件！\n\n确定要执行此项操作吗？')){this.document.selform.submit();return true;}return false;}" type=submit value=删除 name=action2> 
              <input type="Hidden" name="action" value='del'>
        <font color="#FF0000">此操作同时将删除该分类下的全部软件！</font></td>
          </tr>
        </form>
      </table><br><br>
      <% end sub 
		sub Sysmsg(msgtitle,msginfo)
		%> <br>
<table width="85%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableBorder2" >
  <tr> 
    <th><%=msgtitle%></th>
  </tr>
  <tr> 
    <td align="center" class="tablebody1"><%=msginfo%></td>
  </tr>
  <tr> 
    <td height="22" align="center" class="forumRowHighlight"><a href="admin_down_classmana2.asp" >&lt;&lt; 
      返回上一页</a></td>
  </tr>
</table>
<br><br> <%end sub %>
</BODY>
