Permalink
Browse files

Fix CVS-git drift

  • Loading branch information...
1 parent ee8d4be commit 10ec29097f9b963565b206b1179b9f6d899cf749 Francois Marier committed Mar 15, 2009
Showing with 15 additions and 1 deletion.
  1. +15 −1 mod/data/import.php
View
16 mod/data/import.php
@@ -102,11 +102,24 @@
$recordsadded = 0;
if (!$records = data_get_records_csv($filename, $fielddelimiter, $fieldenclosure)) {
- error('get_records_csv failed to read data from the uploaded file. Please check file for field name typos and formatting errors.');
+ print_error('csvfailed','data',"{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}");
} else {
//$db->debug = true;
$fieldnames = array_shift($records);
+ // check the fieldnames are valid
+ $fields = get_records('data_fields', 'dataid', $data->id, '', 'name, id, type');
+ $errorfield = '';
+ foreach ($fieldnames as $name) {
+ if (!isset($fields[$name])) {
+ $errorfield .= "'$name' ";
+ }
+ }
+
+ if (!empty($errorfield)) {
+ print_error('fieldnotmatched','data',"{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}",$errorfield);
+ }
+
foreach ($records as $record) {
if ($recordid = data_add_record($data, 0)) { // add instance to data_record
$fields = get_records('data_fields', 'dataid', $data->id, '', 'name, id, type');
@@ -197,6 +210,7 @@ function my_file_get_contents($filename, $use_include_path = 0) {
function data_get_records_csv($filename, $fielddelimiter=',', $fieldenclosure="\n") {
global $db;
+
if (empty($fielddelimiter)) {
$fielddelimiter = ',';
}

0 comments on commit 10ec290

Please sign in to comment.