diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index fbca58b6db..da9f784623 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2011-04-14 Miguel de Dios + + * include/functions_graph.php: added function "graph_custom_sql_graph2". + + * include/graphs/fgraph.php: added as $homedir parameter in some functions. + + * include/functions_reporting.php: changed to new engine. + 2011-04-14 Sergio Martin * include/graphs/functions_pchart.php diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 734d58cad1..177db560f2 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1223,4 +1223,66 @@ function grafico_eventos_usuario2 ($width, $height) { return pie3d_graph($config['flash_charts'], $data, $width, $height); } + +/** + * Print a custom SQL-defined graph + * + * @param integer ID of report content, used to get SQL code to get information for graph + * @param integer height graph height + * @param integer width graph width + * @param integer Graph type 1 vbar, 2 hbar, 3 pie + */ +function graph_custom_sql_graph2 ($id, $width, $height, $type = 'sql_graph_vbar', $only_image = false, $homedir) { + global $config; + + $report_content = get_db_row ('treport_content', 'id_rc', $id); + if ($report_content["external_source"] != ""){ + $sql = safe_output ($report_content["external_source"]); + } + else { + $sql = get_db_row('treport_custom_sql', 'id', $report_content["treport_custom_sql_id"]); + $sql = safe_output($sql['sql']); + } + + $data_result = get_db_all_rows_sql ($sql); + + if ($data_result === false) + $data_result = array (); + + $data = array (); + + $count = 0; + foreach ($data_result as $data_item) { + $count++; + switch ($type) { + case 'sql_graph_vbar': // vertical bar + $data[$data_item["label"]]['g'] = $data_item["value"]; + break; + case 'sql_graph_hbar': // horizontal bar + $data[$data_item["label"]]['g'] = $data_item["value"]; + break; + case 'sql_graph_pie': // Pie + $data[$data_item["label"]] = $data_item["value"]; + break; + } + } + + $flash_charts = $config['flash_charts']; + + if ($only_image) { + $flash_charts = false; + } + + switch ($type) { + case 'sql_graph_vbar': // vertical bar + return hbar_graph($flash_charts, $data, $width, $height, array(), array(), "", "", false, $homedir); + break; + case 'sql_graph_hbar': // horizontal bar + return vbar_graph($flash_charts, $data, $width, $height, array(), array(), "", "", $homedir); + break; + case 'sql_graph_pie': // Pie + return pie3d_graph($flash_charts, $data, $width, $height, __("other"), $homedir); + break; + } +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6bfc564122..702462f302 100644 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -2423,8 +2423,8 @@ function render_report_html_item ($content, $table, $report, $mini = false) { } $data = array (); - - $data[0] = ''; + + $data[0] = graph_custom_sql_graph2($content["id_rc"], $sizgraph_w, 200, $content["type"], true); array_push($table->data, $data); break; diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 739eda7e86..c36efdef51 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -10,6 +10,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. + // If is called from index if(file_exists('include/functions.php')) { include_once('include/functions.php'); @@ -105,7 +106,8 @@ function slicesbar_graph($chart_data, $width, $height, $colors, $font, $round_co return ""; } -function vbar_graph($flash_chart, $chart_data, $width, $height, $color = array(), $legend = array(), $xaxisname = "", $yaxisname = "") { +function vbar_graph($flash_chart, $chart_data, $width, $height, $color = array(), + $legend = array(), $xaxisname = "", $yaxisname = "", $homedir="") { if($flash_chart) { echo fs_2d_column_chart ($chart_data, $width, $height); } @@ -121,7 +123,7 @@ function vbar_graph($flash_chart, $chart_data, $width, $height, $color = array() $id_graph = serialize_in_temp($graph); - echo ""; + return ""; } } @@ -260,7 +262,8 @@ function polar_graph($flash_chart, $chart_data, $width, $height, $no_data_image) return kiviat_graph('polar', $flash_chart, $chart_data, $width, $height, $no_data_image); } -function hbar_graph($flash_chart, $chart_data, $width, $height, $color = array(), $legend = array(), $xaxisname = "", $yaxisname = "", $force_height = true) { +function hbar_graph($flash_chart, $chart_data, $width, $height, $color = array(), + $legend = array(), $xaxisname = "", $yaxisname = "", $force_height = true, $homedir="") { if($flash_chart) { echo fs_hbar_chart (array_values($chart_data), array_keys($chart_data), $width, $height); } @@ -277,19 +280,19 @@ function hbar_graph($flash_chart, $chart_data, $width, $height, $color = array() $id_graph = serialize_in_temp($graph); - echo ""; + return ""; } } -function pie3d_graph($flash_chart, $chart_data, $width, $height, $others_str = "other") { - return pie_graph('3d', $flash_chart, $chart_data, $width, $height, $others_str); +function pie3d_graph($flash_chart, $chart_data, $width, $height, $others_str = "other", $homedir="") { + return pie_graph('3d', $flash_chart, $chart_data, $width, $height, $others_str, $homedir); } -function pie2d_graph($flash_chart, $chart_data, $width, $height, $others_str = "other") { - return pie_graph('2d', $flash_chart, $chart_data, $width, $height, $others_str); +function pie2d_graph($flash_chart, $chart_data, $width, $height, $others_str = "other", $homedir="") { + return pie_graph('2d', $flash_chart, $chart_data, $width, $height, $others_str, $homedir); } -function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, $others_str) { +function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, $others_str = "other", $homedir="") { // This library allows only 8 colors $max_values = 8; @@ -331,10 +334,10 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, $oth switch($graph_type) { case "2d": - return ""; + return ""; break; case "3d": - return ""; + return ""; break; } }