Location: PHPKode > projects > TVEz - Media Library > tvez-0.2.1/html/admin/admin_movies.php
<?php      

# ------------------------------------------------------------------------------
#
# Contains the administrative front page for the movies
#
# ------------------------------------------------------------------------------
#
# Copyright (C) 2003 Christian Eheim and Alex Pachikov
#                                                                               
# This file is part of TVEz (tvez.sourceforge.net).
#                                                                               
# TVEz is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#                                                                               
# TVEz is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#                                                                               
# You should have received a copy of the GNU General Public License
# along with TVEz; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#                                                                               
# ------------------------------------------------------------------------------
#
# Created on 12/07/2003 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/09/13 03:00:53 $
# $Revision: 1.13 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------

require "admin/admin_access.php";
require "admin/admin_utils.php";

# Search for new movies on the system
if ( isset($_REQUEST['action']) && ($_REQUEST['action'] == "search") ) {

	$movies = null;
	$doubles = array();
	$notfound = null;
	$changed = null;

	foreach ($MOVIE_DIRS as $dir)
		recurse_dir($dir,$EXT);

	$totalfs = sizeof($movies);

	$query = "select * from movies order by title";
	list($total,$entries) = query_db($query);
	
	foreach ($entries as $entry) {
		$name = split( "\/", $entry['path'] );
		# The path does not match the path found in the database
		if ( $movies[end($name)] != $entry['path'] ) {
			if ( !isset($movies[end($name)]) )
				$notfound[$entry['id']] = end($name);
			else
				$changed[$entry['id']] = end($name);
		}
		else unset($movies[end($name)]);
	}

	echo "<blockquote>";
	echo "<h2>".localize_string("New movies")." <small>(<a href=javascript:this.document.location.reload()>".localize_string("Reload")."</a>)</small></h2>";
	echo '<table class="portlet_wide" cellpadding="4" cellspacing="0"><tr>';
	echo '<td>'.localize_string("Total movies found in your database").':</td><td align="right"><b>'.$total.'</b></td></tr>';
	echo '<td>'.localize_string("Total movies found on your file system").':</td><td align="right"><b>'.$totalfs.'</b></td></tr>';
	echo '</table>';
	if (sizeof($doubles)>0) {
		echo '<blockquote>';
		echo "<h4>".localize_string("The following movie(s) have been found multiple times on your system").":<br><span class=\"warning\"><small>".localize_string("Please resolve this problem")."</small></span></h4>";
		foreach ($doubles as $double)
			echo "$double<br>";
		echo '</blockquote>';
	}
	if ($notfound) {
		echo '<blockquote>';
		echo "<h4>".localize_string("The following movie(s) are in the database but were not found on your system").":</h4>";
		foreach ($notfound as $id => $name) {
			$rn = preg_replace("/'/","\'",$name);
			echo "(<a href=\"javascript:if(confirm('".localize_string("Delete this movie")." ($rn)?')) document.location.href='".$_SERVER['PHP_SELF']."?content=admin&page=movies&delete=1&id=$id'\">".localize_string("Delete")."</a>) $name ($id)<br>";
		}
		echo '</blockquote>';
	}
	if ($changed) {
		echo '<blockquote>';
		echo "<h4>".localize_string("The following movie(s) have a path different from the one in your database")."</h4>";
		foreach ($changed as $id => $name)
			echo "(<a href=\"".$_SERVER['PHP_SELF']."?content=admin&page=movies&edit=$id\">".localize_string("Edit")."</a>) $name ($id)<br>";
		echo '</blockquote>';
	}
	if (sizeof($movies)>0) {
		echo '<blockquote>';
		echo "<h4>".localize_string("The following movie(s) have not been added to the database").":";
		if (sizeof($movies)>2)
			echo "<br><span class=\"warning\"><small>".localize_string("If you are adding multiple movies, we suggest using the update_movies script inside of the admin directory").".</small></span>";
		echo "</h4>";
		foreach ($movies as $movie => $path)
			echo "(<a href=\"".$_SERVER['PHP_SELF']."?content=admin&page=movies&queryimdb=1&path=$path\">".localize_string("Add")."</a>) $path<br>";
		echo '</blockquote>';
	}
	
	echo "</blockquote>";
}
elseif (isset($_REQUEST[delete])) {
	delete_movie($_REQUEST['id']);
}

