diff --git a/pandora_console/godmode/snmpconsole/snmp_filters.php b/pandora_console/godmode/snmpconsole/snmp_filters.php index 085b23957d..9316b36b05 100644 --- a/pandora_console/godmode/snmpconsole/snmp_filters.php +++ b/pandora_console/godmode/snmpconsole/snmp_filters.php @@ -28,6 +28,7 @@ $update_filter = (int) get_parameter ('update_filter', -2); $delete_filter = (int) get_parameter ('delete_filter', -1); $description = (string) get_parameter ('description', ''); $filter = (string) get_parameter ('filter', ''); +$index_post = (int) get_parameter('index_post', 0); // Create/update header if ($edit_filter > -2) { @@ -44,9 +45,35 @@ else {// Overview header // Create/update filter if ($update_filter > -2) { + // UPDATE if ($update_filter > -1) { - $values = array('description' => $description, 'filter' => $filter); - $result = db_process_sql_update('tsnmp_filter', $values, array('id_snmp_filter' => $update_filter)); + $new_unified_id = (db_get_value_sql("SELECT unified_filters_id FROM tsnmp_filter WHERE id_snmp_filter = " . $update_filter)); + $elements = get_parameter('elements', array()); + + $elements = explode(",", $elements); + foreach ($elements as $e) { + $filter = get_parameter('filter_' . $e); + $values = array('description' => $description, 'filter' => $filter, 'unified_filters_id' => $new_unified_id); + $result = db_process_sql_update('tsnmp_filter', $values, array('id_snmp_filter' => $e)); + } + if (count($elements) == 1) { + $new_unified_id = (db_get_value_sql("SELECT MAX(unified_filters_id) FROM tsnmp_filter")) + 1; + + $filter = get_parameter('filter_' . $elements[0]); + $values = array('description' => $description, 'filter' => $filter, 'unified_filters_id' => $new_unified_id); + $result = db_process_sql_update('tsnmp_filter', $values, array('id_snmp_filter' => $elements[0])); + } + for ($i = 1; $i < $index_post; $i++) { + $filter = get_parameter('filter_' . $i); + if ($filter != "") { + $values = array( + 'description' => $description, + 'filter' => $filter, + 'unified_filters_id' => $new_unified_id); + $result = db_process_sql_insert('tsnmp_filter', $values); + } + } + if ($result === false) { ui_print_error_message (__('There was a problem updating the filter')); } @@ -54,11 +81,29 @@ if ($update_filter > -2) { ui_print_success_message (__('Successfully updated')); } } + // CREATE else { - $values = array( - 'description' => $description, - 'filter' => $filter); - $result = db_process_sql_insert('tsnmp_filter', $values); + $new_unified_id = (db_get_value_sql("SELECT MAX(unified_filters_id) FROM tsnmp_filter")) + 1; + + if ($index_post == 1) { + $filter = get_parameter('filter_0'); + $values = array( + 'description' => $description, + 'filter' => $filter, + 'unified_filters_id' => 0); + $result = db_process_sql_insert('tsnmp_filter', $values); + } + else { + for ($i = 0; $i < $index_post; $i++) { + $filter = get_parameter('filter_' . $i); + $values = array( + 'description' => $description, + 'filter' => $filter, + 'unified_filters_id' => $new_unified_id); + $result = db_process_sql_insert('tsnmp_filter', $values); + } + } + if ($result === false) { ui_print_error_message (__('There was a problem creating the filter')); } @@ -68,7 +113,15 @@ if ($update_filter > -2) { } } else if ($delete_filter > -1) { // Delete - $result = db_process_sql_delete('tsnmp_filter', array('id_snmp_filter' => $delete_filter)); + $unified_id_to_delete = (db_get_value_sql("SELECT unified_filters_id FROM tsnmp_filter WHERE id_snmp_filter = " . $delete_filter)); + + if ($unified_id_to_delete == 0) { + $result = db_process_sql_delete('tsnmp_filter', array('id_snmp_filter' => $delete_filter)); + } + else { + $result = db_process_sql_delete('tsnmp_filter', array('unified_filters_id' => $unified_id_to_delete)); + } + if ($result === false) { ui_print_error_message (__('There was a problem deleting the filter')); } @@ -88,19 +141,50 @@ if ($edit_filter > -1) { // Create/update form if ($edit_filter > -2) { + $index = $index_post; $table->data = array (); + $table->id = 'filter_table'; $table->width = '100%'; $table->class = 'databox filters'; $table->data[0][0] = __('Description'); $table->data[0][1] = html_print_input_text ('description', $description, '', 60, 100, true); $table->data[1][0] = __('Filter'); - $table->data[1][1] = html_print_input_text ('filter', $filter, '', 60, 100, true); - $table->data[1][1] .= ui_print_help_tip (__("This field contains a substring, could be part of a IP address, a numeric OID, or a plain substring") . SEPARATOR_COLUMN, true); - + if ($edit_filter > -1) { + $filters = db_get_all_rows_sql("SELECT * FROM tsnmp_filter WHERE unified_filters_id = (SELECT unified_filters_id FROM tsnmp_filter WHERE id_snmp_filter = " . $edit_filter . ")"); + $j = 1; + foreach ($filters as $f) { + if ($j != 1) { + $table->data[$j][0] = ""; + } + $table->data[$j][1] = html_print_input_text ('filter_' . $f['id_snmp_filter'], $f['filter'], '', 60, 100, true); + if ($j == 1) { + $table->data[$j][1] .= ui_print_help_tip (__("This field contains a substring, could be part of a IP address, a numeric OID, or a plain substring") . SEPARATOR_COLUMN, true); + } + else { + $table->data[$j][1] .= html_print_image('images/cross.png', true, array('id' => 'delete_filter_' . $f['id_snmp_filter'], 'alt' => __('Click to add new filter'), 'title' => __('Click to add new filter'))); + } + $j++; + $index++; + } + } + else { + $table->data[1][1] = html_print_input_text ('filter_' . $index, $filter, '', 60, 100, true); + $table->data[1][1] .= ui_print_help_tip (__("This field contains a substring, could be part of a IP address, a numeric OID, or a plain substring") . SEPARATOR_COLUMN, true); + } + $index++; echo '