<!--#include file="../siteconfig/conn.asp"-->
<!--#include file="LabelHtml.asp"-->
<%
if session("adminlogin")<>sessionvar then
Response.Write("<script language=javascript>alert('你尚未登录，或者超时了！请重新登录');this.location.href='login.asp';</script>")
Response.End
End if
set rs=server.createobject("adodb.recordset")
set rss=server.createobject("adodb.recordset")
%>
<HTML>
<HEAD>
<TITLE>分类管理</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<LINK REL="stylesheet" HREF="css.css" TYPE="text/css">
</HEAD>
<script language="JavaScript" type="text/javascript" src="js.js"></script>
<BODY>
<%dim Class_SkinId,strOut,Class_Html,Class_Id,UrlClass_Id,ClassCount,StrClass,Class_Name,Class_BottomHtml,Class_TopAd,j,i,jishu,ClassAllCount,k,p,fldr,Class_TopClassId,ClassAd_TopHtml,ClassAd_BottomHtml,UrlClass_Search
Dim fso,f
rs.open"select ClassAd_Html,ClassAd_Type from ClassAd where ClassAd_ClassId=0",conn,1,3
while not rs.eof and not rs.bof
    if rs("ClassAd_Type")=0 then
	   ClassAd_TopHtml=rs("ClassAd_Html")
	else
	   ClassAd_BottomHtml=rs("ClassAd_Html")
	end if
rs.movenext
wend
rs.close
Class_Id=Request("Class_Id")
if Class_Id<>"" then
rs.open"select Class_SkinId,Class_Html,Class_Name,Class_BottomHtml,Class_TopClassId from Class where Class_Id="&Class_Id,conn,1,3
   if not rs.eof then
      if rs("Class_SkinId")=0 then
	     Class_SkinId=Site_ClassSkinId
	  else
         Class_SkinId=rs("Class_SkinId")
	  end if
	  Class_Name=rs("Class_Name")
	  Class_BottomHtml=rs("Class_BottomHtml")
	  ClassCount=int(rs.recordcount)
	  Class_Html=rs("Class_Html")
	  Class_TopClassId=rs("Class_TopClassId")
	  rs.close
	  rs.open"select Skin_Skin from Skin where Skin_Id="&Class_SkinId,conn,1,3
	      strOut=""&rs("Skin_Skin")
	  rs.close
   else
      Response.Write("<script language=javascript>alert('没有找到模板');DivOpenClose('',2,0,0);</script>")
      Response.End()
	   rs.close
   end if
   rs.open"select Class_Html,Class_Name from Class where Class_Id="&Class_TopClassId,conn,1,3
   if not rs.eof then
      strOut=Replace(strOut,"$StrTopClassHtml$","><a href="&Site_Div&rs("Class_Html")&".htm"&" target=_self>"&rs("Class_Name")&"</a>")
   else
      strOut=Replace(strOut,"$StrTopClassHtml$","")
   end if
   rs.close
   strOut=Replace(strOut,"$Class_BottomHtml$",Class_BottomHtml)
   strOut=Replace(strOut,"$StrClassName$",Class_Name)
	  rs.open"select ClassAd_Id,ClassAd_Html,ClassAd_Type from ClassAd where ClassAd_Type=0 and ClassAd_ClassId="&Class_Id,conn,1,3
	    if not rs.eof then
			 strOut=Replace(strOut,"$StrClassTopAd$",rs("ClassAd_Html"))
		else
			 strOut=Replace(strOut,"$StrClassTopAd$",ClassAd_TopHtml)
		end if
	  rs.close
	  rs.open"select ClassAd_Id,ClassAd_Html,ClassAd_Type from ClassAd where ClassAd_Type=1 and ClassAd_ClassId="&Class_Id,conn,1,3
	    if not rs.eof then
			 strOut=Replace(strOut,"$StrClassBottomAd$",rs("ClassAd_Html"))
		else
			 strOut=Replace(strOut,"$StrClassBottomAd$",ClassAd_BottomHtml)
		end if
	  rs.close
   Call SiteLable()
   Call ClassLabel()
   
    Set fso=Server.CreateObject("Scripting.FileSystemObject") 
    fldr = ""
    GetNewsFold = Split(Class_Html, "/")
    For f = 0 To UBound(GetNewsFold)-1
	if fldr="" then
		fldr=GetNewsFold(f)
	else
		fldr=fldr&"\"&GetNewsFold(f)
	end if
        If IsFolder(fldr)=false then
            CreateFolder "../"&fldr
        End If
    Next
	
   Set f=fso.CreateTextFile(Server.MapPath(Site_Div&Class_Html&".htm"),true)
   f.WriteLine strOut
   f.close
   Set f=Nothing
   Set fso=Nothing
   Response.Write("<script language=javascript>alert('生成成功');parent.window.location.reload();DivOpenClose('',2,0,0);</script>")
