From cf8023cd5b380d06a74a95c0686d7021dd404124 Mon Sep 17 00:00:00 2001 From: zarzuelo Date: Thu, 1 Dec 2011 09:53:49 +0000 Subject: [PATCH] 2011-12-01 Sergio Martin * extensions/insert_data.php: Improved the error message to multiple xml creations (csv) bug: 3426375 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5222 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 5 +++ pandora_console/extensions/insert_data.php | 39 +++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index c76ae2c57f..d702face2e 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,8 @@ +2011-12-01 Sergio Martin + + * extensions/insert_data.php: Improved the error message to + multiple xml creations (csv) bug: 3426375 + 2011-11-30 Juan Manuel Ramon * include/functions_config.php: Login hash pass can be left blank. diff --git a/pandora_console/extensions/insert_data.php b/pandora_console/extensions/insert_data.php index d90861a9eb..03ec746abb 100644 --- a/pandora_console/extensions/insert_data.php +++ b/pandora_console/extensions/insert_data.php @@ -41,10 +41,10 @@ function createXMLData($agent, $agentModule, $time, $data) { io_safe_output($agentModule['nombre']), io_safe_output($agentModule['descripcion']), modules_get_type_name($agentModule['id_tipo_modulo']), $data); if (false === @file_put_contents($config['remote_config'] . '/' . io_safe_output($agent['nombre']) . '.' . strtotime($time) . '.data', $xml)) { - ui_print_error_message(sprintf(__('Can\'t save agent (%s), module (%s) data xml.'), $agent['nombre'], $agentModule['nombre'])); + return false; } else { - ui_print_success_message(sprintf(__('Save agent (%s), module (%s) data xml.'), $agent['nombre'], $agentModule['nombre'])); + return true; } } @@ -91,18 +91,49 @@ function mainInsertData() { $date_xml = $date2 . ' ' . $time2 . ':00'; + $done = 0; + $errors = 0; if ($csv !== false) { $file = file($csv['tmp_name']); foreach ($file as $line) { $tokens = explode(';', $line); - createXMLData($agent, $agentModule, trim($tokens[0]), trim($tokens[1])); + $result = createXMLData($agent, $agentModule, trim($tokens[0]), trim($tokens[1])); + + if($result) { + $done++; + } + else { + $errors++; + } } } else { - createXMLData($agent, $agentModule, $date_xml, $data); + $result = createXMLData($agent, $agentModule, $date_xml, $data); + + if($result) { + $done++; + } + else { + $errors++; + } } } + + if($errors > 0) { + $msg = sprintf(__('Can\'t save agent (%s), module (%s) data xml.'), $agent['nombre'], $agentModule['nombre']); + if($errors > 1) { + $msg .= " ($errors)"; + } + ui_print_error_message($msg); + } + if($done > 0){ + $msg = sprintf(__('Save agent (%s), module (%s) data xml.'), $agent['nombre'], $agentModule['nombre']); + if($done > 1) { + $msg .= " ($done)"; + } + ui_print_success_message($msg); + } } echo '
';