From 4ac482f3c4a4853e244efac60db2a332312076c8 Mon Sep 17 00:00:00 2001
From: juanmanuelr <noreply@pandorafms.org>
Date: Tue, 12 Jun 2012 15:45:37 +0000
Subject: [PATCH] 2012-06-12 Juan Manuel Ramon <juanmanuel.ramon@artica.es>

	* include/functions_modules.php
	 include/functions_agents.php: Fixed problem when modules are
	 repeated in source and target agents.

	* operation/events/events_list.php: Delete double confirmation when
	an event is deleted.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6518 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
---
 pandora_console/ChangeLog                     |  9 +++++
 pandora_console/include/functions_agents.php  | 35 ++++++++++++++++---
 pandora_console/include/functions_modules.php |  3 +-
 .../operation/events/events_list.php          |  2 +-
 4 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog
index fd6df8dd97..8a149bf066 100644
--- a/pandora_console/ChangeLog
+++ b/pandora_console/ChangeLog
@@ -1,3 +1,12 @@
+2012-06-12 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
+
+	* include/functions_modules.php
+	 include/functions_agents.php: Fixed problem when modules are 
+	 repeated in source and target agents. 
+	 
+	* operation/events/events_list.php: Delete double confirmation when
+	an event is deleted.
+
 2012-06-12 Miguel de Dios <miguel.dedios@artica.es>
 	
 	* images/console/icons/light_ok.png, images/console/icons/light.png:
diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php
index 620b20286c..de40351a23 100644
--- a/pandora_console/include/functions_agents.php
+++ b/pandora_console/include/functions_agents.php
@@ -618,13 +618,38 @@ function agents_process_manage_config ($source_id_agent, $destiny_id_agents, $co
 			break;
 	}
 	$error = false;
-	
+
+	$repeated_modules = array();
 	foreach ($destiny_id_agents as $id_destiny_agent) {
 		foreach ($target_modules as $id_agent_module) {
-			$result = modules_copy_agent_module_to_agent ($id_agent_module,
-				$id_destiny_agent);
-		
-			if ($result === false) {
+			
+			// Check the module name exists in target
+			$module = modules_get_agentmodule ($id_agent_module);
+			if ($module === false)
+				return false;
+				
+			$modules = agents_get_modules ($id_destiny_agent, false,
+				array ('nombre' => $module['nombre'], 'disabled' => false));
+
+			// Keep all modules repeated
+			if (! empty ($modules)) {
+				$modules_repeated = array_pop (array_keys ($modules));
+				$result = $modules_repeated;
+				$repeated_modules[] = $modules_repeated;		
+			}
+			else {
+			
+				$result = modules_copy_agent_module_to_agent ($id_agent_module,
+					$id_destiny_agent);
+
+				if ($result === false) {
+					$error = true;
+					break;
+				}
+			}
+			
+			// Check if all modules are repeated and no alerts are copied, if YES then error
+			if (empty($target_alerts) and count($repeated_modules) == count($target_modules)) {
 				$error = true;
 				break;
 			}
diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php
index ef86b38435..f294c51371 100644
--- a/pandora_console/include/functions_modules.php
+++ b/pandora_console/include/functions_modules.php
@@ -47,7 +47,8 @@ function modules_copy_agent_module_to_agent ($id_agent_module, $id_destiny_agent
 		
 	$modules = agents_get_modules ($id_destiny_agent, false,
 		array ('nombre' => $module['nombre'], 'disabled' => false));
-	
+
+	// These are the modules that exists in the target 
 	if (! empty ($modules))
 		return array_pop (array_keys ($modules));
 	
diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php
index 7699a74640..3dc0f0108d 100644
--- a/pandora_console/operation/events/events_list.php
+++ b/pandora_console/operation/events/events_list.php
@@ -829,7 +829,7 @@ foreach ($result as $event) {
 		// Delete event
 		if (check_acl ($config["id_user"], $event["id_grupo"], "IM") == 1) {
 			if($event['estado'] != 2) {
-				$data[$i] .= '<a class="delete_event" href="#"  onClick="if (!confirm(\' '.__('Are you sure?').'\')) return false;" id="delete-'.$event['id_evento'].'">';
+				$data[$i] .= '<a class="delete_event" href="#" id="delete-'.$event['id_evento'].'">';
 				$data[$i] .= html_print_image ("images/cross.png", true,
 					array ("title" => __('Delete event'), "id" => 'delete_cross_' . $event['id_evento']));
 				$data[$i] .= '</a>&nbsp;';