00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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 ?>