From 37d062af0e30462b4b07e43ae7c72bad5febe73e Mon Sep 17 00:00:00 2001
From: juanmanuelr <noreply@pandorafms.org>
Date: Mon, 7 Nov 2011 12:59:26 +0000
Subject: [PATCH] 2011-11-07 Juan Manuel Ramon <juanmanuel.ramon@artica.es>

	* operation/agentes/estado_ultimopaquete.php
	godmode/agentes/module_manager.php: Added pagination to this views.

	Fixes: #3417746



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5118 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     |  7 +++
 .../godmode/agentes/module_manager.php        | 45 ++++++++++++++++---
 .../agentes/estado_ultimopaquete.php          | 15 ++++++-
 3 files changed, 60 insertions(+), 7 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index b64c9bd4ca..c0cf410741 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,10 @@
+2011-11-07 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
+
+	* operation/agentes/estado_ultimopaquete.php
+	godmode/agentes/module_manager.php: Added pagination to this views.
+	
+	Fixes: #3417746
+
 2011-11-07 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
 
 	* godmode/modules/manage_network_components_form.php: Fixed network 
diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php
index 26fae6ebb0..a29a427c94 100644
--- a/pandora_console/godmode/agentes/module_manager.php
+++ b/pandora_console/godmode/agentes/module_manager.php
@@ -254,20 +254,52 @@ switch ($sortField) {
 		break;
 }
 
-$modules = db_get_all_rows_filter ('tagente_modulo',
+switch ($config["dbtype"]) {
+	case "mysql":
+	case "postgresql":	
+		$modules = db_get_all_rows_filter ('tagente_modulo',
+			array ('delete_pending' => 0,
+				'id_agente' => $id_agente,
+				'order' => $order,
+				'offset' => (int) get_parameter ('offset'),
+				'limit' => (int) $config['block_size']),
+			array ('id_agente_modulo', 'id_tipo_modulo', 'descripcion', 'nombre',
+				'max', 'min', 'module_interval', 'id_modulo', 'id_module_group',
+				'disabled','max_warning', 'min_warning', 'str_warning',
+				'max_critical', 'min_critical', 'str_critical'));
+		break;
+	case "oracle":		
+		$set = array();
+		$set['limit'] = (int) $config["block_size"];
+		$set['offset'] = (int) get_parameter ('offset');
+		$sql = db_get_all_rows_filter('tagente_modulo',
+			array ('delete_pending' => 0,
+				'id_agente' => $id_agente,
+				'order' => $order),
+			array ('id_agente_modulo', 'id_tipo_modulo', 'descripcion', 'dbms_lob.substr(nombre,4000,1) nombre',
+				'max', 'min', 'module_interval', 'id_modulo', 'id_module_group',
+				'disabled','max_warning', 'min_warning', 'str_warning',
+				'max_critical', 'min_critical', 'str_critical'), 'AND', false, true);
+		$modules = oracle_recode_query ($sql, $set, 'AND', false);
+		break;
+}
+		
+$total_modules = db_get_all_rows_filter ('tagente_modulo',
 	array ('delete_pending' => 0,
 		'id_agente' => $id_agente,
 		'order' => $order),
-	array ('id_agente_modulo', 'id_tipo_modulo', 'descripcion', 'nombre',
-		'max', 'min', 'module_interval', 'id_modulo', 'id_module_group',
-		'disabled','max_warning', 'min_warning', 'str_warning',
-		'max_critical', 'min_critical', 'str_critical'));
+	array ('count(*) total'));	
+	
+$total_modules = isset ($total_modules[0]['total']) ? $total_modules[0]['total'] : 0;	
 
 if ($modules === false) {
 	echo "<div class='nf'>".__('No available data to show')."</div>";
 	return;
 }
 
+// Prepare pagination
+ui_pagination ($total_modules, ui_get_url_refresh (array ('id_agente' => $id_agente,'sort_field' => $sortField, 'sort' => $sort)));
+
 $table->width = '98%';
 $table->head = array ();
 $table->head[0] = __('Name') . ' ' .
@@ -291,6 +323,7 @@ $table->head[6] = __('Warn');
 
 $table->head[7] = __('Action');
 
+$table->rowstyle = array();
 $table->style = array ();
 $table->style[0] = 'font-weight: bold';
 $table->size = array ();
@@ -330,9 +363,9 @@ foreach ($modules as $module) {
 	$data = array ();
 	if ($module['id_module_group'] != $last_modulegroup) {
 		$last_modulegroup = $module['id_module_group'];
-		
 		$data[0] = '<strong>'.modules_get_modulegroup_name ($last_modulegroup).'</strong>';
 		$i = array_push ($table->data, $data);
+		$table->rowstyle[$i - 1] = 'text-align: center';
 		$table->rowclass[$i - 1] = 'datos3';
 		if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK)
 				$table->colspan[$i - 1][0] = 8;
diff --git a/pandora_console/operation/agentes/estado_ultimopaquete.php b/pandora_console/operation/agentes/estado_ultimopaquete.php
index 75f2eb2906..e6c14de93e 100644
--- a/pandora_console/operation/agentes/estado_ultimopaquete.php
+++ b/pandora_console/operation/agentes/estado_ultimopaquete.php
@@ -179,13 +179,26 @@ $modules = db_get_all_rows_filter ('tagente_modulo, tagente_estado',
 		'disabled' => 0,
 		'tagente_estado.utimestamp != 0',
 		'tagente_modulo.id_agente = '.$id_agente,
-		'order' => $order));
+		'order' => $order,
+		'offset' => (int) get_parameter ('offset'),
+		'limit' => (int) $config['block_size']));
+		
+$total_modules = db_get_all_rows_filter ('tagente_modulo',
+	array ('delete_pending' => 0,
+		'id_agente' => $id_agente,
+		'order' => $order),
+	array ('count(*) total'));	
+	
+$total_modules = isset ($total_modules[0]['total']) ? $total_modules[0]['total'] : 0;		
 
 if ($modules === false) {
 	echo "<div class='nf'>".__('This agent doesn\'t have any module')."</div>";
 	return;
 }
 
+// Prepare pagination
+ui_pagination ($total_modules, ui_get_url_refresh (array ('id_agente' => $id_agente, 'tab' => 'data','sort_field' => $sortField, 'sort' => $sort)));
+
 $isFunctionPolicies = enterprise_include_once ('include/functions_policies.php');
 
 echo "<table width='98%' cellpadding='3' cellspacing='3' class='databox'>";