From 71f38f7e02a50724c064219c22ba0cf5388de2f0 Mon Sep 17 00:00:00 2001
From: mdtrooper <tres.14159@gmail.com>
Date: Mon, 1 Feb 2016 15:12:21 +0100
Subject: [PATCH] Working in the migration.

---
 pandora_console/include/constants.php         | 15 +++++
 .../include/functions_migration.php           | 63 +++++++++++++++++++
 .../operation/maps/networkmap_list.php        |  2 +
 3 files changed, 80 insertions(+)

diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php
index d32d6e1b2e..585a3c0d09 100644
--- a/pandora_console/include/constants.php
+++ b/pandora_console/include/constants.php
@@ -460,4 +460,19 @@ define("OPTION_TREE_GROUP_SELECT",		6);
 define("OPTION_SINGLE_SELECT_TIME",		7);
 define("OPTION_CUSTOM_INPUT",			8);
 define("OPTION_AGENT_AUTOCOMPLETE",		9);
+
+/* Maps (new networkmaps and  new visualmaps) */
+define("MAP_TYPE_NETWORKMAP",	0);
+define("MAP_TYPE_VISUALMAP",	1);
+
+define("MAP_SUBTYPE_TOPOLOGY",			0);
+define("MAP_SUBTYPE_POLICIES",			1);
+define("MAP_SUBTYPE_GROUPS",			2);
+define("MAP_SUBTYPE_RADIAL_DYNAMIC",	3);
+
+define("MAP_GENERATION_CIRCULAR",	0);
+define("MAP_GENERATION_PLANO",		1);
+define("MAP_GENERATION_RADIAL",		2);
+define("MAP_GENERATION_SPRING1",	3);
+define("MAP_GENERATION_SPRING2",	4);
 ?>
diff --git a/pandora_console/include/functions_migration.php b/pandora_console/include/functions_migration.php
index f3f46ae911..702205a4fb 100644
--- a/pandora_console/include/functions_migration.php
+++ b/pandora_console/include/functions_migration.php
@@ -21,7 +21,70 @@
  * @subpackage Migration
  */
 
+require_once("include/functions_maps.php");
+
 function migration_open_networkmaps() {
+	$old_networkmaps_open = db_get_all_rows_in_table("tnetwork_map");
 	
+	//~ html_debug($old_networkmaps_open);
+	
+	foreach ($old_networkmaps_open as $old_netw_open) {
+		$new_networkmap = array();
+		
+		$new_networkmap['name'] = $old_netw_open['name'];
+		$new_networkmap['id_user'] = $old_netw_open['id_user'];
+		
+		switch ($old_netw_open['id_user']) {
+			case 'topology':
+				$new_networkmap['type'] = MAP_TYPE_NETWORKMAP;
+				$new_networkmap['subtype'] = MAP_SUBTYPE_TOPOLOGY;
+				break;
+		}
+		
+		switch ($old_netw_open['layout']) {
+			case 'radial':
+				$new_networkmap['generation_method'] = MAP_GENERATION_RADIAL;
+				break;
+		}
+		
+		
+		$filter = array();
+		
+		$filter['show_groups'] = 0;
+		if ($old_netw_open['show_groups']) {
+			$filter['show_groups'] = 1;
+		}
+		$filter['show_module_plugins'] = 0;
+		$filter['show_snmp_modules'] = 0;
+		if ($old_netw_open['show_snmp_modules']) {
+			$filter['show_snmp_modules'] = 1;
+		}
+		$filter['show_modules'] = 0;
+		if ($old_netw_open['show_modules']) {
+			$filter['show_modules'] = 1;
+		}
+		$filter['show_policy_modules'] = 0;
+		$filter['show_pandora_nodes'] = 0;
+		$filter['show_only_modules_with_alerts'] = 0;
+		if ($old_netw_open['only_modules_with_alerts']) {
+			$filter['show_only_modules_with_alerts'] = 1;
+		}
+		$filter['show_module_group'] = 0;
+		if ($old_netw_open['show_modulegroup']) {
+			$filter['show_module_group'] = 1;
+		}
+		$filter['id_tag'] = 0;
+		if ($old_netw_open['id_tag']) {
+			$filter['id_tag'] = 1;
+		}
+		$filter['text'] = '';
+		
+		$new_networkmap['filter'] = json_encode($filter);
+		
+		html_debug($new_networkmap);
+		
+		html_debug(maps_save_map($new_networkmap));
+		html_debug(mysql_error());
+	}
 }
 ?>
diff --git a/pandora_console/operation/maps/networkmap_list.php b/pandora_console/operation/maps/networkmap_list.php
index 6292a10f35..70b2a684d3 100644
--- a/pandora_console/operation/maps/networkmap_list.php
+++ b/pandora_console/operation/maps/networkmap_list.php
@@ -36,6 +36,8 @@ if (!$networkmaps_read && !$networkmaps_write && !$networkmaps_manage) {
 	}
 }
 
+require_once('include/functions_migration.php');
+
 $migrate_open_networkmaps = (int)get_parameter('migrate_open_networkmaps');
 
 if ($migrate_open_networkmaps)