<?php


session_start();
include("include/config.php");
include("include/functions/import.php");

$VIDEOID = $_REQUEST['VIDEOID'];
if (is_numeric($VIDEOID))
{
	$query="SELECT allowdownloads,video_name FROM videos WHERE public='1' AND active='1' AND VIDEOID='".mysql_real_escape_string($VIDEOID)."' limit 1";
	$executequery = $conn->Execute($query);
	$allowdownloads = $executequery->fields[allowdownloads];
	$video_name = $executequery->fields[video_name];
}
else
{
	$error = "$lang[541]";
}

if ($allowdownloads == "1")
{

	if ($config['who_can_download'] == "1")
	{
		if ($_SESSION[USERID] != "" && $_SESSION[USERID] >= 0 && is_numeric($_SESSION[USERID]))
		{
			header("location:$config[videourl]/$video_name");
			exit;
		}
		else
		{
			header("location:$config[baseurl]/login.php");
			exit;
		}
	}
	else
	{
		header("location:$config[videourl]/$video_name");
		exit;
	}

}
else
{
	$error = "$lang[542]";
}

if ($error != "")
{
	STemplate::assign('error',$error);
	$pagetitle = "$lang[219]";
	STemplate::assign('pagetitle',$pagetitle);

	//TEMPLATES BEGIN
	STemplate::display('header.tpl');
	STemplate::display('empty.tpl');
	STemplate::display('footer.tpl');
	//TEMPLATES END
}
?>