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

        if($op=='del'){  //删除
                $sql="delete from ".Getdbname('caiji')." where CS_ID=".$id;
		if($db->query($sql)){
                     exit("<script>window.location='?';</script>");
                }else{
                     exit("<script>alert('删除失败！');history.go(-1);</script>");
                }
        }

        if($ac=='daochudata'){ //导出采集规则文本
	 $guize=trim($_POST['guize']);
	 $guize=CS_ReplaceStr($guize,"\\","");
	 $sname="../../annex/rule/".$_POST['sname'].".txt";
	 fwrite(fopen($sname,"wb"),$guize);
              if (file_exists($sname)){

	           $file = fopen($sname,"r"); // 打开文件
	           Header("Content-type: application/octet-stream");
	           Header("Accept-Ranges: bytes");
	           Header("Accept-Length: ".filesize($sname));
	           Header("Content-Disposition: attachment; filename=" . $_POST['sname'].".txt");
	           echo fread($file,filesize($sname));
	           fclose($file);
	           exit();
              }
        }

        if($ac=='daorudata'){ //导入采集规则
                $text=trim($_POST['guize']);
		$CS_Name=getContent($text,"<cscms_name>","</cscms_name>",5);
		$CS_Url=getContent($text,"<cscms_url>","</cscms_url>",5);
		$CS_Code=getContent($text,"<cscms_code>","</cscms_code>",5);
		$CS_User=getContent($text,"<cscms_user>","</cscms_user>",5);
		$CS_SID=getContent($text,"<cscms_sid>","</cscms_sid>",5);
		$CS_CID=getContent($text,"<cscms_cid>","</cscms_cid>",5);
		$CS_PID=getContent($text,"<cscms_pid>","</cscms_pid>",5);
		$CS_FID=getContent($text,"<cscms_fid>","</cscms_fid>",5);
		$CS_PicMode=getContent($text,"<cscms_picmode>","</cscms_picmode>",5);
		$CS_DanceMode=getContent($text,"<cscms_dancemode>","</cscms_dancemode>",5);
		$CS_Cjurl=getContent($text,"<cscms_cjurl>","</cscms_cjurl>",5);
		$CS_CJKSID=getContent($text,"<cscms_cjksid>","</cscms_cjksid>",5);
		$CS_CJJSID=getContent($text,"<cscms_cjjsid>","</cscms_cjjsid>",5);
		$CS_Listks=getContent($text,"<cscms_listks>","</cscms_listks>",5);
		$CS_Listjs=getContent($text,"<cscms_listjs>","</cscms_listjs>",5);
		$CS_Picks=getContent($text,"<cscms_picks>","</cscms_picks>",5);
		$CS_Picjs=getContent($text,"<cscms_picjs>","</cscms_picjs>",5);
		$CS_Linkks=getContent($text,"<cscms_linkks>","</cscms_linkks>",5);
		$CS_Linkjs=getContent($text,"<cscms_linkjs>","</cscms_linkjs>",5);
		$CS_Nameks=getContent($text,"<cscms_nameks>","</cscms_nameks>",5);
		$CS_Namejs=getContent($text,"<cscms_namejs>","</cscms_namejs>",5);
		$CS_Singerks=getContent($text,"<cscms_singerks>","</cscms_singerks>",5);
		$CS_Singerjs=getContent($text,"<cscms_singerjs>","</cscms_singerjs>",5);
		$CS_Lrcks=getContent($text,"<cscms_lrcks>","</cscms_lrcks>",5);
		$CS_Lrcjs=getContent($text,"<cscms_lrcjs>","</cscms_lrcjs>",5);
		$CS_Playks=getContent($text,"<cscms_playks>","</cscms_playks>",5);
		$CS_Playjs=getContent($text,"<cscms_playjs>","</cscms_playjs>",5);
		$CS_Danceks=getContent($text,"<cscms_danceks>","</cscms_danceks>",5);
		$CS_Dancejs=getContent($text,"<cscms_dancejs>","</cscms_dancejs>",5);
		$CS_DanceTh=getContent($text,"<cscms_danceth>","</cscms_danceth>",5);
		$CS_LrcTh=getContent($text,"<cscms_lrcth>","</cscms_lrcth>",5);

                $sql="Insert ".Getdbname('caiji')."  (CS_Name,CS_Url,CS_Code,CS_User,CS_SID,CS_CID,CS_PID,CS_FID,CS_PicMode,CS_DanceMode,CS_Cjurl,CS_CJKSID,CS_CJJSID,CS_Listks,CS_Listjs,CS_Picks,CS_Picjs,CS_Linkks,CS_Linkjs,CS_Nameks,CS_Namejs,CS_Singerks,CS_Singerjs,CS_Lrcks,CS_Lrcjs,CS_Playks,CS_Playjs,CS_Danceks,CS_Dancejs,CS_LrcTh,CS_DanceTh,CS_AddTime) values ('".$CS_Name."','".$CS_Url."','".$CS_Code."','".$CS_User."',1,".$CS_CID.",".$CS_PID.",".$CS_FID.",".$CS_PicMode.",".$CS_DanceMode.",'".$CS_Cjurl."',".$CS_CJKSID.",".$CS_CJJSID.",'".$CS_Listks."','".$CS_Listjs."','".$CS_Picks."','".$CS_Picjs."','".$CS_Linkks."','".$CS_Linkjs."','".$CS_Nameks."','".$CS_Namejs."','".$CS_Singerks."','".$CS_Singerjs."','".$CS_Lrcks."','".$CS_Lrcjs."','".$CS_Playks."','".$CS_Playjs."','".$CS_Danceks."','".$CS_Dancejs."','".$CS_LrcTh."','".$CS_DanceTh."','".date('Y-m-d H:i:s')."')";
		if($db->query($sql)){
	 		  exit("<script>alert('规则数据导入成功！');window.location='?'</script>");
	 	}else{
	 		  exit("<script>alert('规则数据导入失败！');history.go(-1);</script>");
	 	}
       }
