Merge branch 'ent-6179-csv-decimal-separator' into 'develop'
Add decimal separator to all pandora csv See merge request artica/pandorafms!3434
This commit is contained in:
commit
0d657ab354
|
@ -1482,7 +1482,7 @@ $row++;
|
|||
'.' => '.',
|
||||
',' => ',',
|
||||
];
|
||||
$table_other->data[$row][0] = __('CSV decimal separator').ui_print_help_tip(__('Only for csv reports'), true);
|
||||
$table_other->data[$row][0] = __('CSV decimal separator');
|
||||
$table_other->data[$row][1] = html_print_select($decimal_separator, 'csv_decimal_separator', $config['csv_decimal_separator'], '', '', '', true, false, false);
|
||||
|
||||
$row++;
|
||||
|
|
|
@ -409,6 +409,8 @@ class ModuleTemplates extends HTML
|
|||
case 'export':
|
||||
global $config;
|
||||
|
||||
enterprise_include_once('include/functions_reporting_csv.php');
|
||||
|
||||
$id_network_profile = safe_int($this->id_np);
|
||||
if (empty($id_network_profile)) {
|
||||
return false;
|
||||
|
@ -500,7 +502,7 @@ class ModuleTemplates extends HTML
|
|||
}
|
||||
|
||||
// Then print the first line (row names)
|
||||
echo '"'.implode('","', $row_names).'"';
|
||||
echo '"'.implode('"'.$config['csv_divider'].'"', $row_names).'"';
|
||||
echo "\n";
|
||||
|
||||
// Then print the rest of the data. Encapsulate in quotes in case we have comma's in any of the descriptions
|
||||
|
@ -509,7 +511,19 @@ class ModuleTemplates extends HTML
|
|||
unset($row[$bad_key]);
|
||||
}
|
||||
|
||||
echo '"'.implode('","', $row).'"';
|
||||
if ($config['csv_decimal_separator'] !== '.') {
|
||||
foreach ($row as $name => $data) {
|
||||
if (is_numeric($data)) {
|
||||
// Get the number of decimals, if > 0, format dec comma.
|
||||
$decimals = strlen(substr(strrchr($data, '.'), 1));
|
||||
if ($decimals !== 0) {
|
||||
$row[$name] = csv_format_numeric((float) $data, $decimals, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo '"'.implode('"'.$config['csv_divider'].'"', $row).'"';
|
||||
echo "\n";
|
||||
}
|
||||
|
||||
|
@ -845,7 +859,7 @@ class ModuleTemplates extends HTML
|
|||
$row['id_np'],
|
||||
'',
|
||||
true,
|
||||
['title' => 'Export to CSV']
|
||||
['title' => 'Export tdaso CSV']
|
||||
);
|
||||
$data[3] = '<a href="'.$this->baseUrl.'&action=delete&id_np='.$row['id_np'].'" onclick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/cross.png', true, ['title' => __('Delete')]).'</a>';
|
||||
$data[3] .= '<a href="'.$this->baseUrl.'&action=export&id_np='.$row['id_np'].'">'.html_print_image('images/csv.png', true, ['title' => __('Export to CSV')]).'</a>';
|
||||
|
|
|
@ -3904,17 +3904,23 @@ function series_type_graph_array($data, $show_elements_graph)
|
|||
$data_return['legend'][$key] .= __('Min:').remove_right_zeros(
|
||||
number_format(
|
||||
$value['min'],
|
||||
$config['graph_precision']
|
||||
$config['graph_precision'],
|
||||
$config['csv_decimal_separator'],
|
||||
$config['csv_decimal_separator'] == ',' ? '.' : ','
|
||||
)
|
||||
).' '.__('Max:').remove_right_zeros(
|
||||
number_format(
|
||||
$value['max'],
|
||||
$config['graph_precision']
|
||||
$config['graph_precision'],
|
||||
$config['csv_decimal_separator'],
|
||||
$config['csv_decimal_separator'] == ',' ? '.' : ','
|
||||
)
|
||||
).' '._('Avg:').remove_right_zeros(
|
||||
number_format(
|
||||
$value['avg'],
|
||||
$config['graph_precision']
|
||||
$config['graph_precision'],
|
||||
$config['csv_decimal_separator'],
|
||||
$config['csv_decimal_separator'] == ',' ? '.' : ','
|
||||
)
|
||||
).' '.$str;
|
||||
|
||||
|
@ -3978,7 +3984,8 @@ function series_type_graph_array($data, $show_elements_graph)
|
|||
$data_return['legend'][$key] .= remove_right_zeros(
|
||||
number_format(
|
||||
$value['avg'],
|
||||
$config['graph_precision']
|
||||
$config['graph_precision'],
|
||||
$config['csv_decimal_separator']
|
||||
)
|
||||
).' '.$str;
|
||||
}
|
||||
|
@ -5911,4 +5918,5 @@ function send_test_email(
|
|||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
// This file only uses data retrieved in a request.
|
||||
require_once '../../include/config.php';
|
||||
require_once '../../include/functions.php';
|
||||
enterprise_include_once('include/functions_reporting_csv.php');
|
||||
|
||||
global $config;
|
||||
|
||||
|
@ -49,7 +50,10 @@ $filename = io_safe_output($filename);
|
|||
* );
|
||||
*/
|
||||
$output_csv = function ($data, $filename) {
|
||||
$separator = (string) get_parameter('separator', ';');
|
||||
global $config;
|
||||
|
||||
$separator = (string) $config['csv_divider'];
|
||||
|
||||
$excel_encoding = (bool) get_parameter('excel_encoding', false);
|
||||
|
||||
// CSV Output
|
||||
|
@ -68,9 +72,15 @@ $output_csv = function ($data, $filename) {
|
|||
throw new Exception(__('An error occured exporting the data'));
|
||||
}
|
||||
|
||||
// Get key for item value.
|
||||
$value_key = array_search('value', $items['head']);
|
||||
|
||||
$head_line = implode($separator, $items['head']);
|
||||
echo $head_line."\n";
|
||||
foreach ($items['data'] as $item) {
|
||||
// Find value and replace csv decimal separator.
|
||||
$item[$value_key] = csv_format_numeric($item[$value_key]);
|
||||
|
||||
$item = str_replace('--> '.__('Selected'), '', $item);
|
||||
$line = implode($separator, $item);
|
||||
|
||||
|
|
Loading…
Reference in New Issue