diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 9b8ce75afc4..a6e889cba47 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -32,6 +32,7 @@ require_once(DOL_DOCUMENT_ROOT.'/includes/modules/import/modules_import.php'); require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); $langs->load("exports"); +$langs->load("errors"); if (! $user->societe_id == 0) @@ -566,7 +567,7 @@ if ($step == 3 && $datatoimport) $param='format='.$format.'&datatoimport='.$datatoimport; $modulepart='import'; //$relativepath=$filetoimport; - print ''; + print ''; print $file; print ''; print ''; @@ -731,7 +732,7 @@ if ($step == 4 && $datatoimport) $param='format='.$format.'&datatoimport='.$datatoimport; $modulepart='import'; //$relativepath=$filetoimport; - print ''; + print ''; print $filetoimport; print ''; print ''; @@ -847,8 +848,8 @@ if ($step == 4 && $datatoimport) $htmltext =$langs->trans("Table").": ".$tablename."
"; $htmltext.=$langs->trans("Field").': '.$code."
"; $htmltext.=$langs->trans("Required").': '.yn(eregi('\*$',$label)).''; - $note=''; - if ($note) $htmltext.=$langs->trans("Note").': '.$note; + $note=$objimport->array_import_examplevalues[0][$code]; + if ($note) $htmltext.='
'.$langs->trans("Note").'/'.$langs->trans("Example").': '.$note; $text.=$more; print $html->textwithpicto($text,$htmltext); print ''; @@ -1072,7 +1073,7 @@ if ($step == 5 && $datatoimport) $param='&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; @@ -1133,7 +1134,7 @@ if ($step == 5 && $datatoimport) print ''; $modulepart='import'; //$relativepath=$filetoimport; - print ''; + print ''; print $filetoimport; print ''; print ''; @@ -1147,14 +1148,18 @@ if ($step == 5 && $datatoimport) // Checkbox do not import first line print ''; - print $langs->trans("DoNotImportFirstLine"); + print $langs->trans("Option"); print ''; print ''; + print ' '.$langs->trans("DoNotImportFirstLine"); print ''; print ''; + + print '
'; + print ''.$langs->trans("InformationOnTargetTables").''; print ''; //print ''; @@ -1280,7 +1285,7 @@ if ($step == 6 && $datatoimport) $param='&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; @@ -1345,7 +1350,7 @@ if ($step == 6 && $datatoimport) print ''; @@ -1359,14 +1364,19 @@ if ($step == 6 && $datatoimport) // Checkbox do not import first line print ''; print '
'.$langs->trans("InformationOnTargetTables").'
'; $modulepart='import'; //$relativepath=$filetoimport; - print ''; + print ''; print $filetoimport; print ''; print '
'; - print $langs->trans("DoNotImportFirstLine"); + print $langs->trans("Option"); print ''; - print ''; + print ''; + print ' '.$langs->trans("DoNotImportFirstLine"); print '
'; + + print '
'; + print ''.$langs->trans("InformationOnTargetTables").''; print ''; //print ''; @@ -1457,7 +1467,7 @@ if ($step == 6 && $datatoimport) { $sourcelinenb++; if ($excludefirstline && $sourcelinenb == 1) continue; - + $result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,sizeof($fieldssource),$importid); if (sizeof($obj->errors)) { @@ -1478,12 +1488,15 @@ if ($step == 6 && $datatoimport) $db->rollback(); // We force rollback because this was just a simulation. + // If nothing + if (! sizeof($arrayoferrors) && ! sizeof($arrayofwarnings)) print img_tick().' '.$langs->trans("NoErrors").'
'; + // Errors //var_dump($arrayoferrors); - print ''.$langs->trans("Errors").''; - print '
'; if (sizeof($arrayoferrors)) { + print img_error().' '.$langs->trans("ErrorsOnXLines",sizeof($arrayoferrors)).'
'; + //print '
'.$langs->trans("InformationOnTargetTables").'
'; foreach ($arrayoferrors as $key => $val) { $nboferrors++; @@ -1495,20 +1508,20 @@ if ($step == 6 && $datatoimport) print '* '.$langs->trans("Line").' '.$key.'
'; foreach($val as $i => $err) { - print '   - '.$err['lib'].'
'; + print '     > '.$err['lib'].'
'; } } + //print '
'; + print '
'; } - else print $langs->trans("None"); - - print '
'; + // Warnings //var_dump($arrayoferrors); - print ''.$langs->trans("Warnings").''; - print '
'; if (sizeof($arrayofwarnings)) { + print img_warning().' '.$langs->trans("WarningsOnXLines",sizeof($arrayofwarnings)).'
'; + //print '
'; foreach ($arrayofwarnings as $key => $val) { $nbofwarnings++; @@ -1520,17 +1533,20 @@ if ($step == 6 && $datatoimport) print ' * '.$langs->trans("Line").' '.$key.'
'; foreach($val as $i => $err) { - print '   - '.$err['lib'].'
'; + print '     > '.$err['lib'].'
'; } } + //print '
'; + print '
'; } - else print $langs->trans("None"); - + $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 ''; @@ -1540,7 +1556,7 @@ if ($step == 6 && $datatoimport) { if (empty($nboferrors)) { - print ''.$langs->trans("RunImportFile").''; + print ''.$langs->trans("RunImportFile").''; } else { @@ -1559,6 +1575,266 @@ if ($step == 6 && $datatoimport) if ($mesg) print $mesg; } + + +// STEP 6: Result of simulation +if ($step == 7 && $datatoimport) +{ + $model=$format; + $liste=$objmodelimport->liste_modeles($db); + $importid=$_REQUEST["importid"]; + + + // Create classe to use for import + $dir = DOL_DOCUMENT_ROOT . "/includes/modules/import/"; + $file = "import_".$model.".modules.php"; + $classname = "Import".ucfirst($model); + require_once($dir.$file); + $obj = new $classname($db); + + // Load source fields in input file + $fieldssource=array(); + $result=$obj->import_open_file($conf->import->dir_temp.'/'.$filetoimport,$langs); + if ($result >= 0) + { + // Read first line + $arrayrecord=$obj->import_read_record(); + // Put into array fieldssource starting with 1. + $i=1; + foreach($arrayrecord as $key => $val) + { + $fieldssource[$i]['example1']=dol_trunc($val['val'],24); + $i++; + } + $obj->import_close_file(); + } + + $nboflines=(! empty($_GET["nboflines"])?$_GET["nboflines"]:dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport)); + + $param='&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][1] = $langs->trans("Step")." 1"; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=2&datatoimport='.$datatoimport; + $head[$h][1] = $langs->trans("Step")." 2"; + $h++; + + $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][1] = $langs->trans("Step")." 4"; + $h++; + + $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][1] = $langs->trans("Step")." 6"; + $h++; + + $head[$h][0] = DOL_URL_ROOT.'/imports/import.php?step=7&'.$param; + $head[$h][1] = $langs->trans("Step")." 7"; + $hselected=$h; + $h++; + + dol_fiche_head($head, $hselected, $langs->trans("NewImport")); + + print ''; + + // Module + print ''; + print ''; + + // Lot de donnees a importer + print ''; + print ''; + + print '
'.$langs->trans("Module").''; + //print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_module[0]->picto).' '; + print $objimport->array_import_module[0]->getName(); + print '
'.$langs->trans("DatasetToImport").''; + print img_object($objimport->array_import_module[0]->getName(),$objimport->array_import_icon[0]).' '; + print $objimport->array_import_label[0]; + print '

