From 4d7e20926eac1af4a801585e1f08056ca5cfec1f Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 2 Oct 2013 16:53:20 +0200 Subject: [PATCH] fix to enable import of answers from a different installation/version of LS --- application/helpers/admin/import_helper.php | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/application/helpers/admin/import_helper.php b/application/helpers/admin/import_helper.php index 854ed0249ed..976e77bb11a 100644 --- a/application/helpers/admin/import_helper.php +++ b/application/helpers/admin/import_helper.php @@ -4195,6 +4195,36 @@ function CSVImportResponses($sFullFilepath,$iSurveyId,$aOptions=array()) if(in_array($sLemFieldName,$aCsvHeader)){ $aKeyForFieldNames[$sFieldName]=array_search($sLemFieldName,$aCsvHeader); } + // as fallback just map questions in order of apperance + else + { + // find out where the answer data columns start in CSV + if( ! isset($csv_ans_start_index)) + { + foreach($aCsvHeader as $i=>$name) + { + if(preg_match('/^\d+X\d+X\d+/', $name)) + { + $ans_start_index = $i; + break; + } + } + } + // find out where the answer data columns start in destination table + if( ! isset($table_ans_start_index)) + { + foreach($aRealFieldNames as $i=>$name) + { + if(preg_match('/^\d+X\d+X\d+/', $name)) + { + $table_start_index = $i; + break; + } + } + } + // map answers in order + $aKeyForFieldNames[$sFieldName] = (array_search($sFieldName,$aRealFieldNames)-$table_ans_start_index) + $csv_ans_start_index; + } } }