<?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";

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

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

$Tid=RequestBox("S_ID");

if($Tid==0) $Tid=SafeRequest("S_ID","get");

$Arr=explode(',',$Tid);

$Fhurl="";

if($type=="show"){

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

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

	if($page==""){$page=1;}

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

     if($Tid==""){

	$sql="select S_ID,S_SystemID from s_topic";

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

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

	$SystemID=$classresult[$classnow]['S_SystemID'];

	$classresult=(count($classresult)-1);

     }else{

        $Fhurl="<script language='javascript'>setTimeout('ReadGo();',2000);function ReadGo(){location.href='../admin_videotopic.php';}</script>";

	$topic=$db->getrow("select * from s_topic where S_ID=".$Arr[$classnow]."");

	$classresult=(count($Arr)-1);

	$ID=$Arr[$classnow];

	$SystemID=$topic['S_SystemID'];

     }

	$Table="video";

	if($SystemID=='1'){

		if(!file_exists(_CHSHDJ_ROOT_.S_Templateurl."vodtopic.html")) die(_CHSHDJ_ROOT_.S_Templateurl."vodtopic.html模板文件不存在");

		$ListContent=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."vodtopic.html");

		$Table="video";

		}

	elseif($SystemID=='2'){

		if(!file_exists(_CHSHDJ_ROOT_.S_Templateurl."arttopic.html")) die(_CHSHDJ_ROOT_.S_Templateurl."arttopic.html模板文件不存在");

		$ListContent=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."arttopic.html");

		$Table="article";

		}	

	

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

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

		$sqlstr2=Mark_Sql("s_".$Table,$page_arr2[1][0],$ID);

		$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;

		}	

	$sqlstr2="select * from s_topic where S_ID=".$ID."";

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

//循环开始



if(isset($page_arr2[2][0])!=""){

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:".$Table."(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms:".$Table."}/",$ListContent,$page_arr);

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

		$sqlstr=Mark_Sql("s_".$Table,$page_arr[1][0],$ID);

		}

	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);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:id]",$row['S_ID']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:name]",$row['S_Name']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:content]",$row['S_Content']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:hits]","<script src=".S_SitePath."js/hits.php?id=".$row['S_ID']."&type=6></script>");

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:time]",$row['S_AddTime']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:stars]",$row['S_Reco']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:username]",$row['S_Keywords']);

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:unichen]",getuser('nichen',$row['S_Keywords']));

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:ulink]",linkweburl(1,$row['S_Keywords']));

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:pic]",picshow($row['S_Pic'],'3'));

		$Mark_Text=ReplaceStr($Mark_Text,"[topic:link]",LinkClassUrl("s_topic",$row['S_ID'],$row['S_SystemID'],1));

		$Mark_Text.="<script src=".S_SitePath."js/hits.php?id=".$ids."&type=12></script>";//增加人气			

		$data_content="";

//判断是否有分页标识

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

			$Arr=SPage($sqlstr,$page_arr[2][0],$l,$ID,$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)){

						switch($Table){

							case 'video':$datatmp=datavideo($page_arr[0][0],$page_arr[3][0],$row2,$sorti);break;

							case 'article':$datatmp=dataart($page_arr[0][0],$page_arr[3][0],$row2,$sorti);break;

							default:$datatmp=datavideo($page_arr[0][0],$page_arr[3][0],$row2,$sorti);break;

							}

						$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,$ID);

          if($Arr[5]=="") $page=1; else  $page=$Arr[5];

	  $spanurl=LinkClassUrl("s_topic",$ID,$SystemID,$page);

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

	  spandir($spanurl);	

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

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

	}

	unset($page_arr);

	unset($Arr);

	$page=$page+1;

	if($page>$spanpage){

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

			echo "".$Fhurl."<br/><font style=font-size:10pt;>&nbsp;<b>恭喜你，专题全部生成完毕了．．．</b><font style=font-size:10pt;>";

			}

		else{

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

			}	

		}

	else{	

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

		}

	}



}else{	

	if(!file_exists(_CHSHDJ_ROOT_.S_Templateurl."topic.html")) die(_CHSHDJ_ROOT_.S_Templateurl."topic.html模板文件不存在");

	$ListContent=@file_get_contents(_CHSHDJ_ROOT_.S_Templateurl."topic.html");

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

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

		$sqlstr2=Mark_Sql("s_topic",$page_arr2[1][0],$ID);

		$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;

		}

		

	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;正在开始生成专题列表</div>");



for($l=0;$l<$Arr2[6];$l++){

	$data_content="";

	$Mark_Text=$ListContent;

	$Mark_Text=topandbottom($Mark_Text);

	$pagenum=getpagenum($Mark_Text);

	preg_match_all('/{chshdjcms:topic(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms:topic}/',$Mark_Text,$page_arr);

	//判断是否有分页标识

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

			$sqlstr=Mark_Sql("s_topic",$page_arr[1][0],$ID);

			$Arr=SPage($sqlstr,$page_arr[2][0],$l,$ID,$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=datatopic($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);

		}

	  

	  $Mark_Text=	Common_Mark($Mark_Text,0);

          if($Arr[5]=="") $page=1; else  $page=$Arr[5];

	  $spanurl=LinkClassUrl("s_topic",0,1,$page);

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

	  spandir($spanurl);

	  if($Arr[5]==1){

		  fwrite(fopen("../../".S_Stlistfolder."/index.html","wb"),$Mark_Text);		  

		  }

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

	

	echo "<font style=font-size:10pt;>&nbsp;<font color=red>专题列表&nbsp;第".$page."页&nbsp;成功：</font><a href=../../".$spanurl." target=_blank>".$spanurl."</a></font><br/>";

}

	unset($page_arr);

	unset($Arr);

	

	echo "<br/><font style=font-size:10pt;>&nbsp;<b>暂停".S_StopTime."秒后开始生成专题内容页．．．</b></font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='admin_spantopic.php?type=show';}</script>";

}



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_topic",$ClassID,1,1);

	if($pages==1){

		$pageup=LinkClassUrl("s_topic",$ClassID,1,1);

		}

	else{

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

		}	

	if($pages==$pagejs){

		$pagenext=LinkClassUrl("s_topic",$ClassID,1,$pages);

		}

	else{

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

		}	

	

	$last=LinkClassUrl("s_topic",$ClassID,1,$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_topic",$ClassID,1,$k)."'>第".$k."页</option>\r\n";

		}

	$pagelist.="</select>";	

	if($pagejs<=$pagenum){

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

   			$str.="<a href='".LinkClassUrl("s_topic",$ClassID,1,$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_topic",$ClassID,1,$i)."'>".$i."</a>&nbsp;";

    			}

  			}

  			if($i<=$pagejs){ 

    			$str.="....";

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

   			}

   		}

  		else{

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

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

 		} 

 				if($i<=$pagejs){ 

      				$str.="....";

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

    			}

 		 }

	}

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

	  @mysql_free_result($res);

	 return $arr;

}

?>