<%
'=================================================================================
'                             +-生成某个类的所有分页-+
'函数：CreateHtml(classid,pagesizes)
'功能：生成某个类的所有分页
'参数：
'classid   		---栏目ID
'pagesizes 		---每页显示的记录个数
'=================================================================================
sub CreateHtml(classid,pagesizes)
	dim currentpage,TempArr,Tempdir,ListName,totalnum,pagenum,TempContWrit,dirArr
	dim parentlist,parentrootpath,classdir,newsHref,queryStr,curOffSet,c_keywords,c_desc
	Set fs=Server.CreateObject("Scripting.FileSystemObject")	
	Set rs = Server.CreateObject("adodb.recordset")
	sql="select templet,title,savedir,keywords,description 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")
		c_keywords=rs("keywords")
		c_desc=rs("description")
	else
		response.Write("没有找到栏目(id为:"&classid&")!<input type='button' value='继续发布 →' onclick="&Chr(34)&"javascript:location.href='send.asp'"&Chr(34)&">")
		response.End()
	end if
	rs.close()
	set rs=nothing
	'读取信息
	queryStr="select"
	if(MaxSendPage<>0) then
		queryStr=queryStr&" top "&(MaxSendPage*pagesizes)
	end if
	queryStr=queryStr&" id,SoftName,SoftLicense,SoftAttr,SoftSize,SoftStars,ModifyDate,SoftDemons,SoftOs,SoftHits from t_download_soft where IsCheck=1 and CatalogId="&classid&" order by id desc"
	Set rs = Server.CreateObject("adodb.recordset")
	rs.open queryStr,conn,3,1
	if not rs.eof and not rs.bof then
		TempArr=rs.GetRows()
		totalnum=ubound(TempArr,2)+1'新闻总数	
	else
		totalnum=0			
	end if
	rs.close
	set rs=nothing
	
	pagenum=int((totalnum+pagesizes-1)/pagesizes)'获取总页数
	if(pagenum<1) then 
		pagenum=1
	end if
	if(MaxSendPage<>0 and pagenum>MaxSendPage) then
		pagenum=MaxSendPage
	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)
		call MakeDir(server.mappath(classdir))		
	next
	'读取模板内容
	If (fs.FileExists(server.mappath(Tempdir))) Then
		TempCont=ReadFromTextFile(server.mappath(Tempdir))
		'set file_r = fs.opentextfile(server.mappath(Tempdir),1,True)'读取模板文件
		'TempCont= file_r.ReadAll
		'file_r.close()
		'set file_r=nothing	
		'response.Write(TempCont)'打印模板内容
	else
		response.Write("没有找到模板文件："&server.mappath(Tempdir))
		response.End()
	end if
	if(TempCont<>"") then
		TempCont=replace(TempCont,"$keywords$",c_keywords)
		TempCont=replace(TempCont,"$description$",c_desc)
	else
		response.Write("错误，模板内容为空")
		response.End()
	end if
	'生成每页的HTML文件
	if totalnum<=0 then
		dim blankContent
		blankContent=TempCont
		'替换更新的内容						
		blankContent=replace(blankContent,"$SoftList$","暂时没有数据")		
		blankContent=ReplaceAllLabel(blankContent,classid)		
		blankContent=replace(blankContent,"$ShowPage$","")
		call SaveTextFile(server.mappath(parentrootpath)&"\index_1.htm",blankContent)
		'Set file_w = fs.CreateTextFile(server.mappath(parentrootpath)&"\index_1.htm",true)	
		'file_w.WriteLine(blankContent)
		'file_w.close
		'set file_w=nothing
		response.Write("文件成功保存至："&server.mappath(parentrootpath)&"\index_1.htm")
	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;"
			GetSoftList=""
			for rows=0 to pagesizes-1
				curOffSet=(currentpage-1)*pagesizes+rows
				if (curOffSet>=totalnum) then
		  			exit for
		 		end if				
				newsHref=SiteUrl&"/soft/"&TempArr(0,curOffSet)&".htm"
				GetSoftList=GetSoftList&"<table cellspacing=""0"" cellpadding=""0"" align=""center"" width=""100%"">"&Chr(13)
				GetSoftList=GetSoftList&"<tr>"&Chr(13)
			  GetSoftList=GetSoftList&"  <td height=""29"" class=""soft_th""><span class=""col_right"">更新："&year(TempArr(6,curOffSet))&"-"&month(TempArr(6,curOffSet))&"-"&day(TempArr(6,curOffSet))&"</span> <a href="""&newsHref&""" class=""soft_title"">"&TempArr(1,curOffSet)&"</a></td>"&Chr(13)
			  GetSoftList=GetSoftList&"</tr>"&Chr(13)
			  GetSoftList=GetSoftList&"<tr>"&Chr(13)
			  GetSoftList=GetSoftList&"  <td class=""soft_desc"">"&TempArr(7,curOffSet)&"...</td>"&Chr(13)
			  GetSoftList=GetSoftList&"</tr>"&Chr(13)
			  GetSoftList=GetSoftList&"<tr>"&Chr(13)
			  GetSoftList=GetSoftList&"  <td class=""soft_td""><strong>大小：</strong>"&TempArr(4,curOffSet)&" | <strong>平台：</strong>"&TempArr(8,curOffSet)&" |　<strong>授权：</strong>"&TempArr(2,curOffSet)&"</td>"&Chr(13)
			  GetSoftList=GetSoftList&"</tr>"&Chr(13)
			  GetSoftList=GetSoftList&"<tr>"&Chr(13)
			  GetSoftList=GetSoftList&"  <td class=""soft_td""><strong>软件评价：</strong><img src=""/soft/images/star"&TempArr(5,curOffSet)&".gif"" />|　<strong>软件类型：</strong> "&TempArr(3,curOffSet)&"　|　<strong>人气：</strong>"&TempArr(9,curOffSet)&"</td>"&Chr(13)
			  GetSoftList=GetSoftList&"</tr>"&Chr(13)
			  GetSoftList=GetSoftList&"</table>"&Chr(13)			
			next	
		
			'替换更新的内容						
			TempContWrit=replace(TempContWrit,"$SoftList$",GetSoftList)		
			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")
			call SaveTextFile(server.mappath(parentrootpath)&"/index_"&currentpage&".htm",TempContWrit)
			'Set file_w = fs.CreateTextFile(server.mappath(parentrootpath)&"/index_"&currentpage&".htm",true)		
			'file_w.WriteLine(TempContWrit)
			'file_w.close
			'set file_w=nothing
		next
	
	end if
	set fs=nothing
	set TempArr=nothing
end sub 


'=================================================================================
'                             +-生成某个栏目首页-+
'函数：CreateCatalogHtml(classid)
'功能：生成某个类的所有分页
'参数：
'classid   		---栏目ID
'=================================================================================
sub CreateCatalogHtml(classid)
	dim currentpage,TempArr,Tempdir,ListName,totalnum,pagenum,TempContWrit
	dim parentlist,parentrootpath,classdir,c_keywords,c_desc
	Set fs=Server.CreateObject("Scripting.FileSystemObject")
	Set rs = Server.CreateObject("adodb.recordset")
	sql="select templet,title,savedir,keywords,description 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")
		c_keywords=rs("keywords")
		c_desc=rs("description")
	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)
		call MakeDir(server.mappath(classdir))		
	next
	'读取模板内容
	If (fs.FileExists(server.mappath(Tempdir))) Then
		TempCont=ReadFromTextFile(server.mappath(Tempdir))
		'set file_r = fs.opentextfile(server.mappath(Tempdir),1,True)		'读取模板文件
		'TempCont= file_r.ReadAll
		'file_r.close()
		'set file_r=nothing	
		'response.Write(TempCont)'打印模板内容
	else
		response.write("错误!没有找到模板文件:"&server.mappath(Tempdir))
		response.End()
	end if
	if(TempCont<>"") then
		TempCont=replace(TempCont,"$keywords$",c_keywords)
		TempCont=replace(TempCont,"$description$",c_desc)
	else
		response.Write("错误，模板内容为空")
		response.End()
	end if
	'生成每页的HTML文件
						
		'替换更新的内容						
		'TempCont=replace(TempCont,"$SoftList$",GetSoftList)		
		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")
		call SaveTextFile(server.mappath(parentrootpath)&"/index.htm",TempCont)
		'Set file_w = fs.CreateTextFile(server.mappath(parentrootpath)&"/index.htm",true)		
		'file_w.WriteLine(TempCont)
		'file_w.close
		'set file_w=nothing

set fs=nothing
end sub
%>