diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php
index addff0ad31f..8721f628a9f 100644
--- a/htdocs/imports/import.php
+++ b/htdocs/imports/import.php
@@ -63,8 +63,8 @@ $entitytolang=array( // Translation code
'other'=>'Other'
);
-$array_match_file_to_database=isset($_SESSION["dol_array_match_file_to_database"])?$_SESSION["dol_array_match_file_to_database"]:array();
$datatoimport=isset($_GET["datatoimport"])? $_GET["datatoimport"] : (isset($_POST["datatoimport"])?$_POST["datatoimport"]:'');
+$filetoimport=isset($_GET["filetoimport"])? $_GET["filetoimport"] : (isset($_POST["filetoimport"])?$_POST["filetoimport"]:'');
$action=isset($_GET["action"]) ? $_GET["action"] : (isset($_POST["action"])?$_POST["action"]:'');
$step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"]:1);
$import_name=isset($_POST["import_name"])? $_POST["import_name"] : '';
@@ -80,11 +80,26 @@ $htmlother = new FormOther($db);
$formfile = new FormFile($db);
$sqlusedforimport='';
+// Init $array_match_file_to_database from _SESSION
+$serialized_array_match_file_to_database=isset($_SESSION["dol_array_match_file_to_database"])?$_SESSION["dol_array_match_file_to_database"]:'';
+$array_match_file_to_database=array();
+$fieldsarray=split(',',$serialized_array_match_file_to_database);
+foreach($fieldsarray as $elem)
+{
+ $tabelem=split('=',$elem,2);
+ $key=$tabelem[0];
+ $val=$tabelem[1];
+ if ($key && $val)
+ {
+ $array_match_file_to_database[$key]=$val;
+ }
+}
+
/*
* Actions
*/
-
+/*
if ($action=='downfield' || $action=='upfield')
{
$pos=$array_match_file_to_database[$_GET["field"]];
@@ -105,10 +120,10 @@ if ($action=='downfield' || $action=='upfield')
{
$array_match_file_to_database[$_GET["field"]]=$newpos;
$array_match_file_to_database[$newcode]=$pos;
- $_SESSION["dol_array_match_file_to_database"]=$array_match_file_to_database;
+ $_SESSION["dol_array_match_file_to_database"]=$serialized_array_match_file_to_database;
}
}
-
+*/
if ($action == 'builddoc')
{
// Build import file
@@ -133,19 +148,17 @@ if ($action == 'deleteprof')
}
}
-// Save import config to file
+// Save import config to database
if ($action == 'add_import_model')
{
if ($import_name)
{
- asort($array_match_file_to_database);
-
// Set save string
$hexa='';
foreach($array_match_file_to_database as $key=>$val)
{
if ($hexa) $hexa.=',';
- $hexa.=$key;
+ $hexa.=$key.'='.$val;
}
$objimport->model_name = $import_name;
@@ -175,21 +188,29 @@ if ($action == 'add_import_model')
if ($step == 3 && $action == 'select_model')
{
+ // Reinit match arrays
+ $_SESSION["dol_array_match_file_to_database"]='';
+ $serialized_array_match_file_to_database='';
+ $array_match_file_to_database=array();
+
// Load model from $importmodelid and set $array_match_file_to_database
// and $_SESSION["dol_array_match_file_to_database"]
- $_SESSION["dol_array_match_file_to_database"]=array();
- $array_match_file_to_database=array();
$result = $objimport->fetch($importmodelid);
if ($result > 0)
{
- $fieldsarray=split(',',$objimport->hexa);
- $i=1;
- foreach($fieldsarray as $val)
+ $serialized_array_match_file_to_database=$objimport->hexa;
+ $fieldsarray=split(',',$serialized_array_match_file_to_database);
+ foreach($fieldsarray as $elem)
{
- $array_match_file_to_database[$val]=$i;
- $i++;
+ $tabelem=split('=',$elem);
+ $key=$tabelem[0];
+ $val=$tabelem[1];
+ if ($key && $val)
+ {
+ $array_match_file_to_database[$key]=$val;
+ }
}
- $_SESSION["dol_array_match_file_to_database"]=$array_match_file_to_database;
+ $_SESSION["dol_array_match_file_to_database"]=$serialized_array_match_file_to_database;
}
}
@@ -202,6 +223,11 @@ if ($step == 3 && $action == 'select_model')
if ($step == 1 || ! $datatoimport)
{
+ // Clean saved file-database matching
+ $serialized_array_match_file_to_database='';
+ $array_match_file_to_database=array();
+ $_SESSION["dol_array_match_file_to_database"]='';
+
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
/*
@@ -311,8 +337,7 @@ if ($step == 2 && $datatoimport)
print '';
print '';
- print '
';
-
+ print '
'."\n";
print '