diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php
index 1267e608352..767258e62a7 100644
--- a/htdocs/imports/import.php
+++ b/htdocs/imports/import.php
@@ -449,6 +449,8 @@ if ($step == 2 && $datatoimport)
if ($step == 3 && $datatoimport)
{
+ $liste=$objmodelimport->liste_modeles($db);
+
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
$param='step=3&datatoimport='.$datatoimport.'&format='.$format;
@@ -494,7 +496,8 @@ if ($step == 3 && $datatoimport)
// Source file format
print '
| '.$langs->trans("SourceFileFormat").' | ';
print '';
- print $format;
+ $text=$objmodelimport->getDriverDesc($format);
+ print $html->textwithpicto($objmodelimport->getDriverLabel($format),$text);
print ' |
';
print '';
@@ -576,6 +579,7 @@ if ($step == 3 && $datatoimport)
if ($step == 4 && $datatoimport)
{
$model=$format;
+ $liste=$objmodelimport->liste_modeles($db);
// Create classe to use for import
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/import/";
@@ -585,19 +589,37 @@ if ($step == 4 && $datatoimport)
$obj = new $classname($db);
// Load source fields in input file
- $obj->import_open_file($dir.$file,$langs);
- $fieldssource=array(
+ $result=$obj->import_open_file($conf->import->dir_temp.'/'.$filetoimport,$langs);
+ if ($result >= 0)
+ {
+ // Read first line
+ $arrayrecord=$obj->import_read_record();
+ $fieldssource=array();
+ // Put array into an array starting with 1.
+ $i=1;
+ foreach($arrayrecord as $key => $val)
+ {
+ $newval=dol_trunc($val,24);
+ // Autodetect format (UTF8 or ISO)
+ if (utf8_check($val)) $fieldssource[$i]['example1']=$newval;
+ else $fieldssource[$i]['example1']=utf8_encode($newval);
+ $i++;
+ }
+ $obj->import_close_file();
+ }
+
+/*$fieldssource=array(
1=>array('name'=>'aa','example1'=>'val1','example2'=>'val2'),
2=>array('name'=>'bb','example1'=>'valb1','example2'=>'valb2'),
3=>array('name'=>'cc','example1'=>'valc1','example2'=>'valc2'),
-/* 4=>array('name'=>'dd','example1'=>'valc1','example2'=>'valc2'),
+ 4=>array('name'=>'dd','example1'=>'valc1','example2'=>'valc2'),
5=>array('name'=>'ee','example1'=>'valc1','example2'=>'valc2'),
6=>array('name'=>'ff','example1'=>'valc1','example2'=>'valc2'),
7=>array('name'=>'gg','example1'=>'valc1','example2'=>'valc2'),
8=>array('name'=>'hh','example1'=>'valc1','example2'=>'valc2'),
9=>array('name'=>'ii','example1'=>'valc1','example2'=>'valc2'),
-*/ );
- $obj->import_close_file();
+ );
+*/
// Load targets fields in database
$fieldstarget=$objimport->array_import_fields[0];
@@ -689,7 +711,8 @@ if ($step == 4 && $datatoimport)
// Source file format
print '| '.$langs->trans("SourceFileFormat").' | ';
print '';
- print $format;
+ $text=$objmodelimport->getDriverDesc($format);
+ print $html->textwithpicto($objmodelimport->getDriverLabel($format),$text);
print ' |
';
// File to import
@@ -803,7 +826,11 @@ if ($step == 4 && $datatoimport)
if ($mandatoryfieldshavesource) $mandatoryfieldshavesource=(! empty($valforsourcefieldnb[$i]) && ($valforsourcefieldnb[$i] <= sizeof($fieldssource)));
//print 'xx'.($i).'-'.$valforsourcefieldnb[$i].'-'.$mandatoryfieldshavesource;
}
- $htmltext=$langs->trans("Table").": ".$tablename."
".$langs->trans("Field").': '.$code;
+ $htmltext =$langs->trans("Table").": ".$tablename."
";
+ $htmltext.=$langs->trans("Field").': '.$code."
";
+ $htmltext.=$langs->trans("Required").': '.yn(eregi('\*$',$label)).'';
+ $note='';
+ if ($note) $htmltext.=$langs->trans("Note").': '.$note;
$text.=$more;
print $html->textwithpicto($text,$htmltext);
print '';
@@ -1203,8 +1230,8 @@ function show_elem($fieldssource,$i,$pos,$key,$var)
print img_picto($langs->trans("MoveField",$pos),'uparrow','class="boxhandle" style="cursor:move;"');
print '';
print '';
- print $langs->trans("Field").' '.$pos.': ';
- print ''.$fieldssource[$pos]['name'].' ('.$fieldssource[$pos]['example1'].')';
+ print $langs->trans("Field").' '.$pos;
+ if (isset($fieldssource[$pos]['example1'])) print ' ('.$fieldssource[$pos]['example1'].')';
print ' | ';
}
print '';
diff --git a/htdocs/includes/modules/export/export_csv.modules.php b/htdocs/includes/modules/export/export_csv.modules.php
index e26e6cc92ea..cd12da1be73 100644
--- a/htdocs/includes/modules/export/export_csv.modules.php
+++ b/htdocs/includes/modules/export/export_csv.modules.php
@@ -59,11 +59,11 @@ class ExportCsv extends ModeleExports
$this->separator=',';
if (! empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->EXPORT_CSV_SEPARATOR_TO_USE;
$this->escape='"';
- $this->string='"';
+ $this->enclosure='"';
$this->id='csv'; // Same value then xxx in file name export_xxx.modules.php
$this->label='Csv'; // Label of driver
- $this->desc='Comma Separated Value file format (.csv). This is a text file format.
Fields are separated by separator [ '.$this->separator.' ]. If separator is found inside a field content, field is rounded by round character [ '.$this->string.' ]. Escape character to escape round character is [ '.$this->escape.' ].';
+ $this->desc='Comma Separated Value file format (.csv). This is a text file format.
Fields are separated by separator [ '.$this->separator.' ]. If separator is found inside a field content, field is rounded by round character [ '.$this->enclosure.' ]. Escape character to escape round character is [ '.$this->escape.' ].';
$this->extension='csv'; // Extension for generated file by this driver
$this->picto='mime/other'; // Picto
$ver=split(' ','$Revision$');
diff --git a/htdocs/includes/modules/import/import_csv.modules.php b/htdocs/includes/modules/import/import_csv.modules.php
index 73193bf91ba..ac361ba24bf 100644
--- a/htdocs/includes/modules/import/import_csv.modules.php
+++ b/htdocs/includes/modules/import/import_csv.modules.php
@@ -58,12 +58,12 @@ class ImportCsv extends ModeleImports
$this->separator=',';
if (! empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->EXPORT_CSV_SEPARATOR_TO_USE;
+ $this->enclosure='"';
$this->escape='"';
- $this->string='"';
$this->id='csv'; // Same value then xxx in file name export_xxx.modules.php
$this->label='Csv'; // Label of driver
- $this->desc='Comma Separated Value file format (.csv). This is a text file format.
Fields are separated by separator [ '.$this->separator.' ]. If separator is found inside a field content, field is rounded by round character [ '.$this->string.' ]. Escape character to escape round character is [ '.$this->escape.' ].';
+ $this->desc='Comma Separated Value file format (.csv). This is a text file format.
Fields are separated by separator [ '.$this->separator.' ]. If separator is found inside a field content, field is rounded by round character [ '.$this->enclosure.' ]. Escape character to escape round character is [ '.$this->escape.' ].';
$this->extension='csv'; // Extension for generated file by this driver
$this->picto='mime/other'; // Picto
$ver=split(' ','$Revision$');
@@ -172,6 +172,10 @@ class ImportCsv extends ModeleImports
$this->error=$langs->trans("ErrorFailToOpenFile",$file);
$ret=-1;
}
+ else
+ {
+ $this->file=$file;
+ }
return $ret;
}
@@ -188,31 +192,29 @@ class ImportCsv extends ModeleImports
/**
* \brief Input record line from file
*/
- function import_read_record($array_alias,$array_selected_sorted,$objp)
+ function import_read_record()
{
global $conf;
- if (! empty($conf->global->EXPORT_CSV_FORCE_CHARSET)) $outputlangs->charset_output=$conf->global->EXPORT_CSV_FORCE_CHARSET;
+ //$importlang=new Translate($this->db);
+ //if (! empty($conf->global->IMPORT_CSV_FORCE_CHARSET)) $importlang->charset_output=$conf->global->IMPORT_CSV_FORCE_CHARSET;
- $this->col=0;
- foreach($array_selected_sorted as $code => $value)
- {
- $alias=$array_alias[$code];
- if (empty($alias)) dol_print_error('','Bad value for field with code='.$code.'. Try to redefine export.');
- $newvalue=$outputlangs->convToOutputCharset($objp->$alias);
-
- // Translation newvalue
- if (eregi('^\((.*)\)$',$newvalue,$reg))
- {
- $newvalue=$outputlangs->transnoentities($reg[1]);
- }
-
- $newvalue=$this->csv_clean($newvalue);
-
- fwrite($this->handle,$newvalue.$this->separator);
- $this->col++;
+ $arrayres=array();
+ if (version_compare(phpversion(), '5.3') < 0)
+ {
+ $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure);
}
- fwrite($this->handle,"\n");
- return 0;
+ else
+ {
+ $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
+ }
+// var_dump($this->handle);
+ //var_dump($arrayres);exit;
+ if ($arrayres && is_array($arrayres))
+ {
+ $this->col=sizeof($arrayres);
+ }
+
+ return $arrayres;
}
/**