<?php


session_start();
include("include/config.php");
include("include/functions/import.php");
$thebaseurl = $config['baseurl'];

$mainmenu = "2";
STemplate::assign('mainmenu',$mainmenu);

if (is_numeric($_REQUEST[seriesid]))
{
	$seriesid = $_REQUEST[seriesid];
	STemplate::assign('seriesid',$seriesid);
}
else
{
	$error = "$lang[666]";
}

if ($error == "")
{
	if (does_series_exist($seriesid))
	{
		$query = "SELECT * FROM videos_series WHERE SID='".mysql_real_escape_string($seriesid)."'";
       	$executequery = $conn->execute($query);
       	$seriesarray = $executequery->getarray();
		STemplate::assign('seriesarray',$seriesarray);
		
		STemplate::assign('pagetitle',$seriesarray[0][name]." $lang[258]");
		
		// Last Video In Series Begin
		$query2 = "SELECT * FROM videos WHERE SID='".mysql_real_escape_string($seriesid)."' order by VIDEOID desc limit 1";
       	$executequery2 = $conn->execute($query2);
       	$newestvideo = $executequery2->getarray();
		STemplate::assign('newestvideo',$newestvideo);
		// Last Video In Series End
		
		// Other Videos In Series Begin
		$query3 = "SELECT * FROM videos WHERE SID='".mysql_real_escape_string($seriesid)."' order by VIDEOID asc";
       	$executequery3 = $conn->execute($query3);
       	$seriesvideos = $executequery3->getrows();
		STemplate::assign('seriesvideos',$seriesvideos);
		// Other Videos In Series End
		
		// Series Subscribers Begin
		$query = "select * from videos_series_subscribers where SID='".mysql_real_escape_string($seriesid)."' order by VSID desc"; 
		$results = $conn->execute($query);
		$listseriessubscribers = $results->getrows();
		STemplate::assign('listseriessubscribers',$listseriessubscribers);
		$listseriessubscriberscount = count($listseriessubscribers);
		STemplate::assign('listseriessubscriberscount',$listseriessubscriberscount);
		// Series Subscribers End
		
		$ismaturevideo = $newestvideo[0][mature];
		if ($ismaturevideo == "1")
		{
			if ($_SESSION[USERID] != "" && $_SESSION[USERID] >= 0 && is_numeric($_SESSION[USERID]))
			{
				if ($_SESSION[FAMILYFILTER] == "0")
				{
					$ismemberauthorized = true;	
				}
				else
				{
					$ismemberauthorized = false;
				}
			}
			else
			{
				$ismemberauthorized = false;	
			}
		}
		else
		{
			$ismemberauthorized = true;	
		}

		//if ($ismemberauthorized)
		if ($error == "")
		{
			$USERID = $seriesarray[0][USERID];
			STemplate::assign('USERID',$USERID);
			$SID = $seriesarray[0][SID];
			STemplate::assign('SID',$SID);

			$showtheme = "seriesdetails.tpl";
		}
	}	
	else
	{
		$error = "$lang[667]";
	}
}


//TEMPLATES BEGIN
STemplate::assign('error',$error);
STemplate::assign('message',$message);

STemplate::display('header.tpl');
if ($error == "")
{
	STemplate::display($showtheme);
}
else
{
	STemplate::display('playvideoerror.tpl');
}
STemplate::display('footer.tpl');
//TEMPLATES END
?>