<%
'=================================================================================
'                             +-生成某个类的所有分页-+
'函数：CreateHtml(classid,pagesizes)
'功能：生成某个类的所有分页
'参数：
'classid   		---栏目ID
'pagesizes 		---每页显示的记录个数
'=================================================================================
sub CreateHtml(classid,pagesizes)
	dim currentpage,TempArr,Tempdir,ListName,totalnum,pagenum,TempContWrit,dirArr
	dim parentlist,parentrootpath,classdir,newsHref,curOffset
	Set fs=Server.CreateObject("Scripting.FileSystemObject")	
	Set rs = Server.CreateObject("adodb.recordset")
	sql="select templet,title,savedir from catalogs where id="&classid
	rs.open sql,conn,3,1
	if not rs.eof then
		Tempdir=rs("templet")
		ListName=rs("title")
		parentrootpath=rs("savedir")
	else
		response.Write("暂时没有数据!<input type='button' value='继续发布 →' onclick="&Chr(34)&"javascript:location.href='send.asp'"&Chr(34)&">")
		response.End()
	end if
	rs.close()
	set rs=nothing
	'读取信息
	Set rs = Server.CreateObject("adodb.recordset")
	rs.open "select title,pagepath,id,moditime,title_color,isoutlink from news where checked=true and classid="&classid&" order by id desc",conn,3,1
	if not rs.eof and not rs.bof then
		TempArr=rs.GetRows()
	else		
		response.Write("暂时没有数据!<input type='button' value='继续发布 →' onclick="&Chr(34)&"javascript:location.href='send.asp?classid=0'"&Chr(34)&">")
		response.End()
	end if
	rs.close
	set rs=nothing
	totalnum=ubound(TempArr,2)'新闻总数	
	pagenum=int((totalnum+1+pagesizes-1)/pagesizes)'获取总页数
	if(pagenum<1) then 
		pagenum=1
	end if
	response.write("总共"&totalnum&"条："&pagenum&"(页)"&"<br>")	
	'根据分类选择建立文件夹
	
	parentlist=Split(getparentlist(classid),"|")
	response.Write(parentrootpath&"<br>")
	dirArr=split(parentrootpath,"/")
	for dirn=1 to ubound(dirArr)
		classdir=classdir&"/"&dirArr(dirn)
		If (fs.FolderExists(server.mappath(classdir))) Then		'目录是否存在
			Else
			fs.CreateFolder(server.mappath(classdir))		'创建目录
		End If
	next
	'读取模板内容
	set file_r = fs.opentextfile(server.mappath(Tempdir),1,True)'读取模板文件
	TempCont= file_r.ReadAll
	file_r.close()
	set file_r=nothing	
	'response.Write(TempCont)'打印模板内容
	
	'生成每页的HTML文件
	if totalnum<0 then
		Set file_w = fs.CreateTextFile(server.mappath(parentrootpath)&"/index_"&currentpage&".htm",true)	
		file_w.WriteLine("暂时没有数据，谢谢您的访问！<a href='"&SiteUrl&"'>返回首页</a>")
		file_w.close
		set file_w=nothing
	else	
	for currentpage=1 to pagenum
		TempContWrit=TempCont
		goPage="&nbsp;&nbsp;跳至第<select size=1 onChange=""javascript:window.location.href='index_'+(G_page.selectedIndex+1)+'.htm'"" name=""G_page"">"
		for go_n=1 to pagenum
			if(go_n=currentpage) then
				goPage=goPage&"<option value="""&go_n&""" selected>"&go_n&"</option>"
			else
				goPage=goPage&"<option value="""&go_n&""">"&go_n&"</option>"
			end if
		next
		goPage=goPage&"</select>页&nbsp;&nbsp;"
		GetNewsList=""		
		for rows=0 to pagesizes-1
			curOffset=(currentpage-1)*pagesizes+rows
			if (curOffset>totalnum) then
		  			exit for
		 	end if			
			if(TempArr(5,curOffset)=0) then
				newsHref=SiteUrl&"/"&TempArr(1,curOffset)
			else
				newsHref=TempArr(1,curOffset)
			end if
			GetNewsList=GetNewsList&"<li>"&Chr(13)
			GetNewsList=GetNewsList&"<span class=""col_right"">"&FormatDate(TempArr(3,curOffset),1)&"</span>"&Chr(13)
			GetNewsList=GetNewsList&"<a href="&Chr(34)&newsHref&Chr(34)&" target="&Chr(34)&"_blank"&Chr(34)&"> <span style=""color: "&TempArr(4,curOffset)&""">· "&TempArr(0,curOffset)&"</span></a>"&Chr(13)     			
			GetNewsList=GetNewsList&"</li>"&Chr(13)
		next
		'替换更新的内容						
		TempContWrit=replace(TempContWrit,"$NewsList$",GetNewsList)		
		TempContWrit=ReplaceAllLabel(TempContWrit,classid)
		if err.number>0 then
		response.Write(err.description)
		end if		
		TempContWrit=replace(TempContWrit,"$ShowPage$",""&showPage(currentpage,totalnum,pagenum)&goPage)
		
		'写入文件内容
		response.Write("文件成功保存到："&server.mappath(parentrootpath)&"\index_"&currentpage&".htm"&"<br>")'打印保存路径
		response.Write("OK")
		Set file_w = fs.CreateTextFile(server.mappath(parentrootpath)&"/index_"&currentpage&".htm",true)		
		file_w.WriteLine(TempContWrit&"<"&"!"&"-"&"-"&"M"&"a"&"d"&"e"&" B"&"y"&" T"&"O"&"T"&"C"&"M"&"S"&" 5"&"."&"5"&" h"&"t"&"t"&"p"&":"&"/"&"/"&"w"&"w"&"w"&"."&"t"&"o"&"t"&"c"&"m"&"s"&"."&"c"&"o"&"m"&"-"&"-"&">")
		file_w.close
		set file_w=nothing
	next
	
	end if
