<?php
# Name: PHP版程氏专集CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_label.php");
include_once("../loginstate.php");
SystemPer('8_4');
if(CS_Webmode!=3)  exit(Msg_Error('网站运行模式为动态，不能生成!','javascript:history.go(-1);'));
        global $db;
        $ac=CS_Request("ac");
        $op=CS_Request("op");
        $id=CS_Request("id");
        $xid=CS_Request("xid");
        $cid=CS_Request("cid");
        $tid=CS_Request("tid");
        $sid=CS_Request("sid");
        $fid=CS_Request("fid");
        $type=CS_Request("type");
        $name=CS_Request("name");
        $pages=CS_Request("pages");
        if(empty($pages)) $pages=1;
        if(empty($sid)) $sid=1;
        if(empty($xid)) $xid=0;
        if(empty($fid)) $fid=0;
        if(empty($op)) $op='id';
           if($op=="hits"){
                $title="总人气";
           }elseif($op=="yue"){
                $title="每月人气";
           }elseif($op=="zhou"){
                $title="每周人气";
           }elseif($op=="ri"){
                $title="每日人气";
           }elseif($op=="reco"){
                $title="推荐星际";
           }elseif($op=="new"){
                $title="最新更新";
           }elseif($op=="id"){
                $title="ID";
           }
