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 '
'; @@ -389,7 +414,7 @@ if ($step == 2 && $datatoimport) if (eregi('^\.',$file)) continue; $modulepart='import'; - $urlsource=$_SERVER["PHP_SELF"].'?step='.$step.'&datatoimport='.$datatoimport; + $urlsource=$_SERVER["PHP_SELF"].'?step='.$step.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport); $relativepath=$file; $var=!$var; print ''; @@ -427,18 +452,22 @@ if ($step == 3 && $datatoimport) // Load source fields in input file $fieldssource=array( 1=>array('name'=>'aa','example1'=>'val1','example2'=>'val2'), - 2=>array('name'=>'bb','example1'=>'valb1','example2'=>'valb2') + 2=>array('name'=>'bb','example1'=>'valb1','example2'=>'valb2'), + 3=>array('name'=>'cc','example1'=>'valc1','example2'=>'valc2') ); - // Load targets fields in database $fieldstarget=$objimport->array_import_fields[0]; $maxpos=max(sizeof($fieldssource),sizeof($fieldstarget)); + // Is it a first time in page if (sizeof($array_match_file_to_database) == 0) { - // This is first input in screen, we need to define the $array_match_file_to_database array + // This is first input in screen, we need to define + // $array_match_file_to_database + // $serialized_array_match_file_to_database + // $_SESSION["dol_array_match_file_to_database"] $pos=1; while ($pos <= sizeof($fieldssource)) { @@ -454,14 +483,19 @@ if ($step == 3 && $datatoimport) } // We found the key of targets that is at position pos $array_match_file_to_database[$pos]=$key; + if ($serialized_array_match_file_to_database) $serialized_array_match_file_to_database.=','; + $serialized_array_match_file_to_database.=($pos.'='.$key); break; } } $pos++; } // Save the match array in session. We now will use the array in session. - $_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; } + //print $serialized_array_match_file_to_database; + //print $_SESSION["dol_array_match_file_to_database"]; + //var_dump($array_match_file_to_database);exit; // Now $array_match_file_to_database contains fieldnb(1,2,3...)=>fielddatabase(key in $array_match_file_to_database) @@ -505,18 +539,20 @@ if ($step == 3 && $datatoimport) // Nbre champs importes print ''.$langs->trans("FileToImport").''; - print ''.$_GET["filetoimport"].''; + print ''.$filetoimport.''; print ''; - print '
'; + print '
'."\n"; // List of import models + print ''."\n"; print ''; print ''; print ''; print ''; print ''; + print ''; print '
'; print $langs->trans("SelectImportFields",img_picto('','uparrow','')).' '; $htmlother->select_import_model($importmodelid,'importmodelid',$datatoimport,1); @@ -708,7 +744,7 @@ if ($step == 3 && $datatoimport) if (sizeof($array_match_file_to_database)) { - print ''.$langs->trans("NextStep").''; + print ''.$langs->trans("NextStep").''; } print ''; @@ -717,14 +753,16 @@ if ($step == 3 && $datatoimport) // Area for profils import if (sizeof($array_match_file_to_database)) { - print '
'; + print '
'."\n"; + print ''."\n"; print $langs->trans("SaveImportModel"); - print ''; + print ''; print ''; print ''; print ''; print ''; + print ''; print ''; print ''; @@ -756,7 +794,7 @@ if ($step == 3 && $datatoimport) print ''; diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index b19f2090938..3f092520bbf 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -63,4 +63,5 @@ ChooseFileToImport=Upload file then click on picto %s to select file as source i FieldsInSourceFile=Fields in source file FieldsInTargetDatabase=Target fields in Dolibarr database NoFields=No fields -MoveField=Move field column number %s \ No newline at end of file +MoveField=Move field column number %s +ExampleOfImportFile=Example_of_import_file \ No newline at end of file diff --git a/htdocs/langs/fr_FR/exports.lang b/htdocs/langs/fr_FR/exports.lang index 152f3651b3a..261848d10e5 100644 --- a/htdocs/langs/fr_FR/exports.lang +++ b/htdocs/langs/fr_FR/exports.lang @@ -63,4 +63,5 @@ DownloadEmptyExample=Télécharger fichier vierge exemple FieldsInSourceFile=Champs dans le fichier source FieldsInTargetDatabase=Champs cibles dans la base Dolibarr NoFields=Aucun champ -MoveField=Déplacer champ colonne numéro %s \ No newline at end of file +MoveField=Déplacer champ colonne numéro %s +ExampleOfImportFile=Exemple_de_fichier_import \ No newline at end of file
'; print $obj->label; print ''; - print 'rowid.'">'; + print 'rowid.'&filetoimport='.urlencode($filetoimport).'">'; print img_delete(); print ''; print '