<?php


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

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

// Verify valid video
if (is_numeric($_REQUEST[key]))
{
	$videoid = $_REQUEST[key];
	STemplate::assign('videoid',$videoid);
}
else
{
	$error = "$lang[568]";
}

if ($error == "")
{
	if (does_video_exist($videoid) && private_video_access_check($videoid,$_SESSION[USERID]))
	{
		$query = "SELECT * FROM videos WHERE VIDEOID='".mysql_real_escape_string($videoid)."'";
       	$executequery = $conn->execute($query);
       	$videoarray = $executequery->getarray();
		STemplate::assign('videoarray',$videoarray);
		$videouserid = $videoarray[0][USERID];
		
		STemplate::assign('pagetitle',$videoarray[0][title]." FullScreen Video");
		
		$ismaturevideo = $videoarray[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)
		{
			$USERID = $videoarray[0][USERID];
			STemplate::assign('USERID',$USERID);
			$VIDEOID = $videoarray[0][VIDEOID];
			STemplate::assign('VIDEOID',$VIDEOID);
		
			update_viewcount_video($VIDEOID);
			update_last_viewed_video($VIDEOID);
			update_your_videos_viewed($USERID);
			if (session_verification())
			{
				update_videos_you_viewed($_SESSION[USERID]);
			}
			$query2="SELECT value FROM config WHERE setting='max_comments'";
			$executequery2=$conn->execute($query2);
			$max_comments = $executequery2->fields[value];
			STemplate::assign('max_comments',$max_comments);
    		$query = "SELECT * FROM videos_comments WHERE VIDEOID='$VIDEOID' ORDER BY CID desc limit $max_comments";
    		$executequery = $conn->execute($query);
    		$showcomments =  $executequery->getarray();
			STemplate::assign('showcomments',$showcomments);
			$showtheme = "fullscreen.tpl";
		}
		else
		{
			$showtheme = "playvideoverifymature.tpl";
		}
	}	
	else if (!private_video_access_check($videoid,$_SESSION[USERID]))
	{
		$query = "SELECT USERID FROM videos WHERE VIDEOID='".mysql_real_escape_string($videoid)."'";
       	$executequery = $conn->execute($query);
       	$theowneruserid = $executequery->fields[USERID];
		$query = "SELECT username FROM members WHERE USERID='".mysql_real_escape_string($theowneruserid)."'";
       	$executequery = $conn->execute($query);
       	$theownerusername = $executequery->fields[username];
		
		$error = "$lang[569] <a href='".$thebaseurl."/members/profile/".$theowneruserid."/".$theownerusername."'>".$theownerusername."</a>.";
	}
	else
	{
		$error = "$lang[570]";
	}
}


//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
?>