From 6649b8ad85b2ecc11fdfe900fdd61827f0de437f Mon Sep 17 00:00:00 2001
From: mdtrooper <tres.14159@gmail.com>
Date: Wed, 12 Sep 2012 15:53:58 +0000
Subject: [PATCH] 2012-09-12 Miguel de Dios <miguel.dedios@artica.es>

	* extensions/insert_data.php,
	operation/incidents/incident_detail.php: started to use the new function
	"ui_print_agent_autocomplete_input" to make more easy (and standar)
	the autocomplete agent input.

	* godmode/agentes/agent_manager.php: erased unused source code for
	old ajax call, and started to use the new function
	"ui_print_agent_autocomplete_input" to make more easy (and standar)
	the autocomplete agent input.

	* operation/agentes/exportdata.php: erased duplicated source code
	for call ajax, and rewrote some javascript to use same page to
	ajax.

	* godmode/alerts/alert_list.builder.php,
	godmode/events/event_edit_filter.php,
	godmode/reporting/visual_console_builder.editor.js: rewrote some
	javascript to use same page to ajax.

	* include/ajax/agent.php: cleaned source code style.

	* include/functions_ui.php: removed the old unused code as
	the functions "ui_print_ui_agents_list" and "ui_popup_help". And
	added the first version of "ui_print_agent_autocomplete_input", and
	this function maybe will be changing for a some time.

	* include/functions_html.php: into the function
	"html_print_input_text_extended" added code to use the $alt
	parameter (never it have been used before) and added the function
	"html_print_input_hidden_extended" with more parameters than the
	simple "html_print_input_hidden" function.

	* include/javascript/pandora.js: marked as Deprecated the function
	"agent_module_autocomplete".




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6965 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     |  37 ++
 pandora_console/extensions/insert_data.php    | 138 ++-----
 .../godmode/agentes/agent_manager.php         | 105 +----
 .../godmode/alerts/alert_list.builder.php     |   2 +-
 .../godmode/events/event_edit_filter.php      |   2 +-
 .../visual_console_builder.editor.js          |   2 +-
 pandora_console/include/ajax/agent.php        | 108 ++---
 pandora_console/include/functions_html.php    |  41 ++
 pandora_console/include/functions_ui.php      | 388 +++++++++++++-----
 pandora_console/include/javascript/pandora.js |   6 +
 .../operation/agentes/exportdata.php          | 159 ++-----
 .../operation/incidents/incident_detail.php   |  56 ++-
 12 files changed, 536 insertions(+), 508 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index 1d70357d86..00294e8c6d 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,40 @@
+2012-09-12 Miguel de Dios <miguel.dedios@artica.es>
+
+	* extensions/insert_data.php,
+	operation/incidents/incident_detail.php: started to use the new function
+	"ui_print_agent_autocomplete_input" to make more easy (and standar)
+	the autocomplete agent input.
+	
+	* godmode/agentes/agent_manager.php: erased unused source code for
+	old ajax call, and started to use the new function
+	"ui_print_agent_autocomplete_input" to make more easy (and standar)
+	the autocomplete agent input.
+	
+	* operation/agentes/exportdata.php: erased duplicated source code
+	for call ajax, and rewrote some javascript to use same page to
+	ajax.
+	
+	* godmode/alerts/alert_list.builder.php,
+	godmode/events/event_edit_filter.php,
+	godmode/reporting/visual_console_builder.editor.js: rewrote some
+	javascript to use same page to ajax.
+	
+	* include/ajax/agent.php: cleaned source code style.
+	
+	* include/functions_ui.php: removed the old unused code as
+	the functions "ui_print_ui_agents_list" and "ui_popup_help". And
+	added the first version of "ui_print_agent_autocomplete_input", and
+	this function maybe will be changing for a some time.
+	
+	* include/functions_html.php: into the function
+	"html_print_input_text_extended" added code to use the $alt
+	parameter (never it have been used before) and added the function
+	"html_print_input_hidden_extended" with more parameters than the
+	simple "html_print_input_hidden" function.
+	
+	* include/javascript/pandora.js: marked as Deprecated the function
+	"agent_module_autocomplete".
+
 2012-09-12  Sergio Martin <sergio.martin@artica.es>
 
 	* godmode/agentes/module_manager_editor_plugin.php
