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

# ------------------------------------------------------------------------------
#
# Portlet showing the disk space used for 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 02/12/2003 by Christian Eheim (hide@address.com)
#
# LAST MODIFIED:
# $Date: 2004/01/25 02:11:33 $
# $Revision: 1.5 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------

$query = "SELECT path,time,played from movies";
list($num,$movies) = query_db($query);

$usage = 0;
$time = 0;
$tmissing = 0;
$multi = 0;
$watched = 0;
$wtime = 0;
if (!$num) $num = 0;
if ($num)
foreach ($movies as $movie) {
	# Compute the disk usage
	if (is_file($movie['path']))
		$stat = stat($movie['path']);
	$usage += $stat['size'];
	if (preg_match("/\((\d?)of(\d?)\)/", $movie['path'], $parts)) {
		for ($i=2; $i<=$parts[2]; $i++) {
			$old = $parts[1]."of".$parts[2];
			$new = $i."of".$parts[2];
			$path = preg_replace("/$old/","$new",$movie['path']);
			if (is_file($path))
				$stat = stat($path);
			$usage += $stat['size'];
		}
		$multi++;
	}
	# Compute the total time
	$time += $movie['time'];
	if ($movie['played']) {
		$wtime += $movie['played']*$movie['time'];
		$watched++;
	}
	if ($movie['time'] == 0) $tmissing++;
}
# Convert the disk usage to GB
$us = round($usage/1024/1024/1024);
# Convert the time to hours and minutes
list($days,$hours,$minutes) = convert_time($time);
list($wdays,$whours,$wminutes) = convert_time($wtime);

$content = "<table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\">";
$content .= "<tr><td>".localize_string("Total Movies")."</td><td align=\"right\">$num</td></tr>";
$content .= "<tr><td>".localize_string("Total Size")."</td><td align=\"right\">$us GB</td></tr>";
$content .= "<tr><td>".localize_string("Total Time")."</td><td align=\"right\">$days:$hours:$minutes</td></tr>";
#$content .= "<tr><td colspan=2 align=right>&nbsp;&nbsp;($tmissing ".localize_string("missing").")</td></tr>";
$content .= "<tr><td>".localize_string("Movies Watched")."</td><td align=\"right\">$watched</td></tr>";
$content .= "<tr><td>".localize_string("Time Watched")."</td><td align=\"right\">$wdays:$whours:$wminutes</td></tr>";
$content .= "</table>";

portlet(localize_string("Movie Statistics"),$content);

function convert_time($time) {
$days = floor($time/60/24);
$hours = floor(($time-$days*60*24)/60);
$minutes = $time-60*$hours-$days*60*24;
if ($hours<10) $hours = "0".$hours;
if ($minutes<10) $minutes = "0".$minutes;
return array($days,$hours,$minutes);
}

?>
Return current item: TVEz - Media Library