<?php
/**
*
* creates a horizontal progress bar
*
* @author Harold Kim E. Cantil
* @copyright Kim (c) 2007 - 2008
* @version $1.0$
* @package none
* @subpackage none
*/
class ProgressBar extends Bar{
/**
*
* class constructor
*
* @return none
* @access public
* @param $width (int) progress bar's width
*/
function ProgressBar( $width ){
$this->setWidth( $width );
$this->name = substr( md5 (uniqid ('')) , 0 , 5 );
}
/**
*
* calculates the current width of the progress bar
*
* @access private
* @param $val (int) graphs width
*/
function calculateWidth( $val ) {
$partial = ( $val - $this->min ) * ( $this->width );
$total = ( $this->max - $this->min );
$width = floor ( $partial / $total );
if ( $val <= $this->min) {
$width = 0;
}
if ( $val >= $this->max) {
$width = $this->width ;
}
return $width;
}
/**
*
* fills the progress bar
*
* @access public
* @param $bar (int) graphs current spot
*/
function plot( $bar ) {
$fillWidth = $this->calculateWidth( $bar );
$emptyWidth = $this->width - $fillWidth;
$percentage = $this->calculatePercent( $bar );
//print "<br/> $fillWidth";
//print "<br/> $percentage";
print "
<script language='javascript'>
fill_".$this->name.".style.width=". $fillWidth .";
empty_".$this->name.".style.width=". $emptyWidth .";
document.getElementById('percentage_".$this->name."').innerHTML
= '".$percentage."%';
</script>";
flush ();
}
/**
*
* displays the progress bar
*
* @access public
* @param none
*/
function display(){
// creates the progress bar gui
// initialize bar to zero filling
print '
<table border=0 width="'.$this->width.'" cellspacing="0" cellpadding="1">
<tr>
<td bgcolor="'. $this->borderColor. '" >
<table bgcolor="#FFFFFF" border=0 width="100%"
height="'.$this->height.'" cellspacing="0" cellpadding="0" >
<tr>
<td width="0%"id=fill_'.$this->name.'
bgcolor="'.$this->fillColor.'"></td>
<td width="100%" id=empty_'.$this->name.'
bgcolor="'.$this->emptyColor.'"></td>
</tr>
</table>
</td>
</tr>
</table>
<div id="percentage_'.$this->name.'" >0%</div>
';
}
}
?>
|