<?php
/*
* Written by Sean Dempsey - hide@address.com
* http://www.seandempsey.com
*
*
* This script is distributed under the GPL License
*
* This program 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.
*
* http://www.gnu.org/licenses/gpl.txt
*
*/
class progress_bar{
var $name; // The name of the html element representing the progress bar.
var $percent; // The current percent value of the progress bar (in decimal).
var $width; // The maximum width of the progress bar.
var $percentage; // the actial percent value of the progress bar (in percentage)
/*Function progress_bar - The progress bar constructor function
$name -- the name of the html element representing the progress bar.
$percent -- the initial percent value of the progress bar.
$total -- total value possible.
$auto_create if set to TRUE the create() function will be called upon construction of the progress bar
$animated -- is it animated?
$css_path -- path to the bar images?
*/
function progress_bar($name = 'pbar', $complete=1, $total=100, $auto_create = TRUE, $animated = "TRUE", $css_path=""){
$width = 200;
$this->name = $name;
$this->percent = round( ($complete / $total), 3);
$this->percentage = ($this->percent * 100) . "%";
$this->width = round($this->percent * $width);
if ($css_path != ""){
if ($css_path == ".") $css_path = "";
if ($animated == "TRUE"){
$bar_image = "bar_ani.gif";
}
else{
$bar_image = "bar_static.gif";
}
?>
<style>
/* PROGRESS BAR */
.progressBar{
width:216px;
height:41px;
background:url(<?=$css_path?>bg_bar.gif) no-repeat 0 0;
position:relative;
}
.progressBar span{
position:absolute;
display:block;
width:200px;
height:25px;
background:url(<?=$css_path . $bar_image?>) no-repeat 0 0;
top:8px;
left:8px;
overflow:hidden;
text-align: right;
}
.progressBar span b{
overflow: visible;
z-index: 1;
margin-right: 10px;
font-size: 1.2em;
}
.progressBar em{
position:absolute;
z-index: -1;
display:block;
width:200px;
height:25px;
background:url(<?=$css_path?>bg_cover.gif) repeat-x 0 0;
top:0;
}
</style>
<?
}
if($auto_create){
$this->create();
}
}
/*Function create() - Dispalys the progress bar as an html
element. (Warning: do not call this function twice or if $auto_create is set to TRUE)
(This function becomes usless after the create(); function is called.)*/
function create(){
if ($this->percent > .85) $font_color = "style='color: #FFF';";
?>
<p class="progressBar">
<span><em style="left:<?=$this->width?>px"></em><b <?=$font_color?>><?=$this->percentage?></b></span>
</p>
<?
}
/*Function set_name() - Sets the $percent of the object based on current tasks done and the total tasks to finish.
(This function becomes useless after the create(); function is called.)*/
function set_name($name){
$this->name = $name;
}
/*Function set_percent() - Sets the $percent of the progress bar using a pre-calculated percent.
function set_percent($percent){
$this->percent = $percent;
}
/*Function set_percent_adv() - Sets the $percent of the object based
on current tasks done and the total tasks to finish.
$cur_amount the curent number of tasks completed in a script
$max_amount the number of tasks to complete in a script*/
function set_percent_adv($cur_amount,$max_amount){
$this->percent = ($cur_amount / $max_amount) * 100;
}
/*Function set_width() - Sets the maximum $width of the progress bar.
$cur_amount the curent number of tasks completed in a script
$max_amount the number of tasks to complete in a script*/
function set_width($width){
$this->width = $width;
}
}
?>