### you want to get a movie from imdb
elseif (isset($_REQUEST['queryimdb']) && !isset($_REQUEST['insert'])) {

	require "admin/imdb_lib.php";
	require "admin/admin_globals.inc";

	# Keep the old data around so we can restore any of the fields
	foreach ($movieFields as $field)
		$olddata[$field] = $_REQUEST[$field];

	$text = "";
	$path = null;
	if ( (isset($_REQUEST['id']) && $_REQUEST['id'] != "")
		|| (isset($_REQUEST['number']) && $_REQUEST['number'] != "") ) {
		if ( $_REQUEST['number'] != "" ) $id = $_REQUEST['number'];
		else if ( $_REQUEST['id'] != "" ) $id = $_REQUEST['id'];
		if (preg_match("/[0-9]{7}/", $id)) {

			$text = http_request($IMDB_HTTP,80,5,"/title/tt$id/");
		}
		else {
			exit_error(localize_string("The IMDB movie ID you specified is not valid!"));
		}
	} else {
		if (isset($_REQUEST['title']) && $_REQUEST['title'] != "")
			$as = $_REQUEST['title'];	
		else if (isset($_REQUEST['path']) && $_REQUEST['path'] != "") {
			$as = $_REQUEST['path'];	
		}
		else {
			exit_error(localize_string("You must specify a IMDB movie ID, a title, and a file path!"));
		}
		if (isset($_REQUEST['path']) && $_REQUEST['path'] != "") {
			$path = $_REQUEST['path'];
		}
		list($text,$movie['path']) = search_imdb($as,$path);	
	} 

	if ($text) {
		$movie = parse_imdb_source($text);
		$id = $movie['id'];
	}
	else {
		exit_error(localize_string("Could not retrieve the IMDB page for ID ==1==!", $id));
	}

	$movie['plot'] = get_imdb_plot($id);

	# Restore old entries that could not be updated
	foreach ($movieFields as $field) {
		if ($movie[$field] == "" && $olddata[$field] != "")
			$movie[$field] = $olddata[$field];
	}

print '
   <h2>&nbsp;'.localize_string("New Movie").'</h2>
';
	movie_form($movie);
print '
';

}

### you want to insert the edited info after a submit
elseif (isset($_REQUEST['insert'])) {
	require "admin/image_lib.php";
	require "admin/amazon_lib.php";
	require "admin/admin_globals.inc";

	if (
		(isset($HTTP_POST_VARS['title']) && $HTTP_POST_VARS['title']=="")
		|| (isset($HTTP_POST_VARS['id']) && $HTTP_POST_VARS['id']=="")
		|| (isset($HTTP_POST_VARS['path']) && $HTTP_POST_VARS['path']=="") ) {

		exit_error(localize_string("To insert a movie, you must specify the title, the IMDB id, and a path to the file!"));
	}
	if (isset($HTTP_POST_VARS['id']) && !preg_match("/[0-9]{7}/",$HTTP_POST_VARS['id'])) {
		exit_error(localize_string("The IMDB movie ID you specified is not valid!"));
	}

	foreach ($movieFields as $field)
		$movie[$field] = $_REQUEST[$field];

	if ($movie['quality']=="") $movie['quality'] = "N/A";

	if (insert_movie($movie)) {
		if (isset($_REQUEST['amazon']) && $_REQUEST['amazon']!="") {
			# Get the amazon image urls
			list($sa,$la) = get_amazon_imgs($_REQUEST['amazon']);
		}
		if (isset($_REQUEST['image']) && $_REQUEST['image']!="") {
			# Retrieve the small image from IMDB
			retrieve_image($_REQUEST['image'],"$IMG_PATH/small",$movie['id']);
		}
		else {
			if ($sa) {
				# Retrieve the small image from Amazon
				retrieve_image($sa,"$IMG_PATH/small",$movie['id']);
			}
		}
		if ($la) {
			# Retrieve the small image from Amazon
			retrieve_image($la,"$IMG_PATH/large",$movie['id']);
		}

		$query = "SELECT * from movies where id='".$movie['id']."'";
		list($total,$movies) = query_db($query);

			require "movies/utils.php";
			require "movies/views/small_view.php";
		echo '<blockquote>'.localize_string("Return to the ==1==Admin Page", '<a href="'.$_SERVER['PHP_SELF'].'?content=admin">').'</a></blockquote>';
#		header("HTTP/1.1 303 REDIRECT");
#		header("Redirect: ?content=movies&field=id&search=".$movie['id']."\n\n");
	}
	else {
		exit_error(localize_string("Could not insert the movie into the database"));
	}
}

