<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../../lib/cs_conn.php");
include_once("../../lib/cs_common.php");
include "../loginstate.php";
include "caiji_fun.php";
set_time_limit(0);

	global $db;
	$op=CS_Request("op");
        $id=CS_Request("id");
	$ac=CS_Request("ac");
	$pages=CS_Request("pages");
        $sql="select * from ".Getdbname('caiji')." where CS_ID=$id";
        $row=$db->getrow($sql);
        if($row){
		$CS_Code=$row["CS_Code"];
		$CS_Cjurl=$row["CS_Cjurl"];
		$CS_CJKSID=$row["CS_CJKSID"];
		$CS_CJJSID=$row["CS_CJJSID"];
		$CS_Listks=dhc($row["CS_Listks"]);
		$CS_Listjs=dhc($row["CS_Listjs"]);
		$CS_Linkks=dhc($row["CS_Linkks"]);
		$CS_Linkjs=dhc($row["CS_Linkjs"]);
        }else{
               exit("<script>alert('没有找到该规则！');history.go(-1);</script>");
        }
	if(empty($pages)) $pages=$CS_CJKSID;
	if(empty($op)) $op='dance';
        if($op=='dance'){
             $title='歌曲';$cc="播放";
        }else{
             $title='文章';$cc="内容";
        }
?>
<!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 type="text/javascript" src="../res/js/ajax.js"></script>
<script language="javascript" src="../res/js/jquery.js"></script>
<script language="javascript"> 
function caijigo(url,id,num,i){
        $("#caiji_"+i).html('&nbsp;&nbsp;<img src="../../public/images/load.gif">正在采集本页第<font color=red>'+(i+1)+'</font>条<?php echo $title?>,请稍等...');
 	$.get("caiji_ajax.php?url="+url+"&op="+i+"&ac=<?php echo $op?>&id="+id,function(R){
                if(R=="Err_100"){
		   $("#caiji_"+i).html("抱歉，没有找到该规则！");
                } else if(R=="Err_000"){
		   $("#caiji_"+i).html("获取列表页出错,获取不到数据！");		
                } else if(R=="Err_101"){
		   $("#caiji_"+i).html("获取<?php echo $title.$cc?>页出错,获取不到数据！");	
                } else if(R=="Err_102"){
		   $("#caiji_"+i).html("获取绝对路径内容出错，请检查绝对路径代码！");	
                } else if(R=="Err_103"){
		   $("#caiji_"+i).html("没有获取到<?php echo $title?>名称和<?php echo $title?>内容！");	
                } else if(num==i){
                   <?php if($pages==$CS_CJJSID){ ?>
		   $("#caiji_"+i).html(R+"<br><br><font color=#0000ff>恭喜您，所有页面<?php echo $title?>全部采集完成!</font>");
                   <?php }else{ ?>
		   $("#caiji_"+i).html(R+"<br><br><font color=#ff6600><b>本页歌曲全部采集完毕,2秒后继续下一页！</b></font>");
		   setTimeout("window.location.href ='?ac=caiji&op=<?php echo $op?>&id=<?php echo $id?>&pages=<?php echo ($pages+1)?>';", 2000);
                   <?php } ?>
                } else {
		   $("#caiji_"+i).html(R);
                   $("#dnum").html(i+2);
                   caijigo(url,id,num,i+1);	
                }											  
	});
}
</script>
</head>
<body>
<div class="wrap">
<?php
if($ac=='caiji'){

	$Url=CS_ReplaceStr($CS_Cjurl,'{$ID}',$pages);
	$Content=geturlcontent($Url,$CS_Code);//读取列表文件
	if(empty($Content)) {
		 die("在获取<font color=red>$Url</font>时出错,原因获取不到内容!<br/>暂停三秒采集下一列表<script>setTimeout('ReadGo();',3000);function ReadGo(){window.location='?id=".$id."&pages=".($pages+1)."'}</script>");	
	}
	$Liststr = getContent($Content,$CS_Listks,$CS_Listjs);//截取列表开始--结束
        $dLinkArr=getArr($CS_Linkks,$CS_Linkjs,$Liststr);//获取到连接地址 返回数组
        if(empty($dLinkArr)) exit("获取".$title."连接地址时出错,请确认！");
	$LinkCount=count($dLinkArr);//连接总数

        echo "<div class=\"h_a\">&nbsp;&nbsp;正在采集第<font color=red>".$pages."</font>页列表,共<font color=red>".(($CS_CJJSID-$CS_CJKSID)+1)."</font>页,当前页共<font color=red>".$LinkCount."</font>条数据,已经采集<font id=\"dnum\" color=red>".($DanceCount)."</font>条</div><div class=\"table_full\">
	<table width=\"100%\" class=\"J_check_wrap\">
		<col width=\"100%\" />";


	for($j=0;$j<=$LinkCount-1;$j++){
 		echo "<tr><td id=\"caiji_".$j."\"></td></tr>";
	}
        echo "<script>caijigo('".$Url."','".$id."',".($LinkCount-1).",0);</script></table>";
        //最后采集时间
	$db->query("update ".Getdbname('caiji')." set CS_AddTime='".date('Y-m-d H:i:s')."' where CS_ID=".$id."");
}
?>