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')); ?>