<?php
session_start();
mysql_connect("localhost", $_SESSION["serverUsername"], $_SESSION["serverPassword"]);
mysql_select_db($_SESSION["database"]) or die("Unable to select database");
$title = $_POST["title"];
$year = $_POST["year"];
$director = $_POST["director"];
$description = $_POST["description"];
$cast = $_POST["cast"];
$genre = $_POST["genre"];
$tags = $_POST["tags"];
$seen = $_POST["seen"];
$lastseen = $_POST["lastseen"];
$rating = $_POST["rating"];
$filename = $_POST["filename"];
$timestamp = date("YmdHis");
if ($_POST["timestamp"]) {
$timestamp = $_POST["timestamp"];
}
$length = $_POST["length"];
$artwork = $_POST["artwork"];
$temp = explode("/",$artwork);
$artFileName = $temp[count($temp) - 1];
$ch = curl_init();
$fp = fopen("Images/Artwork/" . $artFileName, "w");
curl_setopt($ch, CURLOPT_URL,$artwork);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$query = "INSERT INTO Library VALUES ('','$title','$year','$director','$description', '$cast','$genre','$tags','$artFileName','$seen','$lastseen','$rating','$filename','$timestamp','','$length')";
mysql_query($query);
mysql_close();
$index = $_POST["index"];
unset($_SESSION["newMovies"][$index]);
$_SESSION["newMovies"] = array_values($_SESSION["newMovies"]);
$_SESSION["addSuccess"] = 1;
$_SESSION["movieAdded"] = $title;
header('Location: verifyNew.php');
?>