?>
<!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 del(_id){ 
  if (confirm("确定删除吗？")){
    window.location='?op=del&id='+_id;
    return true;
  }else{
     return false;
  }		
}
</script>
</head>
<body>
<div class="wrap">
<div class="nav">
	<ul class="cc">
		<li <?php if($ac=='') echo 'class="current"';?>><a href="dance_list.php">规则列表</a></li>
		<li <?php if($ac=='edit') echo 'class="current"';?>><a href="dance_list.php?ac=edit"><?php if($ac=='edit'){ echo '编辑';}else{ echo '添加';}?>规则</a></li>
		<li <?php if($ac=='daoru') echo 'class="current"';?>><a href="dance_list.php?ac=daoru">导入规则</a></li>
             <?php if($ac=='daochu') echo '<li class="current"><a href="###">导出规则</a></li>';?>
	</ul>
</div>
<?php  
if($ac=="edit"){ 
        if(empty($op)) $op=0;
   	$CS_ID=CS_Request("id");
        if($CS_ID){
	   $row=$db->getrow("SELECT * FROM ".Getdbname('caiji')." Where CS_ID='".$CS_ID."'");
	   if($row){
		$Arr=array($row['CS_Name'],$row['CS_Code'],$row['CS_Url'],$row['CS_PicMode'],$row['CS_PID'],$row['CS_FID'],$row['CS_Cjurl'],$row['CS_CJKSID'],$row['CS_CJJSID'],$row['CS_Listks'],$row['CS_Listjs'],$row['CS_Linkks'],$row['CS_Linkjs'],$row['CS_Picks'],$row['CS_Picjs'],$row['CS_CID'],$row['CS_User'],$row['CS_Nameks'],$row['CS_Namejs'],$row['CS_Singerks'],$row['CS_Singerjs'],$row['CS_Lrcks'],$row['CS_Lrcjs'],$row['CS_DanceMode'],$row['CS_Playks'],$row['CS_Playjs'],$row['CS_Danceks'],$row['CS_Dancejs'],$row['CS_DanceTh'],$row['CS_LrcTh']);
                $title="编辑规则";
	   }
        }else{
		$Arr=array('','','','0','0','0','','1','5','','','','','','','','','','','','','','','','','','','','','');
                $title="填加规则";
        }
//print_r($Arr); 

?>
<form class="J_ajaxForm" data-role="edit" action="?ac=edit&op=<?php echo ($op+1)?>" method="post">
<input name="id" type="hidden" value="<?php echo $CS_ID?>" />
<div class="h_a"><?php echo $title?></div>
<div class="table_full">
	<table width="100%" class="J_check_wrap">
		<col class="th" />
		<col width="400" />
		<col />
<?php    if($op==0){ ?>
<script language="javascript">
$(document).ready(function(){
	$("#caijiadd").click(function(){
		var CS_Name=$("#CS_Name").val();
		var CS_Url=$("#CS_Url").val();
		var CS_Cjurl=$("#CS_Cjurl").val();
		var CS_CJKSID=$("#CS_CJKSID").val();
		var CS_CJJSID=$("#CS_CJJSID").val();
		var CS_Listks=$("#CS_Listks").val();
		var CS_Listjs=$("#CS_Listjs").val();
		var CS_PicMode=$("#CS_PicMode").val();
		var CS_Linkks=$("#CS_Linkks").val();
		var CS_Linkjs=$("#CS_Linkjs").val();
		var CS_Picks=$("#CS_Picks").val();
		var CS_Picjs=$("#CS_Picjs").val();

	$("#CS_Name").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Url").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Cjurl").css("border-color","#666 #ccc #ccc #666");
	$("#CS_CJKSID").css("border-color","#666 #ccc #ccc #666");
	$("#CS_CJJSID").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Listks").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Listjs").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Linkks").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Linkjs").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Picks").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Picjs").css("border-color","#666 #ccc #ccc #666");
	if(CS_Name==""){
		$("#CS_Name").css("border","1px solid red");
		$("#Msg").text("请填写采集规则名称！").css("color","red");
		return false;
		}
	else if(CS_Url==""){
		$("#CS_Url").css("border","1px solid red");
		$("#Msg").text("请填写采集站点地址！").css("color","red");
		return false;
		}
	else if(CS_Cjurl==""){
		$("#CS_Cjurl").css("border","1px solid red");
		$("#Msg").text("请填写采集分类地址！").css("color","red");
		return false;
		}
	else if(CS_CJKSID==""){
		$("#CS_CJKSID").css("border","1px solid red");
		$("#Msg").text("请填写开始页数号！").css("color","red");
		return false;
		}
	else if(CS_CJJSID==""){
		$("#CS_CJJSID").css("border","1px solid red");
		$("#Msg").text("请填写结束页数号！").css("color","red");
		return false;
		}
	else if(CS_Listks==""){
		$("#CS_Listks").css("border","1px solid red");
		$("#Msg").text("请填写列表开始代码！").css("color","red");
		return false;
		}
	else if(CS_Listjs==""){
		$("#CS_Listjs").css("border","1px solid red");
		$("#Msg").text("请填写列表结束代码！").css("color","red");
		return false;
		}
	else if(CS_Listks==""){
		$("#CS_Listks").css("border","1px solid red");
		$("#Msg").text("请填写列表开始代码！").css("color","red");
		return false;
		}
	else if(CS_Linkks==""){
		$("#CS_Linkks").css("border","1px solid red");
		$("#Msg").text("请填写歌曲链接开始代码！").css("color","red");
		return false;
		}
	else if(CS_Linkjs==""){
		$("#CS_Linkjs").css("border","1px solid red");
		$("#Msg").text("请填写歌曲链接结束代码！").css("color","red");
		return false;
		}
	else if(CS_PicMode=="ok"){
                     if(CS_Picks==""){
		        $("#CS_Picks").css("border","1px solid red");
		        $("#Msg").text("请填写歌曲图片开始代码！").css("color","red");
		        return false;
                     }
                     if(CS_Picjs==""){
		        $("#CS_Picjs").css("border","1px solid red");
		        $("#Msg").text("请填写歌曲图片结束代码！").css("color","red");
		        return false;
                     }
	        }
        else {
                  document.getElementById("Msg").className="tips_success";
                  document.getElementById('Msg').innerHTML='<img src="../../public/images/load.gif">正在提交,请稍等...';
             }
	});
});
</script>
		<tr>
			<th>规则名称</th>
			<td>
				<input id="CS_Name" name="CS_Name" value="<?php echo $Arr[0]?>" type="text" class="input input_hd length_5">&nbsp;
			</td>
			<td><div class="fun_tips">填写采集规则名称</div></td>
		</tr>
		<tr>
			<th>采集站点地址</th>
			<td>
				<input id="CS_Url" name="CS_Url" value="<?php echo $Arr[2]?>" type="text" class="input input_hd length_5">&nbsp;
			</td>
			<td><div class="fun_tips">采集站点地址，如：http://dj.chshcms.com</div></td>
		</tr>
		<tr>
			<th>站点网页编码</th>
			<td>
			<select class="select_2" name="CS_Code" >
 			     <option value="GB2312" <?php if($Arr[1]=='GB2312') echo "selected='selected'";?>>GB2312</option>
  			     <option value="UTF-8" <?php if($Arr[1]=='UTF-8') echo "selected='selected'";?>>UTF-8</option>								
			</select>&nbsp;&nbsp;&nbsp;&nbsp;<label>采集图片&nbsp;<input name="CS_PicMode" type="checkbox" value="ok" <?php if($Arr[3]=='1'){ echo 'checked';}else{ echo " onClick=\"javascript:document.getElementById('picgo').style.display='';\"";}?>></label>
			</td>
			<td><div class="fun_tips">采集站点网页编码</div></td>
		</tr>
		<tr>
			<th>播放器</th>
			<td>
			<select class="select_2" name="CS_PID" >
                                                <option value="0" <?php if($Arr[4]==0) echo "selected='selected'";?>>wma播放器</option>
                                                <option value="7" <?php if($Arr[4]==7) echo "selected='selected'";?>>mp3,mp4播放器</option>
                                                <option value="1" <?php if($Arr[4]==1) echo "selected='selected'";?>>cmp播放器</option>
                                                <option value="2" <?php if($Arr[4]==2) echo "selected='selected'";?>>flv播放器</option>
                                                <option value="3" <?php if($Arr[4]==3) echo "selected='selected'";?>>优库播放</option>
                                                <option value="4" <?php if($Arr[4]==4) echo "selected='selected'";?>>土豆播放</option>
                                                <option value="5" <?php if($Arr[4]==5) echo "selected='selected'";?>>SWF播放</option>
                                                <option value="6" <?php if($Arr[4]==6) echo "selected='selected'";?>>音乐台播放</option>							
			</select>&nbsp;&nbsp;服务器组：
				         <select class="select_2" name="CS_FID">
                                                <option value="0">选择服务器</option>
            					 <?php
              						$sqlf="select * from ".Getdbname('fwqip')." ";
									$results=$db->query($sqlf);
									if($results){
										while ($row2=$db->fetch_array($results)){
                                                                                    if($row2['CS_ID']==$Arr[5]){
										         echo "<option value='".$row2['CS_ID']."' selected='selected'>".$row2['CS_Name']."</option>";
                                                                                    }else{
										         echo "<option value='".$row2['CS_ID']."' >".$row2['CS_Name']."</option>";
                                                                                    }
										}
									}
			  
			  			 ?>             
                                         </select>
			</td>
			<td><div class="fun_tips">选择音乐播放器、服务器组</div></td>
		</tr>
		<tr>
			<th>采集分类地址</th>
			<td>
				<div class="mb10"><input id="CS_Cjurl" name="CS_Cjurl" value="<?php echo $Arr[6]?>" type="text" class="input input_hd length_5"></div>
				<div class="mb10">
                                 开始页数:&nbsp;<input name="CS_CJKSID" type="text" class="input length_1" value="<?php echo $Arr[7]?>" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">&nbsp;
				 结束页数:&nbsp;<input name="CS_CJJSID" type="text" class="input length_1" value="<?php echo $Arr[8]?>" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">&nbsp;
                                 &nbsp;&nbsp;如：1 - 9
                                </div>
			</td>
			<td><div class="fun_tips">分类页参数  <font color=red>{$ID}</font></div></td>
		</tr>
		<tr>
			<th>列表开始代码</th>
			<td>
				<textarea class="length_6" id="CS_Listks" name="CS_Listks"><?php echo $Arr[9]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲列表开始代码</div></td>
		</tr>
		<tr>
			<th>列表结束代码</th>
			<td>
				<textarea class="length_6" id="CS_Listjs" name="CS_Listjs"><?php echo $Arr[10]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲列表开始代码</div></td>
		</tr>
		<tr>
			<th>歌曲链接开始代码</th>
			<td>
				<textarea class="length_6" id="CS_Linkks" name="CS_Linkks"><?php echo $Arr[11]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲链接地址开始代码</div></td>
		</tr>
		<tr>
			<th>歌曲链接结束代码</th>
			<td>
				<textarea class="length_6" id="CS_Linkjs" name="CS_Linkjs"><?php echo $Arr[12]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲链接地址结束代码</div></td>
		</tr>
		<tbody id="picgo" <?php if($Arr[3]!=1){echo "style=\"display:none\"";} ?>>
		<tr>
			<th>歌曲图片开始代码</th>
			<td>
				<textarea class="length_6" id="CS_Picks" name="CS_Picks"><?php echo $Arr[13]?></textarea>

			</td>
			<td><div class="fun_tips">列表图片地址开始代码</div></td>
		</tr>
		<tr>
			<th>歌曲图片结束代码</th>
			<td>
				<textarea class="length_6" id="CS_Picjs" name="CS_Picjs"><?php echo $Arr[14]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲图片地址结束代码</div></td>
		</tr>
		</tbody>
