diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index a83a2a57c1..d8e9ddc2d0 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,25 @@ +2012-03-15 Sergio Martin + + * include/functions_html.php + include/javascript/pandora.js + include/functions_custom_graphs.php + include/functions.php + operation/agentes/datos_agente.php + operation/agentes/gis_view.php + operation/agentes/graphs.php + operation/agentes/stat_win.php + operation/reporting/graph_viewer.php + mobile/operation/agents/view_agents.php + godmode/agentes/agent_manager.php + godmode/massive/massive_edit_agents.php + godmode/reporting/graph_builder.main.php + godmode/reporting/reporting_builder.item_editor.php + godmode/reporting/graph_builder.preview.php: changed the + html_print_extended_select_for_time function to select + easily the custom period and do it genericly. + Clean all the calls to this function and unify the + combo periods. + 2012-03-15 Vanessa Gil * godmode/alerts/alert_actions.php diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 27fee9cef1..ebcf6cff93 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -235,17 +235,7 @@ $table->data[3][1] = html_print_select_groups(false, "AR", false, 'grupo', $grup $table->data[4][0] = __('Interval'); -$intervals = array (); -$intervals[30] = human_time_description_raw (30); -$intervals[60] = human_time_description_raw (60); -$intervals[300] = human_time_description_raw (300); -$intervals[600] = human_time_description_raw (600); -$intervals[1200] = human_time_description_raw (1200); -$intervals[1800] = human_time_description_raw (1800); -$intervals[3600] = human_time_description_raw (3600); -$intervals[7200] = human_time_description_raw (7200); -$table->data[4][1] = html_print_extended_select_for_time ($intervals, 'intervalo', $intervalo, '', '', '0', 10, true) . __(" seconds."); -//$table->data[4][1] = html_print_input_text ('intervalo', $intervalo, '', 16, 100, true); +$table->data[4][1] = html_print_extended_select_for_time ('intervalo', $intervalo, '', '', '0', 10, true); $table->data[5][0] = __('OS'); $table->data[5][1] = html_print_select_from_sql ('SELECT id_os, name FROM tconfig_os', diff --git a/pandora_console/godmode/massive/massive_edit_agents.php b/pandora_console/godmode/massive/massive_edit_agents.php index 1c07da8045..1e7942a34c 100644 --- a/pandora_console/godmode/massive/massive_edit_agents.php +++ b/pandora_console/godmode/massive/massive_edit_agents.php @@ -247,16 +247,7 @@ $table->data[1][1] = html_print_select_groups(false, "AR", false, 'group', $grou $table->data[2][0] = __('Interval'); -$intervals = array (); -$intervals[30] = human_time_description_raw (30); -$intervals[60] = human_time_description_raw (60); -$intervals[300] = human_time_description_raw (300); -$intervals[600] = human_time_description_raw (600); -$intervals[1200] = human_time_description_raw (1200); -$intervals[1800] = human_time_description_raw (1800); -$intervals[3600] = human_time_description_raw (3600); -$intervals[7200] = human_time_description_raw (7200); -$table->data[2][1] = html_print_extended_select_for_time ($intervals, 'interval', $interval, '', '', '0', 10, true, 'width: 150px') . __(" seconds."); +$table->data[2][1] = html_print_extended_select_for_time ('interval', $interval, '', '', '0', 10, true, 'width: 150px'); $table->data[3][0] = __('OS'); $table->data[3][1] = html_print_select_from_sql ('SELECT id_os, name FROM tconfig_os', diff --git a/pandora_console/godmode/reporting/graph_builder.main.php b/pandora_console/godmode/reporting/graph_builder.main.php index 6de1f90084..36eb2a4836 100644 --- a/pandora_console/godmode/reporting/graph_builder.main.php +++ b/pandora_console/godmode/reporting/graph_builder.main.php @@ -127,8 +127,6 @@ echo ""; echo "".__('Height').""; echo ""; echo ""; - -$periods = custom_graphs_get_sec_periods(); $period_label = $periods[$period]; @@ -136,8 +134,7 @@ echo ""; echo ""; echo "".__('Period').""; echo ""; -html_print_extended_select_for_time ($periods, 'period', $period, '', '', '0', 10); -echo __(" seconds."); +html_print_extended_select_for_time ('period', $period, '', '', '0', 10); echo ""; echo "".__('Stacked').""; echo ""; diff --git a/pandora_console/godmode/reporting/graph_builder.preview.php b/pandora_console/godmode/reporting/graph_builder.preview.php index f650000461..ea1c6d3daf 100644 --- a/pandora_console/godmode/reporting/graph_builder.preview.php +++ b/pandora_console/godmode/reporting/graph_builder.preview.php @@ -96,7 +96,7 @@ $period = (int) get_parameter ('period'); if (! $period) $period = $graph["period"]; else - $period = 3600 * $period; + $period = $period; $events = $graph["events"]; $description = $graph["description"]; @@ -165,8 +165,7 @@ echo "".__('Period').""; echo ""; echo ""; -html_print_select (custom_graphs_get_periods (), 'period', intval ($period / 3600), - '', '', 0, false, false, false); +echo html_print_extended_select_for_time ('period', $period, '', '', '0', 10, true); echo ""; echo ""; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index ab27398202..e5804b5d26 100644 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -384,8 +384,8 @@ html_print_input_hidden('id_item', $idItem); + html_print_extended_select_for_time ('period', $period, '', '', '0', 10); + ?> @@ -401,8 +401,7 @@ html_print_input_hidden('id_item', $idItem); @@ -414,8 +413,7 @@ html_print_input_hidden('id_item', $idItem); diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index eec270b6c7..dd9d001f14 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1552,4 +1552,31 @@ function get_user_dashboards ($id_user) { return db_get_all_rows_sql ($sql); } +/** + * Get all the possible periods in seconds. + * + * @return The possible periods in an associative array. + */ +function get_periods () { + $periods = array (); + + $periods[0] = __('custom'); + $periods[300] = '5 '.__('minutes'); + $periods[1800] = '30 '.__('minutes'); + $periods[3600] = __('1 hour'); + $periods[21600] = '6 '.__('hours'); + $periods[43200] = '12 '.__('hours'); + $periods[86400] = __('1 day'); + $periods[604800] = __('1 week'); + $periods[1296000] = __('15 days'); + $periods[2592000] = '1 '.__('month'); + $periods[7776000] = '3 '.__('months'); + $periods[15552000] = '6 '.__('months'); + $periods[31104000] = '1 '.__('year'); + $periods[62208000] = '2 '.__('years'); + $periods[93312000] = '3 '.__('years'); + + return $periods; +} + ?> diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index 186518fdd2..82c2041c4e 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -115,52 +115,4 @@ function custom_graphs_print ($id_graph, $height, $width, $period, $stacked, $re echo $output; } -/** - * Get all the possible periods in a custom graph. - * - * @return The possible periods in a custom graph in an associative array. - */ -function custom_graphs_get_periods () { - $periods = array (); - - $periods[1] = __('1 hour'); - $periods[2] = '2 '.__('hours'); - $periods[3] = '3 '.__('hours'); - $periods[6] = '6 '.__('hours'); - $periods[12] = '12 '.__('hours'); - $periods[24] = __('1 day'); - $periods[48] = __('2 days'); - $periods[168] = __('1 week'); - $periods[720] = __('1 month'); - $periods[4320] = __('6 months'); - - return $periods; -} - -/** - * Get all the possible periods in a custom graph in seconds. - * - * @return The possible periods in a custom graph in an associative array. - */ -function custom_graphs_get_sec_periods () { - $periods = array (); - - $periods[3600] = __('1 hour'); - $periods[7200] = '2 '.__('hours'); - $periods[10800] = '3 '.__('hours'); - $periods[21600] = '6 '.__('hours'); - $periods[43200] = '12 '.__('hours'); - $periods[86400] = __('1 day'); - $periods[172800] = __('2 days'); - $periods[345600] = __('4 days'); - $periods[604800] = __('1 week'); - $periods[1296000] = __('15 daysk'); - $periods[2592000] = __('1 month'); - $periods[5184000] = __('2 months'); - $periods[15552000] = __('6 months'); - $periods[31104000] = __('1 year'); - - return $periods; -} - ?> diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index e2564ff8e2..3a99537659 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -405,7 +405,6 @@ function html_print_select_from_sql ($sql, $name, $selected = '', $script = '', /** * Render a pair of select for times and text box for set the time more fine. * - * @param array Array with dropdown values. Example: $fields["value"] = "label" * @param string Select form name * @param variant Current selected value. Can be a single value or an * array of selected values (in combination with multiple) @@ -418,21 +417,40 @@ function html_print_select_from_sql ($sql, $name, $selected = '', $script = '', * @return string HTML code if return parameter is true. */ -function html_print_extended_select_for_time ($fields, $name, $selected = '', $script = '', $nothing = '', +function html_print_extended_select_for_time ($name, $selected = '', $script = '', $nothing = '', $nothing_value = '0', $size = false, $return = false, $select_style = false) { + + $fields = get_periods(); if (($selected !== false) && (!isset($fields[$selected]))) { $fields[$selected] = human_time_description_raw($selected,true); } + $units = array( + 1 => __('seconds'), + 60 => __('minutes'), + 3600 => __('hours'), + 86400 => __('days'), + 2592000 => __('months'), + 31104000 => __('years')); + ob_start(); - html_print_select ($fields, $name . '_select', $selected,"javascript: $('#text-" . $name . "').val($('#" . $name . "_select').val());" . $script, - $nothing, $nothing_value, false, false, false, '', false, $select_style); - html_print_input_text ($name, $selected, '', $size); + html_print_select ($fields, $name . '_select', $selected,"" . $script, + $nothing, $nothing_value, false, false, false, '', false, 'font-size: xx-small;'.$select_style); + html_print_input_text ($name . '_text', $selected, '', $size); + html_print_input_hidden ($name, $selected); + html_print_select ($units, $name . '_units', 1, "" . $script, + $nothing, $nothing_value, false, false, false, '', false, 'font-size: xx-small;'.$select_style); + echo " + + "; + $returnString = ob_get_clean(); - + if ($return) return $returnString; else diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 0ca46de661..33a46df486 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -600,3 +600,77 @@ function agent_autocomplete (id_agent_name, id_server_name, id_agent_id ) { //Force to style of items $(".ui-autocomplete").css("text-align", "left"); } + +/** + * Manage events into html_extended_select_for_time + * + * This function has all the events to manage the extended select + * for time + * + * @param name string with the name of the select for time + */ +function period_select_events(name) { + function adjustTextUnits() { + var restPrev; + var unitsSelected = false; + $('#'+name+'_units option').each(function() { + var rest = $('#text-'+name+'_text').val()/$(this).val(); + var restInt = parseInt(rest).toString(); + if(rest != restInt && unitsSelected == false) { + $('#'+name+'_units option:eq('+($(this).index()-1)+')').attr('selected', true); + $('#text-'+name+'_text').val(restPrev); + unitsSelected = true; + } + + restPrev = rest; + }); + + if(unitsSelected == false) { + $('#'+name+'_units option:last').attr('selected', true); + $('#text-'+name+'_text').val(restPrev); + } + } + + adjustTextUnits(); + + // When select a default period, is setted in seconds + $('#'+name+'_select').change(function() { + var value = $('#'+name+'_select').val(); + + if(value == 0) { + value = 300; + } + + $('#hidden-'+name).val(value); + $('#text-'+name+'_text').val(value); + adjustTextUnits(); + }); + + // When select a custom units, the default period changes to 'custom' and + // the time in seconds is calculated into hidden input + $('#'+name+'_units').change(function() { + $('#'+name+'_select option:eq(0)').attr('selected', 'selected'); + calculateSeconds(); + }); + + // When write any character into custom input, it check to convert it to + // integer and calculate in seconds into hidden input + $('#text-'+name+'_text').keyup (function () { + var cleanValue = parseInt($('#text-'+name+'_text').val()); + if(isNaN(cleanValue)) { + cleanValue = ''; + } + + $('#text-'+name+'_text').val(cleanValue); + + $('#'+name+'_select option:eq(0)').attr('selected', 'selected'); + calculateSeconds(); + }); + + // Function to calculate the custom time in seconds into hidden input + function calculateSeconds() { + var calculated = $('#text-'+name+'_text').val()*$('#'+name+'_units').val(); + $('#hidden-'+name).val(calculated); + } + +} diff --git a/pandora_console/mobile/operation/agents/view_agents.php b/pandora_console/mobile/operation/agents/view_agents.php index bf1afb712f..d1665ca7eb 100644 --- a/pandora_console/mobile/operation/agents/view_agents.php +++ b/pandora_console/mobile/operation/agents/view_agents.php @@ -417,12 +417,7 @@ class viewGraph { echo "
"; echo __("Choose period:"); - $intervals = array (); - $intervals[3600] = human_time_description_raw (3600); // 1 hour - $intervals[86400] = human_time_description_raw (86400); // 1 day - $intervals[604800] = human_time_description_raw (604800); // 1 week - $intervals[2592000] = human_time_description_raw (2592000); // 1 month - echo html_print_extended_select_for_time ($intervals, 'period', $this->period, 'this.form.submit();', '', '0', 5) . __(" secs"); + echo html_print_extended_select_for_time ('period', $this->period, 'this.form.submit();', '', '0', 5); echo "

"; $moduletype_name = modules_get_moduletype_name (modules_get_agentmodule_type ($this->idAgentModule)); diff --git a/pandora_console/operation/agentes/datos_agente.php b/pandora_console/operation/agentes/datos_agente.php index 0451e764b9..d37201803c 100644 --- a/pandora_console/operation/agentes/datos_agente.php +++ b/pandora_console/operation/agentes/datos_agente.php @@ -150,18 +150,12 @@ $header_title = __('Received data from')." ".modules_get_agentmodule_agent_name echo "

".$header_title. "

"; -$intervals = array (); -$intervals[3600] = human_time_description_raw (3600); // 1 hour -$intervals[86400] = human_time_description_raw (86400); // 1 day -$intervals[604800] = human_time_description_raw (604800); // 1 week -$intervals[2592000] = human_time_description_raw (2592000); // 1 month - $formtable->data = array (); echo "
"; $formtable->data[0][0] = html_print_radio_button_extended ("selection_mode", 'fromnow', '', $selection_mode, false, '', 'style="margin-right: 15px;"', true) . __("Choose a time from now"); -$formtable->data[0][1] = html_print_extended_select_for_time ($intervals, 'period', $period, '', '', '0', 10, true) . __(" seconds."); +$formtable->data[0][1] = html_print_extended_select_for_time ('period', $period, '', '', '0', 10, true); $formtable->data[1][0] = html_print_radio_button_extended ("selection_mode", 'range','', $selection_mode, false, '', 'style="margin-right: 15px;"', true) . __("Specify time range"); $formtable->data[1][1] = __('Timestamp from'); diff --git a/pandora_console/operation/agentes/gis_view.php b/pandora_console/operation/agentes/gis_view.php index 82f1c9e96b..d608cc1116 100644 --- a/pandora_console/operation/agentes/gis_view.php +++ b/pandora_console/operation/agentes/gis_view.php @@ -69,19 +69,6 @@ if ($agentData === false) { echo "

" . __("There is no GIS data for this agent, so it's positioned in default position of map.") . "

"; } -$intervals = array (); -$intervals[30] = human_time_description_raw (30); -$intervals[60] = human_time_description_raw (60); -$intervals[300] = human_time_description_raw (300); -$intervals[600] = human_time_description_raw (600); -$intervals[1200] = human_time_description_raw (1200); -$intervals[1800] = human_time_description_raw (1800); -$intervals[3600] = human_time_description_raw (3600); -$intervals[7200] = human_time_description_raw (7200); -$intervals[86400] = human_time_description_raw (86400); -$intervals[172800] = human_time_description_raw (172800); -$intervals[604800] = human_time_description_raw (604800); - echo "
"; $dataLastPosition = gis_get_data_last_position_agent($agentId); if ($dataLastPosition !== false) { @@ -91,8 +78,7 @@ if ($dataLastPosition !== false) { echo "
"; echo ""; echo __("Period to show data as path") . ": "; -html_print_extended_select_for_time ($intervals, 'period', $period, '', '', '0', 10); -echo __(" seconds.") . " "; +html_print_extended_select_for_time ('period', $period, '', '', '0', 10); html_print_submit_button(__('Refresh path'), 'refresh', false, 'class = "sub upd"'); echo "
"; diff --git a/pandora_console/operation/agentes/graphs.php b/pandora_console/operation/agentes/graphs.php index 4c5d3a6313..e523ad6d5a 100644 --- a/pandora_console/operation/agentes/graphs.php +++ b/pandora_console/operation/agentes/graphs.php @@ -85,20 +85,8 @@ $options[4] = 'x4'; $table->data[2][1] = html_print_select ($options, "zoom", $zoom, '', '', 0, true); $table->data[3][0] = __('Time range'); -$options = array (); -$options[3600] = human_time_description_raw (3600); -$options[7200] = human_time_description_raw (7200); -$options[21600] = human_time_description_raw (21600); -$options[43200] = human_time_description_raw (43200); -$options[86400] = human_time_description_raw (86400); -$options[172800] = human_time_description_raw (172800); -$options[432000] = human_time_description_raw (432000); -$options[604800] = human_time_description_raw (604800); -$options[1296000] = human_time_description_raw (1296000); -$options[2592000] = human_time_description_raw (2592000); -$options[5184000] = human_time_description_raw (5184000); -$options[15552000] = human_time_description_raw (15552000); -$table->data[3][1] = html_print_extended_select_for_time($options, 'period', $period, '', '', 0, 7, true) . ' ' . __('secs'); + +$table->data[3][1] = html_print_extended_select_for_time('period', $period, '', '', 0, 7, true); $table->data[4][0] = __('Show events'); $table->data[4][1] = html_print_checkbox ("draw_events", 1, (bool) $draw_events, true); diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index 325de10b84..1f3fffa591 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -239,24 +239,8 @@ html_print_select ($options, "zoom", $zoom); echo ''.__('Time range').''; -$options = array (); -$options[3600] = human_time_description_raw (3600); -$options[7200] = human_time_description_raw (7200); -$options[21600] = human_time_description_raw (21600); -$options[43200] = human_time_description_raw (43200); -$options[86400] = human_time_description_raw (86400); -$options[172800] = human_time_description_raw (172800); -$options[432000] = human_time_description_raw (432000); -$options[604800] = human_time_description_raw (604800); -$options[1296000] = human_time_description_raw (1296000); -$options[2592000] = human_time_description_raw (2592000); -$options[5184000] = human_time_description_raw (5184000); -$options[15552000] = human_time_description_raw (15552000); +html_print_extended_select_for_time('period', $period, '', '', 0, 7); -html_print_extended_select_for_time($options, 'period', $period, '', '', 0, 7); -//html_print_select ($options, "period_select", $period,"javascript: $('#text-period').val($('#period_select').val());"); -//html_print_input_text ("period", $period, '', 10); -echo ' '.__('secs.'); echo ''.__('Show events').''; html_print_checkbox ("draw_events", 1, (bool) $draw_events); diff --git a/pandora_console/operation/reporting/graph_viewer.php b/pandora_console/operation/reporting/graph_viewer.php index ad4942c218..877e73a0a2 100644 --- a/pandora_console/operation/reporting/graph_viewer.php +++ b/pandora_console/operation/reporting/graph_viewer.php @@ -89,7 +89,7 @@ if ($view_graph) { if (! $period) $period = $graph["period"]; else - $period = 3600 * $period; + $period = $period; $events = $graph["events"]; $description = $graph["description"]; $stacked = (int) get_parameter ('stacked', -1); @@ -139,9 +139,8 @@ if ($view_graph) { echo "".__('Period').""; echo ""; echo ""; - - html_print_select (custom_graphs_get_periods (), 'period', intval ($period / 3600), - '', '', 0, false, false, false); + + echo html_print_extended_select_for_time ('period', $period, '', '', '0', 10, true); echo ""; echo "";