set fs=nothing
end sub 
'=================================================================================
'                             +-生成某个类的所有分页-+
'函数：CreateImgList(classid,pagesizes)
'功能：生成某个类的所有图片列表分页
'参数：
'classid   		---栏目ID
'pagesizes 		---每页显示的记录个数
'=================================================================================
sub CreateImgList(classid,pagesizes,rowsN,colsN,containW,containH)
	dim currentpage,TempArr,Tempdir,ListName,totalnum,pagenum,TempContWrit
	dim parentlist,parentrootpath,classdir
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	Set rs = Server.CreateObject("adodb.recordset")
	sql="select templet,title,savedir from catalogs where id="&classid
	rs.open sql,conn,3,1
	if not rs.eof then
		Tempdir=rs("templet")
		ListName=rs("title")
		parentrootpath=rs("savedir")
	else
		response.Write("暂时没有数据!<input type='button' value='继续发布 →' onclick="&Chr(34)&"javascript:location.href='send.asp'"&Chr(34)&">")
		response.End()
	end if
	rs.close()
	set rs=nothing
	'读取信息
	Set rs = Server.CreateObject("adodb.recordset")
	rs.open "select title,pagepath,id,photo from news where checked=true and classid="&classid&" order by id desc",conn,3,1
	if not rs.eof then
		TempArr=rs.GetRows()
	else
		response.Write("暂时没有数据!<input type='button' value='继续发布 →' onclick="&Chr(34)&"javascript:location.href='send.asp?classid=0'"&Chr(34)&">")
		response.End()
	end if
	rs.close
	set rs=nothing
	totalnum=ubound(TempArr,2)'新闻总数	
	pagenum=int((totalnum+1+pagesizes-1)/pagesizes)'获取总页数
	if(pagenum<1) then 
		pagenum=1
	end if
	response.write("总共"&totalnum&"条："&pagenum&"(页)"&"<br>")
	
	'根据分类选择建立文件夹
	
	parentlist=Split(getparentlist(classid),"|")
	'获得根节点的保存路径	
	response.Write(parentrootpath&"<br>")
	dirArr=split(parentrootpath,"/")
	for dirn=1 to ubound(dirArr)
		classdir=classdir&"/"&dirArr(dirn)
		If (fs.FolderExists(server.mappath(classdir))) Then		'目录是否存在
			Else
			fs.CreateFolder(server.mappath(classdir))		'创建目录
		End If
	next
	'读取模板内容
	set file_r = fs.opentextfile(server.mappath(Tempdir),1,True)'读取模板文件
	TempCont= file_r.ReadAll
	file_r.close()
	set file_r=nothing	
	'response.Write(TempCont)'打印模板内容
	
	'生成每页的HTML文件
	if totalnum<0 then
		Set file_w = fs.CreateTextFile(server.mappath(parentrootpath)&classdir&"/index_"&currentpage&".htm",true)	
		file_w.WriteLine("暂时没有数据，谢谢您的访问！<a href='"&SiteUrl&"'>返回首页</a>")
		file_w.close
		set file_w=nothing
	else	
	for currentpage=1 to pagenum
		TempContWrit=TempCont
		GetNewsList=""
		goPage="&nbsp;&nbsp;跳至第<select size=1 onChange=""javascript:window.location.href='index_'+(G_page.selectedIndex+1)+'.htm'"" name=""G_page"">"
		for go_n=1 to pagenum
			if(go_n=currentpage) then
				goPage=goPage&"<option value="""&go_n&""" selected>"&go_n&"</option>"
			else
				goPage=goPage&"<option value="""&go_n&""">"&go_n&"</option>"
			end if
		next
		goPage=goPage&"</select>页&nbsp;&nbsp;"
		'NewsArr=NewsArr&"<table width=500  border=0 align=center cellpadding=0 cellspacing=0>"&Chr(13)
		for rows=0 to rowsN-1'rowsN行		
			GetNewsList=GetNewsList&"<div class=""lazy_list_template_con""><ul>"&Chr(13)
			for cols=0 to colsN-1'colsN列
				if ((currentpage-1)*pagesizes+rows*colsN+cols>totalnum) then
		  			exit for
		  		end if
				GetNewsList=GetNewsList&"<li>"&Chr(13)				
          		GetNewsList=GetNewsList&"<div class=""img_border""><div align=""center"">"&Chr(13)
				GetNewsList=GetNewsList&"<table bgcolor=""#ffffff"" width="""&containW&""" height="""&containH&"""  border=""0"" cellpadding=""0"" cellspacing=""0"">"&Chr(13)
				GetNewsList=GetNewsList&"	<tr>"&Chr(13)
				GetNewsList=GetNewsList&"		<td>"&Chr(13)
				GetNewsList=GetNewsList&"<div align=""center""><a href="&Chr(34)&SiteUrl&"/"&TempArr(1,(currentpage-1)*pagesizes+rows*colsN+cols)&Chr(34)&" target="&Chr(34)&"_blank"&Chr(34)&"><img width="""&(containW-4)&""" height="""&(containH-4)&""" src="&Chr(34)&SiteUrl&"/"&Imgsavedir&"/"&TempArr(3,(currentpage-1)*pagesizes+rows*colsN+cols)&Chr(34)&" alt="&Chr(34)&TempArr(0,(currentpage-1)*pagesizes+rows*colsN+cols)&Chr(34)&" align=""absmiddle"" border="&Chr(34)&"0"&Chr(34)&" /></a></div>"&Chr(13)
				GetNewsList=GetNewsList&"</td></tr></table></div></div>"&Chr(13)      			
        		GetNewsList=GetNewsList&"<div><a href="&Chr(34)&SiteUrl&"/"&TempArr(1,(currentpage-1)*pagesizes+rows*colsN+cols)&Chr(34)&" target="&Chr(34)&"_blank"&Chr(34)&">"&left(TempArr(0,(currentpage-1)*pagesizes+rows*colsN+cols),12)&"</a></div>"&Chr(13)
				GetNewsList=GetNewsList&"</li>"&Chr(13)
     			if ((currentpage-1)*pagesizes+rows*colsN+cols>totalnum) then
		  			exit for
		  		end if						
			next			
			GetNewsList=GetNewsList&"</ul></div>"&Chr(13)				
			if ((currentpage-1)*pagesizes+rows*colsN+cols>totalnum) then
		  		exit for
		  	end if			
		next				
		'替换更新的内容								
		TempContWrit=replace(TempContWrit,"$NewsList$",GetNewsList)		
		TempContWrit=ReplaceAllLabel(TempContWrit,classid)
		if err.number>0 then
		response.Write(err.description)
		end if		
		TempContWrit=replace(TempContWrit,"$ShowPage$",""&showPage(currentpage,totalnum,pagenum)&goPage)
		
		'写入文件内容
		response.Write("文件成功保存到："&server.mappath(parentrootpath)&"\index_"&currentpage&".htm"&"<br>")'打印保存路径
		response.Write("OK")
		Set file_w = fs.CreateTextFile(server.mappath(parentrootpath)&"/index_"&currentpage&".htm",true)		
		file_w.WriteLine(TempContWrit&"<"&"!"&"-"&"-"&"M"&"a"&"d"&"e"&" B"&"y"&" T"&"O"&"T"&"C"&"M"&"S"&" 5"&"."&"5"&" h"&"t"&"t"&"p"&":"&"/"&"/"&"w"&"w"&"w"&"."&"t"&"o"&"t"&"c"&"m"&"s"&"."&"c"&"o"&"m"&"-"&"-"&">")
		file_w.close
		set file_w=nothing
	next
	
	end if
set fs=nothing
end sub 
'=================================================================================
'                             +-生成某个栏目首页-+
'函数：CreateCatalogHtml(classid)
'功能：生成某个类的所有分页
'参数：
'classid   		---栏目ID
'=================================================================================
sub CreateCatalogHtml(classid)
	dim currentpage,TempArr,Tempdir,ListName,totalnum,pagenum,TempContWrit
	dim parentlist,parentrootpath,classdir
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	Set rs = Server.CreateObject("adodb.recordset")
	sql="select templet,title,savedir from catalogs where id="&classid
	rs.open sql,conn,3,1
	if not rs.eof and not rs.bof then
		Tempdir=rs("templet")
		ListName=rs("title")
		parentrootpath=rs("savedir")
	else		
		response.Write("暂时没有数据!<input type='button' value='继续发布 →' onclick="&Chr(34)&"javascript:location.href='send.asp'"&Chr(34)&">")
		response.End()
	end if
	rs.close()
	set rs=nothing
	
	
	'根据分类选择建立文件夹
	
	parentlist=Split(getparentlist(classid),"|")
	'获得根节点的保存路径
	
	'response.Write(parentrootpath)	
	dirArr=split(parentrootpath,"/")
	for dirn=1 to ubound(dirArr)
		classdir=classdir&"/"&dirArr(dirn)
		If (fs.FolderExists(server.mappath(classdir))) Then		'目录是否存在
			Else
			fs.CreateFolder(server.mappath(classdir))		'创建目录
		End If
	next
	'读取模板内容
	set file_r = fs.opentextfile(server.mappath(Tempdir),1,True)'读取模板文件
	TempCont= file_r.ReadAll
	file_r.close()
	set file_r=nothing	
	'response.Write(TempCont)'打印模板内容
	
	'生成每页的HTML文件
						
		'替换更新的内容						
		'TempCont=replace(TempCont,"$NewsList$",GetNewsList)		
		TempCont=ReplaceAllLabel(TempCont,classid)
		if err.number>0 then
		response.Write(err.description)
		end if		
		'写入文件内容
		response.Write("文件成功保存到："&server.mappath(parentrootpath)&"\index.htm"&"<br>")'打印保存路径
		response.Write("OK")
		Set file_w = fs.CreateTextFile(server.mappath(parentrootpath)&"/index.htm",true)		
		file_w.WriteLine(TempCont&"<"&"!"&"-"&"-"&"M"&"a"&"d"&"e"&" B"&"y"&" T"&"O"&"T"&"C"&"M"&"S"&" 5"&"."&"5"&" h"&"t"&"t"&"p"&":"&"/"&"/"&"w"&"w"&"w"&"."&"t"&"o"&"t"&"c"&"m"&"s"&"."&"c"&"o"&"m"&"-"&"-"&">")
		file_w.close
		set file_w=nothing

set fs=nothing
end sub
%>