if($ac=='ids'){  //生成分类单ID
           $Htmllink="../..".LinkUrl('show','zj',$op,$sid,$id,$pages);
              if(CS_Mark!=0){
                 $Htmllink.="index.".CS_Suffix;
              }
           $Mark_Text=SpanTopicShow($id,$op,$pages);
	   if(write_file($Htmllink, $Mark_Text)){  //生成
                exit("&nbsp;<font style=font-size:10pt;>&nbsp;专集<font color=#ff6600>《".$name."》</font>内容&nbsp;<font color=red>按".$title."排序</font>&nbsp;第<font color=#0000ff>".$pages."</font></font>页&nbsp;--生成成功：<a href=".$Htmllink." target=_blank>".$Htmllink."</a></font>");
           }else{
                exit("&nbsp;<font style=font-size:10pt;>&nbsp;<font color=#0000ff>专集《".$name."》内容&nbsp;第".$pages."页&nbsp;按".$title."排序--生成失败!</font></font>");
           }  
}elseif($ac=='xuan'){  

     $Arr=explode(',',$id);
     for($k=0;$k<count($Arr);$k++){
           $id=$Arr[$k];
           $row=$db->getRow("select * from ".Getdbname('topic')." where CS_ID=".$id."");
           $Templateurl=$row['CS_Template'];
        if(empty($Templateurl)){
            if($sid==2){
	      $Templateurl="topic-news-show.html";
            }else{
	      $Templateurl="topic-dance-show.html";
            }
        }
	if(!file_exists(_CSDJ_ROOT_.CS_Templateurl.$Templateurl)){
              echo "<tr><td>".$Templateurl."模板文件不存在</td></tr>";
        }else{
              $Mark_Text=@file_get_contents(_CSDJ_ROOT_.CS_Templateurl.$Templateurl);
            if($sid==1){
                 preg_match_all('/{csdjcms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/csdjcms:dance}/',$Mark_Text,$page_arr);//判断是否有分页标识
            }else{
                 preg_match_all('/{csdjcms:news(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/csdjcms:news}/',$Mark_Text,$page_arr);//判断是否有分页标识
            }
              if(!empty($page_arr) && !empty($page_arr[2])){
                   $cscms_nums= $db -> num_rows($db -> query("select * from ".Getdbname('dance')." where cs_tid=".$id.""));//获取总数
                   $pagejs = ceil($cscms_nums / $page_arr[2][0]); // 列表总页数
                   $htmlpage = ceil($pagejs / CS_Createpre); 
                   if($pagejs>CS_Createpre){
                          $pagejs = CS_Createpre;
                   }
              }else{
                  $htmlpage=1;
                  $pagejs=1;
              }
                  if($pagejs==0) $pagejs=1;
                         for($j=0;$j<$pagejs;$j++){
                              $pages=$j+1;
                              $Htmllink="../..".LinkUrl('show','zj',$op,$sid,$id,$pages);
                                 if(CS_Mark!=0){
                                    $Htmllink.="index.".CS_Suffix;
                                 }
                              $Mark_Text=SpanTopicShow($id,$op,$pages);
	                      if(write_file($Htmllink, $Mark_Text)){  //生成
                                   echo "&nbsp;<font style=font-size:10pt;>&nbsp;专集<font color=#ff6600>《".$row['CS_Name']."》</font>内容&nbsp;<font color=red>按".$title."排序</font>&nbsp;第<font color=#0000ff>".$pages."</font></font>页&nbsp;--生成成功：<a href=".$Htmllink." target=_blank>".$Htmllink."</a></font><br>";
                              }else{
                                   echo "&nbsp;<font style=font-size:10pt;>&nbsp;<font color=#0000ff>专集《".$row['CS_Name']."》内容&nbsp;第".$pages."页&nbsp;按".$title."排序--生成失败!</font></font><br>";
                              }  
                         }


              unset($page_arr);
        }

     }
     exit();
}
?>
<!doctype html>
<html>
<head>
<meta charset="gbk">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>chshdjcms management</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<script language="javascript" src="../res/js/jquery.js"></script>
<script language="javascript"> 
function Htmllist(cname,id,num,i){
        $("#cname").html(cname);
        $("#list_"+i).html('&nbsp;&nbsp;<img src="../../public/images/load.gif">正在生成第<font color=red>'+(i+1)+'</font>页歌曲专集内容,请稍等...');
 	$.get("html_topic.php?ac=ids&name="+cname+"&op=<?php echo $op?>&id="+id+"&pages="+(i+1),function(R){
                if(R=="no"){
		   $("#list_"+i).html("<font color=#red>第"+(i+1)+"页生成失败！</font>");		
                } else if(R=="Err_100"){
		   $("#list_"+i).html("专集内容页模版文件不存在！");	
                } else if(num==(i+1)){
		   $("#list_"+i).html(R+"<br><br><font color=#0000ff>恭喜您，第<?php echo $pages?>页 专集全部生成完成,暂停<font color=red><?php echo CS_StopTime?></font>秒正在继续下一页...</font>");
                   setTimeout("location.href='?ac=<?php echo $ac?>&op=<?php echo $op?>&fid=<?php echo $fid?>&xid=<?php echo $xid?>&cid=<?php echo $cid?>&pages=<?php echo ($pages+1)?>'",<?php echo CS_StopTime?>000);
                } else {
		   $("#list_"+i).html(R);
                   $("#dnum").html(i+2);
                   Htmllist(cname,id,num,i+1);	
                }											  
	});
}
</script>
</head>
<body>
<div class="wrap">
<?php if($ac=='list'){ ?>
<div class="h_a">&nbsp;&nbsp;正在生成专集列表&nbsp;第&nbsp;<font color=#0000ff><?php echo $pages?></font>&nbsp;页&nbsp;第&nbsp;<font id="dnum" color=red>0</font>&nbsp;张&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="html.php"><font color=#026E12>紧急返回</font></a></div>
<?php }else{ ?>
<div class="h_a">&nbsp;&nbsp;正在生成专集内容页&nbsp;〈按<?php echo $title?>&nbsp;排序〉&nbsp;第&nbsp;<font color=#0000ff><?php echo $pages?></font>&nbsp;页&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="html.php"><font color=#026E12>紧急返回</font></a></div>
<?php } ?>
<div class="table_full">
	<table width="100%" class="J_check_wrap">
		<col width="100%" />
