<!--#include file="../include/conn.jsp"-->
<!--#include file="../include/const.jsp"-->
<!--#include file="../include/char.jsp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><%=site_info(0)%></title>
<meta http-equiv="Content-Type" content="text/html; chaRset=gb2312">
<link href="Images/Style.css" rel="stylesheet" type="text/css">
</head>
<BODY leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<br>
<TABLE class=tableBorder cellSpacing=1 cellPadding=3 width="95%" align=center 
border=0>
  <TBODY>
    <TR> 
      <TH width="100" height=25 align="center" class=tableHeaderText>类别管理</TH>
    </TR>
    <TR> 
      <TD class=forumrow> <P><B>注意</B>：<BR>
          ①删除论坛同时将删除该论坛下所有帖子！删除分类同时删除下属论坛和其中帖子！ 操作时请完整填写表单信息。<BR>
        </P></TD>
    </TR>
  </TBODY>
</TABLE>
<br>
<%
Function BigClass(intClassID)
	Dim Result
	Result=Result&"<select class='SELECT' name=""ClassID"" id=""ClassID"">"&vbcrlf
	SQL="SELECT F_ID,F_Class FROM Shop_Class ORDER BY F_Orders"
	Set Rs=Conn.Execute(SQL)
	If Not (Rs.EOF Or Rs.BOF) Then
		Result=Result&"<option value=''>作为根分类</option>"
		Do Until Rs.EOF
			If CInt(intClassID)=Rs(0) Then
				Result=Result&"<option value="&Rs(0)&" selected>"&Rs(1)&"</option>"&vbcrlf
			Else
				Result=Result&"<option value="&Rs(0)&">"&Rs(1)&"</option>"&vbcrlf
			End If
			Rs.MoveNext
		Loop
	Else
		Result=Result&"<option value=''>尚未添加分类</option>"
	End If
	Set Rs=Nothing
	Result=Result&"</select>"&vbcrlf
	BigClass=Result
End Function

Dim Admin_flag,Action
Admin_flag="11"
'If Not CheckAdmin(Admin_Flag) Then
If 0=1 Then
    strMsg="<Li>您没有管理本页面的权限。"
    Call Msg()
Else
    SELECT Case Request("Action")
        Case "add"
            Call Add()
		Case "edit"
		    Call Edit()
		Case "edit_save"
		    Call Edit_Save()
        Case "del"
            Call Del()
		Case "Up"
			Call Up(1)
		Case "Down"
			Call Down(1)
		Case "NUp"
			Call Up(2)
		Case "NDown"
			Call Down(2)
        Case Else
            Call Main()
    End Select
End If
CloseDatabase()

Sub Main()
%>
<table class=tableBorder width="95%" border=0 align="center" cellpadding=5 cellspacing=1 >
  <tbody>
    <tr> 
      <th height=22 colspan="5" align="center" sytle="line-height:150%">分类列表</th>
    </tr>
    <tr > 
      <td class=forumHeaderBackgroundAlternate width="33%"  sytle="line-height:150%"> 
        <div align="left">分类列表</div></td>
      <td width="10%" align="center" class="forumHeaderBackgroundAlternate" >添加分类</td>
      <td width="10%" align="center" class="forumHeaderBackgroundAlternate" >添加文章</td>
      <td width="10%" align="center" class="forumHeaderBackgroundAlternate" >分类排序</td>
      <td width="10%" align="center" class="forumHeaderBackgroundAlternate" >删除分类</td>
    </tr>
    <%
	Dim ClassID,NClassID,ParentID,strClass,strNClass,strTemp,n
    SQL="SELECT Shop_Class.F_ID,Shop_Class.F_Class,Shop_Class.F_Orders,Shop_Class.F_Orders AS corder,Shop_NClass.F_ID AS F_NClassID,Shop_NClass.F_NClass,Shop_NClass.F_ParentID,Shop_NClass.F_Orders AS norder FROM Shop_Class LEFT JOIN Shop_NClass ON Shop_NClass.F_ParentID=Shop_Class.F_ID ORDER BY Shop_Class.F_Orders,Shop_NClass.F_Orders"
    Set Rs=Conn.Execute(SQL)
    If Rs.Eof Or Rs.Bof Then
		Response.Write ("<tr><td colspan='2' align='left'>&nbsp;尚未添加分类</td></tr>")	   
    Else
		strTemp=""
	    Do While Not Rs.EOF
			ClassID=Rs("F_ID")
			ParentID=Rs("F_ParentID")
			NClassID=Rs("F_NClassID")
			strClass=Rs("F_Class")
			strNClass=Rs("F_NClass")
			If strClass<>strTemp Then
				strTemp=strClass
	
