<!-- #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">
<%
dim isEdit,boname,msgtitle,msginfo
Dvbbs.LoadTemplates("")
Dvbbs.Head()
	Server.ScriptTimeout=999999

	dim admin_flag
	admin_flag=",22"
	if not Dvbbs.master then
		response.write "<BR><li>本页面为管理员专用，请<a href=admin_login.asp target=_top>登陆</a>后进入。<br><li>您没有管理本页面的权限。"
		response.end
	else

   %>
<SCRIPT LANGUAGE=javascript>
<!--
function Juge(myform)
{

	if (myform.Class.value == "")
	{
		alert("大类名称不能为空！");
		myform.Class.focus();
		return (false);
	}

}


function SelectAll() {
	for (var i=0;i<document.selform.selCateID.length;i++) {
		var e=document.selform.selCateID[i];
		e.checked=!e.checked;
	}
}
//-->
</script>
</head>

<BODY  leftMargin=0>
<% 
if dvbbs.master then   
  select case request("action")
  case "add"
       call SaveAdd()
  case "modify"
       call SaveModify()
  case "del"
       call delCate()
  case "edit"
       isEdit=True
       call myform(isEdit)
  case else
       isEdit=False
       call myform(isEdit) 
  end select
else
  Errmsg=Errmsg+"<br>"+"<li>本页面为管理员专用，请<a href=admin_index.asp target=_top>登陆</a>后进入。<br><li>您没有管理本页面的权限。"
		call dvbbs_error()
end if
  
  
  sub SaveAdd  
      msgtitle="添加大类"
	  if trim(request("Class"))="" then
	   msginfo="添加时出现错误，大类名称不能为空！" 
	  else
	     set rs=server.createobject("adodb.recordset")   '检查版面是否重名
         rs.open "select * from Dclass where Class='" & trim(request("Class")) & "'",conndown,1,1	     
           if not(rs.bof and rs.eof) then
	       msginfo="添加时出现错误，已经有相同名称的大类已存在！"
           else
		    sql="insert into [Dclass](Class) values('" & trim(request("Class")) & "')"
            conndown.execute sql  
            msginfo="添加成功，<a href=""Admin_down_classmana.asp"">点此继续添加分类</a>！" 
		    end if
	     rs.close
	     set rs=nothing
	   end if	
        call Sysmsg(msgtitle,msginfo) 
  end sub 
  
  
  sub SaveModify()
     msgtitle="修改大类"
	  if trim(request("Class"))="" then
	   msginfo="修改大类时出现错误，大类名称不能为空！" 
	  else
	     set rs=server.createobject("adodb.recordset")   '检查版面是否重名
         rs.open "select * from [Dclass] where Class='" & trim(request("Class")) & "'",conndown,1,1	     
           if not(rs.bof and rs.eof) then
	       msginfo="修改大类时出现错误，已经有相同名称的大类已存在！"
           else
		    sql="update [Dclass] set Class='" & trim(request("Class")) & "' where ClassID=" & cstr(request("classID"))
	         conndown.execute sql
            msginfo="修改成功，<a href=""Admin_down_classmana.asp"">点此返回大类管理页面</a>！" 
		    end if
	     rs.close
	     set rs=nothing
	  end if 		 
	call Sysmsg(msgtitle,msginfo) 
  end sub 
  
  sub delCate()
  if Request.Form("selCateID")<>"" then
        msgtitle="删除大类"
        conndown.execute("delete from [Dclass] where ClassID in ("&Request.Form("selCateID")&")")
		'删除该分类下的全部子分类及软件
		conndown.execute("delete from [DNclass] where classID in ("&Request.Form("selCateID")&")")		
		conndown.execute("delete from [download] where classID in ("&Request.Form("selCateID")&")") 
		msginfo="删除操作成功，该分类相关信息已全部删除，<a href=""Admin_down_classmana.asp"">点此返回大类管理页面</a>！" 
        else
		msginfo="删除操作不成功，没有选择分类，<a href=""Admin_down_classmana.asp"">点此返回大类管理页面</a>！" 
		end if
		call Sysmsg(msgtitle,msginfo) 
		
  end sub
  %> <% sub myform(isEdit) %> 
  <table width="85%" 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="85%" border="0" align="center" cellpadding="3" cellspacing="1" class="tableBorder2">
  <tr> 
    <th height="23" colspan="2"> 
      <%
	    set rs=server.createobject("adodb.recordset")
	   if isedit then
	   		boname="修 改"
		   rs.open "select * from [Dclass] where ClassID=" & request("ClassID"),conndown,1,1
	       response.write "编辑大类"
	   else
	       response.write "添加大类"
	       boname="添 加"
	   end if %></th>
        </tr>
        <form name="myform" method="post" action="Admin_down_classmana.asp" onSubmit="return Juge(this)" >
          
    <tr> 
      <td colspan="2" align="center" class="tablebody2"> 
        <input type="Hidden" name="action" value='<% If isedit then%>modify<% Else %>add<% End If %>'> 
              <%If isedit then%> <input type="Hidden" name="ClassID" value='<%=request("ClassID")%>'> 
              <%End If%>
              <%=boname%>大类名称： 
              <input type="text" name="Class" maxlength=40 size="20" value='<% if isedit then
		                                                         response.write rs("Class") 
																 rs.close
															 end if %>'> <input name="submit" type=submit value="<%=boname%>"> 
            </td>
          </tr>
        </form>
        <form name="selform" method="post" action="Admin_down_classmana.asp" >
          
    <tr> 
      <td width="15%" align="center" class="tablebody2">ID</td>
            
      <td width="85%" class="tablebody2">版面名称 </td>
          </tr>
          <%
         rs.open "select * from [Dclass] order by ClassID asc",conndown,1,1
	         if rs.bof and rs.eof then
		        response.write "目前没有任何版面"
	           else 
			   do while not rs.eof %>
          
    <tr> 
      <td width="15%" align="center" class="tablebody1" ><%=rs("classID")%></td>
            
      <td width="85%" class="tablebody2" > 
        <input name="selCateID" type="checkbox" id="selCateID" value="<%=rs("classID")%>"> 
              <a href="Admin_down_classmana.asp?classID=<%=rs("classID")%>&action=edit" class="ArticleList"><%=rs("Class")%></a></td>
          </tr>
          <% rs.movenext
	       loop
	       end if
		 rs.close
		 set rs=nothing
	%>
          
    <tr> 
      <td width="15%" align="center" class="forumRowHighlight">管理操作</td>
            
      <td width="85%" class="forumRow"> 选择/反选 
        <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>
      <% 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="tablebody2"><%=msginfo%></td>
  </tr>
   <tr>           
    <td height="22" align="center" class="forumRowHighlight"><a href="Admin_down_classmana.asp" >&lt;&lt; 
      返回上一页</a></td>
   </tr>
 </table>
      <br> 
	  <%end sub 
end if %> 
</BODY>