2012-04-23 Vanessa Gil <vanessa.gil@artica.es>

* operation/menu.php
	  operation/agentes/exportdata.php: Fixed bug: Error exporting
	data to excel or csv.

	operation/agentes/exportdata.csv.php
	operation/agentes/exportdata.excel.php: Added files.


git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6090 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
vgilc 2012-04-23 11:52:41 +00:00
parent 2511b63667
commit fd483742b2
5 changed files with 386 additions and 74 deletions

View File

@ -1,3 +1,12 @@
2012-04-23 Vanessa Gil <vanessa.gil@artica.es>
* operation/menu.php
operation/agentes/exportdata.php: Fixed bug: Error exporting
data to excel or csv.
operation/agentes/exportdata.csv.php
operation/agentes/exportdata.excel.php: Added files.
2012-04-23 Juan Manuel Ramon <juanmanuel.ramon@artica.es>
* include/functions_networkmap.php

View File

@ -0,0 +1,172 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
session_start ();
require_once ("../../include/config.php");
require_once ("../../include/functions_agents.php");
require_once ("../../include/functions_reporting.php");
require_once ("../../include/functions_modules.php");
require_once ("../../include/functions_users.php");
global $config;
if (!check_acl ($config['id_user'], 0, "AR")) {
require ("../../general/noaccess.php");
return;
}
$group = get_parameter_post ('group', 0);
$agentName = get_parameter_post ('agent', 0);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$agents = agents_get_agents (array('nombre LIKE "' . $agentName . '"'), array ('id_agente'));
break;
case "oracle":
$agents = agents_get_agents (array('nombre LIKE \'%' . $agentName . '%\''), array ('id_agente'));
break;
}
$agent = $agents[0]['id_agente'];
$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)) {
// Disable SQL cache
global $sql_cache;
$sql_cache = array ('saved' => 0);
//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 ();
//If time is negative or zero, don't process - it's invalid
if ($start < 1 || $end < 1) {
ui_print_error_message (__('Invalid time specified'));
return;
}
// ***************************************************
// Starts, ends and dividers
// ***************************************************
//Pure CSV is comma delimited
$datastart = __('Agent').','.__('Module').','.__('Data').','.__('Timestamp')."\n";
$rowstart = '"';
$divider = '","';
$rowend = '"'."\n";
$dataend = "\n";
$extension = "csv";
// ***************************************************
// Header output
// ***************************************************
$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");
// ***************************************************
// Data processing
// ***************************************************
$data = array ();
// Show header
echo $datastart;
foreach ($module as $selected) {
$output = "";
$work_period = 120000;
if ($work_period > $period) {
$work_period = $period;
}
$work_end = $end - $period + $work_period;
//Buffer to get data, anyway this will report a memory exhaustin
while ($work_end <= $end) {
$data = array (); // Reinitialize array for each module chunk
if ($export_type == "avg") {
$arr = array ();
$arr["data"] = reporting_get_agentmodule_data_average ($selected, $work_period, $work_end);
if ($arr["data"] === false) {
continue;
}
$arr["module_name"] = modules_get_agentmodule_name ($selected);
$arr["agent_name"] = modules_get_agentmodule_agent_name ($selected);
$arr["agent_id"] = modules_get_agentmodule_agent ($selected);
$arr["utimestamp"] = $end;
array_push ($data, $arr);
}
else {
$data_single = modules_get_agentmodule_data ($selected, $work_period, $work_end);
if (!empty ($data_single)) {
$data = array_merge ($data, $data_single);
}
}
foreach ($data as $key => $module) {
$output .= $rowstart;
$output .= io_safe_output($module['agent_name']);
$output .= $divider;
$output .= io_safe_output($module['module_name']);
$output .= $divider;
$output .= $module['data'];
$output .= $divider;
$output .= date ("Y-m-d G:i:s", $module['utimestamp']);
$output .= $rowend;
}
echo $output;
unset($output);
$output = "";
unset($data);
unset($data_single);
$work_end = $work_end + $work_period;
}
unset ($output);
$output = "";
} // main foreach
echo $dataend;
exit; // Necesary for CSV export, if not give problems
}
elseif (!empty ($export_btn) && empty ($module)) {
ui_print_error_message (__('No modules specified'));
}
?>

View File

