<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
require_once("../../include/config.inc.php");
include "../../include/label.php";
include "../admin_loginstate.php";
@set_time_limit(0);
?>
<!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!=0){die("<font color=red>当前网站为动态模式,不能生成!!</font>");}
$ClassID=SafeRequest("ClassID","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=1 Order by S_ID asc";
	$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 * from s_class where S_ID=".$ClassID."";
$row=$db->getrow($sql);

if(!IsNul($row['S_Template'])){
	$row['S_Template']="list.html";
	}
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:video(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms:video}/',$ListContent,$page_arr2);//判断是否有分页标识
	if(!empty($page_arr2) && !empty($page_arr2[2])){
		$sqlstr2=Mark_Sql("s_video",$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:video(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/chshdjcms:video}/',$ListContent,$page_arr);
	  if(!empty($page_arr) && !empty($page_arr[2])){
		  $sqlstr=Mark_Sql("s_video",$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);
	 	 $Mark_Text=ReplaceStr($Mark_Text,"[video:classname]",$row['S_Name']);
	 	 $Mark_Text=ReplaceStr($Mark_Text,"[video:classid]",$row['S_ID']);
	 	 $Mark_Text=ReplaceStr($Mark_Text,"[video:classlink]",LinkClassUrl("s_class",$row['S_ID'],1,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=datavideo($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);
          if($Arr[5]=="") $page=1; else  $page=$Arr[5];
	  $spanurl=LinkClassUrl("s_class",$ClassID,1,$page);
	  $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/>";
	@mysql_free_result($result);
	
	 }//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 "<font style=font-size:10pt;></b>&nbsp;暂停".S_StopTime."秒后开始生成音乐分类页．．．<b></font><script language='javascript'>setTimeout('ReadGo();',".(S_StopTime*1000).");function ReadGo(){location.href='admin_spanvideoshow.php?ClassIDs=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>";
		}
	}

	

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,1,1);
	if($pages==1){
		$pageup=LinkClassUrl("s_class",$ClassID,1,1);
		}
	else{
		$pageup=LinkClassUrl("s_class",$ClassID,1,($pages-1));
		}	
	if($pages==$pagejs){
		$pagenext=LinkClassUrl("s_class",$ClassID,1,$pages);
		}
	else{
		$pagenext=LinkClassUrl("s_class",$ClassID,1,($pages+1));
		}	
	
	$last=LinkClassUrl("s_class",$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_class",$ClassID,1,$k)."'>第".$k."页</option>\r\n";
		}
	$pagelist.="</select>";	
	if($pagejs<=$pagenum){
  		for($i=1;$i<=$pagejs;$i++){
                      if($i==$pages){
   			$str.="<a><font color=red>".$i."</font></a>";
                      }else{
   			$str.="<a href='".LinkClassUrl("s_class",$ClassID,1,$i)."'>".$i."</a>";
                      }
 	 	}
	}
	else{
 		if($pages>=$pagenum){
 			for($i=$pages-intval($pagenum/2);$i<=$pages+(intval($pagenum/2));$i++){
   				if($i<=$pagejs){
                                      if($i==$pages){
   			                   $str.="<a><font color=red>".$i."</font></a>";
                                      }else{
   			                   $str.="<a href='".LinkClassUrl("s_class",$ClassID,1,$i)."'>".$i."</a>";
                                      }
    			        } 
  			}
  			if($i<=$pagejs){ 
                                 if($i==$pages){
   			              $str.="<a><font color=red>".$pagejs."</font></a>";
                                 }else{
   			              $str.="<a href='".LinkClassUrl("s_class",$ClassID,1,$pagejs)." '>".$pagejs."</a>";
                                 }
   			}
   		}
  		else{
  			for($i=1;$i<=$pagenum;$i++){
                                      if($i==$pages){
   			                   $str.="<a><font color=red>".$i."</font></a>";
                                      }else{
   			                   $str.="<a href='".LinkClassUrl("s_class",$ClassID,1,$i)."'>".$i."</a>";
                                      }
 		} 
 				if($i<=$pagejs){ 
                                 if($i==$pages){
   			              $str.="<a><font color=red>".$pagejs."</font></a>";
                                 }else{
   			              $str.="<a href='".LinkClassUrl("s_class",$ClassID,1,$pagejs)." '>".$pagejs."</a>";
                                 }
    			}
 		 }
	}
	 $arr=array($str,$result,$sql,$nums,$pagelist,$pages,$pagejs,$first,$pageup,$pagenext,$last,$pagesok);
	 @mysql_free_result($res);
	 return $arr;
}
?>