From 02b4d22ad94a5c3566a2311fbb93c9a24d392083 Mon Sep 17 00:00:00 2001
From: mdtrooper <tres.14159@gmail.com>
Date: Wed, 20 Apr 2011 14:22:40 +0000
Subject: [PATCH] 2011-04-20 Miguel de Dios  <miguel.dedios@artica.es>

	* include/functions_graph.php, include/graphs/functions_pchart.php,
	include/fgraph.php, operation/agentes/stat_win.php: fixed duplicate
	functions, and start to support custom font in Pandora connector.

	* index.php: fixed when include again the extension file.

	* include/functions_html.php: fixed when include this file in other
	location to index.

	* godmode/reporting/graph_builder.preview.php: cleaned source code style.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4268 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     | 13 +++
 .../reporting/graph_builder.preview.php       |  2 -
 pandora_console/include/fgraph.php            |  8 +-
 pandora_console/include/functions_graph.php   | 79 +++++++------------
 pandora_console/include/functions_html.php    | 11 +++
 .../include/graphs/functions_pchart.php       |  6 +-
 pandora_console/index.php                     |  2 +-
 .../operation/agentes/stat_win.php            |  2 +-
 8 files changed, 64 insertions(+), 59 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 4c90d901dd..2abeaf7bc3 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,16 @@
+2011-04-20 Miguel de Dios  <miguel.dedios@artica.es>
+	
+	* include/functions_graph.php, include/graphs/functions_pchart.php,
+	include/fgraph.php, operation/agentes/stat_win.php: fixed duplicate
+	functions, and start to support custom font in Pandora connector.
+
+	* index.php: fixed when include again the extension file.
+	
+	* include/functions_html.php: fixed when include this file in other
+	location to index.
+
+	* godmode/reporting/graph_builder.preview.php: cleaned source code style.
+
 2011-04-20 Javier Lanz <javier.lanz@artica.es>
 
 	* godmode/alerts/configure_alert_action.php: Fixed a small bug about
