<?php

/*

'**************************************************************************************************

' 软件名称: 黑色幻想舞曲管理系统CMS2.0

' 版本编号: hshxsdj 2.0

' 官方网站: http://www.hshxs.com

' 官方论坛：http://bbs.hshxs.com

' 版权所有: 黑色幻想开发团队    噬己翼(QQ:532917920)

' 郑重声明:

'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；

'    2、黑色幻想网络事业部保留此软件的法律追究权利

'**************************************************************************************************

*/


require_once("../../include/config.inc.php");

include "../../include/label.php";

include "../admin_loginstate.php";

?>

<!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=gb2312" />

<link type="text/css" href="../images/style.css" rel="stylesheet" />

<link type="text/css" href="../images/alerts.css" rel="stylesheet" media="screen">

<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>

<script language="javascript" src="../js/jquery.js"></script>

<script language="javascript" src="../js/alerts.js"></script>

</head>

<body>

<?php

SystemPer(11);

if(S_Webmode==1) die("<font color=red>当前网站为动态模式,不能生成!!</font>");

$ClassID=SafeRequest("NewsClassID","post");

if($ClassID==""){$ClassID=SafeRequest("ClassID","get");}

$type=SafeRequest("type","get");



if($ClassID=='0') $type="all";

$classnow=SafeRequest("classnow","get");

if($type=="all" or $type=="spanall"){	

	if($classnow=="") $classnow=0;

	$sql="select S_ID from s_class where S_SystemID=2";

	$classresult=$db->getAll($sql);

	$ClassID=$classresult[$classnow]['S_ID'];

	}

if(!IsNum($ClassID)) $ClassID=1;

$page=SafeRequest("pages","get");

if(!IsNum($page)){$page=1;}

//分类名

$sql="select S_ID,S_Name,S_Template from s_class where S_ID=".$ClassID."";

$row=$db->getrow($sql);

if(file_exists(_CHSHDJ_ROOT_.S_Templateurl.$row['S_Template'])){

	$ListContent=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl.$row['S_Template']);

	preg_match_all('/{chshdjcms:article(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms:article}/',$ListContent,$page_arr2);//判断是否有分页标识

	if(!empty($page_arr2) && !empty($page_arr2[2])){

		$sqlstr2=Mark_Sql("s_article",$page_arr2[1][0],$ClassID);

		$recount2=$db->num_rows($db->query($sqlstr2));

		$Arr2=SPage($sqlstr2,$page_arr2[2][0],1,1,10);//sql,每页显示条数

	}else{

		$recount2=1;

		$Arr2[6]=1;

		$page_arr2[2][0]=1;

		}

	//循环开始

	if($Arr2[6]<S_Createpre) { 

		$spanpage=1;

	}else{

		$spanpage=ceil($Arr2[6]/S_Createpre);

	}

	echo("<div style=' width:100%; background: #F9FBFD; border-top:4px solid #DEEFFA; border-bottom:1px solid #DEEFFA;color:#008EBD; font-size:10pt; height:30px; line-height:30px;font-weight:bold; margin:0 auto;'>&nbsp;正在开始生成分类列表第<font style='color:red; font-size:16px; font-style:italic'>".$page."</font>页，共<font style='color:red; font-size:16px; font-style:italic'>".$spanpage."</font>页</div>");

	

	$pagenum=getpagenum($ListContent);

	  preg_match_all('/{chshdjcms:article(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms:article}/',$ListContent,$page_arr);//判断是否有分页标识

	  	if(!empty($page_arr) && !empty($page_arr[2])){

			$sqlstr=Mark_Sql("s_article",$page_arr[1][0],$ClassID);

			}

			

	for($l=($page-1)*S_Createpre+1;$l<(S_Createpre*$page)+1;$l++){

		if($recount2=='0'){

			if((($l-1)*$page_arr2[2][0])>$recount2) break;

			}

		else{

			if((($l-1)*$page_arr2[2][0])>=$recount2) break;

			}

			

	  $Mark_Text=$ListContent;

	  $Mark_Text=topandbottom($Mark_Text);

	  $sql="select S_ID,S_Name from s_class where S_ID=".$ClassID."";

	  $row=$db->getrow($sql);

	  if($row){

		  $Mark_Text=ReplaceStr($Mark_Text,"[article:classname]",$row['S_Name']);

		  $Mark_Text=ReplaceStr($Mark_Text,"[article:classlink]",LinkClassUrl("s_class",$row['S_ID'],2,1));

		  }	

		

	  $data_content="";

		if(!empty($page_arr) && !empty($page_arr[2])){

			$Arr=SPage($sqlstr,$page_arr[2][0],$l,$ClassID,$pagenum);//sql,每页显示条数

			$result=$db->query($Arr[2]);

			$recount=$db->num_rows($result);

			if($recount==0){

				$data_content="<div align=center><strong><font style=font-size:12px;>该分类暂无数据！</font></strong></div>";

			}else{

				if($result){

					$sorti=1;

					while ($row2 = $db ->fetch_array($result)){

						$datatmp=dataart($page_arr[0][0],$page_arr[3][0],$row2,$sorti);

						$sorti=$sorti+1;

						$data_content.=$datatmp;

						}

					}

			}// end if recount

			$Mark_Text=Page_Mark($Mark_Text,$Arr);	

			$Mark_Text=ReplaceStr($Mark_Text,$page_arr[0][0],$data_content);

			unset($data_content);

		}

	 

	  $Mark_Text=Common_Mark($Mark_Text,$ClassID);

	  $spanurl=LinkClassUrl("s_class",$ClassID,2,$Arr[5]);

	  $spanurl=substr($spanurl,strlen(S_SitePath));

	  spandir($spanurl);

	  fwrite(fopen("../../".$spanurl,"wb"),$Mark_Text);

	echo "&nbsp;<font style=font-size:10pt;>生成<font color=red>".$row['S_Name']."</font>第".$Arr[5]."成功:<a href=../../".$spanurl." target=_blank>".$spanurl."</a></font><br/>";

	 

	}//end for 

	 unset($page_arr);

	 unset($Arr);

	$page=$page+1;

	if($page>$spanpage){	

		if($type=="all" or $type=="spanall"){

			if(($classnow+1)>(count($classresult)-1)){

				if($type=="spanall"){

					echo "&nbsp;<font style=font-size:10pt;><b>暂停".S_StopTime."秒后开始生成新闻分类页．．．</b></font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='admin_spanarticleshow.php?NewsClassIDs=0';}</script>";

					}

				else{	

				echo "&nbsp;<font style=font-size:10pt;><b>所有分类列表已生部生成完毕．．．</b></font>";

					}

				}

			else{	

			echo "<br/>&nbsp;<font style=font-size:10pt;><b>列表生成完毕,暂停".S_StopTime."秒后继续生成下个分类．．．</b></font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='?ClassID=".$ClassID."&type=".$type."&classnow=".($classnow+1)."';}</script>";

				}

			}

		}

	else{	

		echo "<br/>&nbsp;<font style=font-size:10pt;><b>暂停".S_StopTime."秒后继续生成．．．</b></font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='?ClassID=".$ClassID."&type=".$type."&classnow=".$classnow."&pages=".($page)."';}</script>";

		}

}else{

	die("出错了，".$row['S_Template']."模板文件不存在！");

}



