diff --git a/htdocs/imports/import.class.php b/htdocs/imports/import.class.php index f779dbca5356ddbcc252a29193ec1dd42cb1c120..3fe89416617392a0a452d7a3bb9096057d1cd455 100644 --- a/htdocs/imports/import.class.php +++ b/htdocs/imports/import.class.php @@ -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++; diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 2df17bc460bda5f9f90fa06db6869d5eab205882..c5f00ca11fc049706867e5892fc7360340b5bf4b 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -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ó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ó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ó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 '&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ó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ó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 '<br>'; + print '</div>'; + + // Show import id print $langs->trans("NowClickToTestTheImport",$langs->transnoentitiesnoconv("RunSimulateImportFile")).'<br>'; + print '<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 ' > '.$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 ' > '.$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. - + if (sizeof($arrayoferrors) > 0) $db->rollback(); // We force rollback because this was errors. + else $db->commit(); // We can commit if no errors. - // TODO Show result + print '</div>'; + // Show result print '<br>'; print '<center>'; - print $langs->trans("xxxx",$importid).'<br>'; + print $langs->trans("FileWasImported",$importid).'<br>'; + print $langs->trans("YouCanUseImportIdToFindRecord",$importid).'<br>'; print '</center>'; - print '</div>'; - if ($mesg) print $mesg; } diff --git a/htdocs/includes/modules/import/import_csv.modules.php b/htdocs/includes/modules/import/import_csv.modules.php index fc66fb72feb6663e6ad4b078407dfc98f615d40b..9a94de8a8c61594c38deead6a85e6649f88529c8 100644 --- a/htdocs/includes/modules/import/import_csv.modules.php +++ b/htdocs/includes/modules/import/import_csv.modules.php @@ -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); diff --git a/htdocs/includes/modules/modProduit.class.php b/htdocs/includes/modules/modProduit.class.php index 2fd72389ab48e80ae8dccd660bca430471d4a3b6..1c7d6c6baf72c222d9b27d506115aba0e2fa64ab 100644 --- a/htdocs/includes/modules/modProduit.class.php +++ b/htdocs/includes/modules/modProduit.class.php @@ -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'); } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 5979b1a89083857066c53bd785f2ac1c7d346245..73b2071fce74a2f26323ba3e2fe080d51184ed75 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -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 \ No newline at end of file +WarningsOnXLines=Warnings on <b>%s</b> source lines diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 531cd3f23fbd6e1dc076efbe0c39668c54e41e93..a341b9c519d570633779d93148e2ed398cecd12f 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -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. \ No newline at end of file +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>. + diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 053e71bd83d33b79de45b2a1fbc26e7bf437211e..388b10a757026c831bd8a2c54edac1490104ed12 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/htdocs/langs/fr_FR/exports.lang b/htdocs/langs/fr_FR/exports.lang index 2a0df76793b45eae9ed9d76702dbbb39a08f5045..2a26d978606c8bf4a63f1508c0c718235dede92d 100644 --- a/htdocs/langs/fr_FR/exports.lang +++ b/htdocs/langs/fr_FR/exports.lang @@ -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>.