Work on import module

This commit is contained in:
Laurent Destailleur 2009-10-17 13:12:55 +00:00
parent 9f419a7d50
commit b8e871d97f
8 changed files with 134 additions and 125 deletions

View File

@ -1,6 +1,5 @@
<?php
/* Copyright (C) 2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -38,9 +37,8 @@ class Import
var $array_import_tables;
var $array_import_fields;
var $array_import_entities;
var $array_import_regex;
var $array_import_examplevalues;
//var $array_import_sql_start;
//var $array_import_sql_end;
/**
@ -141,16 +139,16 @@ class Import
$this->array_import_label[$i]=$module->getDatasetLabel($r);
// Array of tables to import (key=alias, value=tablename)
$this->array_import_tables[$i]=$module->import_tables_array[$r];
// Array of tables creator field to import (key=alias, value=creator field)
$this->array_import_tables_creator[$i]=$module->import_tables_creator_array[$r];
// Array of fiels to import (key=field, value=label)
$this->array_import_fields[$i]=$module->import_fields_array[$r];
// Tableau des entites a exporter (cle=champ, valeur=entite)
$this->array_import_entities[$i]=$module->import_entities_array[$r];
// Tableau des alias a exporter (cle=champ, valeur=alias)
$this->array_import_regex[$i]=$module->import_regex_array[$r];
// Tableau des alias a exporter (cle=champ, valeur=alias)
$this->array_import_examplevalues[$i]=$module->import_examplevalues_array[$r];
// Requete sql du dataset
//$this->array_import_sql_start[$i]=$module->import_sql_start[$r];
//$this->array_import_sql_end[$i]=$module->import_sql_end[$r];
//$this->array_import_sql[$i]=$module->import_sql[$r];
dol_syslog("Import loaded for module ".$modulename." with index ".$i.", dataset=".$module->import_code[$r].", nb of fields=".sizeof($module->import_fields_code[$r]));
$i++;

View File

@ -304,14 +304,14 @@ if ($step == 1 || ! $datatoimport)
$array_match_file_to_database=array();
$_SESSION["dol_array_match_file_to_database"]='';
$parm='';
if ($excludefirstline) $param.='&excludefirstline=1';
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:M&oacute;dulo_Importaciones');
/*
* Affichage onglets
*/
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1';
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1'.$param;
$head[$h][1] = $langs->trans("Step")." 1";
$hselected=$h;
$h++;
@ -352,7 +352,7 @@ if ($step == 1 || ! $datatoimport)
print '</td><td align="right">';
if ($objimport->array_import_perms[$key])
{
print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$objimport->array_import_code[$key].'">'.img_picto($langs->trans("NewImport"),'filenew').'</a>';
print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$objimport->array_import_code[$key].$param.'">'.img_picto($langs->trans("NewImport"),'filenew').'</a>';
}
else
{
@ -379,6 +379,9 @@ if ($step == 1 || ! $datatoimport)
// STEP 2: Page to select input format file
if ($step == 2 && $datatoimport)
{
$param='&datatoimport='.$datatoimport;
if ($excludefirstline) $param.='&excludefirstline=1';
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:M&oacute;dulo_Importaciones');
$h = 0;
@ -387,7 +390,7 @@ if ($step == 2 && $datatoimport)
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2'.$param;
$head[$h][1] = $langs->trans("Step")." 2";
$hselected=$h;
$h++;
@ -437,10 +440,10 @@ if ($step == 2 && $datatoimport)
print '<td width="16">'.img_picto_common($key,$objmodelimport->getPicto($key)).'</td>';
$text=$objmodelimport->getDriverDesc($key);
print '<td>'.$html->textwithpicto($objmodelimport->getDriverLabel($key),$text).'</td>';
print '<td align="center"><a href="'.DOL_URL_ROOT.'/imports/emptyexample.php?format='.$key.'&datatoimport='.$datatoimport.'" target="_blank">'.$langs->trans("DownloadEmptyExample").'</a></td>';
print '<td align="center"><a href="'.DOL_URL_ROOT.'/imports/emptyexample.php?format='.$key.$param.'" target="_blank">'.$langs->trans("DownloadEmptyExample").'</a></td>';
// Action button
print '<td align="right">';
print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=3&datatoimport='.$datatoimport.'&format='.$key.'">'.img_picto($langs->trans("SelectFormat"),'filenew').'</a>';
print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=3&format='.$key.$param.'">'.img_picto($langs->trans("SelectFormat"),'filenew').'</a>';
print '</td>';
print '</tr>';
}
@ -456,24 +459,26 @@ if ($step == 2 && $datatoimport)
// STEP 3: Page to select file
if ($step == 3 && $datatoimport)
{
$param='&datatoimport='.$datatoimport.'&format='.$format;
if ($excludefirstline) $param.='&excludefirstline=1';
$liste=$objmodelimport->liste_modeles($db);
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:M&oacute;dulo_Importaciones');
$param='step=3&datatoimport='.$datatoimport.'&format='.$format;
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1';
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1'.$param;
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2'.$param;
$head[$h][1] = $langs->trans("Step")." 2";
$hselected=$h;
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3'.$param;
$head[$h][1] = $langs->trans("Step")." 3";
$hselected=$h;
$h++;
@ -508,7 +513,7 @@ if ($step == 3 && $datatoimport)
print '<td>';
$text=$objmodelimport->getDriverDesc($format);
print $html->textwithpicto($objmodelimport->getDriverLabel($format),$text);
print '</td><td align="right" nowrap="nowrap" width="100"><a href="'.DOL_URL_ROOT.'/imports/emptyexample.php?format='.$format.'&datatoimport='.$datatoimport.'" target="_blank">'.$langs->trans("DownloadEmptyExample").'</a>';
print '</td><td align="right" nowrap="nowrap" width="100"><a href="'.DOL_URL_ROOT.'/imports/emptyexample.php?format='.$format.$param.'" target="_blank">'.$langs->trans("DownloadEmptyExample").'</a>';
print '</td></tr>';
@ -536,6 +541,7 @@ if ($step == 3 && $datatoimport)
print '<input type="submit" class="button" value="'.$langs->trans("AddFile").'" name="sendit">';
print '<input type="hidden" value="'.$step.'" name="step">';
print '<input type="hidden" value="'.$format.'" name="format">';
print '<input type="hidden" value="'.$excludefirstline.'" name="excludefirstline">';
print '<input type="hidden" value="'.$datatoimport.'" name="datatoimport">';
print "</tr>\n";
@ -558,16 +564,15 @@ if ($step == 3 && $datatoimport)
if (eregi('^\.',$file)) continue;
$modulepart='import';
$urlsource=$_SERVER["PHP_SELF"].'?step='.$step.'&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport);
$urlsource=$_SERVER["PHP_SELF"].'?step='.$step.$param.'&filetoimport='.urlencode($filetoimport);
$relativepath=$file;
$var=!$var;
print '<tr '.$bc[$var].'>';
print '<td width="16">'.img_mime($file).'</td>';
print '<td>';
$param='format='.$format.'&datatoimport='.$datatoimport;
$modulepart='import';
//$relativepath=$filetoimport;
print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&file='.urlencode($relativepath).'&step=3&format='.$format.'&datatoimport='.$datatoimport.'" target="_blank">';
print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&file='.urlencode($relativepath).'&step=3'.$param.'" target="_blank">';
print $file;
print '</a>';
print '</td>';
@ -576,12 +581,12 @@ if ($step == 3 && $datatoimport)
// Affiche date fichier
print '<td align="right">'.dol_print_date(dol_filemtime($dir.'/'.$file),'dayhour').'</td>';
// Del button
print '<td align="right"><a href="'.DOL_URL_ROOT.'/document.php?action=remove_file&step=3&format='.$format.'&modulepart='.$modulepart.'&file='.urlencode($relativepath);
print '&amp;urlsource='.urlencode($urlsource);
print '<td align="right"><a href="'.DOL_URL_ROOT.'/document.php?action=remove_file&step=3'.$param.'&modulepart='.$modulepart.'&file='.urlencode($relativepath);
print '&urlsource='.urlencode($urlsource);
print '">'.img_delete().'</a></td>';
// Action button
print '<td align="right">';
print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=4&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($relativepath).'">'.img_picto($langs->trans("NewImport"),'filenew').'</a>';
print '<a href="'.DOL_URL_ROOT.'/imports/import.php?step=4'.$param.'&filetoimport='.urlencode($relativepath).'">'.img_picto($langs->trans("NewImport"),'filenew').'</a>';
print '</td>';
print '</tr>';
}
@ -673,16 +678,17 @@ if ($step == 4 && $datatoimport)
// Now $array_match_file_to_database contains fieldnb(1,2,3...)=>fielddatabase(key in $array_match_file_to_database)
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport);
if ($excludefirstline) $param.='&excludefirstline=1';
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:M&oacute;dulo_Importaciones');
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1';
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1'.$param;
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2'.$param;
$head[$h][1] = $langs->trans("Step")." 2";
$h++;
@ -729,10 +735,9 @@ if ($step == 4 && $datatoimport)
// File to import
print '<tr><td width="25%">'.$langs->trans("FileToImport").'</td>';
print '<td>';
$param='format='.$format.'&datatoimport='.$datatoimport;
$modulepart='import';
//$relativepath=$filetoimport;
print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&file='.urlencode($relativepath).'&step=4&format='.$format.'&datatoimport='.$datatoimport.'" target="_blank">';
print '<a href="'.DOL_URL_ROOT.'/document.php?modulepart='.$modulepart.'&file='.urlencode($relativepath).'&step=4'.$param.'" target="_blank">';
print $filetoimport;
print '</a>';
print '</td></tr>';
@ -750,6 +755,7 @@ if ($step == 4 && $datatoimport)
print '<input type="hidden" name="format" value="'.$format.'">';
print '<input type="hidden" name="datatoimport" value="'.$datatoimport.'">';
print '<input type="hidden" name="filetoimport" value="'.$filetoimport.'">';
print '<input type="hidden" name="excludefirstline" value="'.$excludefirstline.'">';
print '<table><tr><td colspan="2">';
print $langs->trans("SelectImportFields",img_picto('','uparrow','')).' ';
$htmlother->select_import_model($importmodelid,'importmodelid',$datatoimport,1);
@ -921,7 +927,7 @@ if ($step == 4 && $datatoimport)
//print 'var userid = \''.$user->id.'\';'."\n";
//print 'var url = "ajaximport.php";'."\n";
//print 'var datatoimport = "'.$datatoimport.'";'."\n";
print 'var newlocation= \''.$_SERVER["PHP_SELF"].'?step=4&format='.$format.'&datatoimport='.urlencode($datatoimport).'&filetoimport='.urlencode($filetoimport).'&action=saveorder&boxorder=\' + boxorder;'."\n";
print 'var newlocation= \''.$_SERVER["PHP_SELF"].'?step=4'.$param.'&filetoimport='.urlencode($filetoimport).'&action=saveorder&boxorder=\' + boxorder;'."\n";
//print 'alert(newlocation);';
//print 'o_options = new Object();'."\n";
//print 'o_options = {asynchronous:false,method: \'get\',parameters: \'step=4&boxorder=\' + boxorder + \'&userid=\' + userid + \'&datatoimport=\' + datatoimport};'."\n";
@ -965,7 +971,7 @@ if ($step == 4 && $datatoimport)
{
if ($mandatoryfieldshavesource)
{
print '<a class="butAction" href="import.php?step=5&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'">'.$langs->trans("NextStep").'</a>';
print '<a class="butAction" href="import.php?step=5'.$param.'&filetoimport='.urlencode($filetoimport).'">'.$langs->trans("NextStep").'</a>';
}
else
{
@ -1021,7 +1027,7 @@ if ($step == 4 && $datatoimport)
print '<tr '.$bc[$var].'><td>';
print $obj->label;
print '</td><td align="right">';
print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&format='.$format.'&datatoimport='.$datatoimport.'&action=deleteprof&id='.$obj->rowid.'&filetoimport='.urlencode($filetoimport).'">';
print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.$param.'&action=deleteprof&id='.$obj->rowid.'&filetoimport='.urlencode($filetoimport).'">';
print img_delete();
print '</a>';
print '</tr>';
@ -1072,29 +1078,30 @@ if ($step == 5 && $datatoimport)
$nboflines=dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport);
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
$param2='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
if ($excludefirstline) $param.='&excludefirstline=1';
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:M&oacute;dulo_Importaciones');
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1';
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1'.$param;
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2'.$param;
$head[$h][1] = $langs->trans("Step")." 2";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3'.$param;
$head[$h][1] = $langs->trans("Step")." 3";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4'.$param;
$head[$h][1] = $langs->trans("Step")." 4";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=5&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=5'.$param;
$head[$h][1] = $langs->trans("Step")." 5";
$hselected=$h;
$h++;
@ -1152,7 +1159,7 @@ if ($step == 5 && $datatoimport)
print '</td><td>';
print '<input type="checkbox" name="excludefirstline" value="1"';
print ($excludefirstline?' checked="true"':'');
print '>';
print ' onClick="javascript: window.location=\''.$_SERVER["PHP_SELF"].'?leftmenu=import&excludefirstline='.($excludefirstline?'0':'1').'&step=5'.$param2.'\';">';
print ' '.$langs->trans("DoNotImportFirstLine");
print '</td></tr>';
@ -1219,18 +1226,20 @@ if ($step == 5 && $datatoimport)
if ($code > sizeof($fieldssource)) continue;
//print $code.'-'.$label;
$alias=eregi_replace('\..*$','',$label);
$listfields[$i]=$label;
$listfields[$i]=$langs->trans("Field").' '.$code.'->'.$label;
}
print sizeof($listfields)?(join(', ',$listfields)):$langs->trans("Error");
print '</td></tr>';
print '</table>';
print '</div>';
// Show import id
print $langs->trans("NowClickToTestTheImport",$langs->transnoentitiesnoconv("RunSimulateImportFile")).'<br>';
print '<br>';
print $langs->trans("NowClickToTestTheImport",$langs->transnoentitiesnoconv("RunSimulateImportFile")).'<br>';
print '</div>';
// Actions
print '<center>';
@ -1290,27 +1299,27 @@ if ($step == 6 && $datatoimport)
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1';
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1'.$param;
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2'.$param;
$head[$h][1] = $langs->trans("Step")." 2";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3'.$param;
$head[$h][1] = $langs->trans("Step")." 3";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4'.$param;
$head[$h][1] = $langs->trans("Step")." 4";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=5&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=5'.$param;
$head[$h][1] = $langs->trans("Step")." 5";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=6&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=6'.$param;
$head[$h][1] = $langs->trans("Step")." 6";
$hselected=$h;
$h++;
@ -1433,15 +1442,13 @@ if ($step == 6 && $datatoimport)
if ($code > sizeof($fieldssource)) continue;
//print $code.'-'.$label;
$alias=eregi_replace('\..*$','',$label);
$listfields[$i]=$label;
$listfields[$i]=$langs->trans("Field").' '.$code.'->'.$label;
}
print sizeof($listfields)?(join(', ',$listfields)):$langs->trans("Error");
print '</td></tr>';
print '</table>';
print '<br>';
// Launch import
$arrayoferrors=array();
$arrayofwarnings=array();
@ -1452,10 +1459,10 @@ if ($step == 6 && $datatoimport)
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S');
$db->begin();
//var_dump($array_match_file_to_database);
$db->begin();
// Open input file
$pathfile=$conf->import->dir_temp.'/'.$filetoimport;
$result=$obj->import_open_file($pathfile,$langs);
@ -1469,14 +1476,8 @@ if ($step == 6 && $datatoimport)
if ($excludefirstline && $sourcelinenb == 1) continue;
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,sizeof($fieldssource),$importid);
if (sizeof($obj->errors))
{
$arrayoferrors[$sourcelinenb]=$obj->errors;
}
if (sizeof($obj->warnings))
{
$arrayofwarnings[$sourcelinenb]=$obj->warnings;
}
if (sizeof($obj->errors)) $arrayoferrors[$sourcelinenb]=$obj->errors;
if (sizeof($obj->warnings)) $arrayofwarnings[$sourcelinenb]=$obj->warnings;
}
// Close file
$obj->import_close_file();
@ -1488,15 +1489,17 @@ if ($step == 6 && $datatoimport)
$db->rollback(); // We force rollback because this was just a simulation.
// If nothing
print '</div>';
// If no errors and no warnings
if (! sizeof($arrayoferrors) && ! sizeof($arrayofwarnings)) print img_tick().' <b>'.$langs->trans("NoErrors").'</b><br>';
// Errors
// Show Errors
//var_dump($arrayoferrors);
if (sizeof($arrayoferrors))
{
print img_error().' <b>'.$langs->trans("ErrorsOnXLines",sizeof($arrayoferrors)).'</b><br>';
//print '<table width="100%" class="border"><tr><td>';
print '<table width="100%" class="border"><tr><td>';
foreach ($arrayoferrors as $key => $val)
{
$nboferrors++;
@ -1511,17 +1514,17 @@ if ($step == 6 && $datatoimport)
print ' &nbsp; &nbsp; > '.$err['lib'].'<br>';
}
}
//print '</td></tr></table>';
print '</td></tr></table>';
print '<br>';
}
// Warnings
// Show Warnings
//var_dump($arrayoferrors);
if (sizeof($arrayofwarnings))
{
print img_warning().' <b>'.$langs->trans("WarningsOnXLines",sizeof($arrayofwarnings)).'</b><br>';
//print '<table width="100%" class="border"><tr><td>';
print '<table width="100%" class="border"><tr><td>';
foreach ($arrayofwarnings as $key => $val)
{
$nbofwarnings++;
@ -1536,19 +1539,19 @@ if ($step == 6 && $datatoimport)
print ' &nbsp; &nbsp; > '.$err['lib'].'<br>';
}
}
//print '</td></tr></table>';
print '</td></tr></table>';
print '<br>';
}
// Show import id
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S');
print '<br>';
print '<center>';
print $langs->trans("NowClickToRunTheImport",$langs->transnoentitiesnoconv("RunImportFile")).'<br>';
print $langs->trans("DataLoadedWithId",$importid).'<br>';
print '</center>';
print '</div>';
print '<br>';
// Actions
print '<center>';
@ -1577,7 +1580,7 @@ if ($step == 6 && $datatoimport)
// STEP 6: Result of simulation
// STEP 7: Real import
if ($step == 7 && $datatoimport)
{
$model=$format;
@ -1618,31 +1621,31 @@ if ($step == 7 && $datatoimport)
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1';
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=1'.$param;
$head[$h][1] = $langs->trans("Step")." 1";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2'.$param;
$head[$h][1] = $langs->trans("Step")." 2";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=3'.$param;
$head[$h][1] = $langs->trans("Step")." 3";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=4'.$param;
$head[$h][1] = $langs->trans("Step")." 4";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=5&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=5'.$param;
$head[$h][1] = $langs->trans("Step")." 5";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=6&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=6'.$param;
$head[$h][1] = $langs->trans("Step")." 6";
$h++;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=7&'.$param;
$head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=7'.$param;
$head[$h][1] = $langs->trans("Step")." 7";
$hselected=$h;
$h++;
@ -1764,15 +1767,13 @@ if ($step == 7 && $datatoimport)
if ($code > sizeof($fieldssource)) continue;
//print $code.'-'.$label;
$alias=eregi_replace('\..*$','',$label);
$listfields[$i]=$label;
$listfields[$i]=$langs->trans("Field").' '.$code.'->'.$label;
}
print sizeof($listfields)?(join(', ',$listfields)):$langs->trans("Error");
print '</td></tr>';
print '</table>';
print '<br>';
// Launch import
$arrayoferrors=array();
$arrayofwarnings=array();
@ -1783,10 +1784,10 @@ if ($step == 7 && $datatoimport)
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S');
$db->begin();
//var_dump($array_match_file_to_database);
$db->begin();
// Open input file
$pathfile=$conf->import->dir_temp.'/'.$filetoimport;
$result=$obj->import_open_file($pathfile,$langs);
@ -1800,14 +1801,8 @@ if ($step == 7 && $datatoimport)
if ($excludefirstline && $sourcelinenb == 1) continue;
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,sizeof($fieldssource),$importid);
if (sizeof($obj->errors))
{
$arrayoferrors[$sourcelinenb]=$obj->errors;
}
if (sizeof($obj->warnings))
{
$arrayofwarnings[$sourcelinenb]=$obj->warnings;
}
if (sizeof($obj->errors)) $arrayoferrors[$sourcelinenb]=$obj->errors;
if (sizeof($obj->warnings)) $arrayofwarnings[$sourcelinenb]=$obj->warnings;
}
// Close file
$obj->import_close_file();
@ -1817,19 +1812,19 @@ if ($step == 7 && $datatoimport)
print $langs->trans("ErrorFailedToOpenFile",$pathfile);
}
$db->rollback(); // We force rollback because this was just a simulation.
// TODO Show result
print '<br>';
print '<center>';
print $langs->trans("xxxx",$importid).'<br>';
print '</center>';
if (sizeof($arrayoferrors) > 0) $db->rollback(); // We force rollback because this was errors.
else $db->commit(); // We can commit if no errors.
print '</div>';
// Show result
print '<br>';
print '<center>';
print $langs->trans("FileWasImported",$importid).'<br>';
print $langs->trans("YouCanUseImportIdToFindRecord",$importid).'<br>';
print '</center>';
if ($mesg) print $mesg;
}

