<!--#include file=conn.asp--><!--#include file=../function.asp-->
<%
checkadmin 
qx=conn.execute("select qx from admin where id="&session("userid")&"")(0)

Id=Trim(request("id"))
requestTB=LCase(request("tb"))
TableName="TB_"&requestTB&"Class"
FileName="News_Class.asp?tb="&requestTB
Select Case LCase(requestTB)
Case "news":TipsTitle="新闻"':If InStr(qx,",8,")<=0 Then alertmsg "权限不够","",true
Case "honor":TipsTitle="公司荣誉"':If InStr(qx,",11,")<=0 Then alertmsg "权限不够","",true
Case "case":TipsTitle="案例"':If InStr(qx,",14,")<=0 Then alertmsg "权限不够","",true
Case "product":TipsTitle="产品"':If InStr(qx,",17,")<=0 Then alertmsg "权限不够","",true
End Select 
'|==================================================================================================================
'+ 以下部分为转换字符
'|==================================================================================================================
function HTMLEncode(fString)
If not isnull(fString) then
    fString = replace(fString, ">", "&gt;")
    fString = replace(fString, "<", "&lt;")
    fString = Replace(fString, CHR(32), "&nbsp;")
    fString = Replace(fString, CHR(9), "&nbsp;")
    fString = Replace(fString, CHR(34), "&quot;")
    fString = Replace(fString, CHR(39), "&#39;")
    fString = Replace(fString, CHR(13), "")
    fString = Replace(fString, CHR(10) & CHR(10), "</p><p> ")
    fString = Replace(fString, CHR(10), "<br> ")
    HTMLEncode = fString
End If
End Function
%>
<!--#include file=top.asp-->
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="100" class="tTitle"><div align="center">
        <table width="1000" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><div align="left"><%=TipsTitle%>分类</div>
				<div align="left" class=tTitleTips> 请注意,删除分类时无提示且为硬删除,请谨慎操作</div>
			</td>
          </tr>
        </table>
      </div></td>
    </tr>
  </table>
  <table width="1000" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td height="10"></td>
    </tr>
  </table>
  <table width="1000" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="110" align="left" valign="top">
	  
	  
	  <!--#include file=left.asp-->
	  
	  
	  
	  
	  
	  
	  </td>
      <td width="890" align="right" valign="top">
	  
	  
	  
	  
	  
	  
<table width="890" border="0" cellspacing="1" cellpadding="0" bgcolor="#c3e9ff">
  <tr bgcolor="#F6F8F1">
    <td height="30" bgcolor="#FFFFFF" align="left"><div align="center">
      <table width="840" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="30" width="140" style="border-bottom:1px dashed #99d9ff"><div align="left"><%=TipsTitle%>分类</div></td>
          <td height="30" width="700" style="border-bottom:1px dashed #99d9ff"><div align="right"><a href=?action=add&tb=<%=requestTB%> style="color:red">添加<%=TipsTitle%>分类</a>  <a href=?action=list&tb=<%=requestTB%> style="color:red"><%=TipsTitle%>分类列表</a></div></td>
        </tr>
      </table>
      <br />


<%
Select Case request("action")
Case "add":add
Case "saveadd":saveadd
Case "","list":list
Case "edit":edit
Case "saveedit":saveedit
Case "del":del
End Select 
%>









<%Sub add%>
      <table width="435" border="0" cellspacing="0" cellpadding="0" class="f14">
        <form action="?action=saveadd&tb=<%=requestTB%>" method=post>
		
		<%If requestTB="product" Then %>
		<tr>
          <td width="105" height=40><div align="right">所属分类：</div></td>
          <td width="232"><div align="left">
            <select name="ClassID">
					<option value="">-=作为一级分类=-</option>
					<%
					Dim rs,sql
					Dim BigRs,BigSql
					Set rs=server.CreateObject("adodb.recordset")
					Set BigRs=server.CreateObject("adodb.recordset")
					sql="select ClassID,ClassName,BigClass,SmallClass,OrderID from "& TableName &" where BigClass=0 and SmallClass=0 order by OrderID ASC,ClassID DESC"
					rs.open sql,conn,1,1
					
						While Not rs.eof
							response.write "<option value='"&Rs("ClassID")&"'>"&Rs("ClassName")&"</option>"
							rs.movenext
						Wend
						rs.close
					%>
				</select>
          </div></td>
          <td width="98" class=f12c969696><div align="left"></div></td>
        </tr>
		<%End if%>
        <tr>
          <td width="105" height=40><div align="right">分类名称：</div></td>
          <td width="232"><div align="left">
            <input name="ClassName" type="text" class="reginput" id="userpass" onmouseover="this.className='reginputhover'" onmouseout="this.className='reginput'" />
          </div></td>
          <td width="98" class=f12c969696><div align="left"></div></td>
        </tr>
		
		<tr>
          <td width="105" height=40><div align="right">分类排序：</div></td>
          <td width="232"><div align="left">
            <input name="OrderID" type="text" class="reginput" id="userpass" onmouseover="this.className='reginputhover'" onmouseout="this.className='reginput'" />
          </div></td>
          <td width="98" class=f12c969696><div align="left">越小越往前</div></td>
        </tr>
        
		<tr>
          <td width="105" height=40><div align="right">顶部菜单列表：</div></td>
          <td width="232"><div align="left">
            <input type="radio" name="isMenu" value="0" checked>不显示<input type="radio" name="isMenu" value="1">显示
          </div></td>
          <td width="98" class=f12c969696><div align="left">是否显示在顶部下拉菜单</div></td>
        </tr>
		<tr>
          <td height=40 colspan="3"><div align="center"><br>
            <input type="submit" value="  提  交  " class="btn" onmouseover="this.className='btn2'" onmouseout="this.className='btn'" />
          </div></td>
          </tr>
		  </form>
      </table>
      <br />

