1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
session_start();

// connect to database
mysql_connect("localhost", $_SESSION["serverUsername"], $_SESSION["serverPassword"]); //connect to MySQL server
mysql_select_db($_SESSION["database"]) or die("Unable to select database"); //connect to database

// create database entry
$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"); // set timestamp to right now as default
if ($_POST["timestamp"]) { // if timestamp was entered into form, use that instead
	$timestamp = $_POST["timestamp"];
}
$length = $_POST["length"];
$artwork = $_POST["artwork"];

$temp = explode("/",$artwork);
$artFileName = $temp[count($temp) - 1];

// download artwork image
$ch = curl_init();    // initialize curl handle 
$fp = fopen("Images/Artwork/" . $artFileName, "w"); // create local image file
curl_setopt($ch, CURLOPT_URL,$artwork); // set url to post to 
curl_setopt($ch, CURLOPT_FAILONERROR, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects 
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // times out after 10s 
curl_setopt($ch, CURLOPT_FILE, $fp); // the file to output the image to 
curl_exec($ch); // run the whole process 
curl_close($ch);  
fclose($fp);

// add movie to database
$query = "INSERT INTO Library VALUES ('','$title','$year','$director','$description', '$cast','$genre','$tags','$artFileName','$seen','$lastseen','$rating','$filename','$timestamp','','$length')";
mysql_query($query);

// close connection to database
mysql_close();

// delete movie from 'verify' queue
$index = $_POST["index"];
unset($_SESSION["newMovies"][$index]);
$_SESSION["newMovies"] = array_values($_SESSION["newMovies"]); // reset array keys after deleting movie

// tell the other page that we've successfully added the movie to the databse
$_SESSION["addSuccess"] = 1;

$_SESSION["movieAdded"] = $title; // to display the title of the movie we just added when we get back to the verifyNew page

// go back to verify page
header('Location: verifyNew.php');

?>