%>
    <tr > 
      <td align="left" class=forumRowHighlight> 
        <%Response.write "<img src='images/collapse.gif' align='absmiddle'>&nbsp;"
		  Response.Write ("<a href=?Action=edit&ClassID="&ClassID&"><font class=bold>" & strClass &"</font></a>")
		  %>
      </td>
      <td width="10%" align="center" class=forumRowHighlight>&nbsp; 
        <%Response.Write ("<a href=?ClassID="&ClassID&" style='color:#006699'>添加分类</a>")%>
      </td>
      <td width="10%" align="center" class=forumRowHighlight>&nbsp; 
        <%Response.Write ("<a href=Admin_ArticleAdd.jsp?ClassID="&ClassID&" style='color:#006699'>添加文章</a> ")%>
      </td>
      <td width="10%" align="center" class=forumRowHighlight>&nbsp; 
        <%Response.Write "<a href=?Action=Up&Orders="&Rs("corder")&">↑</a> "&" <a href=?Action=Down&Orders="&Rs("corder")&">↓</a>"%>
      </td>
      <td width="10%" align="center" class=forumRowHighlight> 
        <%Response.Write ("<a href=?Action=del&ClassID="&ClassID&"  onClick=""{if(confirm('该操作将删除分类『"&strClass&"』下的所有文章，确定执行吗?')){return true;}return false;}"">删除</a>")%>
      </td>
    </tr>
    <%
			End If
			If strNClass<>"" Then			
			%>
    <tr > 
      <td align="left" class=forumRow> 
        <%Response.write "<img hspace=2 src=""images/blank.gIf"" width=""16"" height=""16"" align=absmiddle>"
		  Response.Write (" <a href=?Action=edit&NClassID="&NClassID&"&ParentID="&ParentID&" style='color:#006699'>" & strNClass &"</a>")%>
      </td>
      <td width="10%" align="center" class=forumRow>&nbsp; </td>
      <td width="10%" align="center" class=forumRow>&nbsp; 
        <%Response.Write ("<a href='Admin_ArticleAdd.jsp?ClassID="&ClassID&"&NClassID="&NClassID&"' style='color:#006699'>添加文章</a>")%>
      </td>
      <td width="10%" align="center" class=forumRow>&nbsp; 
        <% Response.Write "<a href=?Action=NUp&Orders="&Rs("norder")&">↑</a> "&" <a href=?Action=NDown&Orders="&Rs("norder")&">↓</a>"%>
      </td>
      <td width="10%" align="center" class=forumRow> 
        <% Response.Write ("<a href=?Action=del&NClassID="&NClassID&"  onClick=""{if(confirm('该操作将删除分类『"&strNClass&"』下的所有文章，确定执行吗?')){return true;}return false;}"" style='color:#006699'>删除</a>")%>
      </td>
    </tr>
    <%
			End If
			Rs.MoveNext
	    Loop
	End If 
	%>
  </tbody>
</table>
<br>
<form name="myform" method="post" action="?">
  <table class=tableBorder width="95%" border=0 align="center" cellpadding=5 cellspacing=1>
    <tbody>
      <tr> 
        <th height=21 colspan="2" sytle="line-height:150%">添加分类</th>
      </tr>
      <tr> 
        <td width="21%"  class=forumRow> 分类名称： </td>
        <td width="79%"  class=forumRowHighlight>
		<input name="ClassName" type="text"  class="INPUT" id="ClassName"></td>
      </tr>
      <tr> 
        <td class=forumRow>父级分类：</td>
        <td class=forumRowHighlight><%=BigClass(0)%></td>
      </tr>
      <tr> 
        <td class=forumRow>&nbsp;</td>
        <td class=forumRowHighlight><input type="submit" name="Submit" value="提交" class="button"> <input type="reSet" name="Submit2" value="重置" class="button"> 
          <input name="action" type="hidden" id="action" value="add"> </td>
      </tr>
    </tbody>
  </table>