<?php
     }elseif($op==1){ 

	$Url=CS_ReplaceStr(CS_Request("CS_Cjurl"),'{$ID}',CS_Request("CS_CJKSID"));
	$Content=geturlcontent($Url,CS_Request("CS_Code"));//读取列表文件
	if(empty($Content)) {
		 exit("<script>alert('".$Url."采集不到内容！');history.go(-1)</script>");	
	}
	$Liststr = getContent($Content,$_POST["CS_Listks"],$_POST["CS_Listjs"]);//截取列表开始--结束
        $dLinkArr=getArr($_POST["CS_Linkks"],$_POST["CS_Linkjs"],$Liststr);//获取到歌曲连接地址 返回数组
        if(empty($dLinkArr)) exit("<script>alert('获取歌曲连接地址时出错,请确认！');history.go(-1)</script>");
        if(CS_Request("CS_PicMode")=='ok'){  //采集图片
           $PicArr=getArr($_POST["CS_Picks"],$_POST["CS_Picjs"],$Liststr);//获取到图片地址 返回数组
           $CS_Pic=$PicArr[0];
        }

        $Playurl=$dLinkArr[0];
     	$_SESSION['CJ_Playurl']=$Playurl;
     	$_SESSION['CJ_Name']=dh($_POST["CS_Name"]);
     	$_SESSION['CJ_Url']=CS_Request("CS_Url");
     	$_SESSION['CJ_Code']=CS_Request("CS_Code");
     	$_SESSION['CJ_PID']=CS_Request("CS_PID");
     	$_SESSION['CJ_FID']=CS_Request("CS_FID");
     	$_SESSION['CJ_Cjurl']=CS_Request("CS_Cjurl");
     	$_SESSION['CJ_CJKSID']=CS_Request("CS_CJKSID");
     	$_SESSION['CJ_CJJSID']=CS_Request("CS_CJJSID");
     	$_SESSION['CJ_Listks']=dh($_POST["CS_Listks"]);
     	$_SESSION['CJ_Listjs']=dh($_POST["CS_Listjs"]);
     	$_SESSION['CJ_Linkks']=dh($_POST["CS_Linkks"]);
     	$_SESSION['CJ_Linkjs']=dh($_POST["CS_Linkjs"]);
     	$_SESSION['CJ_Pic']=$CS_Pic;
     	if(CS_Request("CS_PicMode")=='ok'){
        	$_SESSION['CJ_PicMode']=1;
        	$_SESSION['CJ_Picks']=dh($_POST["CS_Picks"]);
         	$_SESSION['CJ_Picjs']=dh($_POST["CS_Picjs"]);
     	}
        if(empty($_SESSION['CJ_PicMode'])) $_SESSION['CJ_PicMode']=0;
?>
<script language="javascript">
$(document).ready(function(){
	$("#caijiadd").click(function(){
		var CS_Nameks=$("#CS_Nameks").val();
		var CS_Namejs=$("#CS_Namejs").val();
		var CS_Danceks=$("#CS_Danceks").val();
		var CS_Dancejs=$("#CS_Dancejs").val();
		var CS_DanceMode=$("#CS_DanceMode").val();
		var CS_Playks=$("#CS_Playks").val();
		var CS_Playjs=$("#CS_Playjs").val();
		var CS_CID=$("#CS_CID").val();
		var CS_User=$("#CS_User").val();

	$("#CS_Nameks").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Namejs").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Danceks").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Dancejs").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Playks").css("border-color","#666 #ccc #ccc #666");
	$("#CS_Playjs").css("border-color","#666 #ccc #ccc #666");
	$("#CS_CID").css("border-color","#666 #ccc #ccc #666");
	$("#CS_User").css("border-color","#666 #ccc #ccc #666");
	if(CS_CID=="0"){
		$("#CS_CID").css("border","1px solid red");
		$("#Msg").text("请选择要保存的分类！").css("color","red");
		return false;
		}
	else if(CS_User==""){
		$("#CS_User").css("border","1px solid red");
		$("#Msg").text("请填写要保存的所属会员！").css("color","red");
		return false;
	 	}
	else if(CS_Nameks==""){
		$("#CS_Nameks").css("border","1px solid red");
		$("#Msg").text("请填写歌曲名称开始代码！").css("color","red");
		return false;
		}
	else if(CS_Namejs==""){
		$("#CS_Namejs").css("border","1px solid red");
		$("#Msg").text("请填写歌曲名称结束代码！").css("color","red");
		return false;
		}
	else if(CS_Danceks==""){
		$("#CS_Danceks").css("border","1px solid red");
		$("#Msg").text("请填写歌曲地址开始代码！").css("color","red");
		return false;
		}
	else if(CS_Dancejs==""){
		$("#CS_Dancejs").css("border","1px solid red");
		$("#Msg").text("请填写歌曲地址结束代码！").css("color","red");
		return false;
		}
	else if(CS_DanceMode=="1"){
                     if(CS_Playks==""){
		        $("#CS_Playks").css("border","1px solid red");
		        $("#Msg").text("请填写绝对路径开始代码！").css("color","red");
		        return false;
                     }
                     if(CS_Playjs==""){
		        $("#CS_Playjs").css("border","1px solid red");
		        $("#Msg").text("请填写绝对路径结束代码！").css("color","red");
		        return false;
                     }
	        }
        else {
                  document.getElementById("Msg").className="tips_success";
                  document.getElementById('Msg').innerHTML='<img src="../../public/images/load.gif">正在提交,请稍等...';
             }
	});
});
</script>
		<tr>
			<th>保存到分类</th>
			<td>
				         <select class="select_2" id="CS_CID" name="CS_CID">
                                                <option value="0">--选择分类--</option>
            					 <?php
              						$sqlf="select * from ".Getdbname('class')." where CS_SID=1 ";
									$results=$db->query($sqlf);
									if($results){
										while ($row2=$db->fetch_array($results)){
                                                                                    if($row2['CS_ID']==$Arr[15]){
										         echo "<option value='".$row2['CS_ID']."' selected='selected'>".$row2['CS_Name']."</option>";
                                                                                    }else{
										         echo "<option value='".$row2['CS_ID']."' >".$row2['CS_Name']."</option>";
                                                                                    }
										}
									}
			  
			  			 ?>             
                                         </select>

			</td>
			<td><div class="fun_tips">歌曲分类</div></td>
		</tr>
		<tr>
			<th>保存所属会员</th>
			<td>
				<input id="CS_User" name="CS_User" value="<?php echo $Arr[16]?>" type="text" class="input input_hd length_5">&nbsp;

			</td>
			<td><div class="fun_tips">歌曲保存所属会员</div></td>
		</tr>
		<tr>
			<th>歌曲名称开始代码</th>
			<td>
				<textarea class="length_6" id="CS_Nameks" name="CS_Nameks"><?php echo $Arr[17]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲名称开始代码</div></td>
		</tr>
		<tr>
			<th>歌曲名称结束代码</th>
			<td>
				<textarea class="length_6" id="CS_Namejs" name="CS_Namejs"><?php echo $Arr[18]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲名称结束代码</div></td>
		</tr>
		<tr>
			<th>歌曲歌手开始代码</th>
			<td>
				<textarea class="length_6" id="CS_Singerks" name="CS_Singerks"><?php echo $Arr[19]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲歌手开始代码</div></td>
		</tr>
		<tr>
			<th>歌曲歌手结束代码</th>
			<td>
				<textarea class="length_6" id="CS_Singerjs" name="CS_Singerjs"><?php echo $Arr[20]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲歌手结束代码</div></td>
		</tr>
		<tr>
			<th>歌词、介绍开始代码</th>
			<td>
				<textarea class="length_6" id="CS_Lrcks" name="CS_Lrcks"><?php echo $Arr[21]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲歌手开始代码</div></td>
		</tr>
		<tr>
			<th>歌词、介绍结束代码</th>
			<td>
				<textarea class="length_6" id="CS_Lrcjs" name="CS_Lrcjs"><?php echo $Arr[22]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲歌手结束代码</div></td>
		</tr>
		<tr>
			<th>歌曲地址采集模式</th>
			<td>
				<ul class="switch_list cc">
					<li><label><input id="CS_DanceMode" name="CS_DanceMode" type="radio" value="0" <?php if($Arr[23]==0){echo "checked";}?> onClick="javascript:document.getElementById('purl').style.display='none'"><span>播放页</span></label></li>
					<li><label><input id="CS_DanceMode" name="CS_DanceMode" type="radio" value="1" <?php if($Arr[23]==1){echo "checked";}?> onClick="javascript:document.getElementById('purl').style.display=''"><span>绝对路径页</span></label></li>
				</ul>
			</td>
			<td><div class="fun_tips">歌曲地址采集模式</div></td>
		</tr>
		<tbody id="purl" <?php if($Arr[21]!=1){echo "style=\"display:none\"";} ?>>
		<tr>
			<th>绝对路径连接开始代码</th>
			<td>
				<textarea class="length_6" id="CS_Playks" name="CS_Playks"><?php echo $Arr[24]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲绝对路径地址开始代码</div></td>
		</tr>
		<tr>
			<th>绝对路径连接结束代码</th>
			<td>
				<textarea class="length_6" id="CS_Playjs" name="CS_Playjs"><?php echo $Arr[25]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲绝对路径地址结束代码</div></td>
		</tr>
		</tbody>
		<tr>
			<th>歌曲地址开始代码</th>
			<td>
				<textarea class="length_6" id="CS_Danceks" name="CS_Danceks"><?php echo $Arr[26]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲地址开始代码</div></td>
		</tr>
		<tr>
			<th>歌曲地址结束代码</th>
			<td>
				<textarea class="length_6" id="CS_Dancejs" name="CS_Dancejs"><?php echo $Arr[27]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲地址结束代码</div></td>
		</tr>
		<tr>
			<th>歌曲地址字符替换</th>
			<td>
				<textarea class="length_6" id="CS_DanceTh" name="CS_DanceTh"><?php echo $Arr[28]?></textarea>

			</td>
			<td><div class="fun_tips">歌曲地址字符替换,<br><span style="color:red">&nbsp; 格式：被替换的内容@@cscms@@替换为的内容<br>每行为一个多个替换请以回车键换行</span></div></td>
		</tr>
		<tr>
			<th>歌词介绍字符替换</th>
			<td>
				<textarea class="length_6" id="CS_LrcTh" name="CS_LrcTh"><?php echo $Arr[29]?></textarea>

			</td>
			<td><div class="fun_tips">歌词介绍字符替换，<br><span style="color:red">&nbsp; 格式：被替换的内容@@cscms@@替换为的内容<br>每行为一个多个替换请以回车键换行</span></div></td>
		</tr>
