From e32c606fb0a100eb0a0bbb2c673c9e98b61295c5 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Fri, 19 Aug 2016 11:23:09 +0200 Subject: [PATCH] Added new date filters. Ticket #3946. --- .../pandoradb_migrate_6.0_to_6.1.mysql.sql | 6 ++ .../pandoradb_migrate_6.0_to_6.1.oracle.sql | 6 ++ .../godmode/events/event_edit_filter.php | 56 ++++++++++++------- .../operation/events/events_list.php | 30 ++++++++-- pandora_console/pandoradb.oracle.sql | 2 + pandora_console/pandoradb.sql | 4 +- 6 files changed, 79 insertions(+), 25 deletions(-) diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql index 80e1392325..e33f5d0447 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.mysql.sql @@ -52,3 +52,9 @@ ALTER TABLE tplanned_downtime_agents ADD COLUMN `manually_disabled` tinyint(1) D -- Table `tlink` -- --------------------------------------------------------------------- UPDATE `tlink` SET `link` = 'http://library.pandorafms.com/' WHERE `name` = 'Module library'; + +-- --------------------------------------------------------------------- +-- Table `tevent_filter` +-- --------------------------------------------------------------------- +ALTER TABLE tevent_filter ADD COLUMN `date_from` date DEFAULT NULL; +ALTER TABLE tevent_filter ADD COLUMN `date_to` date DEFAULT NULL; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql index 864622f91a..e6a407a6bd 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_6.1.oracle.sql @@ -51,3 +51,9 @@ ALTER TABLE tplanned_downtime_agents ADD COLUMN manually_disabled NUMBER(5, 0) D -- Table `tlink` -- --------------------------------------------------------------------- UPDATE tlink SET link = 'http://library.pandorafms.com/' WHERE name = 'Module library'; + +-- --------------------------------------------------------------------- +-- Table `tevent_filter` +-- --------------------------------------------------------------------- +ALTER TABLE tevent_filter ADD COLUMN date_from date DEFAULT NULL; +ALTER TABLE tevent_filter ADD COLUMN date_to date DEFAULT NULL; diff --git a/pandora_console/godmode/events/event_edit_filter.php b/pandora_console/godmode/events/event_edit_filter.php index 50461f9bbd..0b6e5b338f 100644 --- a/pandora_console/godmode/events/event_edit_filter.php +++ b/pandora_console/godmode/events/event_edit_filter.php @@ -58,7 +58,9 @@ if ($id) { $event_view_hr = $filter['event_view_hr']; $id_user_ack = $filter['id_user_ack']; $group_rep = $filter['group_rep']; - + $date_from = str_replace("-","/",$filter['date_from']); + $date_to = str_replace("-","/",$filter['date_to']); + $tag_with_json = $filter['tag_with']; $tag_with_json_clean = io_safe_output($tag_with_json); $tag_with_base64 = base64_encode($tag_with_json_clean) ; @@ -95,6 +97,9 @@ else { $event_view_hr = ''; $id_user_ack = ''; $group_rep = ''; + $date_from = ''; + $date_to = ''; + $tag_with_json = $tag_with_json_clean = json_encode(array()); $tag_with_base64 = base64_encode($tag_with_json); $tag_without_json = $tag_without_json_clean = json_encode(array()); @@ -117,7 +122,9 @@ if($update || $create) { $event_view_hr = get_parameter('event_view_hr', ''); $id_user_ack = get_parameter('id_user_ack', ''); $group_rep = get_parameter('group_rep', ''); - + $date_from = get_parameter('date_from', ''); + $date_to = get_parameter('date_to', ''); + $tag_with_base64 = get_parameter('tag_with', json_encode(array())); $tag_with_json = io_safe_input(base64_decode($tag_with_base64)); @@ -143,6 +150,8 @@ if($update || $create) { 'group_rep' => $group_rep, 'tag_with' => $tag_with_json, 'tag_without' => $tag_without_json, + 'date_from' => $date_from, + 'date_to' => $date_to, 'filter_only_alert' => $filter_only_alert); } @@ -289,6 +298,11 @@ $table->data[11][0] = '' . __('Repeated') . ''; $table->data[11][1] = html_print_select ($repeated_sel, "group_rep", $group_rep, '', '', '', true); +$table ->data[12][0] = '' . __('Date from') . ''; +$table ->data[12][1] = html_print_input_text ('date_from', $date_from, '', 15, 10, true); + +$table ->data[13][0] = '' . __('Date to') . ''; +$table ->data[13][1] = html_print_input_text ('date_to', $date_to, '', 15, 10, true); $tag_with = json_decode($tag_with_json_clean, true); if (empty($tag_with)) { @@ -328,38 +342,38 @@ $remove_with_tag_disabled = empty($tag_with_temp); $add_without_tag_disabled = empty($tags_select_without); $remove_without_tag_disabled = empty($tag_without_temp); -$table->colspan[13][0] = '2'; -$table->data[13][0] = '' . __('Events with following tags') . ''; -$table->data[14][0] = html_print_select ($tags_select_with, 'select_with', +$table->colspan[14][0] = '2'; +$table->data[14][0] = '' . __('Events with following tags') . ''; +$table->data[15][0] = html_print_select ($tags_select_with, 'select_with', '', '', '', 0, true, false, true, '', false, 'width: 220px;'); -$table->data[14][1] = html_print_button(__('Add'), 'add_whith', +$table->data[15][1] = html_print_button(__('Add'), 'add_whith', $add_with_tag_disabled, '', 'class="add sub"', true); -$table->data[15][0] = html_print_select ($tag_with_temp, +$table->data[16][0] = html_print_select ($tag_with_temp, 'tag_with_temp', array(), '', '', 0, true, true, true, '', false, "width: 220px; height: 50px;"); -$table->data[15][0] .= html_print_input_hidden('tag_with', +$table->data[16][0] .= html_print_input_hidden('tag_with', $tag_with_base64, true); -$table->data[15][1] = html_print_button(__('Remove'), +$table->data[16][1] = html_print_button(__('Remove'), 'remove_whith', $remove_with_tag_disabled, '', 'class="delete sub"', true); -$table->colspan[16][0] = '2'; -$table->data[16][0] = '' . __('Events without following tags') . ''; -$table->data[17][0] = html_print_select ($tags_select_without, 'select_without', +$table->colspan[17][0] = '2'; +$table->data[17][0] = '' . __('Events without following tags') . ''; +$table->data[18][0] = html_print_select ($tags_select_without, 'select_without', '', '', '', 0, true, false, true, '', false, 'width: 220px;'); -$table->data[17][1] = html_print_button(__('Add'), 'add_whithout', +$table->data[18][1] = html_print_button(__('Add'), 'add_whithout', $add_without_tag_disabled, '', 'class="add sub"', true); -$table->data[18][0] = html_print_select ($tag_without_temp, +$table->data[19][0] = html_print_select ($tag_without_temp, 'tag_without_temp', array(), '', '', 0, true, true, true, '', false, "width: 220px; height: 50px;"); -$table->data[18][0] .= html_print_input_hidden('tag_without', +$table->data[19][0] .= html_print_input_hidden('tag_without', $tag_without_base64, true); -$table->data[18][1] = html_print_button(__('Remove'), 'remove_whithout', +$table->data[19][1] = html_print_button(__('Remove'), 'remove_whithout', $remove_without_tag_disabled, '', 'class="delete sub"', true); -$table->data[19][0] = '' . __('Alert events') . ''; -$table->data[19][1] = html_print_select( +$table->data[20][0] = '' . __('Alert events') . ''; +$table->data[20][1] = html_print_select( array( '-1' => __('All'), '0' => __('Filter alert events'), @@ -368,8 +382,8 @@ $table->data[19][1] = html_print_select( if (!is_metaconsole()) { echo $id_agent_module; - $table->data[20][0] = '' . __('Module search') . ''; - $table->data[20][1] .= html_print_autocomplete_modules('module_search', + $table->data[21][0] = '' . __('Module search') . ''; + $table->data[21][1] .= html_print_autocomplete_modules('module_search', $text_module, false, $id_agent_module, true, '', array(), true); } @@ -405,6 +419,8 @@ var val_none = 0; var text_none = ""; $(document).ready( function() { + $("#text-date_from, #text-date_to").datepicker({dateFormat: ""}); + $("#button-add_whith").click(function() { click_button_add_tag("with"); }); diff --git a/pandora_console/operation/events/events_list.php b/pandora_console/operation/events/events_list.php index 60f1f74bce..0265c1082d 100644 --- a/pandora_console/operation/events/events_list.php +++ b/pandora_console/operation/events/events_list.php @@ -77,7 +77,9 @@ if (is_ajax()) { $values['tag_without'] = get_parameter('tag_without', io_json_mb_encode(array())); $values['filter_only_alert'] = get_parameter('filter_only_alert'); $values['id_group_filter'] = get_parameter('id_group_filter'); - + $values['date_from'] = get_parameter('date_from'); + $values['date_to'] = get_parameter('date_to'); + $exists = (bool)db_get_value_filter( 'id_filter', 'tevent_filter', $values); @@ -115,7 +117,9 @@ if (is_ajax()) { $values['tag_without'] = get_parameter('tag_without', io_json_mb_encode(array())); $values['filter_only_alert'] = get_parameter('filter_only_alert'); $values['id_group_filter'] = get_parameter('id_group_filter'); - + $values['date_from'] = get_parameter('date_from'); + $values['date_to'] = get_parameter('date_to'); + $result = db_process_sql_update('tevent_filter', $values, array('id_filter' => $id)); @@ -957,6 +961,20 @@ $(document).ready( function() { $("#filter_only_alert").val(val); if (i == 'id_group_filter') $("#id_group_filter").val(val); + if (i == 'date_from'){ + if((val == '0000-00-00') || (val == null)) { + $("#text-date_from").val(''); + } else { + $("#text-date_from").val(val.replace(/\-/g,"/")); + } + } + if (i == 'date_to'){ + if((val == '0000-00-00') || (val == null)) { + $("#text-date_to").val(''); + } else { + $("#text-date_to").val(val.replace(/\-/g,"/")); + } + } }); reorder_tags_inputs(); // Update the info with the loaded filter @@ -1020,7 +1038,9 @@ $(document).ready( function() { "tag_with": Base64.decode($("#hidden-tag_with").val()), "tag_without": Base64.decode($("#hidden-tag_without").val()), "filter_only_alert" : $("#filter_only_alert").val(), - "id_group_filter": $("#id_group_filter").val() + "id_group_filter": $("#id_group_filter").val(), + "date_from": $("#text-date_from").val(), + "date_to": $("#text-date_to").val() }, function (data) { $(".info_box").hide(); @@ -1115,7 +1135,9 @@ $(document).ready( function() { "tag_with" : Base64.decode($("#hidden-tag_with").val()), "tag_without" : Base64.decode($("#hidden-tag_without").val()), "filter_only_alert" : $("#filter_only_alert").val(), - "id_group_filter": $("#id_group_filter").val() + "id_group_filter": $("#id_group_filter").val(), + "date_from": $("#text-date_from").val(), + "date_to": $("#text-date_to").val() }, function (data) { $(".info_box").hide(); diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index babe5f8e58..a1c7f89b3b 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -1918,6 +1918,8 @@ CREATE TABLE tevent_filter ( group_rep NUMBER(10, 0) DEFAULT 0, tag_with CLOB, tag_without CLOB, + date_from DATE DEFAULT NULL, + date_to DATE DEFAULT NULL, filter_only_alert NUMBER(10, 0) DEFAULT -1 ); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 70a4f2f746..a169fe1004 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1713,7 +1713,9 @@ CREATE TABLE IF NOT EXISTS `tevent_filter` ( `group_rep` int(10) NOT NULL default 0, `tag_with` text NOT NULL, `tag_without` text NOT NULL, - `filter_only_alert` int(10) NOT NULL default -1, + `filter_only_alert` int(10) NOT NULL default -1, + `date_from` date default NULL, + `date_to` date default NULL, PRIMARY KEY (`id_filter`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;