From 1a668350a73f6307a92117927f1b0404a5316103 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 29 Aug 2011 12:25:33 +0000 Subject: [PATCH] 2011-08-29 Miguel de Dios * godmode/reporting/map_builder.php: wrote the source code for copy the relationships between a copy of items in a visual console. Fixes: #3400124 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4836 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 7 +++++ .../godmode/reporting/map_builder.php | 31 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 8c63012ce3..f397601cdf 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,10 @@ +2011-08-29 Miguel de Dios + + * godmode/reporting/map_builder.php: wrote the source code for copy the + relationships between a copy of items in a visual console. + + Fixes: #3400124 + 2011-08-29 Miguel de Dios * include/functions_visual_map.php: fixed the clean $id_agent var for diff --git a/pandora_console/godmode/reporting/map_builder.php b/pandora_console/godmode/reporting/map_builder.php index 1bb2e3acc6..74ab9b63da 100644 --- a/pandora_console/godmode/reporting/map_builder.php +++ b/pandora_console/godmode/reporting/map_builder.php @@ -63,18 +63,30 @@ if ($copy_layout) { // Return from DB the items of the source layout $data_layout_src = db_get_all_rows_filter ("tlayout_data", "id_layout = " . $id_layout); - if(!empty($data_layout_src)){ - for ($a=0;$a < count($data_layout_src); $a++) { + if(!empty($data_layout_src)) { + + //By default the id parent 0 is always 0. + $id_relations = array(0 => 0); + + for ($a=0; $a < count($data_layout_src); $a++) { // Changing the source id by the new visual console id $data_layout_src[$a]['id_layout'] = $idNewVisualConsole; + $old_id = $data_layout_src[$a]['id']; + // Unsetting the source's id unset($data_layout_src[$a]['id']); // Configure the cloned Console $result = db_process_sql_insert('tlayout_data', $data_layout_src[$a]); + $id_relations[$old_id] = 0; + + if ($result !== false) { + $id_relations[$old_id] = $result; + } + if($result) $ninsert++; }// for each item of console @@ -83,9 +95,22 @@ if ($copy_layout) { // If the number of inserts is correct, the copy is completed if ($ninsert == $inserts) { + + //Update the ids of parents + $items = db_get_all_rows_filter ("tlayout_data", "id_layout = " . $idNewVisualConsole); + + foreach ($items as $item) { + $new_parent = $id_relations[$item['parent_item']]; + + db_process_sql_update('tlayout_data', + array('parent_item' => $new_parent), array('id' => $item['id'])); + } + + echo '

'.__('Successfully copied').'

'; db_clean_cache(); - } else { + } + else { echo '

'.__('Not copied. Error copying data').'

'; } }