<?php
     }elseif($op==2){ 
        if(substr($_SESSION['CJ_Playurl'],0,7)!="http://") $_SESSION['CJ_Playurl']=$_SESSION['CJ_Url'].$_SESSION['CJ_Playurl'];
	$Content=geturlcontent($_SESSION['CJ_Playurl'],$_SESSION['CJ_Code']);//读取文件
	if(empty($Content)) {
		 exit("<script>alert('".$_SESSION['CJ_Playurl']."采集不到内容！');history.go(-1);</script>");	
	}
	$CS_Name = getContent($Content,$_POST["CS_Nameks"],$_POST["CS_Namejs"]);  //歌曲名称
	$CS_Singer = getContent($Content,$_POST["CS_Singerks"],$_POST["CS_Singerjs"]);  //歌曲歌手
	$CS_Lrc = getContent($Content,$_POST["CS_Lrcks"],$_POST["CS_Lrcjs"]);  //歌曲歌词、介绍

        if(CS_Request("CS_DanceMode")==1){  //绝对路径采集
	      $Playurl = getContent($Content,$_POST["CS_Playks"],$_POST["CS_Playjs"]);
	      $pContent=geturlcontent($Playurl,$_SESSION['CJ_Code']);//读取绝对路径文件
              if(empty($pContent)) exit("<script>alert('获取绝对路径内容出错，请检查绝对路径代码！');history.go(-1);</script>");
	      $CS_Dance = getContent($pContent,$_POST["CS_Danceks"],$_POST["CS_Dancejs"]);
        }else{
	      $CS_Dance = getContent($Content,$_POST["CS_Danceks"],$_POST["CS_Dancejs"]);  //歌曲地址
        }

        $CS_Dance=collectRep($CS_Dance,$_POST["CS_DanceTh"]);
        $CS_Lrc=collectRep($CS_Lrc,$_POST["CS_LrcTh"]);

     	$_SESSION['CJ_CID']=CS_Request("CS_CID");
     	$_SESSION['CJ_User']=CS_Request("CS_User");
     	$_SESSION['CJ_Nameks']=dh($_POST["CS_Nameks"]);
     	$_SESSION['CJ_Namejs']=dh($_POST["CS_Namejs"]);
     	$_SESSION['CJ_Singerks']=dh($_POST["CS_Singerks"]);
     	$_SESSION['CJ_Singerjs']=dh($_POST["CS_Singerjs"]);
     	$_SESSION['CJ_Lrcks']=dh($_POST["CS_Lrcks"]);
     	$_SESSION['CJ_Lrcjs']=dh($_POST["CS_Lrcjs"]);
     	$_SESSION['CJ_Danceks']=dh($_POST["CS_Danceks"]);
     	$_SESSION['CJ_Dancejs']=dh($_POST["CS_Dancejs"]);
        $_SESSION['CJ_DanceMode']=CS_Request("CS_DanceMode");
     	$_SESSION['CJ_DanceTh']=dh($_POST["CS_DanceTh"]);
     	$_SESSION['CJ_LrcTh']=dh($_POST["CS_LrcTh"]);

     	if(CS_Request("CS_DanceMode")==1){
        	$_SESSION['CJ_Playks']=dh($_POST["CS_Playks"]);
         	$_SESSION['CJ_Playjs']=dh($_POST["CS_Playjs"]);
     	}
?>
		<tr>
			<th>歌曲名称：</th>
			<td><?php echo $CS_Name?></td>
			<td><div class="fun_tips">采集到的歌曲名称</div></td>
		</tr>
		<tr>
			<th>歌曲歌手：</th>
			<td><?php echo $CS_Singer?></td>
			<td><div class="fun_tips">采集到的歌曲歌手</div></td>
		</tr>
		<tr>
			<th>歌曲图片：</th>
			<td><?php echo $_SESSION['CJ_Pic']?></td>
			<td><div class="fun_tips">采集到的歌曲图片</div></td>
		</tr>
		<tr>
			<th>歌曲分类：</th>
			<td><?php echo $CS_Cname?></td>
			<td><div class="fun_tips">采集到的歌曲分类</div></td>
		</tr>
		<tr>
			<th>歌曲地址：</th>
			<td><?php echo $CS_Dance?></td>
			<td><div class="fun_tips">采集到的歌曲地址</div></td>
		</tr>
		<tr>
			<th>歌曲歌词、介绍：</th>
			<td><?php echo $CS_Lrc?></td>
			<td><div class="fun_tips">采集到的歌词、介绍</div></td>
		</tr>
<?php
  }elseif($op==3){  //保存规则

      if(empty($CS_ID)){  //新增
         $sql="Insert ".Getdbname('caiji')."  (CS_Name,CS_Url,CS_Code,CS_User,CS_SID,CS_CID,CS_PID,CS_FID,CS_PicMode,CS_DanceMode,CS_Cjurl,CS_CJKSID,CS_CJJSID,CS_Listks,CS_Listjs,CS_Picks,CS_Picjs,CS_Linkks,CS_Linkjs,CS_Nameks,CS_Namejs,CS_Singerks,CS_Singerjs,CS_Lrcks,CS_Lrcjs,CS_Playks,CS_Playjs,CS_Danceks,CS_Dancejs,CS_LrcTh,CS_DanceTh,CS_AddTime) values ('".$_SESSION['CJ_Name']."','".$_SESSION['CJ_Url']."','".$_SESSION['CJ_Code']."','".$_SESSION['CJ_User']."',1,".$_SESSION['CJ_CID'].",".$_SESSION['CJ_PID'].",".$_SESSION['CJ_FID'].",".$_SESSION['CJ_PicMode'].",".$_SESSION['CJ_DanceMode'].",'".$_SESSION['CJ_Cjurl']."',".$_SESSION['CJ_CJKSID'].",".$_SESSION['CJ_CJJSID'].",'".$_SESSION['CJ_Listks']."','".$_SESSION['CJ_Listjs']."','".$_SESSION['CJ_Picks']."','".$_SESSION['CJ_Picjs']."','".$_SESSION['CJ_Linkks']."','".$_SESSION['CJ_Linkjs']."','".$_SESSION['CJ_Nameks']."','".$_SESSION['CJ_Namejs']."','".$_SESSION['CJ_Singerks']."','".$_SESSION['CJ_Singerjs']."','".$_SESSION['CJ_Lrcks']."','".$_SESSION['CJ_Lrcjs']."','".$_SESSION['CJ_Playks']."','".$_SESSION['CJ_Playjs']."','".$_SESSION['CJ_Danceks']."','".$_SESSION['CJ_Dancejs']."','".$_SESSION['CJ_LrcTh']."','".$_SESSION['CJ_DanceTh']."','".date('Y-m-d H:i:s')."')";

      }else{  //修改
         $sql="update ".Getdbname('caiji')." set CS_Name='".$_SESSION['CJ_Name']."',CS_Url='".$_SESSION['CJ_Url']."',CS_Code='".$_SESSION['CJ_Code']."',CS_User='".$_SESSION['CJ_User']."',CS_SID=1,CS_CID=".$_SESSION['CJ_CID'].",CS_PID=".$_SESSION['CJ_PID'].",CS_FID=".$_SESSION['CJ_FID'].",CS_PicMode=".$_SESSION['CJ_PicMode'].",CS_DanceMode=".$_SESSION['CJ_DanceMode'].",CS_Cjurl='".$_SESSION['CJ_Cjurl']."',CS_CJKSID=".$_SESSION['CJ_CJKSID'].",CS_CJJSID=".$_SESSION['CJ_CJJSID'].",CS_Listks='".$_SESSION['CJ_Listks']."',CS_Listjs='".$_SESSION['CJ_Listjs']."',CS_Picks='".$_SESSION['CJ_Picks']."',CS_Picjs='".$_SESSION['CJ_Picjs']."',CS_Linkks='".$_SESSION['CJ_Linkks']."',CS_Linkjs='".$_SESSION['CJ_Linkjs']."',CS_Nameks='".$_SESSION['CJ_Nameks']."',CS_Namejs='".$_SESSION['CJ_Namejs']."',CS_Singerks='".$_SESSION['CJ_Singerks']."',CS_Singerjs='".$_SESSION['CJ_Singerjs']."',CS_Lrcks='".$_SESSION['CJ_Lrcks']."',CS_Lrcjs='".$_SESSION['CJ_Lrcjs']."',CS_Playks='".$_SESSION['CJ_Playks']."',CS_Playjs='".$_SESSION['CJ_Playjs']."',CS_Danceks='".$_SESSION['CJ_Danceks']."',CS_Dancejs='".$_SESSION['CJ_Dancejs']."',CS_LrcTh='".$_SESSION['CJ_LrcTh']."',CS_DanceTh='".$_SESSION['CJ_DanceTh']."' where CS_ID=".$CS_ID;

      }
         if($db->query($sql)){
               session_destroy();
               exit("<script>alert('保存成功！');window.location='?'</script>");
         }else{
               exit("<script>alert('保存失败！');window.location='?'</script>");
         }
  }     
