2012-03-15 Sergio Martin <sergio.martin@artica.es>

* 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.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5775 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2012-03-15 16:03:51 +00:00
parent 6cde008a82
commit b7fe0fe3dc
16 changed files with 165 additions and 151 deletions

View File

@ -1,3 +1,25 @@
2012-03-15 Sergio Martin <sergio.martin@artica.es>
* 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 <vanessa.gil@artica.es>
* godmode/alerts/alert_actions.php

View File

@ -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',

View File

@ -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',

View File

@ -127,8 +127,6 @@ echo "<td class='datos2'>";
echo "<b>".__('Height')."</b></td>";
echo "<td class='datos2'>";
echo "<input type='text' name='height' value='$height' size=6></td></tr>";
$periods = custom_graphs_get_sec_periods();
$period_label = $periods[$period];
@ -136,8 +134,7 @@ echo "<tr>";
echo "<td class='datos'>";
echo "<b>".__('Period')."</b></td>";
echo "<td class='datos'>";
html_print_extended_select_for_time ($periods, 'period', $period, '', '', '0', 10);
echo __(" seconds.");
html_print_extended_select_for_time ('period', $period, '', '', '0', 10);
echo "</td><td class='datos2'>";
echo "<b>".__('Stacked')."</b></td>";
echo "<td class='datos2'>";

View File

@ -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 "<b>".__('Period')."</b>";
echo "</td>";
echo "<td class='datos'>";
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 "</td>";
echo "<td class='datos'>";

View File

@ -384,8 +384,8 @@ html_print_input_hidden('id_item', $idItem);
</td>
<td style="">
<?php
html_print_extended_select_for_time ($intervals, 'period', $period, '', '', '0', 10);
echo __(" seconds."); ?></td>
html_print_extended_select_for_time ('period', $period, '', '', '0', 10);
?></td>
</tr>
<tr id="row_period1" style="" class="datos">
<td style="vertical-align: top;">
@ -401,8 +401,7 @@ html_print_input_hidden('id_item', $idItem);
</td>
<td style="">
<?php
html_print_extended_select_for_time ($intervals_1, 'period1', $period_pg, '', '', '0', 10);
echo __(" seconds.");
html_print_extended_select_for_time ('period1', $period_pg, '', '', '0', 10);
?>
</td>
</tr>
@ -414,8 +413,7 @@ html_print_input_hidden('id_item', $idItem);
</td>
<td style="">
<?php
html_print_extended_select_for_time ($intervals_1, 'period2', $projection_period, '', '', '0', 10);
echo __(" seconds.");
html_print_extended_select_for_time ('period2', $projection_period, '', '', '0', 10);
?>
</td>
</tr>

View File

@ -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;
}
?>

View File

@ -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;
}
?>

View File

@ -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 "
<script type='text/javascript'>
period_select_events('$name');
</script>
";
$returnString = ob_get_clean();
if ($return)
return $returnString;
else

View File

@ -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);
}
}

View File

@ -417,12 +417,7 @@ class viewGraph {
echo "<form method='post' action='index.php?page=agent&action=view_module_graph&id=" . $this->idAgentModule . "'>";
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 "</form><br />";
$moduletype_name = modules_get_moduletype_name (modules_get_agentmodule_type ($this->idAgentModule));

View File

@ -150,18 +150,12 @@ $header_title = __('Received data from')." ".modules_get_agentmodule_agent_name
echo "<h4>".$header_title. "</h4>";
$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 "<form method='post' action='index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=" . $agentId . "&tab=data_view&id=" . $module_id . "'>";
$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');

View File

@ -69,19 +69,6 @@ if ($agentData === false) {
echo "<p>" . __("There is no GIS data for this agent, so it's positioned in default position of map.") . "</p>";
}
$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 "<br />";
$dataLastPosition = gis_get_data_last_position_agent($agentId);
if ($dataLastPosition !== false) {
@ -91,8 +78,7 @@ if ($dataLastPosition !== false) {
echo "<br />";
echo "<form action='index.php?" . $url . "' method='POST'>";
echo __("Period to show data as path") . ": ";
html_print_extended_select_for_time ($intervals, 'period', $period, '', '', '0', 10);
echo __(" seconds.") . "&nbsp;";
html_print_extended_select_for_time ('period', $period, '', '', '0', 10);
html_print_submit_button(__('Refresh path'), 'refresh', false, 'class = "sub upd"');
echo "</form>";

View File

@ -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);

View File

@ -239,24 +239,8 @@ html_print_select ($options, "zoom", $zoom);
echo '</td></tr><tr><td>'.__('Time range').'</td><td>';
$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 '</td></tr><tr><td>'.__('Show events').'</td><td>';
html_print_checkbox ("draw_events", 1, (bool) $draw_events);

View File

@ -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 "<b>".__('Period')."</b>";
echo "</td>";
echo "<td class='datos'>";
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 "</td>";
echo "<td class='datos'>";