<?php
if($ac=='list'){  //生成专集列表分类页
        if($sid==2){
	      $Templateurl="topic-news.html";
              $fid='news';
        }else{
	      $Templateurl="topic-dance.html";
              $fid='dance';
        }
        $sort=array("hits","id","yue","zhou","ri","reco","new");
        $ttitle=array("总人气","ID","月人气","周人气","日人气","推荐星际","更新时间");
	if(!file_exists(_CSDJ_ROOT_.CS_Templateurl.$Templateurl)){
              echo "<tr><td>".$Templateurl."模板文件不存在</td></tr>";
        }else{
              $Mark_Text=@file_get_contents(_CSDJ_ROOT_.CS_Templateurl.$Templateurl);
              preg_match_all('/{csdjcms:topic(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/csdjcms:topic}/',$Mark_Text,$page_arr);//判断是否有分页标识
              if(!empty($page_arr) && !empty($page_arr[2])){

                   $sql="SELECT COUNT(*) AS total FROM ".Getdbname('topic')." WHERE CS_YID=0 and CS_SID=".$sid;
                   $rows=$db->getRow($sql);
                   $nums = $rows['total']; //获取总数
                   $pagejs = ceil($nums / $page_arr[2][0]); // 总页数
                   if($pagejs<$pages){
 	                   echo "<tr><td>&nbsp;&nbsp;<b><font color=red>恭喜您，全部专集页面生成完毕!</font><b><script>if (confirm(\"是否生成专集内容页面?\")){window.location='?sid=1';}else{window.location='html.php';}</script></td></tr>";
                   }else{
                       for($j=0;$j<7;$j++){
                            $Htmllink="../..".LinkUrl('list','zj',$sort[$j],1,1,$pages);
                            if(CS_Mark!=0){
                               $Htmllink.="index.".CS_Suffix;
                            }
                            $Mark_Text=SpanTopicList($pages,$sort[$j],$fid);
	                    if(write_file($Htmllink, $Mark_Text)){  //生成
                                  echo "<tr><td><font style=font-size:10pt;>&nbsp;专集列表&nbsp;第<font color=#0000ff>".$pages."</font></font>页&nbsp;<font color=red>按".$ttitle[$j]."排序</font>--生成成功：<a href=".$Htmllink." target=_blank>".$Htmllink."</a></font></td></tr>";
                            }else{
                                   echo "<tr><td><font style=font-size:10pt;>&nbsp;<font color=#0000ff>专集列表&nbsp;第".$pages."页&nbsp;按".$ttitle[$j]."排序--生成失败!</font></font></td></tr>";
                            }
                       }
                       echo "<tr><td><font color=#0000ff>恭喜您，专集列表第".$pages."页 全部生成完成,暂停<font color=red>".CS_StopTime."</font>秒正在继续下一页...</font></td></tr><script>setTimeout('updatenext();',".CS_StopTime."000);function updatenext(){location.href='?ac=list&sid=".$sid."&pages=".($pages+1)."';}</script>";
                   }
              }else{
                  echo "<tr><td>抱歉，专集列表标签错误，获取不到每页显示条数!</td></tr>";
              }
              unset($page_arr);
        }

}else{  //专集内容页
        $sort=array("id","hits","yue","zhou","ri","reco","new");
        $ttitle=array("ID","总人气","月人气","周人气","日人气","推荐星际","更新时间");
        $title=$ttitle[$fid];
        $op=$sort[$fid];
        if($op=='time') $type='all';
        if($sid==2){
	      $Templateurl="topic-news-show.html";
        }else{
	      $Templateurl="topic-dance-show.html";
        }
        if(empty($tid)){
            $str='all';
	    $sql="select CS_ID,CS_Name,CS_Template from ".Getdbname('topic')." where CS_SID=".$sid." Order by CS_ID asc";
	    $class=$db->getAll($sql);
            $tid=$class[$xid]['CS_ID'];
            $cname=$class[$xid]['CS_Name'];
            $Templateurl=$class[$xid]['CS_Template'];
        }else{
	    $sql="select * from ".Getdbname('topic')." where CS_ID=$tid";
	    $row=$db->getrow($sql);
            $cname=$row['CS_Name'];
            $Templateurl=$row['CS_Template'];
        }
        if(empty($Templateurl)){
            if($sid==2){
	      $Templateurl="topic-news-show.html";
            }else{
	      $Templateurl="topic-dance-show.html";
            }
        }
	if(!file_exists(_CSDJ_ROOT_.CS_Templateurl.$Templateurl)){
              echo "<tr><td>".$Templateurl."模板文件不存在</td></tr>";
        }else{
              $Mark_Text=@file_get_contents(_CSDJ_ROOT_.CS_Templateurl.$Templateurl);
            if($sid==1){
                 preg_match_all('/{csdjcms:dance(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/csdjcms:dance}/',$Mark_Text,$page_arr);//判断是否有分页标识
            }else{
                 preg_match_all('/{csdjcms:news(.*?pagesize=([\S]+).*?)}([\s\S]+?){\/csdjcms:news}/',$Mark_Text,$page_arr);//判断是否有分页标识
            }
              if(!empty($page_arr) && !empty($page_arr[2])){

                   $sql="SELECT COUNT(*) AS total FROM ".Getdbname('dance')." WHERE CS_YID=0 and CS_TID=".$tid."";
                   $rows=$db->getRow($sql);
                   $nums = $rows['total']; //获取总数
                   $pagejs = ceil($nums / $page_arr[2][0]); // 列表总页数
                   $htmlpage = ceil($pagejs / CS_Createpre); 

              }else{
                  $htmlpage=1;
                  $pagejs=1;
              }
                   if($htmlpage<$pages){
                       if($str=='all'){
                           if(($xid+1)>(count($class)-1)){
                                if($type=='all'){  //完成
                                     echo "<tr><td>&nbsp;<font style=font-size:10pt;><b>恭喜您！专集内容页全部生成完毕．．．</b></font></td></tr>";
                                }elseif($op!='new'){
                                      if($op=='id'){
 	                                      echo "<tr><td>&nbsp;<font style=font-size:10pt;><b>按<font color=#ff6600>".$title."排序</font>专集内容页全部生成完毕...</b></font><script>if (confirm(\"是否生成按其他排序内容页？\")){window.location='?fid=".($fid+1)."&op=".$sort[($fid+1)]."';}else{window.location='html.php';}</script></td></tr>";
                                      }else{
 	                                    echo "<tr><td>&nbsp;<font style=font-size:10pt;><b>按<font color=#ff6600>".$title."排序</font>专集内容页全部生成完毕,".CS_StopTime."秒后生成其他排序分类页面...</b></font><script language='javascript'>setTimeout('ReadGo();',".CS_StopTime."000);function ReadGo(){location.href='?fid=".($fid+1)."&op=".$sort[($fid+1)]."';}</script></td></tr>";
                                      }
                                }else{
 	                              echo "<tr><td>&nbsp;&nbsp;<b><font color=red>恭喜您，全部专集内容页面生成完毕!</font><b></td></tr>";
                                }
                           }else{
 	                           echo "<tr><td>&nbsp;<font style=font-size:10pt;><b><font color=red>《".$cname."》</font>内容生成完毕,暂停".CS_StopTime."秒后继续生成下个专集．．．</b></font><script language='javascript'>setTimeout('ReadGo();',".CS_StopTime."000);function ReadGo(){location.href='?xid=".($xid+1)."&fid=".$fid."&op=".$op."';}</script></td></tr>";
                           }
                       }else{
 	                   echo "<tr><td>&nbsp;&nbsp;<b><font color=red>恭喜您，全部专集内容页面生成完毕!</font><b></td></tr>";
                       }
                   }else{
                         for($j=0;$j<$pagejs;$j++){
                              echo "<tr><td id=\"list_".$j."\"></td></tr>";
                         }
                         echo "<script>Htmllist('".$cname."','".$tid."',".$pagejs.",0);</script>";
                   }
              unset($page_arr);
        }
}
?>
</table>
</div>
</div>
</body>
</html>