From 10bf2819d6e89bdbaa11ad7b913948c7a866eaed Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 4 Dec 2014 12:19:52 +0100 Subject: [PATCH] Now many network maps can be deleted at once --- .../operation/agentes/networkmap_list.php | 241 +++++++++++++++--- 1 file changed, 204 insertions(+), 37 deletions(-) diff --git a/pandora_console/operation/agentes/networkmap_list.php b/pandora_console/operation/agentes/networkmap_list.php index 6e9bb8965c..b6073eb656 100644 --- a/pandora_console/operation/agentes/networkmap_list.php +++ b/pandora_console/operation/agentes/networkmap_list.php @@ -22,12 +22,44 @@ check_login (); if (! check_acl ($config['id_user'], 0, "AR")) { db_pandora_audit("ACL Violation", "Trying to access Networkmap builder"); - include ("general/noaccess.php"); - exit; + if (is_ajax()) { + return; + } + else { + include ("general/noaccess.php"); + exit; + } } require_once('include/functions_networkmap.php'); +if (is_ajax()) { + ob_clean(); + + $delete_networkmaps = (bool) get_parameter('delete_networkmaps'); + if ($delete_networkmaps) { + if (! check_acl ($config['id_user'], 0, "AW")) { + db_pandora_audit("ACL Violation", + "Trying to access Networkmap deletion"); + echo json_encode(-1); + return; + } + + $result = false; + $results = array(); + $ids_networkmap = (array) get_parameter ('ids_networkmap'); + + foreach ($ids_networkmap as $id) { + $results[$id] = (bool) networkmap_delete_networkmap($id); + } + + echo json_encode($results); + return; + } + + return; +} + ui_print_page_header(__('Network map'), "images/op_network.png", false, "network_map", false); // Delete networkmap action @@ -46,7 +78,7 @@ if ($delete_networkmap) { } // Filter form -$group_search = get_parameter('group_search', '0'); +$group_search = (int) get_parameter('group_search'); $type_search = get_parameter('type_filter', '0'); ?> @@ -84,34 +116,36 @@ $type_search = get_parameter('type_filter', '0'); width = "100%"; +$table = new StdClass(); +$table->width = "98%"; $table->style = array(); -$table->style[] = ''; -$table->style[] = 'text-align: center;'; +$table->style[0] = ''; $table->style[1] = 'text-align: center;'; $table->style[2] = 'text-align: center;'; $table->style[3] = 'text-align: center;'; $table->style[4] = 'text-align: center;'; +$table->style[5] = 'text-align: center;'; $table->size = array(); -$table->size[] = '80%'; -$table->size[] = '60px'; -$table->size[] = '30px'; +$table->size[0] = '80%'; +$table->size[1] = '60px'; +$table->size[2] = '30px'; if (check_acl ($config["id_user"], 0, "AW")) { - $table->size[] = '30px'; - $table->size[] = '30px'; + $table->size[3] = '30px'; + $table->size[4] = '30px'; } $table->head = array(); -$table->head[] = __('Name'); -$table->head[] = __('Type'); -$table->head[] = __('Group'); +$table->head[0] = __('Name'); +$table->head[1] = __('Type'); +$table->head[2] = __('Group'); if (check_acl ($config["id_user"], 0, "AW")) { - $table->head[] = __('Edit'); - $table->head[] = __('Delete'); + $table->head[3] = __('Edit'); + $table->head[4] = __('Delete'); + // Checkbox to select all the another checkboxes + $table->head[5] = html_print_checkbox('check_delete_all', 0, false, true); } $id_groups = array_keys(users_get_groups()); @@ -121,7 +155,7 @@ $where['id_group'] = $id_groups; // Order by type field $where['order'] = 'type'; -if ($group_search != '0') +if (!empty($group_search)) $where['id_group'] = $group_search; if ($type_search != '0') @@ -135,8 +169,7 @@ $user_info = users_get_user_by_id($config['id_user']); // $where['id_user'] = $config['id_user']; //} -$network_maps = db_get_all_rows_filter('tnetwork_map', - $where); +$network_maps = db_get_all_rows_filter('tnetwork_map', $where); if ($network_maps === false) { echo "
" . __('Not networkmap defined.') . @@ -150,13 +183,15 @@ else { continue; $data = array(); - $data[] = '' . $network_map['name'] . ''; - $data[] = $network_map['type']; + $data[0] = '' . $network_map['name'] . ''; + $data[1] = $network_map['type']; - $data[] = ui_print_group_icon ($network_map['id_group'], true); + $data[2] = ui_print_group_icon ($network_map['id_group'], true); if (check_acl ($config["id_user"], 0, "AW")) { - $data[] = '' . html_print_image("images/config.png", true) . ''; - $data[] = '' . html_print_image('images/cross.png', true) . ''; + $data[3] = '' . html_print_image("images/config.png", true) . ''; + $data[4] = '' . html_print_image('images/cross.png', true) . ''; + // The value of the checkbox will be the networkmap id to recover it in js to perform the massive deletion + $data[5] = html_print_checkbox('check_delete', $network_map['id_networkmap'], false, true); } $table->data[] = $data; @@ -167,19 +202,151 @@ else { // Create networkmap form if (check_acl ($config['id_user'], 0, "AW")) { + $table_manage = new StdClass(); + $table_manage->width = "100%"; + $table_manage->style = array(); + $table_manage->style[0] = 'font-weight: bold'; + $table_manage->style[3] = 'text-align: right'; + $table_manage->size = array(); + $table_manage->head = array(); + $table_manage->data = array(); + + $actions = array( + 'create' => __('Create'), + 'delete' => __('Delete') + ); $networkmap_types = networkmap_get_types(); - echo '
'; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo "
"; - html_print_input_hidden('add_networkmap', 1); - html_print_select($networkmap_types, 'tab', 'topology', ''); - echo ""; - html_print_submit_button (__('Create networkmap'), 'crt', false, 'class="sub next"'); - echo "
"; + $delete_options = array( + 'selected' => __('Delete selected') + ); + + $row = array(); + $row[] = __('Action'); + $row[] = html_print_select($actions, 'action', 'create', '', '', 0, true, false, false); + $row[] = html_print_select($networkmap_types, 'tab', 'topology', '', '', 0, true) + . html_print_select($delete_options, 'delete_options', 'selected', '', '', 0, true, false, false); + $row[] = html_print_submit_button (__('Execute'), 'crt', false, 'class="sub next"', true) + . html_print_image("images/spinner.gif", true, array('id' => 'action-loading', 'style' => 'display: none;')); + + $table_manage->data[] = $row; + + echo ''; + html_print_table($table_manage); + html_print_input_hidden('add_networkmap', 0); + html_print_input_hidden('delete_networkmaps', 0); echo "
"; } ?> + + \ No newline at end of file