From a14521312b34e5349c1336b42c259552dc33dbe7 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Tue, 2 Feb 2016 09:30:01 +0100 Subject: [PATCH] New maps in progress... --- pandora_console/include/functions_maps.php | 36 ++++++++++-- .../operation/maps/networkmap_editor.php | 56 ++++++++++--------- .../operation/maps/networkmap_list.php | 33 +++++------ 3 files changed, 78 insertions(+), 47 deletions(-) diff --git a/pandora_console/include/functions_maps.php b/pandora_console/include/functions_maps.php index f109d5ba01..385375296f 100644 --- a/pandora_console/include/functions_maps.php +++ b/pandora_console/include/functions_maps.php @@ -49,10 +49,38 @@ function maps_get_subtype_string($subtype) { } } -function maps_get_count_nodes($id) { - $result = db_get_sql( - "SELECT COUNT(*) FROM titem WHERE id_map = " . $id); - +function maps_duplicate_map($id) { + global $config; + $map = db_get_sql("SELECT * FROM tmap WHERE id_map = " . $id); + $result = 0; + if (!empty($map)) { + $map_names = db_get_all_rows_sql("SELECT name FROM tmap WHERE name LIKE '" . $map['name'] . "%'"); + $index = 0; + foreach ($map_names as $map_name) { + $index++; + } + $map['name'] = $map['name'] . '_' . $index; + $result = db_process_sql_insert('tmap', array('id_group' => $map['id_group'], + 'id_user' => $config['id_user'], 'type' => $map['type'], 'subtype' => $map['subtype'], + 'name' => $map['name'], 'description' => $map['description'], 'width' => $map['width'], + 'height' => $map['height'], 'center_x' => $map['center_x'], 'center_y' => $map['center_y'], + 'background' => $map['background'], 'background_options' => $map['background_options'], + 'source_period' => $map['source_period'], 'source' => $map['source'], + 'source_data' => $map['source_data'], 'generation_method' => $map['generation_method'], + 'filter' => $map['filter'])); + } return (int)$result; } + +function maps_get_count_nodes($id) { + $result = db_get_sql("SELECT COUNT(*) FROM titem WHERE id_map = " . $id); + return (int)$result; +} + +function maps_update_map ($id, $values) { + $where = 'id=' . $id; + $result = db_process_sql_update('tmap', $values, $where); + return (int)$result; +} + ?> diff --git a/pandora_console/operation/maps/networkmap_editor.php b/pandora_console/operation/maps/networkmap_editor.php index d3216983aa..42d53af534 100644 --- a/pandora_console/operation/maps/networkmap_editor.php +++ b/pandora_console/operation/maps/networkmap_editor.php @@ -25,35 +25,41 @@ $networkmaps_write = check_acl ($config['id_user'], 0, "MW"); $networkmaps_manage = check_acl ($config['id_user'], 0, "MM"); $id = (int)get_parameter('id_networkmap', 0); +$edit_networkmap = (int)get_parameter('edit_networkmap', 0); +$add_networkmap = (int)get_parameter('add_networkmap', 0); -$name = (string) get_parameter ('name'); -$description = (string) get_parameter ('description'); -$id_group = (int) get_parameter ('id_group'); -$type = (string) get_parameter ('type'); +if ($edit_networkmap) { + $name = (string) get_parameter ('name'); + $description = (string) get_parameter ('description'); + $id_group = (int) get_parameter ('id_group'); + $type = (string) get_parameter ('type'); -if ($name == "") - $result = false; -else { - //FUNCION - /*$result = networkmap_update_networkmap ($id, - array ('name' => $name, - 'id_group' => $id_group, - 'description' => $description), - 'type' => $type);*/ - $result = false; + if ($name == "") { + $result = 0; + } + else { + $result = maps_update_map ($id, + array ('name' => $name, + 'id_group' => $id_group, + 'description' => $description), + 'type' => $type); + } + + $info = ' Name: ' . $name . ' Description: ' . $description . ' ID group: ' . $id_group . ' Type: ' . $type; + + if ($id) { + db_pandora_audit("Networkmap management", "Update networkmap #" . $id, false, false, $info); + } + else { + db_pandora_audit("Networkmap management", "Fail to update networkmap #$id", false, false, $info); + } + + ui_print_result_message ($result, + __('Successfully updated'), + __('Could not be updated')); } +else if ($add_networkmap) { -$info = ' Name: ' . $name . ' Description: ' . $description . ' ID group: ' . $id_group . ' Type: ' . $type; - -if ($id) { - db_pandora_audit("Networkmap management", "Update networkmap #" . $id, false, false, $info); } -else { - db_pandora_audit("Networkmap management", "Fail to update networkmap #$id", false, false, $info); -} - -ui_print_result_message ($result, - __('Successfully updated'), - __('Could not be updated')); ?> diff --git a/pandora_console/operation/maps/networkmap_list.php b/pandora_console/operation/maps/networkmap_list.php index ca61ffdcce..7ea294d2a5 100644 --- a/pandora_console/operation/maps/networkmap_list.php +++ b/pandora_console/operation/maps/networkmap_list.php @@ -66,24 +66,22 @@ $duplicate_networkmap = (bool)get_parameter('duplicate_networkmap', 0); if ($delete_networkmap) { $result_delete = networkmap_delete_networkmap($id); - + if ($result_delete) db_pandora_audit( "Networkmap management", "Delete networkmap #$id"); else db_pandora_audit( "Networkmap management", "Fail try to delete networkmap #$id"); - + ui_print_result_message ($result_delete, __('Successfully deleted'), __('Could not be deleted')); } if ($duplicate_networkmap) { - //FUNCION - //$result_duplicate = networkmap_duplicate($id); - $result_duplicate = array(); - + $result_duplicate = maps_duplicate_map($id); + ui_print_result_message ($result, __('Successfully duplicate'), __('Could not be duplicate')); @@ -135,7 +133,6 @@ $table->head['copy'] = __('Copy'); $table->head['edit'] = __('Edit'); $table->head['delete'] = __('Delete'); -//FUNCION $networkmaps = maps_get_maps(array('type' => MAP_TYPE_NETWORKMAP)); if (empty($networkmaps)) { @@ -146,18 +143,18 @@ if (empty($networkmaps)) { else { foreach ($networkmaps as $networkmap) { $data = array(); - + $data['name'] = $networkmap['name']; - + $data['name'] = '' . $networkmap['name'] . ''; - + $data['type'] = maps_get_subtype_string($networkmap['subtype']); - - + + if (enterprise_installed()) { if ($networkmap['generated']) { $data['nodes'] = maps_get_count_nodes($networkmap['id']); @@ -166,7 +163,7 @@ else { $data['nodes'] = __('Pending to generate'); } } - + if (!empty($networkmap['id_user'])) { $data['group'] = __('Private for (%s)', $networkmap['id_user']); } @@ -174,26 +171,26 @@ else { $data['groups'] = ui_print_group_icon($networkmap['id_group'], true); } - + $data['copy'] = '' . html_print_image("images/copy.png", true) . ''; - + $data['edit'] = '' . + 'edit_networkmap=1&id_networkmap=' . $networkmap['id'] .'">' . html_print_image("images/edit.png", true) . ''; - + $data['delete'] = '' . html_print_image('images/cross.png', true) . ''; - + $table->data[] = $data; } html_print_table($table);