<?php


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

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

if ($_SESSION[USERID] != "" && $_SESSION[USERID] >= 0 && is_numeric($_SESSION[USERID]))
{
	
	// Get Max Width and Height Begin
		$query="SELECT value FROM config WHERE setting='max_thumb_width'";
		$executequery=$conn->execute($query);
		$max_thumb_width = $executequery->fields[value];
		STemplate::assign('max_thumb_width',$max_thumb_width);
		$query="SELECT value FROM config WHERE setting='max_thumb_height'";
		$executequery=$conn->execute($query);
		$max_thumb_height = $executequery->fields[value];
		STemplate::assign('max_thumb_height',$max_thumb_height);
	// Get Max Width and Height End
	
	
	if($_REQUEST[createseries]!="")
	{
		$uploadedimage = $_FILES['uploadseriesimage']['tmp_name'];
		
		if ($_REQUEST[seriesname] == "")
		{
			$error = "$lang[535]";
		}
		elseif ($_REQUEST[seriesdescription] == "")
		{
			$error = "$lang[536]";
		}
    	elseif($uploadedimage == "")
		{
			$error = "$lang[537]";
		}
		elseif ($error == "")
    	{
			$theimageinfo = getimagesize($uploadedimage);

			
			if ($error == "")
			{
				$seriesname = htmlentities(strip_tags($_REQUEST[seriesname]));
				$seriesdescription = htmlentities(strip_tags($_REQUEST[seriesdescription]));
			
				$query = "INSERT INTO videos_series SET USERID='".mysql_real_escape_string($_SESSION[USERID])."', name='".mysql_real_escape_string($seriesname)."', description='".mysql_real_escape_string($seriesdescription)."', date_created='".date("Y-m-d")."', time_created='".time()."'";
				$conn->execute($query);
    			$seriesid = mysql_insert_id();
			
				if ($seriesid == "" || $seriesid <= 0 || !is_numeric($seriesid))
				{
        			$error = "$lang[538]";
				}
			
      			$theseries = $seriesid;
      		
      			if($theimageinfo[2] == 1)
				{
        			$theseries .= ".gif";
				}
      			elseif($theimageinfo[2] == 2)
				{
        			$theseries .= ".jpg";
				}
      			elseif($theimageinfo[2] == 3)
				{
        			$theseries .= ".png";
				}
				else
				{
					$error = "$lang[531]";
				}
			}
			
			
        	if($error == "")
        	{
				$myvideoimgnew=$config[seriesdir]."/".$theseries;
        		$myconvertimg = $_FILES['uploadseriesimage']['tmp_name'];
        		generatevideothumbs($myconvertimg,$myvideoimgnew,$config[max_thumb_width],$config[max_thumb_height]);
				
				if(file_exists($config['seriesdir']."/".$theseries))
				{
					$query = "UPDATE videos_series SET thumbnail='$theseries' WHERE SID='$seriesid'";
					$conn->execute($query);
					$message = "$lang[539]";	
				}
				else
				{
					$error = "$lang[540]";
				}
        	}
    	}
	}
	
	$templateselect = "createseries.tpl";
}
else
{
	header("Location:$config[baseurl]/login.php");exit;
}

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

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