<%End Sub 
Sub saveadd
			ClassID=Trim(request("ClassID"))
			ClassName=Trim(request("ClassName"))
			OrderID=Trim(request("OrderID"))
			isMenu=Trim(request("isMenu"))
			
			If ClassName="" Then
				response.write "<script language=javascript>alert('分类名称不能为空!');history.back();</script>"
				response.End
			Else 
				ClassName=HTMLEncode(ClassName)
			End if

			If OrderID="" Or Not IsNumeric(OrderID) Then 
				OrderID=0
			End if
			If ClassID="" Or Not IsNumeric(ClassID) Then '如果ClassID为空，则添加一级分类
				sql="insert into "&TableName&" (ClassName,OrderID,remark,pic,isMenu) values('"&ClassName&"',"&OrderID&",'"&remark&"','"&pic&"',"&ismenu&")"
				conn.execute sql
			Else 
				'如果ClassID不空,则为二级或三级分类
				Dim CheckRs,CheckSql
				Set CheckRs=server.CreateObject("adodb.recordset")
				CheckSql="select ClassID,ClassName,BigClass,SmallClass,remark from "&TableName&" where ClassID="&ClassID&""
				CheckRs.open CheckSql,conn,1,1
					If CheckRs("BigClass")=0 And CheckRs("SmallClass")=0 Then '如果接收的ID为大类，则执行添加二类语句
						sql="insert into "&TableName&" (ClassName,BigClass,OrderID,remark,pic,ismenu) values ('"&ClassName&"',"&ClassID&","&OrderID&",'"&remark&"','"&pic&"',"&ismenu&")"
						conn.execute sql
					ElseIf CheckRs("SmallClass")=0 Then '如果接收的ID为二级类，则执行添加三类语句
						sql="insert into "&TableName&" (ClassName,BigClass,SmallClass,OrderID,remark,pic,ismenu) values ('"&ClassName&"',"&CheckRs("BigClass")&","&ClassID&","&OrderID&",'"&remark&"','"&pic&"',"&ismenu&")"
						conn.execute sql					
					End if	
				CheckRs.close
			End if	
			response.write "<script language=javascript>alert('添加分类成功!');location.href='"&FileName&"'</script>"
End Sub 











Sub list
%>
      <table width="860" border="0" cellspacing="1" cellpadding="0" bgcolor="#c3e9ff">
    
		<%
		Set rs=server.CreateObject("adodb.recordset")
		Set SmallRs=server.CreateObject("adodb.recordset")

	'一级SQL，取出一级分类
	sql="select * from "& TableName &" where BigClass=0 and SmallClass=0 order by OrderID ASC,ClassID DESC"
	rs.open sql,conn,1,1
		Do While Not rs.eof
		%>
        <tr bgcolor=#F6F8F1>
          <td width="650" height=40><div align="left" style="font-weight:bold">&nbsp;<%=Rs("ClassName")%></div></td>
          <td width="105" height=40><div align="center"><a href=?action=edit&classid=<%=Rs("ClassID")%>&tb=<%=requestTB%>>修改</a></div></td>
          <td width="105" height=40><div align="center"><a href=?action=del&classid=<%=Rs("ClassID")%>&tb=<%=requestTB%>>删除</a></div></td>
        </tr>

		<%
		Set BigRs=server.CreateObject("adodb.recordset")
				BigSql="select * from "&TableName&" where BigClass="&Rs("ClassID")&" and SmallClass=0 order by OrderID ASC,ClassID DESC"
				BigRs.open BigSql,conn,1,1
				If Not bigRs.eof Then 
				Do While Not BigRs.eof
				%>

        <tr bgcolor=#FFFFFF>
          <td width="650" height=40><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=BigRs("ClassName")%></div></td>
          <td width="105" height=40><div align="center"><a href=?action=edit&classid=<%=BigRs("ClassID")%>&tb=<%=requestTB%>>修改</a></div></td>
          <td width="105" height=40><div align="center"><a href=?action=del&classid=<%=BigRs("ClassID")%>&tb=<%=requestTB%>>删除</a></div></td>
        </tr>
				<%
				bigrs.movenext
				Loop
				End If 
		%>

		<%
		rs.movenext
		Loop
		rs.close
		%>


      </table>
      <br />

