<?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]))
{
	$SERIESID = $_REQUEST['SID'];
	if ($SERIESID != "" && $SERIESID >= 0 && is_numeric($SERIESID))
	{
    	$query = "SELECT * FROM videos_series WHERE SID='".mysql_real_escape_string($SERIESID)."'";
    	$executequery = $conn->execute($query);
    	$seriesarray = $executequery->getarray();
		STemplate::assign('seriesarray',$seriesarray);
		
		if($_REQUEST[editseries]!="")
		{
			$name = htmlentities(strip_tags($_REQUEST['name']));
			$name = escape($name);
			$description = htmlentities(strip_tags($_REQUEST['description']));
			$description = escape($description);
			$seriesid = htmlentities(strip_tags($SERIESID));
			
			$photo = $_FILES['uploadseriesimage']['tmp_name'];
			
			if ($photo != "")
			{
				$photoinfo = getimagesize($photo);
			
				$thephotobg = "";
      		
      			if($photoinfo[2] == 1)
				{
        			$thephotobg .= ".gif";
				}
      			elseif($photoinfo[2] == 2)
				{
        			$thephotobg .= ".jpg";
				}
      			elseif($photoinfo[2] == 3)
				{
        			$thephotobg .= ".png";
				}
				else
				{
					$error = "$lang[634]";
				}
				$photoexists = true;
			}			
			
			if ($error == "")
			{
			
				if ($photoexists)
				{
				
					if (is_numeric($seriesid))
					{
						$thephotobg = $seriesid.$thephotobg;
					}
					$myvideoimgnew=$config['seriesdir']."/".$thephotobg;
					if(file_exists($myvideoimgnew))
					{
						unlink($myvideoimgnew);
					}
				
        			$myconvertimg = $_FILES['uploadseriesimage']['tmp_name'];
				
					//move_uploaded_file($myconvertimg, $myvideoimgnew);
					generatevideothumbs($myconvertimg,$myvideoimgnew,$config[max_thumb_width],$config[max_thumb_height]);
				
					if(file_exists($config['seriesdir']."/".$thephotobg))
					{
						$query = "UPDATE videos_series SET thumbnail='$thephotobg' WHERE SID='".mysql_real_escape_string($seriesid)."'";
						$conn->execute($query);
					}
					else
					{
						$error = "$lang[635]";
					}
				}
				
				$query="UPDATE videos_series SET name='".mysql_real_escape_string($name)."', description='".mysql_real_escape_string($description)."' WHERE SID='".mysql_real_escape_string($SERIESID)."'";
				$conn->execute($query);

				$message = "$lang[636] <a href=\"$thebaseurl/myseriesedit.php?SID=$SERIESID\">$lang[637]</a>";

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

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

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