<?php
ob_start(); 
include_once("../comm/db_sql.php");
include_once("../comm/config.php");
include_once("../comm/connect.php");
include_once("../comm/Function.php");
include_once("../product/Function.php");
include_once("../../Smarty/Smarty.class.php");

function info_query_rows($db)
	{
				$info_query=new mysql_db();
				$info_query->table=$db."product_sub_category"; 
				$info_query->table_mod="5"; 
				$info_query->table_where="1";
				$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;
	}
	$rows=info_query_rows($db);	
	$id=$_GET['id'];
	$state=$_GET['state'];
$page_size="0"; //服务器一次处理100个数据
if ($state<>"ok"){
if(empty($id) and $id<>"0" )
{
	        $id=0;
	    	echo "共有".$rows."个数据";
	        echo "正在生成第".$id."个数据";
		header("refresh:0;url='create_hot_sub_category.php?id=".$id."'");
		ob_end_flush();	
		
}else
{
	if ($rows>$id+$page_size){
			$id=$id+$page_size+1;
	    	echo "共有".$rows."个数据";
	        echo "正在生成第".$id."个数据";
				header("refresh:0;url='create_hot_sub_category.php?id=".$id."'");
				ob_end_flush();	
		}else
		{
			$id=$id+$page_size+1;
			$page_size=$rows-($id+$page_size);
			echo $page_size;
			if ($page_size<0)
				{	
					header("refresh:0;url='create_hot_sub_category.php?state=ok'");
					ob_end_flush();	
				}
			else
				{
	    	        echo "共有".$rows."个数据";
	                echo "正在生成第".$id."个数据";
					header("refresh:0;url='create_hot_sub_category.php?id=".$id."'");
					ob_end_flush();	
				}

		}
}


}else
{		
			echo "数据库生成完成!";
}


//系统调用

//返回当前查询行ID
function info_query_ID($s,$db)
	{
				
				$info_query=new mysql_db();
				$info_query->table=$db."product_sub_category"; 
				$info_query->table_mod="5"; 
				$info_query->table_where="1";
				$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();
				$category_record = array("Id"=>$info_query->record['Id'], 
									  	 "channel"=>$info_query->record['channel']
										 ); 
				return($category_record);
				$info_query=NULL;
	}
function create_html($id,$channel)
	{      
	        $f_p = "../../product/sub_category_hot_1_".$channel."_".$id.".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."/product/sub_category_hot.php?id=".$id."&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);
	}
function info_create_list($id,$page_size,$db)
	{
			for($i=0;$i<=$page_size;$i++)
			{
			    $record=info_query_ID($id+$i,$db);
				$id=$record['Id'];
				$channel=$record['channel'];
				if($id != "" and $channel !="")
				{
					create_html($id,$channel);
				}
			}
	}

 	info_create_list($id,$page_size,$db);
	
?>