diff --git a/pandora_console/godmode/reporting/graph_builder.preview.php b/pandora_console/godmode/reporting/graph_builder.preview.php
index eea8fede12..606c20821a 100644
--- a/pandora_console/godmode/reporting/graph_builder.preview.php
+++ b/pandora_console/godmode/reporting/graph_builder.preview.php
@@ -138,8 +138,6 @@ echo "<tr><td>";
 
 if(!empty($modules)) {
 	require_once ($config["homedir"] . '/include/functions_graph.php');
-
-	
 	
 	echo graphic_combined_module2(explode (',', $modules), explode (',', $weights), $period, $width, $height,
 				'Combined%20Sample%20Graph', '', $events, 0, 0, $stacked, $unixdate);
diff --git a/pandora_console/include/fgraph.php b/pandora_console/include/fgraph.php
index 3fa5ab62f9..21e759c1bb 100644
--- a/pandora_console/include/fgraph.php
+++ b/pandora_console/include/fgraph.php
@@ -916,7 +916,7 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
 	$events = db_get_all_rows_sql ($sql);
 	if ($events === false) {
 		if (! $graphic_type) {
-			return fs_error_image ();
+			return fs_error_image2 ();
 		}
 		graphic_error ();
 		return;
@@ -1343,7 +1343,7 @@ function grafico_modulo_sparse ($agent_module_id, $period, $show_events,
 	// Check available data
 	if (count ($data) < $min_necessary) {
 		if (!$graphic_type) {
-			return fs_error_image ();
+			return fs_error_image2 ();
 		}
 		graphic_error ();
 	}
@@ -1599,7 +1599,7 @@ function grafico_modulo_boolean ($agent_module_id, $period, $show_events,
 	// Check available data
 	if (count ($data) < $min_necessary) {
 		if (!$graphic_type) {
-			return fs_error_image ();
+			return fs_error_image2 ();
 		}
 		graphic_error ();
 	}
@@ -1860,7 +1860,7 @@ function grafico_modulo_string ($agent_module_id, $period, $show_events,
 	// Check available data
 	if (count ($data) < $min_necessary) {
 		if (!$graphic_type) {
-			return fs_error_image ();
+			return fs_error_image2 ();
 		}
 		graphic_error ();
 	}
diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php
index 906ae6e28f..a361858d6e 100755
--- a/pandora_console/include/functions_graph.php
+++ b/pandora_console/include/functions_graph.php
@@ -107,7 +107,7 @@ function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events,
 	// Check available data
 	if (count ($data) < $min_necessary) {
 		if (!$graphic_type) {
-			return fs_error_image ();
+			return fs_error_image2 ();
 		}
 		graphic_error ();
 	}
@@ -731,7 +731,7 @@ function graph_event_module2 ($width = 300, $height = 200, $id_agent) {
 	$events = db_get_all_rows_sql ($sql);
 	if ($events === false) {
 		if (! $graphic_type) {
-			return fs_error_image ();
+			return fs_error_image2 ();
 		}
 		graphic_error ();
 		return;
@@ -1401,7 +1401,7 @@ function fs_agent_event_chart2 ($data, $width, $height, $step = 1) {
 	global $config;
 
 	if (sizeof ($data) == 0) {
-		return fs_error_image ();
+		return fs_error_image2 ();
 	}
 
 	// Generate the XML
@@ -1425,27 +1425,8 @@ function fs_agent_event_chart2 ($data, $width, $height, $step = 1) {
 	return get_chart_code2 ($chart, $width, $height, 'include/FusionCharts/FCF_Area2D.swf');
 }
 
-// Returns the code needed to display the chart
-function get_chart_code2 ($chart, $width, $height, $swf) {
-	$random_number = rand ();
-	$div_id = 'chart_div_' . $random_number;
-	$chart_id = 'chart_' . $random_number;
-	$output = '<div id="' . $div_id. '"></div>';
-	$output .= '<script type="text/javascript">
-			<!--
-				$(document).ready(function pie_' . $chart_id . ' () {
-					var myChart = new FusionCharts("' . $swf . '", "' . $chart_id . '", "' . $width. '", "' . $height. '", "0", "1");
-					myChart.setDataXML("' . addslashes($chart->getXML ()) . '");
-					myChart.addParam("WMode", "Transparent");
-					myChart.render("' . $div_id . '");
-				})
-			-->
-			</script>';
-	return $output;
-}
-
 // Prints an error image
-function fs_error_image () {
+function fs_error_image2 () {
 	global $config;
 
 	return print_image("images/image_problem.png", true, array("border" => '0'));
@@ -1530,7 +1511,7 @@ function grafico_modulo_boolean2 ($agent_module_id, $period, $show_events,
 	// Check available data
 	if (count ($data) < $min_necessary) {
 		if (!$graphic_type) {
-			return fs_error_image ();
+			return fs_error_image2 ();
 		}
 		graphic_error ();
 	}
@@ -1843,7 +1824,7 @@ function grafico_modulo_string2 ($agent_module_id, $period, $show_events,
 	// Check available data
 	if (count ($data) < $min_necessary) {
 		if (!$graphic_type) {
-			return fs_error_image ();
+			return fs_error_image2 ();
 		}
 		graphic_error ();
 	}
@@ -1983,7 +1964,7 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
 	 $date = 0) 
 {
 
-        grafico_modulo_log4x_trace("<pre style='text-align:left;'>");
+        grafico_modulo_log4x_trace2("<pre style='text-align:left;'>");
 
 	if ($date == "")
 		$now = time ();
@@ -2018,7 +1999,7 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
 
         $num_slices = $periodo / $adjust_time;
 
-        $fechatope_index = grafico_modulo_log4x_index($fechatope, $adjust_time);
+        $fechatope_index = grafico_modulo_log4x_index2($fechatope, $adjust_time);
 
         $sql1="SELECT utimestamp, SEVERITY " .
                 " FROM tagente_datos_log4x " .
@@ -2029,7 +2010,7 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
         $max_count = -1;
         $min_count = 9999999;
 
-        grafico_modulo_log4x_trace("$sql1");
+        grafico_modulo_log4x_trace2("$sql1");
 
         $rows = 0;
         
@@ -2045,7 +2026,7 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
                 if (!isset($valores[$severity]))
                         $valores[$severity] = array();
 
-                $dest = grafico_modulo_log4x_index($utimestamp, $adjust_time);
+                $dest = grafico_modulo_log4x_index2($utimestamp, $adjust_time);
 
                 $index = (($dest - $fechatope_index) / $adjust_time) - 1;
 
@@ -2062,25 +2043,25 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
                 $min_count = min($min_count, $valores[$severity][$index]['count']);
        }
 
-        grafico_modulo_log4x_trace("$rows rows");
+        grafico_modulo_log4x_trace2("$rows rows");
 
         // Create graph
         // *************
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 
 	//set_error_handler("myErrorHandler");
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 	set_include_path(get_include_path() . PATH_SEPARATOR . getcwd() . "/../../include");
 
 	require_once 'Image/Graph.php';
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 
         $Graph =& Image_Graph::factory('graph', array($width, $height));
  
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 
 
 
@@ -2114,7 +2095,7 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
 
         $title_period = html_entity_decode($title_period);
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 
         if ($pure == 0){
                 $Graph->add(
@@ -2144,7 +2125,7 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
                 $Graph->add($Plotarea = Image_Graph::factory('plotarea', array('Image_Graph_Axis', 'Image_Graph_Axis')));
         }
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 
         $dataset = array();
 
@@ -2169,7 +2150,7 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
                                 $x = 100.0 * ($pivot - $fechatope) / ($now - $fechatope);
                                 if ($x > 100) $x = 100;
 
-                                $size = grafico_modulo_log4x_bubble_size($count, $max_count, $max_bubble_radius);
+                                $size = grafico_modulo_log4x_bubble_size2($count, $max_count, $max_bubble_radius);
 
                                 // pivot is the value in the X axis
                                 // y is the number of steps (from the bottom of the graphics) (zero based)
@@ -2189,14 +2170,14 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
                 $i++;
         }
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 
         // create the 1st plot as smoothed area chart using the 1st dataset
         $Plot =& $Plotarea->addNew('bubble', array(&$dataset));
         $Plot->setFont($Font);
 
         $AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
-        $AxisX->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'grafico_modulo_log4x_format_x_axis'));
+        $AxisX->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'grafico_modulo_log4x_format_x_axis2'));
         $AxisX->forceMinimum($fechatope);
         $AxisX->forceMaximum($now);
 
@@ -2222,10 +2203,10 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
         //$GridY2->setLineStyle(Image_Graph::factory('Image_Graph_Line_Dotted', array("white", "gray", "gray", "gray")));
         $GridY2->setLineStyle(Image_Graph::factory('Image_Graph_Line_Formatted', array(array("transparent", "transparent", "transparent", "gray"))));
         //*/
-        //grafico_modulo_log4x_trace(print_r($AxisX, true));
+        //grafico_modulo_log4x_trace2(print_r($AxisX, true));
 
         $AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
-        $AxisY->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'grafico_modulo_log4x_format_y_axis'));
+        $AxisY->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'grafico_modulo_log4x_format_y_axis2'));
         $AxisY->setLabelOption("showtext",true);
         //$AxisY->setLabelInterval(0);
         //$AxisY->showLabel(IMAGE_GRAPH_LABEL_ZERO);
@@ -2248,7 +2229,7 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
         foreach($colors as $color)
                 $FillArray->addColor($color);
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 
         $FillArray->addColor('green@0.6');
         //$AxisY_Weather =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
@@ -2271,24 +2252,24 @@ function grafico_modulo_log4x_2 ($id_agente_modulo, $periodo, $show_event,
 
         $plotMinMax =& $PlotareaMinMax->addNew('bubble', array(&$dataset, true));
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 
         $Graph->done();
 
-        grafico_modulo_log4x_trace(__LINE__);
+        grafico_modulo_log4x_trace2(__LINE__);
 }
 
-function grafico_modulo_log4x_index($x, $interval)
+function grafico_modulo_log4x_index2($x, $interval)
 {
         return $x + $interval - (($x - 1) % $interval) - 1;
 }
 
-function grafico_modulo_log4x_trace($str)
+function grafico_modulo_log4x_trace2($str)
 {
         //echo "$str\n";
 }
 
-function grafico_modulo_log4x_bubble_size($count, $max_count, $max_bubble_radius)
+function grafico_modulo_log4x_bubble_size2($count, $max_count, $max_bubble_radius)
 {
         //Superformula de ROA
         $r0 = 1.5;
@@ -2322,7 +2303,7 @@ function grafico_modulo_log4x_bubble_size($count, $max_count, $max_bubble_radius
         return 5 + log($count);
 }
 
-function grafico_modulo_log4x_format_x_axis ( $number , $decimals=2, $dec_point=".", $thousands_sep=",")
+function grafico_modulo_log4x_format_x_axis2 ( $number , $decimals=2, $dec_point=".", $thousands_sep=",")
 {
         // $number is the unix time in the local timezone
 
@@ -2334,7 +2315,7 @@ function grafico_modulo_log4x_format_x_axis ( $number , $decimals=2, $dec_point=
         return date("d/m", $number) . "\n" . date("H:i", $number);
 }
 
-function grafico_modulo_log4x_format_y_axis ( $number , $decimals=2, $dec_point=".", $thousands_sep=",")
+function grafico_modulo_log4x_format_y_axis2 ( $number , $decimals=2, $dec_point=".", $thousands_sep=",")
 {
         $n = "";
 
diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php
index 598edba077..300211cfce 100644
--- a/pandora_console/include/functions_html.php
+++ b/pandora_console/include/functions_html.php
@@ -19,6 +19,17 @@
  * @subpackage HTML
  */
 
+if (!isset($config)) {
+	$working_dir = getcwd();
+	$levels = substr_count($working_dir, '/');
+	
+	for ($i = 0; $i < $levels; $i++) {
+		if(file_exists(str_repeat("../", $i) . 'config.php')) {
+			require_once(str_repeat("../", $i) . "config.php");
+		}
+	}
+}
+
 require_once ($config['homedir'].'/include/functions_users.php');
 require_once ($config['homedir'].'/include/functions_groups.php');
 
diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php
index 714e24d7a5..23dd47d7a4 100755
--- a/pandora_console/include/graphs/functions_pchart.php
+++ b/pandora_console/include/graphs/functions_pchart.php
@@ -77,8 +77,10 @@ if(isset($graph['yaxisname'])) {
 if(isset($graph['round_corner'])) { 
 	$round_corner = $graph['round_corner'];
 }
-if(isset($graph['font'])) { 
-	$font = $graph['font'];
+if(isset($graph['font'])) {
+	if (!empty($graph['font'])) {
+		$font = $graph['font'];
+	}
 }
 if(isset($graph['antialiasing'])) { 
 	$antialiasing = $graph['antialiasing'];
diff --git a/pandora_console/index.php b/pandora_console/index.php
index f44456e9a7..bdbf47566a 100644
--- a/pandora_console/index.php
+++ b/pandora_console/index.php
@@ -259,7 +259,7 @@ else {
 		} 
 		elseif (file_exists ($page)) {
 			if (! is_extension ($page)){
-				require ($page);
+				require_once($page);
 			}
 			else {
 				if ($sec[0] == 'g')
diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php
index 0e0f9b24ab..1939d8be96 100644
--- a/pandora_console/operation/agentes/stat_win.php
+++ b/pandora_console/operation/agentes/stat_win.php
@@ -165,7 +165,7 @@ switch ($graph_type) {
 			$label, $unit_name, $draw_alerts, 1, $pure, $date, 1);
 		break;
 	default:
-		echo fs_error_image ('../images');
+		echo fs_error_image2 ('../images');
 		break;
 }