Code: Select all
<?
/** ===============================================================================================
* Create a dynamic view of ANT's movie database.
*
* <b> REQUIREMENTS </b>
*
* 1. PHP4+
* 2. MySQL Server 4.1+
* 3. ANT Movie Catalog export to a MySQL Database
* 4. At least some knowledge of standard HTML and PHP processes.
*
*
* <b> INSTRUCTIONS </b>
*
* 1. Download ANT Movie Catalog to build your movie database.
* 2. Export your Movie Database as SQL, check the option for include images.
* 3. Import the SQL into your MySQL Database on the server, and upload the images to the server.
* 4. Add the following code to the page you want this script to be displayed. Don't
* forget to also include the style sheet within the header of your HTML file.
* $db = new mysql_db("<DB_SERVER>", "<DB_USERNAME>", "<DB_PASSWORD>");
* $moviedb = new Moviedb($db, "<DATABASE_NAME>", "<TABLE_NAME>");
* print $moviedb->get_html();
* 5. There are several SET functions available which can be used to tweak the way this script
* works on your server. Include the function calls just before the print statement included
* on step four (above). The SET functions available are:
* $moviedb->set_min_cat_num($int); // Sets the Minimum number of movies before a category for that type is displayed. (Default 5)
* $moviedb->set_lang_file($filename); // Sets the language file to use (filename only, NOT path)
* $moviedb->set_moviedb_title($string); // Sets the title to be displayed at the top of the script
* $moviedb->set_default_npp($int); // Sets the number of movies per page to be displayed (Default 10)
* $moviedb->set_img_folder($http_path); // Sets the cover images directory (full HTTP path required) (Default: <SCRIPT PATH>/images)
*
* *. YOU SHOULD NOT NEED TO EDIT THIS FILE AT ALL UNLESS YOU KNOW WHAT YOU ARE DOING. :)
*
*
* <b> LICENSE </b>
*
* Copyright © 2005-2006 PK-Designs, Some Rights Reserved. This work is licensed under
* a "Creative Commons License" The below is a human-readable summary of the full Legal Code
* found at: http://creativecommons.org/licenses/by/2.5/legalcode
*
* - <b>You are free..</b>
* - to copy, distribute, display, and perform the work
* - to make derivative works
* - to make commercial use of the work
*
* - <b>Under the following conditions..</b>
* - Attribution. You must attribute the work in the manner specified by the author or licensor.
* - For any reuse or distribution, you must make clear to others the license terms of this work.
* - Any of these conditions can be waived if you get permission from the copyright holder.
*
*
* <b> ATTRIBUTION </b>
*
* If you plan to use this code on any site you own or help create, you must site the author
* M. Shepanski along with a link back to PK-Designs.com. Like most designers, I too do not like
* to include random links to someone's site when I use their script. Because of this I do not
* require that you include this link right near where the script is used on your page, but rather
* just mentioned on your site someplace; perhaps the disclaimer, or about page.
*
* Not required, but it is always nice to hear from people who find my work useful to them.
* If you wish, drop me a line so I can see how you implemented this script on your site.
*
* @author Michael Shepanski <mshepanski@pk-designs.com>
* @copyright Copyright © 2005-2006, Michael Shepanski
* @package PK-Designs
* @version Version 2.2 (2006.04.22)
*=============================================================================================== */
class Moviedb {
# Public Required Variables - Defined with the Constructor
var $db; // Mysql_db Object (Required)
var $dbname; // Database Name (Required)
var $tbname; // Table Name (Required)
# PUBLIC VARIABLES - Use the SET functions below to edit these
var $img_folder; // Path to movie images folder (Default: $SCRIPTDIR/images)
var $moviedb_title; // MovieDB Title to be displayed (Default: PK's Movie Database)
var $min_cat_num; // Minimum number of matches for a category to get its own option (Default: 5)
var $default_npp; // Default number of matches to show per page (Default: 10)
var $lang_file; // Language File to be used (Default: lang-english.inc)
var $res_folder; // Resources folder
# Private Variables - These are used internally within this class
var $THISPAGE; // HTTP Path to this Script
var $HTTPDIR; // HTTP Path to this Script's Folder
var $UNIXDIR; // UNIX Path to this Script's Folder
var $mdb_cat; // GETVAR: Current Category
var $mdb_num; // GETVAR: Current Selected Movie
var $mdb_page; // GETVAR: Current Page Number
var $mdb_npp; // GETVAR: Current Num/Page
var $mdb_search; // GETVAR: Current Search String
var $mdb_order; // GETVAR: Current Order Displayed
var $non_moviedb_gets; // Holds all non-MovieDB GET variables
var $filtered_movies; // Array containing ALL movie info
var $categories; // Array containing ALL category options
var $misc_categories; // All categories to be filed under Miscellaneous
var $num_matches; // Number of movie matches made with selected criteria
var $num_pages; // Total number of pages in the filtered view
var $num_movies; // Total number of movies in the database
/** -------------------------------------------------------------------------------------------
* Create or Load an instance of the worldplot database script.
* @access public
* ------------------------------------------------------------------------------------------*/
function Moviedb($mysql_db, $dbname, $tbname) {
$this->db = $mysql_db;
$this->dbname = $dbname;
$this->tbname = $tbname;
$this->pre_setup_envirnment();
}
/** -------------------------------------------------------------------------------------------
* Sets up envirnment to be used within this class
* @access public
* ------------------------------------------------------------------------------------------*/
function pre_setup_envirnment() {
$unixfile = str_replace("\\", "/", $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF']);
$this->THISPAGE = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$this->HTTPPATH = substr($this->THISPAGE, 0, strrpos($this->THISPAGE, "/"));
$this->UNIXPATH = substr($unixfile, 0, strrpos($unixfile, "/"));
}
/** -------------------------------------------------------------------------------------------
* Finishes the setup of envirnment options AFTER the programmer had a chance to alter any
* public variables.
* @access public
* ------------------------------------------------------------------------------------------*/
function post_setup_envirnment() {
if (!isset($this->img_folder)) { $this->img_folder = $this->HTTPPATH."/images"; }
if (!isset($this->moviedb_title)) { $this->moviedb_title = "PK's Movie Database"; }
if (!isset($this->min_cat_num)) { $this->min_cat_num = 5; }
if (!isset($this->default_npp)) { $this->default_npp = 10; }
if (!isset($this->res_folder)) { $this->res_folder = $this->HTTPPATH."/resource/language/"; }
if (!isset($this->lang_file)) { $this->lang_file = "lang-english.inc"; }
require_once($this->res_folder.$this->lang_file);
$this->fetch_get_vars();
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the movie database to the screen.
* @access public
* ------------------------------------------------------------------------------------------*/
function get_html() {
$this->post_setup_envirnment();
$html = "<div id='mdb_container'>\n";
$html .= $this->get_header_html();
if ($this->mdb_num > 0) {
$html .= $this->get_full_detail_html($this->mdb_num);
} else {
$html .= $this->get_default_html();
}
$html .= $this->get_footer_html();
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* SETS - These are not checked for validity, so make sure you just use them correectly! :)
* @access public
* ------------------------------------------------------------------------------------------*/
function set_min_cat_num($int) { $this->min_cat_num = $int; }
function set_lang_file($filename) { $this->lang_file = $filename; }
function set_moviedb_title($string) { $this->moviedb_title = $string; }
function set_default_npp($int) { $this->default_npp = $int; }
function set_img_folder($http_path) { $this->img_folder = $http_path; }
function set_res_folder($http_path) { $this->res_folder = $http_path; }
/** -------------------------------------------------------------------------------------------
* Collect and Set all the Default GET variables. Stores all non-MovieDB GET variables to
* ensure that we do not forget to include them later.
* @access private
* ------------------------------------------------------------------------------------------*/
function fetch_get_vars() {
$mdb_vars = array("mdb_cat", "mdb_num", "mdb_page", "mdb_npp", "mdb_search", "mdb_order");
# Populate the non_moviedb_gets to contain all GETS not used in this script.
$this->non_moviedb_gets = array();
foreach($_GET as $var => $val) {
if (!in_array($var, $mdb_vars)) { $this->non_moviedb_gets[$var] = $val; }
}
#Set the Default GET values for this script.
$this->mdb_cat = (isset($_GET['mdb_cat']) ? $_GET['mdb_cat'] : "");
$this->mdb_num = (isset($_GET['mdb_num']) ? $_GET['mdb_num'] : 0);
$this->mdb_page = (isset($_GET['mdb_page']) ? $_GET['mdb_page'] : 1);
$this->mdb_npp = (isset($_GET['mdb_npp']) ? $_GET['mdb_npp'] : $this->default_npp);
$this->mdb_search = (isset($_GET['mdb_search']) ? $_GET['mdb_search'] : "");
$this->mdb_order = (isset($_GET['mdb_order']) ? $_GET['mdb_order'] : "DATEADD");
}
/** -------------------------------------------------------------------------------------------
* Convert an associative array to a proper GET string for the address bar.
* @access private
* ------------------------------------------------------------------------------------------*/
function array_to_get($array) {
$str = "";
foreach($array as $var => $val) {
if ($str != "") { $str .= "&"; }
$str .= $var."=".$val;
}
return $str;
}
/** -------------------------------------------------------------------------------------------
* Convert an associative array to private form inputs.
* @access private
* ------------------------------------------------------------------------------------------*/
function array_to_post($array) {
$str = "";
foreach($array as $var => $val) {
$str .= "<input type='hidden' name='".$var."' value='".$val."' />\n";
}
return $str;
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the default movie view to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_default_html() {
$i = 0;
$oldchar = "";
$this->fetch_categories();
$this->fetch_filtered_movies();
$this->num_matches = sizeof($this->filtered_movies);
$this->num_pages = ceil($this->num_matches / $this->mdb_npp);
$html = "<div id='mdb_content'>\n";
$html .= " <div class='panel'>\n";
$html .= $this->get_categories_html();
$html .= $this->get_search_html();
$html .= $this->get_alphabet_html();
$html .= " </div>\n";
$html .= " <div class='mdb_filter_page'>\n";
$html .= $this->get_filter_header_html();
while (($i < $this->mdb_npp) && ((($this->mdb_page-1)*$this->mdb_npp)+$i < $this->num_matches)) {
$newchar = strtolower(substr($this->filtered_movies[(($this->mdb_page-1)*$this->mdb_npp)+$i]['ORIGINALTITLE'], 0, 1));
if ($newchar != $oldchar) {
$oldchar = $newchar;
$html .= " <a name='".$newchar."'></a>\n";
}
$html .= $this->get_short_description_html($this->filtered_movies[(($this->mdb_page-1)*$this->mdb_npp)+$i]);
$i++;
}
$html .= $this->get_filter_footer_html();
$html .= " </div>\n";
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the short movie description to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_short_description_html($movieinfo) {
$i = 0;
$actors_string = "";
$directors_string = "";
# Get the Non-MDB Gets
$non_mdb_gets = $this->array_to_get($this->non_moviedb_gets);
$non_mdb_gets = ((strlen($non_mdb_gets) > 0) ? "&".$non_mdb_gets : "");
# Trim the Description if needed
if (strlen($movieinfo['DESCRIPTION']) > 500) {
$movieinfo['DESCRIPTION'] = substr($movieinfo['DESCRIPTION'], 0, 400);
$movieinfo['DESCRIPTION'] = substr($movieinfo['DESCRIPTION'], 0, strrpos($movieinfo['DESCRIPTION'], " "));
$movieinfo['DESCRIPTION'] = trim($movieinfo['DESCRIPTION']).".. <a href='".$this->THISPAGE."?mdb_page=1&mdb_num=".$movieinfo['NUM']."mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$this->mdb_search.$non_mdb_gets."'>".$this->lang['more']."</a>";
}
# Fix the Rating
if($movieinfo['RATING'] == "") { $movieinfo['RATING'] = "na"; }
# Turn the actors list into links
$actors = $this->get_actors($movieinfo['ACTORS'], 0);
$i=0;
foreach($actors as $actor => $role) {
if ($i == 3) { break; }
if ($i > 0) { $actors_string .= ", "; }
$actors_string .= "<a href='".$this->THISPAGE."?mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$actor.$non_mdb_gets."'>".$actor."</a>";
$i++;
}
if (sizeof($actors) > 3) { $actors_string .= ", <a href='".$this->THISPAGE."?mdb_page=1&mdb_num=".$movieinfo['NUM']."mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$this->mdb_search.$non_mdb_gets."'>...</a>"; }
# Turn the directors list into links
$directors = $this->get_actors($movieinfo['DIRECTOR'], 0);
foreach($directors as $director => $role) {
if ($directors_string != "") { $directors_string .= ", "; }
$directors_string .= "<a href='".$this->THISPAGE."?mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$director.$non_mdb_gets."'>".$director."</a>";
}
# Create the HTML
$html = "<div class='short_detail'>\n";
$html .= " <a href='".$this->THISPAGE."?mdb_num=".$movieinfo['NUM']."&mdb_page=".$this->mdb_page."&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$this->mdb_search.$non_mdb_gets."'><img class='cover' src='".$this->img_folder."/".$movieinfo['PICTURENAME']."' alt='".$movieinfo['ORIGINALTITLE']."' /></a>\n";
$html .= " <div class='title'>\n";
$html .= " <a href='".$this->THISPAGE."?mdb_num=".$movieinfo['NUM']."&mdb_page=".$this->mdb_page."&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$this->mdb_search.$non_mdb_gets."'>".$movieinfo['ORIGINALTITLE']."</a>\n";
$html .= " </div>\n";
$html .= " <div class='quickinfo'>\n";
$html .= " <div class='imdb'><a href='".$movieinfo['URL']."'><img src='".$this->HTTPPATH."/resource/imdb/".$movieinfo['RATING'].".jpg' border=0></a></div>\n";
$html .= " <div class='info'>\n";
$html .= " <span>".$this->lang['year'].":</span> <a href='".$this->THISPAGE."?mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$movieinfo['YEAR'].$non_mdb_gets."'>".$movieinfo['YEAR']."</a>\n";
$html .= " <br /><span>".$this->lang['director'].": </span>\n".$directors_string."\n";
$html .= " <br /><span>".$this->lang['category'].":</span> <a href='".$this->THISPAGE."?mdb_cat=".$movieinfo['CATEGORY']."&mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order.$non_mdb_gets."'>".$movieinfo['CATEGORY']."</a>\n";
$html .= " </div>\n";
$html .= " </div>\n";
$html .= " <div class='short_description'>\n";
$html .= $movieinfo['DESCRIPTION'];
$html .= " </div>\n";
$html .= " <div class='stars'>\n";
$html .= " <span>".$this->lang['starring'].":</span>\n";
$html .= $actors_string;
$html .= " </div>\n";
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the full description to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_full_detail_html($num) {
$count = 0;
$actors_string = "";
# Get the Non-MDB Gets
$non_mdb_gets = $this->array_to_get($this->non_moviedb_gets);
$non_mdb_gets = ((strlen($non_mdb_gets) > 0) ? "&".$non_mdb_gets : "");
$res = $this->db->query("SELECT * FROM `".$this->dbname."`.`".$this->tbname."` WHERE NUM='".$this->mdb_num."'");
$movieinfo = $res->fetch_assoc();
if($movieinfo['RATING'] == "") { $movieinfo['RATING'] = "na"; }
$actors = $this->get_actors($movieinfo['ACTORS'], 0);
foreach ($actors as $actor => $roll) {
if ($count > 0) { $actors_string .= ", "; }
$actors_string .= "<a href='".$this->THISPAGE."?mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$actor.$non_mdb_gets."'>".$actor."</a>".$roll;
$count++;
}
$html = "<div id='mdb_full_detail'>\n";
$html .= " <a href='".$this->img_folder."/".$movieinfo['PICTURENAME']."'><img class='cover' src='".$this->img_folder."/".$movieinfo['PICTURENAME']."' alt='".$movieinfo['ORIGINALTITLE']."' /></a>\n";
$html .= " <div class='title'>".$movieinfo['ORIGINALTITLE']."</div>\n";
$html .= " <div class='quickinfo'>\n";
$html .= " <div class='imdb'><a href='".$movieinfo['URL']."'><img src='".$this->HTTPPATH."/resource/imdb/".$movieinfo['RATING'].".jpg' border=0></a></div>\n";
$html .= " <div class='info'>\n";
$html .= " <span>".$this->lang['year'].":</span> <a href='".$this->THISPAGE."?mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$movieinfo['YEAR'].$non_mdb_gets."'>".$movieinfo['YEAR']."</a>\n";
$html .= " <br /><span>".$this->lang['country'].":</span> <a href='".$this->THISPAGE."?mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$movieinfo['COUNTRY'].$non_mdb_gets."'>".$movieinfo['COUNTRY']."</a>\n";
$html .= " <br /><span>".$this->lang['director'].":</span> <a href='".$this->THISPAGE."?mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$movieinfo['DIRECTOR'].$non_mdb_gets."'>".$movieinfo['DIRECTOR']."</a>\n";
$html .= " <br /><span>".$this->lang['category'].":</span> <a href='".$this->THISPAGE."?mdb_cat=".$movieinfo['CATEGORY']."&mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order.$non_mdb_gets."'>".$movieinfo['CATEGORY']."</a>\n";
$html .= " <br /><span>".$this->lang['length'].":</span> ".$movieinfo['LENGTH']." min\n";
$html .= " </div>\n";
$html .= " </div>\n";
$html .= " <div class='description'>\n";
$html .= " <span>".$this->lang['description'].":</span><br />\n";
$html .= $movieinfo['DESCRIPTION'];
$html .= " </div>\n";
$html .= " <div class='comments'>\n";
$html .= " <span>".$this->lang['comments'].":</span><br />\n";
$html .= $movieinfo['COMMENTS'];
$html .= " </div>\n";
$html .= " <div class='stars'>\n";
$html .= " <span>".$this->lang['starring'].":</span>\n";
$html .= $actors_string;
$html .= " </div>\n";
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* Returns a list containing the first $num actors on the roster. A $num of 0 will return
* all actors.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_actors($actor_string, $num) {
$rtnval = array();
$actors = split(",", $actor_string);
if ($num == 0) { $num = 10000; }
$count = 0;
while(($count < sizeof($actors)) && ($count < $num)) {
$actor = trim($actors[$count]);
$role = "";
if (strpos($actor, "(") != 0) {
$role = " ".trim(substr($actor, strpos($actor, "("), strrpos($actor, ")")));
$actor = trim(substr($actor, 0, strpos($actor, "(")-1));
} else if (strpos($actor, "(") === 0) {
$actor = "";
}
if ($actor != "") { $rtnval[$actor] = $role; }
$count++;
}
return $rtnval;
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the Filter Header to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_filter_header_html($footer=FALSE) {
$divid = ($footer ? "mdb_filter_footer" : "mdb_filter_header");
$showing_min = (($this->mdb_page-1) * $this->mdb_npp) + 1;
$showing_max = (((($showing_min+$this->mdb_npp)-1) > $this->num_matches) ? $this->num_matches : ($showing_min+$this->mdb_npp)-1);
$non_mdb_gets = $this->array_to_get($this->non_moviedb_gets);
$non_mdb_gets = ((strlen($non_mdb_gets) > 0) ? "&".$non_mdb_gets : "");
$prev_html = "";
$next_html = "";
if ($this->mdb_page > 1) {
$prev_page = $this->mdb_page-1;
$prev_link = $this->THISPAGE."?mdb_cat=".$this->mdb_cat."&mdb_page=".$prev_page."&mdb_npp=".$this->mdb_npp."&mdb_search=".$this->mdb_search."&mdb_order=".$this->mdb_order.$non_mdb_gets;
$prev_html = "« <a href='".$prev_link."'>".$this->lang['previous']."</a> |";
}
if ($this->mdb_page < $this->num_pages) {
$next_page = $this->mdb_page + 1;
$next_link = $this->THISPAGE."?mdb_cat=".$this->mdb_cat."&mdb_page=".$next_page."&mdb_npp=".$this->mdb_npp."&mdb_search=".$this->mdb_search."&mdb_order=".$this->mdb_order.$non_mdb_gets;;
$next_html = "| <a href='$next_link'>".$this->lang['next']."</a> »";
}
$html = "<div id='".$divid."'>\n";
$html .= " <div class='pages'>".$prev_html." <span>".$this->lang['page'].":</span> ".$this->mdb_page." ".$this->lang['of']." ".$this->num_pages." ".$next_html."</div>\n";
$html .= " <div class='showing'><span>".$this->lang['showing'].":</span> ".$showing_min."-".$showing_max." ".$this->lang['of']." ".$this->num_matches."</div>\n";
$order_options = array( "ORIGINALTITLE" => $this->lang['title'], "YEAR" => $this->lang['year'],
"RATING" => $this->lang['rating'], "DATEADD" => $this->lang['most_recent']);
if (!$footer) {
$html .= " <div class='sort'>\n";
$html .= " <span>".$this->lang['sort_by'].":</span>\n";
$ordertext = "";
foreach($order_options as $field => $text) {
if ($ordertext != "") { $ordertext .= " |\n"; }
$classtext = (($field == $this->mdb_order) ? "class='selected' " : "");
$ordertext .= " <a ".$classtext."href='".$this->THISPAGE."?mdb_cat=".$this->mdb_cat."&mdb_npp=".$this->mdb_npp."&mdb_search=".$this->mdb_search."&mdb_order=".$field.$non_mdb_gets."'>".$text."</a>";
}
$html .= $ordertext;
$html .= " </div>\n";
}
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the Filter Header to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_filter_footer_html() {
return $this->get_filter_header_html(TRUE);
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the category selector to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_categories_html() {
$selected = (($this->mdb_cat == "") ? " selected" : "");
$non_mdb_gets = $this->array_to_get($this->non_moviedb_gets);
$non_mdb_gets = ((strlen($non_mdb_gets) > 0) ? "&".$non_mdb_gets : "");
$cat_link = $this->THISPAGE."?mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$this->mdb_search.$non_mdb_gets;
$html = "<div id='mdb_categories' class='mdb_menu'>\n";
$html .= " <h4>".$this->lang['categories']."</h4>\n";
$html .= " <table class='cat_list' cellpadding='0' cellspacing='0'>\n";
$html .= " <tr>\n";
$html .= " <td class='cat_title".$selected."'><a href='".$cat_link."'>All Categories</a></td>\n";
$html .= " <td class='cat_num".$selected."'>".$this->num_movies."</td>\n";
$html .= " </tr>\n";
foreach($this->categories as $mycat => $mynum) {
$selected = (($this->mdb_cat == $mycat) ? " selected" : "");
$cat_link = $this->THISPAGE."?mdb_cat=".$mycat."&mdb_npp=".$this->mdb_npp."&mdb_order=".$this->mdb_order."&mdb_search=".$this->mdb_search.$non_mdb_gets;
$html .= " <tr>\n";
$html .= " <td class='cat_title".$selected."'><a href='".$cat_link."'>".$mycat."</a></td>\n";
$html .= " <td class='cat_num".$selected."'>".$mynum."</td>\n";
$html .= " </tr>\n";
}
$html .= " </table>\n";
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the Search Box to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_search_html() {
$html = "<div id='mdb_search' class='mdb_menu'>\n";
$html .= " <h4>".$this->lang['search']."</h4>\n";
$html .= " <form method='get' action='".$this->THISPAGE."'>\n";
$html .= " <input type='hidden' name='mdb_cat' value='".$this->mdb_cat."' />\n";
$html .= " <input type='hidden' name='mdb_npp' value='".$this->mdb_npp."' />\n";
$html .= " <input type='hidden' name='mdb_order' value='".$this->mdb_order."' />\n";
$html .= " <input type='input' name='mdb_search' value='".$this->mdb_search."' />\n";
$html .= $this->array_to_post($this->non_moviedb_gets);
$html .= " </form>\n";
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the Alphabet Box to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_alphabet_html() {
$modval = 8;
$non_mdb_gets = $this->array_to_get($this->non_moviedb_gets);
$non_mdb_gets = ((strlen($non_mdb_gets) > 0) ? "&".$non_mdb_gets : "");
$char_link = $this->THISPAGE."?mdb_cat=".$this->mdb_cat."&mdb_page=1&mdb_npp=".$this->mdb_npp."&mdb_order=ORIGINALTITLE&mdb_search=".$this->mdb_search.$non_mdb_gets;
$html = "<div id='mdb_alphabet' class='mdb_menu'>\n";
$html .= " <h4>".$this->lang['jump_to']."</h4>\n";
$html .= " <table class='char_list' cellpadding='0' cellspacing='0'><tr>\n";
$html .= " <td><a href='".$char_link."'>#</a></td>\n";
$charnum = 1;
while ($charnum <= 26) {
$char = chr($charnum+96);
$alphapage = $this->get_char_page($char);
$char_link = $this->THISPAGE."?mdb_cat=".$this->mdb_cat."&mdb_page=".$alphapage."&mdb_npp=".$this->mdb_npp."&mdb_order=ORIGINALTITLE&mdb_search=".$this->mdb_search.$non_mdb_gets."#".$char;
if ($alphapage > 0) {
$html .= " <td><A href='".$char_link."'>$char</A></td>\n";
} else {
$html .= " <td>".$char."</td>\n";
}
$charnum++;
if($charnum % $modval == 0) { $html .= " </tr><tr>\n"; }
}
while($charnum % $modval != 0) { $html .= " <td> </td>\n"; $charnum++; }
$html .= " </tr></table>\n";
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* Returns the Page Number that the Character Starts ats
* @access private
* ------------------------------------------------------------------------------------------*/
function get_char_page($char) {
$alphapage = 0;
$i = 0;
while(($alphapage == 0) && ($i < sizeof($this->filtered_movies))) {
if (strtolower(substr($this->filtered_movies[$i]['ORIGINALTITLE'], 0, 1)) >= $char) {
$alphapage = ceil(($i+1) / $this->mdb_npp);
}
$i++;
}
return $alphapage;
}
/** -------------------------------------------------------------------------------------------
* Populates the two variables $categories and $misc_categories to be used when displaying
* the category options. Array structure is array(name => number) of all categories. If
* there is less movies than displayed in $this->min_cat_num, the movies will be filed to
* category other.
* @access private
* ------------------------------------------------------------------------------------------*/
function fetch_categories() {
$this->categories = array();
$this->misc_categories = array();
$this->num_movies = 0;
$misc_count = 0;
$res = $this->db->query("SELECT category,count(*) FROM `".$this->dbname."`.`".$this->tbname."` GROUP BY category");
while ($row = $res->fetch_assoc()) {
if (($row['count(*)'] >= $this->min_cat_num) && (trim($row['category']) != "")) {
$this->categories[$row['category']] = $row['count(*)'];
} else {
$misc_count += $row['count(*)'];
array_push($this->misc_categories, $row['category']);
}
$this->num_movies += $row['count(*)'];
}
if ($misc_count > 0) {
$this->categories['Other'] = $misc_count;
}
}
/** -------------------------------------------------------------------------------------------
* Returns array of an array of movie information based on the selections made for $mdb_cat,
* $mdb_page, $mdb_npp, $mdb_search. It's a nasty function, I know. :(
* @access private
* ------------------------------------------------------------------------------------------*/
function fetch_filtered_movies() {
$this->filtered_movies = array();
$query = "SELECT * from `".$this->dbname."`.`".$this->tbname."`";
if (($this->mdb_cat != "") || ($this->mdb_search != "")) { $query .= " WHERE"; }
if (($this->mdb_cat != "") && ($this->mdb_cat != "Other")) { $query .= " CATEGORY = '".$this->mdb_cat."'"; }
if ($this->mdb_cat == "Other") {
$i=0;
while ($i < sizeof($this->misc_categories)) {
if ($i==0) { $query .= " (CATEGORY = '".$this->misc_categories[$i]."'"; }
else { $query .= " OR CATEGORY = '".$this->misc_categories[$i]."'"; }
$i++;
}
$query .= ")";
}
if ($this->mdb_search != "") {
if ($this->mdb_cat != "") { $query .= " AND"; }
$query .= " (MEDIA LIKE '%".$this->mdb_search."%'";
$query .= " OR MEDIATYPE LIKE '%".$this->mdb_search."%'";
$query .= " OR SOURCE LIKE '%".$this->mdb_search."%'";
$query .= " OR ORIGINALTITLE LIKE '%".$this->mdb_search."%'";
$query .= " OR TRANSLATEDTITLE LIKE '%".$this->mdb_search."%'";
$query .= " OR DIRECTOR LIKE '%".$this->mdb_search."%'";
$query .= " OR PRODUCER LIKE '%".$this->mdb_search."%'";
$query .= " OR COUNTRY LIKE '%".$this->mdb_search."%'";
$query .= " OR CATEGORY LIKE '%".$this->mdb_search."%'";
$query .= " OR YEAR LIKE '%".$this->mdb_search."%'";
$query .= " OR ACTORS LIKE '%".$this->mdb_search."%'";
$query .= " OR DESCRIPTION LIKE '%".$this->mdb_search."%'";
$query .= " OR COMMENTS LIKE '%".$this->mdb_search."%'";
$query .= " OR VIDEOFORMAT LIKE '%".$this->mdb_search."%'";
$query .= " OR VIDEOBITRATE LIKE '%".$this->mdb_search."%'";
$query .= " OR AUDIOFORMAT LIKE '%".$this->mdb_search."%'";
$query .= " OR AUDIOBITRATE LIKE '%".$this->mdb_search."%'";
$query .= " OR RESOLUTION LIKE '%".$this->mdb_search."%'";
$query .= " OR FRAMERATE LIKE '%".$this->mdb_search."%'";
$query .= " OR LANGUAGES LIKE '%".$this->mdb_search."%')";
}
$query .= " ORDER BY ".$this->mdb_order." ";
if (($this->mdb_order == "YEAR") || ($this->mdb_order == "RATING") || ($this->mdb_order == "DATEADD")) { $query .= "DESC , ORIGINALTITLE"; }
$res = $this->db->query($query);
while($row = $res->fetch_assoc()) {
array_push($this->filtered_movies, $row);
}
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the movie database HEADER to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_header_html() {
$html = "<div id='mdb_header'>\n";
$html .= " <h3><span>".$this->moviedb_title."</span></h3>\n";
$html .= "</div>\n";
return $html;
}
/** -------------------------------------------------------------------------------------------
* Return the HTML to print the movie database FOOTER to the screen.
* @access private
* ------------------------------------------------------------------------------------------*/
function get_footer_html() {
$html = "<div id='moviedb_footer'>\n";
$html .= " <div class='copyright'>PK's Movie Database - © 2006 <a href='http://pk-designs.com'>PK-Designs.com</a>.</div>\n";
$html .= "</div>\n";
return $html;
}
}