From ef16b40894fd0f55420bc61e1a64c2fbf39586b9 Mon Sep 17 00:00:00 2001
From: zarzuelo <zarzuelo@gmail.com>
Date: Thu, 28 Oct 2010 11:31:12 +0000
Subject: [PATCH] 2010-10-28  Sergio Martin <sergio.martin@artica.es>

	* include/functions_custom_graphs.php
	godmode/reporting/graph_builder.preview.php: Fixed various bugs when
	you try to render a custom graph without modules for bug 3096434



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3476 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                        |  6 ++++++
 .../godmode/reporting/graph_builder.preview.php  | 16 +++++++++++-----
 .../include/functions_custom_graphs.php          |  6 ++++++
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 5c70ad727e..162fb610a1 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,9 @@
+2010-10-28  Sergio Martin <sergio.martin@artica.es>
+
+	* include/functions_custom_graphs.php
+	godmode/reporting/graph_builder.preview.php: Fixed various bugs when
+	you try to render a custom graph without modules for bug 3096434
+
 2010-10-28  Sergio Martin <sergio.martin@artica.es>
 
 	* include/functions_io.php
diff --git a/pandora_console/godmode/reporting/graph_builder.preview.php b/pandora_console/godmode/reporting/graph_builder.preview.php
index 7806cc46f2..ca3b3ad71f 100644
--- a/pandora_console/godmode/reporting/graph_builder.preview.php
+++ b/pandora_console/godmode/reporting/graph_builder.preview.php
@@ -96,11 +96,17 @@ $weights = implode(',', $weight_array);
 	$graph_width = get_db_sql ("SELECT width FROM tgraph WHERE id_graph = ".$id);
 	$graph_height= get_db_sql ("SELECT height FROM tgraph WHERE id_graph = ".$id);
 	
-	if ($config['flash_charts']) {
-		echo graphic_combined_module (explode (',', $modules), explode (',', $weights), $period, $graph_width, $graph_height,
-				'Combined%20Sample%20Graph', '', $events, 0, 0, $stacked);
-	} else {
-		echo "<img src='include/fgraph.php?tipo=combined&id=$modules&weight_l=$weights&label=Combined%20Sample%20Graph&height=$height&width=$width&stacked=$stacked&period=$period' border=1 alt=''>";
+	if(!empty($modules)) {
+		if ($config['flash_charts']) {
+			echo graphic_combined_module (explode (',', $modules), explode (',', $weights), $period, $graph_width, $graph_height,
+					'Combined%20Sample%20Graph', '', $events, 0, 0, $stacked);
+		} else {
+			echo "<img src='include/fgraph.php?tipo=combined&id=$modules&weight_l=$weights&label=Combined%20Sample%20Graph&height=$height&width=$width&stacked=$stacked&period=$period' border=1 alt=''>";
+		}
 	}
+	else {
+		echo "<div class='nf'>".__('Empty graph')."</div>";
+	}
+
 	echo "</td></tr></table>";
 
diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php
index 84f62dc731..f80b9733bd 100644
--- a/pandora_console/include/functions_custom_graphs.php
+++ b/pandora_console/include/functions_custom_graphs.php
@@ -89,6 +89,12 @@ function print_custom_graph ($id_graph, $height, $width, $period, $stacked, $ret
 	$sources = get_db_all_rows_field_filter ('tgraph_source', 'id_graph', $id_graph);
 	$modules = array ();
 	$weights = array ();
+	
+	if($sources === false) {
+		echo "<div class='nf'>".__('Empty graph')."</div>";
+		return;
+	}
+	
 	foreach ($sources as $source) {
 		array_push ($modules, $source['id_agent_module']);
 		array_push ($weights, $source['weight']);