</form>
<%
End Sub

Sub Edit()
    Dim eRs,ClassID,NClassID,ParentID
	ClassID=Request.QueryString("ClassID")
	NClassID=Request.QueryString("NClassID")
	ParentID=Request.QueryString("ParentID")
	If ClassID="" Then
		SQL="SELECT * From Shop_NClass WHERE F_ID="&NClassID
	Else
		SQL="SELECT * From Shop_Class WHERE F_ID="&ClassID
	End If
	Set eRs=Conn.Execute(SQL)
%>
<form name="myform" method="post" action="?">
  <table class=tableBorder width="95%" border=0 align="center" cellpadding=5 cellspacing=1 >
    <tbody>
      <tr> 
        <th height=21 colspan="2" sytle="line-height:150%">修改分类</th>
      </tr>
      <tr> 
        <td width="21%"  class=forumRow> 分类名称： </td>
        <td width="79%" class=forumRowHighlight> <input name="ClassName" type="text" class="INPUT" id="ClassName" value="<%=eRs(1)%>"></td>
      </tr>
      <%If ClassID="" Then%>
      <tr> 
        <td class=forumRow>父级分类：</td>
        <td class=forumRowHighlight> <%=BigClass(ParentID)%> <input name="oldParentID" type="hidden" id="oldParentID" value="<%=ParentID%>"> 
          <input name="NClassID" type="hidden" id="NClassID" value="<%=NClassID%>"></td>
      </tr>
      <%End If%>
      <tr> 
        <td class=forumRow>&nbsp;</td>
        <td class=forumRowHighlight> <input type="submit" name="Submit" value="提交" class="button"> <input type="reSet" name="Submit2" value="重置" class="button"> 
          <input name="action" type="hidden" id="action" value="edit_save"> <input name="GoUrl" type="hidden" id="GoUrl" value="<%=Url%>"></td>
      </tr>
    </tbody>
  </table>
</form>
<%
    Set eRs=Nothing
End Sub

Sub Add()
    Dim strClass,ClassTemplate,ClassID,NClassID,arrClassID,ParentID
	Dim CurrentID,CurrRootID,Orders
	strClass=CheckStr(Request.Form("ClassName"))
	ClassTemplate=CheckStr(Request.Form("Template"))
	ClassID=Request.Form("ClassID")
	If strClass="" Then
		strMsg="<li>分类名称不能为空"
		Response.write strMsg
		response.end
	End If
	If ClassID="" Then
		Set Rs=Conn.Execute("SELECT Max(F_ID) FROM Shop_Class")
		If Rs.EOF Or Rs.BOF Then 
			CurrentID=1
		Else
			CurrentID=Rs(0)+1
		End If
		If IsNull(CurrentID) Then CurrentID=1
		Orders=CurrentID
		SQL="Insert Into Shop_Class(F_ID,F_Class,F_Orders) Values("
		SQL=SQL&CurrentID&",'"&strClass&"',"&Orders&")"
	ElseIf IsNumeric(ClassID) Then
	    Set Rs=Conn.Execute("SELECT Max(F_ID) FROM Shop_NClass")
		If Rs.EOF Or Rs.BOF Then 
			CurrentID=1
		Else
			CurrentID=Rs(0)+1
		End If
		If IsNull(CurrentID) Then CurrentID=1
		Orders=CurrentID
		SQL="Insert Into Shop_NClass(F_ID,F_NClass,F_ParentID,F_Orders) Values("
		SQL=SQL&CurrentID&",'"&strClass&"',"&ClassID&","&Orders&")"
	End If
	Conn.Execute(SQL)
	Set Rs=Nothing
	Response.Redirect "Admin_Class.jsp"
End Sub 

