<?php
require("../../class/connect.php");
include("../../class/db_sql.php");
include("../../class/config.php");
include("../../class/q_functions.php");
include("../../class/user.php");
include("../../class/class.php");
include("../../class/MemberLevel.php");
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
$ecmsreurl=1;
$id=(int)$_GET['id'];
$pathid=(int)$_GET['pathid'];
$classid=(int)$_GET['classid'];
/*
来源识别
if(!strstr($_SERVER['HTTP_REFERER'],$public_r[sitedown]."data/soft/".$softid.".html"))
{
	exit();
}
*/
if(!$classid||empty($class_r[$classid][tbname])||!$id)
{
	echo"<script>alert('此影片不存在');window.close();</script>";
	exit();
}
$query="select onlinepath,id,title,wplay from {$dbtbpre}ecms_".$class_r[$classid][tbname]." where id='$id' and classid='$classid'";
$r=$empire->fetch1($query);
if(!$r[id])
{
	echo"<script>alert('此影片不存在');window.close();</script>";
	exit();
}

//区分下载地址
$path_r=explode("\r\n",$r[onlinepath]);
$showdown_r=explode("::::::",$path_r[$pathid]);
//下载权限
$downgroup=$showdown_r[2];
if($downgroup)
{
	$user=islogin();
	//取得会员资料
	$u=$empire->fetch1("select * from ".$user_tablename." where ".$user_userid."='$user[userid]' and ".$user_rnd."='$user[rnd]' limit 1");
	if(empty($u[$user_userid]))
	{
		echo"<script>alert('同一帐号，只能一人在线');window.close();</script>";
        exit();
    }
	//下载次数限制
	if($level_r[$u[$user_group]][daydown])
	{
		$thetoday=date("Y-m-d");
		if($thetoday==$u[$user_todaydate])
		{
			if($u[$user_todaydown]>=$level_r[$u[$user_group]][daydown])
			{
				echo"<script>alert('您的下载与观看次数已超过系统限制(".$level_r[$u[$user_group]][daydown]." 次)!');window.close();</script>";
				exit();
			}
		}
	}
	if($level_r[$downgroup][level]>$level_r[$u[$user_group]][level])
			{
		    echo"<script>alert('您的会员级别不足(".$level_r[$downgroup][groupname].")，没有观看此影片的权限!');window.close();</script>";
            exit();
			}
	//点数是否足够
	if($showdown_r[3])
	{
		//---------是否有历史记录
			$bakr=$empire->fetch1("select id,truetime from {$dbtbpre}enewsdownrecord where classid='$classid' and id='$id' and pathid='$pathid' and userid='$user[userid]' and online=1 order by downid desc limit 1");
			if($bakr[id]&&(time()-$bakr[truetime]<=$public_r[redodown]*3600))
			{}
			else
			{
				//包月卡
				if($u[$user_userdate]-time()>0)
				{}
				//点数
				else
				{
			       if($showdown_r[3]>$u[$user_userfen])
			       {
					echo"<script>alert('您的点数不足 $showdown_r[3] 点，无法观看此影片');window.close();</script>";
					exit();
			       }
				}
			}
	}
}
db_close();
$empire=null;
//验证码
$pass=md5("wm_chief".$public_r[downpass].$user[userid]);
$op=GetOnlinePass();
$url="../../enews?enews=GetSofturl&classid=$classid&id=$id&pathid=$pathid&pass=".$pass."&p=".$user[userid].":::".$user[rnd]."&onlinetime=".$op[0]."&onlinepass=".$op[1];
$playerpass="wm_chief";
//FLASH
$flashtype=GetFiletype($showdown_r[1]);
if($flashtype==".swf")
{
	$url=$showdown_r[1];
	@include("flasher.php");
	exit();
}
//选择播放器
if(empty($r[wplay]))
{
	@include("realplayer.php");
}
else
{
	@include("mediaplayer.php");
}
?>