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

if(isset($_COOKIE["cs_name"])){
	$cscms_name=$_COOKIE["cs_name"];
}else{
	exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
}

$id=CS_Request("id");
if(empty($id)) exit(Msg_Error('参数错误!','window.close();'));
$Arr=explode(',',$id);

$row=$db->getrow("select * from ".Getdbname('user')." where CS_Name='".$cscms_name."'");

if($row['CS_Vip']==0) exit ("<script>alert('系统检测到您不是VIP会员！只有VIP会员才能使用批量下载！');window.location='space.php?ac=pay&op=vip';</script>");

global $db;
$S_Downall="";
for($i=0;$i<count($Arr);$i++){
       $sql="Select * from ".Getdbname('dance')." where CS_ID=".$Arr[$i];
       $row=$db->getrow($sql);
       $server=$db->getrow("select * from ".Getdbname('fwqip')." where CS_ID=".$row['CS_FID']."");
             $S_Name=$row['CS_Name'];
             $downurl=$row['CS_DownUrl1'];
             if(substr($downurl,0,5)=="csdj_"){
                   $str=explode("_",$downurl);
                   $downurl="http://csdj.so/d/?".substr($str[2],0,-4);
             }elseif(substr($downurl,0,3)=="wk_"){
                   $str=explode("_",$downurl);
                   $downurl=getvdisk(substr($str[1],0,-4));
             }elseif(substr($downurl,0,22)=="http://www.rayfile.com"){
                   $downurl=$downurl;
             }else{
                   $downurl=$server['CS_Downip'].$downurl;
             }
               $S_Url=$downurl;
       $S_Downall=$S_Downall.$S_Name."$$$".$S_Url."###";
            //写入下载记录
		//php获取ip的算法
		$CS_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
		$CS_IP = ($CS_IP) ? $CS_IP : $_SERVER["REMOTE_ADDR"]; 
                  //判断是否已下载过
		  $sqld="select * from ".Getdbname('down')." where CS_User='".$_COOKIE["cs_name"]."' and CS_DID=$Arr[$i]";
		  if($rowd=$db->Getrow($sqld)){//有则更新下载时间
			$db->query("update ".Getdbname('down')." set CS_AddTime='".date('Y-m-d H:i:s')."' where CS_User='".$_COOKIE["cs_name"]."' and CS_DID=$Arr[$i]");
			$db->query("update ".Getdbname('dt')." set CS_Addtime='".date('Y-m-d H:i:s')."' where CS_User='".$_COOKIE["cs_name"]."' and CS_DID=$Arr[$i]");
		  }else{//没有则入库
			$sqlhya="insert into ".Getdbname('down')." (CS_Name,CS_Cion,CS_DID,CS_CID,CS_Ip,CS_User,CS_AddTime) values ('".$S_Name."','".$cion."',".$Arr[$i].",".$row['CS_CID'].",'".$CS_IP."','".$_COOKIE["cs_name"]."','".date('Y-m-d H:i:s')."')";
			if($db->query($sqlhya)){
				$sqldt="insert into ".Getdbname('dt')." (CS_Title,CS_DID,CS_CID,CS_User,CS_AddTime) values ('".$S_Name."',".$Arr[$i].",6,'".$_COOKIE["cs_name"]."','".date('Y-m-d H:i:s')."')";
				$db->query($sqldt);
			}
		  }
         //增加下载次数
         $db->query("update ".Getdbname('dance')." set CS_Xhits=CS_Xhits+1 where CS_ID=".$Arr[$i]."");
}
       $S_Downall=$S_Downall.']';
       $S_Downall=CS_ReplaceStr($S_Downall,"###]","");
?>
<TITLE> 在线批量下载舞曲  <?php echo CS_WebName?></TITLE>
      <dl>
      <dt>下载地址</dt>
      <dd> 
        <script src="js/xunlei_3.js"></script> 
        <script>var GvodUrls = "<?php echo $S_Downall?>";</script> 
        <script src="js/check.js"></script> 
         <script type="text/javascript" src="js/down.js"></script>
         <script>var j=0;for(var i=0;i<GvodUrlLen;i++){j++;Downname = GvodUrlArray[i].split("$$$");document.write('<dl><input type="checkbox" class="CopyAddr"  value="'+Downname[1]+'" name="CopyAddr1" /> <A oncontextmenu=ThunderNetwork_SetHref_b(this) onclick="return xunbotask(this)" href="javascript:void(0)" thunderResTitle="" thunderType="" thunderPid="0" thunderHref="'+ThunderEncode(Downname[1])+'">'+Downname[0]+'</A>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="http://lixian.vip.xunlei.com/lixian_login.html?referfrom=union&ucid=0&furl='+encodeURIComponent(ThunderEncode(Downname[1])) +'" target=_blank>离线下载</a></dl>');}</script>
        <dl>
          <input id="allcheck1" onclick="CheckAll(1)" type="checkbox"  name="checkall" />
          <label for="checkall">全选</label>
          <input name="button" type="button" onclick="CopyToClip(1)" value="复制链接" />
          <input name="button" type="button" onclick="thunderBatchTask(1)" value="批量下载" />
        </dl>
      </dd>
    </dl>
