<?php
ob_start(); 
include_once("../comm/db_sql.php");
include "../CheckUser.php";
include_once("../comm/config.php");
include_once("../comm/connect.php");
include_once("../comm/Function.php");
include_once("../article/Function.php");

//返回总行
function info_query_rows($db)
	{
				$info_query=new mysql_db();
				$info_query->table=$db."channel"; 
				$info_query->table_mod="5"; 
				$info_query->table_where="channel=0";
				$info_query->limit="0";       
				$info_query->page_size="2000000";
				$info_query->query_object="ID"; 
				$info_query->order_by="ID asc";
				$info_query->query();
				$rows=$info_query->rows;
				return $rows;
				$info_query=NULL;
	}
	$rows=info_query_rows($db);	
	echo $rows."页";
//返回各行ID
function info_query_ID($rows,$db)
	{
				for($i=0;$i<$rows;$i++)
					{
						$s=$i;
						$channel=info_query_rows_id($s,$db); //返回各行
						$page=1;
						
						$pages=info_page_channel($db,$page,$channel);         //返回当前频道所有记录

						for($c=1;$c<=$pages;$c++)
							{
								create_html($c,$channel);
							}

						
					}
	}
//返回当前行ID
function info_query_rows_id($s,$db)
	{
				$info_query=new mysql_db();
				$info_query->table=$db."channel"; 
				$info_query->table_mod="5"; 
				$info_query->table_where="channel=0";
				$info_query->limit=$s;       
				$info_query->page_size="1";
				$info_query->query_object="*"; 
				$info_query->order_by="Id asc";
				$info_query->query();
				$info_query->query_result();
				return $info_query->record['Id'];
				$info_query=NULL;
	}
//返回当前频道所有记录数
function info_page_channel($db,$page,$channel)
	{
			$info_query=new mysql_db();
			$info_query->table=$db."article_info";  
			$info_query->table_where="channel=$channel"; 
			$info_query->page_size="36";  
			$info_query->table_mod="6";   
			$info_query->page=$page;
			$info_query->query();
			
			$prepage=$info_query->prepage;
			$nextpage=$info_query->nextpage;
			$pages=$info_query->pages;
			$rows_count=$info_query->rows_count;
			return $pages;
		}
function create_html($page,$channel)
	{      
	        $f_p = "../../article/index_".$page."_".$channel.".html";

			
			$url='';
			if ($_SERVER["SERVER_PORT"]!="80")
			{
				$url=$url.'http://'.$_SERVER['SERVER_NAME'].":".$_SERVER["SERVER_PORT"];
			}
			else
			{
				$url=$url.'http://'.$_SERVER['SERVER_NAME'];
			}	
			$url = $url."/article/index.php?page=".$page."&channel=".$channel;			
			
			$contents = file_get_contents($url);			
			$hdl = fopen ($f_p,"w");
			if(!is_writable ($f_p)){
        		echo "文件没有写的权限";
			}
			if (!fwrite ($hdl,$contents)){ 
        		echo "很抱歉！写入文件失败";  
			}
			fclose ($hdl);
	}

info_query_ID($rows,$db);

?>