<%End Sub %>

<%Sub edit
classid=Int(request("classid"))
Set Rs=server.CreateObject("adodb.recordset")
Sql="select * from "&TableName&" where ClassID="&ClassID&""
Rs.open Sql,conn,1,1
%>
      <table width="435" border="0" cellspacing="0" cellpadding="0" class="f14">
        <form action="?action=saveedit&classid=<%=classid%>&tb=<%=requestTB%>" method=post>
		
        <tr>
          <td width="105" height=40><div align="right">分类名称：</div></td>
          <td width="232"><div align="left">
            <input name="ClassName" value="<%=Rs("ClassName")%>" type="text" class="reginput"  onmouseover="this.className='reginputhover'" onmouseout="this.className='reginput'" />
          </div></td>
          <td width="98" class=f12c969696><div align="left"></div></td>
        </tr>
		
		<tr>
          <td width="105" height=40><div align="right">分类排序：</div></td>
          <td width="232"><div align="left">
            <input name="OrderID" type="text" value="<%=Rs("OrderID")%>" class="reginput"  onmouseover="this.className='reginputhover'" onmouseout="this.className='reginput'" />
          </div></td>
          <td width="98" class=f12c969696><div align="left">越小越往前</div></td>
        </tr>
        
		<tr>
          <td width="105" height=40><div align="right">顶部菜单列表：</div></td>
          <td width="232"><div align="left">
            <input type="radio" name="isMenu" value="0" <%If rs("ismenu")=0 Then response.write "checked" End if%>>不显示<input type="radio" name="isMenu" value="1" <%If rs("ismenu")=1 Then response.write "checked" End if%>>显示
          </div></td>
          <td width="98" class=f12c969696><div align="left">是否显示在顶部下拉菜单</div></td>
        </tr>

		<tr>
          <td height=40 colspan="3"><div align="center"><br>
            <input type="submit" value="  修  改  " class="btn" onmouseover="this.className='btn2'" onmouseout="this.className='btn'" />
          </div></td>
          </tr>
		  </form>
      </table>
      <br />

<%
rs.close
End Sub 

Sub saveedit
EditClassID=Trim(request("ClassID"))
ClassName=Trim(request("ClassName"))
OrderID=Trim(request("OrderID"))
ismenu=Trim(request("ismenu"))

		If EditClassID="" Or Not IsNumeric(EditClassID) Then
				response.write "<script language=javascript>alert('请点击页面进行操作!');history.back();</script>"
				response.End
		End If 
		If ClassName="" Then
			response.write "<script language=javascript>alert('分类名称不能为空!');history.back();</script>"
			response.End
		Else 
			ClassName=HTMLEncode(ClassName)
		End If
		If OrderID="" Or Not IsNumeric(OrderID) Then 
			OrderID=0
		End If 
		'更新分类名
		Dim sql
		sql="update "&TableName&" set ClassName='"&ClassName&"',OrderID="&OrderID&",remark='"&remark&"',pic='"&pic&"',ismenu="&ismenu&" where ClassID="&EditClassID&""
		conn.execute sql
		response.write "<script language=javascript>alert('修改分类成功!');location.href='"&FileName&"';</script>"
End Sub


Sub del
ClassID=Trim(request("ClassID"))
		If ClassID="" Or Not IsNumeric(ClassID) Then
			response.write "<script language=javascript>alert('请点击页面进行操作!');history.back();</script>"
			response.End
		End If
		Dim rs
		Set rs=server.CreateObject("Adodb.recordset")
		sql="select * from "&TableName&" where ClassID="&ClassID&""
		rs.open sql,conn,3,2
		If rs("BigClass")=0 And rs("SmallClass")=0 Then '如果删除的类为根类时
			sql="delete from "&TableName&" where ClassID="&ClassID&"" '删除大类
			conn.execute sql
			sql="delete from "&TableName&" where BigClass="&ClassID&"" '删除根类下的子类.包括二类,三类
			conn.execute sql
		ElseIf rs("BigClass")<>0 And rs("SmallClass")=0 Then 
			sql="delete from "&TableName&" where ClassID="&ClassID&"" '删除二类
			conn.execute sql
			sql="delete from "&TableName&" where SmallClass="&ClassID&"" '删除二类下的三类
			conn.execute sql
		Else '如果为三类
			sql="delete from "&TableName&" where ClassID="&ClassID&"" '删除三类
			conn.execute sql
		End If 
		response.write "<script language=javascript>alert('删除分类成功!');location.href='"&FileName&"';</script>"
End Sub 
%>











    </div></td>
  </tr>
</table>
	  
	  
	  
	  
	  </td>
    </tr>
  </table>
  
	  </td>
    </tr>
  </table>
  <!--#include file=bottom.asp-->