else
rs.open"select Class_SkinId,Class_Id,Class_TopClassId,Class_Html,Class_Name,Class_BottomHtml from Class",conn,1,3
ClassCount=int(rs.recordcount)
redim ClassArray(ClassCount,6)
j=1
while not rs.eof and not rs.bof
   ClassArray(j,0)=rs("Class_Id")
   ClassArray(j,1)=rs("Class_Name")
   ClassArray(j,2)=rs("Class_Html")
   ClassArray(j,4)=rs("Class_BottomHtml")
   if rs("Class_SkinId")=0 then
      ClassArray(j,5)=Site_ClassSkinId
   else
      ClassArray(j,5)=rs("Class_SkinId")
   end if
   ClassArray(j,6)=rs("Class_TopClassId")
   j=j+1
rs.movenext
wend
rs.close
i=1
for i=i to ClassCount
	  rs.open"select Skin_Skin from Skin where Skin_Id="&ClassArray(i,5),conn,1,3
	      strOut=rs("Skin_Skin")
	  rs.close
   strOut=Replace(strOut,"$Class_BottomHtml$",ClassArray(i,4))
   strOut=Replace(strOut,"$StrClassName$",ClassArray(i,1))
	  rs.open"select ClassAd_Html,ClassAd_Type from ClassAd where ClassAd_Type=0 and ClassAd_ClassId="&ClassArray(i,0),conn,1,3
	    if not rs.eof and not rs.bof then
			 strOut=Replace(strOut,"$StrClassTopAd$",rs("ClassAd_Html"))
		else
			 strOut=Replace(strOut,"$StrClassTopAd$",ClassAd_TopHtml)
		end if
	  rs.close
	  rs.open"select ClassAd_Html,ClassAd_Type from ClassAd where ClassAd_Type=1 and  ClassAd_ClassId="&ClassArray(i,0),conn,1,3
	    if not rs.eof and not rs.bof then
			 strOut=Replace(strOut,"$StrClassBottomAd$",rs("ClassAd_Html"))
		else
			 strOut=Replace(strOut,"$StrClassBottomAd$",ClassAd_BottomHtml)
		end if
	  rs.close
   strOut=Replace(strOut,"$StrClassId$",ClassArray(i,0))
   rs.open"select Class_Html,Class_Name from Class where Class_Id="&ClassArray(i,6),conn,1,3
   if not rs.eof then
      strOut=Replace(strOut,"$StrTopClassHtml$","><a href="&Site_Div&rs("Class_Html")&".htm"&" target=_self>"&rs("Class_Name")&"</a>")
   else
      strOut=Replace(strOut,"$StrTopClassHtml$","")
   end if
   rs.close
   Call SiteLable()
   Call ClassAllLabel()

    Set fso=Server.CreateObject("Scripting.FileSystemObject") 
    fldr = ""
    GetNewsFold = Split(ClassArray(i,2), "/")
    For f = 0 To UBound(GetNewsFold)-1
	if fldr="" then
		fldr=GetNewsFold(f)
	else
		fldr=fldr&"\"&GetNewsFold(f)
	end if
        If IsFolder(fldr)=false then
            CreateFolder "../"&fldr
        End If
    Next
	
   Set f=fso.CreateTextFile(Server.MapPath(Site_Div&ClassArray(i,2)&".htm"),true)
   f.WriteLine strOut
   f.close
   Set f=Nothing
   Set fso=Nothing
next
   Response.Write("<script language=javascript>alert('生成成功');parent.window.location.reload();DivOpenClose('',2,0,0);</script>")
end if
%>
</BODY>
</HTML>

