<?php
/*
'**************************************************************************************************
' 软件名称: 盘锦DJ舞曲网CMS Content Management PjRen.Net
' 版本编号: Version 2.5
' 盘锦舞曲: http://www.pj57.com
' 官方网站: http://www.pjren.net
' 小说网站: http://www.hx39.com
' 0427DJ网: http://www.0427dj.net
' 官方论坛: http://www.tianjiazhen.com
' 版权所有: 盘锦舞曲开发团队    盘锦人(QQ:814006710)
' 郑重声明:
'    1、任何个人或组织不得在未经授权的情况下删除、修改、拷贝本软件及其他副本上一切关于版权的信息；
'    2、盘锦网络事业部保留此软件的法律追究权利
'**************************************************************************************************
*/
include "../include/label.php";
include "../include/userset.php";
date_default_timezone_set('PRC');
if(isset($_COOKIE["s_name"])){
	$S_Name=$_COOKIE["s_name"];
}
else{
	$S_Name="";
}
if(isset($_COOKIE["s_id"])){
	$S_UID=$_COOKIE["s_id"];
}
else{
	$S_UID="";
}
$S_ID=SafeRequest("id","get","zr");
if(!IsNul($S_ID))  exit("参数错误！"); 
global $db;
	$sql="select * from s_video where S_ID=".$S_ID;
	$rowv=$db->getrow($sql);
	if($rowv){
			if(S_DjDown==0){
				recordvideo($S_Name,$S_ID,0);
			}else{
				if(($S_Name=="")||($S_UID=="")){
					exit("<script language=javascript>alert('出错了，请登陆后再下载！');location.href = 'index.php';</script>");
				}else{
					$sql="select * from s_users where S_Name='".$S_Name."'";
					$row=$db->getrow($sql);
					if($row){
							if($row["S_State"]==0){
								if($row["S_UseType"]==0){//点卡会员
										if($row["S_Coin"]>=$rowv["S_IsEnd"]){

											recordvideo($S_Name,$S_ID,$rowv["S_IsEnd"]);
										}else{

											exit("<script language=javascript>alert('您的余额不足，请充值！');location.href = 'index.php';</script>");
										}
								}else{//月卡会员
										$time1=$row["S_UseDate"];
										$time2=date('Y-m-d');
										$diff=(strtotime($time1)-strtotime($time2))/(60*60*24);
											if($diff>=0){
												recordvideo($S_Name,$S_ID,0);
														
											}else{
												exit("<script language=javascript>alert('您的帐号已到期，请充值！');location.href = 'index.php';</script>");												
											}
								}
							}else{
								exit("<script language=javascript>alert('对不起，您的账号被锁定！');location.href = 'index.php';</script>");
							}
					}else{

						exit("<script language=javascript>alert('对不起，请先登陆！');location.href = 'index.php';</script>");
					}
				}
			}
	}else{
		exit("<script language=javascript>alert('对不起，数据不存在！');location.href = '".S_SiteDomain."".S_SitePath."';</script>");
	}