function SPage($mysql,$pagesize,$pages,$ClassID,$pagenum=10){

	global $db;

	$pagesok=$pagesize;//每页显示记录数

    if (!isset($pages)||$pages==""||!is_numeric($pages)||$pages<=0){

    $pages=1;

	}

  	$sqlstr=$mysql;

  	$res=$db -> query($sqlstr);

 	$nums= $db -> num_rows($res);

	if($nums==0){$nums=1;}

    $pagejs=ceil($nums/$pagesok);//总页数

    if($pages>$pagejs){

     $pages=$pagejs;

    }

    $sql=$sqlstr." LIMIT ".$pagesok*($pages-1).",".$pagesok;

	$result = $db -> query($sql);

	$str="";

	$first=LinkClassUrl("s_class",$ClassID,2,1);

	if($pages==1){

		$pageup=LinkClassUrl("s_class",$ClassID,2,1);

		}

	else{

		$pageup=LinkClassUrl("s_class",$ClassID,2,($pages-1));

		}	

	if($pages==$pagejs){

		$pagenext=LinkClassUrl("s_class",$ClassID,2,$pages);

		}

	else{

		$pagenext=LinkClassUrl("s_class",$ClassID,2,($pages+1));

		}	

	

	$last=LinkClassUrl("s_class",$ClassID,2,$pagejs);

		$pagelist="<select onchange=javascript:window.location=this.options[this.selectedIndex].value;>\r\n<option value='0'>跳转</option>\r\n";

	for($k=1;$k<=$pagejs;$k++){

		$pagelist.="<option value='".LinkClassUrl("s_class",$ClassID,2,$k)."'>第".$k."页</option>\r\n";

		}

	$pagelist.="</select>";	

	if($pagejs<=$pagenum){

  		for($i=1;$i<=$pagejs;$i++){

   			$str.="<a href='".LinkClassUrl("s_class",$ClassID,2,$i)."'>".$i."</a>&nbsp;";

 	 	}

	}

	else{

 		if($pages>=$pagenum){

 			for($i=$pages-intval($pagenum/2);$i<=$pages+(intval($pagenum/2));$i++){

   				if($i<=$pagejs){

   					$str.="<a href='".LinkClassUrl("s_class",$ClassID,2,$i)."'>".$i."</a>&nbsp;";

    			}

  			}

  			if($i<=$pagejs){ 

    			$str.="....";

	    		$str.="<a href='".LinkClassUrl("s_class",$ClassID,2,$pagejs)." '>".$pagejs."</a>&nbsp;";

   			}

   		}

  		else{

  			for($i=1;$i<=$pagenum;$i++){

    			$str.="<a href='".LinkClassUrl("s_class",$ClassID,2,$i)." '>".$i."</a>&nbsp;";

 		} 

 				if($i<=$pagejs){ 

      				$str.="....";

	  				$str.="<a href='".LinkClassUrl("s_class",$ClassID,2,$pagejs)." '>".$pagejs."</a>&nbsp;";

    			}

 		 }

	}

	 $arr=array($str,$result,$sql,$nums,$pagelist,$pages,$pagejs,$first,$pageup,$pagenext,$last,$pagesok);

	  @mysql_free_result($res);

	 return $arr;

}

?>