From eb590aae7255dc55fda3a545aba32ae1e0b98718 Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar <alex@artica.es>
Date: Mon, 22 Sep 2014 19:42:40 +0200
Subject: [PATCH 1/6] Improvements on the combined graphs

* pandora_console/operation/agentes/interface_traffic_graph_win.php:
	Modified the graph function call. Modified the refresh time.

* pandora_console/include/functions_graph.php: Modified the function
	"graphic_combined_module". Now is possible to set the items
	name and choose which values will appear on the items list.

* pandora_console/include/functions_custom_graphs.php: Added new
	parameters to the function "custom_graphs_print" to call the
	function "graphic_combined_module".
---
 .../include/functions_custom_graphs.php       |  22 +++-
 pandora_console/include/functions_graph.php   | 102 +++++++++++-------
 .../agentes/interface_traffic_graph_win.php   |  21 +++-
 3 files changed, 97 insertions(+), 48 deletions(-)

diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php
index 4b1c12acf0..f4bc30d104 100644
--- a/pandora_console/include/functions_custom_graphs.php
+++ b/pandora_console/include/functions_custom_graphs.php
@@ -145,14 +145,25 @@ function custom_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGr
  * @param $height Height of the returning image.
  * @param $width Width of the returning image.
  * @param $period Period of time to get data in seconds.
- * @param $stacked Wheter the graph is stacked or not.
+ * @param $stacked Whether the graph is stacked or not.
  * @param $return Whether to return an output string or echo now (optional, echo by default).
  * @param $date Date to start printing the graph
+ * @param bool Wether to show an image instead a interactive chart or not
+ * @param string Background color
+ * @param array List of names for the items. Should have the same size as the module list.
+ * @param bool Show the last value of the item on the list.
+ * @param bool Show the max value of the item on the list.
+ * @param bool Show the min value of the item on the list.
+ * @param bool Show the average value of the item on the list.
+ *
+ * @return Mixed 
  */
 
 function custom_graphs_print($id_graph, $height, $width, $period,
 	$stacked = null, $return = false, $date = 0, $only_image = false,
-	$background_color = 'white', $modules_param = array(), $homeurl = '') {
+	$background_color = 'white', $modules_param = array(), $homeurl = '',
+	$name_list = array(), $show_last = true, $show_max = true,
+	$show_min = true, $show_avg = true) {
 	
 	global $config;
 	
@@ -214,7 +225,12 @@ function custom_graphs_print($id_graph, $height, $width, $period,
 		1,
 		false,
 		false,
-		$background_color);
+		$background_color,
+		$name_list,
+		$show_last,
+		$show_max,
+		$show_min,
+		$show_avg);
 	
 	if ($return)
 		return $output;
diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php
index 3813ae71f5..f66640f036 100755
--- a/pandora_console/include/functions_graph.php
+++ b/pandora_console/include/functions_graph.php
@@ -854,6 +854,11 @@ function graph_get_formatted_date($timestamp, $format1, $format2) {
  * @param int Date to start of getting info.
  * @param mixed If is a projection graph this parameter will be module data with prediction data (the projection) 
  * or false in other case.
+ * @param array List of names for the items. Should have the same size as the module list.
+ * @param bool Show the last value of the item on the list.
+ * @param bool Show the max value of the item on the list.
+ * @param bool Show the min value of the item on the list.
+ * @param bool Show the average value of the item on the list.
  * 
  * @return Mixed 
  */
@@ -861,7 +866,9 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 	$width, $height, $title, $unit_name, $show_events = 0,
 	$show_alerts = 0, $pure = 0, $stacked = 0, $date = 0,
 	$only_image = false, $homeurl = '', $ttl = 1, $projection = false,
-	$prediction_period = false, $background_color = 'white') {
+	$prediction_period = false, $background_color = 'white',
+	$name_list = array(), $show_last = true, $show_max = true,
+	$show_min = true, $show_avg = true) {
 	
 	global $config;
 	global $graphic_type;
@@ -971,23 +978,28 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 		if ($projection != false && $i != 0) {
 			$agent_module_id = $module_list[0];
 			
-			//Get and process agent name
-			$agent_name = io_safe_output(
-				modules_get_agentmodule_agent_name ($agent_module_id));
-			$agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false);
+			if (!empty($name_list) && isset($name_list[$i])) {
+				$module_name_list[$i] = $name_list[$i];
+			}
+			else {
+				//Get and process agent name
+				$agent_name = io_safe_output(
+					modules_get_agentmodule_agent_name ($agent_module_id));
+				$agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false);
+				
+				
+				$agent_id = agents_get_agent_id ($agent_name);
+				
+				
+				//Get and process module name
+				$module_name = io_safe_output(
+					modules_get_agentmodule_name ($agent_module_id));
+				$module_name = sprintf(__("projection for %s"), $module_name);
+				$module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false);
+
+				$module_name_list[$i] = $agent_name ." / ". $module_name;
+			}
 			
-			
-			$agent_id = agents_get_agent_id ($agent_name);
-			
-			
-			//Get and process module name
-			$module_name = io_safe_output(
-				modules_get_agentmodule_name ($agent_module_id));
-			$module_name = sprintf(__("projection for %s"), $module_name);
-			$module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false);
-			
-			
-			$module_name_list[$i] = $agent_name ." / ". $module_name;
 			$id_module_type = modules_get_agentmodule_type ($agent_module_id);
 			$module_type = modules_get_moduletype_name ($id_module_type);
 			$uncompressed_module = is_module_uncompressed ($module_type);
@@ -995,20 +1007,26 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 		else {
 			$agent_module_id = $module_list[$i];
 			
-			//Get and process agent name
-			$agent_name = io_safe_output(
-				modules_get_agentmodule_agent_name ($agent_module_id));
-			$agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false);
-			
-			
-			$agent_id = agents_get_agent_id ($agent_name);
-			
-			//Get and process module name
-			$module_name = io_safe_output(
-				modules_get_agentmodule_name ($agent_module_id));
-			$module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false);
-			
-			$module_name_list[$i] = $agent_name . " / " . $module_name;
+			if (!empty($name_list) && isset($name_list[$i])) {
+				$module_name_list[$i] = $name_list[$i];
+			}
+			else {
+				//Get and process agent name
+				$agent_name = io_safe_output(
+					modules_get_agentmodule_agent_name ($agent_module_id));
+				$agent_name = ui_print_truncate_text($agent_name, 'agent_small', false, true, false, '...', false);
+				
+				
+				$agent_id = agents_get_agent_id ($agent_name);
+				
+				//Get and process module name
+				$module_name = io_safe_output(
+					modules_get_agentmodule_name ($agent_module_id));
+				$module_name = ui_print_truncate_text($module_name, 'module_small', false, true, false, '...', false);
+
+				$module_name_list[$i] = $agent_name . " / " . $module_name;
+			}
+
 			$id_module_type = modules_get_agentmodule_type ($agent_module_id);
 			$module_type = modules_get_moduletype_name ($id_module_type);
 			$uncompressed_module = is_module_uncompressed ($module_type);
@@ -1199,18 +1217,22 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 		
 		$graph_stats = get_graph_statistics($graph_values[$i]);
 		