Sub Edit_Save()
    Dim strClass,ClassTemplate,ClassID,NClassID,ParentID
	strClass=CheckStr(Request.Form("ClassName"))
	'ClassTemplate=CheckStr(Request.Form("Template"))
	ClassID=Request.Form("ClassID")
	ParentID=Request.Form("oldParentID")
	NClassID=Request.Form("NClassID")

	If strClass="" Then
		strMsg="<li>分类名称不能为空"
		response.write strMsg
		response.end
	End If
	If ParentID="" Then
		SQL="UPDATE Shop_Class Set F_Class='"&strClass&"' WHERE F_ID="&Request.Form("oldClassID")
	Else
		If ClassID="" Then
		  response.write strMsg
		  response.end
		End If
		SQL="UPDATE Shop_NClass Set F_NClass='"&strClass&"',F_ParentID="&ClassID&" WHERE F_ID="&NClassID
		'If CInt(ParentID)<>Cint(ClassID) Then '如果变更所属分类则更新相应文章分类
		'	Conn.Execute("UPDATE Article SET ClassID="&ClassID&" Where ClassID="&ParentID)
		'End If
	End If
	response.write SQL
	Conn.Execute(SQL)
	Set Rs=Nothing
	Response.Redirect "Admin_Class.jsp"
End Sub

Sub Del()
    Dim ClassID,NClassID
	ClassID=Request.QueryString("ClassID")
	NClassID=Request.QueryString("NClassID")
	If ClassID<>"" Then
		SQL="SELECT Count(F_ID) FROM Shop_NClass WHERE F_ParentID="&ClassID
		Set Rs=Conn.Execute(SQL)
		If Rs(0)>=1 Then
			strMsg="该分类下含有子分类,请删除子分类后再进行本操作"
			response.write strMsg
			response.end
			
		End If
	End If
	If ClassID<>"" Then
		Conn.Execute("DELETE FROM Shop_Class WHERE F_ID="&ClassID)
		'Conn.Execute("DELETE FROM Article WHERE F_ClassID="&ClassID)
	ElseIf NClassID<>"" Then
		Conn.Execute("DELETE FROM Shop_NClass WHERE F_ID="&NClassID)
		'Conn.Execute("DELETE FROM Article WHERE NClassID="&NClassID)	
	End If
	Response.Redirect "Admin_Class.jsp"
End Sub

Sub Down(Mode)
	Dim OldOrders,NewOrders
	If Mode=1 Then
		SqlStr=" FROM Shop_Class"
	ElseIf Mode=2 Then
		SqlStr=" FROM Shop_NClass"
	End If
	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Sql="Select Top 2 F_Orders "&SqlStr&" Where F_Orders>="&Request.QueryString("Orders")&" Order By F_Orders"
	Rs.Open SQL,Conn,1,3
	If Not (Rs.EOF Or Rs.BOF) Then
		OldOrders=rs("F_orders")
		Rs.MoveNext
		If Not (Rs.EOF Or  Rs.BOF) Then
			NewOrders=Rs("F_orders")
			Rs("F_orders")=OldOrders
			Rs.Update
			Rs.MovePrevious
			Rs("F_orders")=NewOrders
			Rs.Update
		End If
	End If
	Rs.Close
	Set Rs=Nothing
	Response.Redirect "Admin_Class.jsp"
End Sub

Sub Up(Mode)
	Dim OldOrders,NewOrders
	If Mode=1 Then
		SqlStr=" FROM Shop_Class"
	ElseIf Mode=2 Then
		SqlStr=" FROM Shop_NClass"
	End If
	Set Rs=Server.CreateObject("ADODB.RecordSet")
	SQL="Select Top 2 F_Orders "&SqlStr&" Where F_Orders<="&Request.QueryString("Orders")&" Order By F_Orders Desc"
	Rs.open sql,conn,1,3
	If Not (Rs.EOF Or Rs.BOF) Then
		OldOrders=Rs("F_orders")
		Rs.MoveNext
		If Not (Rs.EOF Or Rs.BOF) Then
			NewOrders=Rs("F_orders")
			Rs("F_orders")=OldOrders
			Rs.Update
			Rs.MovePrevious
			Rs("F_orders")=NewOrders
			Rs.Update
		End If
	End If
	Rs.Close
	Set Rs=Nothing
	Response.Redirect "Admin_Class.jsp"
End Sub
%>
<br>
</body>
</html>
