false); // ProgressBar Frame
/* 'show' => false, # frame show (true/false)
'left' => 200, # frame position from left
'top' => 100, # frame position from top
'width' => 300, # frame width
'height' => 75, # frame height
'color' => '#c0c0c0', # frame color
'border' => 2, # frame border
'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf' # frame border color
*/
public $label = array(); // ProgressBar Labels
/* 'name' => array( # label name
'type' => 'text', # label type (text,button,step,percent,crossbar)
'value' => 'Please wait ...', # label value
'left' => 10, # label position from left
'top' => 20, # label position from top
'width' => 0, # label width
'height' => 0, # label height
'align' => 'left', # label align
'font-size' => 11, # label font size
'font-family' => 'Verdana, Tahoma, Arial', # label font family
'font-weight' => '', # label font weight
'color' => '#000000', # label font color
'bgr_color' => '' # label background color
)
*/
// constructor
public function __construct($width = 0, $height = 0)
{
$this->code = substr(md5(microtime()), 0, 6);
if ($width > 0)
$this->width = $width;
if ($height > 0)
$this->height = $height;
}
// private functions
private function _calculatePercent($step)
{
// avoid divison through 0
if ($this->max - $this->min == 0)
$this->max ++;
$percent = round(($step - $this->min) / ($this->max - $this->min) * 100);
if ($percent > 100)
$percent = 100;
return $percent;
}
private function _calculatePosition($step)
{
switch ($this->direction)
{
case 'right':
case 'left':
$bar = $this->width;
break;
case 'down':
case 'up':
$bar = $this->height;
break;
}
// avoid divison through 0
if ($this->max - $this->min == 0)
$this->max ++;
$pixel = round(($step - $this->min) * ($bar - ($this->pedding * 2)) / ($this->max - $this->min));
if ($step <= $this->min)
$pixel = 0;
if ($step >= $this->max)
$pixel = $bar - ($this->pedding * 2);
switch ($this->direction)
{
case 'right':
$position['left'] = $this->pedding;
$position['top'] = $this->pedding;
$position['width'] = $pixel;
$position['height'] = $this->height - ($this->pedding * 2);
break;
case 'left':
$position['left'] = $this->width - $this->pedding - $pixel;
$position['top'] = $this->pedding;
$position['width'] = $pixel;
$position['height'] = $this->height - ($this->pedding * 2);
break;
case 'down':
$position['left'] = $this->pedding;
$position['top'] = $this->pedding;
$position['width'] = $this->width - ($this->pedding * 2);
$position['height'] = $pixel;
break;
case 'up':
$position['left'] = $this->pedding;
$position['top'] = $this->height - $this->pedding - $pixel;
$position['width'] = $this->width - ($this->pedding * 2);
$position['height'] = $pixel;
break;
}
return $position;
}
private function _setStep($step)
{
if ($step > $this->max)
$step = $this->max;
if ($step < $this->min)
$step = $this->min;
$this->step = $step;
}
// public functions
public function setFrame($width = 0, $height = 0)
{
$this->frame = array (
'show' => true,
'left' => 20,
'top' => 35,
'width' => $this->width + 6,
'height' => 'auto',
'color' => '#c0c0c0',
'border' => 2,
'brd_color' => '#dfdfdf #404040 #404040 #dfdfdf'
);
if ($width > 0)
$this->frame['width'] = $width;
if ($height > 0)
$this->frame['height'] = $height;
}
public function addLabel($type, $name, $value = ' ')
{
switch($type)
{
case 'text':
$this->label[$name] = array(
'type' => 'text',
'value' => $value,
'left' => 0, // keep all to the left in box
'top' => 2, // default top is 2px
'width' => $this->width,
'height' => 0,
'align' => 'left',
'font-size' => 11,
'font-family' => 'Verdana, Tahoma, Arial',
'font-weight' => 'normal',
'color' => '#000000',
'bgr_color' => ''
);
break;
case 'button':
$this->label[$name] = array(
'type' => 'button',
'value' => $value,
'action' => '',
'target' => 'self',
'left' => 5,
'top' => 5,
'width' => 0,
'height' => 0,
'align' => 'center',
'font-size' => 11,
'font-family' => 'Verdana, Tahoma, Arial',
'font-weight' => 'normal',
'color' => '#000000',
'bgr_color' => ''
);
break;
case 'step':
$this->label[$name] = array(
'type' => 'step',
'value' => $value,
'left' => $this->left + 5,
'top' => $this->top + 5,
'width' => 10,
'height' => 0,
'align' => 'right',
'font-size' => 11,
'font-family' => 'Verdana, Tahoma, Arial',
'font-weight' => 'normal',
'color' => '#000000',
'bgr_color' => ''
);
break;
case 'percentlbl':
case 'percent':
// check font size
if ($this->height <= 11)
$font_size = $this->height - 1;
else
$font_size = 11;
$this->label[$name] = array(
'type' => $type, // either percent or percentlbl
'value' => $value,
'left' => false,
'top' => round(($this->height - $font_size) / log($this->height - $font_size, 7), 0) - $this->pedding,
'width' => $this->width,
'height' => 0,
'align' => 'center',
'font-size' => $font_size,
'font-family' => 'sans-serif',
'font-weight' => 'normal',
'color' => '#000000',
'bgr_color' => ''
);
// print "THIS[$name]: ".$this->label[$name]['left']." | ".$this->label[$name]['width']."
";
break;
case 'crossbar':
$this->label[$name] = array(
'type' => 'crossbar',
'value' => $value,
'left' => $this->left + ($this->width / 2),
'top' => $this->top - 16,
'width' => 10,
'height' => 0,
'align' => 'center',
'font-size' => 11,
'font-family' => 'Verdana, Tahoma, Arial',
'font-weight' => 'normal',
'color' => '#000000',
'bgr_color' => ''
);
break;
}
}
public function addButton($name, $value, $action, $target = 'self')
{
$this->addLabel('button', $name, $value);
$this->label[$name]['action'] = $action;
$this->label[$name]['target'] = $target;
}
public function setLabelPosition($name, $left, $top, $width, $height, $align='')
{
// print "SET POSITION[$name]: $left
";
// if this is percent, we ignore anything, it is auto positioned
if ($this->label[$name]['type'] != 'percent')
{
foreach (array('top', 'left', 'width', 'height') as $pos_name)
if ($$pos_name !== false)
$this->label[$name][$pos_name] = intval($$pos_name);
if ($align != '')
$this->label[$name]['align'] = $align;
}
// init
if ($this->status != 'new')
{
$output = ''."\n";
echo $output;
flush();
}
}
public function setLabelColor($name, $color)
{
$this->label[$name]['color'] = $color;
if ($this->status != 'new')
{
echo ''."\n";
flush();
}
}
public function setLabelBackground($name, $color)
{
$this->label[$name]['bgr_color'] = $color;
if ($this->status != 'new')
{
echo ''."\n";
flush();
}
}
public function setLabelFont($name, $size, $family = '', $weight = '')
{
// just in case if it is too small
if (intval($size) < 0)
$size = 11;
// if this is percent, the size is not allowed to be bigger than the bar size - 5px
if ($this->label[$name]['type'] == 'percent' && intval($size) >= $this->height)
$size = $this->height - 1;
// position the label new if this is percent
if ($this->label[$name]['type'] == 'percent')
$this->label[$name]['top'] = round(($this->height - intval($size)) / log($this->height - intval($size), 7), 0) - $this->pedding;
// print "HEIGHT: ".$this->height.", Size: ".intval($size).", Pedding: ".$this->pedding.", Calc: ".round($this->height - intval($size)).", Log: ".log($this->height - intval($size), 7)."
";
// then set like usual
$this->label[$name]['font-size'] = intval($size);
if ($family != '')
$this->label[$name]['font-family'] = $family;
if ($weight != '')
$this->label[$name]['font-weight'] = $weight;
if ($this->status != 'new')
{
$output = ''."\n";
echo $output;
flush();
}
}
public function setLabelValue($name, $value)
{
$this->label[$name]['value'] = $value;
// print "NAME[$name], Status: ".$this->status.": ".$value."
";
if ($this->status != 'new')
{
echo ''."\n";
flush();
}
}
public function setBarColor($color)
{
$this->color = $color;
if ($this->status != 'new')
{
echo ''."\n";
flush();
}
}
public function setBarBackground($color)
{
$this->bgr_color = $color;
if ($this->status != 'new')
{
echo ''."\n";
flush();
}
}
public function setBarDirection($direction)
{
$this->direction = $direction;
if ($this->status != 'new')
{
$this->position = $this->_calculatePosition($this->step);
echo ''."\n";
flush();
}
}
public function getHtml()
{
$html = '';
$js = '';
$html_button = '';
$this->_setStep($this->step);
$this->position = $this->_calculatePosition($this->step);
if ($this->top || $this->left)
$style_master = 'position:relative;top:'.$this->top.'px;left:'.$this->left.'px;width:'.($this->width + 10).'px;';
$html = '
".print_r($this->label, 1)."