-		$min = $graph_stats['min'];
-		$max = $graph_stats['max'];
-		$avg = $graph_stats['avg'];
-		$last = $graph_stats['last'];
+		$min = number_format($graph_stats['min'], 2);
+		$max = number_format($graph_stats['max'], 2);
+		$avg = number_format($graph_stats['avg'], 2);
+		$last = number_format($graph_stats['last'], 2);
 		$units = modules_get_unit($agent_module_id);
 		
 		if ($projection == false or ($projection != false and $i == 0)) {
-			$module_name_list[$i] .= ": " .
-				__('Last') . ": $last $units; " .
-				__("Max") . ": $max $units; " .
-				__("Min") . ": $min $units; " .
-				__("Avg") . ": $avg";
+			$module_name_list[$i] .= ": ";
+			if ($show_last)
+				$module_name_list[$i] .= __('Last') . ": $last $units; ";
+			if ($show_max)
+				$module_name_list[$i] .= __("Max") . ": $max $units; ";
+			if ($show_min)
+				$module_name_list[$i] .= __("Min") . ": $min $units; ";
+			if ($show_avg)
+				$module_name_list[$i] .= __("Avg") . ": $avg $units";
 		}
 		
 		if ($weight_list[$i] != 1) {
diff --git a/pandora_console/operation/agentes/interface_traffic_graph_win.php b/pandora_console/operation/agentes/interface_traffic_graph_win.php
index 606c002616..5daf30f11b 100644
--- a/pandora_console/operation/agentes/interface_traffic_graph_win.php
+++ b/pandora_console/operation/agentes/interface_traffic_graph_win.php
@@ -60,8 +60,8 @@ $params = json_decode($params_json, true);
 $interface_name = (string) $params['interface_name'];
 $agent_id = (int) $params['agent_id'];
 $interface_traffic_modules = array(
-		'in' => (int) $params['traffic_module_in'],
-		'out' => (int) $params['traffic_module_out']
+		__('In') => (int) $params['traffic_module_in'],
+		__('Out') => (int) $params['traffic_module_out']
 	);
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -69,7 +69,7 @@ $interface_traffic_modules = array(
 	<head>
 <?php
 		// Parsing the refresh before sending any header
-		$refresh = (int) get_parameter('refresh', SECONDS_10MINUTES);
+		$refresh = (int) get_parameter('refresh', SECONDS_5MINUTES);
 		if ($refresh > 0) {
 			$query = ui_get_url_refresh(false);
 			
@@ -135,8 +135,19 @@ $interface_traffic_modules = array(
 		else
 			echo '<div style="margin-left: 50px; padding-top: 10px;">';
 		
-		$modules = array($interface_traffic_modules['in'], $interface_traffic_modules['out']);
-		custom_graphs_print(0, $height, $width, $period, null, false, $date, false, 'white', $modules, $config['homeurl']);
+		custom_graphs_print(0,
+			$height,
+			$width,
+			$period,
+			null,
+			false,
+			$date,
+			false,
+			'white',
+			array_values($interface_traffic_modules),
+			$config['homeurl'],
+			array_keys($interface_traffic_modules),
+			false);
 		
 		echo '</div>';
 		

From b78e69a592f656ca25b08a37cbb7877fa183ffe2 Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar <alex@artica.es>
Date: Tue, 23 Sep 2014 13:07:58 +0200
Subject: [PATCH 2/6] Improved the items information of the module graphs

* pandora_console/godmode/setup/setup_visuals.php,
  pandora_console/include/functions_config.php: Added a
	new config token to choose if the module graphs
	data should be shortened.

* pandora_console/include/functions_custom_graphs.php:
	Added the unit list parameter to the function
	"custom_graphs_print".

* pandora_console/operation/agentes/interface_traffic_graph_win.php:
	Improved a function call.

* pandora_console/include/functions_graph.php: Modified
	the function "graphic_combined_module". Now is
	possible to add custom units for the items and
	short the data.
---
 .../godmode/setup/setup_visuals.php           | 25 ++++++-
 pandora_console/include/functions_config.php  |  2 +
 .../include/functions_custom_graphs.php       |  5 +-
 pandora_console/include/functions_graph.php   | 66 +++++++++++++++----
 .../agentes/interface_traffic_graph_win.php   |  1 +
 5 files changed, 83 insertions(+), 16 deletions(-)

diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php
index 8419d7cc33..831417c13b 100644
--- a/pandora_console/godmode/setup/setup_visuals.php
+++ b/pandora_console/godmode/setup/setup_visuals.php
@@ -400,12 +400,33 @@ $table->data[$row][1] = html_print_input_text ('networkmap_max_width', $config["
 $row++;
 
 $table->data[$row][0] = __('Fixed header');
-$table->data[$row][1] = html_print_checkbox('fixed_header', 1, $config['fixed_header'], true);
+$table->data[$row][1] = __('Yes') . '&nbsp;' .
+	html_print_radio_button ('fixed_header', 1, '', $config["fixed_header"], true) .
+	'&nbsp;&nbsp;';
+$table->data[$row][1] .= __('No') . '&nbsp;' .
+	html_print_radio_button ('fixed_header', 0, '', $config["fixed_header"], true);
 
 $row++;
 
 $table->data[$row][0] = __('Fixed menu');
-$table->data[$row][1] = html_print_checkbox('fixed_menu', 1, $config['fixed_menu'], true);
+$table->data[$row][1] = __('Yes') . '&nbsp;' .
+	html_print_radio_button ('fixed_menu', 1, '', $config["fixed_menu"], true) .
+	'&nbsp;&nbsp;';
+$table->data[$row][1] .= __('No') . '&nbsp;' .
+	html_print_radio_button ('fixed_menu', 0, '', $config["fixed_menu"], true);
+
+$row++;
+
+if (!isset($config["short_module_graph_data"]))
+	$config["short_module_graph_data"] = true;
+
+$table->data[$row][0] = __('Shortened module graph data');
+$table->data[$row][0] .= ui_print_help_tip(__('The data number of the module graphs will be rounded and shortened'), true);
+$table->data[$row][1] = __('Yes') . '&nbsp;' .
+	html_print_radio_button ('short_module_graph_data', 1, '', $config["short_module_graph_data"], true) .
+	'&nbsp;&nbsp;';
+$table->data[$row][1] .= __('No') . '&nbsp;' .
+	html_print_radio_button ('short_module_graph_data', 0, '', $config["short_module_graph_data"], true);
 
 $row++;
 
diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php
index eceb41f5ea..8cc9d1864b 100644
--- a/pandora_console/include/functions_config.php
+++ b/pandora_console/include/functions_config.php
@@ -447,6 +447,8 @@ function config_update_config () {
 						$error_update[] = __('Custom graphviz directory');
 					if (!config_update_value ('networkmap_max_width', get_parameter('networkmap_max_width')))
 						$error_update[] = __('Networkmap max width');
+					if (!config_update_value ('short_module_graph_data', get_parameter('short_module_graph_data')))
+						$error_update[] = __('Shortened module graph data');
 					
 					$interval_values = get_parameter ('interval_values');
 					
diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php
index f4bc30d104..f0e03d935a 100644
--- a/pandora_console/include/functions_custom_graphs.php
+++ b/pandora_console/include/functions_custom_graphs.php
@@ -162,8 +162,8 @@ function custom_graphs_get_user ($id_user = 0, $only_names = false, $returnAllGr
 function custom_graphs_print($id_graph, $height, $width, $period,
 	$stacked = null, $return = false, $date = 0, $only_image = false,
 	$background_color = 'white', $modules_param = array(), $homeurl = '',
-	$name_list = array(), $show_last = true, $show_max = true,
-	$show_min = true, $show_avg = true) {
+	$name_list = array(), $unit_list = array(), $show_last = true,
+	$show_max = true, $show_min = true, $show_avg = true) {
 	
 	global $config;
 	
@@ -227,6 +227,7 @@ function custom_graphs_print($id_graph, $height, $width, $period,
 		false,
 		$background_color,
 		$name_list,
+		$unit_list,
 		$show_last,
 		$show_max,
 		$show_min,
diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php
index f66640f036..7d54e946cf 100755
--- a/pandora_console/include/functions_graph.php
+++ b/pandora_console/include/functions_graph.php
@@ -855,6 +855,7 @@ function graph_get_formatted_date($timestamp, $format1, $format2) {
  * @param mixed If is a projection graph this parameter will be module data with prediction data (the projection) 
  * or false in other case.
  * @param array List of names for the items. Should have the same size as the module list.
+ * @param array List of units for the items. Should have the same size as the module list.
  * @param bool Show the last value of the item on the list.
  * @param bool Show the max value of the item on the list.
  * @param bool Show the min value of the item on the list.
@@ -867,7 +868,7 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 	$show_alerts = 0, $pure = 0, $stacked = 0, $date = 0,
 	$only_image = false, $homeurl = '', $ttl = 1, $projection = false,
 	$prediction_period = false, $background_color = 'white',
-	$name_list = array(), $show_last = true, $show_max = true,
+	$name_list = array(), $unit_list = array(), $show_last = true, $show_max = true,
 	$show_min = true, $show_avg = true) {
 	
 	global $config;
@@ -935,6 +936,9 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 	else {
 		$module_number = count ($module_list);
 	}
+
+	$names_number = count($name_list);
+	$units_number = count($unit_list);
 	
 	// interval - This is the number of "rows" we are divided the time to fill data.
 	//    more interval, more resolution, and slower.
@@ -978,7 +982,7 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 		if ($projection != false && $i != 0) {
 			$agent_module_id = $module_list[0];
 			
-			if (!empty($name_list) && isset($name_list[$i])) {
+			if (!empty($name_list) && $names_number == $module_number && isset($name_list[$i])) {
 				$module_name_list[$i] = $name_list[$i];
 			}
 			else {
@@ -1007,7 +1011,7 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 		else {
 			$agent_module_id = $module_list[$i];
 			
-			if (!empty($name_list) && isset($name_list[$i])) {
+			if (!empty($name_list) && $names_number == $module_number && isset($name_list[$i])) {
 				$module_name_list[$i] = $name_list[$i];
 			}
 			else {
@@ -1216,23 +1220,61 @@ function graphic_combined_module ($module_list, $weight_list, $period,
 		$avg = round($avg / $countAvg, 1);
 		
 		$graph_stats = get_graph_statistics($graph_values[$i]);
+
+		if (!isset($config["short_module_graph_data"]))
+			$config["short_module_graph_data"] = true;
 		
-		$min = number_format($graph_stats['min'], 2);
-		$max = number_format($graph_stats['max'], 2);
-		$avg = number_format($graph_stats['avg'], 2);
-		$last = number_format($graph_stats['last'], 2);
-		$units = modules_get_unit($agent_module_id);
+		if ($config["short_module_graph_data"]) {
+			$min = $graph_stats['min'];
+			$max = $graph_stats['max'];
+			$avg = $graph_stats['avg'];
+			$last = $graph_stats['last'];
+			
+			if ($min > 1000000)
+				$min = sprintf("%sM", number_format($min / 1000000, 2));
+			else if ($min > 1000)
+				$min = sprintf("%sK", number_format($min / 1000, 2));
+
+			if ($max > 1000000)
+				$max = sprintf("%sM", number_format($max / 1000000, 2));
+			else if ($max > 1000)
+				$max = sprintf("%sK", number_format($max / 1000, 2));
+
+			if ($avg > 1000000)
+				$avg = sprintf("%sM", number_format($avg / 1000000, 2));
+			else if ($avg > 1000)
+				$avg = sprintf("%sK", number_format($avg / 1000, 2));
+
+			if ($last > 1000000)
+				$last = sprintf("%sM", number_format($last / 1000000, 2));
+			else if ($last > 1000)
+				$last = sprintf("%sK", number_format($last / 1000, 2));
+		}
+		else {
+			$min = number_format($graph_stats['min'], 2);
+			$max = number_format($graph_stats['max'], 2);
+			$avg = number_format($graph_stats['avg'], 2);
+			$last = number_format($graph_stats['last'], 2);
+		}
+		
+
+		if (!empty($unit_list) && $units_number == $module_number && isset($unit_list[$i])) {
+			$unit = $unit_list[$i];
+		}
+		else {
+			$unit = modules_get_unit($agent_module_id);
+		}
 		
 		if ($projection == false or ($projection != false and $i == 0)) {
 			$module_name_list[$i] .= ": ";
 			if ($show_last)
-				$module_name_list[$i] .= __('Last') . ": $last $units; ";
+				$module_name_list[$i] .= __('Last') . ": $last $unit; ";
 			if ($show_max)
-				$module_name_list[$i] .= __("Max") . ": $max $units; ";
+				$module_name_list[$i] .= __("Max") . ": $max $unit; ";
 			if ($show_min)
-				$module_name_list[$i] .= __("Min") . ": $min $units; ";
+				$module_name_list[$i] .= __("Min") . ": $min $unit; ";
 			if ($show_avg)
-				$module_name_list[$i] .= __("Avg") . ": $avg $units";
+				$module_name_list[$i] .= __("Avg") . ": $avg $unit";
 		}
 		
 		if ($weight_list[$i] != 1) {
diff --git a/pandora_console/operation/agentes/interface_traffic_graph_win.php b/pandora_console/operation/agentes/interface_traffic_graph_win.php
index 5daf30f11b..b7826ccd14 100644
--- a/pandora_console/operation/agentes/interface_traffic_graph_win.php
+++ b/pandora_console/operation/agentes/interface_traffic_graph_win.php
@@ -147,6 +147,7 @@ $interface_traffic_modules = array(
 			array_values($interface_traffic_modules),
 			$config['homeurl'],
 			array_keys($interface_traffic_modules),
+			array_fill(0, count($interface_traffic_modules),"bytes/s"),
 			false);
 		
 		echo '</div>';

From 011cb0f0af107a12712bb7476f044ae6cd458c4b Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar <alex@artica.es>
Date: Tue, 23 Sep 2014 18:05:44 +0200
Subject: [PATCH 3/6] Big improvement on the SNMP statistics section

* pandora_console/operation/snmpconsole/snmp_view.php: Removed the code of
	the statistics section.

* pandora_console/operation/snmpconsole/snmp_statistics.php: Added file.
	Statistics section for SNMP.
---
 .../operation/snmpconsole/snmp_statistics.php | 209 +++++
 .../operation/snmpconsole/snmp_view.php       | 789 ++++++++----------
 2 files changed, 563 insertions(+), 435 deletions(-)
 create mode 100644 pandora_console/operation/snmpconsole/snmp_statistics.php

diff --git a/pandora_console/operation/snmpconsole/snmp_statistics.php b/pandora_console/operation/snmpconsole/snmp_statistics.php
new file mode 100644
index 0000000000..d5d6cc8500
--- /dev/null
+++ b/pandora_console/operation/snmpconsole/snmp_statistics.php
@@ -0,0 +1,209 @@
+<?php
+
+// Pandora FMS - http://pandorafms.com
+// ==================================================
+// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
+// Please see http://pandorafms.org for full contribution list
+
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation for version 2.
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+
+
+// Load global vars
+global $config;
+
+enterprise_include ("operation/snmpconsole/snmp_view.php");
+include_once($config['homedir'] . '/include/functions_graph.php');
+require_once($config['homedir'] . "/include/functions_agents.php");
+require_once($config['homedir'] . "/include/functions_snmp.php");
+
+check_login ();
+
+// ACL
+if (! check_acl ($config['id_user'], 0, "AR")) {
+	db_pandora_audit("ACL Violation",
+		"Trying to access SNMP Console");
+	require ("general/noaccess.php");
+	exit;
+}
+
+// Read parameters
+$refr = (int)get_parameter("refr", 0);
+
+
+// Page header and tabs
+
+// Fullscreen
+$fullscreen = array();
+if ($config["pure"]) {
+	$fullscreen['text'] = '<a target="_top" href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure=0&refr=' . $refr . '">' .
+		html_print_image("images/normal_screen.png", true, array("title" => __('Normal screen')))  . '</a>';
+}
+else {
+	$fullscreen['text'] = '<a target="_top" href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure=1&refr=' . $refr . '">' .
+		html_print_image("images/full_screen.png", true, array("title" => __('Full screen'))) . '</a>';
+}
+
+// List
+$list = array();
+$list['text'] = '<a href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_view&pure=' . $config["pure"] . '&refr=' . $refr . '">' . 
+	html_print_image("images/op_snmp.png", true, array ("title" => __('List'))) .'</a>';
+
+// Statistics (This file)
+$statistics = array();
+$statistics['active'] = true;
+$statistics['text'] = '<a href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure=' . $config["pure"] . '&refr=' . $refr . '">' . 
+	html_print_image("images/op_reporting.png", true, array ("title" => __('Statistics'))) .'</a>';
+
+// Header
+ui_print_page_header(__("SNMP Console"), "images/op_snmp.png", false,
+	"", false, array($fullscreen, $list, $statistics));
+
+// Retrieving the data
+
+$user_groups = users_get_groups($config['id_user'], "AR", false);
+$user_groups_str = '0';
+if (!empty($user_groups)) {
+	$user_groups_str = implode(",", array_keys($user_groups));
+}
+
+$last_month_timestamp = date("Y-m-d H:i:s", time() - SECONDS_1MONTH);
+
+$sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num
+						FROM ttrap
+						WHERE timestamp >= '%s'
+							AND (source = ''
+								OR source NOT IN (SELECT direccion FROM tagente)
+								OR source IN (SELECT direccion
+											  FROM tagente
+											  WHERE id_grupo IN (%s)))
+						GROUP BY %s
+						ORDER BY num DESC, timestamp DESC
+						LIMIT 25";
+
+$sql_traps_generated_by_source = sprintf($sql_traps_generated, "source", $last_month_timestamp, $user_groups_str, "source");
+$sql_traps_generated_by_oid = sprintf($sql_traps_generated, "oid", $last_month_timestamp, $user_groups_str, "oid");
+
+$traps_generated_by_source = db_get_all_rows_sql($sql_traps_generated_by_source);
+$traps_generated_by_oid = db_get_all_rows_sql($sql_traps_generated_by_oid);
+
+// No traps 
+if (empty($traps_generated_by_source) || empty($traps_generated_by_oid)) {
+	echo '<div class="nf">'.__('There are no SNMP traps in database').'</div>';
+	return;
+}
+
+$water_mark = array('file' => $config['homedir'] .  "/images/logo_vertical_water.png",
+		'url' => ui_get_full_url("/images/logo_vertical_water.png"));
+
+// By SOURCE
+$table_source = new StdClass();
+$table_source->width = '100%';
+$table_source->head[] = __("Traps received by source") . " - " . sprintf(__('Top %d'), 25);
+$table_source->head_colspan[] = 2;
+$table_source->headstyle[] = "background-color: #82b92e";
+$table_source->size = array();
+$table_source->size['table'] = '50%';
+$table_source->size['graph'] = '50%';
+$table_source->data = array();
+
+$table_source_row = array();
+
+$table_source_data = new StdClass();
+$table_source_data->width = '100%';
+$table_source_data->head = array();
+$table_source_data->head['source'] = __('Source IP');
+$table_source_data->head['num'] = __('Number');
+$table_source_data->data = array();
+
+$table_source_graph_data = array();
+
+foreach ($traps_generated_by_source as $trap) {
+	$row = array();
+
+	$agent = agents_get_agent_with_ip($trap['source']);
+	if ($agent === false) {
+		$row['source'] = '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&new_agent=1&direccion='.$trap["source"].'" title="'.__('Create agent').'">'.$trap["source"].'</a>';
+	}
+	else {
+		$agent_id = $agent["id_agente"];
+		$agent_name = ui_print_truncate_text($agent["nombre"], "agent_medium", true, true, true, '[&hellip;]', '');
+		$row['source'] = "<a href=\"index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=$agent_id\" title=\"".__('View agent details')."\">";
+		$row['source'] .= "<strong>$agent_name</strong></a>";
+	}
+	$row['num'] = (int) $trap['num'];
+
+	$table_source_data->data[] = $row;
+
+	$table_source_graph_data[$trap["source"]] = (int) $trap["num"];
+}
+
+$table_source_row['table'] = html_print_table($table_source_data, true);
+unset($table_source_data);
+
+if (empty($table_source_graph_data))
+	$table_source_graph = graph_nodata_image();
+else
+	$table_source_graph = pie3d_graph($config['flash_charts'], $table_source_graph_data, 400, 550, __("Other"),
+		'', $water_mark, $config['fontpath'], $config['font_size'], 1);
+
+$table_source_row['graph'] = $table_source_graph;
+
+$table_source->data[] = $table_source_row;
+
+html_print_table($table_source);
+unset($table_source);
+
+// By OID
+$table_oid = new StdClass();
+$table_oid->width = '100%';
+$table_oid->head[] = __("Traps received by OID") . " - " . sprintf(__('Top %d'), 25);
+$table_oid->head_colspan[] = 2;
+$table_oid->headstyle[] = "background-color: #82b92e";
+$table_oid->size = array();
+$table_oid->size['table'] = '50%';
+$table_oid->size['graph'] = '50%';
+$table_oid->data = array();
+
+$table_oid_row = array();
+
+$table_oid_data = new StdClass();
+$table_oid_data->width = '100%';
+$table_oid_data->head = array();
+$table_oid_data->head['oid'] = __('Trap OID');
+$table_oid_data->head['num'] = __('Number');
+$table_oid_data->data = array();
+
+$table_oid_graph_data = array();
+
+foreach ($traps_generated_by_oid as $trap) {
+	$table_oid_data->data[] = array(
+			'oid' => $trap['oid'],
+			'num' => (int) $trap['num']
+		);
+
+	$table_oid_graph_data[$trap["oid"]] = (int) $trap["num"];
+}
+
+$table_oid_row['table'] = html_print_table($table_oid_data, true);
+unset($table_oid_data);
+
+if (empty($table_oid_graph_data))
+	$table_oid_graph = graph_nodata_image();
+else
+	$table_oid_graph = pie3d_graph($config['flash_charts'], $table_oid_graph_data, 400, 550, __("Other"),
+		'', $water_mark, $config['fontpath'], $config['font_size'], 1);
+
+$table_oid_row['graph'] = $table_oid_graph;
+
+$table_oid->data[] = $table_oid_row;
+
+html_print_table($table_oid);
+unset($table_oid);
+
+?>
\ No newline at end of file
diff --git a/pandora_console/operation/snmpconsole/snmp_view.php b/pandora_console/operation/snmpconsole/snmp_view.php
index 8e16bd4993..c2372746ce 100644
--- a/pandora_console/operation/snmpconsole/snmp_view.php
+++ b/pandora_console/operation/snmpconsole/snmp_view.php
@@ -40,7 +40,6 @@ $offset = (int) get_parameter ('offset',0);
 $trap_type = (int) get_parameter ('trap_type', -1);
 $group_by = (int)get_parameter('group_by', 0);
 $refr = (int)get_parameter("refr", 0);
-$tab = (string) get_parameter("tab");
 
 $user_groups = users_get_groups ($config['id_user'],"AR", false);
 $str_user_groups = '';
@@ -65,22 +64,11 @@ $url = "index.php?sec=estado&" .
 	"trap_type=" . $trap_type . "&" .
 	"group_by=" .$group_by;
 
-switch ($tab) {
-	case 'statistics':
-		$statistics['active'] = true;
-		break;
-	
-	default:
-		$list['active'] = true;
-		break;
-}
-$statistics['text'] = '<a href="' . $url . '&pure=' . $config["pure"] . '&refr=' . $refr . '&tab=statistics">' . 
+$statistics['text'] = '<a href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure=' . $config["pure"] . '&refr=' . $refr . '">' . 
 	html_print_image("images/op_reporting.png", true, array ("title" => __('Statistics'))) .'</a>';
 $list['text'] = '<a href="' . $url . '&pure=' . $config["pure"] . '&refr=' . $refr . '">' . 
 	html_print_image("images/op_snmp.png", true, array ("title" => __('List'))) .'</a>';
-
-if ($tab)
-	$url .= "&tab=$tab";
+$list['active'] = true;
 
 if ($config["pure"]) {
 	$fullscreen['text'] = '<a target="_top" href="'.$url.'&pure=0&refr=' . $refr . '">' . html_print_image("images/normal_screen.png", true, array("title" => __('Normal screen')))  . '</a>';
@@ -354,441 +342,372 @@ ui_toggle($filter, __('Toggle filter(s)'));
 
 unset ($table);
 
-if ($tab == '') {
-
-	$traps = db_get_all_rows_sql($sql);
-	$trapcount = (int) db_get_value_sql($sql_count);
-
-	// No traps 
-	if (empty ($traps)) {
-		echo '<div class="nf">'.__('There are no SNMP traps in database').'</div>';
-		return;
-	}
-
-	if (($config['dbtype'] == 'oracle') && ($traps !== false)) {
-		for ($i=0; $i < count($traps); $i++) {
-			unset($traps[$i]['rnum']);
-		}
-	}
-
-	$url_snmp = "index.php?" .
-		"sec=snmpconsole&" .
-		"sec2=operation/snmpconsole/snmp_view&" .
-		"filter_severity=" . $filter_severity . "&" .
-		"filter_fired=" . $filter_fired . "&" .
-		"filter_status=" . $filter_status . "&" .
-		"refr=" . ((int)get_parameter('refr', 0)) . "&" .
-		"pure=" . $config["pure"] . "&" .
-		"group_by=" . $group_by . "&" .
-		"free_search_string=" . $free_search_string;
-
-	$urlPagination = $url_snmp . "&pagination=" . $pagination . "&offset=" . $offset;
-
-	ui_pagination ($trapcount, $urlPagination, $offset, $pagination);
-
-	echo '<form name="eventtable" method="POST" action="' . $url_snmp . '">';
-
-	$table->cellpadding = 4;
-	$table->cellspacing = 4;
-	$table->width = '99%';
-	$table->class = "databox";
-	$table->head = array ();
-	$table->size = array ();
-	$table->data = array ();
-	$table->align = array ();
-
-	$table->head[0] = __('Status');
-	$table->align[0] = "center";
-	$table->size[0] = '5%';
-
-	$table->head[1] = __('SNMP Agent');
-	$table->align[1] = "center";
-	$table->size[1] = '15%';
-
-	$table->head[2] = __('OID');
-	$table->align[2] = "center";
-	$table->size[2] = '18%';
-
-	if ($group_by) {
-		$table->head[3] = __('Count');
-		$table->align[3] = "center";
-		$table->size[3] = '5%';
-	}
-
-	$table->head[4] = __('Value');
-	$table->align[4] = "center";
-	$table->size[4] = '10%';
-
-	$table->head[5] = __('User ID');
-	$table->align[5] = "center";
-	$table->size[5] = '10%';
-
-	$table->head[6] = __('Timestamp');
-	$table->align[6] = "center";
-	$table->size[6] = '10%';
-
-	$table->head[7] = __('Alert');
-	$table->align[7] = "center";
-	$table->size[7] = '5%';
-
-	$table->head[8] = __('Action');
-	$table->align[8] = "center";
-	$table->size[8] = '10%';
-
-	$table->head[9] = html_print_checkbox_extended ("allbox", 1, false, false, "javascript:CheckAll();", 'class="chk" title="'.__('All').'"', true);
-	$table->align[9] = "center";
-	$table->size[9] = '5%';
-
-	$table->style[8] = "background: #F3F3F3; color: #111 !important;";
-
-	// Skip offset records
-	$idx = 0;
-	if ($traps !== false) {
-
-		foreach ($traps as $trap) {
-			$data = array ();
-			if (empty($trap["description"])){
-				$trap["description"]="";
-			}
-			$severity = enterprise_hook ('get_severity', array ($trap));
-			if ($severity === ENTERPRISE_NOT_HOOK) {
-				$severity = $trap["alerted"] == 1 ? $trap["priority"] : 1;
-			}
-			
-			//Status
-			if ($trap["status"] == 0) {
-				$data[0] = html_print_image("images/pixel_red.png", true, array("title" => __('Not validated'), "width" => "20", "height" => "20"));
-			}
-			else {
-				$data[0] = html_print_image("images/pixel_green.png", true, array("title" => __('Validated'), "width" => "20", "height" => "20"));
-			}
-			
-			// Agent matching source address
-			$table->cellclass[$idx][1] = get_priority_class ($severity);
-			$agent = agents_get_agent_with_ip ($trap['source']);
-			if ($agent === false) {
-				if (! check_acl ($config["id_user"], 0, "AR")) {
-					continue;
-				}
-				$data[1] = '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&new_agent=1&direccion='.$trap["source"].'" title="'.__('Create agent').'">'.$trap["source"].'</a>';
-			}
-			else {
-				if (! check_acl ($config["id_user"], $agent["id_grupo"], "AR")) {
-					continue;
-				}
-				$data[1] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent["id_agente"].'" title="'.__('View agent details').'">';
-				$data[1] .= '<strong>'.$agent["nombre"].'</strong></a>';
-			}
-			
-			//OID
-			$table->cellclass[$idx][2] = get_priority_class ($severity);
-			$data[2] = '<a href="javascript: toggleVisibleExtendedInfo(' . $trap["id_trap"] . ');">' . (empty($trap["oid"]) ? __('N/A') : $trap["oid"]) .'</a>';
-			
-			//Count
-			if ($group_by) {
-				$sql = "SELECT * FROM ttrap WHERE 1=1 
-						$where_without_group
-						AND oid='".$trap['oid']."' 
-						AND source='".$trap['source']."'";
-				$group_traps = db_get_all_rows_sql($sql);
-				$count_group_traps = count($group_traps);
-				$table->cellclass[$idx][3] = get_priority_class ($severity);
-				$data[3] = '<strong>'.$count_group_traps.'</strong></a>';
-			}
-			//Value
-			$table->cellclass[$idx][4] = get_priority_class ($severity);
-			if (empty ($trap["value"])) {
-				$data[4] = __('N/A');
-			}
-			else {
-				$data[4] = ui_print_truncate_text($trap["value"], GENERIC_SIZE_TEXT, false);
-			}
-			
-			//User
-			$table->cellclass[$idx][5] = get_priority_class ($severity);
-			if (!empty ($trap["status"])) {
-				$data[5] = '<a href="index.php?sec=workspace&sec2=operation/users/user_edit&ver='.$trap["id_usuario"].'">'.substr ($trap["id_usuario"], 0, 8).'</a>';
-				if (!empty($trap["id_usuario"]))
-					$data[5] .= ui_print_help_tip(get_user_fullname($trap["id_usuario"]), true);
-			}
-			else {
-				$data[5] = '--';
-			}
-			
-			// Timestamp
-			$table->cellclass[$idx][6] = get_priority_class ($severity);
-			$data[6] = '<span title="'.$trap["timestamp"].'">';
-			$data[6] .= ui_print_timestamp ($trap["timestamp"], true);
-			$data[6] .= '</span>';
-			
-			// Use alert severity if fired
-			if (!empty ($trap["alerted"])) {
-				$data[7] = html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20", "border" => "0", "title" => __('Alert fired'))); 		
-			}
-			else {
-				$data[7] = html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20", "border" => "0", "title" => __('Alert not fired')));
-			}
-			
-			//Actions
-			$data[8] = "";
-			
-			if (empty ($trap["status"]) && check_acl ($config["id_user"], 0, "IW")) {
-				$data[8] .= '<a href="' . $url_snmp . '&check='.$trap["id_trap"].'">' . html_print_image("images/ok.png", true, array("border" => '0', "title" => __('Validate'))) . '</a> ';
-			}
-			if ($trap['source'] == '') {
-				$is_admin = db_get_value('is_admin', 'tusuario', 'id_user',$config['id_user']);
-				if ($is_admin) {
-					$data[8] .= '<a href="' . $url_snmp . '&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . '</a> ';
-				}
-			} else {
-				$agent_trap_group = db_get_value('id_grupo', 'tagente', 'nombre', $trap['source']);
-				if ((check_acl ($config["id_user"], $agent_trap_group, "AW"))) {
-					$data[8] .= '<a href="' . $url_snmp . '&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . '</a> ';
-				}
-			}
-
-			$data[8] .= '<a href="javascript: toggleVisibleExtendedInfo(' . $trap["id_trap"] . ');">' . html_print_image("images/eye.png", true, array("alt" => __('Show more'), "title" => __('Show more'))) .'</a>';
-	                $data[8] .= enterprise_hook ('editor_link', array ($trap));
-
-			
-			$data[9] = html_print_checkbox_extended ("snmptrapid[]", $trap["id_trap"], false, false, '', 'class="chk"', true);
-			
-			array_push ($table->data, $data);
-			
-			//Hiden file for description
-			$string = '<table style="border:solid 1px #D3D3D3;" width="90%" class="toggle">
-				<tr>
-					<td align="left" valign="top" width="15%" ><b>' . __('Custom data:') . '</b></td>
-					<td align="left" >';
-			
-			if ($group_by) {
-				$new_url = "index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&" .
-				"filter_severity=" . $filter_severity . "&" .
-				"filter_fired=" . $filter_fired . "&" .
-				"filter_status=" . $filter_status . "&" .
-				"refr=" . ((int)get_parameter('refr', 0)) . "&" .
-				"pure=" . $config["pure"] . "&" .
-				"group_by=0&" .
-				"free_search_string=" . $free_search_string;
-				
-				$string .= '<a href='.$new_url.'>'.__('See more details').'</a>';
-			} else {	
-				// Print binding vars separately
-				$binding_vars = explode ("\t", $trap['oid_custom']);
-				foreach ($binding_vars as $var) {
-					$string .= $var . "<br/>";
-				}
-			}
-			
-			$string .= '</td>
-				</tr>
-				<tr>
-					<td align="left" valign="top">' . '<b>' . __('OID:') . '</td>
-					<td align="left"> ' . $trap['oid'] . '</td>
-				</tr>';
-			
-			if ($trap["description"] != "") {
-				$string .= '<tr>
-						<td align="left" valign="top">' . '<b>' . __('Description:') . '</td>
-						<td align="left">' . $trap['description'] . '</td>
-					</tr>';
-			}
-			
-			if ($trap["type"] != "") {
-				$trap_types = array(-1 => __('None'), 0 => __('Cold start (0)'), 1 => __('Warm start (1)'), 2 => __('Link down (2)'), 3 => __('Link up (3)'), 4 => __('Authentication failure (4)'), 5 => __('Other'));
-				
-				switch ($trap["type"]) {
-					case -1:
-						$desc_trap_type = __('None');
-						break;
-					case 0:
-						$desc_trap_type = __('Cold start (0)');
-						break;
-					case 1:
-						$desc_trap_type = __('Warm start (1)');
-						break;
-					case 2:
-						$desc_trap_type = __('Link down (2)');
-						break;
-					case 3:
-						$desc_trap_type = __('Link up (3)');
-						break;
-					case 4:
-						$desc_trap_type = __('Authentication failure (4)');
-						break;
-					default:
-						$desc_trap_type = __('Other');
-						break;
-				}
-				$string .= '<tr><td align="left" valign="top">' . '<b>' . __('Type:') . '</td><td align="left">' . $desc_trap_type . '</td></tr>';
-			}
-			
-			if ($group_by) {
-				$sql = "SELECT * FROM ttrap WHERE 1=1 
-						$where_without_group
-						AND oid='".$trap['oid']."' 
-						AND source='".$trap['source']."'";
-				$group_traps = db_get_all_rows_sql($sql);
-				$count_group_traps = count($group_traps);
-				
-				$sql = "SELECT timestamp FROM ttrap WHERE 1=1 
-						$where_without_group
-						AND oid='".$trap['oid']."' 
-						AND source='".$trap['source']."'
-						ORDER BY `timestamp` DESC";		
-				$last_trap = db_get_value_sql($sql);
-				
-				$sql = "SELECT timestamp FROM ttrap WHERE 1=1
-						$where_without_group
-						AND oid='".$trap['oid']."' 
-						AND source='".$trap['source']."'
-						ORDER BY `timestamp` ASC";
-				$first_trap = db_get_value_sql($sql);
-				
-				$string .= '<tr>
-						<td align="left" valign="top">' . '<b>' . __('Count:') . '</td>
-						<td align="left">' . $count_group_traps . '</td>
-					</tr>';
-				$string .= '<tr>
-						<td align="left" valign="top">' . '<b>' . __('First trap:') . '</td>
-						<td align="left">' . $first_trap . '</td>
-					</tr>';
-				$string .= '<tr>
-						<td align="left" valign="top">' . '<b>' . __('Last trap:') . '</td>
-						<td align="left">' . $last_trap . '</td>
-					</tr>';
-
-			}
-			$string .=  '</table>';
-			
-			$data = array($string); //$data = array($trap['description']);
-			$idx++;
-			$table->rowclass[$idx] = 'trap_info_' . $trap['id_trap'];
-			$table->colspan[$idx][0] = 10;
-			$table->rowstyle[$idx] = 'display: none;';
-			array_push ($table->data, $data);
-			
-			$idx++;
-		}
-	}
-
-	// No matching traps
-	if ($idx == 0) {
-		echo '<div class="nf">' . __('No matching traps found') . '</div>';
-	}
-	else {
-		html_print_table ($table);
-	}
-
-	unset ($table);
-
-	echo '<div style="width:98%; text-align:right;">';
-	if (check_acl ($config["id_user"], 0, "IW")) {
-		html_print_submit_button (__('Validate'), "updatebt", false, 'class="sub ok"');
-	}
-
-	if (check_acl ($config['id_user'], 0, "IM")) {
-		echo "&nbsp;";
-		html_print_submit_button (__('Delete'), "deletebt", false, 'class="sub delete" onClick="javascript:return confirm(\''.__('Are you sure?').'\')"');
-	}
-	echo "</div></form>";
-
-
-	echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
-	echo '<h3>' . __('Status') . '</h3>';
-	echo html_print_image("images/pixel_green.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Validated');
-	echo '<br />';
-	echo html_print_image("images/pixel_red.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not validated');
-	echo '</div>';
-	echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
-	echo '<h3>' . __('Alert') . '</h3>';
-	echo html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20")) . ' - ' .__('Fired');
-	echo '<br />';
-	echo html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not fired');
-	echo '</div>';
-	echo '<div style="float:left; padding-left:30px; line-height: 19px; vertical-align: top; width:120px;">';
-	echo '<h3>' . __('Action') . '</h3>';
-	echo html_print_image("images/ok.png", true) . ' - ' .__('Validate');
-	echo '<br />';
-	echo html_print_image("images/cross.png", true) . ' - ' . __('Delete');
-	echo '</div>';
-	echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
-	echo '<h3>'.__('Legend').'</h3>';
-	foreach (get_priorities () as $num => $name) {
-		echo '<span class="'.get_priority_class ($num).'">'.$name.'</span>';
-		echo '<br />';
-	}
-	echo '</div>';
-	echo '<div style="clear:both;">&nbsp;</div>';
+$traps = db_get_all_rows_sql($sql);
+$trapcount = (int) db_get_value_sql($sql_count);
 
+// No traps 
+if (empty ($traps)) {
+	echo '<div class="nf">'.__('There are no SNMP traps in database').'</div>';
+	return;
 }
-else {
 
-	$traps = db_get_all_rows_sql($sql_all);
-	$trapcount = (int) db_get_value_sql($sql_count);
-
-	// No traps 
-	if (empty ($traps)) {
-		echo '<div class="nf">'.__('There are no SNMP traps in database').'</div>';
-		return;
+if (($config['dbtype'] == 'oracle') && ($traps !== false)) {
+	for ($i=0; $i < count($traps); $i++) {
+		unset($traps[$i]['rnum']);
 	}
+}
 
-	if (($config['dbtype'] == 'oracle') && ($traps !== false)) {
-		for ($i=0; $i < count($traps); $i++) {
-			unset($traps[$i]['rnum']);
-		}
-	}
+$url_snmp = "index.php?" .
+	"sec=snmpconsole&" .
+	"sec2=operation/snmpconsole/snmp_view&" .
+	"filter_severity=" . $filter_severity . "&" .
+	"filter_fired=" . $filter_fired . "&" .
+	"filter_status=" . $filter_status . "&" .
+	"refr=" . ((int)get_parameter('refr', 0)) . "&" .
+	"pure=" . $config["pure"] . "&" .
+	"group_by=" . $group_by . "&" .
+	"free_search_string=" . $free_search_string;
 
-	include_once($config['homedir'] . '/include/functions_graph.php');
+$urlPagination = $url_snmp . "&pagination=" . $pagination . "&offset=" . $offset;
+
+ui_pagination ($trapcount, $urlPagination, $offset, $pagination);
+
+echo '<form name="eventtable" method="POST" action="' . $url_snmp . '">';
+
+$table->cellpadding = 4;
+$table->cellspacing = 4;
+$table->width = '99%';
+$table->class = "databox";
+$table->head = array ();
+$table->size = array ();
+$table->data = array ();
+$table->align = array ();
+
+$table->head[0] = __('Status');
+$table->align[0] = "center";
+$table->size[0] = '5%';
+
+$table->head[1] = __('SNMP Agent');
+$table->align[1] = "center";
+$table->size[1] = '15%';
+
+$table->head[2] = __('OID');
+$table->align[2] = "center";
+$table->size[2] = '18%';
+
+if ($group_by) {
+	$table->head[3] = __('Count');
+	$table->align[3] = "center";
+	$table->size[3] = '5%';
+}
+
+$table->head[4] = __('Value');
+$table->align[4] = "center";
+$table->size[4] = '10%';
+
+$table->head[5] = __('User ID');
+$table->align[5] = "center";
+$table->size[5] = '10%';
+
+$table->head[6] = __('Timestamp');
+$table->align[6] = "center";
+$table->size[6] = '10%';
+
+$table->head[7] = __('Alert');
+$table->align[7] = "center";
+$table->size[7] = '5%';
+
+$table->head[8] = __('Action');
+$table->align[8] = "center";
+$table->size[8] = '10%';
+
+$table->head[9] = html_print_checkbox_extended ("allbox", 1, false, false, "javascript:CheckAll();", 'class="chk" title="'.__('All').'"', true);
+$table->align[9] = "center";
+$table->size[9] = '5%';
+
+$table->style[8] = "background: #F3F3F3; color: #111 !important;";
+
+// Skip offset records
+$idx = 0;
+if ($traps !== false) {
 
-	$data_aux = array();
 	foreach ($traps as $trap) {
-		$source = $trap['source'];
-		$oid = $trap['oid'];
-
-		if (!isset($data_aux[$source]))
-			$data_aux[$source] = array();
-
-		if (!isset($data_aux[$source][$oid]))
-			$data_aux[$source][$oid] = array('num' => 1, 'text' => '');
-		else {
-			$data_aux[$source][$oid]['num']++;
-			if (empty($data_aux[$source][$oid]['text']))
-				$data_aux[$source][$oid]['text'] = $trap['text'];
+		$data = array ();
+		if (empty($trap["description"])){
+			$trap["description"]="";
+		}
+		$severity = enterprise_hook ('get_severity', array ($trap));
+		if ($severity === ENTERPRISE_NOT_HOOK) {
+			$severity = $trap["alerted"] == 1 ? $trap["priority"] : 1;
 		}
 		
-	}
-
-	$id = -1;
-	$data = array();
-
-	if (!empty($traps)) {
-		$data['name'] = __("Traps received by source");
-		$data['children'] = array();
-
-		foreach ($data_aux as $source => $oid_data) {
-			$children = array();
-			$children['id'] = $id++;
-			$children['name'] = $source;
-			$children['children'] = array();
-			foreach ($oid_data as $oid => $values) {
-				$children_data = array();
-				$children_data['id'] = $id++;
-				$children_data['name'] = $oid;
-				$children_data['value'] = $values['num'];
-				$children_data['tooltip_content'] = '';
-				if (!empty($values['text']))
-					$children_data['tooltip_content'] .= "<b>" . $values['text'] . "</b><br>";
-				$children_data['tooltip_content'] .= sprintf(__('%d traps received from this source with this oid'), $values['num']);
-				$children['children'][] = $children_data;
-			}
-			$data['children'][] = $children;
+		//Status
+		if ($trap["status"] == 0) {
+			$data[0] = html_print_image("images/pixel_red.png", true, array("title" => __('Not validated'), "width" => "20", "height" => "20"));
 		}
+		else {
+			$data[0] = html_print_image("images/pixel_green.png", true, array("title" => __('Validated'), "width" => "20", "height" => "20"));
+		}
+		
+		// Agent matching source address
+		$table->cellclass[$idx][1] = get_priority_class ($severity);
+		$agent = agents_get_agent_with_ip ($trap['source']);
+		if ($agent === false) {
+			if (! check_acl ($config["id_user"], 0, "AR")) {
+				continue;
+			}
+			$data[1] = '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&new_agent=1&direccion='.$trap["source"].'" title="'.__('Create agent').'">'.$trap["source"].'</a>';
+		}
+		else {
+			if (! check_acl ($config["id_user"], $agent["id_grupo"], "AR")) {
+				continue;
+			}
+			$data[1] = '<a href="index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente='.$agent["id_agente"].'" title="'.__('View agent details').'">';
+			$data[1] .= '<strong>'.$agent["nombre"].'</strong></a>';
+		}
+		
+		//OID
+		$table->cellclass[$idx][2] = get_priority_class ($severity);
+		$data[2] = '<a href="javascript: toggleVisibleExtendedInfo(' . $trap["id_trap"] . ');">' . (empty($trap["oid"]) ? __('N/A') : $trap["oid"]) .'</a>';
+		
+		//Count
+		if ($group_by) {
+			$sql = "SELECT * FROM ttrap WHERE 1=1 
+					$where_without_group
+					AND oid='".$trap['oid']."' 
+					AND source='".$trap['source']."'";
+			$group_traps = db_get_all_rows_sql($sql);
+			$count_group_traps = count($group_traps);
+			$table->cellclass[$idx][3] = get_priority_class ($severity);
+			$data[3] = '<strong>'.$count_group_traps.'</strong></a>';
+		}
+		//Value
+		$table->cellclass[$idx][4] = get_priority_class ($severity);
+		if (empty ($trap["value"])) {
+			$data[4] = __('N/A');
+		}
+		else {
+			$data[4] = ui_print_truncate_text($trap["value"], GENERIC_SIZE_TEXT, false);
+		}
+		
+		//User
+		$table->cellclass[$idx][5] = get_priority_class ($severity);
+		if (!empty ($trap["status"])) {
+			$data[5] = '<a href="index.php?sec=workspace&sec2=operation/users/user_edit&ver='.$trap["id_usuario"].'">'.substr ($trap["id_usuario"], 0, 8).'</a>';
+			if (!empty($trap["id_usuario"]))
+				$data[5] .= ui_print_help_tip(get_user_fullname($trap["id_usuario"]), true);
+		}
+		else {
+			$data[5] = '--';
+		}
+		
+		// Timestamp
+		$table->cellclass[$idx][6] = get_priority_class ($severity);
+		$data[6] = '<span title="'.$trap["timestamp"].'">';
+		$data[6] .= ui_print_timestamp ($trap["timestamp"], true);
+		$data[6] .= '</span>';
+		
+		// Use alert severity if fired
+		if (!empty ($trap["alerted"])) {
+			$data[7] = html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20", "border" => "0", "title" => __('Alert fired'))); 		
+		}
+		else {
+			$data[7] = html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20", "border" => "0", "title" => __('Alert not fired')));
+		}
+		
+		//Actions
+		$data[8] = "";
+		
+		if (empty ($trap["status"]) && check_acl ($config["id_user"], 0, "IW")) {
+			$data[8] .= '<a href="' . $url_snmp . '&check='.$trap["id_trap"].'">' . html_print_image("images/ok.png", true, array("border" => '0', "title" => __('Validate'))) . '</a> ';
+		}
+		if ($trap['source'] == '') {
+			$is_admin = db_get_value('is_admin', 'tusuario', 'id_user',$config['id_user']);
+			if ($is_admin) {
+				$data[8] .= '<a href="' . $url_snmp . '&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . '</a> ';
+			}
+		} else {
+			$agent_trap_group = db_get_value('id_grupo', 'tagente', 'nombre', $trap['source']);
+			if ((check_acl ($config["id_user"], $agent_trap_group, "AW"))) {
+				$data[8] .= '<a href="' . $url_snmp . '&delete='.$trap["id_trap"].'&offset='.$offset.'" onClick="javascript:return confirm(\''.__('Are you sure?').'\')">' . html_print_image("images/cross.png", true, array("border" => "0", "title" => __('Delete'))) . '</a> ';
+			}
+		}
+
+		$data[8] .= '<a href="javascript: toggleVisibleExtendedInfo(' . $trap["id_trap"] . ');">' . html_print_image("images/eye.png", true, array("alt" => __('Show more'), "title" => __('Show more'))) .'</a>';
+                $data[8] .= enterprise_hook ('editor_link', array ($trap));
+
+		
+		$data[9] = html_print_checkbox_extended ("snmptrapid[]", $trap["id_trap"], false, false, '', 'class="chk"', true);
+		
+		array_push ($table->data, $data);
+		
+		//Hiden file for description
+		$string = '<table style="border:solid 1px #D3D3D3;" width="90%" class="toggle">
+			<tr>
+				<td align="left" valign="top" width="15%" ><b>' . __('Custom data:') . '</b></td>
+				<td align="left" >';
+		
+		if ($group_by) {
+			$new_url = "index.php?sec=snmpconsole&sec2=operation/snmpconsole/snmp_view&" .
+			"filter_severity=" . $filter_severity . "&" .
+			"filter_fired=" . $filter_fired . "&" .
+			"filter_status=" . $filter_status . "&" .
+			"refr=" . ((int)get_parameter('refr', 0)) . "&" .
+			"pure=" . $config["pure"] . "&" .
+			"group_by=0&" .
+			"free_search_string=" . $free_search_string;
+			
+			$string .= '<a href='.$new_url.'>'.__('See more details').'</a>';
+		} else {	
+			// Print binding vars separately
+			$binding_vars = explode ("\t", $trap['oid_custom']);
+			foreach ($binding_vars as $var) {
+				$string .= $var . "<br/>";
+			}
+		}
+		
+		$string .= '</td>
+			</tr>
+			<tr>
+				<td align="left" valign="top">' . '<b>' . __('OID:') . '</td>
+				<td align="left"> ' . $trap['oid'] . '</td>
+			</tr>';
+		
+		if ($trap["description"] != "") {
+			$string .= '<tr>
+					<td align="left" valign="top">' . '<b>' . __('Description:') . '</td>
+					<td align="left">' . $trap['description'] . '</td>
+				</tr>';
+		}
+		
+		if ($trap["type"] != "") {
+			$trap_types = array(-1 => __('None'), 0 => __('Cold start (0)'), 1 => __('Warm start (1)'), 2 => __('Link down (2)'), 3 => __('Link up (3)'), 4 => __('Authentication failure (4)'), 5 => __('Other'));
+			
+			switch ($trap["type"]) {
+				case -1:
+					$desc_trap_type = __('None');
+					break;
+				case 0:
+					$desc_trap_type = __('Cold start (0)');
+					break;
+				case 1:
+					$desc_trap_type = __('Warm start (1)');
+					break;
+				case 2:
+					$desc_trap_type = __('Link down (2)');
+					break;
+				case 3:
+					$desc_trap_type = __('Link up (3)');
+					break;
+				case 4:
+					$desc_trap_type = __('Authentication failure (4)');
+					break;
+				default:
+					$desc_trap_type = __('Other');
+					break;
+			}
+			$string .= '<tr><td align="left" valign="top">' . '<b>' . __('Type:') . '</td><td align="left">' . $desc_trap_type . '</td></tr>';
+		}
+		
+		if ($group_by) {
+			$sql = "SELECT * FROM ttrap WHERE 1=1 
+					$where_without_group
+					AND oid='".$trap['oid']."' 
+					AND source='".$trap['source']."'";
+			$group_traps = db_get_all_rows_sql($sql);
+			$count_group_traps = count($group_traps);
+			
+			$sql = "SELECT timestamp FROM ttrap WHERE 1=1 
+					$where_without_group
+					AND oid='".$trap['oid']."' 
+					AND source='".$trap['source']."'
+					ORDER BY `timestamp` DESC";		
+			$last_trap = db_get_value_sql($sql);
+			
+			$sql = "SELECT timestamp FROM ttrap WHERE 1=1
+					$where_without_group
+					AND oid='".$trap['oid']."' 
+					AND source='".$trap['source']."'
+					ORDER BY `timestamp` ASC";
+			$first_trap = db_get_value_sql($sql);
+			
+			$string .= '<tr>
+					<td align="left" valign="top">' . '<b>' . __('Count:') . '</td>
+					<td align="left">' . $count_group_traps . '</td>
+				</tr>';
+			$string .= '<tr>
+					<td align="left" valign="top">' . '<b>' . __('First trap:') . '</td>
+					<td align="left">' . $first_trap . '</td>
+				</tr>';
+			$string .= '<tr>
+					<td align="left" valign="top">' . '<b>' . __('Last trap:') . '</td>
+					<td align="left">' . $last_trap . '</td>
+				</tr>';
+
+		}
+		$string .=  '</table>';
+		
+		$data = array($string); //$data = array($trap['description']);
+		$idx++;
+		$table->rowclass[$idx] = 'trap_info_' . $trap['id_trap'];
+		$table->colspan[$idx][0] = 10;
+		$table->rowstyle[$idx] = 'display: none;';
+		array_push ($table->data, $data);
+		
+		$idx++;
 	}
-	
-	echo graph_snmp_traps_treemap($data, 'auto', 500);
 }
 
+// No matching traps
+if ($idx == 0) {
+	echo '<div class="nf">' . __('No matching traps found') . '</div>';
+}
+else {
+	html_print_table ($table);
+}
+
+unset ($table);
+
+echo '<div style="width:98%; text-align:right;">';
+if (check_acl ($config["id_user"], 0, "IW")) {
+	html_print_submit_button (__('Validate'), "updatebt", false, 'class="sub ok"');
+}
+
+if (check_acl ($config['id_user'], 0, "IM")) {
+	echo "&nbsp;";
+	html_print_submit_button (__('Delete'), "deletebt", false, 'class="sub delete" onClick="javascript:return confirm(\''.__('Are you sure?').'\')"');
+}
+echo "</div></form>";
+
+
+echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
+echo '<h3>' . __('Status') . '</h3>';
+echo html_print_image("images/pixel_green.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Validated');
+echo '<br />';
+echo html_print_image("images/pixel_red.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not validated');
+echo '</div>';
+echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
+echo '<h3>' . __('Alert') . '</h3>';
+echo html_print_image("images/pixel_yellow.png", true, array("width" => "20", "height" => "20")) . ' - ' .__('Fired');
+echo '<br />';
+echo html_print_image("images/pixel_gray.png", true, array("width" => "20", "height" => "20")) . ' - ' . __('Not fired');
+echo '</div>';
+echo '<div style="float:left; padding-left:30px; line-height: 19px; vertical-align: top; width:120px;">';
+echo '<h3>' . __('Action') . '</h3>';
+echo html_print_image("images/ok.png", true) . ' - ' .__('Validate');
+echo '<br />';
+echo html_print_image("images/cross.png", true) . ' - ' . __('Delete');
+echo '</div>';
+echo '<div style="float:left; padding-left:30px; line-height: 17px; vertical-align: top; width:120px;">';
+echo '<h3>'.__('Legend').'</h3>';
+foreach (get_priorities () as $num => $name) {
+	echo '<span class="'.get_priority_class ($num).'">'.$name.'</span>';
+	echo '<br />';
+}
+echo '</div>';
+echo '<div style="clear:both;">&nbsp;</div>';
+
+
 ?>
 
 <script language="JavaScript" type="text/javascript">

From e8bf265f664c140f89bfde4ad5a42f3f552677fb Mon Sep 17 00:00:00 2001
From: artica <artica.devel@gmail.com>
Date: Wed, 24 Sep 2014 00:01:09 +0200
Subject: [PATCH 4/6] Auto-updated build strings.

---
 pandora_agents/unix/DEBIAN/control             | 2 +-
 pandora_agents/unix/DEBIAN/make_deb_package.sh | 2 +-
 pandora_agents/unix/pandora_agent              | 2 +-
 pandora_agents/unix/pandora_agent.redhat.spec  | 2 +-
 pandora_agents/unix/pandora_agent.spec         | 2 +-
 pandora_agents/win32/installer/pandora.mpi     | 2 +-
 pandora_agents/win32/pandora.cc                | 2 +-
 pandora_agents/win32/versioninfo.rc            | 2 +-
 pandora_console/DEBIAN/control                 | 2 +-
 pandora_console/DEBIAN/make_deb_package.sh     | 2 +-
 pandora_console/include/config_process.php     | 2 +-
 pandora_console/install.php                    | 2 +-
 pandora_console/pandora_console.redhat.spec    | 2 +-
 pandora_console/pandora_console.spec           | 2 +-
 pandora_console/pandoradb_data.sql             | 2 +-
 pandora_server/DEBIAN/control                  | 2 +-
 pandora_server/DEBIAN/make_deb_package.sh      | 2 +-
 pandora_server/lib/PandoraFMS/Config.pm        | 2 +-
 pandora_server/pandora_server.redhat.spec      | 2 +-
 pandora_server/pandora_server.spec             | 2 +-
 pandora_server/util/pandora_db.pl              | 2 +-
 pandora_server/util/pandora_manage.pl          | 2 +-
 22 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/pandora_agents/unix/DEBIAN/control b/pandora_agents/unix/DEBIAN/control
index 1fc12dbbeb..2d346ee065 100644
--- a/pandora_agents/unix/DEBIAN/control
+++ b/pandora_agents/unix/DEBIAN/control
@@ -1,5 +1,5 @@
 package: pandorafms-agent-unix
-Version: 5.1-140923
+Version: 5.1-140924
 Architecture: all
 Priority: optional
 Section: admin
diff --git a/pandora_agents/unix/DEBIAN/make_deb_package.sh b/pandora_agents/unix/DEBIAN/make_deb_package.sh
index 64a50ba914..8868aa37a4 100644
--- a/pandora_agents/unix/DEBIAN/make_deb_package.sh
+++ b/pandora_agents/unix/DEBIAN/make_deb_package.sh
@@ -14,7 +14,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
-pandora_version="5.1-140923"
+pandora_version="5.1-140924"
 
 echo "Test if you has the tools for to make the packages."
 whereis dpkg-deb | cut -d":" -f2 | grep dpkg-deb > /dev/null
diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent
index 531c28dd69..689b535368 100644
--- a/pandora_agents/unix/pandora_agent
+++ b/pandora_agents/unix/pandora_agent
@@ -41,7 +41,7 @@ my $Sem = undef;
 my $ThreadSem = undef;
 
 use constant AGENT_VERSION => '5.1';
-use constant AGENT_BUILD => '140923';
+use constant AGENT_BUILD => '140924';
 
 # Commands to retrieve total memory information in kB
 use constant TOTALMEMORY_CMDS => {
diff --git a/pandora_agents/unix/pandora_agent.redhat.spec b/pandora_agents/unix/pandora_agent.redhat.spec
index 3e3d7f70f3..cb41b7908f 100644
--- a/pandora_agents/unix/pandora_agent.redhat.spec
+++ b/pandora_agents/unix/pandora_agent.redhat.spec
@@ -3,7 +3,7 @@
 #
 %define name        pandorafms_agent_unix
 %define version     5.1
-%define release     140923
+%define release     140924
 
 Summary:            Pandora FMS Linux agent, PERL version
 Name:               %{name}
diff --git a/pandora_agents/unix/pandora_agent.spec b/pandora_agents/unix/pandora_agent.spec
index d0f95de33e..bda25cf396 100644
--- a/pandora_agents/unix/pandora_agent.spec
+++ b/pandora_agents/unix/pandora_agent.spec
@@ -3,7 +3,7 @@
 #
 %define name        pandorafms_agent_unix
 %define version     5.1
-%define release     140923
+%define release     140924
 
 Summary:            Pandora FMS Linux agent, PERL version
 Name:               %{name}
diff --git a/pandora_agents/win32/installer/pandora.mpi b/pandora_agents/win32/installer/pandora.mpi
index 0eaf9ad0d0..5330716913 100644
--- a/pandora_agents/win32/installer/pandora.mpi
+++ b/pandora_agents/win32/installer/pandora.mpi
@@ -186,7 +186,7 @@ UpgradeApplicationID
 {}
 
 Version
-{140923}
+{140924}
 
 ViewReadme
 {Yes}
diff --git a/pandora_agents/win32/pandora.cc b/pandora_agents/win32/pandora.cc
index 68885f4e44..053807a3e3 100644
--- a/pandora_agents/win32/pandora.cc
+++ b/pandora_agents/win32/pandora.cc
@@ -30,7 +30,7 @@ using namespace Pandora;
 using namespace Pandora_Strutils;
 
 #define PATH_SIZE    _MAX_PATH+1
-#define PANDORA_VERSION ("5.1(Build 140923)")
+#define PANDORA_VERSION ("5.1(Build 140924)")
 
 string pandora_path;
 string pandora_dir;
diff --git a/pandora_agents/win32/versioninfo.rc b/pandora_agents/win32/versioninfo.rc
index 1bac33f9e0..dd1ead41a2 100644
--- a/pandora_agents/win32/versioninfo.rc
+++ b/pandora_agents/win32/versioninfo.rc
@@ -11,7 +11,7 @@ BEGIN
       VALUE "LegalCopyright", "Artica ST"
       VALUE "OriginalFilename", "PandoraAgent.exe"
       VALUE "ProductName", "Pandora FMS Windows Agent"
-      VALUE "ProductVersion", "(5.1(Build 140923))"
+      VALUE "ProductVersion", "(5.1(Build 140924))"
       VALUE "FileVersion", "1.0.0.0"
     END
   END
diff --git a/pandora_console/DEBIAN/control b/pandora_console/DEBIAN/control
index f0f1531a97..ef372dc642 100644
--- a/pandora_console/DEBIAN/control
+++ b/pandora_console/DEBIAN/control
@@ -1,5 +1,5 @@
 package: pandorafms-console
-Version: 5.1-140923
+Version: 5.1-140924
 Architecture: all
 Priority: optional
 Section: admin
diff --git a/pandora_console/DEBIAN/make_deb_package.sh b/pandora_console/DEBIAN/make_deb_package.sh
index d48b1cdaf6..0684bdc8eb 100644
--- a/pandora_console/DEBIAN/make_deb_package.sh
+++ b/pandora_console/DEBIAN/make_deb_package.sh
@@ -14,7 +14,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
-pandora_version="5.1-140923"
+pandora_version="5.1-140924"
 
 package_pear=0
 package_pandora=1
diff --git a/pandora_console/include/config_process.php b/pandora_console/include/config_process.php
index c45b61696e..ef090cad67 100644
--- a/pandora_console/include/config_process.php
+++ b/pandora_console/include/config_process.php
@@ -22,7 +22,7 @@
 /**
  * Pandora build version and version 
  */
-$build_version = 'PC140923';
+$build_version = 'PC140924';
 $pandora_version = 'v5.1';
 
 // Do not overwrite default timezone set if defined.
diff --git a/pandora_console/install.php b/pandora_console/install.php
index 2d454e5eaf..4091bcf851 100644
--- a/pandora_console/install.php
+++ b/pandora_console/install.php
@@ -63,7 +63,7 @@
 		<div style='height: 10px'>
 			<?php
 $version = '5.1';
-$build = '140923';
+$build = '140924';
 			$banner = "v$version Build $build";
 			
 			error_reporting(0);
diff --git a/pandora_console/pandora_console.redhat.spec b/pandora_console/pandora_console.redhat.spec
index d8a6ed18fd..e7e59ce3b6 100644
--- a/pandora_console/pandora_console.redhat.spec
+++ b/pandora_console/pandora_console.redhat.spec
@@ -3,7 +3,7 @@
 #
 %define name        pandorafms_console
 %define version     5.1
-%define release     140923
+%define release     140924
 
 # User and Group under which Apache is running
 %define httpd_name  httpd
diff --git a/pandora_console/pandora_console.spec b/pandora_console/pandora_console.spec
index 9dec35f2b5..824aab81ab 100644
--- a/pandora_console/pandora_console.spec
+++ b/pandora_console/pandora_console.spec
@@ -3,7 +3,7 @@
 #
 %define name        pandorafms_console
 %define version     5.1
-%define release     140923
+%define release     140924
 %define httpd_name      httpd
 # User and Group under which Apache is running
 %define httpd_name  apache2
diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql
index 141161bf82..79f00e6753 100644
--- a/pandora_console/pandoradb_data.sql
+++ b/pandora_console/pandoradb_data.sql
@@ -38,7 +38,7 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES
 ('graph_res','5'),
 ('step_compact','1'),
 ('db_scheme_version','5.1'),
-('db_scheme_build','PD140923'),
+('db_scheme_build','PD140924'),
 ('show_unknown','0'),
 ('show_lastalerts','1'),
 ('style','pandora'),
diff --git a/pandora_server/DEBIAN/control b/pandora_server/DEBIAN/control
index d4b832c690..a632983a0f 100644
--- a/pandora_server/DEBIAN/control
+++ b/pandora_server/DEBIAN/control
@@ -1,5 +1,5 @@
 package: pandorafms-server
-Version: 5.1-140923
+Version: 5.1-140924
 Architecture: all
 Priority: optional
 Section: admin
diff --git a/pandora_server/DEBIAN/make_deb_package.sh b/pandora_server/DEBIAN/make_deb_package.sh
index 7fba1f2876..589070fa48 100644
--- a/pandora_server/DEBIAN/make_deb_package.sh
+++ b/pandora_server/DEBIAN/make_deb_package.sh
@@ -14,7 +14,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 
-pandora_version="5.1-140923"
+pandora_version="5.1-140924"
 
 package_cpan=0
 package_pandora=1
diff --git a/pandora_server/lib/PandoraFMS/Config.pm b/pandora_server/lib/PandoraFMS/Config.pm
index 9e26113577..258d834dfc 100644
--- a/pandora_server/lib/PandoraFMS/Config.pm
+++ b/pandora_server/lib/PandoraFMS/Config.pm
@@ -43,7 +43,7 @@ our @EXPORT = qw(
 
 # version: Defines actual version of Pandora Server for this module only
 my $pandora_version = "5.1";
-my $pandora_build = "140923";
+my $pandora_build = "140924";
 our $VERSION = $pandora_version." ".$pandora_build;
 
 # Setup hash
diff --git a/pandora_server/pandora_server.redhat.spec b/pandora_server/pandora_server.redhat.spec
index f29c772217..69dacbb54d 100644
--- a/pandora_server/pandora_server.redhat.spec
+++ b/pandora_server/pandora_server.redhat.spec
@@ -3,7 +3,7 @@
 #
 %define name        pandorafms_server
 %define version     5.1
-%define release     140923
+%define release     140924
 
 Summary:            Pandora FMS Server
 Name:               %{name}
diff --git a/pandora_server/pandora_server.spec b/pandora_server/pandora_server.spec
index db4e65fdcb..5b93aa0af0 100644
--- a/pandora_server/pandora_server.spec
+++ b/pandora_server/pandora_server.spec
@@ -3,7 +3,7 @@
 #
 %define name        pandorafms_server
 %define version     5.1
-%define release     140923
+%define release     140924
 
 Summary:            Pandora FMS Server
 Name:               %{name}
diff --git a/pandora_server/util/pandora_db.pl b/pandora_server/util/pandora_db.pl
index 53798069e1..3319e9dddd 100644
--- a/pandora_server/util/pandora_db.pl
+++ b/pandora_server/util/pandora_db.pl
@@ -33,7 +33,7 @@ use PandoraFMS::Tools;
 use PandoraFMS::DB;
 
 # version: define current version
-my $version = "5.1 PS140923";
+my $version = "5.1 PS140924";
 
 # Pandora server configuration
 my %conf;
diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl
index 7d862d9021..a747cf44c8 100644
--- a/pandora_server/util/pandora_manage.pl
+++ b/pandora_server/util/pandora_manage.pl
@@ -34,7 +34,7 @@ use Encode::Locale;
 Encode::Locale::decode_argv;
 
 # version: define current version
-my $version = "5.1 PS140923";
+my $version = "5.1 PS140924";
 
 # save program name for logging
 my $progname = basename($0);

From ad59a12e1d901c206b929a914adc2e663bcdc01a Mon Sep 17 00:00:00 2001
From: Vanessa Gil <vanessa.gil@artica.es>
Date: Wed, 24 Sep 2014 10:39:52 +0200
Subject: [PATCH 5/6] Changed view module detail in tree view. Ticket #1342.

---
 pandora_console/operation/tree.php | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php
index 8b06be0357..922f1c45b1 100644
--- a/pandora_console/operation/tree.php
+++ b/pandora_console/operation/tree.php
@@ -86,12 +86,14 @@ if (is_ajax ())
 	}
 	if ($printModuleTable) {
 		$id_module = get_parameter('id_module');
+		$id_agent = get_parameter('id_agent');
 		
 		if (defined ('METACONSOLE')) {
 			$server = metaconsole_get_connection ($server_name);
 			metaconsole_connect($server);
 		}
 		
+		treeview_printTable($id_agent, $server);
 		treeview_printModuleTable($id_module, $server);
 		
 		
@@ -451,7 +453,7 @@ if (is_ajax ())
 					echo " ";
 				}
 				
-				echo "<a style='vertical-align: middle;' onfocus='JavaScript: this.blur()' href='javascript: loadModuleTable(" . $row["id_agente_modulo"] . ", \"" . $server_name . "\")'>";
+				echo "<a style='vertical-align: middle;' onfocus='JavaScript: this.blur()' href='javascript: loadModuleTable(" . $row["id_agente_modulo"] . ", \"" . $server_name . "\"". "," . $id.")'>";				
 				echo ui_print_truncate_text(io_safe_output($row['nombre']), 40, true);
 				echo "</a>";
 				if ($row['quiet']) {
@@ -847,11 +849,11 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri
 		});
 	}
 	
-	function loadModuleTable(id_module, server_name) {
+	function loadModuleTable(id_module, server_name, id_agent) {
 		$.ajax({
 			type: "POST",
 			url: <?php echo '"' . ui_get_full_url("ajax.php", false, false, false) . '"'; ?>,
-			data: "page=<?php echo $_GET['sec2']; ?>&printModuleTable=1&id_module=" + id_module + "&server_name=" + server_name,
+			data: "page=<?php echo $_GET['sec2']; ?>&printModuleTable=1&id_module=" + id_module + "&server_name=" + server_name +"&id_agent="+id_agent,
 			success: function(data) {
 				$('#cont').html(data);
 				forced_title_callback();

From c1cbeac245331acca1b2aca4cbf39735de4a791d Mon Sep 17 00:00:00 2001
From: Alejandro Gallardo Escobar <alex@artica.es>
Date: Wed, 24 Sep 2014 13:09:15 +0200
Subject: [PATCH 6/6] Now the parent groups without modules appear on the group
 view table

* pandora_console/operation/agentes/group_view.php: Added the parent_id
	to the groups array.

* pandora_console/include/functions_groups.php: Fixed the function
	"groups_get_childrens". Improvements on the function
	"groups_get_group_row".
---
 pandora_console/include/functions_groups.php    | 17 ++++++++++++++---
 .../operation/agentes/group_view.php            |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php
index ca3e9b4e4f..78aa6df80d 100644
--- a/pandora_console/include/functions_groups.php
+++ b/pandora_console/include/functions_groups.php
@@ -250,7 +250,7 @@ function groups_get_childrens($parent, $groups = null, $onlyPropagate = false) {
 		
 		if ($group['propagate'] || $onlyPropagate) {
 			if ($group['parent'] == $parent) {
-				$return = $return + array($group['id_grupo'] => $group) + groups_get_childrens($group['id_grupo'], $groups);
+				$return = $return + array($group['id_grupo'] => $group) + groups_get_childrens($group['id_grupo'], $groups, $onlyPropagate);
 			}
 		}
 		
@@ -869,8 +869,19 @@ function groups_get_group_row($id_group, $group_all, $group, &$printed_groups) {
 	// Get stats for this group
 	$data = reporting_get_group_stats($id_group);
 	
-	if ($data["total_agents"] == 0)
-		return; // Skip empty groups
+	if ($data["total_agents"] == 0) {
+		if (!empty($group['childs'])) {
+			$group_childrens = groups_get_childrens($id_group, null, true);
+			$group_childrens_agents = groups_total_agents(array_keys($group_childrens));
+
+			if (empty($group_childrens_agents)) {
+				return; // Skip empty groups
+			}
+		}
+		else {
+			return; // Skip empty groups
+		}
+	}
 	
 	// Calculate entire row color
 	if ($data["monitor_alerts_fired"] > 0) {
diff --git a/pandora_console/operation/agentes/group_view.php b/pandora_console/operation/agentes/group_view.php
index 963290c629..fae1bddc9f 100644
--- a/pandora_console/operation/agentes/group_view.php
+++ b/pandora_console/operation/agentes/group_view.php
@@ -58,6 +58,7 @@ $groups_full = users_get_groups ($config['id_user'], "AR", true, true);
 $groups = array();
 foreach ($groups_full as $group) {
 	$groups[$group['id_grupo']]['name'] = $group['nombre'];
+	$groups[$group['id_grupo']]['parent'] = $group['parent'];
 	
 	if ($group['id_grupo'] != 0) {
 		$groups[$group['parent']]['childs'][] = $group['id_grupo'];