<?php 
require_once('session.php');
require_once('../fun/funsql.php'); 
require_once('../fun/funlogic.php');
require_once('../fun/funhtml.php');
set_time_limit(0);
if (isset($_GET["rel"])){$rel=$_GET["rel"];}else{$rel="";}
$htmlstr=new htmlstr($dbz,"../");



$fp=openfile("../cache/config.txt");
$fps=explode(",,",$fp);
$newsfp=openfile("../cache/newsconfig.txt");
$newsfps=explode(",,",$newsfp);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Home</title>
<link href="css_body.css" rel="stylesheet" type="text/css" />
</head>
<script type="text/javascript" src="../fun/adminjs.js"></script>
<body>
<?php 
if($rel=='page_html'){
  $id=@funstr($_GET["id"]);
  $str='';
  if($id==''){
    $sql=query("select * from ".$dbz."page order by id desc limit 0,1");
	if($row=fetch($sql)){
	  if($row["styles"]==1){$str=$htmlstr->pagestr($row["id"]);}elseif($row["tags"]==1){$str=$htmlstr->globals($row["mg"]);}else{$str=$row["mg"];}
	}
	createfile("../".$row["files"],$str);
	echo tanshow("","main.php?rel=page_add");
  }
  else{
    $sql=query("select * from ".$dbz."page where id=$id");
	if($row=fetch($sql)){
	  if($row["styles"]==1){$str=$htmlstr->pagestr($id);}elseif($row["tags"]==1){$str=$htmlstr->globals($row["mg"]);}else{$str=$row["mg"];}
	}
	createfile("../".$row["files"],$str);
	echo tanshow("","main.php?rel=page");
  }
}?>

<?php 
if($rel=='news_html'){
  $id=@funstr($_GET["id"]);
  $page=@funstr($_GET["page"]);
  $str='';
  if($id==''){
    $sql=query("select * from ".$dbz."news order by id desc limit 0,1");
	if($row=fetch($sql)){
	  $str=$htmlstr->newstr($row["id"],0);
	  createfile("../news/".$row["id"].".htm",$str);
	  $arrs=explode("{[c9:pagelist]}",$row["mg"]);
	  $arri=1;
	  while($arri<count($arrs)){
	    $str=$htmlstr->newstr($row["id"],$arri);
	    createfile("../news/".$row["id"]."_".($arri+1).".htm",$str);
		$arri+=1;
	  }
	}
	echo tanshow("","news.php?rel=news_add");
  }
  else{
    $sql=query("select * from ".$dbz."news where id=$id");
	if($row=fetch($sql)){
	  
	  $str=$htmlstr->newstr($row["id"],0);
	  createfile("../news/".$row["id"].".htm",$str);
	  $arrs=explode("{[c9:pagelist]}",$row["mg"]);
	  $arri=1;
	  while($arri<count($arrs)){
	    $str=$htmlstr->newstr($row["id"],$arri);
	    createfile("../news/".$row["id"]."_".($arri+1).".htm",$str);
		$arri+=1;
	  }
	}
	echo tanshow("","news.php?rel=news&page=$page");
  }
}
?>

<?php 
if($rel=='class_html'){
  $id=@funstr($_GET["id"]);
  $page=@funstr($_GET["page"]);
  if($page==''){$page=0;}
  echo "正在生成分类ID为:$id";
  $sql=query("select * from ".$dbz."class where id=$id");
  if($row=fetch($sql)){
    if($row["lists"]==1){
	  $nums=rows(query("select * from ".$dbz."news where trees like '%:".$id.":%'"));
	  $num=ceil($nums/$newsfps[2]);
	  if($page==0){
	    $str=$htmlstr->liststr($id,$page);
		createfile("../newslist/".$id.".htm",$str);
		echo tanshow("","html.php?rel=class_html&id=$id&page=".($page+1));
	  }
	  else{
	    if($page<$num){
		  $str=$htmlstr->liststr($id,$page);
		  createfile("../newslist/".$id."_".($page+1).".htm",$str);
		  echo tanshow("","html.php?rel=class_html&id=$id&page=".($page+1));
		}
		else{
		  echo tanshow("","class.php?rel=class");
		}
	  }
	}
	else{
	  $str=$htmlstr->classstr($id);
	  createfile("../newslist/".$id.".htm",$str);
	  echo tanshow("","class.php?rel=class");
	}
  }
}
?>

<?php 
if($rel=='index_html'){
  $str=$htmlstr->indexs();
  createfile("../index.htm",$str);
  echo "首页生成地址:<a href=\"../index.htm\" target=_blank>index.htm</a>";
}
?>

