<?php


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

if ($_SESSION[USERID] != "" && $_SESSION[USERID] >= 0 && is_numeric($_SESSION[USERID]))
{
	$VIDEOID = $_REQUEST['VIDEOID'];
	if ($VIDEOID != "" && $VIDEOID >= 0 && is_numeric($VIDEOID))
	{
    	$query = "SELECT * FROM videos WHERE VIDEOID='".mysql_real_escape_string($VIDEOID)."'";
    	$executequery = $conn->execute($query);
    	$videoarray = $executequery->getarray();
		STemplate::assign('videoarray',$videoarray);
		
		if($_REQUEST[editvideo]!="")
		{
			$title = htmlentities(strip_tags($_REQUEST['title']),ENT_QUOTES,'UTF-8');
			$title = escape($title);
			$description = htmlentities(strip_tags($_REQUEST['description']),ENT_QUOTES,'UTF-8');
			$description = escape($description);
			$tags = htmlentities(strip_tags($_REQUEST['tags']),ENT_QUOTES,'UTF-8');
			$tags = escape($tags);
			$category = htmlentities(strip_tags($_REQUEST['category']),ENT_QUOTES,'UTF-8');
			$category = escape($category);
			$public = htmlentities(strip_tags($_REQUEST['public']),ENT_QUOTES,'UTF-8');
			$public = escape($public);
			$allowcomments = htmlentities(strip_tags($_REQUEST['allowcomments']),ENT_QUOTES,'UTF-8');
			$allowcomments = escape($allowcomments);
			$allowratings = htmlentities(strip_tags($_REQUEST['allowratings']),ENT_QUOTES,'UTF-8');
			$allowratings = escape($allowratings);
			$allowembeds = htmlentities(strip_tags($_REQUEST['allowembeds']),ENT_QUOTES,'UTF-8');
			$allowembeds = escape($allowembeds);
			$allowdownloads = htmlentities(strip_tags($_REQUEST['allowdownloads']),ENT_QUOTES,'UTF-8');
			$allowdownloads = escape($allowdownloads);
			$mature = htmlentities(strip_tags($_REQUEST['mature']),ENT_QUOTES,'UTF-8');
			$mature = escape($mature);
			
			$addtosql = "";
			if ($category != "" && $category >= 0 && is_numeric($category))
			{
				$addtosql .= ", categories='".mysql_real_escape_string($category)."'";
			}
			if ($public != "" && $public >= 0 && is_numeric($public))
			{
				$addtosql .= ", public='".mysql_real_escape_string($public)."'";
				
				if ($public == "0")
				{
					$query = "DELETE FROM channels_videos WHERE VIDEOID='".mysql_real_escape_string($VIDEOID)."'";
      				$conn->Execute($query);
				}
			}
			if ($allowcomments != "" && $allowcomments >= 0 && is_numeric($allowcomments))
			{
				$addtosql .= ", allowcomments='".mysql_real_escape_string($allowcomments)."'";
			}
			if ($allowratings != "" && $allowratings >= 0 && is_numeric($allowratings))
			{
				$addtosql .= ", allowratings='".mysql_real_escape_string($allowratings)."'";
			}
			if ($allowembeds != "" && $allowembeds >= 0 && is_numeric($allowembeds))
			{
				$addtosql .= ", allowembeds='".mysql_real_escape_string($allowembeds)."'";
			}
			if ($allowdownloads != "" && $allowdownloads >= 0 && is_numeric($allowdownloads))
			{
				$addtosql .= ", allowdownloads='".mysql_real_escape_string($allowdownloads)."'";
			}
			if ($mature != "" && $mature >= 0 && is_numeric($mature))
			{
				$addtosql .= ", mature='".mysql_real_escape_string($mature)."'";
			}
			
			$VIDEOID = htmlentities(strip_tags($VIDEOID));			
			
			if ($error == "")
			{
				
				$query="UPDATE videos SET title='".mysql_real_escape_string($title)."', description='".mysql_real_escape_string($description)."', tags='".mysql_real_escape_string($tags)."' $addtosql WHERE VIDEOID='".mysql_real_escape_string($VIDEOID)."'";
				$conn->execute($query);

				$message = "$lang[648] <a href=\"$thebaseurl/myvideosedit.php?VIDEOID=$VIDEOID\">$lang[649]</a>";

			}
		}
		$templateselect = "myvideosedit.tpl";
	}
	else
	{
		$error = "$lang[650]";
		$templateselect = "playvideoerror.tpl";
	}
}
else
{
	header("Location:$config[baseurl]/login.php");exit;
}

STemplate::assign('pagetitle',"$lang[318]");

//TEMPLATES BEGIN
STemplate::assign('error',$error);
STemplate::assign('message',$message);
STemplate::display('header.tpl');
STemplate::display($templateselect);
STemplate::display('footer.tpl');
//TEMPLATES END
?>