### you want to edit a movie
elseif ($_REQUEST['edit']) {
# ------------------------------------------------------------------------------# Insert a movie
# ------------------------------------------------------------------------------
                                                                                
    global $MYSQL;
    $query = "select * from movies where id='".$_REQUEST['edit']."'";
	list($nn, $movies) = query_db($query);

	print '<h2>'.localize_string("Movie Update").'</h2>';

    movie_form($movies[0]);

}

### you want to make a new entry into the database
else {
print '
   <h2>'.localize_string("Insert Movie").'</h2>
   <blockquote>
   <i>'.localize_string("It is strongly recommended that if you have lots of movies to insert you use the update_movies script in the admin directory").'.<br>
   '.localize_string("If any of the fields require multiple names use / (a forward slash) as deliminator").'.</i>
   </blockquote>
';
    movie_form(null);
}


# ----------------------------------------------------------------------------- 
# Edit movie function. 
# ----------------------------------------------------------------------------- 
function movie_form($movie) {
#	require "../config/config_file.php";

    print '
<script>
function encodeForms() {
	var actors = document.movie.editActors.value;
	var writers = document.movie.editWriters.value;
	var directors = document.movie.editDirector.value;
	var genres = document.movie.editGenres.value;

	var regex = new RegExp("/", "gi");
	actors = actors.replace(regex, "|");
	regex = new RegExp("\t", "gi");
	actors = actors.replace(regex, "");

	regex = new RegExp("\n", "gi");
	genres = genres.replace(regex, "/");
	writers = writers.replace(regex, "/");
	directors = directors.replace(regex, "/");
	actors = actors.replace(regex, "/");

	genres = removeTrailingSlash(genres);
	writers= removeTrailingSlash(writers);
	directors = removeTrailingSlash(directors);
	actors = removeTrailingSlash(actors);

	document.movie.actors.value = actors;
	document.movie.writers.value = writers
	document.movie.director.value = directors;
	document.movie.genres.value = genres;
}

function removeTrailingSlash(text) {
	while (text.charAt(text.length-1) == "/") {
		text = text.substring(0, text.length-1);
	}
	return(text);
}
</script>
        <form method="POST" name="movie" action="'.$_SERVER['PHP_SELF'].'">
		<input type="hidden" name="content" value="admin">
		<input type="hidden" name="page" value="movies">
      <table cellpadding="6" cellspacing="0" border="1" class="singlemovie">
    <tr>
    <td valign="top" align="left">'.localize_string("Title").'<span
	     class="asterisk">*</span></td>
    <td valign="top"><input type="text" size="35"
     name="title" value="'.$movie["title"].'"><br> </td>
    <td valign="top" align="left">'.localize_string("ID").'<span
     class="asterisk">* <small><span class="faint">(IMDB)</span></small></td>
    <td valign="top"><input type="text" size="10" maxlength="7"
     name="id" value="'.$movie["id"].'">';
	 print '<input type="submit" name="queryimdb" value="IMDB">';
	 print '<br> </td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("Path+Filename").'<span
	         class="asterisk">*</span><br>
    </td>
	';
	# ????????????????????????????????????????????????????????
	$movie["path"] = preg_replace("/\\\/","",$movie["path"]);
	# ????????????????????????????????????????????????????????
	echo '
    <td colspan="3" valign="top"><input type="text" size="80"
     name="path" value="'.$movie["path"].'"><br> </td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("Year").' <span class="faint"><small>('.localize_string("4 digit").')</span><br> </small></td>
    <td valign="top"><input type="text" maxlength=4 size="4" name="year" value="'.$movie["year"].'"><br> </td>
    <td valign="top" align="left">'.localize_string("Time").' <small><span class="faint">(in minutes)</span></small><br> </td>
    <td valign="top"><input type="text" maxlength="4" size="4" name="time" value="'.$movie["time"].'"><br> </td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("Country").'<br></td>
    <td valign="top"><input type="text" size="10" name="country" value="'.$movie["country"].'"><br> </td>
    <td valign="top" align="left">'.localize_string("Language").'<br></td>
    <td valign="top"><input type="text" size="10" name="language" value="'.$movie["language"].'"><br> </td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("Writer(s)").'<small><span
     class="faint"></td>
    <td valign="top">
	<input type="hidden" name="writers" values="'.$movie["writers"].'">
	<textarea rows="3" cols="35" name="editWriters">';
	foreach (explode("/", $movie["writers"]) as $writer) {
		print "$writer\n";
	}
	echo '</textarea></td>

    <td valign="top" align="left">'.localize_string("Image").'</td>
    <td valign="top">
	<input type="hidden" name="imgext" value="">
    ';
	if (isset($movie['image']) && $movie['image'] != "")
		echo '<img src="admin/passthru.php?url='.$movie['image'].'" width="50" align="top">';
	elseif (isset($_REQUEST['edit'])) {
		require "movies/utils.php";
#		$imgname = $movie{'id'}.".".$movie{'imgext'};
		$img = get_valid_img("small",$movie['id']);
		echo '<img src="'.$img.'" width="50" align="top">';
	}
	echo '
		</td>
    </tr>

    <tr>
    <td valign="top" align="left">'.localize_string("Director(s)").'<br> </td>
    <td valign="top">
	<input type="hidden" name="director" values="'.$movie["director"].'">
	<textarea rows="3" cols="35" name="editDirector">';
	foreach (explode("/", $movie["director"]) as $director) {
		print "$director\n";
	}
	echo '</textarea></td>
    <td valign="top" align="left">'.localize_string("Genre(s)").'<br> </td>
    <td valign="top">
	<input type="hidden" name="genres" values="'.$movie["genres"].'">
	<textarea rows="3" cols="35" name="editGenres">';
	foreach (explode("/", $movie["genres"]) as $genre) {
		print "$genre\n";
	}
	echo '</textarea></td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("Actor(s)").'<br>
    </td>
    <td colspan="3" valign="top">
	<input type="hidden" name="actors" values="'.$movie["actors"].'">
    <textarea rows="3" cols="80" name="editActors">';
	foreach (explode("/", $movie["actors"]) as $actor) {
		print "$actor\n";
	}
	echo '</textarea></td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("Plot").'<br>
    </td>
    <td valign="top" colspan="3"><textarea cols="80"
     rows="5" name="plot">'.$movie["plot"].'</textarea><br></td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("AKA").'<br>
    </td>
    <td valign="top" colspan="3">
		<textarea cols="80" rows"3" name="aka">'.$movie["aka"].'</textarea>
	 </td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("Votes").'<br>
    </td>
    <td valign="top">
     <input type="text" maxlength="20" size="10" name="votes" value="'.$movie["votes"].'">
     </td>
     <td valign="top" align="left">'.localize_string("Points").'<br>
    </td>
    <td valign="top">
     <input type="text" maxlength="20" size="10" name="points" value="'.$movie["points"].'">
     </td>
    </tr>
    <tr>
    <td valign="top" align="left">'.localize_string("Played").'<br>
    </td>
    <td valign="top" colspan="3">
     <input type="text" maxlength=20 size="10" name="played" value="'.$movie["played"].'">
     </td>
    </tr>
	<tr>
		<td valign="top" align="left">'.localize_string("Quality").'<br></td>
		<td valign="top"><input type="text" maxlength="20" size="10" name="quality" value="'.$movie["quality"].'"></td>
		<td valign="top" align="left">'.localize_string("Date added").' <small><span class="faint">(yyyy-mm-dd)</span><br></small></td>
		<td valign="top"><input type="text" maxlength="20" size="10" name="date" value="'.$movie["date"].'"></td>
	</tr>
    </table>
    <p align="center">
	';
	if (isset($movie['image']) && $movie['image'] != "")
		echo '<input type="hidden" name="image" value="'.$movie['image'].'">';
	if (isset($movie['amazon']) && $movie['amazon'] != "")
		echo '<input type="hidden" name="amazon" value="'.$movie['amazon'].'">';
	echo '
	<input type="submit" onclick="javascript:encodeForms()" name="insert" value="'.localize_string("Insert Movie Data").'">&nbsp;
    <input type="reset" value="'.localize_string("Reset the Form").'">&nbsp;
	';
	if ($movie && !isset($_REQUEST{'queryimdb'}) )
		print '<input type="submit" value="'.localize_string("Delete Movie").'" name=delete onclick="javascript:return confirm(\''.localize_string("Delete this movie").' '.($movie['id']).'?\')">';
	print '
  </p>
    </form>
    ';
}

?>
Return current item: TVEz - Media Library