'; + print ''.$langs->trans("InformationOnSourceFile").''; + print ''; + //print ''; + + // Source file format + print ''; + print ''; + + // File to import + print ''; + print ''; + + // Nb of fields + print ''; + + // Checkbox do not import first line + print ''; + + print '
'.$langs->trans("InformationOnSourceFile").'
'.$langs->trans("SourceFileFormat").''; + $text=$objmodelimport->getDriverDesc($format); + print $html->textwithpicto($objmodelimport->getDriverLabel($format),$text); + print '
'.$langs->trans("FileToImport").''; + $modulepart='import'; + //$relativepath=$filetoimport; + print ''; + print $filetoimport; + print ''; + print '
'; + print $langs->trans("NbOfSourceLines"); + print ''; + print $nboflines; + print '
'; + print $langs->trans("Option"); + print ''; + print ''; + print ' '.$langs->trans("DoNotImportFirstLine"); + print '
'; + + print '
'; + + print ''.$langs->trans("InformationOnTargetTables").''; + print ''; + //print ''; + + // Tables imported + print ''; + + // Fields imported + print ''; + + print '
'.$langs->trans("InformationOnTargetTables").'
'; + print $langs->trans("TablesTarget"); + print ''; + $listtables=array(); + foreach($array_match_file_to_database as $code=>$label) + { + //var_dump($fieldssource); + if ($code > sizeof($fieldssource)) continue; + //print $code.'-'.$label; + $alias=eregi_replace('\..*$','',$label); + $listtables[$alias]=$objimport->array_import_tables[0][$alias]; + } + if (sizeof($listtables)) + { + $newval=''; + foreach ($listtables as $val) + { + if ($newval) print ', '; + $newval=$val; + // Link to Dolibarr wiki pages + /*$helppagename='EN:Table_'.$newval; + if ($helppagename && empty($conf->global->MAIN_HELP_DISABLELINK)) + { + // Get helpbaseurl, helppage and mode from helppagename and langs + $arrayres=getHelpParamFor($helppagename,$langs); + $helpbaseurl=$arrayres['helpbaseurl']; + $helppage=$arrayres['helppage']; + $mode=$arrayres['mode']; + $newval.=' '.img_picto($langs->trans($mode == 'wiki' ? 'GoToWikiHelpPage': 'GoToHelpPage'),DOL_URL_ROOT.'/theme/common/helpdoc.png','',1).''; + }*/ + print $newval; + } + } + else print $langs->trans("Error"); + print '
'; + print $langs->trans("FieldsTarget").''; + $listfields=array(); + $i=0; + $sort_array_match_file_to_database=$array_match_file_to_database; + ksort($sort_array_match_file_to_database); + //var_dump($sort_array_match_file_to_database); + foreach($sort_array_match_file_to_database as $code=>$label) + { + $i++; + //var_dump($fieldssource); + if ($code > sizeof($fieldssource)) continue; + //print $code.'-'.$label; + $alias=eregi_replace('\..*$','',$label); + $listfields[$i]=$label; + } + print sizeof($listfields)?(join(', ',$listfields)):$langs->trans("Error"); + print '
'; + + print '
'; + + // Launch import + $arrayoferrors=array(); + $arrayofwarnings=array(); + $maxnboferrors=empty($conf->global->IMPORT_MAX_NB_OF_ERRORS)?50:$conf->global->IMPORT_MAX_NB_OF_ERRORS; + $maxnbofwarnings=empty($conf->global->IMPORT_MAX_NB_OF_WARNINGS)?50:$conf->global->IMPORT_MAX_NB_OF_WARNINGS; + $nboferrors=0; + $nbofwarnings=0; + + $importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S'); + + $db->begin(); + + //var_dump($array_match_file_to_database); + + // Open input file + $pathfile=$conf->import->dir_temp.'/'.$filetoimport; + $result=$obj->import_open_file($pathfile,$langs); + if ($result > 0) + { + $sourcelinenb=0; + // Loop on each input file record + while ($arrayrecord=$obj->import_read_record()) + { + $sourcelinenb++; + 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; + } + } + // Close file + $obj->import_close_file(); + } + else + { + 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 '
'; + + print ''; + + if ($mesg) print $mesg; +} + + + print '
'; diff --git a/htdocs/includes/modules/import/import_csv.modules.php b/htdocs/includes/modules/import/import_csv.modules.php index d473a894370..fc66fb72feb 100644 --- a/htdocs/includes/modules/import/import_csv.modules.php +++ b/htdocs/includes/modules/import/import_csv.modules.php @@ -273,7 +273,7 @@ class ImportCsv extends ModeleImports function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid) { global $langs,$conf; - + $error=0; $warning=0; $this->errors=array(); @@ -331,7 +331,7 @@ class ImportCsv extends ModeleImports // Make some tests // Required field is ok - if (eregi('\*',$objimport->array_import_fields[0][$val]) && empty($newval)) + if (eregi('\*',$objimport->array_import_fields[0][$val]) && ($newval=='')) { $this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key); $this->errors[$error]['type']='NOTNULL'; @@ -351,7 +351,7 @@ class ImportCsv extends ModeleImports { if ($listfields) { - $sql='INSERT INTO '.$tablename.'('.$listfields.',import_key) VALUES('.$listvalues.",'".$importid."')"; + $sql='INSERT INTO '.$tablename.'('.$listfields.', import_key) VALUES('.$listvalues.", '".$importid."')"; dol_syslog("import_csv.modules sql=".$sql); //print '> '.join(',',$arrayrecord); @@ -369,7 +369,6 @@ class ImportCsv extends ModeleImports else { //print 'E'; -print $sql; $this->errors[$error]['lib']=$this->db->lasterror(); $this->errors[$error]['type']='SQL'; $error++; diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index b74c1544a64..5979b1a8908 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -1,5 +1,7 @@ # Dolibarr language file - en_US - errors CHARSET=UTF-8 +Error=Error +Errors=Errors MenuManager=Menu manager ErrorLoginAlreadyExists=Login %s already exists. ErrorGroupAlreadyExists=Group %s already exists. @@ -51,4 +53,6 @@ ErrorRecordHasChildren=Failed to delete records since it has some childs. WarningConfFileMustBeReadOnly=Warning, your config file (htdocs/conf/conf.php) can be overwritten by the web server. This is a serious security hole. Modify permissions on file to be in read only mode for operating system user used by Web server. If you use Windows and FAT format for your disk, you must know that this file system does not allow to add permissions on file, so can't be completely safe. 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. Pleas, 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. \ No newline at end of file +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. +ErrorsOnXLines=Errors on %s source lines +WarningsOnXLines=Warnings on %s source lines \ No newline at end of file diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 9c2988c1ab3..03cc9b2ecab 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -540,6 +540,7 @@ CreditCard=Credit card FieldsWithAreMandatory=Fields with %s are mandatory FieldsWithIsForPublic=Fields with %s are shown on public list of members. If you don't want this, check the "public" box. AccordingToGeoIPDatabase=(according to GeoIP convertion) +Line=Line # Week day Day1=Monday diff --git a/htdocs/langs/fr_FR/errors.lang b/htdocs/langs/fr_FR/errors.lang index b85bf0c77ae..053e71bd83d 100644 --- a/htdocs/langs/fr_FR/errors.lang +++ b/htdocs/langs/fr_FR/errors.lang @@ -1,5 +1,7 @@ # Dolibarr language file - fr_FR - errors CHARSET=UTF-8 +Error=Erreur +Errors=Erreurs MenuManager=Gestionnaire de menu ErrorLoginAlreadyExists=Le login %s existe déjà. ErrorGroupAlreadyExists=Le groupe %s existe déjà. @@ -53,3 +55,5 @@ 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 diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index 1ab2d47b6c6..d13583b38e4 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -539,6 +539,7 @@ CreditCard=Carte de crédit FieldsWithAreMandatory=Les champs marqués par un %s sont obligatoires FieldsWithIsForPublic=Les champs marqués par %s seront affiches sur la liste publique des membres. Si vous ne le souhaitez pas, décochez la case "public". AccordingToGeoIPDatabase=(obtenu par conversion GeoIP) +Line=Ligne # Week day Day1=Lundi