From d2bc06276619cfed3eb404e416841650604a38e0 Mon Sep 17 00:00:00 2001
From: daniel <daniel.barbero@artica.es>
Date: Fri, 5 Jan 2018 10:29:46 +0100
Subject: [PATCH] fixed errors extensions agent-modules and recursion groups

---
 pandora_console/extensions/agents_modules.php | 441 +++++++++---------
 pandora_console/godmode/groups/group_list.php |   2 +-
 .../massive/massive_delete_modules.php        |  50 +-
 .../godmode/massive/massive_edit_modules.php  |  70 ++-
 .../operation/agentes/ver_agente.php          |   3 +-
 5 files changed, 275 insertions(+), 291 deletions(-)

diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php
index 6e6cf9a92e..4da2ad8238 100644
--- a/pandora_console/extensions/agents_modules.php
+++ b/pandora_console/extensions/agents_modules.php
@@ -14,17 +14,16 @@
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 // GNU General Public License for more details.
 
-include_once($config['homedir'] . "/include/functions_agents.php");
-include_once($config['homedir'] . "/include/functions_modules.php");
-include_once($config['homedir'] . '/include/functions_users.php');
 $refr = get_parameter('refresh', 0); // By default 30 seconds
-
 function mainAgentsModules() {
 	global $config;
 	
 	// Load global vars
 	require_once ("include/config.php");
 	require_once ("include/functions_reporting.php");
+	include_once($config['homedir'] . "/include/functions_agents.php");
+	include_once($config['homedir'] . "/include/functions_modules.php");
+	include_once($config['homedir'] . '/include/functions_users.php');
 	
 	check_login ();
 	// ACL Check
@@ -52,7 +51,6 @@ function mainAgentsModules() {
 		}
 	}
 	
-	
 	if ($config["realtimestats"] == 0) {
 		$updated_info = __('Last update'). " : ". ui_print_timestamp (db_get_sql ("SELECT min(utimestamp) FROM tgroup_stat"), true);
 	}
@@ -103,7 +101,6 @@ function mainAgentsModules() {
 		serialize_in_temp($agents_id, $config['id_user']."_agents", 1);
 	}
 	
