From 2adf9511218f10a30cd11cc9f881ae0c937a16f7 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Mon, 30 Oct 2017 15:45:31 +0100 Subject: [PATCH 1/3] Added free search values to data table --- pandora_console/include/ajax/module.php | 22 ++++++++++++------- pandora_console/include/functions_modules.php | 20 +++++++++++------ .../operation/agentes/estado_monitores.php | 6 +++++ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 32de285b11..a174c84ba5 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -123,12 +123,16 @@ if ($get_module_detail) { $time_from = (string) get_parameter ('time_from', date ('h:iA')); $date_to = (string) get_parameter ('date_to', date ('Y-m-j')); $time_to = (string) get_parameter ('time_to', date ('h:iA')); + $freesearch = (string) get_parameter ('freesearch', ''); $formtable->width = '98%'; $formtable->class = "databox"; $formtable->data = array (); $formtable->size = array (); + $moduletype_name = modules_get_moduletype_name( + modules_get_agentmodule_type($module_id)); + $periods = array(SECONDS_5MINUTES =>__('5 minutes'), SECONDS_30MINUTES =>__('30 minutes'), SECONDS_1HOUR =>__('1 hour'), @@ -148,13 +152,18 @@ if ($get_module_detail) { "selection_mode", 'fromnow', '', $selection_mode, false, '', 'style="margin-right: 15px;"', true) . __("Choose a time from now"); $formtable->data[0][1] = html_print_select ($periods, 'period', $period, '', '', 0, true, false, false); - $formtable->data[0][2] = ''; + if (preg_match("/_string/", $moduletype_name)) { + $formtable->data[0][2] = __('Free search') . ' '; + $formtable->data[0][2] .= html_print_input_text ('freesearch', $freesearch, '', 25, null, true); + } else { + $freesearch = ''; + $formtable->data[0][2] = ''; + } + $formtable->cellstyle[0][3] = 'vertical-align: middle;'; $formtable->data[0][3] = "" . html_print_image ("images/refresh.png", true, array ("style" => 'vertical-align: middle;', "border" => "0" )) . ""; - $formtable->rowspan[0][3] = 2; - $formtable->cellstyle[0][3] = 'vertical-align: middle;'; $formtable->data[1][0] = html_print_radio_button_extended( "selection_mode", 'range','', $selection_mode, false, '', @@ -177,9 +186,6 @@ if ($get_module_detail) { html_print_table($formtable); - $moduletype_name = modules_get_moduletype_name( - modules_get_agentmodule_type($module_id)); - $offset = (int) get_parameter("offset"); $block_size = (int) $config["block_size"]; @@ -222,10 +228,10 @@ if ($get_module_detail) { } $count = modules_get_agentmodule_data ($module_id, $period, - $date, true, $conexion); + $date, true, $conexion, 'ASC', $freesearch); $module_data = modules_get_agentmodule_data ($module_id, $period, - $date, false, $conexion, 'DESC'); + $date, false, $conexion, 'DESC', $freesearch); if (empty($module_data)) { $result = array(); diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index bcdeb6819c..0c522ceece 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1720,7 +1720,8 @@ function modules_get_next_data ($id_agent_module, $utimestamp = 0, $string = 0) * @return array The module value and the timestamp */ function modules_get_agentmodule_data ($id_agent_module, $period, - $date = 0, $trash=false, $conexion = false, $order = 'ASC') { + $date = 0, $trash=false, $conexion = false, $order = 'ASC', + $freesearch = '') { global $config; $module = db_get_row('tagente_modulo', 'id_agente_modulo', @@ -1742,12 +1743,17 @@ function modules_get_agentmodule_data ($id_agent_module, $period, case 17: //async_string case 23: - $sql = sprintf ("SELECT datos AS data, utimestamp - FROM tagente_datos_string - WHERE id_agente_modulo = %d - AND utimestamp > %d AND utimestamp <= %d - ORDER BY utimestamp %s", - $id_agent_module, $datelimit, $date, $order); + $sql = sprintf ( + "SELECT datos AS data, utimestamp FROM tagente_datos_string + WHERE id_agente_modulo = %d + %s + AND utimestamp > %d AND utimestamp <= %d + ORDER BY utimestamp %s", + $id_agent_module, + !empty($freesearch) ? " AND datos REGEXP '" . $freesearch . "' " : "", + $datelimit, $date, + $order + ); break; //log4x case 24: diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index f5c870dc83..0d6e9b8c6b 100755 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -364,6 +364,12 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri extra_parameters = '&selection_mode=' + selection_mode + '&date_from=' + date_from + '&date_to=' + date_to + '&time_from=' + time_from + '&time_to=' + time_to; } + + // Get the free text in both options + var freesearch = $('#text-freesearch').val(); + if (freesearch == null) freesearch = ''; + extra_parameters += '&freesearch=' + freesearch; + title = ; $.ajax({ type: "POST", From 443163515db7856a998f81d60d9ac2bfee1601ec Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 2 Nov 2017 15:51:37 +0100 Subject: [PATCH 2/3] Added checkbox to free search on agents data view --- pandora_console/include/ajax/module.php | 28 ++++++++++++------- pandora_console/include/functions_modules.php | 20 ++++++++++++- .../operation/agentes/estado_monitores.php | 11 ++++++-- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index a174c84ba5..7daf28fcd1 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -124,6 +124,7 @@ if ($get_module_detail) { $date_to = (string) get_parameter ('date_to', date ('Y-m-j')); $time_to = (string) get_parameter ('time_to', date ('h:iA')); $freesearch = (string) get_parameter ('freesearch', ''); + $free_checkbox = (bool) get_parameter ('free_checkbox', false); $formtable->width = '98%'; $formtable->class = "databox"; @@ -152,18 +153,13 @@ if ($get_module_detail) { "selection_mode", 'fromnow', '', $selection_mode, false, '', 'style="margin-right: 15px;"', true) . __("Choose a time from now"); $formtable->data[0][1] = html_print_select ($periods, 'period', $period, '', '', 0, true, false, false); - if (preg_match("/_string/", $moduletype_name)) { - $formtable->data[0][2] = __('Free search') . ' '; - $formtable->data[0][2] .= html_print_input_text ('freesearch', $freesearch, '', 25, null, true); - } else { - $freesearch = ''; - $formtable->data[0][2] = ''; - } - $formtable->cellstyle[0][3] = 'vertical-align: middle;'; + $formtable->data[0][2] = ''; $formtable->data[0][3] = "" . html_print_image ("images/refresh.png", true, array ("style" => 'vertical-align: middle;', "border" => "0" )) . ""; + $formtable->rowspan[0][3] = 2; + $formtable->cellstyle[0][3] = 'vertical-align: middle;'; $formtable->data[1][0] = html_print_radio_button_extended( "selection_mode", 'range','', $selection_mode, false, '', @@ -184,6 +180,18 @@ if ($get_module_detail) { $formtable->data[1][2] .= html_print_input_text('time_to', $time_to, '', 9, 7, true); + $freesearch_object = ''; + if (preg_match("/_string/", $moduletype_name)) { + $formtable->data[2][0] = __('Free search') . ' '; + $formtable->data[2][1] = html_print_input_text ('freesearch', $freesearch, '', 20, null, true); + $formtable->data[2][2] = html_print_checkbox('free_checkbox', 1, $free_checkbox, true) . + $formtable->data[2][2] .= ' ' . __('Exact phrase'); + $freesearch_object = json_encode( array( + 'value' => io_safe_output($freesearch), + 'exact' => (bool)$free_checkbox + )); + } + html_print_table($formtable); $offset = (int) get_parameter("offset"); @@ -228,10 +236,10 @@ if ($get_module_detail) { } $count = modules_get_agentmodule_data ($module_id, $period, - $date, true, $conexion, 'ASC', $freesearch); + $date, true, $conexion, 'ASC', $freesearch_object); $module_data = modules_get_agentmodule_data ($module_id, $period, - $date, false, $conexion, 'DESC', $freesearch); + $date, false, $conexion, 'DESC', $freesearch_object); if (empty($module_data)) { $result = array(); diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 0c522ceece..6d09e2d9a9 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1716,6 +1716,13 @@ function modules_get_next_data ($id_agent_module, $utimestamp = 0, $string = 0) * @param int Agent module id * @param int Period of time to check (in seconds) * @param int Top date to check the values. Default current time. + * @param + * @param + * @param string 'ASC' od 'DESC' + * @param string with a json with parameters to filter data + * string object: + * value: Text to search + * exact: Boolean. True if search exact phrase or false to content * * @return array The module value and the timestamp */ @@ -1743,6 +1750,17 @@ function modules_get_agentmodule_data ($id_agent_module, $period, case 17: //async_string case 23: + // Free search is a json with value and exact modifier + $freesearch = json_decode($freesearch, true); + $freesearch_sql = ''; + if (isset($freesearch['value']) && !empty($freesearch['value'])) { + $freesearch_sql = " AND datos "; + if ($freesearch['exact']){ + $freesearch_sql .= "='" . $freesearch['value'] . "' "; + } else { + $freesearch_sql .= " LIKE '%" . $freesearch['value'] . "%' "; + } + } $sql = sprintf ( "SELECT datos AS data, utimestamp FROM tagente_datos_string WHERE id_agente_modulo = %d @@ -1750,7 +1768,7 @@ function modules_get_agentmodule_data ($id_agent_module, $period, AND utimestamp > %d AND utimestamp <= %d ORDER BY utimestamp %s", $id_agent_module, - !empty($freesearch) ? " AND datos REGEXP '" . $freesearch . "' " : "", + $freesearch_sql, $datelimit, $date, $order ); diff --git a/pandora_console/operation/agentes/estado_monitores.php b/pandora_console/operation/agentes/estado_monitores.php index 0d6e9b8c6b..3fceedda4e 100755 --- a/pandora_console/operation/agentes/estado_monitores.php +++ b/pandora_console/operation/agentes/estado_monitores.php @@ -367,8 +367,15 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri // Get the free text in both options var freesearch = $('#text-freesearch').val(); - if (freesearch == null) freesearch = ''; - extra_parameters += '&freesearch=' + freesearch; + if (freesearch != null && freesearch !== '') { + var free_checkbox = $('input[name=free_checkbox]:checked').val(); + extra_parameters += '&freesearch=' + freesearch; + if (free_checkbox == 1) { + extra_parameters += '&free_checkbox=1'; + } else { + extra_parameters += '&free_checkbox=0'; + } + } title = ; $.ajax({ From 24e93d0cd6ec82a6d359f76db0e390fc47c12625 Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 2 Nov 2017 18:11:54 +0100 Subject: [PATCH 3/3] Fixed style code --- pandora_console/include/ajax/module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 7daf28fcd1..66063ed5ab 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -184,7 +184,7 @@ if ($get_module_detail) { if (preg_match("/_string/", $moduletype_name)) { $formtable->data[2][0] = __('Free search') . ' '; $formtable->data[2][1] = html_print_input_text ('freesearch', $freesearch, '', 20, null, true); - $formtable->data[2][2] = html_print_checkbox('free_checkbox', 1, $free_checkbox, true) . + $formtable->data[2][2] = html_print_checkbox('free_checkbox', 1, $free_checkbox, true); $formtable->data[2][2] .= ' ' . __('Exact phrase'); $freesearch_object = json_encode( array( 'value' => io_safe_output($freesearch),