diff --git a/htdocs/imports/import.class.php b/htdocs/imports/import.class.php index f779dbca535..3fe89416617 100644 --- a/htdocs/imports/import.class.php +++ b/htdocs/imports/import.class.php @@ -1,6 +1,5 @@ - * Copyright (C) 2009 Laurent Destailleur +/* Copyright (C) 2009 Laurent Destailleur * * 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 2df17bc460b..c5f00ca11fc 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 ''; if ($objimport->array_import_perms[$key]) { - print ''.img_picto($langs->trans("NewImport"),'filenew').''; + print ''.img_picto($langs->trans("NewImport"),'filenew').''; } 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 ''.img_picto_common($key,$objmodelimport->getPicto($key)).''; $text=$objmodelimport->getDriverDesc($key); print ''.$html->textwithpicto($objmodelimport->getDriverLabel($key),$text).''; - print ''.$langs->trans("DownloadEmptyExample").''; + print ''.$langs->trans("DownloadEmptyExample").''; // Action button print ''; - print ''.img_picto($langs->trans("SelectFormat"),'filenew').''; + print ''.img_picto($langs->trans("SelectFormat"),'filenew').''; print ''; print ''; } @@ -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 ''; $text=$objmodelimport->getDriverDesc($format); print $html->textwithpicto($objmodelimport->getDriverLabel($format),$text); - print ''.$langs->trans("DownloadEmptyExample").''; + print ''.$langs->trans("DownloadEmptyExample").''; print ''; @@ -536,6 +541,7 @@ if ($step == 3 && $datatoimport) print ''; print ''; print ''; + print ''; print ''; print "\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 ''; print ''.img_mime($file).''; print ''; - $param='format='.$format.'&datatoimport='.$datatoimport; $modulepart='import'; //$relativepath=$filetoimport; - print ''; + print ''; print $file; print ''; print ''; @@ -576,12 +581,12 @@ if ($step == 3 && $datatoimport) // Affiche date fichier print ''.dol_print_date(dol_filemtime($dir.'/'.$file),'dayhour').''; // Del button - print ''.img_delete().''; // Action button print ''; - print ''.img_picto($langs->trans("NewImport"),'filenew').''; + print ''.img_picto($langs->trans("NewImport"),'filenew').''; print ''; print ''; } @@ -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 ''.$langs->trans("FileToImport").''; print ''; - $param='format='.$format.'&datatoimport='.$datatoimport; $modulepart='import'; //$relativepath=$filetoimport; - print ''; + print ''; print $filetoimport; print ''; print ''; @@ -750,6 +755,7 @@ if ($step == 4 && $datatoimport) print ''; print ''; print ''; + print ''; print ''; @@ -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 ''; @@ -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 ''; print '
'; 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 ''.$langs->trans("NextStep").''; + print ''.$langs->trans("NextStep").''; } else { @@ -1021,7 +1027,7 @@ if ($step == 4 && $datatoimport) print '
'; print $obj->label; print ''; - print 'rowid.'&filetoimport='.urlencode($filetoimport).'">'; + print 'rowid.'&filetoimport='.urlencode($filetoimport).'">'; print img_delete(); print ''; print '
'; print ''; + print ' onClick="javascript: window.location=\''.$_SERVER["PHP_SELF"].'?leftmenu=import&excludefirstline='.($excludefirstline?'0':'1').'&step=5'.$param2.'\';">'; print ' '.$langs->trans("DoNotImportFirstLine"); print '
'; + print ''; + + + // Show import id + print $langs->trans("NowClickToTestTheImport",$langs->transnoentitiesnoconv("RunSimulateImportFile")).'
'; print '
'; - print $langs->trans("NowClickToTestTheImport",$langs->transnoentitiesnoconv("RunSimulateImportFile")).'
'; - - print ''; // Actions print '
'; @@ -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 ''; print ''; - print '
'; - // 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 ''; + + // If no errors and no warnings if (! sizeof($arrayoferrors) && ! sizeof($arrayofwarnings)) print img_tick().' '.$langs->trans("NoErrors").'
'; - // Errors + // Show Errors //var_dump($arrayoferrors); if (sizeof($arrayoferrors)) { print img_error().' '.$langs->trans("ErrorsOnXLines",sizeof($arrayoferrors)).'
'; - //print '
'; + print '
'; foreach ($arrayoferrors as $key => $val) { $nboferrors++; @@ -1511,17 +1514,17 @@ if ($step == 6 && $datatoimport) print '     > '.$err['lib'].'
'; } } - //print '
'; + print '
'; print '
'; } - // Warnings + // Show Warnings //var_dump($arrayoferrors); if (sizeof($arrayofwarnings)) { print img_warning().' '.$langs->trans("WarningsOnXLines",sizeof($arrayofwarnings)).'
'; - //print '
'; + print '
'; foreach ($arrayofwarnings as $key => $val) { $nbofwarnings++; @@ -1536,19 +1539,19 @@ if ($step == 6 && $datatoimport) print '     > '.$err['lib'].'
'; } } - //print '
'; + print '
'; print '
'; } + // Show import id $importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S'); - print '
'; print '
'; print $langs->trans("NowClickToRunTheImport",$langs->transnoentitiesnoconv("RunImportFile")).'
'; print $langs->trans("DataLoadedWithId",$importid).'
'; print '
'; - print ''; + print '
'; // Actions print '
'; @@ -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 ''; print ''; - print '
'; - // 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 '
'; - print '
'; - print $langs->trans("xxxx",$importid).'
'; - print '
'; + if (sizeof($arrayoferrors) > 0) $db->rollback(); // We force rollback because this was errors. + else $db->commit(); // We can commit if no errors. print ''; + + // Show result + print '
'; + print '
'; + print $langs->trans("FileWasImported",$importid).'
'; + print $langs->trans("YouCanUseImportIdToFindRecord",$importid).'
'; + print '
'; + 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 fc66fb72feb..9a94de8a8c6 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 2fd72389ab4..1c7d6c6baf7 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 5979b1a8908..73b2071fce7 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -54,5 +54,6 @@ WarningConfFileMustBeReadOnly=Warning, your config file (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 % en provide the error code %s in your message, or even better by adding a screen copy of this page. +ErrorWrongValueForField=Wrong value for field number %s (value '%s' does not match regex rule %s) ErrorsOnXLines=Errors on %s source lines -WarningsOnXLines=Warnings on %s source lines \ No newline at end of file +WarningsOnXLines=Warnings on %s source lines diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 531cd3f23fb..a341b9c519d 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: %s ErrorMissingMandatoryValue=Mandatory data is empty in source file for field %s. TooMuchErrors=There is still %s other source lines with errors but output has been limited. TooMuchWarnings=There is still %s 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 import_key='%s'. + diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index 053e71bd83d..388b10a7570 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 (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 %s en lui indiquant le code erreur %s dans votre message ou mieux en fournissant une copie d'écran de cette page. -ErrorsOnXLines=Erreurs sur %s lines sources -WarningsOnXLines=Alertes sur %s lines sources \ No newline at end of file +ErrorWrongValueForField=Mauvaise valeur pour le champ numéro %s (la valeur '%s' ne respecte pas la règle %s) +ErrorsOnXLines=Erreurs sur %s lignes sources +WarningsOnXLines=Alertes sur %s 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 2a0df76793b..2a26d978606 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 %s. TooMuchErrors=Il y a encore %s autres lignes en erreur mais leur affichage a été limité. TooMuchWarnings=Il y a encore %s 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 %s. +YouCanUseImportIdToFindRecord=Vous pourrez retrouver les enregistrements issus de cet import dans votre base par un filtrage sur le champ import_key='%s'.