?>

<div class="btn_wrap">
	<div class="btn_wrap_pd">
		<button type="submit" id="caijiadd" class="btn btn_submit mr10 J_ajax_submit_btn">提交下一步</button>
                <div class="tips_error" id="Msg"></div>
	</div>
</div>
<?php
}elseif($ac=='daochu'){
	$sql="select * from ".Getdbname('caiji')." where CS_ID=$id";
	$row=$db->getRow($sql);
	if($row){
		$rule="<cscms_name>".$row["CS_Name"]."</cscms_name>\r\n";
		$rule.="<cscms_url>".$row["CS_Url"]."</cscms_url>\r\n";
		$rule.="<cscms_code>".$row["CS_Code"]."</cscms_code>\r\n";
		$rule.="<cscms_user>".$row["CS_User"]."</cscms_user>\r\n";
		$rule.="<cscms_sid>".$row["CS_SID"]."</cscms_sid>\r\n";
		$rule.="<cscms_cid>".$row["CS_CID"]."</cscms_cid>\r\n";
		$rule.="<cscms_pid>".$row["CS_PID"]."</cscms_pid>\r\n";
		$rule.="<cscms_fid>".$row["CS_FID"]."</cscms_fid>\r\n";
		$rule.="<cscms_picmode>".$row["CS_PicMode"]."</cscms_picmode>\r\n";
		$rule.="<cscms_dancemode>".$row["CS_DanceMode"]."</cscms_dancemode>\r\n";
		$rule.="<cscms_cjurl>".$row["CS_Cjurl"]."</cscms_cjurl>\r\n";
		$rule.="<cscms_cjksid>".$row["CS_CJKSID"]."</cscms_cjksid>\r\n";
		$rule.="<cscms_cjjsid>".$row["CS_CJJSID"]."</cscms_cjjsid>\r\n";
		$rule.="<cscms_listks>".$row["CS_Listks"]."</cscms_listks>\r\n";
		$rule.="<cscms_listjs>".$row["CS_Listjs"]."</cscms_listjs>\r\n";
		$rule.="<cscms_picks>".$row["CS_Picks"]."</cscms_listjs>\r\n";
		$rule.="<cscms_picjs>".$row["CS_Picjs"]."</cscms_picjs>\r\n";
		$rule.="<cscms_linkks>".$row["CS_Linkks"]."</cscms_linkks>\r\n";
		$rule.="<cscms_linkjs>".$row["CS_Linkjs"]."</cscms_linkjs>\r\n";
		$rule.="<cscms_nameks>".$row["CS_Nameks"]."</cscms_nameks>\r\n";
		$rule.="<cscms_namejs>".$row["CS_Namejs"]."</cscms_namejs>\r\n";
		$rule.="<cscms_singerks>".$row["CS_Singerks"]."</cscms_singerks>\r\n";
		$rule.="<cscms_singerjs>".$row["CS_Singerjs"]."</cscms_singerjs>\r\n";
		$rule.="<cscms_lrcks>".$row["CS_Lrcks"]."</cscms_lrcks>\r\n";
		$rule.="<cscms_lrcjs>".$row["CS_Lrcjs"]."</cscms_lrcjs>\r\n";
		$rule.="<cscms_playks>".$row["CS_Playks"]."</cscms_playks>\r\n";
		$rule.="<cscms_playjs>".$row["CS_Playjs"]."</cscms_playjs>\r\n";
		$rule.="<cscms_danceks>".$row["CS_Danceks"]."</cscms_danceks>\r\n";
		$rule.="<cscms_dancejs>".$row["CS_Dancejs"]."</cscms_dancejs>\r\n";
		$rule.="<cscms_danceth>".$row["CS_DanceTh"]."</cscms_danceth>\r\n";
		$rule.="<cscms_lrcth>".$row["CS_LrcTh"]."</cscms_lrcth>\r\n";			
	}
?>
	<form action="?ac=daochudata" method="post" class="J_ajaxForm" id="J_backup_form">
	<div class="table_full"><input type=hidden value="<?php echo $row["CS_Name"]?>" name="sname">
		<table width="100%">
			<col class="th" />
			<tr>
				<th>采集规则导出</th>
				<td>
					<div class="sql_list J_check_wrap">
						<dl>
							<dt>
								<span style="color:red">采集规则导出</span>
							</dt>
							<dd>
                                                                <textarea rows="50" name="guize" id="guize" style="width:98%;height:290px;font-family:Georgia, 'Times New Roman', Times, serif"><?php echo $rule;?></textarea>
							</dd>
						</dl>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="btn_wrap">
		<div class="btn_wrap_pd">
		<button class="btn btn_submit J_ajax_submit_btn" id="custon_btn" type="submit">规则另存为</button>
		<div id="J_backup_tip"></div>
		</div>
	</div>
	</form>
<?php
}elseif($ac=='daoru'){
?>
<script language="javascript">
$(document).ready(function(){
	$("#daoru").click(function(){
	var guize=$("#guize").val();
	$("#guize").css("border-color","#666 #ccc #ccc #666");
	if(guize==""){
		$("#guize").css("border","1px solid red");
		$("#Msg").text("请先粘贴要导入的规则！").css("color","red");
		return false;
		}
	});
});
</script>
	<form action="?ac=daorudata" method="post" class="J_ajaxForm" id="J_backup_form">
	<div class="table_full">
		<table width="100%">
			<col class="th" />
			<tr>
				<th id="Msg">采集规则导入</th>
				<td>
					<div class="sql_list J_check_wrap">
						<dl>
							<dt>
								<span style="color:red">采集规则粘贴到下面进行导入</span>
							</dt>
							<dd>
                                                                <textarea rows="50" name="guize" id="guize" style="width:98%;height:290px;font-family:Georgia, 'Times New Roman', Times, serif"></textarea>
							</dd>
						</dl>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="btn_wrap">
		<div class="btn_wrap_pd">
		<button class="btn btn_submit J_ajax_submit_btn" id="daoru" type="submit">规则导入</button>
		</div>
	</div>
	</form>
<?php
}else{ //规则列表
?> 
<div class="table_list">
<table width="100%" id="dellist">
		<thead>
			<tr>
				<td><label>ID</label></td>
				<td>名称</td>
				<td><span>地址</span></td>
				<td><span>播放器</span></td>
				<td><span>最后采集时间</span></td>
				<td>导出/编辑/删除</td>
			</tr>
		</thead>
      <?php 
        $sql="select * from ".Getdbname('caiji')." where CS_SID=1 order by CS_ID asc";
	$rs=$db->query($sql);
	$num=$db->num_rows($rs);
        if($num==0) echo "<tr><td class=\"tac\" colspan=\"6\">啊哦，没有符合条件的内容！</td></tr>";
 	for($i=0;$i<$num;$i++){ 
		$row=$db->fetch_array($rs);
      ?>
                       <tr>
				<td>&nbsp;<?php echo $row['CS_ID']?></td>
				<td><a href="?ac=edit&id=<?php echo $row['CS_ID']?>"><?php echo $row['CS_Name']?></a></td>
				<td><a href="<?php echo $row['CS_Url']?>" target="cjurl"><?php echo $row['CS_Url']?></a></td>
				<td>
                                   <?php
                                       if($row['CS_PID']==0){ 
                                              echo 'wma播放器';
                                       }elseif($row['CS_PID']==1){ 
                                              echo 'cmp播放器';
                                       }elseif($row['CS_PID']==2){ 
                                              echo 'flv播放器';
                                       }elseif($row['CS_PID']==3){ 
                                              echo '优库播放器';
                                       }elseif($row['CS_PID']==4){ 
                                              echo '土豆播放器';
                                       }elseif($row['CS_PID']==5){ 
                                              echo 'SWF播放器';
                                       }elseif($row['CS_PID']==6){ 
                                              echo '音乐台播放器';
                                       }elseif($row['CS_PID']==7){ 
                                              echo 'FLASH播放器';
                                       }
                                    ?>
                                </td>
				<td><?php echo $row['CS_AddTime']?></td>
				<td><a href="caiji.php?ac=caiji&id=<?php echo $row['CS_ID']?>">采集</a> &nbsp;&nbsp;<a href="?ac=daochu&id=<?php echo $row['CS_ID']?>">导出</a> &nbsp;&nbsp;<a href="?ac=edit&id=<?php echo $row['CS_ID']?>">编辑</a> &nbsp;&nbsp;<a style="cursor:pointer;"  onclick="del(<?php echo $row['CS_ID']?>)">删除</a></td>
			</tr>
      <?php
 	}
      ?>
</table>
</div>
<?php } ?> 
</div>
</body>
</html>