@ -0,0 +1,176 @@
<?php
// Pandora FMS - http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
session_start ();
require_once ("../../include/config.php");
require_once ("../../include/functions_agents.php");
require_once ("../../include/functions_reporting.php");
require_once ("../../include/functions_modules.php");
require_once ("../../include/functions_users.php");
global $config;
if (!check_acl ($config['id_user'], 0, "AR")) {
require ("../../general/noaccess.php");
return;
}
$group = get_parameter_post ('group', 0);
$agentName = get_parameter_post ('agent', 0);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$agents = agents_get_agents (array('nombre LIKE "' . $agentName . '"'), array ('id_agente'));
break;
case "oracle":
$agents = agents_get_agents (array('nombre LIKE \'%' . $agentName . '%\''), array ('id_agente'));
break;
}
$agent = $agents[0]['id_agente'];
$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)) {
// Disable SQL cache
global $sql_cache;
$sql_cache = array ('saved' => 0);
//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 ();
//If time is negative or zero, don't process - it's invalid
if ($start < 1 || $end < 1) {
ui_print_error_message (__('Invalid time specified'));
return;
}
// ***************************************************
// Starts, ends and dividers
// ***************************************************
//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";
// ***************************************************
// Header output
// ***************************************************
$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");
// ***************************************************
// Data processing
// ***************************************************
$data = array ();
// Show header
echo $datastart;
foreach ($module as $selected) {
$output = "";
$work_period = 120000;
if ($work_period > $period) {
$work_period = $period;
}
$work_end = $end - $period + $work_period;
//Buffer to get data, anyway this will report a memory exhaustin
while ($work_end <= $end) {
$data = array (); // Reinitialize array for each module chunk
if ($export_type == "avg") {
$arr = array ();
$arr["data"] = reporting_get_agentmodule_data_average ($selected, $work_period, $work_end);
if ($arr["data"] === false) {
continue;
}
$arr["module_name"] = modules_get_agentmodule_name ($selected);
$arr["agent_name"] = modules_get_agentmodule_agent_name ($selected);
$arr["agent_id"] = modules_get_agentmodule_agent ($selected);
$arr["utimestamp"] = $end;
array_push ($data, $arr);
}
else {
$data_single = modules_get_agentmodule_data ($selected, $work_period, $work_end);
if (!empty ($data_single)) {
$data = array_merge ($data, $data_single);
}
}
foreach ($data as $key => $module) {
$output .= $rowstart;
$output .= io_safe_output($module['agent_name']);
$output .= $divider;
$output .= io_safe_output($module['module_name']);
$output .= $divider;
$output .= $module['data'];
$output .= $divider;
$output .= date ("Y-m-d G:i:s", $module['utimestamp']);
$output .= $rowend;
}
echo $output;
unset($output);
$output = "";
unset($data);
unset($data_single);
$work_end = $work_end + $work_period;
}
unset ($output);
$output = "";
} // main foreach
echo $dataend;
/*
switch ($export_type) {
case "excel":
exit; // Necesary for CSV export, if not give problems
break;
}
*/
}
elseif (!empty ($export_btn) && empty ($module)) {
ui_print_error_message (__('No modules specified'));
}
?>

View File

@ -202,43 +202,6 @@ if (!empty ($export_btn) && !empty ($module)) {
$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;
}
// ***************************************************
// Header output
// ***************************************************
switch ($export_type) {
case "excel":
case "csv":
$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");
break;
}
// ***************************************************
@ -248,8 +211,6 @@ if (!empty ($export_btn) && !empty ($module)) {
$data = array ();
switch ($export_type) {
case "data":
case "excel":
case "csv":
case "avg":
// Show header
@ -287,12 +248,7 @@ if (!empty ($export_btn) && !empty ($module)) {
$data = array_merge ($data, $data_single);
}
}
/*
if ($work_end > $end) {
$work_period = $work_end - $end;
$work_end = $end;
}
*/
foreach ($data as $key => $module) {
$output .= $rowstart;
$output .= io_safe_output($module['agent_name']);
@ -310,11 +266,8 @@ if (!empty ($export_btn) && !empty ($module)) {
case "data":
case "avg":
echo $output;
exit;
break;
case "excel":
case "csv":
echo $output;
break;
}
unset($output);
$output = "";
@ -327,29 +280,13 @@ if (!empty ($export_btn) && !empty ($module)) {
} // main foreach
echo $dataend;
break;
default:
ui_print_error_message (__('Invalid method supplied'));
return;
break;
}
switch ($export_type) {
case "excel":
case "csv":
exit; // Necesary for CSV export, if not give problems
break;
default:
return;
break;
}
}
elseif (!empty ($export_btn) && empty ($module)) {
ui_print_error_message (__('No modules specified'));
}
echo '<form method="post" action="index.php?sec=estado&amp;sec2=operation/agentes/exportdata" name="export_form">';
echo '<form method="post" action="index.php?sec=reporting&amp;sec2=operation/agentes/exportdata" name="export_form">';
$table->width = '98%';
$table->border = 0;
@ -387,7 +324,6 @@ if (!in_array ($agent, array_keys ($agents))) {
$agent = current (array_keys ($agents));
}
//$table->data[1][1] = html_print_select ($agents, "agent", $agent, 'this.form.submit();', '', 0, true, false, true, 'w130', false);
//Src code of lightning image with skins
$src_code = html_print_image ('images/lightning.png', true, false, true);
$table->data[1][1] = html_print_input_text_extended ('agent', agents_get_name ($agent), 'text-agent', '', 40, 100, false, '',
@ -529,5 +465,25 @@ $(document).ready (function () {
$(".ui-autocomplete").css("text-align", "left");
}
});
$("select#export_type").change (function () {
type = $("#export_type").val();
var f = document.forms.export_form;
switch (type) {
case 'csv':
f.action = "operation/agentes/exportdata.csv.php";
break;
case 'excel':
f.action = "operation/agentes/exportdata.excel.php";
break;
case 'avg':
case 'data':
f.action = "index.php?sec=reporting&sec2=operation/agentes/exportdata";
break;
}
});
/* ]]> */
</script>

View File

@ -191,10 +191,12 @@ if (check_acl ($config['id_user'], 0, "AR")) {
$sub["godmode/reporting/graphs"]["text"] = __('Custom graphs');
//Set godomode path
$sub["godmode/reporting/graphs"]["subsecs"] = array(
"operation/reporting/graph_viewer",
"godmode/reporting/graph_builder");
$sub["godmode/reporting/graphs"]["subsecs"] = array("operation/reporting/graph_viewer",
"godmode/reporting/graph_builder");
$sub["operation/agentes/exportdata"]["text"] = __('Export data');
$sub["operation/agentes/exportdata"]["subsecs"] = array("operation/agentes/exportdata");
enterprise_hook ('dashboard_menu');
enterprise_hook ('reporting_godmenu');
@ -368,9 +370,6 @@ if (check_acl ($config['id_user'], 0, "AR")) {
$sub = array ();
$sub["operation/agentes/exportdata"]["text"] = __('Export data');
$sub["operation/agentes/exportdata"]["refr"] = 0;
foreach ($config["extensions"] as $extension) {
//If no operation_menu is a godmode extension
if ($extension["operation_menu"] == '') {