Skip to content
Snippets Groups Projects
Commit 1addc14a authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Work on import module

parent 8904424e
No related branches found
No related tags found
No related merge requests found
...@@ -449,6 +449,8 @@ if ($step == 2 && $datatoimport) ...@@ -449,6 +449,8 @@ if ($step == 2 && $datatoimport)
if ($step == 3 && $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'); llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
$param='step=3&datatoimport='.$datatoimport.'&format='.$format; $param='step=3&datatoimport='.$datatoimport.'&format='.$format;
...@@ -494,7 +496,8 @@ if ($step == 3 && $datatoimport) ...@@ -494,7 +496,8 @@ if ($step == 3 && $datatoimport)
// Source file format // Source file format
print '<tr><td width="25%">'.$langs->trans("SourceFileFormat").'</td>'; print '<tr><td width="25%">'.$langs->trans("SourceFileFormat").'</td>';
print '<td>'; print '<td>';
print $format; $text=$objmodelimport->getDriverDesc($format);
print $html->textwithpicto($objmodelimport->getDriverLabel($format),$text);
print '</td></tr>'; print '</td></tr>';
print '</table>'; print '</table>';
...@@ -576,6 +579,7 @@ if ($step == 3 && $datatoimport) ...@@ -576,6 +579,7 @@ if ($step == 3 && $datatoimport)
if ($step == 4 && $datatoimport) if ($step == 4 && $datatoimport)
{ {
$model=$format; $model=$format;
$liste=$objmodelimport->liste_modeles($db);
// Create classe to use for import // Create classe to use for import
$dir = DOL_DOCUMENT_ROOT . "/includes/modules/import/"; $dir = DOL_DOCUMENT_ROOT . "/includes/modules/import/";
...@@ -585,19 +589,37 @@ if ($step == 4 && $datatoimport) ...@@ -585,19 +589,37 @@ if ($step == 4 && $datatoimport)
$obj = new $classname($db); $obj = new $classname($db);
// Load source fields in input file // Load source fields in input file
$obj->import_open_file($dir.$file,$langs); $result=$obj->import_open_file($conf->import->dir_temp.'/'.$filetoimport,$langs);
$fieldssource=array( 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'), 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'), 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'), 5=>array('name'=>'ee','example1'=>'valc1','example2'=>'valc2'),
6=>array('name'=>'ff','example1'=>'valc1','example2'=>'valc2'), 6=>array('name'=>'ff','example1'=>'valc1','example2'=>'valc2'),
7=>array('name'=>'gg','example1'=>'valc1','example2'=>'valc2'), 7=>array('name'=>'gg','example1'=>'valc1','example2'=>'valc2'),
8=>array('name'=>'hh','example1'=>'valc1','example2'=>'valc2'), 8=>array('name'=>'hh','example1'=>'valc1','example2'=>'valc2'),
9=>array('name'=>'ii','example1'=>'valc1','example2'=>'valc2'), 9=>array('name'=>'ii','example1'=>'valc1','example2'=>'valc2'),
*/ ); );
$obj->import_close_file(); */
// Load targets fields in database // Load targets fields in database
$fieldstarget=$objimport->array_import_fields[0]; $fieldstarget=$objimport->array_import_fields[0];
...@@ -689,7 +711,8 @@ if ($step == 4 && $datatoimport) ...@@ -689,7 +711,8 @@ if ($step == 4 && $datatoimport)
// Source file format // Source file format
print '<tr><td width="25%">'.$langs->trans("SourceFileFormat").'</td>'; print '<tr><td width="25%">'.$langs->trans("SourceFileFormat").'</td>';
print '<td>'; print '<td>';
print $format; $text=$objmodelimport->getDriverDesc($format);
print $html->textwithpicto($objmodelimport->getDriverLabel($format),$text);
print '</td></tr>'; print '</td></tr>';
// File to import // File to import
...@@ -803,7 +826,11 @@ if ($step == 4 && $datatoimport) ...@@ -803,7 +826,11 @@ if ($step == 4 && $datatoimport)
if ($mandatoryfieldshavesource) $mandatoryfieldshavesource=(! empty($valforsourcefieldnb[$i]) && ($valforsourcefieldnb[$i] <= sizeof($fieldssource))); if ($mandatoryfieldshavesource) $mandatoryfieldshavesource=(! empty($valforsourcefieldnb[$i]) && ($valforsourcefieldnb[$i] <= sizeof($fieldssource)));
//print 'xx'.($i).'-'.$valforsourcefieldnb[$i].'-'.$mandatoryfieldshavesource; //print 'xx'.($i).'-'.$valforsourcefieldnb[$i].'-'.$mandatoryfieldshavesource;
} }
$htmltext=$langs->trans("Table").": ".$tablename."<br>".$langs->trans("Field").': '.$code; $htmltext =$langs->trans("Table").": <b>".$tablename."</b><br>";
$htmltext.=$langs->trans("Field").': <b>'.$code."</b><br>";
$htmltext.=$langs->trans("Required").': <b>'.yn(eregi('\*$',$label)).'</b>';
$note='';
if ($note) $htmltext.=$langs->trans("Note").': '.$note;
$text.=$more; $text.=$more;
print $html->textwithpicto($text,$htmltext); print $html->textwithpicto($text,$htmltext);
print '</td>'; print '</td>';
...@@ -1203,8 +1230,8 @@ function show_elem($fieldssource,$i,$pos,$key,$var) ...@@ -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 img_picto($langs->trans("MoveField",$pos),'uparrow','class="boxhandle" style="cursor:move;"');
print '</td>'; print '</td>';
print '<td style="font-weight: normal">'; print '<td style="font-weight: normal">';
print $langs->trans("Field").' '.$pos.': '; print $langs->trans("Field").' '.$pos;
print '<b>'.$fieldssource[$pos]['name'].'</b> ('.$fieldssource[$pos]['example1'].')'; if (isset($fieldssource[$pos]['example1'])) print ' (<i>'.$fieldssource[$pos]['example1'].'</i>)';
print '</td>'; print '</td>';
} }
print '</tr>'; print '</tr>';
......
...@@ -59,11 +59,11 @@ class ExportCsv extends ModeleExports ...@@ -59,11 +59,11 @@ class ExportCsv extends ModeleExports
$this->separator=','; $this->separator=',';
if (! empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->EXPORT_CSV_SEPARATOR_TO_USE; if (! empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->EXPORT_CSV_SEPARATOR_TO_USE;
$this->escape='"'; $this->escape='"';
$this->string='"'; $this->enclosure='"';
$this->id='csv'; // Same value then xxx in file name export_xxx.modules.php $this->id='csv'; // Same value then xxx in file name export_xxx.modules.php
$this->label='Csv'; // Label of driver $this->label='Csv'; // Label of driver
$this->desc='<b>Comma Separated Value</b> file format (.csv). This is a text file format.<br>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='<b>Comma Separated Value</b> file format (.csv). This is a text file format.<br>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->extension='csv'; // Extension for generated file by this driver
$this->picto='mime/other'; // Picto $this->picto='mime/other'; // Picto
$ver=split(' ','$Revision$'); $ver=split(' ','$Revision$');
......
...@@ -58,12 +58,12 @@ class ImportCsv extends ModeleImports ...@@ -58,12 +58,12 @@ class ImportCsv extends ModeleImports
$this->separator=','; $this->separator=',';
if (! empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->EXPORT_CSV_SEPARATOR_TO_USE; if (! empty($conf->global->EXPORT_CSV_SEPARATOR_TO_USE)) $this->separator=$conf->global->EXPORT_CSV_SEPARATOR_TO_USE;
$this->enclosure='"';
$this->escape='"'; $this->escape='"';
$this->string='"';
$this->id='csv'; // Same value then xxx in file name export_xxx.modules.php $this->id='csv'; // Same value then xxx in file name export_xxx.modules.php
$this->label='Csv'; // Label of driver $this->label='Csv'; // Label of driver
$this->desc='<b>Comma Separated Value</b> file format (.csv). This is a text file format.<br>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='<b>Comma Separated Value</b> file format (.csv). This is a text file format.<br>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->extension='csv'; // Extension for generated file by this driver
$this->picto='mime/other'; // Picto $this->picto='mime/other'; // Picto
$ver=split(' ','$Revision$'); $ver=split(' ','$Revision$');
...@@ -172,6 +172,10 @@ class ImportCsv extends ModeleImports ...@@ -172,6 +172,10 @@ class ImportCsv extends ModeleImports
$this->error=$langs->trans("ErrorFailToOpenFile",$file); $this->error=$langs->trans("ErrorFailToOpenFile",$file);
$ret=-1; $ret=-1;
} }
else
{
$this->file=$file;
}
return $ret; return $ret;
} }
...@@ -188,31 +192,29 @@ class ImportCsv extends ModeleImports ...@@ -188,31 +192,29 @@ class ImportCsv extends ModeleImports
/** /**
* \brief Input record line from file * \brief Input record line from file
*/ */
function import_read_record($array_alias,$array_selected_sorted,$objp) function import_read_record()
{ {
global $conf; 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; $arrayres=array();
foreach($array_selected_sorted as $code => $value) if (version_compare(phpversion(), '5.3') < 0)
{ {
$alias=$array_alias[$code]; $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure);
if (empty($alias)) dol_print_error('','Bad value for field with code='.$code.'. Try to redefine export.'); }
$newvalue=$outputlangs->convToOutputCharset($objp->$alias); else
// Translation newvalue
if (eregi('^\((.*)\)$',$newvalue,$reg))
{ {
$newvalue=$outputlangs->transnoentities($reg[1]); $arrayres=fgetcsv($this->handle,100000,$this->separator,$this->enclosure,$this->escape);
} }
// var_dump($this->handle);
$newvalue=$this->csv_clean($newvalue); //var_dump($arrayres);exit;
if ($arrayres && is_array($arrayres))
fwrite($this->handle,$newvalue.$this->separator); {
$this->col++; $this->col=sizeof($arrayres);
} }
fwrite($this->handle,"\n");
return 0; return $arrayres;
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment