From afef30bc75e0d50cea721a7519a99b1f4d81abab Mon Sep 17 00:00:00 2001 From: m-lopez-f Date: Mon, 28 Sep 2015 16:17:30 +0200 Subject: [PATCH] Fixed when export csv in custom graph and only print one register and add label in export data, tiquet: #2755 --- .../include/graphs/export_data.php | 27 ++++++++++--------- .../include/graphs/flot/pandora.flot.js | 25 +++++++++++++---- .../operation/reporting/graph_viewer.php | 1 + 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/pandora_console/include/graphs/export_data.php b/pandora_console/include/graphs/export_data.php index 4958d84c95..99b685c938 100644 --- a/pandora_console/include/graphs/export_data.php +++ b/pandora_console/include/graphs/export_data.php @@ -53,20 +53,23 @@ $output_csv = function ($data, $filename) { header ('Content-Disposition: attachment; filename="'.$filename.'.csv"'); // Header - if (!isset($data['head']) || !isset($data['data'])) - throw new Exception(__('An error occured exporting the data')); - - $head_line = implode($separator, $data['head']); - echo $head_line . "\n"; // Item / data - foreach ($data['data'] as $items) { - $line = implode($separator, $items); - - if ($excel_encoding) - echo mb_convert_encoding($line, 'UTF-16LE', 'UTF-8') . "\n"; - else - echo $line . "\n"; + foreach ($data as $items) { + if (!isset($items['head']) || !isset($items['data'])) + throw new Exception(__('An error occured exporting the data')); + + $head_line = implode($separator, $items['head']); + echo $head_line . "\n"; + foreach ($items['data'] as $item) { + + $line = implode($separator, $item); + + if ($excel_encoding) + echo mb_convert_encoding($line, 'UTF-16LE', 'UTF-8') . "\n"; + else + echo $line . "\n"; + } } }; diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 83b6134f61..a19122d4ee 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1099,8 +1099,9 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, * } */ if (type === 'csv') { + result = { - head: ['date', 'value'], + head: ['date', 'value','label'], data: [] }; @@ -1113,7 +1114,7 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, else if (typeof labels[index] !== 'undefined') date = labels[index]; - result.data.push([date, value]); + result.data.push([date, value,dataObject.label]); }); } /* [ @@ -1150,7 +1151,8 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, result.push({ 'date': date, - 'value': value + 'value': value, + 'label': dataObject.label }); }); } @@ -1162,8 +1164,21 @@ function pandoraFlotArea(graph_id, values, labels, labels_long, legend, } try { - dataObject = retrieveDataOject(dataObjects); - graphData = processDataObject(dataObject); + var elements = []; + var custom_graph = $('input:hidden[name=custom_graph]').value; + + if (custom_graph) { + dataObject = retrieveDataOject(dataObjects); + dataObjects.forEach(function (element) { + elements.push(processDataObject(element)); + }); + graphData = elements; + } + else { + dataObject = retrieveDataOject(dataObjects); + elements.push(processDataObject(dataObject)); + graphData = elements; + } // Transform the object data into a string // cause PHP has limitations in the number diff --git a/pandora_console/operation/reporting/graph_viewer.php b/pandora_console/operation/reporting/graph_viewer.php index 931b3fb578..193806b96a 100644 --- a/pandora_console/operation/reporting/graph_viewer.php +++ b/pandora_console/operation/reporting/graph_viewer.php @@ -104,6 +104,7 @@ if ($view_graph) { exit; } html_print_input_hidden ('lineWidhtGraph', $config['custom_graph_width']); + html_print_input_hidden ('custom_graph', 1); $url = "index.php?" . "sec=reporting&" . "sec2=operation/reporting/graph_viewer&" .