<?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('2_1');
$ac=CS_Request("ac");
$op=CS_Request("op");
@set_time_limit(0);

if($ac=='saomiao'){
   echo("<link href=\"../res/css/admin_style.css\" rel=\"stylesheet\" /><div class=\"h_a\">&nbsp;正在扫描硬盘歌曲...</div>");
      $hz=CS_Request("hz");
		$shux=CS_Request("shux");
		$CS_CID=CS_Request("CS_CID");
		$CS_TID=CS_Request("CS_TID");
		$CS_Singer=CS_Request("CS_Singer");
		$CS_User=CS_Request("CS_User");
		$CS_PID=CS_Request("CS_PID");
		$CS_FID=CS_Request("CS_FID");
		$CS_Year=CS_Request("CS_Year");
		$CS_Reco=CS_Request("CS_Reco");
		$CS_Coin=CS_Request("CS_Coin");
		$CS_Vip=CS_Request("CS_Vip");
		$CS_Tags=$_POST["CS_Tags"];
		$YP=$_POST["YP"];
		$dance=$_POST["dance"];
                $CS_Template=CS_Request("CS_Template");

        $dir=$YP.$dance;
        if(empty($YP)||$YP=="../../"){
              $dir=str_replace("../../","",$dir);
              if(substr($dir,0,1)!="/") $dir="/".$dir;
              if(substr($dir,-1)!="/") $dir=$dir."/";
              $dir="../..".$dir;
        }
	if(is_dir($dir)){ //是否为文件夹
		if ($dh = opendir($dir)) { //打开文件夹
			while (($file= readdir($dh)) !== false){ //读取文件夹里面的所有东西
				$nowfilepath=$dir.'/'.$file; //当前的目录
				if(!is_dir($nowfilepath)){ 
	                              $sys=pathinfo($file);//获取文件名后缀
	                              if(is_int(strpos($hz,$sys['extension'])) !== false){  //判断是否是音乐文件

                                          $dance=str_replace("\\","/",$dance);
                                          $CS_Name=substr($file,0,-4);
                                          $CS_PlayUrl="/".$dance."/".$file;
                                          $CS_PlayUrl=str_replace("//","/",$CS_PlayUrl);
                                          $CS_DownUrl=$CS_PlayUrl;

                                        if($shux==2){ //判断歌曲属性
                                          if(substr($dir,0,2)==".."){
                                             $dpath=$_SERVER['DOCUMENT_ROOT']."/".$dance."/".$file;
                                          }else{
                                             $dpath=$dir."/".$file;
                                          }
                                             $dpath=str_replace("\\","/",$dpath);
                                             $dpath=str_replace("//","/",$dpath);

		                             $CS_Yz=DjData("yz",$dpath);
		                             $CS_Dx =DjData("dx",$dpath);
		                             $CS_Sc = DjData("sj",$dpath);
                                        }else{
		                          $CS_Yz ="";
		                          $CS_Dx ="";
		                          $CS_Sc ="";
                                        }

				          //判断数据是否相同
				          $CS_ID= $db->Getone("select CS_ID from ".Getdbname('dance')." where CS_Name='".$CS_Name."'");
				          if($CS_ID){

					    echo "<font style=font-size:13px;>&nbsp;&nbsp;歌曲&nbsp;&nbsp;<font color=red>".$file."</font>&nbsp;&nbsp;<font color=#0000ff>已经存在，跳过入库!</font>．．．<br/>";

				          }else{
					          $sql="Insert ".Getdbname('dance')."  (CS_PlayUrl,CS_DownUrl1,CS_Tags,CS_Name,CS_CID,CS_User,CS_TID,CS_Singer,CS_PID,CS_FID,CS_Year,CS_Reco,CS_Coin,CS_Vip,CS_Template,CS_Yz,CS_Dx,CS_Sc,CS_AddTime) values ('".$CS_PlayUrl."','".$CS_DownUrl."','".$CS_Tags."','".$CS_Name."',".$CS_CID.",'".$CS_User."',".$CS_TID.",'".$CS_Singer."',".$CS_PID.",".$CS_FID.",'".$CS_Year."',".$CS_Reco.",".$CS_Coin.",".$CS_Vip.",'".$CS_Template."','".$CS_Yz."','".$CS_Dx."','".$CS_Sc."','".date('Y-m-d H:i:s')."')";
					          if($db->query($sql)){
					          	echo "<font style=font-size:13px;>&nbsp;&nbsp;歌曲&nbsp;&nbsp;<font color=red>".$file."</font>&nbsp;&nbsp;<font color=#026E12>入库成功</font>．．．<br/>";
					          }else{
					                echo "<font style=font-size:13px;>&nbsp;&nbsp;歌曲&nbsp;&nbsp;<font color=red>".$file."</font>&nbsp;&nbsp;<font color=#ff6600>入库失败，未知错误</font>．．．<br/>";
                                                  }
				          }
                                      }
				} 
			} 
			closedir($dh); 
		} 
	} 
    echo "<script>setTimeout(\"window.location='javascript:history.go(-1);'\",4000);</script>";
    exit("&nbsp;&nbsp;<font color=#0000ff><b>恭喜你！所有歌曲扫描入库完毕．．．</b></font><br><br>");
}
?>
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title>chshdjcms management</title>
<link href="../res/css/admin_style.css" rel="stylesheet" />
<link href="../../public/css/webox.css" rel="stylesheet" />
<script type="text/javascript" src="../res/js/ajax.js"></script>
<script language="javascript" src="../res/js/jquery.js"></script>
<script src="../../public/js/webox.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){
	$("#adddance").click(function(){
		var CS_CID=document.getElementById('CS_CID').value;
		var CS_User=document.getElementById('CS_User').value;
		var dance=document.getElementById('dance').value;
		var CS_Coin=document.getElementById('CS_Coin').value;
	if(CS_CID=="0"){
		$("#Msg").text("请选择歌曲分类！").css("color","red");
		return false;
		}
	else if(CS_User==""){
		$("#Msg").text("请填写歌曲所属会员！").css("color","red");
		return false;
		}
	else if(CS_Coin==""){
		$("#Msg").text("请填写歌曲下载金币！").css("color","red");
		return false;
		}
	else if(dance==""){
		$("#Msg").text("请填写歌曲目录路径！").css("color","red");
		return false;
		}
	});
});
function saomiao(_path){
      if(_path){
          Popsboxif('浏览歌曲文件',540,418,'?ac=look&path='+_path+'');
      }else{
            alert("请先填写硬盘路径！");
      }
}
function ReturnValue(_path){
	window.parent.document.form.dance.value=_path;
	this.parent.$('.webox').css({display:'none'});
	this.parent.$('.background').css({display:'none'});
}
</script>
</head>
<?php
if($ac=='look'){
echo '<body class="body_none">
      <div>
      <div class="pop_cont pop_table">
	<table width="100%" style="table-layout:fixed;">
		<col width="250" />
		<col />
				<tr>
					<td colspan="2">&nbsp;<img src=../res/images/dir2.gif border=0 width=16 height=16 align=absmiddle>&nbsp;当前目录: <font color=red><?php echo $path?></font></td>
					<td><a href="javascript:history.back(1);">返回上一页</a>&nbsp;</td>
				</tr>';
        $dir=$_GET['path'];
        $yp=@$_GET['yp'];
        if(empty($yp)) $yp=$dir;
	if(@is_dir($dir)){ //是否为文件夹
		if ($dh = opendir($dir)) { //打开文件夹
			while (($file= readdir($dh)) !== false){ //读取文件夹里面的所有东西
				$nowfilepath=$dir.'/'.$file; //当前的目录
				if(@is_dir($nowfilepath)){ 
					if($file!='.' and $file!='..'){
						echo "<tr>";
						echo "<td><input type='checkbox' value='0' class='checkbox' onClick=\"ReturnValue('".str_replace($yp,"",str_replace("//","/",$nowfilepath))."');\" />";
						echo "&nbsp;<a href='?ac=look&yp=".$yp."&path=".str_replace("//","/",$nowfilepath)."/'>".$file."</a></td>";
						echo "<td>&nbsp;</td>";
						echo "<td>".date('Y-m-d H:i:s',filemtime($nowfilepath))."</td>";
						echo "</tr>";

					}
				}else{ //不是文件夹时，直接输出文件
	                              $sys=pathinfo($file);//获取文件名后缀
	                              if($sys['extension'] =="mp3" || $sys['extension'] =="wma" || $sys['extension'] =="mpg" || $sys['extension'] =="mp4" || $sys['extension'] =="avi" || $sys['extension'] =="flv"){  //判断是否是音乐文件
					echo "<tr>";
					echo "<td><input type='checkbox' value='0' class='checkbox' disabled />&nbsp;".$file."</td>";
					echo "<td>".formatsize(filesize($nowfilepath))."</td>";
					echo "<td>".date('Y-m-d H:i:s',filemtime($nowfilepath))."</td>";
					echo "</tr>";
                                      }
				} 
			} 
			closedir($dh); 
		} 
	} 
echo "</table></div></div>";
exit();
}
?>
<body>
<div class="wrap">
<form class="J_ajaxForm" data-role="edit" name="form" action="?ac=saomiao" method="post">
<div class="h_a">硬盘扫描</div>
<div class="table_full">
	<table width="100%" class="J_check_wrap">
		<col class="th" />
		<col width="400" />
		<col />
		<tr>
			<th>音乐标签</th>
			<td>
				<input name="CS_Tags" id="CS_Tags" value="" type="text" class="input input_hd length_4">
                                &nbsp;<input class="btn" type="button" onclick="Popsboxif('选择标签',530,380,'../../public/tags.php?f=form.CS_Tags');" value="选择标签" />
			</td>
			<td><div class="fun_tips">填写音乐标签</div></td>
		</tr>
		<tr>
			<th>音乐分类</th>
			<td>
				<select class="select_2" name="CS_CID" id="CS_CID">
                                                <option value="0">选择分类</option>
            					 <?php
              						$sqlclass="select * from ".Getdbname('class')." where CS_YID=0 and CS_SID=1 and CS_FID=0";
									$results=$db->query($sqlclass);
									if($results){
										while ($row3=$db->fetch_array($results)){
										         echo "<option value='".$row3['CS_ID']."' >".$row3['CS_Name']."</option>";
		                                                                     //处理此分类下的子分类
		                                                                     $sql2="select * from ".Getdbname('class')." where CS_FID=".$row3['CS_ID']."";
		                                                                     $class2=$db->query($sql2);
		                                                                     if($class2){
			                                                                     while($row2=$db->fetch_array($class2)){
										                    echo "<option value='".$row2['CS_ID']."' >├ ".$row2['CS_Name']."</option>";
			                                                                     }
		                                                                     }
										}
									}
			  
			  			 ?>               
                                         </select>&nbsp;&nbsp;音乐专集：
				         <select class="select_2" name="CS_TID">
                                                <option value="0">选择专集</option>
            					 <?php
              						$sqlt="select * from ".Getdbname('topic')." where CS_YID=0 and CS_SID=1";
									$results=$db->query($sqlt);
									if($results){
										while ($row1=$db->fetch_array($results)){
										         echo "<option value='".$row1['CS_ID']."' >".$row1['CS_Name']."</option>";
										}
									}
			  
			  			 ?>             
                                         </select>
			</td>
			<td><div class="fun_tips">选择音乐分类、专集</div></td>
		</tr>
		<tr>
			<th>音乐歌手</th>
			<td>
				<input name="CS_Singer" value="" type="text" class="input input_hd length_2">
                                &nbsp;&nbsp;所属会员：
				<input id="CS_User" name="CS_User" value="" type="text" class="input input_hd length_2">
			</td>
			<td><div class="fun_tips">填写音乐歌手、会员</div></td>
		</tr>
		<tr>
			<th>音乐播放器</th>
			<td>
				<select class="select_2" name="CS_PID">
                                                <option value="0" selected='selected'>wma播放器</option>
                                                <option value="7" >mp3,mp4播放器</option>
                                                <option value="1" >cmp播放器</option>
                                                <option value="2" >flv播放器</option>
                                                <option value="3" >优库播放</option>
                                                <option value="4" >土豆播放</option>
                                                <option value="5" >SWF播放</option>
                                                <option value="6" >音乐台播放</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)){
										         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 name="CS_Year" value="2013" type="text" class="input input_hd length_2">
                                &nbsp;&nbsp;推荐星际：
				         <select class="select_2" name="CS_Reco">
                                                <option value="0">不推荐</option>
                                                <option value="1" >一星际</option>
                                                <option value="2" >二星际</option>
                                                <option value="3" >三星际</option>
                                                <option value="4" >四星际</option>
                                                <option value="5" >五星际</option>           
                                         </select>
			</td>
			<td><div class="fun_tips">选择发行年份、推荐星际</div></td>
		</tr>
		<tr>
			<th>下载金币</th>
			<td>
				<input id="CS_Coin" name="CS_Coin" value="1" type="text" class="input input_hd length_2">
                                &nbsp;个&nbsp;下载级别：
				         <select class="select_2" name="CS_Vip">
                                                <option value="0">游客下载</option>
                                                <option value="1" >普通会员</option>
                                                <option value="2" >VIP会员</option>          
                                         </select>
			</td>
			<td><div class="fun_tips">填写下载点数、级别</div></td>
		</tr>
		<tr>
			<th>播放页模版</th>
			<td>
				<input name="CS_Template" id="CS_Template" value="dance-play.html" type="text" class="input input_hd length_2">
                                &nbsp;&nbsp;<input class="btn" type="button" value="浏览" style="width:60px" onclick="Popsboxif('选择模版',450,400,'../skins/skin_re.php');"/>
			</td>
			<td><div class="fun_tips">可以利用这个功能支持所有播放器</div></td>
		</tr>
		<tr>
			<th>服务器硬盘路径</th>
			<td>
				<input type="text" name="YP" class="input length_3" value="">
                                &nbsp;<input class="btn btn_submit" type="button" onclick="saomiao(''+YP.value+'');" value="浏览歌曲目录..." />
                        </td>
			<td><div class="fun_tips">硬盘路径，如：E:/舞曲/&nbsp;如果是站内目录就填../../</div></td>
		</tr>
		<tr>
			<th>歌曲目录路径</th>
			<td>
				<input type="text" id="dance" name="dance" class="input length_3" value="">
                        </td>
			<td><div class="fun_tips">歌曲目录路径，如：/中文舞曲/&nbsp;</div></td>
		</tr>
		<tr>
			<th>是否扫描歌曲属性</th>
			<td>
				<label><input name="shux" type="radio" value="1" checked /><span>关闭</span></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<label><input name="shux" type="radio" value="2" /><span>开启</span></label>
                        </td>
			<td><div class="fun_tips">是否扫描歌曲属性，如：音质，大小，时长,开启后会消耗服务器资源的</div></td>
		</tr>
		<tr>
			<th>入库类型</th>
			<td>
				<input type="text" id="hz" name="hz" class="input length_3" value="mp3|wma|mp4|flv">
                        </td>
			<td><div class="fun_tips">歌曲入库类型，注意用“|”来阁开</div></td>
		</tr>
</div>
<div class="btn_wrap">
	<div class="btn_wrap_pd">
		<button type="submit" id="adddance" class="btn btn_submit mr10 J_ajax_submit_btn">提交扫描</button>
                <div class="tips_error" id="Msg"></div>
	</div>
</div>
</div>
</body>
</html>

