Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

ProgressBar.php

Go to the documentation of this file.
00001 <?php
00002 /* $Id: template.php,v 1.3 2003/09/21 10:33:12 mikko Exp $ */
00003 /*
00004  * ImaComm - a web based photo album software
00005  * Copyright (C) 2003, Mikko Kokkonen
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or (at
00010  * your option) any later version.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020  */
00021 
00022 class ProgressBar
00023 {
00024         var $pos;
00025         var $max;
00026         var $step;
00027         var $h;
00028 
00029         function ProgressBar($max = 100, $step = 1)
00030         {
00031                 if ($max != 0)
00032                 {
00033                         $this->max = $max;
00034                 }
00035                 else
00036                 {
00037                         $this->max = 1;
00038                 }
00039                 $this->step = $step;
00040                 $this->pos = 0;
00041         }
00042 
00043         function Init()
00044         {
00045                 global $document;
00046                 
00047                 $img = $document->theme()."/images/progressbar.png";
00048                 $im = getimagesize($img);
00049                 $this->h = $im[1];
00050                 $buf = jsBegin();
00051                 $buf .= "document.write('<div id=\"pb\"><img id=\"progressbar\" src=\"$img\" height=\"{$im[1]}\" width=\"0\" alt=\"\" />');\n";
00052                 $buf .= "document.write('<div id=\"pb_text\"></div>');\n";
00053                 $buf .= "document.write('<div id=\"progressbar_status\"></div></div>');\n";
00054                 $buf .= jsEnd();
00055 
00056                 return $buf;
00057         }
00058         
00059         function setPosition($pos)
00060         {
00061                 $this->pos = $pos;
00062         }
00063 
00064         function getPosition()
00065         {
00066                 return $this->pos;
00067         }
00068 
00069         function step()
00070         {
00071                 $this->pos += $this->step;
00072         }
00073 
00074         function render()
00075         {
00076                 if ($this->max != 0)
00077                 {
00078                         $width = 300 * ($this->pos / $this->max);
00079                 }
00080                 $p = round(($this->pos / $this->max) * 100, 2);
00081                 $buf .= "<script type=\"text/javascript\">\n<!--\n";
00082                 $buf .= "document.getElementById('progressbar').width=$width;\n";
00083                 $buf .= "document.getElementById('progressbar').height=".$this->h.";\n";
00084                 $buf .= jsReplace('pb_text', "$p %");
00085                 $buf .= "// -->\n</script>\n";
00086                 print $buf; flush();
00087         }
00088 
00089         function inc()
00090         {
00091                 $this->step();
00092                 $this->render();
00093         }
00094 
00095         function hide()
00096         {
00097                 $buf .= jsBegin();
00098 //              $buf .= "document.getElementById('pb').style.display = none;\n";
00099                 $buf .= jsReplace('pb', null);
00100                 $buf .= jsEnd();
00101                 print $buf; flush();
00102         }
00103 
00104         function status($msg = null)
00105         {
00106                 $buf = jsBegin();
00107                 $buf .= jsReplace('progressbar_status', $msg);
00108                 $buf .= jsEnd();
00109 
00110                 print $buf; flush();
00111         }
00112 }
00113 ?>

Generated on Sun Oct 19 11:08:00 2003 for ImaComm by doxygen1.3