2009-05-19 Evi Vanoost <vanooste@rcbi.rochester.edu>
* include/functions_incidents.php: Removed upgrade_inc13to21. An old function that shouldn't be there anymore. * include/functions_agents.php: Fixed documentation. Fixed some bugs in get_agents () when empty values were passed. * include/functions_ui.php: Added $config['ignore_callback']. Useful if you decide to flush the buffers (eg. to offer a download) * include/functions_db.php: Cleaned up get_db_all_rows_filter and added some documentation and todo's. Added get_agentmodule_data to get all datapoints of a module. Cleaned up get_agentmodule_data_average * include/functions_html.php: Some situations generated a warning when alt wasn't specified (can't add keys on non-arrays) * include/exportdata.php: Rewritten. Added filters for group. Works using functions and export into HTML, CSV and Excel with the option for expansion (specify the delimiter values) git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1697 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
c97174e590
commit
50079425c2
|
@ -1,3 +1,25 @@
|
|||
2009-05-19 Evi Vanoost <vanooste@rcbi.rochester.edu>
|
||||
|
||||
* include/functions_incidents.php: Removed upgrade_inc13to21. An old
|
||||
function that shouldn't be there anymore.
|
||||
|
||||
* include/functions_agents.php: Fixed documentation. Fixed some bugs in
|
||||
get_agents () when empty values were passed.
|
||||
|
||||
* include/functions_ui.php: Added $config['ignore_callback']. Useful if
|
||||
you decide to flush the buffers (eg. to offer a download)
|
||||
|
||||
* include/functions_db.php: Cleaned up get_db_all_rows_filter and added
|
||||
some documentation and todo's. Added get_agentmodule_data to get all
|
||||
datapoints of a module. Cleaned up get_agentmodule_data_average
|
||||
|
||||
* include/functions_html.php: Some situations generated a warning when alt
|
||||
wasn't specified (can't add keys on non-arrays)
|
||||
|
||||
* include/exportdata.php: Rewritten. Added filters for group. Works using
|
||||
functions and export into HTML, CSV and Excel with the option for
|
||||
expansion (specify the delimiter values)
|
||||
|
||||
2009-05-19 Esteban Sanchez <estebans@artica.es>
|
||||
|
||||
* godmode/agentes/massive_delete_alerts.php: Fixed an error when selecting
|
||||
|
|
|
@ -192,29 +192,49 @@ function get_agent_alerts_compound ($id_agent, $filter = '', $options = false) {
|
|||
* @param array Fields to get.
|
||||
* @param string Access needed in the agents groups.
|
||||
*
|
||||
* @return array An array with all alerts defined for an agent.
|
||||
* @return mixed An array with all alerts defined for an agent or false in case no allowed groups are specified.
|
||||
*/
|
||||
function get_agents ($filter = false, $fields = false, $access = 'AR') {
|
||||
if (! is_array ($filter))
|
||||
if (! is_array ($filter)) {
|
||||
$filter = array ();
|
||||
}
|
||||
|
||||
if (! isset ($filter['id_grupo'])) {
|
||||
$filter['id_grupo'] = array_keys (get_user_groups (false, $access));
|
||||
//Get user groups
|
||||
$groups = array_keys (get_user_groups (false, $access));
|
||||
|
||||
//If no group specified, get all user groups
|
||||
if (empty ($filter['id_grupo'])) {
|
||||
$filter['id_grupo'] = $groups;
|
||||
} elseif (! is_array ($filter['id_grupo'])) {
|
||||
//If group is specified but not allowed, return false
|
||||
if (! in_array ($filter['id_grupo'], $groups)) {
|
||||
return false;
|
||||
}
|
||||
$filter['id_grupo'] = (array) $filter['id_grupo']; //Make an array
|
||||
} else {
|
||||
if (! is_array ($filter['id_grupo'])) {
|
||||
if (! in_array ($filter['id_grupo'], array_keys (get_user_groups (false, $access))))
|
||||
return false;
|
||||
} else {
|
||||
$user_groups = get_user_groups (false, $access);
|
||||
foreach ($filter['id_grupo'] as $i => $id_group)
|
||||
if (! isset ($user_groups[$id_group]))
|
||||
unset ($filter['id_grupo'][$i]);
|
||||
if (count ($filter['id_grupo']) == 0)
|
||||
$filter['id_grupo'] = $user_groups;
|
||||
//Check each group specified to the user groups, remove unwanted groups
|
||||
foreach ($filter['id_grupo'] as $key => $id_group) {
|
||||
if (! in_array ($id_group, $groups)) {
|
||||
unset ($filter['id_grupo'][$key]);
|
||||
}
|
||||
}
|
||||
//If no allowed groups are specified return false
|
||||
if (count ($filter['id_grupo']) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return @get_db_all_rows_filter ('tagente', $filter, $fields);
|
||||
if (in_array (1, $filter['id_grupo'])) {
|
||||
unset ($filter['id_grupo']);
|
||||
}
|
||||
|
||||
if (!is_array ($fields)) {
|
||||
$fields = array ();
|
||||
$fields[0] = "id_agente";
|
||||
$fields[1] = "nombre";
|
||||
}
|
||||
|
||||
return get_db_all_rows_filter ('tagente', $filter, $fields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1704,24 +1704,25 @@ get_db_all_rows_filter ('table', 'disabled = 0 OR history_data = 0', 'name');
|
|||
* @return mixed Array of the row or false in case of error.
|
||||
*/
|
||||
function get_db_all_rows_filter ($table, $filter, $fields = false, $where_join = 'AND') {
|
||||
//TODO: Validate and clean fields
|
||||
if (empty ($fields)) {
|
||||
$fields = '*';
|
||||
} else {
|
||||
if (is_array ($fields))
|
||||
$fields = implode (',', $fields);
|
||||
else if (! is_string ($fields))
|
||||
return false;
|
||||
} elseif (is_array ($fields)) {
|
||||
$fields = implode (',', $fields);
|
||||
} elseif (! is_string ($fields)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_array ($filter))
|
||||
//TODO: Validate and clean filter options
|
||||
if (is_array ($filter)) {
|
||||
$filter = format_array_to_where_clause_sql ($filter, $where_join, ' WHERE ');
|
||||
else if (is_string ($filter))
|
||||
} elseif (is_string ($filter)) {
|
||||
$filter = 'WHERE '.$filter;
|
||||
else
|
||||
} else {
|
||||
$filter = '';
|
||||
}
|
||||
|
||||
$sql = sprintf ('SELECT %s FROM %s %s',
|
||||
$fields, $table, $filter);
|
||||
$sql = sprintf ('SELECT %s FROM %s %s', $fields, $table, $filter);
|
||||
|
||||
return get_db_all_rows_sql ($sql);
|
||||
}
|
||||
|
@ -2197,6 +2198,45 @@ function get_previous_data ($id_agent_module, $utimestamp = 0) {
|
|||
return get_db_row_sql ($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the values of an agent module in a period of time.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* @return array The module value and the timestamp
|
||||
*/
|
||||
function get_agentmodule_data ($id_agent_module, $period, $date = 0) {
|
||||
if ($date < 1) {
|
||||
$date = get_system_time ();
|
||||
}
|
||||
|
||||
$datelimit = $date - $period;
|
||||
|
||||
$sql = sprintf ("SELECT datos AS data, utimestamp FROM tagente_datos WHERE id_agente_modulo = %d
|
||||
AND utimestamp > %d AND utimestamp <= %d ORDER BY utimestamp ASC",
|
||||
$id_agent_module, $datelimit, $date);
|
||||
|
||||
$values = get_db_all_rows_sql ($sql);
|
||||
|
||||
if ($values === false) {
|
||||
return array ();
|
||||
}
|
||||
|
||||
$module_name = get_agentmodule_name ($id_agent_module);
|
||||
$agent_id = get_agentmodule_agent ($id_agent_module);
|
||||
$agent_name = get_agentmodule_agent_name ($id_agent_module);
|
||||
|
||||
foreach ($values as $key => $data) {
|
||||
$values[$key]["module_name"] = $module_name;
|
||||
$values[$key]["agent_id"] = $agent_id;
|
||||
$values[$key]["agent_name"] = $agent_name;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the average value of an agent module in a period of time.
|
||||
*
|
||||
|
@ -2204,11 +2244,13 @@ function get_previous_data ($id_agent_module, $utimestamp = 0) {
|
|||
* @param int Period of time to check (in seconds)
|
||||
* @param int Top date to check the values. Default current time.
|
||||
*
|
||||
* @return int The average module value in the interval.
|
||||
* @return float The average module value in the interval.
|
||||
*/
|
||||
function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
|
||||
if (! $date)
|
||||
if ($date < 1) {
|
||||
$date = get_system_time ();
|
||||
}
|
||||
|
||||
$datelimit = $date - $period;
|
||||
|
||||
$sql = sprintf ("SELECT SUM(datos), COUNT(*) FROM tagente_datos
|
||||
|
@ -2216,16 +2258,21 @@ function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
|
|||
AND utimestamp > %d AND utimestamp <= %d
|
||||
ORDER BY utimestamp ASC",
|
||||
$id_agent_module, $datelimit, $date);
|
||||
|
||||
$values = get_db_row_sql ($sql);
|
||||
|
||||
$sum = (float) $values[0];
|
||||
$total = (int) $values[1];
|
||||
|
||||
/* Get also the previous data before the selected interval. */
|
||||
$previous_data = get_previous_data ($id_agent_module, $datelimit);
|
||||
if ($previous_data)
|
||||
|
||||
if ($previous_data) {
|
||||
return ($previous_data['datos'] + $sum) / ($total + 1);
|
||||
if ($total > 0)
|
||||
} elseif ($total > 0) {
|
||||
return $sum / $total;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2291,7 +2338,7 @@ function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) {
|
|||
* @param int Period of time to check (in seconds)
|
||||
* @param int Top date to check the values. Default current time.
|
||||
*
|
||||
* @return int The sumatory of the module values in the interval.
|
||||
* @return float The sumatory of the module values in the interval.
|
||||
*/
|
||||
function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) {
|
||||
if (! $date)
|
||||
|
|
|
@ -804,12 +804,14 @@ function print_image ($src, $return = false, $options = false) {
|
|||
$output .= $attribute.'="'.safe_input ($options[$attribute]).'" ';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$options = array ();
|
||||
}
|
||||
|
||||
if (!isset ($options["alt"]) && isset ($options["title"])) {
|
||||
$options["alt"] = $options["title"]; //Set alt to title if it's not set
|
||||
} elseif (!isset ($options["alt"])) {
|
||||
$options["alt"] = ''; //Alt is mandatory, empty string will do
|
||||
$options["alt"] = "";
|
||||
}
|
||||
|
||||
if (!empty ($style)) {
|
||||
|
|
|
@ -403,35 +403,4 @@ function get_incidents_attach ($id_incident) {
|
|||
function get_incidents_notes_author ($id_note) {
|
||||
return (string) get_db_value ('id_usuario', 'tnota', 'id_nota', (int) $id_note);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ignore This function should never be used
|
||||
*/
|
||||
function upgrade_inc13to21 () {
|
||||
$sql = "ALTER TABLE `tincidencia` CHANGE `id_incidencia` `id_incidencia` BIGINT( 6 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT";
|
||||
process_sql ($sql);
|
||||
$sql = "ALTER TABLE `tincidencia` ADD `id_lastupdate` VARCHAR( 60 ) NULL AFTER `id_creator` ;";
|
||||
process_sql ($sql);
|
||||
$sql = "ALTER TABLE `tincidencia` CHANGE `actualizacion` `actualizacion` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
|
||||
process_sql ($sql);
|
||||
$sql = "ALTER TABLE `tnota` ADD `id_incident` BIGINT( 6 ) UNSIGNED ZEROFILL NOT NULL AFTER `id_nota` ;";
|
||||
process_sql ($sql);
|
||||
$sql = "ALTER TABLE `tincidencia` ADD `id_agente_modulo` BIGINT( 100 ) NOT NULL AFTER `id_lastupdate` ;";
|
||||
process_sql ($sql);
|
||||
$sql = "ALTER TABLE `tincidencia` ADD INDEX ( `id_agente_modulo` ) ;";
|
||||
process_sql ($sql);
|
||||
|
||||
$sql = "UPDATE tnota, tnota_inc SET tnota.id_incident = tnota_inc.id_incidencia WHERE tnota.id_nota = tnota_inc.id_nota";
|
||||
$result = process_sql ($sql);
|
||||
if ($result !== false) {
|
||||
$sql = "DROP TABLE `tnota_inc`";
|
||||
process_sql ($sql);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = 'show tables like "tnota_inc"';
|
||||
$result = get_db_sql ($sql);
|
||||
if (!empty ($result)) {
|
||||
upgrade_inc13to21 ();
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -574,6 +574,11 @@ function require_jquery_file ($name, $path = 'include/javascript/') {
|
|||
*/
|
||||
function process_page_head ($string, $bitfield) {
|
||||
global $config;
|
||||
|
||||
if (isset ($config['ignore_callback']) && $config['ignore_callback'] == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
|
||||
if ($config["refr"] > 0) {
|
||||
|
@ -713,6 +718,10 @@ function process_page_head ($string, $bitfield) {
|
|||
function process_page_body ($string, $bitfield) {
|
||||
global $config;
|
||||
|
||||
if (isset ($config['ignore_callback']) && $config['ignore_callback'] == true) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show custom background
|
||||
if ($config["pure"] == 0) {
|
||||
$output = '<body style="background-color:#555555;">';
|
||||
|
|
|
@ -21,312 +21,226 @@
|
|||
|
||||
// Load global vars
|
||||
require_once ("include/config.php");
|
||||
require_once ("include/functions_agents.php");
|
||||
|
||||
check_login();
|
||||
|
||||
if (! give_acl ($config['id_user'], 0, "AR") && ! give_acl ($config['id_user'], 0, "AW")) {
|
||||
if (!give_acl ($config['id_user'], 0, "AR")) {
|
||||
require ("general/noaccess.php");
|
||||
return;
|
||||
}
|
||||
|
||||
function give_average_from_module ($id_agente, $id_agente_modulo, $hour, $day, $start_date, $end_date){
|
||||
// Return average value from an agentmodule, for a specific hour of specific day of week,
|
||||
// Only valid for non-string kind of data.
|
||||
global $config;
|
||||
require_javascript_file ('calendar');
|
||||
|
||||
echo "<h2>".__('Pandora Agents')." » ".__('Export data')."</h2>";
|
||||
|
||||
$group = get_parameter_post ('group', 1);
|
||||
$agent = get_parameter_post ('agent', 0);
|
||||
$module = (array) get_parameter_post ('module_arr', array ());
|
||||
$start_date = get_parameter_post ('start_date', 0);
|
||||
$end_date = get_parameter_post ('end_date', 0);
|
||||
$start_time = get_parameter_post ('start_time', 0);
|
||||
$end_time = get_parameter_post ('end_time', 0);
|
||||
$export_type = get_parameter_post ('export_type', 'data');
|
||||
$export_btn = get_parameter_post ('export_btn', 0);
|
||||
|
||||
if (!empty ($export_btn) && !empty ($module)) {
|
||||
//Convert start time and end time to unix timestamps
|
||||
$start = strtotime ($start_date." ".$start_time);
|
||||
$end = strtotime ($end_date." ".$end_time);
|
||||
$period = $end - $start;
|
||||
$data = array ();
|
||||
|
||||
// Convert to unix date
|
||||
$start_date = date("U", $start_date);
|
||||
$end_date = date("U", $end_date);
|
||||
|
||||
$query1 = "SELECT AVG(datos)
|
||||
FROM tagente_datos
|
||||
WHERE id_agente_modulo = ". $id_agente_modulo."
|
||||
AND HOUR(utimestamp) = ".$hour."
|
||||
AND WEEKDAY(utimestamp) = ".$day."
|
||||
AND utimestamp >= $start_date
|
||||
AND utimestamp <= $end_date";
|
||||
|
||||
if (($resq1 = mysql_query($query1)) AND ($row=mysql_fetch_array($resq1)))
|
||||
return $row[0];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
function generate_average_table ($id_de_mi_agente, $id_agente_modulo, $fecha_inicio, $fecha_fin){
|
||||
// Genera una tabla con los promedios de los datos de un módulo no-string
|
||||
global $config;
|
||||
|
||||
$dias_de_la_semana = array (__('Sunday'),__('Monday'), __('Tuesday'), __('Wednesday'), __('Thurdsday'), __('Friday'), __('Saturday'));
|
||||
$nombre_modulo = get_agentmodule_name ($id_agente_modulo);
|
||||
|
||||
// Table header
|
||||
echo "<table border=0 cellpadding=4 cellspacing=4 width='90%' class='databox'>";
|
||||
echo "<tr>
|
||||
<th style='width: 5%' rowspan='2'></th>";
|
||||
echo "<th colspan='7'>".__('day')."</th>
|
||||
</tr>";
|
||||
echo "<tr>";
|
||||
for ($dia=0;$dia<7;++$dia)
|
||||
echo "<th style='width: 14%'>".$dias_de_la_semana[$dia]."</th>";
|
||||
echo "</tr>";
|
||||
$color = 0;
|
||||
for ($hora=0;$hora<24;++$hora){
|
||||
if ($color == 1){
|
||||
$tdcolor = "datos";
|
||||
$color = 0;
|
||||
} else {
|
||||
$tdcolor = "datos2";
|
||||
$color = 1;
|
||||
}
|
||||
echo "<tr><th class='datos3'> $hora ".__('Hr')."</th>";
|
||||
for ($dia=0; $dia<7; ++$dia){
|
||||
echo "<td class='$tdcolor'>";
|
||||
echo format_numeric (give_average_from_module ($id_de_mi_agente, $id_agente_modulo, $hora, $dia, $fecha_inicio, $fecha_fin));
|
||||
echo "</td>";
|
||||
}
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>";
|
||||
}
|
||||
|
||||
|
||||
if ((isset($_POST["export"])) AND (! isset($_POST["update_agent"]))){
|
||||
|
||||
if (isset($_POST["export_type"]))
|
||||
$export_type = $_POST["export_type"];
|
||||
else
|
||||
$export_type = 3; // Standard table;
|
||||
|
||||
// Header
|
||||
echo "<h2>".__('Pandora Agents')." » ";
|
||||
echo __('Database export results')."</h2>";
|
||||
|
||||
if ($export_type == 1) { // CSV
|
||||
|
||||
if (isset ($_POST["origen_modulo"])){
|
||||
$origen = $_POST["origen"];
|
||||
if (! give_acl ($config['id_user'], dame_id_grupo ($origen), "AR")) {
|
||||
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
|
||||
"Trying to access Agent Export Data");
|
||||
require ("general/noaccess.php");
|
||||
}
|
||||
$origen_modulo = $_POST["origen_modulo"];
|
||||
$id_agentemodulo = $origen_modulo[0];
|
||||
$start_date =$_POST["start_date"];
|
||||
$end_date=$_POST["end_date"];
|
||||
$start_time =$_POST["start_time"];
|
||||
$end_time=$_POST["end_time"];
|
||||
$from_date = $start_date." ".$start_time;
|
||||
$to_date = $end_date." ".$end_time;
|
||||
|
||||
$agentmodule_name = get_agentmodule_name ($origen_modulo[0]);
|
||||
echo __('Data from agent '). "<b>" . get_agent_name($origen). "- $agentmodule_name</b> ". __('from'). " <b>". $from_date. "</b> ". __('to'). " <b>". $to_date. "</b><br>";
|
||||
|
||||
echo "<a href='operation/agentes/export_csv.php?from_date=$from_date&to_date=$to_date&agent=$origen&agentmodule=$id_agentemodulo'><img src='images/disk.png'> ".__('Download file')."</a> pandora_export_$agentmodule_name.txt";
|
||||
} else
|
||||
echo "<b class='error'>".__('No module has been selected')."</b>";
|
||||
}
|
||||
|
||||
if ($export_type == 2){ // Avarage day/hour matrix
|
||||
if (isset ($_POST["origen_modulo"])){
|
||||
$origen = $_POST["origen"];
|
||||
$origen_modulo = $_POST["origen_modulo"];
|
||||
$start_date =$_POST["start_date"];
|
||||
$end_date=$_POST["end_date"];
|
||||
$start_time =$_POST["start_time"];
|
||||
$end_time=$_POST["end_time"];
|
||||
|
||||
$agentmodule_name = get_agentmodule_name ($origen_modulo[0]);
|
||||
$from_date = $start_date." ".$start_time;
|
||||
$to_date = $end_date." ".$end_time;
|
||||
|
||||
echo __('Data from agent '). "<b>" . get_agent_name ($origen). "- $agentmodule_name</b> ". __('from'). " <b>". $from_date. "</b> ". __('to'). " <b>". $to_date. "</b><br>";
|
||||
echo "<br>";
|
||||
|
||||
$from_date = date("U", strtotime($from_date));
|
||||
$to_date = date("U", strtotime($to_date));
|
||||
|
||||
// For each module
|
||||
for ($a=0;$a <count($origen_modulo); $a++){
|
||||
$id_modulo = $origen_modulo[$a];
|
||||
$tipo = get_moduletype_name (get_agentmodule_type ($id_modulo));
|
||||
|
||||
if ($tipo != "generic_data_string")
|
||||
echo "<br>". generate_average_table ($origen,$id_modulo,$from_date,$to_date);
|
||||
}
|
||||
}
|
||||
//If time is negative or zero, don't process - it's invalid
|
||||
if ($start < 1 || $end < 1) {
|
||||
print_error_message (__('Invalid time specified'));
|
||||
return;
|
||||
}
|
||||
|
||||
if ($export_type == 3) { // Standard table
|
||||
if (isset ($_POST["origen_modulo"])){
|
||||
$origen = $_POST["origen"];
|
||||
if (! give_acl ($config['id_user'], dame_id_grupo ($origen), "AR")) {
|
||||
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
|
||||
"Trying to access Agent Export Data");
|
||||
require ("general/noaccess.php");
|
||||
}
|
||||
$origen_modulo = $_POST["origen_modulo"];
|
||||
$agentmodule_name = get_agentmodule_name ($origen_modulo[0]);
|
||||
$start_date =$_POST["start_date"];
|
||||
$end_date=$_POST["end_date"];
|
||||
$start_time =$_POST["start_time"];
|
||||
$end_time=$_POST["end_time"];
|
||||
|
||||
$from_date = $start_date." ".$start_time;
|
||||
$to_date = $end_date." ".$end_time;
|
||||
|
||||
echo __('Data from agent '). "<b>" . get_agent_name($origen). "- $agentmodule_name</b>". __(' from '). "<b>". $from_date. "</b>". __(' to '). "<b>". $to_date. "</b><br>";
|
||||
|
||||
echo "<br><table cellpadding='4' cellspacing='4' width='600' class='databox'>";
|
||||
echo "<tr>
|
||||
<th class='datos'>".__('Module')."</th>
|
||||
<th class='datos'>".__('Data')."</th>
|
||||
<th class='datos'>Timestamp</th>";
|
||||
|
||||
// Convert to unix date
|
||||
$from_date = date("U", strtotime($from_date));
|
||||
$to_date = date("U", strtotime($to_date));
|
||||
|
||||
// Begin the render !
|
||||
for ($a=0; $a <count($origen_modulo); $a++){ // For each module (not used multiple modules yet!)
|
||||
$id_modulo = $origen_modulo[$a];
|
||||
$tipo = get_moduletype_name (get_agentmodule_type ($id_modulo));
|
||||
if ($tipo == "generic_data_string")
|
||||
$sql1 = 'SELECT * FROM tagente_datos_string WHERE utimestamp > '.$from_date.' AND utimestamp < '.$to_date.' AND id_agente_modulo ='.$id_modulo.' ORDER BY utimestamp DESC';
|
||||
else
|
||||
$sql1 = 'SELECT * FROM tagente_datos WHERE utimestamp > '.$from_date.' AND utimestamp < '.$to_date.' AND id_agente_modulo ='.$id_modulo.' ORDER BY utimestamp DESC';
|
||||
$result1 = get_db_all_rows_sql ($sql1);
|
||||
if ($result1 === false)
|
||||
$result1 = array ();
|
||||
$color=1;
|
||||
foreach ($result1 as $row){
|
||||
if ($color == 1){
|
||||
$tdcolor = "datos";
|
||||
$color = 0;
|
||||
} else {
|
||||
$tdcolor = "datos2";
|
||||
$color = 1;
|
||||
}
|
||||
echo "<tr><td class='$tdcolor'>";
|
||||
echo $agentmodule_name;
|
||||
echo "</td><td class='$tdcolor'>";
|
||||
echo $row["datos"];
|
||||
echo "</td><td class='$tdcolor'>";
|
||||
echo $row["utimestamp"];
|
||||
echo "</td></tr>";
|
||||
// Data
|
||||
$data = array ();
|
||||
switch ($export_type) {
|
||||
case "data":
|
||||
case "excel":
|
||||
case "csv":
|
||||
foreach ($module as $selected) {
|
||||
$data_single = get_agentmodule_data ($selected, $period, $start);
|
||||
|
||||
if (!empty ($data_single)) {
|
||||
$data = array_merge ($data, $data_single);
|
||||
}
|
||||
}
|
||||
echo "</table>";
|
||||
} else
|
||||
echo "<b class='error'>".__('No module has been selected')."</b>";
|
||||
|
||||
break;
|
||||
case "avg":
|
||||
foreach ($module as $selected) {
|
||||
$arr = array ();
|
||||
$arr["data"] = get_agentmodule_data_average ($selected, $period, $start);
|
||||
if ($arr["data"] === false) {
|
||||
continue;
|
||||
}
|
||||
$arr["module_name"] = get_agentmodule_name ($selected);
|
||||
$arr["agent_name"] = get_agentmodule_agent_name ($selected);
|
||||
$arr["agent_id"] = get_agentmodule_agent ($selected);
|
||||
$arr["utimestamp"] = $end;
|
||||
array_push ($data, $arr);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
print_error_message (__('Invalid method supplied'));
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
// Starts, ends and dividers
|
||||
switch ($export_type) {
|
||||
case "data":
|
||||
case "avg":
|
||||
default:
|
||||
//HTML output - don't style or use XHTML just in case somebody needs to copy/paste it. (Office doesn't handle <thead> and <tbody>)
|
||||
$datastart = '<table style="width:700px;"><tr><td>'.__('Agent').'</td><td>'.__('Module').'</td><td>'.__('Data').'</td><td>'.__('Timestamp').'</td></tr>';
|
||||
$rowstart = '<tr><td>';
|
||||
$divider = '</td><td>';
|
||||
$rowend = '</td></tr>';
|
||||
$dataend = '</table>';
|
||||
break;
|
||||
case "excel":
|
||||
//Excel is tab-delimited, needs quotes and needs Windows-style newlines
|
||||
$datastart = __('Agent')."\t".__('Module')."\t".__('Data')."\t".__('Timestamp')."\r\n";
|
||||
$rowstart = '"';
|
||||
$divider = '"'."\t".'"';
|
||||
$rowend = '"'."\r\n";
|
||||
$dataend = "\r\n";
|
||||
$extension = "xls";
|
||||
break;
|
||||
case "csv":
|
||||
//Pure CSV is comma delimited
|
||||
$datastart = __('Agent').','.__('Module').','.__('Data').','.__('Timestamp')."\n";
|
||||
$rowstart = '"';
|
||||
$divider = '","';
|
||||
$rowend = '"'."\n";
|
||||
$dataend = "\n";
|
||||
$extension = "csv";
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
// Option B: Print Form
|
||||
// Form view
|
||||
$ahora=date("Y/m/d H:i:s");
|
||||
$ahora_s = date("U");
|
||||
$ayer = date ("Y/m/d H:i:s", $ahora_s - 86400);
|
||||
if (isset($_GET["date_from"]))
|
||||
$date_from=$_GET["date_from"];
|
||||
else
|
||||
if (isset($_POST["from_date"]))
|
||||
$date_from = $_POST["from_date"];
|
||||
else
|
||||
$date_from = $ayer;
|
||||
|
||||
if (isset($_GET["date_to"]))
|
||||
$date_to = $_GET["date_to"];
|
||||
else
|
||||
if (isset($_POST["to_date"]))
|
||||
$date_to = $_POST["to_date"];
|
||||
else
|
||||
$date_to = $ahora;
|
||||
|
||||
$config['js'][] = 'calendar';
|
||||
|
||||
echo "<h2>".__('Pandora Agents')." » ";
|
||||
echo __('Export data')."</h2>";
|
||||
|
||||
echo '<form method="post" action="index.php?sec=estado&sec2=operation/agentes/exportdata" name="export_form">';
|
||||
echo '<table width=550 border=0 cellspacing=3 cellpadding=5 class=databox_color>';
|
||||
echo '<tr>';
|
||||
echo "<td class='datos'><b>".__('Source agent')."</b></td>";
|
||||
echo "<td class='datos'>";
|
||||
|
||||
|
||||
// Show combo with agents
|
||||
echo '<select name="origen" class="w130">';
|
||||
if ( (isset($_POST["update_agent"])) AND (isset($_POST["origen"])) ) {
|
||||
echo "<option value=".$_POST["origen"].">".get_agent_name($_POST["origen"])."</option>";
|
||||
$output = $datastart;
|
||||
foreach ($data as $key => $module) {
|
||||
$output .= $rowstart;
|
||||
$output .= $module['agent_name'];
|
||||
$output .= $divider;
|
||||
$output .= $module['module_name'];
|
||||
$output .= $divider;
|
||||
$output .= $module['data'];
|
||||
$output .= $divider;
|
||||
$output .= date ($config["date_format"], $module['utimestamp']);
|
||||
$output .= $rowend;
|
||||
}
|
||||
$sql1='SELECT * FROM tagente';
|
||||
$result=mysql_query($sql1);
|
||||
while ($row=mysql_fetch_array($result)){
|
||||
if ( (isset($_POST["update_agent"])) AND (isset($_POST["origen"])) ){
|
||||
if (give_acl($config['id_user'], $row["id_grupo"], "AR"))
|
||||
if ( $_POST["origen"] != $row["id_agente"])
|
||||
echo "<option value=".$row["id_agente"].">".$row["nombre"]."</option>";
|
||||
} else {
|
||||
if (give_acl($config['id_user'], $row["id_grupo"], "AR"))
|
||||
echo "<option value=".$row["id_agente"].">".$row["nombre"]."</option>";
|
||||
}
|
||||
$output .= $dataend;
|
||||
|
||||
switch ($export_type) {
|
||||
default:
|
||||
case "data":
|
||||
case "avg":
|
||||
echo $output;
|
||||
return;
|
||||
break;
|
||||
case "excel":
|
||||
case "csv":
|
||||
//Encase into a file and offer download
|
||||
//Flush buffers - we don't need them.
|
||||
$config['ignore_callback'] = true;
|
||||
while (@ob_end_clean ());
|
||||
header("Content-type: application/octet-stream");
|
||||
header("Content-Disposition: attachment; filename=export_".date("Ymd", $start)."_".date("Ymd", $end).".".$extension);
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
echo $output;
|
||||
exit;
|
||||
//Exit necessary so it doesn't continue processing and give erroneous downloads
|
||||
break;
|
||||
}
|
||||
echo "</select> ";
|
||||
echo "<input type=submit name='update_agent' class='sub upd' value='".__('Get Info')."'>";
|
||||
|
||||
|
||||
echo '<tr>';
|
||||
echo "<td class='datos2'>";
|
||||
echo "<b>".__('Modules')."</b>";
|
||||
echo "<td class='datos2'>";
|
||||
|
||||
// Combo with modules
|
||||
echo "<select name='origen_modulo[]' size=8 class='w130'>";
|
||||
if ((isset($_POST["update_agent"])) && (isset($_POST["origen"])) ) {
|
||||
// Populate Module/Agent combo
|
||||
$agente_modulo = $_POST["origen"];
|
||||
$sql = "SELECT * FROM tagente_modulo WHERE id_agente = ".$agente_modulo;
|
||||
$result = mysql_query ($sql);
|
||||
while ($row=mysql_fetch_array($result)) {
|
||||
echo "<option value=".$row["id_agente_modulo"].">".$row["nombre"];
|
||||
}
|
||||
} else {
|
||||
echo "<option value=-1>".__('N/A')."</option>";
|
||||
}
|
||||
echo "</select>";
|
||||
|
||||
echo "<tr><td class='datos'>";
|
||||
echo "<b>".__('Begin date (*)')."</b>";
|
||||
echo "<td class='datos'>";
|
||||
echo "<input type='text' id='start_date' name='start_date' size=10 value='".substr ($date_from, 0, 10)."'> <img src='images/calendar_view_day.png' onclick='scwShow(scwID(\"start_date\"),this);'> ";
|
||||
echo "<input type='text' name='start_time' size=10 value='".substr ($date_from, 11, 8)."'>";
|
||||
|
||||
|
||||
echo "<tr><td class='datos2'>";
|
||||
echo "<b>".__('End date (*)')."</b>";
|
||||
|
||||
echo "<td class='datos2'>";
|
||||
echo "<input type='text' id='end_date' name='end_date' size=10 value='".substr ($date_to, 0, 10)."'> <img src='images/calendar_view_day.png' onclick='scwShow(scwID(\"end_date\"),this);'> ";
|
||||
echo "<input type='text' name='end_time' size=10 value='".substr ($date_to, 11, 8)."'>";
|
||||
|
||||
echo "<tr><td class='datos'>";
|
||||
echo "<b>".__('Export type')."</b>";
|
||||
echo "<td class='datos'>";
|
||||
// Combo for data export type
|
||||
echo "<select name='export_type'>";
|
||||
echo "<option value=3>".__('Data table')."</option>";
|
||||
echo "<option value=1>".__('Standalone CSV ascii file')."</option>";
|
||||
echo "<option value=2>".__('Average per hour/day')."</option>";
|
||||
echo "</select>";
|
||||
echo "</table>";
|
||||
|
||||
// Submit button
|
||||
echo '<div class="action-buttons" style="width: 550">';
|
||||
print_submit_button (__('Export'), 'export', false, 'class="sub wand"');
|
||||
echo "</div>";
|
||||
echo "</form>";
|
||||
} elseif (!empty ($export_btn) && empty ($module)) {
|
||||
print_error_message (__('No modules specified'));
|
||||
}
|
||||
|
||||
?>
|
||||
echo '<form method="post" action="index.php?sec=estado&sec2=operation/agentes/exportdata" name="export_form">';
|
||||
|
||||
$table->width = 550;
|
||||
$table->border = 0;
|
||||
$table->cellspacing = 3;
|
||||
$table->cellpadding = 5;
|
||||
$table->class = "databox_color";
|
||||
|
||||
$table->data = array ();
|
||||
|
||||
//Group selector
|
||||
$table->data[0][0] = '<b>'.__('Group').'</b>';
|
||||
|
||||
$groups = get_user_groups ($config['id_user'], "AR");
|
||||
|
||||
$table->data[0][1] = print_select ($groups, "group", $group, 'this.form.submit();', '', 0, true, false, true, 'w130', false);
|
||||
|
||||
//Agent selector
|
||||
$table->data[1][0] = '<b>'.__('Source agent').'</b>';
|
||||
|
||||
if ($group > 0) {
|
||||
$filter['id_grupo'] = (array) $group;
|
||||
} else {
|
||||
$filter['id_grupo'] = array_keys ($groups);
|
||||
}
|
||||
|
||||
$agents = array ();
|
||||
$rows = get_agents ($filter, false, 'AR');
|
||||
foreach ($rows as $row) {
|
||||
$agents[$row['id_agente']] = $row['nombre'];
|
||||
}
|
||||
|
||||
if (!in_array ($agent, array_keys ($agents))) {
|
||||
$agent = current (array_keys ($agents));
|
||||
}
|
||||
|
||||
$table->data[1][1] = print_select ($agents, "agent", $agent, 'this.form.submit();', '', 0, true, false, true, 'w130', false);
|
||||
|
||||
//Module selector
|
||||
$table->data[2][0] = '<b>'.__('Modules').'</b>';
|
||||
|
||||
if ($agent > 0) {
|
||||
$modules = get_agent_modules ($agent);
|
||||
} else {
|
||||
$modules = array ();
|
||||
}
|
||||
|
||||
$table->data[2][1] = print_select ($modules, "module_arr[]", array_keys ($modules), '', '', 0, true, true, true, 'w130', false);
|
||||
|
||||
//Start date selector
|
||||
$table->data[3][0] = '<b>'.__('Begin date (*)').'</b>';
|
||||
|
||||
$table->data[3][1] = print_input_text ('start_date', date ("Y-m-d", get_system_time () - 86400), false, 10, 10, true);
|
||||
$table->data[3][1] .= print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => 'scwShow(scwID("text-start_date"),this);'));
|
||||
$table->data[3][1] .= print_input_text ('start_time', date ("H:m", get_system_time () - 86400), false, 10, 5, true);
|
||||
|
||||
//End date selector
|
||||
$table->data[4][0] = '<b>'.__('End date (*)').'</b>';
|
||||
$table->data[4][1] = print_input_text ('end_date', date ("Y-m-d", get_system_time ()), false, 10, 10, true);
|
||||
$table->data[4][1] .= print_image ("images/calendar_view_day.png", true, array ("alt" => "calendar", "onclick" => 'scwShow(scwID("text-end_date"),this);'));
|
||||
$table->data[4][1] .= print_input_text ('end_time', date ("H:m", get_system_time ()), false, 10, 5, true);
|
||||
|
||||
//Export type
|
||||
$table->data[5][0] = '<b>'.__('Export type').'</b>';
|
||||
|
||||
$export_types = array ();
|
||||
$export_types["data"] = __('Data table');
|
||||
$export_types["csv"] = __('CSV');
|
||||
$export_types["excel"] = __('MS Excel');
|
||||
$export_types["avg"] = __('Average per hour/day');
|
||||
|
||||
$table->data[5][1] = print_select ($export_types, "export_type", $export_type, '', '', 0, true, false, true, 'w130', false);
|
||||
|
||||
print_table ($table);
|
||||
|
||||
// Submit button
|
||||
echo '<div class="action-buttons" style="width:550px;">';
|
||||
print_submit_button (__('Export'), 'export_btn', false, 'class="sub wand"');
|
||||
echo '</div></form>';
|
||||
|
||||
?>
|
Loading…
Reference in New Issue