<?php 
if($rel=='class_while_html'){
  $id=@funstr($_GET["id"]);
  $page=@funstr($_GET["page"]);
  if($id==''){$id=0;}
  if($page==''){$page=0;}
  
  $sql=query("select * from ".$dbz."class where id>$id order by id asc limit 0,1");
  if($row=fetch($sql)){
    $id=$row["id"];
	echo "正在生成分类ID为:$id";
    if($row["lists"]==1){
	  $nums=rows(query("select * from ".$dbz."news where trees like '%:".$id.":%'"));
	  $num=ceil($nums/$newsfps[2]);
	  if($page==0){
	    $str=$htmlstr->liststr($id,$page);
		createfile("../newslist/".$id.".htm",$str);
		echo tanshow("","html.php?rel=class_while_html&id=$id&page=".($page+1));
	  }
	  else{
	    if($page<$num){
		  $str=$htmlstr->liststr($id,$page);
		  createfile("../newslist/".$id."_".($page+1).".htm",$str);
		  echo tanshow("","html.php?rel=class_while_html&id=$id&page=".($page+1));
		}
		else{
		  echo tanshow("","html.php?rel=class_while_html&id=$id");
		}
	  }
	}
	else{
	  $str=$htmlstr->classstr($id);
	  createfile("../newslist/".$id.".htm",$str);
	  echo tanshow("","html.php?rel=class_while_html&id=$id");
	}
  }
  else{
    echo "全部分类静态完成.";
  }
}
?>

<?php if($rel=='news_html_num'){?>
<div class='bodytitle'><div class='bodytitleleft'></div><div class='bodytitletxt'>信息静态设置</div></div>
<table width="96%" border="0" cellpadding="0" cellspacing="0" align="center" style="margin-bottom:8px;display:block" id="td1" >
<tr> 
<td>
<form id="form1" name="form1" method="get" action="html.php">
<input type="hidden" name="rel" value="news_while_html">
<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#E2F5BC" class="sysinfo">
<tr align="center" height="24">
<td height="30" colspan="3" align="left" bgcolor="#EDF9D5"><b>&nbsp;信息静态设置</b>    &nbsp;&nbsp;</td>
</tr>
<tr align="center"> 
<td width="20%" height="25" bgcolor="#FFFFFF">变量说明</td>
<td bgcolor="#FFFFFF">变量值</td>
<td width="30%" bgcolor="#FFFFFF">介绍</td>
</tr>  
<tr align="center" height="24" bgcolor="#FFFFFF"> 
<td height="30" align="left" bgcolor="#FFFFFF"> 开始ID:</td>
<td align="left" bgcolor="#FFFFFF">
<input type='text' name='starts' id='starts' value='0' style='width:60%'></td>
<td align="left" bgcolor="#FFFFFF">只能为数字</td>
</tr>
<tr align="center" height="24" bgcolor="#FFFFFF"> 
<td height="30" align="left" bgcolor="#FFFFFF"> 结束ID:</td>
<td align="left" bgcolor="#FFFFFF">
<input type='text' name='ends' id='ends' value='1000' style='width:60%'></td>
<td align="left" bgcolor="#FFFFFF">只能为数字</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="#E2F5BC" class="sysinfo">
<tr align="center" height="24">
  <td height="30" colspan="3" align="left" bgcolor="#EDF9D5"><b>&nbsp;请按照说明设置.</b></td>
  </tr>
<tr align="center" height="24">
  <td height="30" colspan="3" align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="确定" /> 
    <input type="reset" name="Submit2" value="重置" /></td>
  </tr>
</table>
</form>
</td>
</tr>
</table>
<?php }?>

<?php 
if($rel=='news_while_html'){
  $starts=funstr($_GET["starts"]);
  $ends=funstr($_GET["ends"]);
  
  if($starts>$ends){
    echo "按照设置静态完成.";
  }
  else{
    $sql=query("select * from ".$dbz."news where id>$starts order by id asc limit 0,1");
	if($row=fetch($sql)){
	  echo "正在静态信息ID:".$row["id"];
	  $str=$htmlstr->newstr($row["id"],0);
	  createfile("../news/".$row["id"].".htm",$str);
	  $arrs=explode("{[c9:pagelist]}",$row["mg"]);
	  $arri=1;
	  while($arri<count($arrs)){
	    $str=$htmlstr->newstr($row["id"],$arri);
	    createfile("../news/".$row["id"]."_".($arri+1).".htm",$str);
		$arri+=1;
	  }
	  
	  echo tanshow("","html.php?rel=news_while_html&starts=".$row["id"]."&ends=$ends");
	}
	else{
	  echo "按照设置静态完成.";
	}
  }
}
?>

<?php mysql_close();?>
</body>
</html>