From 53b220b10b90b431cf6cf3e3a416533d151bc35e Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Wed, 8 Jun 2016 22:31:25 +0100 Subject: [PATCH] Fixed excel import notifications (#478) --- application/controllers/Customers.php | 4 +-- application/controllers/Items.php | 35 ++++++++----------- .../views/customers/form_excel_import.php | 26 +++++++------- application/views/items/form_excel_import.php | 26 +++++++------- 4 files changed, 40 insertions(+), 51 deletions(-) diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 8d5962718..ec6fd8890 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -227,9 +227,9 @@ class Customers extends Persons if(count($failCodes) > 0) { - $msg = 'Most customers imported. But some were not, here is list of their CODE (' . count($failCodes) . '): ' . implode(', ', $failCodes); + $message = 'Most customers imported. But some were not, here is the list (' . count($failCodes) . '): ' . implode(', ', $failCodes); - echo json_encode(array('success' => FALSE, 'message' => $msg)); + echo json_encode(array('success' => FALSE, 'message' => $message)); } else { diff --git a/application/controllers/Items.php b/application/controllers/Items.php index 431edb1e2..9ff1e0160 100644 --- a/application/controllers/Items.php +++ b/application/controllers/Items.php @@ -577,14 +577,9 @@ class Items extends Secure_Controller public function do_excel_import() { - $message = 'do_excel_import'; - $failCodes = array(); - if($_FILES['file_path']['error'] != UPLOAD_ERR_OK) { echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('items_excel_import_failed'))); - - return; } else { @@ -592,8 +587,10 @@ class Items extends Secure_Controller { // Skip the first row as it's the table description fgetcsv($handle); - $i = 1; + + $failCodes = array(); + while(($data = fgetcsv($handle)) !== FALSE) { // XSS file data sanity check @@ -722,27 +719,23 @@ class Items extends Secure_Controller $i++; } + + if(count($failCodes) > 0) + { + $message = 'Most Items imported. But some were not, here is the list (' . count($failCodes) . '): ' . implode(', ', $failCodes); + + echo json_encode(array('success' => FALSE, 'message' => $message)); + } + else + { + echo json_encode(array('success' => TRUE, 'message' => 'Import of Items successful')); + } } else { echo json_encode(array('success' => FALSE, 'message' => 'Your uploaded file has no data or wrong format')); - - return; } } - - $success = TRUE; - if(count($failCodes) > 0) - { - $message = 'Most items imported. But some were not, here is list of their codes (' . count($failCodes) . '): ' . implode(', ', $failCodes); - $success = FALSE; - } - else - { - $message = 'Import of Items successful'; - } - - echo json_encode(array('success' => $success, 'message' => $message)); } } ?> diff --git a/application/views/customers/form_excel_import.php b/application/views/customers/form_excel_import.php index 4ad7684e8..5419c8fdf 100644 --- a/application/views/customers/form_excel_import.php +++ b/application/views/customers/form_excel_import.php @@ -1,6 +1,6 @@ -'item_form', 'class'=>'form-horizontal')); ?> +'excel_form', 'class'=>'form-horizontal')); ?>
@@ -24,28 +24,26 @@ //validation and submit handling $(document).ready(function() { - $('#item_form').validate($.extend({ - submitHandler:function(form) - { + $('#excel_form').validate($.extend({ + submitHandler:function(form) { $(form).ajaxSubmit({ - success:function(response) - { - dialog_support.hide(); - table_support.handle_submit('', response); - }, - dataType:'json' - }); - + success:function(response) + { + dialog_support.hide(); + $.notify(response.message, { type: response.success ? 'success' : 'danger'} ); + }, + dataType: 'json' + }); }, errorLabelContainer: "#error_message_box", wrapper: "li", rules: { - file_path:"required" + file_path: "required" }, messages: { - file_path:"lang->line('common_import_full_path'); ?>" + file_path: "lang->line('common_import_full_path'); ?>" } }, form_support.error)); }); diff --git a/application/views/items/form_excel_import.php b/application/views/items/form_excel_import.php index d9354b7f8..95daf7618 100644 --- a/application/views/items/form_excel_import.php +++ b/application/views/items/form_excel_import.php @@ -1,6 +1,6 @@
    -'item_form', 'class'=>'form-horizontal')); ?> +'excel_form', 'class'=>'form-horizontal')); ?>
    @@ -24,28 +24,26 @@ //validation and submit handling $(document).ready(function() { - $('#item_form').validate($.extend({ - submitHandler:function(form) - { + $('#excel_form').validate($.extend({ + submitHandler:function(form) { $(form).ajaxSubmit({ - success:function(response) - { - dialog_support.hide(); - table_support.handle_submit('', response); - }, - dataType:'json' - }); - + success:function(response) + { + dialog_support.hide(); + $.notify(response.message, { type: response.success ? 'success' : 'danger'} ); + }, + dataType: 'json' + }); }, errorLabelContainer: "#error_message_box", wrapper: "li", rules: { - file_path:"required" + file_path: "required" }, messages: { - file_path:"lang->line('common_import_full_path'); ?>" + file_path: "lang->line('common_import_full_path'); ?>" } }, form_support.error)); });