diff --git a/pandora_console/extensions/insert_data.php b/pandora_console/extensions/insert_data.php
index d92fbb3ea1..e552a6ceee 100644
--- a/pandora_console/extensions/insert_data.php
+++ b/pandora_console/extensions/insert_data.php
@@ -110,7 +110,7 @@ function mainInsertData() {
 			}
 			else {
 				$result = createXMLData($agent, $agentModule, $date_xml, $data);
-
+				
 				if($result) {
 					$done++;
 				}
@@ -146,11 +146,18 @@ function mainInsertData() {
 	$table->style[0] = 'font-weight: bolder;';
 	
 	$table->data = array();
+	
 	$table->data[0][0] = __('Agent');
-	$src_code = html_print_image('images/lightning.png', true, false, true);
-	$table->data[0][1] = html_print_input_text_extended ('id_agent', $id_agent, 'text_id_agent', '', 30, 100, false, '',
-		array('style' => 'background: url(' . $src_code . ') no-repeat right;'), true)
-		. ui_print_help_tip(__('Type at least two characters to search'), true);
+	$params = array();
+	$params['return'] = true;
+	$params['show_helptip'] = true;
+	$params['input_name'] = 'id_agent';
+	$params['value'] = $id_agent;
+	$params['javascript_is_function_select'] = true;
+	$params['javascript_name_function_select'] = 'custom_select_function';
+	$params['javascript_code_function_select'] = '';
+	$table->data[0][1] = ui_print_agent_autocomplete_input($params);
+	
 	$table->data[1][0] = __('Module');
 	$modules = array ();
 	if ($id_agent)
@@ -182,95 +189,6 @@ function mainInsertData() {
 <script type="text/javascript">
 	/* <![CDATA[ */
 	$(document).ready (function () {
-		$("#text_id_agent").autocomplete({
-			minLength: 2,
-			source: function( request, response ) {
-				var term = request.term; //Word to search
-				
-				var data_params = {
-					page: "operation/agentes/exportdata",
-					"search_agents_2": 1,
-					"q": term,
-					id_group: function() {
-						return $("#id_group").val();
-					}
-				};
-				
-				jQuery.ajax ({
-					data: data_params,
-					async: false,
-					type: "POST",
-					url: action="ajax.php",
-					timeout: 10000,
-					dataType: "json",
-					success: function (data) {
-						response(data);
-						return;
-					}
-				});
-				return;
-			},
-			select: function( event, ui ) {
-				var agent_name = ui.item.name;
-				
-				//Put the name
-				$(this).val(agent_name);
-				
-				$('#id_agent_module').empty ();
-				var inputs = [];
-				inputs.push ("agent_name=" + agent_name);
-				inputs.push ('filter=delete_pending = 0');
-				inputs.push ("get_agent_modules_json=1");
-				inputs.push ("page=operation/agentes/ver_agente");
-				jQuery.ajax ({
-					data: inputs.join ("&"),
-					type: 'GET',
-					url: action="ajax.php",
-					timeout: 10000,
-					dataType: 'json',
-					success: function (data) {
-						$('#id_agent_module').append ($('<option></option>').attr ('value', 0).text ("--"));
-						jQuery.each (data, function (i, val) {
-							s = js_html_entity_decode (val['nombre']);
-							$('#id_agent_module').append ($('<option></option>').attr ('value', val['id_agente_modulo']).text (s));
-						});
-						$('#id_agent_module').enable();
-						$('#id_agent_module').fadeIn ('normal');
-
-						$('#submit-submit').enable();
-						$('#submit-submit').fadeIn ('normal');
-					}
-				});
-				
-				return false;
-			}
-		})
-		.data( "autocomplete")._renderItem = function( ul, item ) {
-			if ((item.ip == "") || (typeof(item.ip) == "undefined")) {
-				text = "<a>" + item.name + "</a>";
-			}
-			else {
-				text = "<a>" + item.name
-					+ "<br><span style=\"font-size: 70%; font-style: italic;\">IP:" + item.ip + "</span></a>";
-			}
-			
-			return $("<li></li>")
-				.data("item.autocomplete", item)
-				.append(text)
-				.appendTo(ul);
-		};
-		
-		//Force the size of autocomplete
-		$(".ui-autocomplete").css("max-height", "100px");
-		$(".ui-autocomplete").css("overflow-y", "auto");
-		/* prevent horizontal scrollbar */
-		$(".ui-autocomplete").css("overflow-x", "hidden");
-		/* add padding to account for vertical scrollbar */
-		$(".ui-autocomplete").css("padding-right", "20px");
-		
-		//Force to style of items
-		$(".ui-autocomplete").css("text-align", "left");
-
 		$("#text-time").timeEntry ({
 			spinnerImage: 'images/time-entry.png',
 			spinnerSize: [20, 20, 0]
@@ -279,6 +197,36 @@ function mainInsertData() {
 		$("#text-date").datepicker ();
 		
 	});
+	
+	function custom_select_function(agent_name) {
+		$('#id_agent_module').empty ();
+		
+		var inputs = [];
+		inputs.push ("agent_name=" + agent_name);
+		inputs.push ('filter=delete_pending = 0');
+		inputs.push ("get_agent_modules_json=1");
+		inputs.push ("page=operation/agentes/ver_agente");
+		jQuery.ajax ({
+			data: inputs.join ("&"),
+			type: 'GET',
+			url: action="ajax.php",
+			timeout: 10000,
+			dataType: 'json',
+			success: function (data) {
+				$('#id_agent_module').append ($('<option></option>').attr ('value', 0).text ("--"));
+				jQuery.each (data, function (i, val) {
+					s = js_html_entity_decode (val['nombre']);
+					$('#id_agent_module').append ($('<option></option>').attr ('value', val['id_agente_modulo']).text (s));
+				});
+				$('#id_agent_module').enable();
+				$('#id_agent_module').fadeIn ('normal');
+				
+				$('#submit-submit').enable();
+				$('#submit-submit').fadeIn ('normal');
+			}
+		});
+	}
+	
 	/* ]]> */
 </script>
 <?php
@@ -286,4 +234,4 @@ function mainInsertData() {
 
 extensions_add_godmode_function('mainInsertData');
 extensions_add_godmode_menu_option(__('Insert Data'), 'AW', 'gagente');
-?>
+?>
\ No newline at end of file
diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php
index 8f064d5401..53db670a45 100644
--- a/pandora_console/godmode/agentes/agent_manager.php
+++ b/pandora_console/godmode/agentes/agent_manager.php
@@ -16,39 +16,8 @@
 if (is_ajax ()) {
 	global $config;
 	
-	$search_parents = (bool) get_parameter ('search_parents');
 	$search_parents_2 = (bool) get_parameter ('search_parents_2');
 	
-	if ($search_parents) {
-		require_once ('include/functions_agents.php');
-		
-		$id_agent = (int) get_parameter ('id_agent');
-		$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
-		
-		$filter = array ();
-		
-		switch ($config['dbtype']) {
-			case "mysql":
-			case "postgresql":
-				$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
-				break;
-			case "oracle":
-				$filter[] = '(upper(nombre) LIKE upper("%'.$string.'%") OR upper(direccion) LIKE upper("%'.$string.'%") OR upper(comentarios) LIKE upper("%'.$string.'%"))';
-				break;
-		}
-		$filter[] = 'id_agente != '.$id_agent;
-		
-		$agents = agents_get_agents ($filter, array ('nombre', 'direccion'));
-		if ($agents === false)
-			return;
-		
-		foreach ($agents as $agent) {
-			echo io_safe_output($agent['nombre']) . "|" . io_safe_output($agent['direccion'])  . "\n";
-		}
-		
-		return;
-	}
-	
 	if ($search_parents_2) {
 		require_once ('include/functions_agents.php');
 		
@@ -220,11 +189,12 @@ $groups = users_get_groups ($config["id_user"], "AR",false);
 $agents = agents_get_group_agents (array_keys ($groups));
 
 $table->data[2][0] = __('Parent');
-//Image src with skins
-$src_code = html_print_image('images/lightning.png', true, false, true);
-$table->data[2][1] = html_print_input_text_extended ('id_parent', agents_get_name ($id_parent), 'text-id_parent', '', 30, 100, false, '',
-	array('style' => 'background: url(' . $src_code . ') no-repeat right;'), true)
-	. ui_print_help_tip (__("Type at least two characters to search"), true);
+$params = array();
+$params['return'] = true;
+$params['show_helptip'] = true;
+$params['input_name'] = 'id_parent';
+$params['value'] = agents_get_name ($id_parent);
+$table->data[2][1] = ui_print_agent_autocomplete_input($params);
 
 $table->data[2][1] .= html_print_checkbox ("cascade_protection", 1, $cascade_protection, true).__('Cascade protection'). "&nbsp;" . ui_print_help_icon("cascade_protection", true);
 
@@ -291,7 +261,7 @@ if (!$new_agent) {
 		$table->data[3][1] .= '</a>'.ui_print_help_tip (__('Delete this conf file implies that for restore you must reactive remote config in the local agent.'), true);
 	}
 	else
-		$table->data[3][1] = '<em>'.__('Not available').'</em>';		
+		$table->data[3][1] = '<em>'.__('Not available').'</em>';
 }
 else
 	$table->data[3][1] = '<em>'.__('Not available').'</em>';
@@ -365,7 +335,7 @@ if($fields === false) $fields = array();
 foreach ($fields as $field) {
 	
 	$data[0] = '<b>'.$field['name'].'</b>';
-		
+	
 	$custom_value = db_get_value_filter('description', 'tagent_custom_data', array('id_field' => $field['id_field'], 'id_agent' => $id_agente));
 	
 	if($custom_value === false) {
@@ -435,65 +405,6 @@ function changeIcons() {
 
 $(document).ready (function () {
 	$("select#id_os").pandoraSelectOS ();
-	
-	$("#text-id_parent").autocomplete({
-		minLength: 2,
-		source: function( request, response ) {
-			var term = request.term; //Word to search
-			
-			var data_params = {
-				"page": "godmode/agentes/agent_manager",
-				"search_parents_2": 1,
-				"q": term};
-			
-			jQuery.ajax ({
-				data: data_params,
-				async: false,
-				type: "POST",
-				url: action="ajax.php",
-				timeout: 10000,
-				dataType: "json",
-				success: function (data) {
-					response(data);
-					return;
-				}
-			});
-			return;
-		},
-		select: function( event, ui ) {
-			var agent_name = ui.item.name;
-			
-			//Put the name
-			$(this).val(agent_name);
-			
-			return false;
-		}
-	})
-	.data( "autocomplete")._renderItem = function( ul, item ) {
-		if (item.ip == "") {
-			text = "<a>" + item.name + "</a>";
-		}
-		else {
-			text = "<a>" + item.name
-				+ "<br><span style=\"font-size: 70%; font-style: italic;\">IP:" + item.ip + "</span></a>";
-		}
-		
-		return $("<li></li>")
-			.data("item.autocomplete", item)
-			.append(text)
-			.appendTo(ul);
-	};
-	
-	//Force the size of autocomplete
-	$(".ui-autocomplete").css("max-height", "100px");
-	$(".ui-autocomplete").css("overflow-y", "auto");
-	/* prevent horizontal scrollbar */
-	$(".ui-autocomplete").css("overflow-x", "hidden");
-	/* add padding to account for vertical scrollbar */
-	$(".ui-autocomplete").css("padding-right", "20px");
-	
-	//Force to style of items
-	$(".ui-autocomplete").css("text-align", "left");
 });
 /* ]]> */
 </script>
\ No newline at end of file
diff --git a/pandora_console/godmode/alerts/alert_list.builder.php b/pandora_console/godmode/alerts/alert_list.builder.php
index 4abd33d1ad..8dbec73fd2 100644
--- a/pandora_console/godmode/alerts/alert_list.builder.php
+++ b/pandora_console/godmode/alerts/alert_list.builder.php
@@ -148,7 +148,7 @@ $(document).ready (function () {
 			var term = request.term; //Word to search
 			
 			var data_params = {
-				page: "operation/agentes/exportdata",
+				page: "include/ajax/agent",
 				"search_agents_2": 1,
 				id_group: function() { return $("#id_group").val(); },
 				"q": term};
diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php
index 5429737e74..196a0ce6ba 100644
--- a/pandora_console/godmode/events/event_edit_filter.php
+++ b/pandora_console/godmode/events/event_edit_filter.php
@@ -285,7 +285,7 @@ $(document).ready( function() {
 			var term = request.term; //Word to search
 			
 			var data_params = {
-				page: "operation/agentes/exportdata",
+				page: "include/ajax/agent",
 				"search_agents_2": 1,
 				id_group: function() { return $("#id_group").val(); },
 				"q": term};
diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js
index 109858bc6c..b6401d28cd 100644
--- a/pandora_console/godmode/reporting/visual_console_builder.editor.js
+++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js
@@ -62,7 +62,7 @@ function eventsTextAgent() {
 				var params = [];
 				params.push("all=enabled");
 				params.push("search_agents_2=1");
-				params.push("page=operation/agentes/exportdata");
+				params.push("page=include/ajax/agent");
 				params.push("id_group="+ $("#group").val());
 				params.push("q="+ term);
 				jQuery.ajax ({
diff --git a/pandora_console/include/ajax/agent.php b/pandora_console/include/ajax/agent.php
index 7a9221baba..1d244d5751 100644
--- a/pandora_console/include/ajax/agent.php
+++ b/pandora_console/include/ajax/agent.php
@@ -48,44 +48,44 @@ if ($get_agents_group) {
 }
 
 if ($search_agents && ($config['metaconsole'] == 0)) {
-
+	
 	require_once ('include/functions_agents.php');
-
-    $id_agent = (int) get_parameter ('id_agent');
-    $string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
-    $id_group =  get_parameter('id_group', -1);
-    $addedItems = html_entity_decode((string) get_parameter('add'));
-    $addedItems = json_decode($addedItems);
-
-    if ($addedItems != null) {
-        foreach ($addedItems as $item) {
-            echo $item . "|\n";
-        }
-    }
-
-    $filter = array ();
+	
+	$id_agent = (int) get_parameter ('id_agent');
+	$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
+	$id_group =  get_parameter('id_group', -1);
+	$addedItems = html_entity_decode((string) get_parameter('add'));
+	$addedItems = json_decode($addedItems);
+	
+	if ($addedItems != null) {
+		foreach ($addedItems as $item) {
+			echo $item . "|\n";
+		}
+	}
+	
+	$filter = array ();
 	switch ($config["dbtype"]) {
 		case "mysql":
-		case "postgresql":	
-	    		$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
+		case "postgresql":
+				$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
 			break;
 		case "oracle":
-	    		$filter[] = '(UPPER(nombre)  LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
+				$filter[] = '(UPPER(nombre)  LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
 			break;
-	}			
+	}
 	
-	if ($id_group != -1)	
+	if ($id_group != -1)
 		$filter['id_grupo'] = $id_group;
-
-    $agents = agents_get_agents ($filter, array ('id_agente','nombre', 'direccion'));
-    if ($agents === false)
-        return;
-
-    foreach ($agents as $agent) {
-        echo io_safe_output($agent['nombre']) . "|" . io_safe_output($agent['id_agente']) . "|" . io_safe_output($agent['direccion']) . "\n";
-    }
-
-    return;
+	
+	$agents = agents_get_agents ($filter, array ('id_agente','nombre', 'direccion'));
+	if ($agents === false)
+		return;
+	
+	foreach ($agents as $agent) {
+		echo io_safe_output($agent['nombre']) . "|" . io_safe_output($agent['id_agente']) . "|" . io_safe_output($agent['direccion']) . "\n";
+	}
+	
+	return;
 }
 elseif ($search_agents && ($config['metaconsole'] == 1)) {
 	$servers = db_get_all_rows_sql ("SELECT * FROM tmetaconsole_setup");
@@ -103,26 +103,26 @@ elseif ($search_agents && ($config['metaconsole'] == 1)) {
 		$id_group = (int) get_parameter('id_group');
 		$addedItems = html_entity_decode((string) get_parameter('add'));
 		$addedItems = json_decode($addedItems);
-
+		
 		if ($addedItems != null) {
 			foreach ($addedItems as $item) {
 				echo $item . "|\n";
 			}
 		}
-
+		
 		$filter = array ();
 		switch ($config["dbtype"]) {
 			case "mysql":
-			case "postgresql":	
+			case "postgresql":
 					$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
 				break;
 			case "oracle":
 					$filter[] = '(UPPER(nombre)  LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
 				break;
-		}			
-			
+		}
+		
 		$filter['id_grupo'] = $id_group;
-
+		
 		$agents = agents_get_agents ($filter, array ('id_agente','nombre', 'direccion'));
 		if ($agents === false)
 			continue;
@@ -136,22 +136,22 @@ elseif ($search_agents && ($config['metaconsole'] == 1)) {
 }
 
 if ($search_agents_2 && (!defined('METACONSOLE'))) {
-
+	
 	require_once ('include/functions_agents.php');
-
+	
 	$id_agent = (int) get_parameter ('id_agent');
 	$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
 	$id_group = (int) get_parameter('id_group', -1);
 	$addedItems = html_entity_decode((string) get_parameter('add'));
 	$addedItems = json_decode($addedItems);
 	$all = (string)get_parameter('all', 'all');
-
+	
 	if ($addedItems != null) {
 		foreach ($addedItems as $item) {
 			echo $item . "|\n";
 		}
 	}
-
+	
 	$filter = array ();
 	switch ($config['dbtype']) {
 		case "mysql":
@@ -164,27 +164,27 @@ if ($search_agents_2 && (!defined('METACONSOLE'))) {
 			$filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
 			break;
 	}
-
+	
 	if ($id_group != -1)
 	$filter['id_grupo'] = $id_group;
-
+	
 	switch ($all) {
 		case 'enabled':
 			$filter['disabled'] = 0;
 			break;
 	}
-
+	
 	$agents = agents_get_agents ($filter, array ('id_agente', 'nombre', 'direccion'));
 	if ($agents === false)
 		$agents = array();
-		
+	
 	$data = array();
 	foreach ($agents as $agent) {
 		$data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), 'ip' => io_safe_output($agent['direccion']));
 	}
-		
+	
 	echo json_encode($data);
-
+	
 	return;
 }
 elseif ($search_agents_2 && ($config['metaconsole'] == 1) && defined('METACONSOLE')) {
@@ -198,19 +198,19 @@ elseif ($search_agents_2 && ($config['metaconsole'] == 1) && defined('METACONSOL
 		if (metaconsole_load_external_db ($server) != NOERR) {
 			continue;
 		}
-	
+		
 		$id_agent = (int) get_parameter ('id_agent');
 		$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
 		$id_group = (int) get_parameter('id_group');
 		$addedItems = html_entity_decode((string) get_parameter('add'));
 		$addedItems = json_decode($addedItems);
-	
+		
 		if ($addedItems != null) {
 			foreach ($addedItems as $item) {
 				echo $item . "|\n";
 			}
 		}
-	
+		
 		$filter = array ();
 		switch ($config["dbtype"]) {
 			case "mysql":
@@ -221,9 +221,9 @@ elseif ($search_agents_2 && ($config['metaconsole'] == 1) && defined('METACONSOL
 				$filter[] = '(UPPER(nombre)  LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
 				break;
 		}
-			
+		
 		$filter['id_grupo'] = $id_group;
-	
+		
 		$agents = agents_get_agents ($filter, array ('id_agente','nombre', 'direccion'));
 		if ($agents === false)
 			continue;
@@ -235,10 +235,10 @@ elseif ($search_agents_2 && ($config['metaconsole'] == 1) && defined('METACONSOL
 		}
 		//Restore db connection
 		metaconsole_restore_db();
-
+	
 	}
-
+	
 	echo json_encode($data);
 	return;
 }
-?>
+?>
\ No newline at end of file
diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php
index 5640e675e9..0873483534 100644
--- a/pandora_console/include/functions_html.php
+++ b/pandora_console/include/functions_html.php
@@ -542,6 +542,10 @@ function html_print_input_text_extended ($name, $value, $id, $alt, $size, $maxle
 		$attributes = array ();
 	}
 	
+	if (!empty($alt)) {
+		$output .= 'alt="' . $alt . '" ';
+	}
+	
 	//Attributes specified by function call
 	$attrs = array ("name" => "unnamed", "value" => "",
 		"id" => "text-".sprintf ('%04d', $idcounter),
@@ -713,6 +717,43 @@ function html_print_input_hidden ($name, $value, $return = false, $class = false
 	
 	if ($return)
 		return $output;
+	
+	echo $output;
+}
+
+/**
+ * Render an input hidden element. Extended version, use html_print_input_hidden() to simplify.
+ *
+ * The element will have an id like: "hidden-$name"
+ * 
+ * @param string $name Input name.
+ * @param string $value Input value.
+ * @param string $id Input value.
+ * @param bool $return Whether to return an output string or echo now (optional, echo by default).
+ * @param string $class Set the class of input.
+ *
+ * @return string HTML code if return parameter is true.
+ */
+function html_print_input_hidden_extended($name, $value, $id, $return = false, $class = false) {
+	if ($class !== false) {
+		$classText = 'class="' . $class . '"';
+	}
+	else {
+		$classText = '';
+	}
+	
+	if (empty($id)) {
+		$ouput_id = 'hidden-' . $name;
+	}
+	else {
+		$ouput_id = $id;
+	}
+	
+	$output = '<input id="' . $ouput_id . '" name="' . $name . '" type="hidden" ' . $classText . ' value="' . $value . '" />';
+	
+	if ($return)
+		return $output;
+	
 	echo $output;
 }
 
diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php
index 60121090d3..d84aee78a5 100644
--- a/pandora_console/include/functions_ui.php
+++ b/pandora_console/include/functions_ui.php
@@ -1703,95 +1703,6 @@ function ui_print_status_image ($type, $title = "", $return = false, $options =
 	return html_print_image ($imagepath, $return, $options);
 }
 
-/**
- * Prints a form to search agents.
- *
- * @param array Extra options for the function. To be documented.
- * @param array Extra and hidden filter for the agent search.
- */
-function ui_print_ui_agents_list ($options = false, $filter = false, $return = false) {
-	global $config;
-	
-	$output = '';
-	
-	$group_filter = true;
-	$text_filter = true;
-	$access = 'AR';
-	$table_heads = array (__('Name'), __('Group'), __('Status'));
-	$table_renders = array ('view_link', 'group', 'status');
-	$table_align = array ('', '', 'center');
-	$table_size = array ('50%', '45%', '5%');
-	$fields = false;
-	$show_filter_form = true;
-	if (is_array ($options)) {
-		if (isset ($options['group_filter']))
-			$group_filter = (bool) $options['group_filter'];
-		if (isset ($options['text_filter']))
-			$text_filter = (bool) $options['text_filter'];
-		if (isset ($options['access']))
-			$access = (string) $options['access'];
-		if (isset ($options['table_heads']))
-			$table_heads = (array) $options['table_heads'];
-		if (isset ($options['table_renders']))
-			$table_renders = (array) $options['table_renders'];
-		if (isset ($options['table_align']))
-			$table_align = (array) $options['table_align'];
-		if (isset ($options['table_size']))
-			$table_size = (array) $options['table_size'];
-		if (isset ($options['fields']))
-			$fields = (array) $options['fields'];
-		if (isset ($options['show_filter_form']))
-			$show_filter_form = (bool) $options['show_filter_form'];
-		
-		if (count ($table_renders) != count ($table_heads))
-			trigger_error ('Different count for table_renders and table_heads options');
-		
-		unset ($options);
-	}
-	
-	if ($return)
-		return ui_get_include_contents ($config['homedir'].'/general/ui/agents_list.php',
-			get_defined_vars ());
-	
-	include ($config['homedir'].'/general/ui/agents_list.php');
-}
-
-/**
- * Get the content of a PHP file instead of dumping to the output.
- * 
- * Picked from PHP official doc.
- *
- * @param string File name to include and get content.
- * @param array Extra parameters in an indexed array to be passed to the file.
- *
- * @return string Content of the file after being processed. False if the file
- * could not be included.
- */
-function ui_get_include_contents ($filename, $params = false) {
-	global $config;
-	
-	ob_start ();
-	
-	if (is_array ($params)) {
-		extract ($params);
-	}
-	
-	$filename = realpath ($filename);
-	if (strncmp ($config["homedir"], $filename, strlen ($config["homedir"])) != 0) {
-		return false;
-	}
-	
-	$result = include ($filename);
-	if ($result === false) {
-		ob_end_clean ();
-		return false;
-	}
-	
-	$contents = ob_get_contents ();
-	ob_end_clean ();
-
-	return $contents;
-}
 /**
  * Print a code into a DIV and enable a toggle to show and hide it
  * 
@@ -2116,21 +2027,286 @@ function ui_print_page_header ($title, $icon = "", $return = false, $help = "",
 	return $buffer;
 }
 
-/** 
- * Add a help link to show help in a popup window.
- * 
- *
- * @param string $help_id Help id to be shown when clicking.
- * @param bool $return Whether to print this (false) or return (true)
- * 
- * @return string Link with the popup.
- */
-function ui_popup_help ($help_id, $return = false) {
-	$output = "&nbsp;<a href='javascript:help_popup(".$help_id.")'>[H]</a>";
-	if ($return)
-		return $output;
-	echo $output;
+function ui_print_agent_autocomplete_input($parameters) {
+	global $config;
+	
+	//Normalize and extract the data from $parameters
+	//------------------------------------------------------------------
+	$return = false; //Default value
+	if (isset($parameters['return'])) {
+		$return = $parameters['return'];
+	}
+	
+	$input_name = uniqid('agent_autocomplete_'); //Default value
+	if (isset($parameters['input_name'])) {
+		$input_name = $parameters['input_name'];
+	}
+	
+	$input_id = 'text-' . $input_name; //Default value
+	if (isset($parameters['input_id'])) {
+		$input_id = $parameters['input_id'];
+	}
+	
+	//Default value
+	$icon_image = html_print_image('images/lightning.png', true, false, true);
+	if (isset($parameters['icon_image'])) {
+		$icon_image = $parameters['icon_image'];
+	}
+	
+	$value = ''; //Default value
+	if (isset($parameters['value'])) {
+		$value = $parameters['value'];
+	}
+	
+	$show_helptip = true; //Default value
+	if (isset($parameters['show_helptip'])) {
+		$show_helptip = $parameters['show_helptip'];
+	}
+	
+	$helptip_text = __("Type at least two characters to search."); //Default value
+	if (isset($parameters['helptip_text'])) {
+		$helptip_text = $parameters['helptip_text'];
+	}
+	
+	$print_hidden_input_idagent = false; //Default value
+	if (isset($parameters['print_hidden_input_idagent'])) {
+		$print_hidden_input_idagent = $parameters['print_hidden_input_idagent'];
+	}
+	
+	$hidden_input_idagent_name = uniqid('agent_autocomplete_idagent_'); //Default value
+	if (isset($parameters['hidden_input_idagent_name'])) {
+		$hidden_input_idagent_name = $parameters['hidden_input_idagent_name'];
+	}
+	
+	$hidden_input_idagent_id = 'hidden-' . $input_name; //Default value
+	if (isset($parameters['hidden_input_idagent_id'])) {
+		$hidden_input_idagent_name = $parameters['hidden_input_idagent_id'];
+	}
+	
+	$hidden_input_idagent_value = 0; //Default value
+	if (isset($parameters['hidden_input_idagent_value'])) {
+		$hidden_input_idagent_value = $parameters['hidden_input_idagent_value'];
+	}
+	
+	$size = 30; //Default value
+	if (isset($parameters['size'])) {
+		$size = $parameters['size'];
+	}
+	
+	$maxlength = 100; //Default value
+	if (isset($parameters['maxlength'])) {
+		$maxlength = $parameters['maxlength'];
+	}
+	
+	$disabled = false; //Default value
+	if (isset($parameters['disabled'])) {
+		$disabled = $parameters['disabled'];
+	}
+	
+	// Javascript configurations
+	//-----------------------------------------
+	$javascript = true; //Default value
+	if (isset($parameters['javascript'])) {
+		$javascript = $parameters['javascript'];
+	}
+	
+	$selectbox_id = 'id_agent_module'; //Default value
+	if (isset($parameters['selectbox_id'])) {
+		$selectbox_id = $parameters['selectbox_id'];
+	}
+	
+	$javascript_is_function_select = false; //Default value
+	if (isset($parameters['javascript_is_function_select'])) {
+		$javascript_is_function_select = $parameters['javascript_is_function_select'];
+	}
+	
+	$javascript_name_function_select = 'function_select_' . $input_name; //Default value
+	if (isset($parameters['javascript_name_function_select'])) {
+		$javascript_name_function_select = $parameters['javascript_name_function_select'];
+	}
+	
+	$javascript_code_function_select = '';
+	$javascript_code_function_select .= '
+		function function_select_' . $input_name . '(agent_name) {
+			
+			$("#' . $selectbox_id . '").empty ();
+			var inputs = [];
+			inputs.push ("agent_name=" + agent_name);
+			inputs.push ("filter=delete_pending = 0");
+			inputs.push ("get_agent_modules_json=1");
+			inputs.push ("page=operation/agentes/ver_agente");
+			jQuery.ajax ({
+				data: inputs.join ("&"),
+				type: "GET",
+				url: action="ajax.php",
+				timeout: 10000,
+				dataType: "json",
+				success: function (data) {
+					$("#' . $selectbox_id . '")
+						.append($("<option></option>")
+						.attr("value", 0).text("--"));
+					
+					jQuery.each (data, function(i, val) {
+						s = js_html_entity_decode(val["nombre"]);
+						$("#' . $selectbox_id . '")
+							.append ($("<option></option>")
+							.attr("value", val["id_agente_modulo"]).text (s));
+					});
+					
+					$("#' . $selectbox_id . '").enable();
+					$("#' . $selectbox_id . '").fadeIn ("normal");
+				}
+			});
+			
+			return false;
+		}
+		';
+	if (isset($parameters['javascript_code_function_select'])) {
+		$javascript_code_function_select = $parameters['javascript_code_function_select'];
+	}
+	
+	//Default value
+	$javascript_page = 'godmode/agentes/agent_manager';
+	if (isset($parameters['javascript_page'])) {
+		$javascript_page = $parameters['javascript_page'];
+	}
+	
+	$javascript_function_change ='';
+	$javascript_function_change .='
+		function set_functions_change_autocomplete_' . $input_name . '() {
+			$("#' . $input_id . '").autocomplete({
+				minLength: 2,
+				source: function( request, response ) {
+					var term = request.term; //Word to search
+					
+					var data_params = {
+						"page": "' . $javascript_page . '",
+						"search_parents_2": 1,
+						"q": term};
+					
+					jQuery.ajax ({
+						data: data_params,
+						async: false,
+						type: "POST",
+						url: action="ajax.php",
+						timeout: 10000,
+						dataType: "json",
+						success: function (data) {
+								response(data);
+								
+								return;
+							}
+						});
+					
+					return;
+				},
+				select: function( event, ui ) {
+					var agent_name = ui.item.name;
+					
+					//Put the name
+					$(this).val(agent_name);
+					
+					if (' . ((int)$javascript_is_function_select) . ') {
+						' . $javascript_name_function_select . '(agent_name);
+					}
+					
+					return false;
+				}
+				})
+			.data( "autocomplete")._renderItem = function( ul, item ) {
+				if (item.ip == "") {
+					text = "<a>" + item.name + "</a>";
+				}
+				else {
+					text = "<a>" + item.name
+						+ "<br><span style=\"font-size: 70%; font-style: italic;\">IP:" + item.ip + "</span></a>";
+				}
+				
+				return $("<li></li>")
+					.data("item.autocomplete", item)
+					.append(text)
+					.appendTo(ul);
+			};
+		
+		//Force the size of autocomplete
+		$(".ui-autocomplete").css("max-height", "100px");
+		$(".ui-autocomplete").css("overflow-y", "auto");
+		/* prevent horizontal scrollbar */
+		$(".ui-autocomplete").css("overflow-x", "hidden");
+		/* add padding to account for vertical scrollbar */
+		$(".ui-autocomplete").css("padding-right", "20px");
+		
+		//Force to style of items
+		$(".ui-autocomplete").css("text-align", "left");
+	}
+	';
+	if (isset($parameters['javascript_function_change'])) {
+		$javascript_function_change = $parameters['javascript_function_change'];
+	}
+	
+	$javascript_document_ready = true;//Default value
+	if (isset($parameters['javascript_document_ready'])) {
+		$javascript_document_ready = $parameters['javascript_document_ready'];
+	}
+	
+	$javascript_tags = true;//Default value
+	if (isset($parameters['javascript_tags'])) {
+		$javascript_tags = $parameters['javascript_tags'];
+	}
+	
+	$javascript_code = ''; //Default value
+	if (isset($parameters['disabled'])) {
+		$disabled = $parameters['disabled'];
+	}
+	//------------------------------------------------------------------
+	
+	$html = '';
+	
+	$attrs = '';
+	if ($show_helptip) {
+		$attrs = array('style' => 'background: url(' . $icon_image . ') no-repeat right;');
+	}
+	
+	$html = html_print_input_text_extended($input_name, $value,
+		$input_id, $helptip_text, $size, $maxlength, $disabled, '', $attrs, true);
+	if ($show_helptip) {
+		$html .= ui_print_help_tip ($helptip_text, true);
+	}
+	
+	if ($print_hidden_input_idagent) {
+		$html .= html_print_input_hidden_extended($hidden_input_idagent_name,
+			$hidden_input_idagent_value, $hidden_input_idagent_id, true);
+	}
+	
+	//Write the javascript
+	if ($javascript) {
+		if ($javascript_tags) {
+			$html .= '<script type="text/javascript">
+				/* <![CDATA[ */';
+		}
+		
+		$html .= $javascript_function_change;
+		if ($javascript_is_function_select) {
+			$html .= $javascript_code_function_select;
+		}
+		
+		if ($javascript_document_ready) {
+			$html .= '$(document).ready (function () {
+				set_functions_change_autocomplete_' . $input_name . '();
+				});';
+		}
+		
+		if ($javascript_tags) {
+			$html .= '/* ]]> */
+				</script>';
+		}
+	}
+	
+	if ($return) {
+		return $html;
+	}
+	else {
+		echo $html;
+	}
 }
-
-
-?>
+?>
\ No newline at end of file
diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js
index edb85a65c9..64adec1614 100644
--- a/pandora_console/include/javascript/pandora.js
+++ b/pandora_console/include/javascript/pandora.js
@@ -430,6 +430,8 @@ function agent_changed_by_multiple_agents_id (event, id_agent, selected) {
 }
 
 
+
+//------------------DEPRECATED------------------------------------------
 /**
  * Autocomplete Agent box and module selector functions.
  * 
@@ -566,6 +568,9 @@ function agent_module_autocomplete (id_agent_name, id_agent_id, id_agent_module_
 	//Force to style of items
 	$(".ui-autocomplete").css("text-align", "left");
 }
+//------------------DEPRECATED------------------------------------------
+
+
 
 /**
  * Autocomplete Agent box functions.
@@ -792,6 +797,7 @@ function toggleBoth(name) {
  */
 function calculateSeconds(name) {
 	var calculated = $('#text-'+name+'_text').val()*$('#'+name+'_units').val();
+	
 	$('.'+name).val(calculated);
 }
 
diff --git a/pandora_console/operation/agentes/exportdata.php b/pandora_console/operation/agentes/exportdata.php
index e412f2144c..a248cf476f 100644
--- a/pandora_console/operation/agentes/exportdata.php
+++ b/pandora_console/operation/agentes/exportdata.php
@@ -15,116 +15,6 @@
 
 global $config;
 
-if (is_ajax ()) {
-	$search_agents = (bool) get_parameter ('search_agents');
-	$search_agents_2 = (bool) get_parameter ('search_agents_2');
-	
-	if ($search_agents) {
-		
-		require_once ('include/functions_agents.php');
-		
-		$id_agent = (int) get_parameter ('id_agent');
-		$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
-		$id_group = (int) get_parameter('id_group', -1);
-		$addedItems = html_entity_decode((string) get_parameter('add'));
-		$addedItems = json_decode($addedItems);
-		$all = (string)get_parameter('all', 'all');
-		
-		if ($addedItems != null) {
-			foreach ($addedItems as $item) {
-				echo $item . "|\n";
-			}
-		}
-		
-		$filter = array ();
-		switch ($config['dbtype']) {
-			case "mysql":
-				$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
-				break;
-			case "postgresql":	
-				$filter[] = '(nombre LIKE \'%'.$string.'%\' OR direccion LIKE \'%'.$string.'%\' OR comentarios LIKE \'%'.$string.'%\')';
-				break;
-			case "oracle":
-				$filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
-				break;
-		}
-		
-		if ($id_group != -1)
-			$filter['id_grupo'] = $id_group; 
-		
-		switch ($all) {
-			case 'enabled':
-				$filter['disabled'] = 0;
-				break;
-		}
-		
-		$agents = agents_get_agents ($filter, array ('nombre', 'direccion'));
-		if ($agents === false)
-			return;
-			
-		foreach ($agents as $agent) {
-			echo io_safe_output($agent['nombre'])."|".io_safe_output($agent['direccion'])."\n";
-		}
-		
-		return;
- 	}
- 	
- 	if ($search_agents_2) {
- 	
- 		require_once ('include/functions_agents.php');
- 	
- 		$id_agent = (int) get_parameter ('id_agent');
- 		$string = (string) get_parameter ('q'); /* q is what autocomplete plugin gives */
- 		$id_group = (int) get_parameter('id_group', -1);
- 		$addedItems = html_entity_decode((string) get_parameter('add'));
- 		$addedItems = json_decode($addedItems);
- 		$all = (string)get_parameter('all', 'all');
- 	
- 		if ($addedItems != null) {
- 			foreach ($addedItems as $item) {
- 				echo $item . "|\n";
- 			}
- 		}
- 	
- 		$filter = array ();
- 		switch ($config['dbtype']) {
- 			case "mysql":
- 				$filter[] = '(nombre COLLATE utf8_general_ci LIKE "%'.$string.'%" OR direccion LIKE "%'.$string.'%" OR comentarios LIKE "%'.$string.'%")';
- 				break;
- 			case "postgresql":
- 				$filter[] = '(nombre LIKE \'%'.$string.'%\' OR direccion LIKE \'%'.$string.'%\' OR comentarios LIKE \'%'.$string.'%\')';
- 				break;
- 			case "oracle":
- 				$filter[] = '(UPPER(nombre) LIKE UPPER(\'%'.$string.'%\') OR UPPER(direccion) LIKE UPPER(\'%'.$string.'%\') OR UPPER(comentarios) LIKE UPPER(\'%'.$string.'%\'))';
- 				break;
- 		}
- 	
- 		if ($id_group != -1)
- 		$filter['id_grupo'] = $id_group;
- 	
- 		switch ($all) {
- 			case 'enabled':
- 				$filter['disabled'] = 0;
- 				break;
- 		}
- 	
- 		$agents = agents_get_agents ($filter, array ('id_agente', 'nombre', 'direccion'));
- 		if ($agents === false)
- 			$agents = array();
- 		
- 		$data = array();
- 		foreach ($agents as $agent) {
- 			$data[] = array('id' => $agent['id_agente'], 'name' => io_safe_output($agent['nombre']), 'ip' => io_safe_output($agent['direccion']));
- 		}
- 		
- 		echo json_encode($data);
- 	
- 		return;
- 	}
- 	
- 	return;
-}
-
 // Load global vars
 require_once ("include/config.php");
 require_once ("include/functions_agents.php");
@@ -168,12 +58,12 @@ $export_type = get_parameter_post ('export_type', 'data');
 $export_btn = get_parameter ('export_btn', 0);
 
 if (!empty ($export_btn) && !empty ($module)) {
-
+	
 	// Disable SQL cache
 	global $sql_cache;
 	$sql_cache = array ('saved' => 0);
-
-
+	
+	
 	//Convert start time and end time to unix timestamps
 	$start = strtotime ($start_date." ".$start_time);
 	$end = strtotime ($end_date." ".$end_time);
@@ -185,11 +75,11 @@ if (!empty ($export_btn) && !empty ($module)) {
 		ui_print_error_message (__('Invalid time specified'));
 		return;
 	}
-
-	// ***************************************************
+	
+	//******************************************************************
 	// Starts, ends and dividers
-	// ***************************************************
-
+	//******************************************************************
+	
 	switch ($export_type) {
 		case "data":
 		case "avg":
@@ -202,42 +92,42 @@ if (!empty ($export_btn) && !empty ($module)) {
 			$dataend = '</table>';
 			break;
 	}
-
-	// ***************************************************
+	
+	//******************************************************************
 	// Data processing
-	// ***************************************************
-
+	//******************************************************************
+	
 	$data = array ();
 	switch ($export_type) {
 		case "data":
 		case "avg":
 			// Show header
 			echo $datastart;
-
+			
 			foreach ($module as $selected) {
-
+				
 				$output = "";
 				$work_period = 120000;
 				if ($work_period > $period) {
 					$work_period = $period;
 				}
-
+				
 				$work_end = $end - $period + $work_period;
 				//Buffer to get data, anyway this will report a memory exhaustin
-
+				
 				while ($work_end <= $end) {
-
+					
 					$data = array (); // Reinitialize array for each module chunk
 					if ($export_type == "avg") {
 						$arr = array ();
 						$arr["data"] = reporting_get_agentmodule_data_average ($selected, $work_period, $work_end);
 						if ($arr["data"] === false) {
 							continue;
-						}	
+						}
 						$arr["module_name"] = modules_get_agentmodule_name ($selected);
 						$arr["agent_name"] = modules_get_agentmodule_agent_name ($selected);
 						$arr["agent_id"] = modules_get_agentmodule_agent ($selected);
-						$arr["utimestamp"] = $end;				
+						$arr["utimestamp"] = $end;
 						array_push ($data, $arr);
 					}
 					else {
@@ -292,16 +182,16 @@ if (empty($export_btn)) {
 	$table->cellpadding = 5;
 	$table->class = "databox_color";
 	$table->style[0] = 'vertical-align: top;';
-
+	
 	$table->data = array ();
-
+	
 	//Group selector
 	$table->data[0][0] = '<b>'.__('Group').'</b>';
-		
+	
 	$groups = users_get_groups ($config['id_user'], "AR");
-		
+	
 	$table->data[0][1] = html_print_select_groups($config['id_user'], "AR", true, "group", $group, 'submit_group();', '', 0, true, false, true, 'w130', false);
-		
+	
 	//Agent selector
 	$table->data[1][0] = '<b>'.__('Source agent').'</b>';
 	
@@ -423,7 +313,7 @@ $(document).ready (function () {
 				var term = request.term; //Word to search
 				
 				var data_params = {
-					page: "operation/agentes/exportdata",
+					page: "include/ajax/agent",
 					search_agents_2: 1,
 					id_group: function() { return $("#group").val(); },
 					"q": term};
@@ -479,7 +369,6 @@ $(document).ready (function () {
 		//Force to style of items
 		$(".ui-autocomplete").css("text-align", "left");
 	}
-
 });
 
 function change_action() {
diff --git a/pandora_console/operation/incidents/incident_detail.php b/pandora_console/operation/incidents/incident_detail.php
index a88231f82f..3ac81ea7d1 100755
--- a/pandora_console/operation/incidents/incident_detail.php
+++ b/pandora_console/operation/incidents/incident_detail.php
@@ -50,15 +50,15 @@ if (isset ($_GET["id"])) {
 	$id_grupo = $row["id_grupo"];
 	$id_creator = $row["id_creator"]; //creator
 	$id_lastupdate = $row["id_lastupdate"]; //last updater
-	$id_agent = $row["id_agent"]; 		// Agent
+	$id_agent = $row["id_agent"]; // Agent
 	
 	// Note add - everybody that can read incidents, can add notes
 	if (isset ($_GET["insertar_nota"])) {
 		$nota = get_parameter ("nota");
-
+		
 		$sql = sprintf ("INSERT INTO tnota (id_usuario, id_incident, nota) VALUES ('%s', %d, '%s')",$config["id_user"],$id_inc, $nota);
 		$id_nota = db_process_sql ($sql, "insert_id");
-
+		
 		if ($id_nota !== false) {
 			incidents_process_touch ($id_inc);
 		}
@@ -66,7 +66,7 @@ if (isset ($_GET["id"])) {
 			__('Successfully added'),
 			__('Could not be added'));
 	}
-
+	
 	// Delete note
 	if (isset ($_POST["delete_nota"])) {
 		$id_nota = get_parameter ("delete_nota", 0);
@@ -76,7 +76,7 @@ if (isset ($_GET["id"])) {
 		// incidents notes. note authors are 
 		// able to delete their own notes
 			$result = incidents_delete_note ($id_nota);
-
+			
 			if (!empty ($result)) {
 				incidents_process_touch ($id_inc);
 			}
@@ -85,7 +85,7 @@ if (isset ($_GET["id"])) {
 				__('Could not be deleted'));
 		}
 	}
-
+	
 	// Delete file
 	if (((check_acl ($config["id_user"], $id_grupo, "IM")==1) OR
 		($id_owner == $config["id_user"])) AND isset ($_POST["delete_file"])) {
@@ -108,7 +108,7 @@ if (isset ($_GET["id"])) {
 			__('Successfully deleted'),
 			__('Could not be deleted'));
 	}
-
+	
 	// Upload file
 	if ((check_acl ($config["id_user"], $id_grupo, "IW") == 1) AND isset ($_GET["upload_file"]) AND ($_FILES['userfile']['name'] != "")) {
 		$description = get_parameter ("file_description", __('No description available'));
@@ -116,7 +116,7 @@ if (isset ($_GET["id"])) {
 		// Insert into database
 		$filename = io_safe_input ($_FILES['userfile']['name']);
 		$filesize = io_safe_input ($_FILES['userfile']['size']);
-
+		
 		//The following is if you have clamavlib installed
 		//(php5-clamavlib) and enabled in php.ini
 		//http://www.howtoforge.com/scan_viruses_with_php_clamavlib
@@ -131,9 +131,9 @@ if (isset ($_GET["id"])) {
 		
 		$sql = sprintf ("INSERT INTO tattachment (id_incidencia, id_usuario, filename, description, size) 
 			VALUES (%d, '%s', '%s', '%s', %d)", $id_inc, $config["id_user"], $filename, $description, $filesize);
-
+		
 		$id_attachment = db_process_sql ($sql,"insert_id");
-
+		
 		// Copy file to directory and change name
 		if ($id_attachment !== false) {
 			$nombre_archivo = $config["attachment_store"]
@@ -154,7 +154,7 @@ if (isset ($_GET["id"])) {
 			echo '<h3 class="error">'.__('File could not be saved due to database error').'</h3>';
 			$result = false;
 		}
-
+		
 		if ($result !== false) {
 			unlink ($_FILES['userfile']['tmp_name']);
 			incidents_process_touch ($id_inc);
@@ -336,15 +336,35 @@ foreach ($agents_incidents as $agent_incident) {
 	$result_agent_incidents[$agent_incident['id_agente']] = $agent_incident['nombre'];
 }
 
-echo '</td></tr><tr><td class="datos"><b>'.__('Agent').'</b></td><td class="datos">';
+echo '</td>';
+echo '</tr>';
 
-html_print_input_hidden('id_agent', $id_agent);
-html_print_input_text_extended ('agent', agents_get_name ($id_agent), 'text-agent', '', 30, 100, false, '', array('style' => 'background: url(images/lightning.png) no-repeat right;'));
-ui_print_help_tip(__("Type at least two characters to search"), false);
+echo '<tr>';
+echo '<td class="datos"><b>'.__('Agent').'</b></td>';
+echo '<td class="datos">';
+//html_print_input_hidden('id_agent', $id_agent);
+//html_print_input_text_extended ('agent', agents_get_name ($id_agent), 'text-agent', '', 30, 100, false, '', array('style' => 'background: url(images/lightning.png) no-repeat right;'));
+//ui_print_help_tip(__("Type at least two characters to search"), false);
+echo '</td>';
+echo '</tr>';
 
-//html_print_select ($result_agent_incidents, "incident_agents", $id_agent, '', __('None'), 0, false, false, false, 'w135', false);
+//////////
+echo '<tr>';
+echo '<td class="datos"><b>'.__('Teste').'</b></td>';
+echo '<td class="datos">';
+$params = array();
+$params['show_helptip'] = true;
+$params['input_name'] = 'agent';
+$params['value'] = agents_get_name ($id_agent);
+$params['print_hidden_input_idagent'] = true;
+$params['hidden_input_idagent_value'] = $id_agent;
+$params['hidden_input_idagent_name'] = 'id_agent';
+ui_print_agent_autocomplete_input($params);
+echo '</td>';
+echo '</tr>';
+//////////
 
-echo '</td></tr><tr><td class="datos2" colspan="4">';
+echo '<tr><td class="datos2" colspan="4">';
 
 if ((check_acl ($config["id_user"], $id_grupo, "IM") == 1) OR ($usuario == $config["id_user"])) {
 	html_print_textarea ("descripcion", 15, 80, $texto, 'style="height:200px;"');
@@ -493,6 +513,6 @@ if (isset ($id_inc)) {
 ?>
 <script>
 $(document).ready (function () {
-	agent_autocomplete('#text-agent', '#hidden-server_name', '#hidden-id_agent');
+	//agent_autocomplete('#text-agent', '#hidden-server_name', '#hidden-id_agent');
 });
 </script>
\ No newline at end of file