View File

@ -272,7 +272,7 @@ class ImportCsv extends ModeleImports
*/
function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid)
{
global $langs,$conf;
global $langs,$conf,$user;
$error=0;
$warning=0;
@ -298,7 +298,7 @@ class ImportCsv extends ModeleImports
else
{
// For each table to insert, me make a separate insert
foreach($objimport->array_import_tables[0] as $alias=>$tablename)
foreach($objimport->array_import_tables[0] as $alias => $tablename)
{
// Build sql request
$sql='';
@ -338,12 +338,19 @@ class ImportCsv extends ModeleImports
$errorforthistable++;
$error++;
}
// Test format
// TODO
// Other tests
// TODO...
// Test format only if field is not a missing mandatory field
else {
if (! empty($objimport->array_import_regex[0][$val]) && ! eregi($objimport->array_import_regex[0][$val],$newval))
{
$this->errors[$error]['lib']=$langs->trans('ErrorWrongValueForField',$key,$newval,$objimport->array_import_regex[0][$val]);
$this->errors[$error]['type']='REGEX';
$errorforthistable++;
$error++;
}
// Other tests
// ...
}
}
$i++;
}
@ -351,7 +358,12 @@ class ImportCsv extends ModeleImports
{
if ($listfields)
{
$sql='INSERT INTO '.$tablename.'('.$listfields.', import_key) VALUES('.$listvalues.", '".$importid."')";
// Build SQL request
$sql ='INSERT INTO '.$tablename.'('.$listfields.', import_key';
if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$objimport->array_import_tables_creator[0][$alias];
$sql.=') VALUES('.$listvalues.", '".$importid."'";
if (! empty($objimport->array_import_tables_creator[0][$alias])) $sql.=', '.$user->id;
$sql.=')';
dol_syslog("import_csv.modules sql=".$sql);
//print '> '.join(',',$arrayrecord);

View File

@ -152,15 +152,13 @@ class modProduit extends DolibarrModules
$r++;
$this->import_code[$r]=$this->rights_class.'_'.$r;
$this->import_label[$r]="Products"; // Translation key
//$this->import_permission[$r]=array(array("societe","import"));
$this->import_tables_array[$r]=array('p'=>MAIN_DB_PREFIX.'product');
$this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.envente'=>"OnSell*",'p.duration'=>"Duration");
$this->import_entities_array[$r]=array('p.ref'=>"product",'p.label'=>"product",'p.description'=>"product",'p.note'=>"product",'p.price'=>"product",'p.price_ttc'=>"product",'p.tva_tx'=>'product','p.envente'=>"product",'p.duration'=>"product");
$this->import_examplevalues_array[$r]=array('p.ref'=>"PR123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.envente'=>"0 or 1",'p.duration'=>"1y");
//$this->import_sql_start[$r]='INSERT INTO '.MAIN_DB_PREFIX.'product as p';
//$this->import_sql_end[$r] ='';
$this->import_tables_creator_array[$r]=array('p'=>'fk_user_author'); // Fields to store import user id
$this->import_fields_array[$r]=array('p.ref'=>"Ref*",'p.label'=>"Label*",'p.description'=>"Description",'p.note'=>"Note",'p.price'=>"SellingPriceHT",'p.price_ttc'=>"SellingPriceTTC",'p.tva_tx'=>'VAT','p.envente'=>"OnSell*",'p.fk_product_type'=>"Type*",'p.finished'=>'Nature','p.duration'=>"Duration",'p.weight'=>"Weight",'p.volume'=>"Volume",'p.datec'=>'DateCreation*');
//if ($conf->barcode->enabled) $this->import_fields_array[$r]=
$this->import_entities_array[$r]=array('p.ref'=>"product",'p.label'=>"product",'p.description'=>"product",'p.note'=>"product",'p.price'=>"product",'p.price_ttc'=>"product",'p.tva_tx'=>'product','p.envente'=>"product",'p.fk_product_type'=>"product",'p.finished'=>"product",'p.duration'=>"product",'p.weight'=>'product','p.volume'=>'product','p.datec'=>"product");
$this->import_regex_array[$r]=array('p.ref'=>'[^ ]','p.envente'=>'^[0|1]','p.fk_product_type'=>'^[0|1]','p.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$');
$this->import_examplevalues_array[$r]=array('p.ref'=>"PR123456",'p.label'=>"My product",'p.description'=>"This is a description example for record",'p.note'=>"Some note",'p.price'=>"100",'p.price_ttc'=>"110",'p.tva_tx'=>'10','p.envente'=>"0 or 1",'p.fk_product_type'=>"0 for product, 1 for service",'p.finished'=>'','p.duration'=>"1y",'p.datec'=>'2008-12-31');
}

View File

@ -54,5 +54,6 @@ WarningConfFileMustBeReadOnly=Warning, your config file (<b>htdocs/conf/conf.php
ErrorModuleRequireJavascript=Javascript must not be disabled to have this feature working. To enable/disable Javascript, go to menu Home->Setup->Display.
ErrorPasswordsMustMatch=Both typed passwords must match each other
ErrorContactEMail=A technical error occured. Please, contact administrator to folowwing email <b>%</b> en provide the error code <b>%s</b> in your message, or even better by adding a screen copy of this page.
ErrorWrongValueForField=Wrong value for field number <b>%s</b> (value '<b>%s</b>' does not match regex rule <b>%s</b>)
ErrorsOnXLines=Errors on <b>%s</b> source lines
WarningsOnXLines=Warnings on <b>%s</b> source lines
WarningsOnXLines=Warnings on <b>%s</b> source lines

View File

@ -89,5 +89,7 @@ DataLoadedWithId=All data will be loaded with the following import id: <b>%s<b>
ErrorMissingMandatoryValue=Mandatory data is empty in source file for field <b>%s</b>.
TooMuchErrors=There is still <b>%s</b> other source lines with errors but output has been limited.
TooMuchWarnings=There is still <b>%s</b> other source lines with warnings but output has been limited.
EmptyLine=Empty line
CorrectErrorBeforeRunningImport=You must first correct all errors before running definitive import.
EmptyLine=Empty line (will be discarded)
CorrectErrorBeforeRunningImport=You must first correct all errors before running definitive import.
YouCanUseImportIdToFindRecord=You can find all imported records in your database by filtering on field <b>import_key='%s'</b>.

View File

@ -55,5 +55,6 @@ WarningConfFileMustBeReadOnly=Attention, votre fichier de configuration (<b>htdo
ErrorModuleRequireJavascript=Le javascript ne doit pas etre désactivé pour que cette fonctionnalité soit utilisable. Pour activer/désactiver l'utilisation de javascript, aller dans le menu Accueil->Configuration->Affichage.
ErrorPasswordsMustMatch=Les 2 mots de passe saisis doivent correspondre
ErrorContactEMail=Une erreur technique est apparue. Merci de contacter l'administrateur à l'email suivant <b>%s</b> en lui indiquant le code erreur <b>%s</b> dans votre message ou mieux en fournissant une copie d'écran de cette page.
ErrorsOnXLines=Erreurs sur <b>%s</b> lines sources
WarningsOnXLines=Alertes sur <b>%s</b> lines sources
ErrorWrongValueForField=Mauvaise valeur pour le champ numéro <b>%s</b> (la valeur '<b>%s</b>' ne respecte pas la règle <b>%s</b>)
ErrorsOnXLines=Erreurs sur <b>%s</b> lignes sources
WarningsOnXLines=Alertes sur <b>%s</b> lignes sources

View File

@ -89,5 +89,7 @@ DataLoadedWithId=Toutes les données seront importées avec l'id d'import suivan
ErrorMissingMandatoryValue=Donnée obligatoire non renseignées dans le fichier source, champ numéro <b>%s</b>.
TooMuchErrors=Il y a encore <b>%s</b> autres lignes en erreur mais leur affichage a été limité.
TooMuchWarnings=Il y a encore <b>%s</b> autres lignes en warnings mais leur affichage a été limité.
EmptyLine=Ligne vide
EmptyLine=Ligne vide (sera ignorée)
CorrectErrorBeforeRunningImport=Vous devez d'abord corriger toutes les erreurs avant de pouvoir lancer l'import définitif.
FileWasImported=Le fichier a été importé sous le numéro d'import <b>%s</b>.
YouCanUseImportIdToFindRecord=Vous pourrez retrouver les enregistrements issus de cet import dans votre base par un filtrage sur le champ <b>import_key='%s'</b>.