-
 	if ($config["pure"] == 0) {
 		if($modules_selected[0] && $agents_id[0]){
 			
@@ -128,7 +125,6 @@ function mainAgentsModules() {
 				. "</a>";
 				
 		} else {
-			
 			$fullscreen['text'] = '<a href="index.php?extension_in_menu=estado&amp;sec=extensions&amp;sec2=extensions/agents_modules&amp;pure=1&amp;
 			offset='.$offset.'&group_id='.$group_id.'&modulegroup='.$modulegroup.'&refresh='.$refr.'">'
 				. html_print_image ("images/full_screen.png", true, array ("title" => __('Full screen mode')))
@@ -247,7 +243,6 @@ function mainAgentsModules() {
 		ui_require_css_file('countdown');
 	}
 	
-	
 	if($config['pure'] != 1){
 		echo '<form method="post" action="' 
 		. ui_get_url_refresh (array ('offset' => $offset, 'hor_offset' => $offset, 'group_id' => $group_id, 'modulegroup' => $modulegroup)).'">';
@@ -321,8 +316,7 @@ function mainAgentsModules() {
 				foreach ($result_sql as $key => $value) {
 					$all_modules[$value['id_agente_modulo']] = io_safe_output($name); 
 				}
-			} 
-			 
+			}
 		}
 	}
 	else{
@@ -353,7 +347,6 @@ function mainAgentsModules() {
 	$name = '';
 	$cont = 0;
 	
-	
 	foreach ($all_modules as $key => $module) {
 		if ($module == $name) {
 			$modules_by_name[$cont-1]['id'][] = $key;
@@ -454,7 +447,7 @@ function mainAgentsModules() {
 				"selection_a_m=" . $selection_a_m . "&" .
 				"hor_offset=" . $new_hor_offset . "&".
 				"offset=" . $offset .
-				 "'>" .
+				"'>" .
 				html_print_image(
 					"images/arrow.png", true,
 					array('title' => __('More modules'))) .
@@ -585,7 +578,13 @@ function mainAgentsModules() {
 	echo "<tr><td class='legend_square_simple'><div style='background-color: " . COL_NOTINIT . ";'></div></td><td>" . __("Cell turns blue when the module is in 'not initialize' status") . "</td></tr>";
 	echo "</table>";
 	echo "</div>";
-	
+	$pure_var = $config['pure'];
+	if($pure_var){
+		$pure_var = 1;
+	}
+	else{
+		$pure_var = 0;
+	}
 	echo "
 		<style type='text/css'>
 			.rotate_text_module {
@@ -597,6 +596,7 @@ function mainAgentsModules() {
 				white-space: nowrap;
 			}
 		</style>
+
 		<script type='text/javascript'>
 			$(document).ready(function () {
 				//Get max width of name of modules
@@ -619,9 +619,211 @@ function mainAgentsModules() {
 					$(\"#div_module_r_\" + id).css('margin-top', (max_width - 20) + 'px');
 					$(\"#div_module_r_\" + id).show();
 				});
+
+				var refr =" . $refr . ";
+				var pure =" . $pure_var . ";
+				var href ='" . ui_get_url_refresh ($ignored_params) . "';
+					
+				if (pure) {
+					var startCountDown = function (duration, cb) {
+						$('div.vc-countdown').countdown('destroy');
+						if (!duration) return;
+						var t = new Date();
+						t.setTime(t.getTime() + duration * 1000);
+						$('div.vc-countdown').countdown({
+							until: t,
+							format: 'MS',
+							layout: '(%M%nn%M:%S%nn%S" .  __('Until refresh') . ") ',
+							alwaysExpire: true,
+							onExpiry: function () {
+								$('div.vc-countdown').countdown('destroy');
+								url = js_html_entity_decode( href ) + duration;
+								$(document).attr (\"location\", url);
+							}
+						});
+					}
+					
+					startCountDown(refr, false);
+					var controls = document.getElementById('vc-controls');
+					autoHideElement(controls, 1000);
+					
+					$('select#refresh').change(function (event) {
+						refr = Number.parseInt(event.target.value, 10);
+						startCountDown(refr, false);
+					});
+				}
+				else {
+					
+					var agentes_id = $(\"#id_agents2\").val();
+					var id_agentes = $.get(\"full_agents_id\");
+					if (agentes_id === null && id_agentes !== null) {
+						id_agentes = id_agentes.split(\";\")
+						id_agentes.forEach(function(element) {
+							$(\"#id_agents2 option[value=\"+ element +\"]\").attr(\"selected\",true);
+						});
+						
+						selection_agent_module();
+					}
+					
+					$('#refresh').change(function () {
+						$('#hidden-vc_refr').val($('#refresh option:selected').val());
+					});
+				}
+				
+				$(\"#group_id\").change (function () {
+					
+					jQuery.post (\"ajax.php\",
+						{\"page\" : \"operation/agentes/ver_agente\",
+							\"get_agents_group_json\" : 1,
+							\"id_group\" : this.value,
+							\"privilege\" : \"AW\",
+							\"keys_prefix\" : \"_\",
+							\"recursion\" : $('#checkbox-recursion').is(':checked')
+						},
+						function (data, status) {
+							$(\"#id_agents2\").html('');
+							$(\"#module\").html('');
+							jQuery.each (data, function (id, value) {
+								// Remove keys_prefix from the index
+								id = id.substring(1);
+								
+								option = $(\"<option></option>\")
+									.attr (\"value\", value[\"id_agente\"])
+									.html (value[\"alias\"]);
+								$(\"#id_agents\").append (option);
+								$(\"#id_agents2\").append (option);
+							});
+						},
+						\"json\"
+					);
+				});
+				
+				$(\"#checkbox-recursion\").change (function () {
+					jQuery.post (\"ajax.php\",
+						{\"page\" : \"operation/agentes/ver_agente\",
+							\"get_agents_group_json\" : 1,
+							\"id_group\" : 	$(\"#group_id\").val(),
+							\"privilege\" : \"AW\",
+							\"keys_prefix\" : \"_\",
+							\"recursion\" : $('#checkbox-recursion').is(':checked')
+						},
+						function (data, status) {
+							$(\"#id_agents2\").html('');
+							$(\"#module\").html('');
+							jQuery.each (data, function (id, value) {
+								// Remove keys_prefix from the index
+								id = id.substring(1);
+								
+								option = $(\"<option></option>\")
+									.attr (\"value\", value[\"id_agente\"])
+									.html (value[\"alias\"]);
+								$(\"#id_agents\").append (option);
+								$(\"#id_agents2\").append (option);
+							});
+						},
+						\"json\"
+					);
+				});
+				
+				$(\"#modulegroup\").change (function () {
+					jQuery.post (\"ajax.php\",
+						{\"page\" : \"operation/agentes/ver_agente\",
+							\"get_modules_group_json\" : 1,
+							\"id_module_group\" : this.value,
+							\"id_agents\" : $(\"#id_agents2\").val(),
+							\"selection\" : $(\"#selection_agent_module\").val()
+						},
+						function (data, status) {
+							$(\"#module\").html('');
+							if(data){
+								jQuery.each (data, function (id, value) {
+									option = $(\"<option></option>\")
+										.attr (\"value\", value[\"id_agente_modulo\"])
+										.html (value[\"nombre\"]);
+									$(\"#module\").append (option);
+								});
+							}
+						},
+						\"json\"
+					);
+				});
+
+				$(\"#id_agents2\").click (function(){
+					selection_agent_module();
+				});
+
+				$(\"#selection_agent_module\").change(function() {
+					jQuery.post (\"ajax.php\",
+						{\"page\" : \"operation/agentes/ver_agente\",
+							\"get_modules_group_json\" : 1,
+							\"id_module_group\" : $(\"#modulegroup\").val(),
+							\"id_agents\" : $(\"#id_agents2\").val(),
+							\"selection\" : $(\"#selection_agent_module\").val()
+						},
+						function (data, status) {
+							$(\"#module\").html('');
+							if(data){
+								jQuery.each (data, function (id, value) {
+									option = $(\"<option></option>\")
+										.attr (\"value\", value[\"id_agente_modulo\"])
+										.html (value[\"nombre\"]);
+									$(\"#module\").append (option);
+								});
+							}
+						},
+						\"json\"
+					);
+				});
 			});
+
+			function selection_agent_module() {
+				jQuery.post (\"ajax.php\",
+					{\"page\" : \"operation/agentes/ver_agente\",
+						\"get_modules_group_json\" : 1,
+						\"id_module_group\" : $(\"#modulegroup\").val(),
+						\"id_agents\" : $(\"#id_agents2\").val(),
+						\"selection\" : $(\"#selection_agent_module\").val()
+					},
+					function (data, status) {
+						$(\"#module\").html('');
+						if(data){
+							jQuery.each (data, function (id, value) {
+								option = $(\"<option></option>\")
+									.attr (\"value\", value[\"id_agente_modulo\"])
+									.html (value[\"nombre\"]);
+								$(\"#module\").append (option);
+							});
+							
+							var id_modules = $.get(\"full_modules_selected\");
+							if(id_modules !== null) {
+								id_modules = id_modules.split(\";\");
+								id_modules.forEach(function(element) {
+									$(\"#module option[value=\"+ element +\"]\").attr(\"selected\",true);
+								});
+							}
+						}
+					},
+					\"json\"
+				);
+			}
+
+			(function($) {  
+				$.get = function(key)   {  
+					key = key.replace(/[\[]/, '\\[');  
+					key = key.replace(/[\]]/, '\\]');  
+					var pattern = \"[\\?&]\" + key + \"=([^&#]*)\";  
+					var regex = new RegExp(pattern);  
+					var url = unescape(window.location.href);  
+					var results = regex.exec(url);  
+					if (results === null) {  
+						return null;  
+					} else {  
+						return results[1];  
+					}  
+				}  
+			})(jQuery);
 		</script>
-		";
+	";
 }
 
 extensions_add_operation_menu_option(__("Agents/Modules view"), 'estado', 'agents_modules/icon_menu.png', "v1r1","view");
@@ -629,213 +831,4 @@ extensions_add_main_function('mainAgentsModules');
 
 $ignored_params['refresh']='';
 
-?>
-<script type="text/javascript">
-	$(document).ready (function () {
-		var refr = <?php echo (int)$refr; ?>;
-		var pure = <?php echo (int) $config['pure']; ?>;
-		var href = "<?php echo ui_get_url_refresh ($ignored_params); ?>";
-		
-		
-		if (pure) {
-			var startCountDown = function (duration, cb) {
-				$('div.vc-countdown').countdown('destroy');
-				if (!duration) return;
-				var t = new Date();
-				t.setTime(t.getTime() + duration * 1000);
-				$('div.vc-countdown').countdown({
-					until: t,
-					format: 'MS',
-					layout: '(%M%nn%M:%S%nn%S <?php echo __('Until refresh'); ?>) ',
-					alwaysExpire: true,
-					onExpiry: function () {
-						$('div.vc-countdown').countdown('destroy');
-						url = js_html_entity_decode( href ) + duration;
-						$(document).attr ("location", url);
-					}
-				});
-			}
-			
-			startCountDown(refr, false);
-			//~ // Auto hide controls
-			var controls = document.getElementById('vc-controls');
-			autoHideElement(controls, 1000);
-			
-			$('select#refresh').change(function (event) {
-				refr = Number.parseInt(event.target.value, 10);
-				startCountDown(refr, false);
-			});
-		}
-		else {
-			
-			var agentes_id = $("#id_agents2").val();
-			var id_agentes = $.get("full_agents_id");
-			if (agentes_id === null && id_agentes !== null) {
-				id_agentes = id_agentes.split(";")
-				id_agentes.forEach(function(element) {
-					$("#id_agents2 option[value="+ element +"]").attr("selected",true);
-				});
-				
-				selection_agent_module();
-			}
-			
-			$('#refresh').change(function () {
-				$('#hidden-vc_refr').val($('#refresh option:selected').val());
-			});
-		}
-		
-		$("#group_id").change (function () {
-			
-			jQuery.post ("ajax.php",
-				{"page" : "operation/agentes/ver_agente",
-					"get_agents_group_json" : 1,
-					"id_group" : this.value,
-					"privilege" : "AW",
-					"keys_prefix" : "_",
-					"recursion" : $('#checkbox-recursion').is(':checked')
-				},
-				function (data, status) {
-					$("#id_agents2").html('');
-					$("#module").html('');
-					jQuery.each (data, function (id, value) {
-						// Remove keys_prefix from the index
-						id = id.substring(1);
-						
-						option = $("<option></option>")
-							.attr ("value", value["id_agente"])
-							.html (value["alias"]);
-						$("#id_agents").append (option);
-						$("#id_agents2").append (option);
-					});
-				},
-				"json"
-			);
-		});
-		
-		$("#checkbox-recursion").change (function () {
-			jQuery.post ("ajax.php",
-				{"page" : "operation/agentes/ver_agente",
-					"get_agents_group_json" : 1,
-					"id_group" : 	$("#group_id").val(),
-					"privilege" : "AW",
-					"keys_prefix" : "_",
-					"recursion" : $('#checkbox-recursion').is(':checked')
-				},
-				function (data, status) {
-					$("#id_agents2").html('');
-					$("#module").html('');
-					jQuery.each (data, function (id, value) {
-						// Remove keys_prefix from the index
-						id = id.substring(1);
-						
-						option = $("<option></option>")
-							.attr ("value", value["id_agente"])
-							.html (value["alias"]);
-						$("#id_agents").append (option);
-						$("#id_agents2").append (option);
-					});
-				},
-				"json"
-			);
-		});
-		
-		$("#modulegroup").change (function () {
-			jQuery.post ("ajax.php",
-				{"page" : "operation/agentes/ver_agente",
-					"get_modules_group_json" : 1,
-					"id_module_group" : this.value,
-					"id_agents" : $("#id_agents2").val(),
-					"selection" : $("#selection_agent_module").val()
-				},
-				function (data, status) {
-					$("#module").html('');
-					if(data){
-						jQuery.each (data, function (id, value) {
-							option = $("<option></option>")
-								.attr ("value", value["id_agente_modulo"])
-								.html (value["nombre"]);
-							$("#module").append (option);
-						});
-					}
-				},
-				"json"
-			);
-		});
-
-		$("#id_agents2").click (function(){
-			selection_agent_module();
-		});
-
-		$("#selection_agent_module").change(function() {
-			jQuery.post ("ajax.php",
-				{"page" : "operation/agentes/ver_agente",
-					"get_modules_group_json" : 1,
-					"id_module_group" : $("#modulegroup").val(),
-					"id_agents" : $("#id_agents2").val(),
-					"selection" : $("#selection_agent_module").val()
-				},
-				function (data, status) {
-					$("#module").html('');
-					if(data){
-						jQuery.each (data, function (id, value) {
-							option = $("<option></option>")
-								.attr ("value", value["id_agente_modulo"])
-								.html (value["nombre"]);
-							$("#module").append (option);
-						});
-					}
-				},
-				"json"
-			);
-		});
-
-	});
-
-	function selection_agent_module() {
-		jQuery.post ("ajax.php",
-			{"page" : "operation/agentes/ver_agente",
-				"get_modules_group_json" : 1,
-				"id_module_group" : $("#modulegroup").val(),
-				"id_agents" : $("#id_agents2").val(),
-				"selection" : $("#selection_agent_module").val()
-			},
-			function (data, status) {
-				$("#module").html('');
-				if(data){
-					jQuery.each (data, function (id, value) {
-						option = $("<option></option>")
-							.attr ("value", value["id_agente_modulo"])
-							.html (value["nombre"]);
-						$("#module").append (option);
-					});
-					
-					var id_modules = $.get("full_modules_selected");
-					if(id_modules !== null) {
-						id_modules = id_modules.split(";");
-						id_modules.forEach(function(element) {
-			    			$("#module option[value="+ element +"]").attr("selected",true);
-						});
-					}
-				}
-			},
-			"json"
-		);
-	}
-	
-	(function($) {  
-    $.get = function(key)   {  
-        key = key.replace(/[\[]/, '\\[');  
-        key = key.replace(/[\]]/, '\\]');  
-        var pattern = "[\\?&]" + key + "=([^&#]*)";  
-        var regex = new RegExp(pattern);  
-        var url = unescape(window.location.href);  
-        var results = regex.exec(url);  
-        if (results === null) {  
-            return null;  
-        } else {  
-            return results[1];  
-        }  
-    }  
-	})(jQuery); 
-
-</script>
\ No newline at end of file
+?>
\ No newline at end of file
diff --git a/pandora_console/godmode/groups/group_list.php b/pandora_console/godmode/groups/group_list.php
index e62a8f4a86..d02571078e 100644
--- a/pandora_console/godmode/groups/group_list.php
+++ b/pandora_console/godmode/groups/group_list.php
@@ -130,7 +130,7 @@ if (is_ajax ()) {
 		}
 		else {
 			$agents = agents_get_group_agents($id_group, $filter, "none",
-				false, $recursion, false, '|', $add_alert_bulk_op);
+				true, $recursion, false, '|', $add_alert_bulk_op);
 		}
 		
 		$agents_disabled = array();
diff --git a/pandora_console/godmode/massive/massive_delete_modules.php b/pandora_console/godmode/massive/massive_delete_modules.php
index b1cd1b220c..580c86c26c 100755
--- a/pandora_console/godmode/massive/massive_delete_modules.php
+++ b/pandora_console/godmode/massive/massive_delete_modules.php
@@ -698,8 +698,6 @@ $(document).ready (function () {
 
 	$("#checkbox-recursion").click(function () {
 		recursion = this.checked ? 1 : 0;
-
-		$("#groups_select").trigger("change");
 	});
 
 	$("#groups_select").change (
@@ -790,33 +788,33 @@ $(document).ready (function () {
 	});
 	
 	$('#agents').change(function(e){
-				for(var i=0;i<document.forms["form_modules"].agents.length;i++)	{
-					
-					if(document.forms["form_modules"].agents[0].selected == true){
-						var any = true;
-					}
-					if(i != 0 && document.forms["form_modules"].agents[i].selected){
-							var others = true;
-					}
-					if(any && others){
-							document.forms["form_modules"].agents[0].selected = false;
-					}	
-				}
+		for(var i=0;i<document.forms["form_modules"].agents.length;i++)	{
+			
+			if(document.forms["form_modules"].agents[0].selected == true){
+				var any = true;
+			}
+			if(i != 0 && document.forms["form_modules"].agents[i].selected){
+					var others = true;
+			}
+			if(any && others){
+					document.forms["form_modules"].agents[0].selected = false;
+			}	
+		}
 	});
 	
 	$('#module').change(function(e){
-				for(var i=0;i<document.forms["form_modules"].module.length;i++)	{
-					
-					if(document.forms["form_modules"].module[0].selected == true){
-						var any = true;
-					}
-					if(i != 0 && document.forms["form_modules"].module[i].selected){
-							var others = true;
-					}
-					if(any && others){
-							document.forms["form_modules"].module[0].selected = false;
-					}	
-				}
+		for(var i=0;i<document.forms["form_modules"].module.length;i++)	{
+			
+			if(document.forms["form_modules"].module[0].selected == true){
+				var any = true;
+			}
+			if(i != 0 && document.forms["form_modules"].module[i].selected){
+					var others = true;
+			}
+			if(any && others){
+					document.forms["form_modules"].module[0].selected = false;
+			}	
+		}
 	});
 		
 });
diff --git a/pandora_console/godmode/massive/massive_edit_modules.php b/pandora_console/godmode/massive/massive_edit_modules.php
index 78037d1ad5..db07eee465 100755
--- a/pandora_console/godmode/massive/massive_edit_modules.php
+++ b/pandora_console/godmode/massive/massive_edit_modules.php
@@ -296,8 +296,7 @@ $table->data['form_agents_1'][1] = html_print_select_groups (false, 'AW', true,
 	html_print_checkbox ("recursion", 1, false, true, false);
 $table->data['form_agents_1'][3] = __('Select all modules of this group') . ' ' .
 	html_print_checkbox_extended ("force_group", 'group', '', '', false,
-		'', 'style="margin-right: 40px;"', true);
-
+		'', 'style="margin-right: 40px;"');
 
 $table->rowclass['form_modules_3'] = '';
 $table->data['form_modules_3'][0] = __('Module Status');
@@ -695,7 +694,6 @@ $(document).ready (function () {
 	
 	clean_lists();
 	
-	
 	$(".select_modules_row").css('display', '<?php echo $modules_row?>');
 	$(".select_agents_row").css('display', '<?php echo $agents_row?>');
 	$(".select_modules_row_2").css('display', 'none');
@@ -948,7 +946,7 @@ $(document).ready (function () {
 				}
 			}
 			else if (this.id == "checkbox-recursion") {
-				$("#checkbox-force_group").attr("checked", false);
+				$("#checkbox-force_group").prop("checked", false);
 				$("#groups_select").trigger("change");
 			}
 			else if (this.id == "checkbox-warning_inverse") {
@@ -962,7 +960,7 @@ $(document).ready (function () {
 			}
 			else {
 				if (this.id == "checkbox-force_group") {
-					$("#checkbox-recursion").attr("checked", false);
+					$("#checkbox-recursion").prop("checked", false);
 				}
 				
 				if (this.checked) {
@@ -1058,8 +1056,6 @@ $(document).ready (function () {
 
 	$("#checkbox-recursion").click(function () {
 		recursion = this.checked ? 1 : 0;
-
-		$("#groups_select").trigger("change");
 	});
 
 	$("#groups_select").change (
@@ -1102,11 +1098,11 @@ $(document).ready (function () {
 					"get_agents_group_json" : 1,
 					"recursion" : recursion,
 					"id_group" : this.value,
-				status_agents: function () {
-					return $("#status_agents").val();
-				},
-				// Add a key prefix to avoid auto sorting in js object conversion
-				"keys_prefix" : "_"
+					status_agents: function () {
+						return $("#status_agents").val();
+					},
+					// Add a key prefix to avoid auto sorting in js object conversion
+					"keys_prefix" : "_"
 				},
 				function (data, status) {
 					$("#id_agents").html('');
@@ -1130,7 +1126,6 @@ $(document).ready (function () {
 		$("#groups_select").trigger("change");
 	});
 	
-
 	if("<?php echo $update ?>"){
 		if("<?php echo $selection_mode ?>" == 'agents'){
 			$("#groups_select").trigger("change");
@@ -1138,7 +1133,6 @@ $(document).ready (function () {
 	}
 
 	$("#status_module").change(function() {
-		
 		selector = $("#form_edit input[name=selection_mode]:checked").val();
 		if(selector == 'agents') {
 			$("#id_agents").trigger("change");
@@ -1158,33 +1152,33 @@ $(document).ready (function () {
 	});
 	
 	$('#agents').change(function(e){
-				for(var i=0;i<document.forms["form_edit"].agents.length;i++)	{
-					
-					if(document.forms["form_edit"].agents[0].selected == true){
-						var any = true;
-					}
-					if(i != 0 && document.forms["form_edit"].agents[i].selected){
-							var others = true;
-					}
-					if(any && others){
-							document.forms["form_edit"].agents[0].selected = false;
-					}	
-				}
+		for(var i=0;i<document.forms["form_edit"].agents.length;i++)	{
+			
+			if(document.forms["form_edit"].agents[0].selected == true){
+				var any = true;
+			}
+			if(i != 0 && document.forms["form_edit"].agents[i].selected){
+					var others = true;
+			}
+			if(any && others){
+					document.forms["form_edit"].agents[0].selected = false;
+			}	
+		}
 	});
 	
 	$('#module').change(function(e){
-				for(var i=0;i<document.forms["form_edit"].module.length;i++)	{
-					
-					if(document.forms["form_edit"].module[0].selected == true){
-						var any = true;
-					}
-					if(i != 0 && document.forms["form_edit"].module[i].selected){
-							var others = true;
-					}
-					if(any && others){
-							document.forms["form_edit"].module[0].selected = false;
-					}	
-				}
+		for(var i=0;i<document.forms["form_edit"].module.length;i++)	{
+			
+			if(document.forms["form_edit"].module[0].selected == true){
+				var any = true;
+			}
+			if(i != 0 && document.forms["form_edit"].module[i].selected){
+					var others = true;
+			}
+			if(any && others){
+					document.forms["form_edit"].module[0].selected = false;
+			}	
+		}
 	});
 	
 });
diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php
index b2479fec88..c6181a6a3f 100644
--- a/pandora_console/operation/agentes/ver_agente.php
+++ b/pandora_console/operation/agentes/ver_agente.php
@@ -51,14 +51,13 @@ if (is_ajax ()) {
 		$id_os = get_parameter('id_os', '');
 		$agent_name = get_parameter('name', '');
 		$privilege = (string) get_parameter ('privilege', "AR");
-		
 		// Is is possible add keys prefix to avoid auto sorting in js object conversion
 		$keys_prefix = (string) get_parameter ('keys_prefix', '');
 		$status_agents = (int)get_parameter('status_agents', AGENT_STATUS_ALL);
 		
 		if ($id_group > 0) {
 			$groups = array($id_group);
-			if ($recursion === 'true') {
+			if ($recursion === 'true' || $recursion == 1 ) {
 				$groups = array_merge($groups,
 					groups_get_id_recursive($id_group, true));
 			}