diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php
index 4ca236ffcb1..93d57acaee2 100644
--- a/htdocs/imports/import.php
+++ b/htdocs/imports/import.php
@@ -569,72 +569,45 @@ if ($step == 3 && $datatoimport)
print '
';
+ $fieldsplaced=array();
+ foreach($array_match_file_to_database as $key => $val)
+ {
+ $listofkeys[$key]=1;
+ }
+
//var_dump($array_match_file_to_database);
- $pos=1;
print "\n\n";
print ''."\n";
// List of source fields
-// print ' ';
$var=true;
- while ($pos <= $maxpos)
+ $lefti=1;
+ foreach ($array_match_file_to_database as $key => $val)
{
$var=!$var;
+ show_elem($fieldssource,$lefti,$key,$val,$var); // key is field number is source file
+ //print '> '.$lefti.'-'.$key.'-'.$val;
+ $listofkeys[$key]=1;
+ $fieldsplaced[$key]=1;
+ $lefti++;
-// print "';
-// print '| ';
- // Get name of database field at position $pos into $namefield
- $namefield='';
- $posbis=1;
- foreach($fieldstarget as $key => $val)
- {
- if ($posbis < $pos)
- {
- $posbis++;
- continue;
- }
- // We found the key of targets that is at position pos
- $namefield=$key;
- break;
- }
- // Now we check if there is a file field linked to this $namefield database field
- $keyfound='';
- foreach($fieldssource as $key => $val)
- {
- if (! empty($array_match_file_to_database[$key]) && $array_match_file_to_database[$key] == $namefield)
- {
-// print $langs->trans("Field").' '.$key.': ';
-// print $fieldssource[$key]['name'].' ('.$fieldssource[$key]['example1'].')';
- $keyfound=$key;
- break;
- }
- }
-// print ' | ';
-
- show_elem($fieldssource,$pos,$var,$keyfound);
-
- // Arrows
-// print ' ';
- if (sizeof($fieldssource) > 1 && $pos <= sizeof($fieldssource))
- {
-// if ($pos < $maxpos) print ''.img_down().'';
-// if ($pos > 1) print ''.img_up().'';
- }
-// print ' | ';
-
-// print '';
-// if (sizeof($fieldssource) > 1 && $pos <= sizeof($fieldssource)) print ' -> ';
-// print ' | ';
-
-// print ' ';
-
- $pos++;
-
- if ($pos > sizeof($fieldstarget)) break;
+ if ($lefti > sizeof($fieldstarget)) break; // Other fields are in the not imported area
+ }
+
+ // Complete source fields from sizeof($fieldssource)+1 to sizeof($fieldstarget)
+ $more=1;
+ while ($lefti <= sizeof($fieldstarget))
+ {
+ $var=!$var;
+ $newkey=getnewkey($fieldssource,$listofkeys);
+ show_elem($fieldssource,$lefti,$newkey,'',$var); // key start after field number in source file
+ //print '> '.$lefti.'-'.$newkey;
+ $listofkeys[$key]=1;
+ $lefti++;
+ $more++;
}
- // print ' ';
print " \n";
print "\n";
@@ -675,16 +648,39 @@ if ($step == 3 && $datatoimport)
print "\n\n";
print ''."\n";
- // Print all input fields discarded
- show_elem('','',$var,'');
+ $nbofnotimportedfields=0;
+ foreach ($fieldssource as $key => $val)
+ {
+ if (empty($fieldsplaced[$key]))
+ {
+ $var=!$var;
+ $nbofnotimportedfields++;
+ show_elem($fieldssource,$lefti,$key,'',$var);
+ //print '> '.$lefti.'-'.$key;
+ $listofkeys[$key]=1;
+ $lefti++;
+ }
+ }
+
+ // Print one more empty field
+ $newkey=getnewkey($fieldssource,$listofkeys);
+ show_elem($fieldssource,$lefti,$newkey,'',$var);
+ //print '> '.$lefti.'-'.$newkey;
+ $listofkeys[$newkey]=1;
+ $nbofnotimportedfields++;
print " \n";
print "\n";
print ' | ';
print '';
- // Print empty cells
- show_elem('','',$var,'none');
+ $i=0;
+ while ($i < $nbofnotimportedfields)
+ {
+ // Print empty cells
+ show_elem('','','','none',$var);
+ $i++;
+ }
print ' |
';
print '';
@@ -944,7 +940,7 @@ llxFooter('$Date$ - $Revision$');
/*
* Function to put the movable box of a source field
*/
-function show_elem($fieldssource,$pos,$var,$key)
+function show_elem($fieldssource,$i,$pos,$key,$var)
{
global $langs,$bc;
@@ -953,7 +949,7 @@ function show_elem($fieldssource,$pos,$var,$key)
print ''."\n";
print '';
- if (empty($key))
+ if ($pos && $pos > sizeof($fieldssource)) // NoFields
{
print '| ';
print img_picto(($pos>0?$langs->trans("MoveField",$pos):''),'uparrow','class="boxhandle" style="cursor:move;"');
@@ -971,7 +967,7 @@ function show_elem($fieldssource,$pos,$var,$key)
print ' ';
print ' | ';
}
- else
+ else // Print field of source file
{
//print ''.img_file('','').' | ';
print '';
@@ -979,8 +975,8 @@ function show_elem($fieldssource,$pos,$var,$key)
print img_picto($langs->trans("MoveField",$pos),'uparrow','class="boxhandle" style="cursor:move;"');
print ' | ';
print '';
- print $langs->trans("Field").' '.$key.': ';
- print ''.$fieldssource[$key]['name'].' ('.$fieldssource[$key]['example1'].')';
+ print $langs->trans("Field").' '.$pos.': ';
+ print ''.$fieldssource[$pos]['name'].' ('.$fieldssource[$pos]['example1'].')';
print ' | ';
}
print '
';
@@ -992,4 +988,29 @@ function show_elem($fieldssource,$pos,$var,$key)
}
+/**
+ * Return not used field number
+ *
+ * @param unknown_type $listofkey
+ * @return unknown
+ */
+function getnewkey(&$fieldssource,&$listofkey)
+{
+ $i=sizeof($fieldssource)+1;
+ // Max number of key
+ $maxkey=0;
+ foreach($listofkey as $key=>$val)
+ {
+ $maxkey=max($maxkey,$key);
+ }
+ // Found next empty key
+ while($i <= $maxkey)
+ {
+ if (empty($listofkey[$i])) break;
+ else $i++;
+ }
+
+ $listofkey[$i]=1;
+ return $i;
+}
?>