| Server IP : 87.98.154.146 / Your IP : 216.73.216.101 Web Server : Apache System : Linux webm005.cluster126.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64 User : bsiadvisil ( 110003) PHP Version : 7.3.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/bsiadvisil/old/plugins/content/rgraph/lib/ |
Upload File : |
<?php
/**
* @filesource: rgraph-chart.php
*
* @package rgraph Joomla! Plugin
* @version Version 1
* @author Joachim Schmidt - joachim.schmidt@jschmidt-systemberatung.de
* @copyright (C) 2016 Joachim Schmidt. All rights reserved.
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*
* @abstract: json php-helper class for rgraph charts package
*
*/
defined('_JEXEC') or die('Restricted access');
include_once 'rgraph_options.php';
class plg_rgraph_chart
{
private $scripts = array(
"bar" => "RGraph.bar.js",
"bipolar" => "RGraph.bipolar.js",
"annotate" => "RGraph.common.annotate.js",
"contextmenu" => "RGraph.common.context.js",
"core" => "RGraph.common.core.js",
"csv" => "RGraph.common.csv.js",
"dynamic" => "RGraph.common.dynamic.js",
"tooltips" => "RGraph.common.dynamic.js",
"effects" => "RGraph.common.effects.js",
"key" => "RGraph.common.key.js",
"resizing" => "RGraph.common.resizing.js",
"tooltips" => "RGraph.common.tooltips.js",
"zoom" => "RGraph.common.zoom.js",
"cornergauge" => "RGraph.cornergauge.js",
// "background" => "RGraph.drawing.background.js",
// "circle" => "RGraph.drawing.circle.js",
// "image" => "RGraph.drawing.image.js",
// "marker1" => "RGraph.drawing.marker1.js",
// "marker2" => "RGraph.drawing.marker2.js",
// "marker3" => "RGraph.drawing.marker3.js",
// "poly" => "RGraph.drawing.poly.js",
"keyinteractive" => "RGraph.drawing.rect.js",
"rect" => "RGraph.drawing.rect.js",
// "text" => "RGraph.drawing.text.js",
// "xaxis" => "RGraph.drawing.xaxis.js",
// "yaxis" => "RGraph.drawing.yaxis.js",
"fuel" => "RGraph.fuel.js",
"funnel" => "RGraph.funnel.js",
"gantt" => "RGraph.gantt.js",
"gauge" => "RGraph.gauge.js",
"hbar" => "RGraph.hbar.js",
// "hprogess" => "RGraph.hprogress.js",
"line" => "RGraph.line.js",
"meter" => "RGraph.meter.js",
// "modaldialog" => "RGraph.modaldialog.js",
"odometer" => "RGraph.odo.js",
"pie" => "RGraph.pie.js",
"radar" => "RGraph.radar.js",
"rose" => "RGraph.rose.js",
"rscatter" => "RGraph.rscatter.js",
"scatter" => "RGraph.scatter.js",
"bubble" => "RGraph.scatter.js",
// "thermometer" => "RGraph.thermometer.js",
// "vprogress" => "RGraph.vprogress.js",
"waterfall" => "RGraph.waterfall.js"
);
private $valid_chart_types = array(
"Bar",
"HBar",
"Bipolar",
"Bubble",
"Line",
"Pie",
"Donut",
"Fuel",
"Funnel",
"Gauge",
"Gantt",
"CornerGauge",
"Meter",
"Odometer",
"Radar",
"Rose",
"Rscatter",
"Scatter",
"Waterfall"
);
function __construct ($id, $data = null, $chart_type = "Bar")
{
$this->rgraph_chart($id, $data, $chart_type);
}
function rgraph_chart ($id, $data, $chart_type)
{
if ($this->isValidType($chart_type))
$this->chart_type = $chart_type;
else
$this->chart_type = "Bar";
$this->id = $id;
if ($data != null)
$this->set_data($data);
}
function set_id ($id)
{
$this->id = $id;
}
function get_id ()
{
return ($this->id);
}
function set_data ($data)
{
if (! is_array($data))
return - 1;
$this->data = $data;
return true;
}
function get_data ()
{
return $this->data;
}
function set_left ($left)
{
if (! is_array($left))
return - 1;
$this->left = $left;
return true;
}
function set_right ($right)
{
if (! is_array($right))
return - 1;
$this->right = $right;
return true;
}
function get_left ($left)
{
return $this->left;
}
function get_right ($left)
{
return $this->right;
}
function set_min ($min)
{
if (! is_numeric($min))
return - 1;
$this->min = $min;
return true;
}
function get_min ($min)
{
return $this->min;
}
function set_max ($max)
{
if (! is_numeric($max))
return - 1;
$this->max = $max;
return true;
}
function get_max ($max)
{
return $this->max;
}
function set_value ($val)
{
if (! is_numeric($val))
return - 1;
$this->value = $val;
return true;
}
function get_value ($val)
{
return $this->value;
}
function set_chartType ($type)
{
if ($this->isValidType($type))
{
$this->chart_type = $type;
return true;
}
return false;
}
function get_chartType ()
{
return $this->chart_type;
}
private function isValidType ($type)
{
for ($i = 0; $i < count($this->valid_chart_types); $i ++)
{
if ($type == $this->valid_chart_types[$i])
return true;
}
return false;
}
public function getScript ($type)
{
$type = strtolower($type);
foreach ($this->scripts as $key => $script)
{
if ($key == $type)
{
return $script;
break;
}
}
return - 1;
}
public function rearrangeData ($update = true)
{
if (! is_array($this->data[0]))
return $this->data;
$k = 0;
$result = array();
$tmp = array();
for ($i = 0; $i < count($this->data[0]); $i ++)
{
for ($j = 0; $j < count($this->data); $j ++)
{
$tmp[$j] = $this->data[$j][$i];
}
$result[$k] = $tmp;
$k ++;
}
if ($update === true)
$this->data = $result;
return $result;
}
public static function getChartScript ($file)
{
if (! file_exists($file))
return null;
if (! function_exists('file_get_contents'))
{
$fp = fopen($file, "r");
$content = fgets($fp);
fclose($fp);
}
else
{
$content = trim(file_get_contents($file));
}
return $content;
}
public static function getEventScript ($file)
{
if (! file_exists($file))
return null;
if (! function_exists('file_get_contents'))
{
$fp = fopen($file, "r");
$content = fgets($fp);
fclose($fp);
}
else
{
$content = trim(file_get_contents($file));
}
return $content;
}
public static function getDataFromFile ($file)
{
$OK = false;
if (file_exists($file))
{
if (! function_exists('file_get_contents'))
{
$fp = fopen($file, "r");
$content = fgets($fp);
fclose($fp);
}
else
{
$content = trim(file_get_contents($file));
}
$OK = true;
}
if ($OK == false)
return - 1;
return json_decode($content, true);
}
public static function getDataFromUrl ($url)
{
if (function_exists('file_get_contents'))
{
$content = trim(file_get_contents($url));
}
elseif (function_exists('curl_init'))
{
$fp = curl_init($url);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fp, CURLOPT_HEADER, 0);
$content = trim(curl_exec($fp));
curl_close($fp);
}
else
return - 1;
if ($content !== null)
return json_decode($content, true);
return - 1;
}
public static function getsheetsData ($key, $lines, $keep_keys = true)
{
$feed = "https://docs.google.com/spreadsheet/pub?hl=en_US&hl=en_US&key=$key&single=true&gid=0&output=csv";
$keys = array();
$newArray = array();
$data = array();
if (($handle = fopen($feed, 'r')) !== FALSE)
{
$i = 0;
while (($lineArray = fgetcsv($handle, 4000, ',', '"')) !== FALSE && $lines >= $i)
{
for ($j = 0; $j < count($lineArray); $j ++)
{
$data[$i][$j] = $lineArray[$j];
}
$i ++;
}
fclose($handle);
}
else
return - 1;
if ($keep_keys)
{
$columns = array();
$count = count($data) - 1;
$labels = array_shift($data);
$i = 0;
foreach ($labels as $label)
{
if ($label == null)
$label = $i;
$keys[] = $label;
$i ++;
}
for ($j = 0; $j < $count; $j ++)
{
$d = array_combine($keys, $data[$j]);
$newArray[$j] = $d;
}
for ($i = 0; $i < count($keys); $i ++)
$columns[$keys[$i]] = array_column($newArray, $keys[$i]);
}
else
{
for ($i = 0; $i < count($data[0]); $i ++)
$columns[$i] = array_column($data, $i);
}
foreach ($columns as $key => $values)
{
foreach ($values as $key2 => $value)
{
if (is_numeric($value))
settype($value, "double");
$columns[$key][$key2] = $value;
if ($value == "")
$columns[$key][$key2] = null;
}
}
return $columns;
}
public static function set_numeric ($data, $type = "float")
{
if (! is_array($data[0]))
{
for ($i = 0; $i < count($data); $i ++)
{
if (is_numeric($data[$i]))
settype($data[$i], $type);
elseif ($data[$i] === "")
$data[$i] = null;
}
}
else
{
for ($i = 0; $i < count($data); $i ++)
for ($j = 0; $j < count($data[$i]); $j ++)
{
if (is_numeric($data[$i][$j]))
settype($data[$i][$j], $type);
elseif ($data[$i][$j] === "")
$data[$i][$j] = null;
}
}
return $data;
}
public static function getDataFromDB ($connection, $sql)
{
mysqli_query($connection, "SET NAMES 'utf8'");
$result = mysqli_query($connection, $sql);
$type = array();
$data = array();
if ($result == false)
{
return false;
}
else
{
$cols = mysqli_num_fields($result);
for ($i = 0; $i < $cols; $i ++)
{
$fieldinfo = mysqli_fetch_field_direct($result, $i);
switch ($fieldinfo->type)
{
case 1:
case 2:
case 3:
case 8:
case 9:
$type[$i] = "integer";
break;
case 246:
case 4:
$type[$i] = "float";
break;
case 5:
$type[$i] = "double";
break;
default:
$type[$i] = "string";
}
}
}
if (mysqli_num_rows($result) == 0)
return "-1";
for ($i = 0; $i < $cols; $i ++)
$data[$i] = array();
$row = mysqli_fetch_row($result);
while ($row)
{
for ($i = 0; $i < $cols; $i ++)
{
settype($row[$i], $type[$i]);
array_push($data[$i], $row[$i]);
}
$row = mysqli_fetch_row($result);
}
mysqli_free_result($result);
return $data;
}
public static function getCSVdata ($csv_file, $header_lines = 0, $sepchar = ";", $cols = null)
{
$data = array();
if (isset($cols))
array_unshift($cols, 0);
if (($handle = fopen($csv_file, "r")) !== FALSE)
{
$init_done = false;
while (($csv_data = fgetcsv($handle, 1000, $sepchar)) !== FALSE)
{
if ($header_lines <= 0)
{
if ($init_done == false)
{
$num = count($csv_data);
if (empty($cols))
{
for ($i = 0; $i < $num; $i ++)
$cols[$i] = $i;
}
for ($i = 0; $i < count($cols); $i ++)
$data[$i] = array();
$init_done = true;
}
$k = 0;
for ($c = 0; $c < $num; $c ++)
{
if (strpos($csv_data[$c], ",") !== false)
$csv_data[$c] = str_replace(",", ".", $csv_data[$c]);
if (is_numeric($csv_data[$c]))
settype($csv_data[$c], "float");
if ($k < count($cols))
{
if ($c == $cols[$k])
{
array_push($data[$k], $csv_data[$c]);
$k ++;
}
}
}
}
$header_lines --;
}
fclose($handle);
return $data;
}
else
return "-1";
}
public static function createScatterData ($x_values, $y_values, $color = null, $tooltip = null)
{
if (! is_array($x_values) && ! is_array($y_values))
return null;
$data = array();
for ($i = 0; $i < count($x_values); $i ++)
{
if (! isset($color[$i]))
$color[$i] = null;
if (! isset($tooltip[$i]))
$tooltip[$i] = null;
if (! isset($y_values[$i]))
$y_values[$i] = null;
$data[$i] = array(
$x_values[$i],
$y_values[$i],
(string) $color[$i],
(string) $tooltip[$i]
);
}
return $data;
}
function set_options ($options)
{
$this->options = $options;
}
function toString ()
{
if (function_exists('json_encode'))
{
ini_set('serialize_precision', -1);
$string = json_encode($this);
$trans = array(
'"JAVA_VAR' => "",
'JAVA_VAR"' => "",
'QQ' => '"',
'<\/' => '</'
);
$string = strtr($string, $trans);
return $string;
}
else
return null;
}
function toPrettyString ()
{
return $this->my_json_format($this->toString());
}
private function my_json_format ($json)
{
$tab = " ";
$new_json = "";
$indent_level = 0;
$in_string = false;
$len = strlen($json);
for ($c = 0; $c < $len; $c ++)
{
$char = $json[$c];
switch ($char)
{
case '{':
case '[':
if (! $in_string)
{
$new_json .= $char . "\n" . str_repeat($tab, $indent_level + 1);
$indent_level ++;
}
else
{
$new_json .= $char;
}
break;
case '}':
case ']':
if (! $in_string)
{
$indent_level --;
$new_json .= "\n" . str_repeat($tab, $indent_level) . $char;
}
else
{
$new_json .= $char;
}
break;
case ',':
if (! $in_string)
{
$new_json .= ",\n" . str_repeat($tab, $indent_level);
}
else
{
$new_json .= $char;
}
break;
case ':':
if (! $in_string)
{
$new_json .= ": ";
}
else
{
$new_json .= $char;
}
break;
case '"':
if ($c > 0 && $json[$c - 1] != '\\')
{
$in_string = ! $in_string;
}
default:
$new_json .= $char;
break;
}
}
return $new_json;
}
}
?>