<?php

/*

'**************************************************************************************************

' 软件名称: 黑色幻想舞曲管理系统CMS2.0

' 版本编号: hshxsdj 2.0

' 官方网站: http://www..hshxs.com

' 官方论坛：http://bbs.hshxs.com

' 版权所有: 黑色幻想开发团队    噬己翼(QQ:532917920)

' 郑重声明:

'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；

'    2、黑色幻想网络事业部保留此软件的法律追究权利

'**************************************************************************************************

*/

include "../include/conn.php";

include "../include/function.php";

include "admin_version.php";

include "admin_loginstate.php";

include "../include/userset.php";

include "../include/class_ftp.php";

@header("Cache-control: private"); 

@header("Content-type: text/html;charset=gb2312");

$playadd=playadd(1);

@set_time_limit(0);

@error_reporting(0);

$ac=SafeRequest("ac","get");

$activepath=SafeRequest("activepath","auto");

$ftp_server=s_ftpip;

$ftp_user_name=s_ftpuid;

$ftp_user_pass=s_ftppwd;

$ftp_dk=s_ftpdk;

$ftp_path="/".$activepath."/";

?>

<link  href="images/style.css" rel="stylesheet" type="text/css" />

<link type="text/css" href="images/alerts.css" rel="stylesheet" media="screen">

<script type="text/javascript" language="javascript">var tentpath='<?php echo S_SitePath?>';</script>

<script language="javascript" src="js/jquery.js"></script>

<script language="javascript" src="js/alerts.js"></script>

<script type="text/javascript" language="javascript">

function SelectTemplets(fname){

   if(document.all){

     var posLeft = window.event.clientY-100;

     var posTop = window.event.clientX-400;

   }

   else{

     var posLeft = 100;

     var posTop = 100;

   }

   window.open("admin_ftp.php?ac=ftp&activepath="+fname, "popmoldWin", "scrollbars=yes,resizable=yes,statebar=no,width=600,height=400,left="+posLeft+", top="+posTop);

}

</script>

</head>

<body>

<?php

SystemPer(2);

