<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache");
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");
	$cjurl=CS_Request("url");

        $sql="select * from ".Getdbname('caiji')." where CS_ID=$id";
        $row=$db->getrow($sql);
        if($row){
		$CS_Url=$row["CS_Url"];
		$CS_Code=$row["CS_Code"];
		$CS_User=$row["CS_User"];
		$CS_SID=$row["CS_SID"];
		$CS_CID=$row["CS_CID"];
		$CS_PID=$row["CS_PID"];
		$CS_FID=$row["CS_FID"];
		$CS_PicMode=$row["CS_PicMode"];
		$CS_DanceMode=$row["CS_DanceMode"];
		$CS_Listks=dhc($row["CS_Listks"]);
		$CS_Listjs=dhc($row["CS_Listjs"]);
		$CS_Picks=dhc($row["CS_Picks"]);
		$CS_Picjs=dhc($row["CS_Picjs"]);
		$CS_Linkks=dhc($row["CS_Linkks"]);
		$CS_Linkjs=dhc($row["CS_Linkjs"]);
		$CS_Nameks=dhc($row["CS_Nameks"]);
		$CS_Namejs=dhc($row["CS_Namejs"]);
		$CS_Singerks=dhc($row["CS_Singerks"]);
		$CS_Singerjs=dhc($row["CS_Singerjs"]);
		$CS_Lrcks=dhc($row["CS_Lrcks"]);
		$CS_Lrcjs=dhc($row["CS_Lrcjs"]);
		$CS_Playks=dhc($row["CS_Playks"]);
		$CS_Playjs=dhc($row["CS_Playjs"]);
		$CS_Danceks=dhc($row["CS_Danceks"]);
		$CS_Dancejs=dhc($row["CS_Dancejs"]);
		$CS_DanceTh=dhc($row["CS_DanceTh"]);
		$CS_LrcTh=dhc($row["CS_LrcTh"]);
        }else{
               exit("Err_100");  //没有找到该规则
        }

	$Content=geturlcontent($cjurl,$CS_Code);//读取列表文件
	if(empty($Content)) {
		 exit("Err_000");
	}
	$Liststr = getContent($Content,$CS_Listks,$CS_Listjs);//截取列表开始--结束
        $dLinkArr=getArr($CS_Linkks,$CS_Linkjs,$Liststr);//获取到连接地址 返回数组

        $CS_Pic='';
        if($CS_PicMode==1){  //采集图片
           $PicArr=getArr($CS_Picks,$CS_Picjs,$Liststr);//获取到图片地址 返回数组
           $CS_Pic=$PicArr[$op];
        }
        if(substr($dLinkArr[$op],0,7)!='http://') $dLinkArr[$op]=$CS_Url.$dLinkArr[$op];
	$DanceContent=geturlcontent($dLinkArr[$op],$CS_Code);//读取文件
	if(empty($DanceContent)) {
               exit("Err_101");
	}

	$CS_Name = getContent($DanceContent,$CS_Nameks,$CS_Namejs);  //名称
        if($ac=='dance'){  //歌曲
	      $CS_Singer = getContent($DanceContent,$CS_Singerks,$CS_Singerjs);  //歌手
	      $CS_Lrc = getContent($DanceContent,$CS_Lrcks,$CS_Lrcjs);  //歌词、介绍

              if(CS_Request("CS_DanceMode")==1){  //绝对路径采集
	            $Playurl = getContent($DanceContent,$CS_Playks,$CS_Playjs);
	            $pContent=geturlcontent($Playurl,$CS_Code);//读取绝对路径文件
                    if(empty($pContent)) exit("Err_102");
	            $CS_Dance = getContent($pContent,$CS_Danceks,$CS_Dancejs);
              }else{
	            $CS_Dance = getContent($DanceContent,$CS_Danceks,$CS_Dancejs);  //地址
              }
            if(empty($CS_Name)||empty($CS_Dance)){
                exit("Err_103");
            }
        }else{  //文章
            $CS_News = getContent($DanceContent,$CS_Danceks,$CS_Dancejs);  //文章内容
            if(empty($CS_Name)||empty($CS_News)){
                exit("Err_103");
            }
        }
        $CS_Dance=collectRep($CS_Dance,$CS_DanceTh);
        $CS_News=collectRep($CS_News,$CS_DanceTh);
        $CS_Lrc=collectRep($CS_Lrc,$CS_LrcTh);
        $CS_Pic1=$CS_Pic;
        $CS_Singer1=$CS_Singer;
        $CS_News1=$CS_News;
        $CS_Lrc1=$CS_Lrc;
        if(empty($CS_Singer)) $CS_Singer='没有采集到歌手';
        if(empty($CS_Pic)) $CS_Pic='没有采集到图片';
        if(empty($CS_Lrc)) $CS_Lrc='没有采集到歌词或者介绍';
        if(empty($CS_News)) $CS_News='没有采集到内容';

        if($ac=='dance'){  //歌曲
	       //判断数据是否相同
	       $CS_ID= $db->Getone("select CS_ID from ".Getdbname('dance')." where CS_Name='".$CS_Name."' and CS_PlayUrl='".$CS_Dance."'");
	       if($CS_ID){
	            $title="<font color=#0000ff>已经存在，未入库!</font>";
	       }else{
                   $sql="Insert ".Getdbname('dance')."  (CS_YID,CS_PlayUrl,CS_DownUrl1,CS_Name,CS_Pic,CS_CID,CS_Singer,CS_User,CS_PID,CS_FID,CS_Content,CS_AddTime) values (1,'".$CS_Dance."','".$CS_Dance."','".$CS_Name."','".$CS_Pic1."',".$CS_CID.",'".$CS_Singer1."','".$CS_User."',".$CS_PID.",".$CS_FID.",'".$CS_Lrc1."','".date('Y-m-d H:i:s')."')";
                   if($db->query($sql)){
                       $title="<font color=green>保存成功</font>";
                   }else{
                       $title="<font color=reg>保存失败</font>";
                   }
               }
               echo "".($op+1).".&nbsp;名称：<font color=red>".$CS_Name."</font>&nbsp;&nbsp;歌手：<font color=red>".$CS_Singer."</font>&nbsp;&nbsp;地址：<font color=red>".$CS_Dance."</font>&nbsp;&nbsp;----".$title;
        }else{
	       //判断数据是否相同
	       $CS_ID= $db->Getone("select CS_ID from ".Getdbname('news')." where CS_Name='".$CS_Name."'");
	       if($CS_ID){
	            $title="<font color=#0000ff>已经存在，未入库!</font>";
	       }else{
                   $sql="Insert ".Getdbname('news')."  (CS_YID,CS_Laiyuan,CS_Name,CS_Pic,CS_CID,CS_User,CS_Content,CS_AddTime) values (1,'".CS_WebName."','".$CS_Name."','".$CS_Pic1."',".$CS_CID.",'".$CS_User."','".$CS_News1."','".date('Y-m-d H:i:s')."')";
                   if($db->query($sql)){
                       $title="<font color=green>保存成功</font>";
                   }else{
                       $title="<font color=reg>保存失败</font>";
                   }
               }
               echo "".($op+1).".&nbsp;名称：<font color=red>".$CS_Name."</font>&nbsp;&nbsp;来源：<font color=red>".CS_WebPath."</font>----".$title;
        }
?>



