Location: PHPKode > projects > TVEz - Media Library > tvez-0.2.1/html/movies/stats/year_stat.php
<?php

# ------------------------------------------------------------------------------
#
# Top 10 Portlet
#
# ------------------------------------------------------------------------------
#
# 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 02/12/2003 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/02/05 21:34:33 $
# $Revision: 1.5 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------

    $query = "SELECT year,count(year) number from movies group by year";
    list($ynum,$year_movies) = query_db($query);
	if ($ynum) {
		$cc=0;
		# Skip missing year fields
		while ( ($first = $year_movies[$cc]['year']) == 0 ) $cc++;
		$last = $year_movies[(sizeof($year_movies)-1)]['year'];
		foreach ($year_movies as $movie)
			$years[$movie['year']] = $movie['number'];

		# Zero the years in the first decade
		$data = "";
		$begin = floor($first/10)*10;
		for ($i=$begin; $i<$first; $i++)
			$data .= "$i^0^^";

		$max = 0;
		for ($i=$first; $i<=$last; $i++) {
			$height = (isset($years[$i])) ? $years[$i] : 0;
			if ($height > $max) $max = $height;
			$data .= "$i^$height^^";
		}

		# Zero the years in the first decade
		$end = (floor($last/10)+1)*10;
		for ($i=$last+1; $i<$end; $i++)
			$data .= "$i^0^^";

		$xt = ($end - $begin)/10;
		$xmin = $begin;
		$xmax = $end-10;

		if ($max >= 100) {
			$yt = ceil($max/20);
			$ymax = ceil($max/20)*20;
		} else {
			$yt = ceil($max/10);
			$ymax = ceil($max/10)*10;
		}
		$ymin = 0;

		$query = "width=500&height=200&xTitle=Production%20Years&yTitle=Number%20of%20Movies&xTicks=$xt&xMin=$xmin&xMax=$xmax&yTicks=$yt&yMin=$ymin&yMax=$ymax&data=";
		$query .= $data;

		portlet(localize_string("Years of Production"),'<img src="shared/Graph/bar_graph.php?'.$query.'">',"x");
	}
	else
		portlet(localize_string("Years of Production"),"No movies have been added","x");

?>
Return current item: TVEz - Media Library