if($ac=="ftpend"){

$S_ftpip = SafeRequest("ftpip","post");

$S_ftpuid = SafeRequest("ftpuid","post");

$S_ftppwd=SafeRequest("ftppwd","post");

$S_ftpdk = SafeRequest("ftpdk","post");

if(!$S_ftpip){exit("<script language=javascript>alert('请填写FTP服务器！');window.location.href='javascript:history.go(-1);';</script>");}

if(!$S_ftpuid){exit("<script language=javascript>alert('请填写FTP用户名！');window.location.href='javascript:history.go(-1);';</script>");}

if(!$S_ftppwd){exit("<script language=javascript>alert('请填写FTP密码！');window.location.href='javascript:history.go(-1);';</script>");}

if(!$S_ftpdk){exit("<script language=javascript>alert('请填写FTP端口！');window.location.href='javascript:history.go(-1);';</script>");}

	$strs="<?php"."\r\n";

	$strs=$strs."define(\"s_ftpip\",\"".$S_ftpip."\");\r\n";

	$strs=$strs."define(\"s_ftpuid\",\"".$S_ftpuid."\");\r\n";

	$strs=$strs."define(\"s_ftppwd\",\"".$S_ftppwd."\");\r\n";

	$strs=$strs."define(\"s_ftpdk\",\"".$S_ftpdk."\");\r\n";

	$strs=$strs."?>";

	//写文件

	$ifile = new iFile('../include/class_ftp.php','w');

	$ifile->WriteFile($strs,3); 

die("<script language=javascript>alert('保存成功！');window.location.href='javascript:history.go(-1);';</script>");

}elseif($ac=="ftp"){

?>

<style>

.linerow {border-bottom: 1px solid #CBD8AC;}

</style>

</head>

<body leftmargin='0' topmargin='0'>

<table width='100%' border='0' cellpadding='0' cellspacing='1' class="tb_style" align="center">

   <tr bgcolor='#FFFFFF'>

      <td colspan='3'>

<!-- 开始文件列表  -->

           <table width='100%' border='0' cellspacing='0' cellpadding='2'>

                <tr>

			<td colspan='2' class='linerow'>&nbsp;<img src=images/dir2.gif border=0 width=16 height=16 align=absmiddle>&nbsp;当前目录: <?php echo $activepath;?></td>

			<td class='linerow'>&nbsp;</td>



                </tr>

                <tr bgcolor="#CCCCCC">

			<td width="10%" align="center" class='td_border'><strong>选择</strong></td>

			<td width="70%" class='td_border'><strong>目录名称</strong></td>

			<td width="20%" class='td_border'>大小</td>

                </tr>

<?php

$conn_id = ftp_connect($ftp_server,$ftp_dk) or die("<tr><td>FTP 连接失败 !</td></tr>");

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if ((!$conn_id) || (!$login_result)) {

    die("<tr><td>FTP用户名或密码错误 !</td></tr>");

}

$contents = ftp_nlist($conn_id, $ftp_path);

for($i=0;$i<count($contents);$i++){

        $sys=pathinfo($contents[$i]);//获取文件名后缀

	if($sys['extension'] =="mp3" || $sys['extension'] =="mP3" || $sys['extension'] =="Mp3" || $sys['extension'] =="MP3" || $sys['extension'] =="wma" || $sys['extension'] =="WMA" || $sys['extension'] =="wMA" || $sys['extension'] =="WmA" || $sys['extension'] =="WMa" || $sys['extension'] =="Wma" || $sys['extension'] =="wMa" || $sys['extension'] =="wmA")//判断是否是音乐文件

	{

echo "<tr>";

echo "<td align='center' class='linerow' bgcolor='#F9FBF0'><input type='checkbox' value='0' class='checkbox' disabled /></td>";

echo "<td class='linerow' bgcolor='#F9FBF0'>".str_replace( $ftp_path, "", $contents[$i])."</td>";

echo "<td class='linerow' bgcolor='#F9FBF0'>".formatsize(ftp_size($conn_id, $ftp_path.str_replace( '$activepath', "", $contents[$i])))."</td>";

echo "</tr>";

        }

}

?>

           </table>

      </td>

   </tr>

</table>

<?php

}elseif($ac=="go"){

echo "</br>";

$ftp_path=SafeRequest("path","post"); 

$ftp_path="/".$ftp_path."/";

if(!$ftp_path){exit("<script language=javascript>alert('请填写扫描路径！');window.location.href='javascript:history.go(-1);';</script>");} 

$conn_id = ftp_connect($ftp_server,$ftp_dk) or die("FTP 连接失败 !");

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if ((!$conn_id) || (!$login_result)) {

    die("FTP用户名或密码错误 !");

}

$contents = ftp_nlist($conn_id, $ftp_path);

for($i=0;$i<count($contents);$i++){

        $sys=pathinfo($contents[$i]);//获取文件名后缀

	if($sys['extension'] =="mp3" || $sys['extension'] =="mP3" || $sys['extension'] =="Mp3" || $sys['extension'] =="MP3" || $sys['extension'] =="wma" || $sys['extension'] =="WMA" || $sys['extension'] =="wMA" || $sys['extension'] =="WmA" || $sys['extension'] =="WMa" || $sys['extension'] =="Wma" || $sys['extension'] =="wMa" || $sys['extension'] =="wmA")//判断是否是音乐文件

	{

		$S_Color = SafeRequest("S_Color","post");

		$S_ClassID = SafeRequest("S_ClassID","post");

		$S_Topic = SafeRequest("S_Topic","post");

		$S_Author = SafeRequest("S_Author","post");

		$S_Reco = SafeRequest("S_Reco","post");

		$S_Source = SafeRequest("S_Source","post");

		$S_Server= SafeRequest("S_Server","post");

		$S_Year = SafeRequest("S_Year","post");

		$S_Area = SafeRequest("S_Area","post");

		$S_Language = SafeRequest("S_Language","post");

		$S_AddTime =date('Y-m-d H:i:s');

		$S_Direct = SafeRequest("S_Direct","post");

		$S_IsEnd = SafeRequest("S_xzds","post");

		$S_Templay=SafeRequest("S_Templay","post");

		$S_playform = SafeRequest("S_playform","post");

		//判断 

		if(!S_Templay){$S_Templay="play.html";}

		if(!IsNul($S_Year)){$S_Year="未知";}

		$name=explode(".".$sys['extension']."",str_replace( $ftp_path, "", $contents[$i]));

		$name=$name[0];

		$vdata=$ftp_path.str_replace( $ftp_path, "", $contents[$i]);

		$down=$vdata;

		$s_addtime=date("Y-m-d H:i:s");

		$S_Content=$name;

		$s_addtime=date("Y-m-d H:i:s");

		if($S_IsEnd==""){$S_IsEnd=0;}

                $S_Dx=formatsize(ftp_size($conn_id, $ftp_path.$contents[$i]));

               //判断数据是否存在

                global $db;

                       $s_ids= $db->Getone("select s_id from s_video where S_name='".$name."'");

                             if($s_ids){

                                    echo "&nbsp;&nbsp;<font color=#0000ff >".$name."</font>,<font color=#FF0000 >该舞曲已经存在-->>>入库失败!</br></font>";

                             }else{

                                 //判断数据是否完整

                                       if(!IsNul($name) or !IsNul($S_playform) or !IsNul($vdata)){

                                             echo "&nbsp;&nbsp;<font color=#0000ff >".$name."</font>,<font color=#FF0000 >该舞曲地址不对-->>>入库失败!</br></font>";

                                       }else{

                                       //执行入库处理

                                            $sql3="Insert s_video (S_Name,S_Color,S_Remark,S_ClassID,S_Topic,S_Pic,S_Author,S_Content,S_Reco,S_IsEnd,S_Source,S_Vdata,S_Year,S_Area,S_Language,S_Direct,S_AddTime,S_PlayTime,S_AddPath,S_Templay,S_Dx) values ('".$name."','".$S_Color."','".$down."',".$S_ClassID.",".$S_Topic.",'0','".$S_Author."','".$S_ConTent."',".$S_Reco.",".S_IsEnd.",'".$S_playform."','".$vdata."','".$S_Year."','".$S_Area."','".$S_Language."','".$S_Direct."','".$S_AddTime."','".$S_AddTime."','".$S_Server."','".$S_Templay."','".$S_Dx."')";

                                            if($db->query($sql3)){

                                               echo "&nbsp;歌曲：&nbsp;<font color=#FF0000 >".$name."</font>-->>><font color=#0000ff >扫描入库成功!</font></br>";

                                            }else{

                                               echo "&nbsp;歌曲：&nbsp;<font color=#0000FF >".$name."</font>-->>><font color=#FF0000 >扫描入库失败!</font></br>";

                                            }

                                       }

                            }

        }

}

die("</br>&nbsp;&nbsp;<font color=#0000ff>恭喜您,数据全部扫描入库完成!");

}else{

?>

<div class="r_main">

	<div class="r_content">

		<div class="r_content_1">

<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">	

							<form action="?ac=ftpend" method="post"  name="form" >

							  <tr>

                                <td colspan="3" class="td_title">&nbsp;远程FTP舞曲扫描入库&nbsp;&nbsp;<font color=red>《如遇到扫描时(显示FTP连接失败),请尝试关闭服务器安全软件，比如D盾，安全狗等在试!》</font></td>

                              </tr>

							  <tr>

							    <td  height="30" class="td_border">&nbsp;FTP服务器IP：</td>

							    <td class="td_border"><input name="ftpip" type="text" id="ftpip" value="<?php echo s_ftpip;?>" size="40" />

							      <font color="#FF0000">＊</font>&nbsp;端口：<input name="ftpdk" type="text" id="ftpdk" value="<?php echo s_ftpdk;?>" size="20" /> <font color="#FF0000">＊FTP端口，默认是21</font></td>

							  </tr>

                              				  <tr>

							    <td  height="30" class="td_border">&nbsp;FTP用户名：</td>

							    <td class="td_border"><input name="ftpuid" type="text" id="ftpuid" value="<?php echo s_ftpuid;?>" size="20" />

							      &nbsp;FTP密码：<input name="ftppwd" type="password" id="ftppwd" value="<?php echo s_ftppwd;?>" size="20" />

							      &nbsp;&nbsp;<input type="submit" name="Submit" value="保存FTP信息"class="rb1"/></td>

							  </tr>

							  <tr></form>

</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0"  class="tb_style">

							<form action="?ac=go" method="post"  name="form1" >

                              				  <tr>

							    <td  height="30" class="td_border">&nbsp;扫描路径：</td>

							    <td class="td_border"><input name="path" type="text" id="path" value="" size="50" />

							      &nbsp;<input type="button" value="填写路径后远程浏览..." style="width:120px"  onClick="SelectTemplets(''+path.value+'');" class="rb1" />

							      <font color="#FF0000">＊&nbsp;注意：路径前后都不要带“/”</font></td>

							  </tr>

							  <tr>

								

								<td width="11%" height="30" class="td_border">&nbsp;舞曲歌手：</td>

							    <td height="30" class="td_border"><input name="S_Author" type="text" id="S_Author" value="本站原创" size="20" onFocus="this.style.borderColor='#F93'" onBlur="this.style.borderColor='#CCC'" />

<select onChange='S_Author.value=this.value;'>

                                                <option value=''>选择歌手</option>

                                                <option value='网络转摘'>网络转摘</option>

                                                <option value='本站原创'>本站原创</option>

                                                </select><font color="#FF0000">＊</font>

                                  颜色：

<select name="S_Color" >

  <option  value=""></option>

  <option style="background-color:#00FF00;color: #00FF00" value="#00FF00">绿色</option>

  <option style="background-color:#0000CC;color: #0000CC" value="#0000CC">深蓝</option>

  <option style="background-color:#FFFF00;color: #FFFF00" value="#FFFF00">黄色</option>

  <option style="background-color:#FF33CC;color: #FF33CC" value="#FF33CC">粉红</option>

  <option style="background-color:#FF0000;color: #FF0000" value="#FF0000">红色</option>

  <option style="background-color:#660099;color: #660099" value="#660099">紫色</option>

  <option style="background-color:#FFFFFF;color: #FFFFFF" value="">无色</option>									

</select>

&nbsp;&nbsp;舞曲分类：

<select name="S_ClassID" id="S_ClassID">

              <?php

              	$sqlclass="select * from s_class where S_SystemID=1 ";

				$results=$db->query($sqlclass);

				if($results){

					while ($row3=$db->fetch_array($results)){

							echo "<option value='".$row3['S_ID']."' >".$row3['S_Name']."</option>";	

						

						}

					}

			  ?>	 

</select>

<font color="#FF0000">＊</font><label id="SClassID"></label></td>

							  </tr>

							  <tr>

							    <td width="11%" height="30" class="td_border">&nbsp;推荐星级：</td>

						        <td height="30" class="td_border">

<select name="S_Reco" id="S_Reco" style=" color:#FF0000; " >

                                  <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>&nbsp;&nbsp;&nbsp;下载点数：&nbsp;<input id="S_xzds" name="S_xzds" size="10" value="0"></td>

							  </tr>

							  <tr>

							    <td height="30" class="td_border">&nbsp;所属会员：</td>

							    <td height="30" class="td_border">

<input name="S_Direct" type="text" id="S_Direct" value="admin" size="30" onFocus="this.style.borderColor='#F93'" onBlur="this.style.borderColor='#CCC'" />

<select onChange='S_Direct.value=this.value;'>

                                                <option value='admin'>选择会员</option>

              <?php

              	$sqluser="select * from s_users where S_State=0 ";

				$results=$db->query($sqluser);

				if($results){

					while ($rowu=$db->fetch_array($results)){

						if($direct=="".$rowu['S_Name'].""){

							echo "<option value='".$rowu['S_Name']."' selected='selected'>".$rowu['S_Name']."</option>";

							}

						else{

							echo "<option value='".$rowu['S_Name']."' >".$rowu['S_Name']."</option>";

							}	

						

						}

					}

			  ?>	



                                                </select><font color="#FF0000">&nbsp;＊请选择会员，您也可以输入会员名称如：admin</font>

</td>

						      </tr>

						

							  <tr>

								

								<td width="11%" height="30" class="td_border">&nbsp;所属地区：</td>

							    <td height="30" class="td_border"><select name="S_Area" id="S_Area" >

                                <?php

                                if($area!=""){

									echo "<option value=$area>$area</option>";

									}

								?>

                                  	<option value="未知">选择地区</option>

                <?php

              	$sqlclass="select * from s_area ";

				$results=$db->query($sqlclass);

				if($results){

					while ($row3=$db->fetch_array($results)){

							echo "<option value='".$row3['S_AreaName']."' >".$row3['S_AreaName']."</option>";	

						

						}

					}

			  ?>

                                </select>

&nbsp;所属语言：

<select name="S_Language" id="S_Language" >

	<?php

    if($lan!=""){

        echo "<option value=$lan>$lan</option>";

        }

    ?>

  <option value="未知">选择语言</option>

                <?php

              	$sqlclass="select * from s_area ";

				$results=$db->query($sqlclass);

				if($results){

					while ($row3=$db->fetch_array($results)){

							echo "<option value='".$row3['S_Language']."' >".$row3['S_Language']."</option>";	

					

						}

					}

			  ?>

    </select>

&nbsp;发行年月：<input id="S_Year" name="S_Year" size="8" value="2011">&nbsp;播放页面风格模板：<input id="S_Templay" name="S_Templay" size="10" value="play.html">                                

                                                            <font color="#FF0000">＊可以利用这个功能支持所有播放器</font></td>

							  </tr>

							  

							  <tr>

							    <td width="11%" height="30" class="td_border">&nbsp;所属专题：</td>

						        <td height="30" class="td_border">

              <select name="S_Topic" id="S_Topic">

              <option value="0">选择专题</option>

              <?php

              	$sqlclass="select * from s_topic where S_SystemID=1 ";

				$results=$db->query($sqlclass);

				if($results){

					while ($row3=$db->fetch_array($results)){

							echo "<option value='".$row3['S_ID']."' >".$row3['S_Name']."</option>";	

					

						}

					}

			  

			  ?>

               </select>&nbsp;播放来源：

<select name="S_playform" id="S_playform">

                                              

                                               <?php echo playselect($playadd,"");?>

                                               </select> <font color="#FF0000">＊</font> 

                                                            &nbsp;服务器组:

                                                                                                            <select name="S_Server" id="S_Server">

                                                <option value="0" style="color:#FF0000;">不设置</option>

              <?php

              	$sqlfwq="select * from s_pathip  ";

				$results=$db->query($sqlfwq);

				if($results){

					while ($rowf=$db->fetch_array($results)){



							echo "<option value='".$rowf['S_ID']."' >".$rowf['S_Name']."</option>";

	

						

						}

					}

			  ?>

                                                </select>                        

                                                             </td>

							  </tr>

							  <tr>

								

								<td height="40" colspan="2" align="center" class="td_border"> &nbsp;

								  <input type="submit" name="Submit" value="开始扫描"class="rb1"  id="addvideo"/>

								  &nbsp;&nbsp; </td>

							  </tr>

							</form>  

					  </table>

                      		</div>

	</div>

</div>

<?php 

}

include "admin_bottom.php"; 

function formatsize($size) {

	$prec=3;

	$size = round(abs($size));

	$units = array(0=>" B ", 1=>" KB", 2=>" MB", 3=>" GB", 4=>" TB");

	if ($size==0) return str_repeat(" ", $prec)."0$units[0]";

	$unit = min(4, floor(log($size)/log(2)/10));

	$size = $size * pow(2, -10*$unit);

	$digi = $prec - 1 - floor(log($size)/log(10));

	$size = round($size * pow(10, $digi)) * pow(10, -$digi);

	return $size.$units[$unit];

}

?>

</body>

</html>