<?php
if (!defined('__ebclass')) {
define('__ebclass', 1);
/**************************************************************************************************
* Class: PHP interface to eB/Charts free/fee WEB Service ( see http://charts.eb-mon.net)
***************************************************************************************************
* Version : 1.0
* Released : 01-04-2004
* Last Modified : 01-04-2004
* Author : miran <hide@address.com>
*
***************************************************************************************************
* Changes
* 20/4/2004 XHTML 1.0 Transitional
* 7/5/2004 additional colors
*
***************************************************************************************************
* Description:
*
* PHP interface to eB/Charts WEB Service
*
***************************************************************************************************
* TODO :
***************************************************************************************************
*
***************************************************************************************************
* USAGE
*
* See example script in documentation chapter of the http://charts.eb-mon.net
*
***************************************************************************************************
* This class LICENCE
*
* The GNU General Public License (GPL) http://www.opensource.org/licenses/gpl-license.html
*
* For any suggestions or bug report please contact : hide@address.com
***************************************************************************************************/
/**************************/
/* Functions in this file */
/**************************/
// add_label($a)
// add_value($a,$b=null)
// add_value_line($a,$b=null,$c=3)
// draw()
// draws()
// enable_3d($a)
// enable_group($a=null)
// enable_headers($a=null)
// enable_spine($a=null)
// enable_stack($a=null)
// get_random($a)
// make_seed()
// set_bg($a)
// set_bg_alt($a)
// set_bm($a)
// set_bot_text($a,$b=null,$c=null)
// set_bt($a,$b=null,$c=null)
// set_colors($a)
// set_color_table($a)
// set_depth($a)
// set_explode($a)
// set_font($a,$b)
// set_gap($a)
// set_img_border($a)
// set_label_class($a='')
// set_lab_font($a,$b)
// set_left_text($a,$b=null,$c=null)
// set_lm($a)
// set_lt($a,$b=null,$c=null)
// set_name($a)
// set_pie($a)
// set_right_text($a,$b=null,$c=null)
// set_rm($a)
// set_rt($a,$b=null,$c=null)
// set_tb_border($a)
// set_th_class($a='')
// set_title($a,$b=null,$c=null)
// set_tm($a)
// set_transparent($a=null)
// show_agr_values($a=null)
// show_horizontal($a=null)
// show_legend($a=null)
// show_percentage($a=null)
// show_symbols($a)
// show_values($a=null)
class chart {
var $m = 1;
var $hid = '';
var $w = 0;
var $h = 0;
var $stre = '';
var $labels = '';
var $headers = 0;
var $title = '';
var $hti = '';
var $bti = '';
var $lti = '';
var $rti = '';
var $htif = '';
var $btif = '';
var $ltif = '';
var $rtif = '';
var $htis = 0;
var $btis = 0;
var $ltis = 0;
var $rtis = 0;
var $border = 0;
var $ct = '';
var $colt = '';
var $font = '';
var $fonts = 0;
var $tbborder = 0;
var $thclass = '';
var $labelclass = '';
var $transparent = 0;
var $dy = Array();
var $dyd = Array();
var $dyc = Array();
var $dyn = 0;
var $ly = Array();
var $lyd = Array();
var $lyc = Array(); // color
var $lys = Array(); // debelina
var $lyn = 0;
var $ls = 0;
var $rs = 0;
var $ts = 0;
var $bs = 0;
var $name = '';
var $refe = '';
//bar specific
var $bga = '';
var $showlegend = 0;
var $ef3d = 0;
var $gap = 0;
var $stack = 0;
var $pe = 0;
var $showvalues = 0;
var $showagrvalues = 0;
//pie specific
var $expl = '';
var $pie_m = 0;
var $depth = 20;
var $label_font = '';
var $label_font_size = '';
//line specific
var $symbols = 0;
var $spine = 0;
//all specific
var $background = '';
var $error = array();
var $hlink = Array();
var $draws = false;
var $color_table = Array();
///////////////////////////////////////////////////////
function Chart($aa, $tip, $w, $h) {
$tip = ltrim(rtrim(strtolower($tip)));
switch ($tip) {
case 'pie' :
$this->tip = 2;
break;
case 'bar' :
$this->tip = 1;
break;
case 'line' :
$this->tip = 3;
break;
case 'combo' :
$this->tip = 4;
break;
case 'radar' :
$this->tip = 5;
break;
case 'trend' :
$this->tip = 6;
break;
case 'step' :
$this->tip = 7;
break;
case 'area' :
$this->tip = 8;
break;
default :
$this->error[] = 1;
}
if ((!is_integer($w)) or (!is_integer($h))) $this->error[] = 2;
$this->refe = $_SERVER['HTTP_REFERER'];
$this->hid = ltrim(rtrim(strtoupper($aa)));
$this->hlink[0] = 'http://charts.eb-mon.net/';
$this->w = $w;
$this->h = $h;
$this->color_table[0] = "0x6666ff,0xffff00,0xff66ff,0x99ffff,0xffcc33,0xcccccc,0xcc9999,0x339966,0x999900,0xcc3300,0x669999,0x993333,0x006600,0x990099,0xff9966,0x99ff99,0x9999ff,0xcc6600,0x33cc33,0xcc99ff,0xff6666,0x99cc66,0x009999,0xcc3333,0x9933ff,0xff0000,0x0000ff,0x00ff00,0xffcc99,0x999999";
$this->color_table[1] = "0x669999,0x993333,0x006600,0x990099,0xff9966,0x99ff99,0x9999ff,0xcc6600,0x33cc33,0xcc99ff,0xff6666,0x99cc66,0x6666ff,0xffff00,0xff66ff,0x99ffff, 0xffcc33,0xcccccc, 0xcc9999,0x339966,0x999900,0xcc3300,0x009999,0xcc3333,0x9933ff,0xff0000,0x0000ff,0x00ff00,0xffcc99,0x999999";
$this->color_table[2] = "0xD6B8D9,0x7D0440,0xCCD29C,0xCD672F,0x8F7DA0,0xE9E497,0xA9A67E,0xD8D7F1,0x5C776B,0x5C1F4D,0xD6B8D9,0xC7D38E,0x93785F,0xCBAC9F,0xEB769A,0xA74F78";
$this->color_table[3] = "0xD6B8D9,0xC7D38E,0x93785F,0xCBAC9F,0xEB769A,0xA74F78,0xE3D782,0xC7555A,0x7D1242,0x51779C,0x82CBD9,0x1A2A67,0xBCCCC1";
$this->color_table[4] = "0xE3D782,0xC7555A,0x7D1242,0x51779C,0x82CBD9,0x1A2A67,0xBCCCC1,0x993300,0x6B5E4F,0x934266,0x629191,0x93928F,0x485EB4,0xB5A689";
$this->color_table[5] = "0x993300,0x6B5E4F,0x934266,0x629191,0x93928F,0x485EB4,0xB5A689,0xFFCC33,0x33FFCC,0x9999FF,0xFF6600,0x00008B,0xCC9900,0x8B0000";
$this->color_table[6] = "0xFFCC33,0x33FFCC,0x9999FF,0xFF6600,0x00008B,0xCC9900,0x8B0000,0xAC0000,0xE76C42,0x99CC99,0xCC3300,0xC6FCFB,0x64BCB7,0x2F3293,0xFF6666,0x339276";
$this->color_table[7] = "0xCC9900,0x8B0000,0xAC0000,0xE76C42,0x99CC99,0xCC3300,0xC6FCFB,0x64BCB7,0x2F3293,0xFF6666,0x339276";
}
/////////////////////////////////////////////////////////////////
function draw() {
if (strlen($this->ct) == 0) $ct1 = $this->get_random(7);
else $ct1 = $this->ct;
$la = explode(",", $this->labels);
if ($this->dy[0]) $ldy = explode(",", $this->dy[0]);
else $ldy = explode(",", $this->ly[0]);
//if (la.length!=ldy.length) haserror=1;
$stre = '';
if ($this->tip == 2) {
if (strlen($this->expl) > 0) $stre .= '&exp='.$this->expl;
// alert(explode);
if (strlen($this->label_font) > 0) $stre .= '&lbf='.$this->label_font;
if (strlen($this->label_font_size) > 0) $stre .= '&lbs='.$this->label_font_size;
if ($this->depth > 0) $stre .= '&dep='.$this->depth;
if ($this->pie_m > 0) $this->m = $this->pie_m;
}
if (($this->tip == 3) || ($this->tip == 7) || ($this->tip == 8)) {
if (strlen($this->bga) > 0) $stre .= '&bga='.urlencode($this->bga);
if ($this->ef3d > 0) $stre .= '&e3='.$this->ef3d;
if ($this->stack > 0) $stre .= '&st='.$this->stack;
if ($this->showvalues > 0) $stre .= '&sv='.$this->showvalues;
if ($this->symbols > 0) $stre .= '&si='.$this->symbols;
if ($this->spine > 0) $stre .= '&sp='.$this->spine;
//if (stack>0) stre.='&st='+stack;
}
if (($this->tip == 8)) {
if ($this->stack > 0) $stre .= '&st='.$this->stack;
}
if (($this->tip == 1) || ($this->tip == 4)) {
if (strlen($this->bga) > 0) $stre .= '&bga='.urldecode($this->bga);
if ($this->ef3d > 0) $stre .= '&e3='.$this->ef3d;
if ($this->gap > 0) $stre .= '&g='.$this->gap;
if ($this->stack > 0) $stre .= '&st='.$this->stack;
if ($this->showvalues > 0) $stre .= '&sv='.$this->showvalues;
if ($this->showagrvalues > 0) $stre .= '&ag='.$this->showagrvalues;
if ($this->pe > 0) $this->m=3;
}
//............................................................
$str .= '<table cellspacing="0" cellpadding="0" width="'.$this->w.'" border="'.$this->tbborder.'">';
//a=title.length;
//alert( title.length + showlegend + headers);
if ( ($this->headers == 0) && ((strlen($this->title) > 0) || ($this->showlegend == 1) ))
$str .= '<tr><th align="center" class="'.$this->thclass.'">'.urldecode($this->title).'</th></tr><tr><td align="center">';
else $str .= '<tr><td align="center">';
//............................................................
$n = 0;
$str .= '<img src="'.$this->hlink[$n].'?draw';
$str .= '&id='.$this->hid;
if ($this->border > 0) {
$this->w = $this->w-3;
$this->h = $this->h-3;
}
if ($this->haserror > 0) $str .= '&err='.$this->haserror;
$str .= '&w='.$this->w;
$str .= '&h='.$this->h;
$str .= '&tip='.$this->tip;
$str .= '&m='.$this->m;
$str .= '&en=p';
$str .= '&ct='.$ct1;
if ($this->ls > 0) $str .= '&ls='.$this->ls;
if ($this->ts > 0) $str .= '&ts='.$this->ts;
if ($this->rs > 0) $str .= '&rs='.$this->rs;
if ($this->bs > 0) $str .= '&bs='.$this->bs;
if (strlen($this->colt) > 0) $str .= '&colt='.$this->colt;
if (strlen($this->font) > 0) $str .= '&f='.$this->font;
if (strlen($this->name) > 0) $str .= '&s='.$this->name;
if ($this->fonts > 0) $str .= '&fs='.$this->fonts;
if (strlen($this->background) > 0) $str .= '&b='.$this->background;
if ($this->transparent > 0) $str .= '&t='.$this->transparent;
if ($this->spine > 0) $str .= '&sp='.$this->spine;
$str .= $stre;
if (gettype($this->labels) == 'array') $a = implode(",", $this->labels);
else $a = $this->labels;
$str .= '&lab='.urlencode($a);
for ($i = 0; $i < $this->dyn; $i++) if ($this->dy[$i]) {
if (gettype($this->dy[$i]) == 'array') $a = implode(",", $this->dy[$i]);
else $a = $this->dy[$i];
$str .= '&dy'.$i.'='.urlencode($a);
}
for ($i = 0; $i < $this->dyn; $i++) if ($this->dyd[$i]) {
if (gettype($this->dyd[$i]) == 'array') $a = implode(",", $this->dyd[$i]);
else $a = $this->dyd[$i];
$str .= '&dyd'.$i.'='.urlencode($a);
}
for ($i = 0; $i < $this->lyn; $i++) if ($this->ly[$i]) {
if (gettype($this->ly[$i]) == 'array') $a = implode(",", $this->ly[$i]);
else $a = $this->ly[$i];
$str .= '&ly'.$i.'='.urlencode($a);
}
for ($i = 0; $i < $this->lyn; $i++) if ($this->lyd[$i]) {
if (gettype($this->lyd[$i]) == 'array') $a = implode(",", $this->lyd[$i]);
else $a = $this->lyd[$i];
$str .= '&lyd'.$i.'='.urlencode($a);
}
for ($i = 0; $i < $this->lyn; $i++) if ($this->lys[$i]) {
if (gettype($this->lys[$i]) == 'array') $a = implode(",", $this->lys[$i]);
else $a = $this->lys[$i];
$str .= '&lys'.$i.'='.urlencode($a);
}
if (strlen($this->title) > 1) if ($this->headers > 0) $str .= '&hti='.$this->title;
//alert(title);
if (strlen($this->bti) > 1) if ($this->headers > 0) $str .= '&bti='.urlencode($this->bti);
if (strlen($this->lti) > 1) if ($this->headers > 0) $str .= '&lti='.urlencode($this->lti);
if (strlen($this->rti) > 1) if ($this->headers > 0) $str .= '&rti='.urlencode($this->rti);
if (strlen($this->rtif) > 1) if ($this->headers > 0) $str .= '&rtif='.urlencode($this->rtif);
if (strlen($this->btif) > 1) if ($this->headers > 0) $str .= '&btif='.urlencode($this->btif);
if (strlen($this->ltif) > 1) if ($this->headers > 0) $str .= '&ltif='.urlencode($this->ltif);
if (strlen($this->htif) > 1) if ($this->headers > 0) $str .= '&htif='.urlencode($this->htif);
if ($this->htis > 0) if ($this->headers > 0) $str .= '&htis='.$this->htis;
if ($this->btis > 0) if ($this->headers > 0) $str .= '&btis='.$this->btis;
if ($this->ltis > 0) if ($this->headers > 0) $str .= '&ltis='.$this->ltis;
if ($this->rtis > 0) if ($this->headers > 0) $str .= '&rtis='.$this->rtis;
$str .= '"';
if ($this->border > 0) $str .= ' border="'.$this->border.'"';
else $str .= ' border="0"';
if (strlen($this->title) > 1) $str .= ' alt="'.urldecode($this->title).'"';
else $str .= ' alt=""';
$str .= ' />';
//............................................................
if ((strlen($this->title) > 1) || ($this->showlegend == 1)) $str .= '</td></tr>';
if (($this->tip == 1) || ($this->tip == 4) || ($this->tip == 3) || ($this->tip == 6) || ($this->tip == 5) || ($this->tip == 8)) if ($this->showlegend == 1) {
$n = 0;
$str .= '<tr><td align="center" class="'.$this->labelclass.'">';
for ($i = 0; $i < $this->dyn; $i++) {
if ($this->dyd[$i]) {
$co = $this->color_table[$ct1];
if (strlen($this->colt) > 0) $co = $this->colt;
$co1 = explode(",", $co);
$tco = $co1[$i];
$tco1 = explode("0x", $tco);
$tco2 = '#'.$tco1[1];
$str .= ' <span style="background-color: '.$tco2.';"> </span> '.$this->dyd[$i].' ';
}
}
for ($ii = 0; $ii < $this->lyn; $ii++) {
if ($this->lyd[$ii]) {
$co = $this->color_table[$ct1];
if (strlen($this->colt) > 0) $co = $this->colt;
$co1 = explode(",", $co);
$ind = $ii+$i;
$tco = $co1[$ind];
$tco1 = explode("0x", $tco);
$tco2 = '#'.$tco1[1];
$str .= ' <span style="background-color: '.$tco2.';"> </span> '.$this->lyd[$ii].' ';
}
}
//$str .= '</td></tr>';
//
}
if ($this->tip == 2) if ($this->showlegend == 1) {
$n = 0;
$llx = explode(",", $this->labels);
$llxn = count($llx);
// alert(llxn);
$str .= '<tr><td align="center" class="'.$this->labelclass.'">';
for ($i = 0; $i < $llxn; $i++) {
if ($llx[$i]) {
$co = $this->color_table[$ct1];
if (strlen($this->colt) > 0) $co = $this->colt;
$co1 = explode(",", $co);
$tco = $co1[$i];
$tco1 = explode("0x", $tco);
$tco2 = '#'.$tco1[1];
$str .= ' <span style="background-color:'.$tco2.';"> </span> '.$llx[$i].' ';
}
}
//$str .= "</td></tr>";
}
// if ((strlen($this->title) > 1) || ($this->showlegend == 1) || $tbset==1)) $str .= "</table>";
$str .= "</td></tr>";
$str .= "</table>";
//............................................................
if ($this->draws) return $str;
else echo $str;
} //end draw
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
function add_label($a) { $this->labels=$a; }
function add_value($a,$b=null) { if ($this->tip==3) $this->add_value_line($a, $b); else { $this->dy[$this->dyn]=$a; $this->dyd[$this->dyn]=$b; $this->dyn++;}}
function add_value_line($a,$b=null,$c=3) { $this->ly[$this->lyn]=$a; $this->lyd[$this->lyn]=$b;$this->lys[$this->lyn]=$c; $this->lyn++;}
function draws() { $this->draws=true; }
function enable_3d($a) { $this->ef3d=$a;}
function enable_group($a=null) { $this->stack=2;}
function enable_headers($a=null) { $this->headers=1;}
function enable_spine($a=null) { $this->spine=1;}
function enable_stack($a=null) { $this->stack=1;}
function get_random($a){ srand($this->make_seed()); return rand(0, $a);}
function make_seed() {list($usec, $sec) = explode(' ', microtime());return (float) $sec + ((float) $usec * 100000);}
function set_bg($a) { if (strstr($a, "#")) $a = str_replace("#", "0x", $a); $this->background=str_replace("0X", "0x", strtoupper($a));}
function set_bg_alt($a) { if (strstr($a, "#")) $a = str_replace("#", "0x", $a); $this->bga=str_replace("0X", "0x", strtoupper($a));}
function set_bm($a) { $this->bs=$a;}
function set_bot_text($a,$b=null,$c=null) { $this->bti=$a; if ($b) $this->btif=$b; if ($c) $this->btis=$c;}
function set_bt($a,$b=null,$c=null) {$this->bti=$a; if ($b) $this->btif=$b; if ($c) $this->btis=$c;}
function set_color_table($a) { if (strstr($a, "#")) $a = str_replace("#", "0x", $a); $this->colt=str_replace("0X", "0x", strtoupper(str_replace(" ","",$a)));}
function set_colors($a) { $this->ct=$a;}
function set_depth($a) { $this->depth=$a;}
function set_label_class($a='') { $this->labelclass=$a;}
function set_th_class($a='') { $this->thclass=$a;}
function set_explode($a) { $this->expl=$a;}
function set_font($a,$b) { $this->font=$a; $this->fonts=$b; }
function set_gap($a) { $this->gap=$a;}
function set_img_border($a) { $this->border=$a;}
function set_lab_font($a,$b) { $this->label_font=$a; if ($b) $this->label_font_size=$b;}
function set_left_text($a,$b=null,$c=null) { $this->lti=$a; if ($b) $this->ltif=$b; if ($c) $this->ltis=$c;}
function set_lm($a) { $this->ls=$a;}
function set_lt($a,$b=null,$c=null) { $this->lti=$a; if ($b) $this->ltif=$b; if ($c) $this->ltis=$c;}
function set_name($a) { $this->name=$a;}
function set_right_text($a,$b=null,$c=null) { $this->rti=$a; if ($b) $this->rtif=$b; if ($c) $this->rtis=$c;}
function set_rm($a) { $this->rs=$a;}
function set_pie($a) { $this->pie_m=$a;}
function set_rt($a,$b=null,$c=null) { $this->rti=$a; if ($b) $this->rtif=$b; if ($c) $this->rtis=$c;}
function set_tb_border($a) { $this->tbborder=$a;}
function set_title($a,$b=null,$c=null) { $this->title=urlencode($a); if ($b) $this->htif=$b; if ($c) $this->htis=$c;}
function set_tm($a) { $this->ts=$a;}
function set_transparent($a=null) { $this->transparent=1;}
function show_agr_values($a=null) { $this->showagrvalues=1;}
function show_horizontal($a=null) { $this->m=2;}
function show_legend($a=null) { $this->showlegend=1;}
function show_percentage($a=null) { $this->pe=1;}
function show_symbols($a) { $this->symbols=$a;}
function show_values($a=null) { $this->showvalues=1;}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
} // end class
} // end define
?>