Location: PHPKode > scripts > IMDBSearch > imdbsearch/new.php
<?
/*	Retrieves a record and adds it to local db
	called from list.php
	Don't modify without written authorization
	Created by: Randy Gerritse
	Email: hide@address.com
	©2003, All rights reserved.
	================================================================================ */

require("init.php");

$imdb = new IMDBSearch($_REQUEST["item"]);
if (!isset($imdb->imdb_result["multiple"])) {
	
	$indb = $connection->execute($sql->checkID($imdb->imdb_result["id"]));
	if (count($indb) <= 0) {
		
		//add the movie
		$connection->execute($sql->addMovie($imdb->imdb_result["id"],$imdb->imdb_result["title"],$imdb->imdb_result["cover"],$imdb->imdb_result["year"],$imdb->imdb_result["rating"],$imdb->imdb_result["tagline"],$imdb->imdb_result["outline"],$imdb->imdb_result["outlinemore"]));
		
		//get the movie genres
		if (count($imdb->imdb_result["genre"]) > 0) {
			foreach ($imdb->imdb_result["genre"] as $genre) {
				//create the genre if not existent
				$genres = $connection->execute($sql->getGenre($genre));
				if (count($genres) <= 0) {
					$genreid = $connection->execute($sql->createGenre(strtolower($genre)));
				} else {
					$gen = current($genres);
					$genreid = $gen["id"];
				}
				//add the movie to the genre
				$connection->execute($sql->addMovieToGenre($imdb->imdb_result["id"],$genreid));
			}
		}
		
		//get the movie cast
		if (count($imdb->imdb_result["cast"]) > 0) {
			foreach ($imdb->imdb_result["cast"] as $actor) {
				//create the actor if not existent
				$actors = $connection->execute($sql->getActor($actor["Name"]));
				if (count($actors) <= 0) {
					$actorid = $connection->execute($sql->createActor($actor["Name"]));
				} else {
					$act = current($actors);
					$actorid = $act["id"];
				}
				//add the actor to the movie
				$connection->execute($sql->addActorToMovie($imdb->imdb_result["id"],$actorid,$actor["Character"]));
			}
		}
		
		//get the directors
		if (count($imdb->imdb_result["directors"]) > 0) {
			foreach ($imdb->imdb_result["directors"] as $director) {
				//create the director if not existent
				$directors = $connection->execute($sql->getDirector($director["name"]));
				if (count($directors) <= 0) {
					$directorid = $connection->execute($sql->createDirector($director["name"]));
				} else {
					$dir = current($directors);
					$directorid = $dir["id"];
				}
				//add the director to the movie
				$connection->execute($sql->addDirectorToMovie($imdb->imdb_result["id"],$directorid));
			}
		}
		
		echo '('.$imdb->imdb_result["rating"].') '.$imdb->imdb_result["title"].' (id = '.$imdb->imdb_result["id"].')<br>';
		flush();
	} else 
		echo "al bestaand";
}
?>
Return current item: IMDBSearch