function recordvideo($S_Name,$S_ID,$S_DisCount){
		global $db;
		$sql="Select S_ID,S_Name,S_Remark,S_Addpath,S_Direct,S_Author,S_Source,S_ClassID from s_video where S_ID=".$S_ID."";
		$row=$db->getrow($sql);
		$server=$db->getrow("select * from s_pathip where S_ID=".$row['S_Addpath']."");
		if($row){
		   $S_Url=$row['S_Remark'];
		   $S_Urla=substr($S_Url,2,7);
		   $S_Urlb=substr($S_Url,0,22);
		   $S_Urlc=substr($S_Url,0,3);
		   $db->query("update s_video set S_Downhits=S_Downhits+1 where S_ID=".$S_ID."");//增加下载次数
		   $dowmurl=$S_Url;
		   if($row['S_Addpath']==0){
		       $dowmurla=substr($dowmurl,0,4);
		       if($dowmurla=="http"){
		           $dowmurl=$dowmurl;
		       }else{
		           $dowmurl=S_SiteDomain.$dowmurl;
		       }
		   }else{
		           $dowmurl=$server['S_DownPath'].$dowmurl;
	           }
	        }
	if($S_Name!=""){
		$tishi="";
		$sql="select * from s_users where S_Name='".$S_Name."'";
		$result=$db->query($sql);
		$rowu=$db->fetch_array($result);
		$S_Coin=$rowu["S_Coin"] - $S_DisCount;
                //减去相应点数
		$cookies="down_$S_ID"; 
		if($_COOKIE[$cookies]=='yes'){ 
			        //保存下载记录
				$S_Name=$row['S_Name'];
				$S_User=$rowu['S_Name'];
				$S_Djid=$S_ID;
				$S_Classid=$row['S_ClassID'];
				$S_Addtime=date('Y-m-d H:i:s');
				global $db;
                                //判断是否已下载过
				$sqld="select * from s_down where S_User='".$S_User."' and S_Djid=$S_ID";
				if($rowd=$db->Getrow($sqld)){//有则更新下载时间
				   $sqlup2="update s_down set S_Addtime='".date('Y-m-d H:i:s')."' where S_User='".$S_User."' and S_Djid=$S_ID";
				   $db->query($sqlup2);
				   $sqlup3="update s_dt set S_Addtime='".date('Y-m-d H:i:s')."' where S_User='".$S_User."' and S_Djid=$S_ID";
				   $db->query($sqlup3);
				}else{//没有则入库
				   $sqlhya="insert into s_down (S_Name,S_Djid,S_Classid,S_User,S_Addtime) values ('".$S_Name."',".$S_Djid.",".$S_Classid.",'".$S_User."','".$S_Addtime."')";
				   if($db->query($sqlhya)){
				      //产生动态
				      $S_Djid=$S_Djid;
				      $S_Xid=2;
				      $S_Name=$S_Name;
				      $S_Classid=$S_Classid;
				      $S_User=$S_User;
				      $S_Addtime=date('Y-m-d H:i:s');
				      $sqldt="insert into s_dt (S_Name,S_Djid,S_Classid,S_User,S_Xid,S_Addtime) values ('".$S_Name."',".$S_Djid.",".$S_Classid.",'".$S_User."',".$S_Xid.",'".$S_Addtime."')";
				      $db->query($sqldt);
				    }
				}
		}else{
		     setcookie($cookies,'yes',time()+86400);
		          $sqlup="update s_users set S_Coin=".$S_Coin." where S_Name='".$S_Name."'";
		          $db->query($sqlup);
		}
	}
//DJ95资源
if($row['S_Source']=="dj95"){
include "../include/dj95_config.php";
  $Dj95_d32=MD5(Dj95_ym.Dj95_key.$S_ID);
  $Dj95_d8=substr($Dj95_d32,-8);
  $Dj95_d16=substr($Dj95_d32,-16);
  $Dj95_d1=substr($Dj95_d32,8,16);
  $DJ95_md5=$Dj95_d1.$Dj95_d8.$Dj95_d16;
  $dowmurl="http://www.95Dj.com:81/B.do?u=".$S_Url."&i=".Dj95_name."&id=".$S_ID."&n=".$S_Djname."&qq=".$DJ95_md5."&fwdid=".$row['S_Addpath']."&ac=down";
   echo "<script src=\"".$dowmurl."\"></script>";
?>
   <script>document.writeln("<a href='"+Dj95_Play_wma+"' target=\"Dj95Down\">下载高速推荐(极速)<\/a>")</script></br><font color=#ff0000>注意：如果遇到不能下载，请用右键目标另寸为!</font>
<?php
exit();
}
//官方资源
if($S_Urla=="chshcms"){
	header('Content-Type:application/force-download');
    header("Location:".$server['S_DownPath'].$S_Url);
	}
//飞速网盘资源
if($S_Urlb=="http://www.rayfile.com"){
	header('Content-Type:application/force-download');
    header("Location:".$server['S_DownPath'].$S_Url);
	}
//威客网盘资源
if($S_Urlc=="wk_"){$kimi=explode("_",$S_Url);$dowmurl=getvdisk(trim($kimi[1]));header("Location:$dowmurl");}
//本站资源
 if(S_Downmode==2){//判断下载类型
   		header('Content-Type:application/force-download');
    	header("Location:".$dowmurl);
   }elseif(S_Downmode==1){
   		header('Content-Type:application/force-download');
    	header("Location:".$dowmurl);
   }
}
?>
